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

Side by Side Diff: extensions/renderer/user_script_set.cc

Issue 1293673002: Create thread-safe RendererExtensionRegistry from ExtensionSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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/renderer/user_script_set.h ('k') | extensions/renderer/user_script_set_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer/user_script_set.h" 5 #include "extensions/renderer/user_script_set.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "content/public/common/url_constants.h" 8 #include "content/public/common/url_constants.h"
9 #include "content/public/renderer/render_frame.h" 9 #include "content/public/renderer/render_frame.h"
10 #include "content/public/renderer/render_thread.h" 10 #include "content/public/renderer/render_thread.h"
11 #include "extensions/common/extension.h" 11 #include "extensions/common/extension.h"
12 #include "extensions/common/extension_set.h"
13 #include "extensions/common/extensions_client.h" 12 #include "extensions/common/extensions_client.h"
14 #include "extensions/common/permissions/permissions_data.h" 13 #include "extensions/common/permissions/permissions_data.h"
15 #include "extensions/renderer/extension_injection_host.h" 14 #include "extensions/renderer/extension_injection_host.h"
16 #include "extensions/renderer/extensions_renderer_client.h" 15 #include "extensions/renderer/extensions_renderer_client.h"
17 #include "extensions/renderer/injection_host.h" 16 #include "extensions/renderer/injection_host.h"
17 #include "extensions/renderer/renderer_extension_registry.h"
18 #include "extensions/renderer/script_context.h" 18 #include "extensions/renderer/script_context.h"
19 #include "extensions/renderer/script_injection.h" 19 #include "extensions/renderer/script_injection.h"
20 #include "extensions/renderer/user_script_injector.h" 20 #include "extensions/renderer/user_script_injector.h"
21 #include "extensions/renderer/web_ui_injection_host.h" 21 #include "extensions/renderer/web_ui_injection_host.h"
22 #include "third_party/WebKit/public/web/WebDocument.h" 22 #include "third_party/WebKit/public/web/WebDocument.h"
23 #include "third_party/WebKit/public/web/WebLocalFrame.h" 23 #include "third_party/WebKit/public/web/WebLocalFrame.h"
24 #include "url/gurl.h" 24 #include "url/gurl.h"
25 25
26 namespace extensions { 26 namespace extensions {
27 27
28 namespace { 28 namespace {
29 29
30 GURL GetDocumentUrlForFrame(blink::WebLocalFrame* frame) { 30 GURL GetDocumentUrlForFrame(blink::WebLocalFrame* frame) {
31 GURL data_source_url = ScriptContext::GetDataSourceURLForFrame(frame); 31 GURL data_source_url = ScriptContext::GetDataSourceURLForFrame(frame);
32 if (!data_source_url.is_empty() && frame->isViewSourceModeEnabled()) { 32 if (!data_source_url.is_empty() && frame->isViewSourceModeEnabled()) {
33 data_source_url = GURL(content::kViewSourceScheme + std::string(":") + 33 data_source_url = GURL(content::kViewSourceScheme + std::string(":") +
34 data_source_url.spec()); 34 data_source_url.spec());
35 } 35 }
36 36
37 return data_source_url; 37 return data_source_url;
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 UserScriptSet::UserScriptSet(const ExtensionSet* extensions) 42 UserScriptSet::UserScriptSet() {}
43 : extensions_(extensions) {
44 }
45 43
46 UserScriptSet::~UserScriptSet() { 44 UserScriptSet::~UserScriptSet() {
47 } 45 }
48 46
49 void UserScriptSet::AddObserver(Observer* observer) { 47 void UserScriptSet::AddObserver(Observer* observer) {
50 observers_.AddObserver(observer); 48 observers_.AddObserver(observer);
51 } 49 }
52 50
53 void UserScriptSet::RemoveObserver(Observer* observer) { 51 void UserScriptSet::RemoveObserver(Observer* observer) {
54 observers_.RemoveObserver(observer); 52 observers_.RemoveObserver(observer);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 const char* body = NULL; 131 const char* body = NULL;
134 int body_length = 0; 132 int body_length = 0;
135 CHECK(iter.ReadData(&body, &body_length)); 133 CHECK(iter.ReadData(&body, &body_length));
136 script->css_scripts()[j].set_external_content( 134 script->css_scripts()[j].set_external_content(
137 base::StringPiece(body, body_length)); 135 base::StringPiece(body, body_length));
138 } 136 }
139 137
140 if (only_inject_incognito && !script->is_incognito_enabled()) 138 if (only_inject_incognito && !script->is_incognito_enabled())
141 continue; // This script shouldn't run in an incognito tab. 139 continue; // This script shouldn't run in an incognito tab.
142 140
143 const Extension* extension = extensions_->GetByID(script->extension_id()); 141 const Extension* extension =
142 RendererExtensionRegistry::Get()->GetByID(script->extension_id());
144 if (whitelisted_only && 143 if (whitelisted_only &&
145 (!extension || 144 (!extension ||
146 !PermissionsData::CanExecuteScriptEverywhere(extension))) { 145 !PermissionsData::CanExecuteScriptEverywhere(extension))) {
147 continue; 146 continue;
148 } 147 }
149 148
150 scripts_.push_back(script.Pass()); 149 scripts_.push_back(script.Pass());
151 } 150 }
152 151
153 FOR_EACH_OBSERVER(Observer, 152 FOR_EACH_OBSERVER(Observer,
(...skipping 27 matching lines...) Expand all
181 int tab_id, 180 int tab_id,
182 UserScript::RunLocation run_location, 181 UserScript::RunLocation run_location,
183 const GURL& document_url, 182 const GURL& document_url,
184 bool is_declarative) { 183 bool is_declarative) {
185 scoped_ptr<ScriptInjection> injection; 184 scoped_ptr<ScriptInjection> injection;
186 scoped_ptr<const InjectionHost> injection_host; 185 scoped_ptr<const InjectionHost> injection_host;
187 blink::WebLocalFrame* web_frame = render_frame->GetWebFrame(); 186 blink::WebLocalFrame* web_frame = render_frame->GetWebFrame();
188 187
189 const HostID& host_id = script->host_id(); 188 const HostID& host_id = script->host_id();
190 if (host_id.type() == HostID::EXTENSIONS) { 189 if (host_id.type() == HostID::EXTENSIONS) {
191 injection_host = ExtensionInjectionHost::Create(host_id.id(), extensions_); 190 injection_host = ExtensionInjectionHost::Create(host_id.id());
192 if (!injection_host) 191 if (!injection_host)
193 return injection.Pass(); 192 return injection.Pass();
194 } else { 193 } else {
195 DCHECK_EQ(host_id.type(), HostID::WEBUI); 194 DCHECK_EQ(host_id.type(), HostID::WEBUI);
196 injection_host.reset(new WebUIInjectionHost(host_id)); 195 injection_host.reset(new WebUIInjectionHost(host_id));
197 } 196 }
198 197
199 if (web_frame->parent() && !script->match_all_frames()) 198 if (web_frame->parent() && !script->match_all_frames())
200 return injection.Pass(); // Only match subframes if the script declared it. 199 return injection.Pass(); // Only match subframes if the script declared it.
201 200
(...skipping 24 matching lines...) Expand all
226 injector.Pass(), 225 injector.Pass(),
227 render_frame, 226 render_frame,
228 injection_host.Pass(), 227 injection_host.Pass(),
229 run_location, 228 run_location,
230 tab_id)); 229 tab_id));
231 } 230 }
232 return injection.Pass(); 231 return injection.Pass();
233 } 232 }
234 233
235 } // namespace extensions 234 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/user_script_set.h ('k') | extensions/renderer/user_script_set_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698