fix: make devtools extensions load correctly (#17614)

This commit is contained in:
Samuel Attard 2019-03-30 17:36:13 -07:00 committed by GitHub
parent d597a0e8b0
commit 75442b794f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View file

@ -1649,13 +1649,24 @@ bool WebContents::SendIPCMessageWithSender(bool internal,
const std::string& channel, const std::string& channel,
const base::ListValue& args, const base::ListValue& args,
int32_t sender_id) { int32_t sender_id) {
std::vector<content::RenderFrameHost*> target_hosts;
if (!send_to_all) {
auto* frame_host = web_contents()->GetMainFrame(); auto* frame_host = web_contents()->GetMainFrame();
if (frame_host) { if (frame_host) {
return frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(), target_hosts.push_back(frame_host);
internal, send_to_all,
channel, args, sender_id));
} }
return false; } else {
target_hosts = web_contents()->GetAllFrames();
}
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, bool WebContents::SendIPCMessageToFrame(bool internal,

View file

@ -213,6 +213,7 @@ void AtomRenderFrameObserver::OnBrowserMessage(bool internal,
EmitIPCEvent(frame, internal, channel, args, sender_id); EmitIPCEvent(frame, internal, channel, args, sender_id);
// Also send the message to all sub-frames. // Also send the message to all sub-frames.
// TODO(MarshallOfSound): Completely move this logic to the main process
if (send_to_all) { if (send_to_all) {
for (blink::WebFrame* child = frame->FirstChild(); child; for (blink::WebFrame* child = frame->FirstChild(); child;
child = child->NextSibling()) child = child->NextSibling())

View file

@ -397,7 +397,7 @@ const loadDevToolsExtensions = function (win, manifests) {
extensionInfoArray.forEach((extension) => { extensionInfoArray.forEach((extension) => {
win.devToolsWebContents._grantOriginAccess(extension.startPage) 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) { app.on('web-contents-created', function (event, webContents) {

View file

@ -122,7 +122,7 @@ export function injectTo (extensionId: string, context: any) {
[targetExtensionId, connectInfo] = args [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) 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.i18n = require('@electron/internal/renderer/extensions/i18n').setup(extensionId)
chrome.webNavigation = require('@electron/internal/renderer/extensions/web-navigation').setup() 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 () {}
}
} }