Backport (3-0-x) - Fix devtools not functioning well (#13571)

* implement devtools showItemInFolder message

* add stubs for new devtools messages

* fix: update devtools url

* spec: enable back devtools tests

* spec: disable the i18nString test

It is failed because of fs.statSyncNoException, I'll fix it in another
PR.
This commit is contained in:
trop[bot] 2018-07-06 13:19:21 +10:00 committed by Samuel Attard
parent 8585372e11
commit c2f4144996
5 changed files with 78 additions and 6 deletions

View file

@ -168,6 +168,7 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
d->RegisterHandlerWithCallback("setIsDocked", &Delegate::SetIsDocked,
delegate);
d->RegisterHandler("openInNewTab", &Delegate::OpenInNewTab, delegate);
d->RegisterHandler("showItemInFolder", &Delegate::ShowItemInFolder, delegate);
d->RegisterHandler("save", &Delegate::SaveToFile, delegate);
d->RegisterHandler("append", &Delegate::AppendToFile, delegate);
d->RegisterHandler("requestFileSystems", &Delegate::RequestFileSystems,
@ -183,11 +184,21 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
d->RegisterHandler("searchInPath", &Delegate::SearchInPath, delegate);
d->RegisterHandler("setWhitelistedShortcuts",
&Delegate::SetWhitelistedShortcuts, delegate);
d->RegisterHandler("setEyeDropperActive", &Delegate::SetEyeDropperActive,
delegate);
d->RegisterHandler("showCertificateViewer", &Delegate::ShowCertificateViewer,
delegate);
d->RegisterHandler("zoomIn", &Delegate::ZoomIn, delegate);
d->RegisterHandler("zoomOut", &Delegate::ZoomOut, delegate);
d->RegisterHandler("resetZoom", &Delegate::ResetZoom, delegate);
d->RegisterHandler("setDevicesDiscoveryConfig",
&Delegate::SetDevicesDiscoveryConfig, delegate);
d->RegisterHandler("setDevicesUpdatesEnabled",
&Delegate::SetDevicesUpdatesEnabled, delegate);
d->RegisterHandler("performActionOnRemotePage",
&Delegate::PerformActionOnRemotePage, delegate);
d->RegisterHandler("openRemotePage", &Delegate::OpenRemotePage, delegate);
d->RegisterHandler("openNodeFrontend", &Delegate::OpenNodeFrontend, delegate);
d->RegisterHandler("dispatchProtocolMessage",
&Delegate::DispatchProtocolMessageFromDevToolsFrontend,
delegate);
@ -198,6 +209,7 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
d->RegisterHandler("setPreference", &Delegate::SetPreference, delegate);
d->RegisterHandler("removePreference", &Delegate::RemovePreference, delegate);
d->RegisterHandler("clearPreferences", &Delegate::ClearPreferences, delegate);
d->RegisterHandler("connectionReady", &Delegate::ConnectionReady, delegate);
d->RegisterHandler("registerExtensionsAPI", &Delegate::RegisterExtensionsAPI,
delegate);
return d;

View file

@ -43,6 +43,7 @@ class DevToolsEmbedderMessageDispatcher {
virtual void SetIsDocked(const DispatchCallback& callback,
bool is_docked) = 0;
virtual void OpenInNewTab(const std::string& url) = 0;
virtual void ShowItemInFolder(const std::string& file_system_path) = 0;
virtual void SaveToFile(const std::string& url,
const std::string& content,
bool save_as) = 0;
@ -64,10 +65,23 @@ class DevToolsEmbedderMessageDispatcher {
const std::string& file_system_path,
const std::string& query) = 0;
virtual void SetWhitelistedShortcuts(const std::string& message) = 0;
virtual void SetEyeDropperActive(bool active) = 0;
virtual void ShowCertificateViewer(const std::string& cert_chain) = 0;
virtual void ZoomIn() = 0;
virtual void ZoomOut() = 0;
virtual void ResetZoom() = 0;
virtual void SetDevicesDiscoveryConfig(
bool discover_usb_devices,
bool port_forwarding_enabled,
const std::string& port_forwarding_config,
bool network_discovery_enabled,
const std::string& network_discovery_config) = 0;
virtual void SetDevicesUpdatesEnabled(bool enabled) = 0;
virtual void PerformActionOnRemotePage(const std::string& page_id,
const std::string& action) = 0;
virtual void OpenRemotePage(const std::string& browser_id,
const std::string& url) = 0;
virtual void OpenNodeFrontend() = 0;
virtual void DispatchProtocolMessageFromDevToolsFrontend(
const std::string& message) = 0;
virtual void SendJsonRequest(const DispatchCallback& callback,
@ -78,6 +92,7 @@ class DevToolsEmbedderMessageDispatcher {
const std::string& value) = 0;
virtual void RemovePreference(const std::string& name) = 0;
virtual void ClearPreferences() = 0;
virtual void ConnectionReady() = 0;
virtual void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) = 0;
};

View file

@ -7,6 +7,7 @@
#include "brightray/browser/inspectable_web_contents_impl.h"
#include "atom/common/platform_util.h"
#include "base/guid.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
@ -47,7 +48,7 @@ const double kPresetZoomFactors[] = {0.25, 0.333, 0.5, 0.666, 0.75, 0.9,
2.5, 3.0, 4.0, 5.0};
const char kChromeUIDevToolsURL[] =
"chrome-devtools://devtools/bundled/inspector.html?"
"chrome-devtools://devtools/bundled/devtools_app.html?"
"remoteBase=%s&"
"can_dock=%s&"
"toolbarColor=rgba(223,223,223,1)&"
@ -485,6 +486,14 @@ void InspectableWebContentsImpl::SetIsDocked(const DispatchCallback& callback,
void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) {}
void InspectableWebContentsImpl::ShowItemInFolder(
const std::string& file_system_path) {
if (file_system_path.empty())
return;
base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path);
platform_util::ShowItemInFolder(path);
}
void InspectableWebContentsImpl::SaveToFile(const std::string& url,
const std::string& content,
bool save_as) {
@ -543,6 +552,10 @@ void InspectableWebContentsImpl::SearchInPath(
void InspectableWebContentsImpl::SetWhitelistedShortcuts(
const std::string& message) {}
void InspectableWebContentsImpl::SetEyeDropperActive(bool active) {}
void InspectableWebContentsImpl::ShowCertificateViewer(
const std::string& cert_chain) {}
void InspectableWebContentsImpl::ZoomIn() {
double new_level = GetNextZoomLevel(GetDevToolsZoomLevel(), false);
SetZoomLevelForWebContents(GetDevToolsWebContents(), new_level);
@ -560,8 +573,24 @@ void InspectableWebContentsImpl::ResetZoom() {
UpdateDevToolsZoomLevel(0.);
}
void InspectableWebContentsImpl::SetDevicesDiscoveryConfig(
bool discover_usb_devices,
bool port_forwarding_enabled,
const std::string& port_forwarding_config,
bool network_discovery_enabled,
const std::string& network_discovery_config) {}
void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) {}
void InspectableWebContentsImpl::PerformActionOnRemotePage(
const std::string& page_id,
const std::string& action) {}
void InspectableWebContentsImpl::OpenRemotePage(const std::string& browser_id,
const std::string& url) {}
void InspectableWebContentsImpl::OpenNodeFrontend() {}
void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend(
const std::string& message) {
// If the devtools wants to reload the page, hijack the message and handle it
@ -609,6 +638,8 @@ void InspectableWebContentsImpl::ClearPreferences() {
update.Get()->Clear();
}
void InspectableWebContentsImpl::ConnectionReady() {}
void InspectableWebContentsImpl::RegisterExtensionsAPI(
const std::string& origin,
const std::string& script) {

View file

@ -83,6 +83,7 @@ class InspectableWebContentsImpl
int stream_id) override;
void SetIsDocked(const DispatchCallback& callback, bool is_docked) override;
void OpenInNewTab(const std::string& url) override;
void ShowItemInFolder(const std::string& file_system_path) override;
void SaveToFile(const std::string& url,
const std::string& content,
bool save_as) override;
@ -100,10 +101,23 @@ class InspectableWebContentsImpl
const std::string& file_system_path,
const std::string& query) override;
void SetWhitelistedShortcuts(const std::string& message) override;
void SetEyeDropperActive(bool active) override;
void ShowCertificateViewer(const std::string& cert_chain) override;
void ZoomIn() override;
void ZoomOut() override;
void ResetZoom() override;
void SetDevicesDiscoveryConfig(
bool discover_usb_devices,
bool port_forwarding_enabled,
const std::string& port_forwarding_config,
bool network_discovery_enabled,
const std::string& network_discovery_config) override;
void SetDevicesUpdatesEnabled(bool enabled) override;
void PerformActionOnRemotePage(const std::string& page_id,
const std::string& action) override;
void OpenRemotePage(const std::string& browser_id,
const std::string& url) override;
void OpenNodeFrontend() override;
void DispatchProtocolMessageFromDevToolsFrontend(
const std::string& message) override;
void SendJsonRequest(const DispatchCallback& callback,
@ -114,6 +128,7 @@ class InspectableWebContentsImpl
const std::string& value) override;
void RemovePreference(const std::string& name) override;
void ClearPreferences() override;
void ConnectionReady() override;
void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) override;

View file

@ -2761,8 +2761,7 @@ describe('BrowserWindow module', () => {
})
})
// TODO(alexeykuzmin): [Ch66] Enable the tests.
xdescribe('for a valid extension', () => {
describe('for a valid extension', () => {
const extensionName = 'foo'
const removeExtension = () => {
@ -2803,7 +2802,8 @@ describe('BrowserWindow module', () => {
expect(this.message).to.have.own.property('tabId')
expect(this.message.tabId).to.equal(w.webContents.id)
})
it('has "i18nString" with proper contents', function () {
// TODO(zcbena): [Ch66] Enable the tests.
xit('has "i18nString" with proper contents', function () {
expect(this.message).to.have.own.property('i18nString')
expect(this.message.i18nString).to.equal('foo - bar (baz)')
})
@ -2849,8 +2849,7 @@ describe('BrowserWindow module', () => {
})
})
// TODO(alexeykuzmin): [Ch66] Times out. Fix it and enable.
xit('works when used with partitions', (done) => {
it('works when used with partitions', (done) => {
if (w != null) {
w.destroy()
}