Auto merge of #25967 - paulrouget:devtoolsToast, r=Manishearth

Re-enabling devtools on UWP
This commit is contained in:
bors-servo 2020-03-16 15:38:23 -04:00 committed by GitHub
commit fdc725925d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 7 deletions

View file

@ -14,6 +14,7 @@ using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::UI::ViewManagement;
using namespace winrt::Windows::ApplicationModel::Core;
using namespace winrt::Windows::UI::Notifications;
namespace winrt::ServoApp::implementation {
BrowserPage::BrowserPage() {
@ -109,7 +110,10 @@ void BrowserPage::SetTransientMode(bool transient) {
void BrowserPage::SetArgs(hstring args) { servoControl().SetArgs(args); }
void BrowserPage::Shutdown() { servoControl().Shutdown(); }
void BrowserPage::Shutdown() {
ToastNotificationManager::History().Clear();
servoControl().Shutdown();
}
/**** USER INTERACTIONS WITH UI ****/

View file

@ -67,6 +67,12 @@ void prompt_alert(const char *message, bool trusted) {
sServo->Delegate().OnServoPromptAlert(char2hstring(message), trusted);
}
void on_devtools_started(Servo::DevtoolsServerState result,
const unsigned int port) {
sServo->Delegate().OnServoDevtoolsStarted(
result == Servo::DevtoolsServerState::Started, port);
}
Servo::PromptResult prompt_ok_cancel(const char *message, bool trusted) {
return sServo->Delegate().OnServoPromptOkCancel(char2hstring(message),
trusted);
@ -87,17 +93,12 @@ const char *prompt_input(const char *message, const char *default,
}
}
void on_devtools_started(Servo::DevtoolsServerState result,
const unsigned int port) {
// FIXME
}
Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
float dpi, ServoDelegate &aDelegate)
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
capi::CInitOptions o;
hstring defaultPrefs = L" --pref dom.webxr.enabled";
hstring defaultPrefs = L" --pref dom.webxr.enabled --devtools";
o.args = *hstring2char(args + defaultPrefs);
o.url = *hstring2char(url);
o.width = mWindowWidth;

View file

@ -95,6 +95,7 @@ public:
virtual bool OnServoAllowNavigation(hstring) = 0;
virtual void OnServoAnimatingChanged(bool) = 0;
virtual void OnServoIMEStateChanged(bool) = 0;
virtual void OnServoDevtoolsStarted(bool, unsigned int) = 0;
virtual void Flush() = 0;
virtual void MakeCurrent() = 0;
virtual void OnServoMediaSessionMetadata(hstring, hstring, hstring) = 0;

View file

@ -11,6 +11,8 @@ using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::System;
using namespace winrt::Windows::Devices::Input;
using namespace winrt::Windows::UI::Notifications;
using namespace winrt::Windows::Data::Xml::Dom;
using namespace concurrency;
using namespace winrt::servo;
@ -556,6 +558,22 @@ std::optional<hstring> ServoControl::OnServoPromptInput(winrt::hstring message,
return string;
}
void ServoControl::OnServoDevtoolsStarted(bool success,
const unsigned int port) {
auto toastTemplate = ToastTemplateType::ToastText01;
auto toastXml = ToastNotificationManager::GetTemplateContent(toastTemplate);
auto toastTextElements = toastXml.GetElementsByTagName(L"text");
std::wstring message;
if (success) {
message = L"DevTools server has started on port " + std::to_wstring(port);
} else {
message = L"Error: could not start DevTools";
}
toastTextElements.Item(0).InnerText(message);
auto toast = ToastNotification(toastXml);
ToastNotificationManager::CreateToastNotifier().Show(toast);
}
template <typename Callable> void ServoControl::RunOnUIThread(Callable cb) {
Dispatcher().RunAsync(CoreDispatcherPriority::High, cb);
}

View file

@ -114,6 +114,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
virtual servo::Servo::PromptResult OnServoPromptYesNo(winrt::hstring, bool);
virtual std::optional<hstring> OnServoPromptInput(winrt::hstring,
winrt::hstring, bool);
virtual void OnServoDevtoolsStarted(bool success, const unsigned int port);
private:
winrt::event<Windows::Foundation::EventHandler<hstring>> mOnURLChangedEvent;

View file

@ -52,3 +52,5 @@
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <winrt/Windows.UI.Xaml.Markup.h>
#include <winrt/Windows.UI.Xaml.Navigation.h>
#include <winrt/Windows.UI.Notifications.h>
#include <winrt/Windows.Data.Xml.Dom.h>