diff options
-rw-r--r-- | chrome/browser/ui/webui/webui_webview_browsertest.cc | 18 | ||||
-rw-r--r-- | extensions/browser/web_ui_user_script_loader.cc | 16 | ||||
-rw-r--r-- | extensions/browser/web_ui_user_script_loader.h | 1 |
3 files changed, 30 insertions, 5 deletions
diff --git a/chrome/browser/ui/webui/webui_webview_browsertest.cc b/chrome/browser/ui/webui/webui_webview_browsertest.cc index 6c3ed9c..a8fcadc 100644 --- a/chrome/browser/ui/webui/webui_webview_browsertest.cc +++ b/chrome/browser/ui/webui/webui_webview_browsertest.cc @@ -4,6 +4,8 @@ #include "base/macros.h" #include "base/path_service.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/ui_test_utils.h" @@ -131,3 +133,19 @@ IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScriptWithCode) { "testAddContentScriptWithCode", new base::StringValue(GetTestUrl("empty.html").spec()))); } + +#if defined(OS_CHROMEOS) +// Right now we only have incognito WebUI on CrOS, but this should +// theoretically work for all platforms. +IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScriptIncognito) { + Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( + browser()->profile(), GetWebViewEnabledWebUIURL()); + + SetWebUIInstance( + incognito_browser->tab_strip_model()->GetActiveWebContents()->GetWebUI()); + + ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( + "testAddContentScript", + new base::StringValue(GetTestUrl("empty.html").spec()))); +} +#endif diff --git a/extensions/browser/web_ui_user_script_loader.cc b/extensions/browser/web_ui_user_script_loader.cc index 817834b..73b0c9a 100644 --- a/extensions/browser/web_ui_user_script_loader.cc +++ b/extensions/browser/web_ui_user_script_loader.cc @@ -8,6 +8,7 @@ #include "base/strings/string_util.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_process_host.h" #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h" namespace { @@ -80,10 +81,14 @@ void WebUIUserScriptLoader::LoadScripts( int render_process_id = iter->second.render_process_id; int render_view_id = iter->second.render_view_id; - CreateWebUIURLFetchers(&script.js_scripts(), render_process_id, - render_view_id); - CreateWebUIURLFetchers(&script.css_scripts(), render_process_id, - render_view_id); + content::BrowserContext* browser_context = + content::RenderProcessHost::FromID(render_process_id) + ->GetBrowserContext(); + + CreateWebUIURLFetchers(&script.js_scripts(), browser_context, + render_process_id, render_view_id); + CreateWebUIURLFetchers(&script.css_scripts(), browser_context, + render_process_id, render_view_id); script_render_info_map_.erase(script.id()); } @@ -99,6 +104,7 @@ void WebUIUserScriptLoader::LoadScripts( void WebUIUserScriptLoader::CreateWebUIURLFetchers( extensions::UserScript::FileList* script_files, + content::BrowserContext* browser_context, int render_process_id, int render_view_id) { for (extensions::UserScript::File& file : *script_files) { @@ -107,7 +113,7 @@ void WebUIUserScriptLoader::CreateWebUIURLFetchers( // loader is destroyed, all the fetchers will be destroyed. Therefore, // we are sure it is safe to use base::Unretained(this) here. scoped_ptr<WebUIURLFetcher> fetcher(new WebUIURLFetcher( - browser_context(), render_process_id, render_view_id, file.url(), + browser_context, render_process_id, render_view_id, file.url(), base::Bind(&WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete, base::Unretained(this), &file))); fetchers_.push_back(fetcher.release()); diff --git a/extensions/browser/web_ui_user_script_loader.h b/extensions/browser/web_ui_user_script_loader.h index 83c10c3..f74ef00 100644 --- a/extensions/browser/web_ui_user_script_loader.h +++ b/extensions/browser/web_ui_user_script_loader.h @@ -46,6 +46,7 @@ class WebUIUserScriptLoader : public extensions::UserScriptLoader { // Creates WebUiURLFetchers for the given |script_files|. void CreateWebUIURLFetchers(extensions::UserScript::FileList* script_files, + content::BrowserContext* browser_context, int render_process_id, int render_view_id); |