OLD | NEW |
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/strings/string_util.h" |
7 #include "content/public/renderer/render_frame.h" | 8 #include "content/public/renderer/render_frame.h" |
8 #include "extensions/common/api/messaging/message.h" | 9 #include "extensions/common/api/messaging/message.h" |
9 #include "extensions/common/constants.h" | 10 #include "extensions/common/constants.h" |
10 #include "extensions/common/extension_messages.h" | 11 #include "extensions/common/extension_messages.h" |
11 #include "extensions/common/manifest_handlers/background_info.h" | 12 #include "extensions/common/manifest_handlers/background_info.h" |
12 #include "extensions/renderer/console.h" | 13 #include "extensions/renderer/console.h" |
13 #include "extensions/renderer/content_watcher.h" | 14 #include "extensions/renderer/content_watcher.h" |
14 #include "extensions/renderer/dispatcher.h" | 15 #include "extensions/renderer/dispatcher.h" |
15 #include "extensions/renderer/messaging_bindings.h" | 16 #include "extensions/renderer/messaging_bindings.h" |
16 #include "extensions/renderer/script_context.h" | 17 #include "extensions/renderer/script_context.h" |
| 18 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 19 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
18 #include "third_party/WebKit/public/web/WebDocument.h" | 20 #include "third_party/WebKit/public/web/WebDocument.h" |
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
20 | 22 |
21 namespace extensions { | 23 namespace extensions { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 base::LazyInstance<std::set<const ExtensionFrameHelper*>> g_frame_helpers = | 27 base::LazyInstance<std::set<const ExtensionFrameHelper*>> g_frame_helpers = |
26 LAZY_INSTANCE_INITIALIZER; | 28 LAZY_INSTANCE_INITIALIZER; |
27 | 29 |
28 // Returns true if the render frame corresponding with |frame_helper| matches | 30 // Returns true if the render frame corresponding with |frame_helper| matches |
29 // the given criteria. | 31 // the given criteria. |
30 bool RenderFrameMatches(const ExtensionFrameHelper* frame_helper, | 32 bool RenderFrameMatches(const ExtensionFrameHelper* frame_helper, |
31 ViewType match_view_type, | 33 ViewType match_view_type, |
32 int match_window_id, | 34 int match_window_id, |
33 const std::string& match_extension_id) { | 35 const std::string& match_extension_id) { |
34 if (match_view_type != VIEW_TYPE_INVALID && | 36 if (match_view_type != VIEW_TYPE_INVALID && |
35 frame_helper->view_type() != match_view_type) | 37 frame_helper->view_type() != match_view_type) |
36 return false; | 38 return false; |
37 GURL url = frame_helper->render_frame()->GetWebFrame()->document().url(); | 39 |
38 if (!url.SchemeIs(kExtensionScheme)) | 40 // Not all frames have a valid ViewType, e.g. devtools, most GuestViews, and |
| 41 // unclassified detached WebContents. |
| 42 if (frame_helper->view_type() == VIEW_TYPE_INVALID) |
39 return false; | 43 return false; |
40 if (url.host() != match_extension_id) | 44 |
| 45 // This logic matches ExtensionWebContentsObserver::GetExtensionFromFrame. |
| 46 blink::WebSecurityOrigin origin = |
| 47 frame_helper->render_frame()->GetWebFrame()->securityOrigin(); |
| 48 if (origin.isUnique() || |
| 49 !base::EqualsASCII(base::StringPiece16(origin.protocol()), |
| 50 kExtensionScheme) || |
| 51 !base::EqualsASCII(base::StringPiece16(origin.host()), |
| 52 match_extension_id.c_str())) |
41 return false; | 53 return false; |
| 54 |
42 if (match_window_id != extension_misc::kUnknownWindowId && | 55 if (match_window_id != extension_misc::kUnknownWindowId && |
43 frame_helper->browser_window_id() != match_window_id) | 56 frame_helper->browser_window_id() != match_window_id) |
44 return false; | 57 return false; |
45 return true; | 58 return true; |
46 } | 59 } |
47 | 60 |
48 } // namespace | 61 } // namespace |
49 | 62 |
50 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, | 63 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, |
51 Dispatcher* extension_dispatcher) | 64 Dispatcher* extension_dispatcher) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 const std::string& module_name, | 228 const std::string& module_name, |
216 const std::string& function_name, | 229 const std::string& function_name, |
217 const base::ListValue& args, | 230 const base::ListValue& args, |
218 bool user_gesture) { | 231 bool user_gesture) { |
219 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, | 232 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, |
220 module_name, function_name, | 233 module_name, function_name, |
221 args, user_gesture); | 234 args, user_gesture); |
222 } | 235 } |
223 | 236 |
224 } // namespace extensions | 237 } // namespace extensions |
OLD | NEW |