Auto merge of #27106 - paulrouget:defaulturl, r=jdm

[UWP] Better default url management

Fix #27046
This commit is contained in:
bors-servo 2020-06-29 09:23:09 -04:00 committed by GitHub
commit 56e0e557a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 37 deletions

View file

@ -7,7 +7,6 @@
#include "BrowserPage.h" #include "BrowserPage.h"
#include "BrowserPage.g.cpp" #include "BrowserPage.g.cpp"
#include "ConsoleLog.g.cpp" #include "ConsoleLog.g.cpp"
#include "DefaultUrl.h"
#include "Devtools/Client.h" #include "Devtools/Client.h"
using namespace std::placeholders; using namespace std::placeholders;
@ -148,7 +147,7 @@ void BrowserPage::OnStopButtonClicked(IInspectable const &,
void BrowserPage::OnHomeButtonClicked(IInspectable const &, void BrowserPage::OnHomeButtonClicked(IInspectable const &,
RoutedEventArgs const &) { RoutedEventArgs const &) {
servoControl().LoadURIOrSearch(DEFAULT_URL); servoControl().GoHome();
} }
// Given a pref, update its associated UI control. // Given a pref, update its associated UI control.

View file

@ -1,3 +1,8 @@
#pragma once #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"

View file

@ -5,6 +5,8 @@
namespace winrt::servo { namespace winrt::servo {
using namespace Windows::Storage;
void on_load_started() { sServo->Delegate().OnServoLoadStarted(); } void on_load_started() { sServo->Delegate().OnServoLoadStarted(); }
void on_load_ended() { sServo->Delegate().OnServoLoadEnded(); } 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, EGLNativeWindowType eglNativeWindow, float dpi,
ServoDelegate &aDelegate) ServoDelegate &aDelegate)
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) { : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
Windows::Storage::ApplicationDataContainer localSettings = ApplicationDataContainer localSettings =
Windows::Storage::ApplicationData::Current().LocalSettings(); ApplicationData::Current().LocalSettings();
if (!localSettings.Containers().HasKey(L"servoUserPrefs")) { if (!localSettings.Containers().HasKey(L"servoUserPrefs")) {
Windows::Storage::ApplicationDataContainer container = ApplicationDataContainer container = localSettings.CreateContainer(
localSettings.CreateContainer( L"servoUserPrefs", ApplicationDataCreateDisposition::Always);
L"servoUserPrefs",
Windows::Storage::ApplicationDataCreateDisposition::Always);
} }
auto prefs = localSettings.Containers().Lookup(L"servoUserPrefs"); auto prefs = localSettings.Containers().Lookup(L"servoUserPrefs");
if (!prefs.Values().HasKey(L"shell.homepage")) { 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")) { 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; std::vector<capi::CPref> cprefs;
for (auto pref : prefs.Values()) { for (auto pref : prefs.Values()) {
auto key = *hstring2char(pref.Key()); auto key = *hstring2char(pref.Key());
auto value = pref.Value(); auto value = pref.Value();
auto type = value.as<Windows::Foundation::IPropertyValue>().Type(); auto type = value.as<Windows::Foundation::IPropertyValue>().Type();
capi::CPref pref; capi::CPref cpref;
pref.key = key; cpref.key = key;
pref.pref_type = capi::CPrefType::Missing; cpref.pref_type = capi::CPrefType::Missing;
pref.value = NULL; cpref.value = NULL;
if (type == Windows::Foundation::PropertyType::Boolean) { if (type == Windows::Foundation::PropertyType::Boolean) {
pref.pref_type = capi::CPrefType::Bool; cpref.pref_type = capi::CPrefType::Bool;
auto val = unbox_value<bool>(value); auto val = unbox_value<bool>(value);
pref.value = &val; cpref.value = &val;
} else if (type == Windows::Foundation::PropertyType::String) { } else if (type == Windows::Foundation::PropertyType::String) {
pref.pref_type = capi::CPrefType::Str; cpref.pref_type = capi::CPrefType::Str;
pref.value = *hstring2char(unbox_value<hstring>(value)); 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) { } 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); auto val = unbox_value<int64_t>(value);
pref.value = &val; cpref.value = &val;
} else if (type == Windows::Foundation::PropertyType::Double) { } 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); auto val = unbox_value<double>(value);
pref.value = &val; cpref.value = &val;
} else if (type == Windows::Foundation::PropertyType::Empty) { } else if (type == Windows::Foundation::PropertyType::Empty) {
pref.pref_type = capi::CPrefType::Missing; cpref.pref_type = capi::CPrefType::Missing;
} else { } else {
log(L"skipping pref %s. Unknown type", key); log(L"skipping pref %s. Unknown type", key);
continue; continue;
} }
cprefs.push_back(pref); cprefs.push_back(cpref);
} }
capi::CPrefList prefsList = {cprefs.size(), cprefs.data()}; capi::CPrefList prefsList = {cprefs.size(), cprefs.data()};
@ -222,7 +229,7 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
bool logToFile = true; bool logToFile = true;
#endif #endif
if (logToFile) { if (logToFile) {
auto current = winrt::Windows::Storage::ApplicationData::Current(); auto current = ApplicationData::Current();
auto filePath = auto filePath =
std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt"; std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt";
sLogHandle = sLogHandle =
@ -315,9 +322,16 @@ Servo::PrefTuple Servo::ResetPref(hstring key) {
return updatedPref; 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) { void Servo::SaveUserPref(PrefTuple pref) {
auto localSettings = auto localSettings = ApplicationData::Current().LocalSettings();
Windows::Storage::ApplicationData::Current().LocalSettings();
auto values = localSettings.Containers().Lookup(L"servoUserPrefs").Values(); auto values = localSettings.Containers().Lookup(L"servoUserPrefs").Values();
auto [key, val, isDefault] = pref; auto [key, val, isDefault] = pref;
if (isDefault) { if (isDefault) {

View file

@ -26,8 +26,7 @@ class ServoDelegate;
class Servo { class Servo {
public: public:
Servo(hstring, hstring, GLsizei, GLsizei, EGLNativeWindowType, float, Servo(hstring, GLsizei, GLsizei, EGLNativeWindowType, float, ServoDelegate &);
ServoDelegate &);
~Servo(); ~Servo();
ServoDelegate &Delegate() { return mDelegate; } ServoDelegate &Delegate() { return mDelegate; }
@ -69,6 +68,7 @@ public:
bool LoadUri(hstring uri) { return load_uri(*hstring2char(uri)); } bool LoadUri(hstring uri) { return load_uri(*hstring2char(uri)); }
void ChangeVisibility(bool visible) { change_visibility(visible); } void ChangeVisibility(bool visible) { change_visibility(visible); }
bool IsUriValid(hstring uri) { return is_uri_valid(*hstring2char(uri)); } bool IsUriValid(hstring uri) { return is_uri_valid(*hstring2char(uri)); }
void GoHome();
void Scroll(float dx, float dy, float x, float y) { void Scroll(float dx, float dy, float x, float y) {
scroll((int32_t)dx, (int32_t)dy, (int32_t)x, (int32_t)y); scroll((int32_t)dx, (int32_t)dy, (int32_t)x, (int32_t)y);
} }

View file

@ -270,6 +270,9 @@ void ServoControl::ChangeVisibility(bool visible) {
void ServoControl::Stop() { void ServoControl::Stop() {
RunOnGLThread([=] { mServo->Stop(); }); RunOnGLThread([=] { mServo->Stop(); });
} }
void ServoControl::GoHome() {
RunOnGLThread([=] { mServo->GoHome(); });
}
hstring ServoControl::LoadURIOrSearch(hstring input) { hstring ServoControl::LoadURIOrSearch(hstring input) {
// Initial input is valid // Initial input is valid
if (mServo->IsUriValid(input)) { if (mServo->IsUriValid(input)) {
@ -306,9 +309,7 @@ void ServoControl::SendMediaSessionAction(int32_t action) {
} }
void ServoControl::TryLoadUri(hstring input) { void ServoControl::TryLoadUri(hstring input) {
if (!mLooping) { if (mLooping) {
mInitialURL = input;
} else {
RunOnGLThread([=] { RunOnGLThread([=] {
if (!mServo->LoadUri(input)) { if (!mServo->LoadUri(input)) {
RunOnUIThread([=] { RunOnUIThread([=] {
@ -336,8 +337,8 @@ void ServoControl::Loop() {
log(L"Entering loop"); log(L"Entering loop");
ServoDelegate *sd = static_cast<ServoDelegate *>(this); ServoDelegate *sd = static_cast<ServoDelegate *>(this);
EGLNativeWindowType win = GetNativeWindow(); EGLNativeWindowType win = GetNativeWindow();
mServo = std::make_unique<Servo>(mInitialURL, mArgs, mPanelWidth, mServo = std::make_unique<Servo>(mArgs, mPanelWidth, mPanelHeight, win,
mPanelHeight, win, mDPI, *sd); mDPI, *sd);
} else { } else {
// FIXME: this will fail since create_task didn't pick the thread // FIXME: this will fail since create_task didn't pick the thread
// where Servo was running initially. // where Servo was running initially.

View file

@ -3,7 +3,6 @@
#include "Pref.g.h" #include "Pref.g.h"
#include "OpenGLES.h" #include "OpenGLES.h"
#include "Servo.h" #include "Servo.h"
#include "DefaultUrl.h"
using namespace winrt::Windows::Foundation::Collections; using namespace winrt::Windows::Foundation::Collections;
@ -49,6 +48,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
void ChangeVisibility(bool); void ChangeVisibility(bool);
void Shutdown(); void Shutdown();
hstring LoadURIOrSearch(hstring); hstring LoadURIOrSearch(hstring);
void GoHome();
void SendMediaSessionAction(int32_t); void SendMediaSessionAction(int32_t);
ServoApp::Pref SetBoolPref(hstring aKey, bool aVal) { ServoApp::Pref SetBoolPref(hstring aKey, bool aVal) {
@ -214,7 +214,6 @@ private:
int mPanelHeight = 0; int mPanelHeight = 0;
int mPanelWidth = 0; int mPanelWidth = 0;
float mDPI = 1; float mDPI = 1;
hstring mInitialURL = DEFAULT_URL;
hstring mCurrentUrl = L""; hstring mCurrentUrl = L"";
bool mTransient = false; bool mTransient = false;

View file

@ -26,6 +26,7 @@ namespace ServoApp {
void Reload(); void Reload();
void Stop(); void Stop();
String LoadURIOrSearch(String url); String LoadURIOrSearch(String url);
void GoHome();
void SetTransientMode(Boolean transient); void SetTransientMode(Boolean transient);
void SetArgs(String args); void SetArgs(String args);
void Shutdown(); void Shutdown();