Skip to content

Commit 2b7d2db

Browse files
committed
Add Hook to control render process selection of devtools page iframe in webview guest
Ref nwjs#6004
1 parent 83386a3 commit 2b7d2db

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/browser/nw_extensions_browser_hooks.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
3131
#include "extensions/common/manifest_constants.h"
3232
#include "extensions/common/manifest_handlers/webview_info.h"
33+
#include "extensions/common/manifest_url_handlers.h"
3334

3435
#if defined(OS_WIN)
3536
#define _USE_MATH_DEFINES
@@ -204,10 +205,25 @@ bool RphGuestFilterURLHook(RenderProcessHost* rph, const GURL* url) {
204205
typedef bool (*RphGuestFilterURLHookFn)(content::RenderProcessHost* rph, const GURL* url);
205206
CONTENT_EXPORT extern RphGuestFilterURLHookFn gRphGuestFilterURLHook;
206207

208+
bool GuestSwapProcessHook(content::BrowserContext* browser_context, const GURL& url) {
209+
if (!url.SchemeIs("chrome-extension"))
210+
return false;
211+
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context);
212+
std::string extension_id = url.host();
213+
const Extension* extension = registry->enabled_extensions().GetByID(extension_id);
214+
if (extension && !extensions::ManifestURL::Get(extension, "devtools_page").is_empty())
215+
return true;
216+
return false;
217+
}
218+
219+
typedef bool(*GuestSwapProcessHookFn)(content::BrowserContext*, const GURL& url);
220+
CONTENT_EXPORT extern GuestSwapProcessHookFn gGuestSwapProcessHook;
221+
207222
void LoadNWAppAsExtensionHook(base::DictionaryValue* manifest,
208223
const base::FilePath& extension_path,
209224
std::string* error) {
210225
gRphGuestFilterURLHook = RphGuestFilterURLHook;
226+
gGuestSwapProcessHook = GuestSwapProcessHook;
211227
if (!manifest)
212228
return;
213229

0 commit comments

Comments
 (0)