OLD | NEW |
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" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 const Extension* ScriptContextSet::GetExtensionFromFrameAndWorld( | 134 const Extension* ScriptContextSet::GetExtensionFromFrameAndWorld( |
135 const blink::WebLocalFrame* frame, | 135 const blink::WebLocalFrame* frame, |
136 int world_id, | 136 int world_id, |
137 bool use_effective_url) { | 137 bool use_effective_url) { |
138 std::string extension_id; | 138 std::string extension_id; |
139 if (world_id != 0) { | 139 if (world_id != 0) { |
140 // Isolated worlds (content script). | 140 // Isolated worlds (content script). |
141 extension_id = ScriptInjection::GetHostIdForIsolatedWorld(world_id); | 141 extension_id = ScriptInjection::GetHostIdForIsolatedWorld(world_id); |
142 } else { | 142 } else { |
143 // For looking up the extension associated with this frame, we either want | 143 // Extension pages (chrome-extension:// URLs). |
144 // to use the current url or possibly the data source url (which this frame | 144 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); |
145 // may be navigating to shortly), depending on the security origin of the | |
146 // frame. We don't always want to use the data source url because some | |
147 // frames (eg iframes and windows created via window.open) briefly contain | |
148 // an about:blank script context that is scriptable by their parent/opener | |
149 // before they finish navigating. | |
150 GURL frame_url(frame->document().url()); | |
151 GURL data_src_url = ScriptContext::GetDataSourceURLForFrame(frame); | |
152 if (frame_url.is_empty() && data_src_url.is_valid() && | |
153 frame->getSecurityOrigin().canAccess( | |
154 blink::WebSecurityOrigin::create(data_src_url))) { | |
155 frame_url = data_src_url; | |
156 } | |
157 | |
158 frame_url = ScriptContext::GetEffectiveDocumentURL(frame, frame_url, | 145 frame_url = ScriptContext::GetEffectiveDocumentURL(frame, frame_url, |
159 use_effective_url); | 146 use_effective_url); |
160 extension_id = | 147 extension_id = |
161 RendererExtensionRegistry::Get()->GetExtensionOrAppIDByURL(frame_url); | 148 RendererExtensionRegistry::Get()->GetExtensionOrAppIDByURL(frame_url); |
162 } | 149 } |
163 | 150 |
164 // There are conditions where despite a context being associated with an | 151 // There are conditions where despite a context being associated with an |
165 // extension, no extension actually gets found. Ignore "invalid" because CSP | 152 // extension, no extension actually gets found. Ignore "invalid" because CSP |
166 // blocks extension page loading by switching the extension ID to "invalid". | 153 // blocks extension page loading by switching the extension ID to "invalid". |
167 const Extension* extension = | 154 const Extension* extension = |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return Feature::WEB_PAGE_CONTEXT; | 216 return Feature::WEB_PAGE_CONTEXT; |
230 } | 217 } |
231 | 218 |
232 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, | 219 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, |
233 ScriptContext* context) { | 220 ScriptContext* context) { |
234 removed->insert(context); | 221 removed->insert(context); |
235 Remove(context); // Note: context deletion is deferred to the message loop. | 222 Remove(context); // Note: context deletion is deferred to the message loop. |
236 } | 223 } |
237 | 224 |
238 } // namespace extensions | 225 } // namespace extensions |
OLD | NEW |