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

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

Issue 2873503002: NOT YET READY: Improve granularity of window namespaces in Blink.
Patch Set: Rebasing... Created 3 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extension_frame_helper.h" 5 #include "extensions/renderer/extension_frame_helper.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/timer/elapsed_timer.h" 9 #include "base/timer/elapsed_timer.h"
10 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
11 #include "extensions/common/api/messaging/message.h" 11 #include "extensions/common/api/messaging/message.h"
12 #include "extensions/common/api/messaging/port_id.h" 12 #include "extensions/common/api/messaging/port_id.h"
13 #include "extensions/common/constants.h" 13 #include "extensions/common/constants.h"
14 #include "extensions/common/extension_messages.h" 14 #include "extensions/common/extension_messages.h"
15 #include "extensions/common/manifest_handlers/background_info.h" 15 #include "extensions/common/manifest_handlers/background_info.h"
16 #include "extensions/renderer/console.h" 16 #include "extensions/renderer/console.h"
17 #include "extensions/renderer/content_watcher.h" 17 #include "extensions/renderer/content_watcher.h"
18 #include "extensions/renderer/dispatcher.h" 18 #include "extensions/renderer/dispatcher.h"
19 #include "extensions/renderer/messaging_bindings.h" 19 #include "extensions/renderer/messaging_bindings.h"
20 #include "extensions/renderer/renderer_extension_registry.h"
20 #include "extensions/renderer/script_context.h" 21 #include "extensions/renderer/script_context.h"
21 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 22 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
22 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 23 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
23 #include "third_party/WebKit/public/web/WebDocument.h" 24 #include "third_party/WebKit/public/web/WebDocument.h"
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" 25 #include "third_party/WebKit/public/web/WebLocalFrame.h"
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 namespace { 29 namespace {
29 30
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 blink::WebLocalFrame* web_frame = helper->render_frame()->GetWebFrame(); 134 blink::WebLocalFrame* web_frame = helper->render_frame()->GetWebFrame();
134 // Check if this is the top frame. 135 // Check if this is the top frame.
135 if (web_frame->Top() == web_frame) 136 if (web_frame->Top() == web_frame)
136 return helper->render_frame(); 137 return helper->render_frame();
137 } 138 }
138 } 139 }
139 return nullptr; 140 return nullptr;
140 } 141 }
141 142
142 // static 143 // static
144 content::RenderFrame* ExtensionFrameHelper::FindFrame(
145 content::RenderFrame* relative_to_frame,
146 const std::string& name) {
147 // Only pierce browsing instance boundaries if |relative_to_frame| is an
148 // extension.
149 GURL effective_url = ScriptContext::GetEffectiveDocumentURL(
150 relative_to_frame->GetWebFrame(),
151 relative_to_frame->GetWebFrame()->GetDocument().Url(), true);
152 const Extension* extension =
153 extensions::RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(
154 effective_url);
155 if (!extension)
156 return nullptr;
157
158 // Try to match all same-origin frames in this process.
159 for (const ExtensionFrameHelper* helper : g_frame_helpers.Get()) {
160 if (!relative_to_frame->GetWebFrame()->GetSecurityOrigin().CanAccess(
161 helper->render_frame()->GetWebFrame()->GetSecurityOrigin()))
162 continue;
163
164 if (helper->render_frame()->GetWebFrame()->AssignedName().Utf8() == name)
165 return helper->render_frame();
166 }
167
168 return nullptr;
169 }
170
171 // static
143 bool ExtensionFrameHelper::IsContextForEventPage(const ScriptContext* context) { 172 bool ExtensionFrameHelper::IsContextForEventPage(const ScriptContext* context) {
144 content::RenderFrame* render_frame = context->GetRenderFrame(); 173 content::RenderFrame* render_frame = context->GetRenderFrame();
145 return context->extension() && render_frame && 174 return context->extension() && render_frame &&
146 BackgroundInfo::HasLazyBackgroundPage(context->extension()) && 175 BackgroundInfo::HasLazyBackgroundPage(context->extension()) &&
147 ExtensionFrameHelper::Get(render_frame)->view_type() == 176 ExtensionFrameHelper::Get(render_frame)->view_type() ==
148 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; 177 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
149 } 178 }
150 179
151 void ExtensionFrameHelper::DidCreateDocumentElement() { 180 void ExtensionFrameHelper::DidCreateDocumentElement() {
152 did_create_current_document_element_ = true; 181 did_create_current_document_element_ = true;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 const base::ListValue& args) { 358 const base::ListValue& args) {
330 extension_dispatcher_->InvokeModuleSystemMethod( 359 extension_dispatcher_->InvokeModuleSystemMethod(
331 render_frame(), extension_id, module_name, function_name, args); 360 render_frame(), extension_id, module_name, function_name, args);
332 } 361 }
333 362
334 void ExtensionFrameHelper::OnDestruct() { 363 void ExtensionFrameHelper::OnDestruct() {
335 delete this; 364 delete this;
336 } 365 }
337 366
338 } // namespace extensions 367 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/extension_frame_helper.h ('k') | third_party/WebKit/Source/core/exported/WebFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698