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

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

Issue 2628053003: Remove extension group from DOMWrapperWorld. (Closed)
Patch Set: 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"
14 #include "extensions/renderer/script_context.h" 13 #include "extensions/renderer/script_context.h"
15 #include "extensions/renderer/script_injection.h" 14 #include "extensions/renderer/script_injection.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 15 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 16 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "v8/include/v8.h" 17 #include "v8/include/v8.h"
19 18
20 namespace extensions { 19 namespace extensions {
21 20
22 namespace { 21 namespace {
23 // There is only ever one instance of the ScriptContextSet. 22 // There is only ever one instance of the ScriptContextSet.
24 ScriptContextSet* g_context_set = nullptr; 23 ScriptContextSet* g_context_set = nullptr;
25 } 24 }
26 25
27 ScriptContextSet::ScriptContextSet(ExtensionIdSet* active_extension_ids) 26 ScriptContextSet::ScriptContextSet(ExtensionIdSet* active_extension_ids)
28 : active_extension_ids_(active_extension_ids) { 27 : active_extension_ids_(active_extension_ids) {
29 DCHECK(!g_context_set); 28 DCHECK(!g_context_set);
30 g_context_set = this; 29 g_context_set = this;
31 } 30 }
32 31
33 ScriptContextSet::~ScriptContextSet() { 32 ScriptContextSet::~ScriptContextSet() {
34 g_context_set = nullptr; 33 g_context_set = nullptr;
35 } 34 }
36 35
37 ScriptContext* ScriptContextSet::Register( 36 ScriptContext* ScriptContextSet::Register(
38 blink::WebLocalFrame* frame, 37 blink::WebLocalFrame* frame,
39 const v8::Local<v8::Context>& v8_context, 38 const v8::Local<v8::Context>& v8_context,
40 int extension_group,
41 int world_id) { 39 int world_id) {
42 const Extension* extension = 40 const Extension* extension =
43 GetExtensionFromFrameAndWorld(frame, world_id, false); 41 GetExtensionFromFrameAndWorld(frame, world_id, false);
44 const Extension* effective_extension = 42 const Extension* effective_extension =
45 GetExtensionFromFrameAndWorld(frame, world_id, true); 43 GetExtensionFromFrameAndWorld(frame, world_id, true);
46 44
47 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); 45 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
48 Feature::Context context_type = 46 Feature::Context context_type = ClassifyJavaScriptContext(
49 ClassifyJavaScriptContext(extension, extension_group, frame_url, 47 extension, world_id, frame_url, frame->document().getSecurityOrigin());
50 frame->document().getSecurityOrigin());
51 Feature::Context effective_context_type = ClassifyJavaScriptContext( 48 Feature::Context effective_context_type = ClassifyJavaScriptContext(
52 effective_extension, extension_group, 49 effective_extension, world_id,
53 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true), 50 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true),
54 frame->document().getSecurityOrigin()); 51 frame->document().getSecurityOrigin());
55 52
56 ScriptContext* context = 53 ScriptContext* context =
57 new ScriptContext(v8_context, frame, extension, context_type, 54 new ScriptContext(v8_context, frame, extension, context_type,
58 effective_extension, effective_context_type); 55 effective_extension, effective_context_type);
59 contexts_.insert(context); // takes ownership 56 contexts_.insert(context); // takes ownership
60 return context; 57 return context;
61 } 58 }
62 59
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 const Extension* extension = 161 const Extension* extension =
165 RendererExtensionRegistry::Get()->GetByID(extension_id); 162 RendererExtensionRegistry::Get()->GetByID(extension_id);
166 if (!extension && !extension_id.empty() && extension_id != "invalid") { 163 if (!extension && !extension_id.empty() && extension_id != "invalid") {
167 // TODO(kalman): Do something here? 164 // TODO(kalman): Do something here?
168 } 165 }
169 return extension; 166 return extension;
170 } 167 }
171 168
172 Feature::Context ScriptContextSet::ClassifyJavaScriptContext( 169 Feature::Context ScriptContextSet::ClassifyJavaScriptContext(
173 const Extension* extension, 170 const Extension* extension,
174 int extension_group, 171 int world_id,
175 const GURL& url, 172 const GURL& url,
176 const blink::WebSecurityOrigin& origin) { 173 const blink::WebSecurityOrigin& origin) {
177 // WARNING: This logic must match ProcessMap::GetContextType, as much as 174 // WARNING: This logic must match ProcessMap::GetContextType, as much as
178 // possible. 175 // possible.
179 176
180 DCHECK_GE(extension_group, 0); 177 // The main world ID is 0. Non-zero world IDs should indicate worlds created
181 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) { 178 // for content script.
dcheng 2017/01/12 01:39:52 This is the only real functional change in this CL
Devlin 2017/01/12 16:30:12 This isn't quite correct - instead, it should be:
dcheng 2017/01/12 18:35:12 Looking at this, I'm not actually sure what the ri
Devlin 2017/01/12 21:31:39 So, a couple of things here. Unspecified contexts
dcheng 2017/01/12 21:40:41 It could, but I'm not sure the burden of fixing th
Devlin 2017/01/12 22:02:09 There is a behavior change from the current behavi
179 if (world_id != 0) {
182 return extension ? // TODO(kalman): when does this happen? 180 return extension ? // TODO(kalman): when does this happen?
183 Feature::CONTENT_SCRIPT_CONTEXT 181 Feature::CONTENT_SCRIPT_CONTEXT
184 : Feature::UNSPECIFIED_CONTEXT; 182 : Feature::UNSPECIFIED_CONTEXT;
185 } 183 }
186 184
187 // We have an explicit check for sandboxed pages before checking whether the 185 // We have an explicit check for sandboxed pages before checking whether the
188 // extension is active in this process because: 186 // extension is active in this process because:
189 // 1. Sandboxed pages run in the same process as regular extension pages, so 187 // 1. Sandboxed pages run in the same process as regular extension pages, so
190 // the extension is considered active. 188 // the extension is considered active.
191 // 2. ScriptContext creation (which triggers bindings injection) happens 189 // 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; 224 return Feature::WEB_PAGE_CONTEXT;
227 } 225 }
228 226
229 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, 227 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed,
230 ScriptContext* context) { 228 ScriptContext* context) {
231 removed->insert(context); 229 removed->insert(context);
232 Remove(context); // Note: context deletion is deferred to the message loop. 230 Remove(context); // Note: context deletion is deferred to the message loop.
233 } 231 }
234 232
235 } // namespace extensions 233 } // 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