Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: extensions/browser/web_ui_user_script_loader.cc

Issue 1062963006: Make WebUI webview content script work with incognito. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webui_api_4
Patch Set: Comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/web_ui_user_script_loader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/web_ui_user_script_loader.h" 5 #include "extensions/browser/web_ui_user_script_loader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "content/public/browser/browser_context.h" 9 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/render_process_host.h"
11 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h" 12 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h"
12 13
13 namespace { 14 namespace {
14 15
15 void SerializeOnFileThread( 16 void SerializeOnFileThread(
16 scoped_ptr<extensions::UserScriptList> user_scripts, 17 scoped_ptr<extensions::UserScriptList> user_scripts,
17 extensions::UserScriptLoader::LoadScriptsCallback callback) { 18 extensions::UserScriptLoader::LoadScriptsCallback callback) {
18 scoped_ptr<base::SharedMemory> memory = 19 scoped_ptr<base::SharedMemory> memory =
19 extensions::UserScriptLoader::Serialize(*user_scripts); 20 extensions::UserScriptLoader::Serialize(*user_scripts);
20 content::BrowserThread::PostTask( 21 content::BrowserThread::PostTask(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 for (extensions::UserScript& script : *user_scripts_cache_) { 75 for (extensions::UserScript& script : *user_scripts_cache_) {
75 if (added_script_ids.count(script.id()) == 0) 76 if (added_script_ids.count(script.id()) == 0)
76 continue; 77 continue;
77 78
78 auto iter = script_render_info_map_.find(script.id()); 79 auto iter = script_render_info_map_.find(script.id());
79 DCHECK(iter != script_render_info_map_.end()); 80 DCHECK(iter != script_render_info_map_.end());
80 int render_process_id = iter->second.render_process_id; 81 int render_process_id = iter->second.render_process_id;
81 int render_view_id = iter->second.render_view_id; 82 int render_view_id = iter->second.render_view_id;
82 83
83 CreateWebUIURLFetchers(&script.js_scripts(), render_process_id, 84 content::BrowserContext* browser_context =
84 render_view_id); 85 content::RenderProcessHost::FromID(render_process_id)
85 CreateWebUIURLFetchers(&script.css_scripts(), render_process_id, 86 ->GetBrowserContext();
86 render_view_id); 87
88 CreateWebUIURLFetchers(&script.js_scripts(), browser_context,
89 render_process_id, render_view_id);
90 CreateWebUIURLFetchers(&script.css_scripts(), browser_context,
91 render_process_id, render_view_id);
87 92
88 script_render_info_map_.erase(script.id()); 93 script_render_info_map_.erase(script.id());
89 } 94 }
90 95
91 // If no fetch is needed, call OnWebUIURLFetchComplete directly. 96 // If no fetch is needed, call OnWebUIURLFetchComplete directly.
92 if (fetchers_.empty()) { 97 if (fetchers_.empty()) {
93 OnWebUIURLFetchComplete(); 98 OnWebUIURLFetchComplete();
94 return; 99 return;
95 } 100 }
96 for (auto fetcher : fetchers_) 101 for (auto fetcher : fetchers_)
97 fetcher->Start(); 102 fetcher->Start();
98 } 103 }
99 104
100 void WebUIUserScriptLoader::CreateWebUIURLFetchers( 105 void WebUIUserScriptLoader::CreateWebUIURLFetchers(
101 extensions::UserScript::FileList* script_files, 106 extensions::UserScript::FileList* script_files,
107 content::BrowserContext* browser_context,
102 int render_process_id, 108 int render_process_id,
103 int render_view_id) { 109 int render_view_id) {
104 for (extensions::UserScript::File& file : *script_files) { 110 for (extensions::UserScript::File& file : *script_files) {
105 if (file.GetContent().empty()) { 111 if (file.GetContent().empty()) {
106 // The WebUIUserScriptLoader owns these WebUIURLFetchers. Once the 112 // The WebUIUserScriptLoader owns these WebUIURLFetchers. Once the
107 // loader is destroyed, all the fetchers will be destroyed. Therefore, 113 // loader is destroyed, all the fetchers will be destroyed. Therefore,
108 // we are sure it is safe to use base::Unretained(this) here. 114 // we are sure it is safe to use base::Unretained(this) here.
109 scoped_ptr<WebUIURLFetcher> fetcher(new WebUIURLFetcher( 115 scoped_ptr<WebUIURLFetcher> fetcher(new WebUIURLFetcher(
110 browser_context(), render_process_id, render_view_id, file.url(), 116 browser_context, render_process_id, render_view_id, file.url(),
111 base::Bind(&WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete, 117 base::Bind(&WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete,
112 base::Unretained(this), &file))); 118 base::Unretained(this), &file)));
113 fetchers_.push_back(fetcher.release()); 119 fetchers_.push_back(fetcher.release());
114 } 120 }
115 } 121 }
116 } 122 }
117 123
118 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete( 124 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete(
119 extensions::UserScript::File* script_file, 125 extensions::UserScript::File* script_file,
120 bool success, 126 bool success,
(...skipping 15 matching lines...) Expand all
136 } 142 }
137 } 143 }
138 144
139 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { 145 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() {
140 content::BrowserThread::PostTask( 146 content::BrowserThread::PostTask(
141 content::BrowserThread::FILE, FROM_HERE, 147 content::BrowserThread::FILE, FROM_HERE,
142 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), 148 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_),
143 scripts_loaded_callback_)); 149 scripts_loaded_callback_));
144 scripts_loaded_callback_.Reset(); 150 scripts_loaded_callback_.Reset();
145 } 151 }
OLDNEW
« no previous file with comments | « extensions/browser/web_ui_user_script_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698