From 75442b794fba206b2e693a0e0587d4f8f8ce8e86 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Sat, 30 Mar 2019 17:36:13 -0700 Subject: [PATCH] fix: make devtools extensions load correctly (#17614) --- atom/browser/api/atom_api_web_contents.cc | 23 +++++++++++++++------ atom/renderer/atom_render_frame_observer.cc | 1 + lib/browser/chrome-extension.js | 2 +- lib/renderer/chrome-api.ts | 8 ++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 05149fe886..1d47c1971b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1649,13 +1649,24 @@ bool WebContents::SendIPCMessageWithSender(bool internal, const std::string& channel, const base::ListValue& args, int32_t sender_id) { - auto* frame_host = web_contents()->GetMainFrame(); - if (frame_host) { - return frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(), - internal, send_to_all, - channel, args, sender_id)); + std::vector target_hosts; + if (!send_to_all) { + auto* frame_host = web_contents()->GetMainFrame(); + if (frame_host) { + target_hosts.push_back(frame_host); + } + } else { + target_hosts = web_contents()->GetAllFrames(); } - return false; + + bool handled = false; + for (auto* frame_host : target_hosts) { + handled = frame_host->Send( + new AtomFrameMsg_Message(frame_host->GetRoutingID(), internal, + false, channel, args, sender_id)) || + handled; + } + return handled; } bool WebContents::SendIPCMessageToFrame(bool internal, diff --git a/atom/renderer/atom_render_frame_observer.cc b/atom/renderer/atom_render_frame_observer.cc index 19f527d73b..af340620fd 100644 --- a/atom/renderer/atom_render_frame_observer.cc +++ b/atom/renderer/atom_render_frame_observer.cc @@ -213,6 +213,7 @@ void AtomRenderFrameObserver::OnBrowserMessage(bool internal, EmitIPCEvent(frame, internal, channel, args, sender_id); // Also send the message to all sub-frames. + // TODO(MarshallOfSound): Completely move this logic to the main process if (send_to_all) { for (blink::WebFrame* child = frame->FirstChild(); child; child = child->NextSibling()) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 531004f7c7..2afbfccef0 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -397,7 +397,7 @@ const loadDevToolsExtensions = function (win, manifests) { extensionInfoArray.forEach((extension) => { win.devToolsWebContents._grantOriginAccess(extension.startPage) }) - win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`) + win.devToolsWebContents.executeJavaScript(`InspectorFrontendAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`) } app.on('web-contents-created', function (event, webContents) { diff --git a/lib/renderer/chrome-api.ts b/lib/renderer/chrome-api.ts index 59c5a20818..eff62384ce 100644 --- a/lib/renderer/chrome-api.ts +++ b/lib/renderer/chrome-api.ts @@ -122,7 +122,7 @@ export function injectTo (extensionId: string, context: any) { [targetExtensionId, connectInfo] = args } - const { tabId, portId } = ipcRendererInternal.sendSync('CHROME_RUNTIME_CONNECT', targetExtensionId, connectInfo) + const { tabId, portId } = ipcRendererUtils.invokeSync('CHROME_RUNTIME_CONNECT', targetExtensionId, connectInfo) return new Port(tabId, portId, extensionId, connectInfo.name) }, @@ -210,4 +210,10 @@ export function injectTo (extensionId: string, context: any) { chrome.i18n = require('@electron/internal/renderer/extensions/i18n').setup(extensionId) chrome.webNavigation = require('@electron/internal/renderer/extensions/web-navigation').setup() + + // Electron has no concept of a browserAction but we should stub these APIs for compatibility + chrome.browserAction = { + setIcon () {}, + setPopup () {} + } }