mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #27106 - paulrouget:defaulturl, r=jdm
[UWP] Better default url management Fix #27046
This commit is contained in:
commit
56e0e557a5
7 changed files with 56 additions and 37 deletions
|
@ -7,7 +7,6 @@
|
|||
#include "BrowserPage.h"
|
||||
#include "BrowserPage.g.cpp"
|
||||
#include "ConsoleLog.g.cpp"
|
||||
#include "DefaultUrl.h"
|
||||
#include "Devtools/Client.h"
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
@ -148,7 +147,7 @@ void BrowserPage::OnStopButtonClicked(IInspectable const &,
|
|||
|
||||
void BrowserPage::OnHomeButtonClicked(IInspectable const &,
|
||||
RoutedEventArgs const &) {
|
||||
servoControl().LoadURIOrSearch(DEFAULT_URL);
|
||||
servoControl().GoHome();
|
||||
}
|
||||
|
||||
// Given a pref, update its associated UI control.
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#define DEFAULT_URL L"https://servo.org/hl-home/"
|
||||
#define DEFAULT_URL_PROD L"https://servo.org/hl-home/"
|
||||
|
||||
// For development purpose.
|
||||
// Will override DEFAULT_URL_PROD or any locally stored preferences.
|
||||
// #define OVERRIDE_DEFAULT_URL "data:text/html,<input>"
|
||||
// #define OVERRIDE_DEFAULT_URL "http://localhost:8000/test.html"
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
namespace winrt::servo {
|
||||
|
||||
using namespace Windows::Storage;
|
||||
|
||||
void on_load_started() { sServo->Delegate().OnServoLoadStarted(); }
|
||||
|
||||
void on_load_ended() { sServo->Delegate().OnServoLoadEnded(); }
|
||||
|
@ -125,23 +127,21 @@ const char *prompt_input(const char *message, const char *default,
|
|||
}
|
||||
}
|
||||
|
||||
Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
|
||||
Servo::Servo(hstring args, GLsizei width, GLsizei height,
|
||||
EGLNativeWindowType eglNativeWindow, float dpi,
|
||||
ServoDelegate &aDelegate)
|
||||
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
|
||||
Windows::Storage::ApplicationDataContainer localSettings =
|
||||
Windows::Storage::ApplicationData::Current().LocalSettings();
|
||||
ApplicationDataContainer localSettings =
|
||||
ApplicationData::Current().LocalSettings();
|
||||
if (!localSettings.Containers().HasKey(L"servoUserPrefs")) {
|
||||
Windows::Storage::ApplicationDataContainer container =
|
||||
localSettings.CreateContainer(
|
||||
L"servoUserPrefs",
|
||||
Windows::Storage::ApplicationDataCreateDisposition::Always);
|
||||
ApplicationDataContainer container = localSettings.CreateContainer(
|
||||
L"servoUserPrefs", ApplicationDataCreateDisposition::Always);
|
||||
}
|
||||
|
||||
auto prefs = localSettings.Containers().Lookup(L"servoUserPrefs");
|
||||
|
||||
if (!prefs.Values().HasKey(L"shell.homepage")) {
|
||||
prefs.Values().Insert(L"shell.homepage", box_value(DEFAULT_URL));
|
||||
prefs.Values().Insert(L"shell.homepage", box_value(DEFAULT_URL_PROD));
|
||||
}
|
||||
|
||||
if (!prefs.Values().HasKey(L"dom.webxr.enabled")) {
|
||||
|
@ -151,35 +151,42 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
|
|||
std::vector<capi::CPref> cprefs;
|
||||
|
||||
for (auto pref : prefs.Values()) {
|
||||
|
||||
auto key = *hstring2char(pref.Key());
|
||||
auto value = pref.Value();
|
||||
|
||||
auto type = value.as<Windows::Foundation::IPropertyValue>().Type();
|
||||
capi::CPref pref;
|
||||
pref.key = key;
|
||||
pref.pref_type = capi::CPrefType::Missing;
|
||||
pref.value = NULL;
|
||||
capi::CPref cpref;
|
||||
cpref.key = key;
|
||||
cpref.pref_type = capi::CPrefType::Missing;
|
||||
cpref.value = NULL;
|
||||
if (type == Windows::Foundation::PropertyType::Boolean) {
|
||||
pref.pref_type = capi::CPrefType::Bool;
|
||||
cpref.pref_type = capi::CPrefType::Bool;
|
||||
auto val = unbox_value<bool>(value);
|
||||
pref.value = &val;
|
||||
cpref.value = &val;
|
||||
} else if (type == Windows::Foundation::PropertyType::String) {
|
||||
pref.pref_type = capi::CPrefType::Str;
|
||||
pref.value = *hstring2char(unbox_value<hstring>(value));
|
||||
cpref.pref_type = capi::CPrefType::Str;
|
||||
cpref.value = *hstring2char(unbox_value<hstring>(value));
|
||||
#ifdef OVERRIDE_DEFAULT_URL
|
||||
if (pref.Key() == L"shell.homepage") {
|
||||
cpref.value = OVERRIDE_DEFAULT_URL;
|
||||
}
|
||||
#endif
|
||||
} else if (type == Windows::Foundation::PropertyType::Int64) {
|
||||
pref.pref_type = capi::CPrefType::Int;
|
||||
cpref.pref_type = capi::CPrefType::Int;
|
||||
auto val = unbox_value<int64_t>(value);
|
||||
pref.value = &val;
|
||||
cpref.value = &val;
|
||||
} else if (type == Windows::Foundation::PropertyType::Double) {
|
||||
pref.pref_type = capi::CPrefType::Float;
|
||||
cpref.pref_type = capi::CPrefType::Float;
|
||||
auto val = unbox_value<double>(value);
|
||||
pref.value = &val;
|
||||
cpref.value = &val;
|
||||
} else if (type == Windows::Foundation::PropertyType::Empty) {
|
||||
pref.pref_type = capi::CPrefType::Missing;
|
||||
cpref.pref_type = capi::CPrefType::Missing;
|
||||
} else {
|
||||
log(L"skipping pref %s. Unknown type", key);
|
||||
continue;
|
||||
}
|
||||
cprefs.push_back(pref);
|
||||
cprefs.push_back(cpref);
|
||||
}
|
||||
|
||||
capi::CPrefList prefsList = {cprefs.size(), cprefs.data()};
|
||||
|
@ -222,7 +229,7 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
|
|||
bool logToFile = true;
|
||||
#endif
|
||||
if (logToFile) {
|
||||
auto current = winrt::Windows::Storage::ApplicationData::Current();
|
||||
auto current = ApplicationData::Current();
|
||||
auto filePath =
|
||||
std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt";
|
||||
sLogHandle =
|
||||
|
@ -315,9 +322,16 @@ Servo::PrefTuple Servo::ResetPref(hstring key) {
|
|||
return updatedPref;
|
||||
}
|
||||
|
||||
void Servo::GoHome() {
|
||||
ApplicationDataContainer localSettings =
|
||||
ApplicationData::Current().LocalSettings();
|
||||
auto prefs = localSettings.Containers().Lookup(L"servoUserPrefs");
|
||||
auto home = unbox_value<hstring>(prefs.Values().Lookup(L"shell.homepage"));
|
||||
LoadUri(home);
|
||||
}
|
||||
|
||||
void Servo::SaveUserPref(PrefTuple pref) {
|
||||
auto localSettings =
|
||||
Windows::Storage::ApplicationData::Current().LocalSettings();
|
||||
auto localSettings = ApplicationData::Current().LocalSettings();
|
||||
auto values = localSettings.Containers().Lookup(L"servoUserPrefs").Values();
|
||||
auto [key, val, isDefault] = pref;
|
||||
if (isDefault) {
|
||||
|
|
|
@ -26,8 +26,7 @@ class ServoDelegate;
|
|||
|
||||
class Servo {
|
||||
public:
|
||||
Servo(hstring, hstring, GLsizei, GLsizei, EGLNativeWindowType, float,
|
||||
ServoDelegate &);
|
||||
Servo(hstring, GLsizei, GLsizei, EGLNativeWindowType, float, ServoDelegate &);
|
||||
~Servo();
|
||||
ServoDelegate &Delegate() { return mDelegate; }
|
||||
|
||||
|
@ -69,6 +68,7 @@ public:
|
|||
bool LoadUri(hstring uri) { return load_uri(*hstring2char(uri)); }
|
||||
void ChangeVisibility(bool visible) { change_visibility(visible); }
|
||||
bool IsUriValid(hstring uri) { return is_uri_valid(*hstring2char(uri)); }
|
||||
void GoHome();
|
||||
void Scroll(float dx, float dy, float x, float y) {
|
||||
scroll((int32_t)dx, (int32_t)dy, (int32_t)x, (int32_t)y);
|
||||
}
|
||||
|
|
|
@ -270,6 +270,9 @@ void ServoControl::ChangeVisibility(bool visible) {
|
|||
void ServoControl::Stop() {
|
||||
RunOnGLThread([=] { mServo->Stop(); });
|
||||
}
|
||||
void ServoControl::GoHome() {
|
||||
RunOnGLThread([=] { mServo->GoHome(); });
|
||||
}
|
||||
hstring ServoControl::LoadURIOrSearch(hstring input) {
|
||||
// Initial input is valid
|
||||
if (mServo->IsUriValid(input)) {
|
||||
|
@ -306,9 +309,7 @@ void ServoControl::SendMediaSessionAction(int32_t action) {
|
|||
}
|
||||
|
||||
void ServoControl::TryLoadUri(hstring input) {
|
||||
if (!mLooping) {
|
||||
mInitialURL = input;
|
||||
} else {
|
||||
if (mLooping) {
|
||||
RunOnGLThread([=] {
|
||||
if (!mServo->LoadUri(input)) {
|
||||
RunOnUIThread([=] {
|
||||
|
@ -336,8 +337,8 @@ void ServoControl::Loop() {
|
|||
log(L"Entering loop");
|
||||
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
|
||||
EGLNativeWindowType win = GetNativeWindow();
|
||||
mServo = std::make_unique<Servo>(mInitialURL, mArgs, mPanelWidth,
|
||||
mPanelHeight, win, mDPI, *sd);
|
||||
mServo = std::make_unique<Servo>(mArgs, mPanelWidth, mPanelHeight, win,
|
||||
mDPI, *sd);
|
||||
} else {
|
||||
// FIXME: this will fail since create_task didn't pick the thread
|
||||
// where Servo was running initially.
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "Pref.g.h"
|
||||
#include "OpenGLES.h"
|
||||
#include "Servo.h"
|
||||
#include "DefaultUrl.h"
|
||||
|
||||
using namespace winrt::Windows::Foundation::Collections;
|
||||
|
||||
|
@ -49,6 +48,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
|
|||
void ChangeVisibility(bool);
|
||||
void Shutdown();
|
||||
hstring LoadURIOrSearch(hstring);
|
||||
void GoHome();
|
||||
void SendMediaSessionAction(int32_t);
|
||||
|
||||
ServoApp::Pref SetBoolPref(hstring aKey, bool aVal) {
|
||||
|
@ -214,7 +214,6 @@ private:
|
|||
int mPanelHeight = 0;
|
||||
int mPanelWidth = 0;
|
||||
float mDPI = 1;
|
||||
hstring mInitialURL = DEFAULT_URL;
|
||||
hstring mCurrentUrl = L"";
|
||||
bool mTransient = false;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace ServoApp {
|
|||
void Reload();
|
||||
void Stop();
|
||||
String LoadURIOrSearch(String url);
|
||||
void GoHome();
|
||||
void SetTransientMode(Boolean transient);
|
||||
void SetArgs(String args);
|
||||
void Shutdown();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue