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

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

Issue 2628053003: Remove extension group from DOMWrapperWorld. (Closed)
Patch Set: Fix GCCallbackTest Created 3 years, 11 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
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/script_context_set.h" 5 #include "extensions/renderer/script_context_set.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
11 #include "content/public/renderer/render_frame.h" 11 #include "content/public/renderer/render_frame.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/renderer/extension_groups.h" 13 #include "extensions/renderer/extensions_renderer_client.h"
14 #include "extensions/renderer/script_context.h" 14 #include "extensions/renderer/script_context.h"
15 #include "extensions/renderer/script_injection.h" 15 #include "extensions/renderer/script_injection.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "v8/include/v8.h" 18 #include "v8/include/v8.h"
19 19
20 namespace extensions { 20 namespace extensions {
21 21
22 namespace { 22 namespace {
23 // There is only ever one instance of the ScriptContextSet. 23 // There is only ever one instance of the ScriptContextSet.
24 ScriptContextSet* g_context_set = nullptr; 24 ScriptContextSet* g_context_set = nullptr;
25 } 25 }
26 26
27 ScriptContextSet::ScriptContextSet(ExtensionIdSet* active_extension_ids) 27 ScriptContextSet::ScriptContextSet(ExtensionIdSet* active_extension_ids)
28 : active_extension_ids_(active_extension_ids) { 28 : active_extension_ids_(active_extension_ids) {
29 DCHECK(!g_context_set); 29 DCHECK(!g_context_set);
30 g_context_set = this; 30 g_context_set = this;
31 } 31 }
32 32
33 ScriptContextSet::~ScriptContextSet() { 33 ScriptContextSet::~ScriptContextSet() {
34 g_context_set = nullptr; 34 g_context_set = nullptr;
35 } 35 }
36 36
37 ScriptContext* ScriptContextSet::Register( 37 ScriptContext* ScriptContextSet::Register(
38 blink::WebLocalFrame* frame, 38 blink::WebLocalFrame* frame,
39 const v8::Local<v8::Context>& v8_context, 39 const v8::Local<v8::Context>& v8_context,
40 int extension_group,
41 int world_id) { 40 int world_id) {
42 const Extension* extension = 41 const Extension* extension =
43 GetExtensionFromFrameAndWorld(frame, world_id, false); 42 GetExtensionFromFrameAndWorld(frame, world_id, false);
44 const Extension* effective_extension = 43 const Extension* effective_extension =
45 GetExtensionFromFrameAndWorld(frame, world_id, true); 44 GetExtensionFromFrameAndWorld(frame, world_id, true);
46 45
47 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); 46 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
48 Feature::Context context_type = 47 Feature::Context context_type = ClassifyJavaScriptContext(
49 ClassifyJavaScriptContext(extension, extension_group, frame_url, 48 extension, world_id, frame_url, frame->document().getSecurityOrigin());
50 frame->document().getSecurityOrigin());
51 Feature::Context effective_context_type = ClassifyJavaScriptContext( 49 Feature::Context effective_context_type = ClassifyJavaScriptContext(
52 effective_extension, extension_group, 50 effective_extension, world_id,
53 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true), 51 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true),
54 frame->document().getSecurityOrigin()); 52 frame->document().getSecurityOrigin());
55 53
56 ScriptContext* context = 54 ScriptContext* context =
57 new ScriptContext(v8_context, frame, extension, context_type, 55 new ScriptContext(v8_context, frame, extension, context_type,
58 effective_extension, effective_context_type); 56 effective_extension, effective_context_type);
59 contexts_.insert(context); // takes ownership 57 contexts_.insert(context); // takes ownership
60 return context; 58 return context;
61 } 59 }
62 60
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 const Extension* extension = 162 const Extension* extension =
165 RendererExtensionRegistry::Get()->GetByID(extension_id); 163 RendererExtensionRegistry::Get()->GetByID(extension_id);
166 if (!extension && !extension_id.empty() && extension_id != "invalid") { 164 if (!extension && !extension_id.empty() && extension_id != "invalid") {
167 // TODO(kalman): Do something here? 165 // TODO(kalman): Do something here?
168 } 166 }
169 return extension; 167 return extension;
170 } 168 }
171 169
172 Feature::Context ScriptContextSet::ClassifyJavaScriptContext( 170 Feature::Context ScriptContextSet::ClassifyJavaScriptContext(
173 const Extension* extension, 171 const Extension* extension,
174 int extension_group, 172 int world_id,
175 const GURL& url, 173 const GURL& url,
176 const blink::WebSecurityOrigin& origin) { 174 const blink::WebSecurityOrigin& origin) {
177 // WARNING: This logic must match ProcessMap::GetContextType, as much as 175 // WARNING: This logic must match ProcessMap::GetContextType, as much as
178 // possible. 176 // possible.
179 177
180 DCHECK_GE(extension_group, 0); 178 // Worlds not within this range are not for content scripts, so ignore them.
181 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { 179 // TODO(devlin): Isolated worlds with a non-zero id could belong to
180 // chrome-internal pieces, like dom distiller and translate. Do we need any
181 // bindings (even those for basic web pages) for those?
182 if (world_id >= ExtensionsRendererClient::Get()->GetLowestIsolatedWorldId()) {
182 return extension ? // TODO(kalman): when does this happen? 183 return extension ? // TODO(kalman): when does this happen?
183 Feature::CONTENT_SCRIPT_CONTEXT 184 Feature::CONTENT_SCRIPT_CONTEXT
184 : Feature::UNSPECIFIED_CONTEXT; 185 : Feature::UNSPECIFIED_CONTEXT;
185 } 186 }
186 187
187 // We have an explicit check for sandboxed pages before checking whether the 188 // We have an explicit check for sandboxed pages before checking whether the
188 // extension is active in this process because: 189 // extension is active in this process because:
189 // 1. Sandboxed pages run in the same process as regular extension pages, so 190 // 1. Sandboxed pages run in the same process as regular extension pages, so
190 // the extension is considered active. 191 // the extension is considered active.
191 // 2. ScriptContext creation (which triggers bindings injection) happens 192 // 2. ScriptContext creation (which triggers bindings injection) happens
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return Feature::WEB_PAGE_CONTEXT; 227 return Feature::WEB_PAGE_CONTEXT;
227 } 228 }
228 229
229 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, 230 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed,
230 ScriptContext* context) { 231 ScriptContext* context) {
231 removed->insert(context); 232 removed->insert(context);
232 Remove(context); // Note: context deletion is deferred to the message loop. 233 Remove(context); // Note: context deletion is deferred to the message loop.
233 } 234 }
234 235
235 } // namespace extensions 236 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context_set.h ('k') | extensions/renderer/script_context_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698