mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Allow embedder to bypass devtools prompt
This commit is contained in:
parent
3f999ce785
commit
8cf2f14baa
16 changed files with 83 additions and 35 deletions
|
@ -80,9 +80,10 @@ void BrowserPage::BindServoEvents() {
|
|||
: Visibility::Visible);
|
||||
});
|
||||
servoControl().OnDevtoolsStatusChanged(
|
||||
[=](DevtoolsStatus status, unsigned int port) {
|
||||
[=](DevtoolsStatus status, unsigned int port, hstring token) {
|
||||
mDevtoolsStatus = status;
|
||||
mDevtoolsPort = port;
|
||||
mDevtoolsToken = token;
|
||||
});
|
||||
Window::Current().VisibilityChanged(
|
||||
[=](const auto &, const VisibilityChangedEventArgs &args) {
|
||||
|
@ -318,8 +319,8 @@ void BrowserPage::OnDevtoolsButtonClicked(IInspectable const &,
|
|||
hstring port = to_hstring(mDevtoolsPort);
|
||||
if (mDevtoolsClient == nullptr) {
|
||||
DevtoolsDelegate *dd = static_cast<DevtoolsDelegate *>(this);
|
||||
mDevtoolsClient =
|
||||
std::make_unique<DevtoolsClient>(L"localhost", port, *dd);
|
||||
mDevtoolsClient = std::make_unique<DevtoolsClient>(L"localhost", port,
|
||||
mDevtoolsToken, *dd);
|
||||
}
|
||||
mDevtoolsClient->Run();
|
||||
std::wstring message =
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
void BuildPrefList();
|
||||
DevtoolsStatus mDevtoolsStatus = DevtoolsStatus::Stopped;
|
||||
unsigned int mDevtoolsPort = 0;
|
||||
hstring mDevtoolsToken;
|
||||
std::unique_ptr<servo::DevtoolsClient> mDevtoolsClient;
|
||||
Collections::IObservableVector<IInspectable> mLogs;
|
||||
};
|
||||
|
|
|
@ -31,6 +31,11 @@ void DevtoolsClient::Run() {
|
|||
connecting.Completed([=](const auto &, const auto &) {
|
||||
mDataReader = DataReader(socket.InputStream());
|
||||
mDataWriter = DataWriter(socket.OutputStream());
|
||||
|
||||
JsonObject out;
|
||||
out.Insert(L"auth_token", JsonValue::CreateStringValue(mToken));
|
||||
Send(out);
|
||||
|
||||
mReceiveOp = {Loop()};
|
||||
mReceiveOp->Completed([=](const auto &, const auto &) {
|
||||
mReceiveOp = {};
|
||||
|
|
|
@ -19,8 +19,9 @@ enum DevtoolsMessageLevel { Error, Warn, None };
|
|||
class DevtoolsClient {
|
||||
|
||||
public:
|
||||
DevtoolsClient(hstring hostname, hstring port, DevtoolsDelegate &d)
|
||||
: mDelegate(d), mHostname(hostname), mPort(port){};
|
||||
DevtoolsClient(hstring hostname, hstring port, hstring token,
|
||||
DevtoolsDelegate &d)
|
||||
: mDelegate(d), mHostname(hostname), mToken(token), mPort(port){};
|
||||
|
||||
~DevtoolsClient() { Stop(); }
|
||||
void Run();
|
||||
|
@ -30,6 +31,7 @@ public:
|
|||
|
||||
private:
|
||||
hstring mPort;
|
||||
hstring mToken;
|
||||
hstring mHostname;
|
||||
DevtoolsDelegate &mDelegate;
|
||||
std::optional<DataReader> mDataReader;
|
||||
|
|
|
@ -83,9 +83,9 @@ void show_context_menu(const char *title, const char *const *items_list,
|
|||
}
|
||||
|
||||
void on_devtools_started(Servo::DevtoolsServerState result,
|
||||
const unsigned int port) {
|
||||
sServo->Delegate().OnServoDevtoolsStarted(
|
||||
result == Servo::DevtoolsServerState::Started, port);
|
||||
const unsigned int port, const char *token) {
|
||||
auto state = result == Servo::DevtoolsServerState::Started;
|
||||
sServo->Delegate().OnServoDevtoolsStarted(state, port, char2hstring(token));
|
||||
}
|
||||
|
||||
void on_log_output(const char *buffer, uint32_t buffer_length) {
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
virtual bool OnServoAllowNavigation(hstring) = 0;
|
||||
virtual void OnServoAnimatingChanged(bool) = 0;
|
||||
virtual void OnServoIMEStateChanged(bool) = 0;
|
||||
virtual void OnServoDevtoolsStarted(bool, const unsigned int) = 0;
|
||||
virtual void OnServoDevtoolsStarted(bool, const unsigned int, hstring) = 0;
|
||||
virtual void OnServoMediaSessionMetadata(hstring, hstring, hstring) = 0;
|
||||
virtual void OnServoMediaSessionPlaybackStateChange(int) = 0;
|
||||
virtual void OnServoPromptAlert(hstring, bool) = 0;
|
||||
|
|
|
@ -571,11 +571,11 @@ std::optional<hstring> ServoControl::OnServoPromptInput(winrt::hstring message,
|
|||
return string;
|
||||
}
|
||||
|
||||
void ServoControl::OnServoDevtoolsStarted(bool success,
|
||||
const unsigned int port) {
|
||||
void ServoControl::OnServoDevtoolsStarted(bool success, const unsigned int port,
|
||||
hstring token) {
|
||||
RunOnUIThread([=] {
|
||||
auto status = success ? DevtoolsStatus::Running : DevtoolsStatus::Failed;
|
||||
mOnDevtoolsStatusChangedEvent(status, port);
|
||||
mOnDevtoolsStatusChangedEvent(status, port, token);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -185,7 +185,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, const unsigned int);
|
||||
virtual void OnServoDevtoolsStarted(bool, const unsigned int, winrt::hstring);
|
||||
|
||||
DevtoolsStatus GetDevtoolsStatus();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace ServoApp {
|
|||
delegate void EventDelegate();
|
||||
delegate void HistoryChangedDelegate(Boolean back, Boolean forward);
|
||||
delegate void MediaSessionMetadataDelegate(String title, String artist, String album);
|
||||
delegate void DevtoolsStatusChangedDelegate(DevtoolsStatus status, UInt32 port);
|
||||
delegate void DevtoolsStatusChangedDelegate(DevtoolsStatus status, UInt32 port, String token);
|
||||
|
||||
enum DevtoolsStatus {
|
||||
Running = 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue