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

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

Issue 2105033003: tabId support to chrome.extensions.getViews() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor followup to patch 5 Created 4 years, 5 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/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "content/public/renderer/render_frame.h" 8 #include "content/public/renderer/render_frame.h"
9 #include "extensions/common/api/messaging/message.h" 9 #include "extensions/common/api/messaging/message.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
(...skipping 14 matching lines...) Expand all
25 namespace { 25 namespace {
26 26
27 base::LazyInstance<std::set<const ExtensionFrameHelper*>> g_frame_helpers = 27 base::LazyInstance<std::set<const ExtensionFrameHelper*>> g_frame_helpers =
28 LAZY_INSTANCE_INITIALIZER; 28 LAZY_INSTANCE_INITIALIZER;
29 29
30 // Returns true if the render frame corresponding with |frame_helper| matches 30 // Returns true if the render frame corresponding with |frame_helper| matches
31 // the given criteria. 31 // the given criteria.
32 bool RenderFrameMatches(const ExtensionFrameHelper* frame_helper, 32 bool RenderFrameMatches(const ExtensionFrameHelper* frame_helper,
33 ViewType match_view_type, 33 ViewType match_view_type,
34 int match_window_id, 34 int match_window_id,
35 int match_tab_id,
35 const std::string& match_extension_id) { 36 const std::string& match_extension_id) {
36 if (match_view_type != VIEW_TYPE_INVALID && 37 if (match_view_type != VIEW_TYPE_INVALID &&
37 frame_helper->view_type() != match_view_type) 38 frame_helper->view_type() != match_view_type)
38 return false; 39 return false;
39 40
40 // Not all frames have a valid ViewType, e.g. devtools, most GuestViews, and 41 // Not all frames have a valid ViewType, e.g. devtools, most GuestViews, and
41 // unclassified detached WebContents. 42 // unclassified detached WebContents.
42 if (frame_helper->view_type() == VIEW_TYPE_INVALID) 43 if (frame_helper->view_type() == VIEW_TYPE_INVALID)
43 return false; 44 return false;
44 45
45 // This logic matches ExtensionWebContentsObserver::GetExtensionFromFrame. 46 // This logic matches ExtensionWebContentsObserver::GetExtensionFromFrame.
46 blink::WebSecurityOrigin origin = 47 blink::WebSecurityOrigin origin =
47 frame_helper->render_frame()->GetWebFrame()->getSecurityOrigin(); 48 frame_helper->render_frame()->GetWebFrame()->getSecurityOrigin();
48 if (origin.isUnique() || 49 if (origin.isUnique() ||
49 !base::EqualsASCII(base::StringPiece16(origin.protocol()), 50 !base::EqualsASCII(base::StringPiece16(origin.protocol()),
50 kExtensionScheme) || 51 kExtensionScheme) ||
51 !base::EqualsASCII(base::StringPiece16(origin.host()), 52 !base::EqualsASCII(base::StringPiece16(origin.host()),
52 match_extension_id.c_str())) 53 match_extension_id.c_str()))
53 return false; 54 return false;
54 55
55 if (match_window_id != extension_misc::kUnknownWindowId && 56 if (match_window_id != extension_misc::kUnknownWindowId &&
56 frame_helper->browser_window_id() != match_window_id) 57 frame_helper->browser_window_id() != match_window_id)
57 return false; 58 return false;
59
60 if (match_tab_id != extension_misc::kUnknownTabId &&
61 frame_helper->tab_id() != match_tab_id)
62 return false;
63
58 return true; 64 return true;
59 } 65 }
60 66
61 // Runs every callback in |callbacks_to_be_run_and_cleared| while |frame_helper| 67 // Runs every callback in |callbacks_to_be_run_and_cleared| while |frame_helper|
62 // is valid, and clears |callbacks_to_be_run_and_cleared|. 68 // is valid, and clears |callbacks_to_be_run_and_cleared|.
63 void RunCallbacksWhileFrameIsValid( 69 void RunCallbacksWhileFrameIsValid(
64 base::WeakPtr<ExtensionFrameHelper> frame_helper, 70 base::WeakPtr<ExtensionFrameHelper> frame_helper,
65 std::vector<base::Closure>* callbacks_to_be_run_and_cleared) { 71 std::vector<base::Closure>* callbacks_to_be_run_and_cleared) {
66 // The JavaScript code can cause re-entrancy. To avoid a deadlock, don't run 72 // The JavaScript code can cause re-entrancy. To avoid a deadlock, don't run
67 // callbacks that are added during the iteration. 73 // callbacks that are added during the iteration.
(...skipping 22 matching lines...) Expand all
90 } 96 }
91 97
92 ExtensionFrameHelper::~ExtensionFrameHelper() { 98 ExtensionFrameHelper::~ExtensionFrameHelper() {
93 g_frame_helpers.Get().erase(this); 99 g_frame_helpers.Get().erase(this);
94 } 100 }
95 101
96 // static 102 // static
97 std::vector<content::RenderFrame*> ExtensionFrameHelper::GetExtensionFrames( 103 std::vector<content::RenderFrame*> ExtensionFrameHelper::GetExtensionFrames(
98 const std::string& extension_id, 104 const std::string& extension_id,
99 int browser_window_id, 105 int browser_window_id,
106 int tab_id,
100 ViewType view_type) { 107 ViewType view_type) {
101 std::vector<content::RenderFrame*> render_frames; 108 std::vector<content::RenderFrame*> render_frames;
102 for (const ExtensionFrameHelper* helper : g_frame_helpers.Get()) { 109 for (const ExtensionFrameHelper* helper : g_frame_helpers.Get()) {
103 if (RenderFrameMatches(helper, view_type, browser_window_id, extension_id)) 110 if (RenderFrameMatches(helper, view_type, browser_window_id, tab_id,
111 extension_id))
104 render_frames.push_back(helper->render_frame()); 112 render_frames.push_back(helper->render_frame());
105 } 113 }
106 return render_frames; 114 return render_frames;
107 } 115 }
108 116
109 // static 117 // static
110 content::RenderFrame* ExtensionFrameHelper::GetBackgroundPageFrame( 118 content::RenderFrame* ExtensionFrameHelper::GetBackgroundPageFrame(
111 const std::string& extension_id) { 119 const std::string& extension_id) {
112 for (const ExtensionFrameHelper* helper : g_frame_helpers.Get()) { 120 for (const ExtensionFrameHelper* helper : g_frame_helpers.Get()) {
113 if (RenderFrameMatches(helper, VIEW_TYPE_EXTENSION_BACKGROUND_PAGE, 121 if (RenderFrameMatches(helper, VIEW_TYPE_EXTENSION_BACKGROUND_PAGE,
114 extension_misc::kUnknownWindowId, extension_id)) { 122 extension_misc::kUnknownWindowId,
123 extension_misc::kUnknownTabId, extension_id)) {
115 blink::WebLocalFrame* web_frame = helper->render_frame()->GetWebFrame(); 124 blink::WebLocalFrame* web_frame = helper->render_frame()->GetWebFrame();
116 // Check if this is the top frame. 125 // Check if this is the top frame.
117 if (web_frame->top() == web_frame) 126 if (web_frame->top() == web_frame)
118 return helper->render_frame(); 127 return helper->render_frame();
119 } 128 }
120 } 129 }
121 return nullptr; 130 return nullptr;
122 } 131 }
123 132
124 // static 133 // static
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, 289 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id,
281 module_name, function_name, 290 module_name, function_name,
282 args, user_gesture); 291 args, user_gesture);
283 } 292 }
284 293
285 void ExtensionFrameHelper::OnDestruct() { 294 void ExtensionFrameHelper::OnDestruct() {
286 delete this; 295 delete this;
287 } 296 }
288 297
289 } // namespace extensions 298 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/extension_frame_helper.h ('k') | extensions/renderer/resources/app_window_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698