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

Side by Side Diff: extensions/browser/extension_api_frame_id_map.cc

Issue 2856653004: Require a process ID when looking up RFHs by FrameTreeNode ID. (Closed)
Patch Set: Simplify ExtNavThrottle Created 3 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser/extension_api_frame_id_map.h" 5 #include "extensions/browser/extension_api_frame_id_map.h"
6 6
7 #include <tuple> 7 #include <tuple>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 // static 122 // static
123 int ExtensionApiFrameIdMap::GetParentFrameId( 123 int ExtensionApiFrameIdMap::GetParentFrameId(
124 content::NavigationHandle* navigation_handle) { 124 content::NavigationHandle* navigation_handle) {
125 if (navigation_handle->IsInMainFrame()) 125 if (navigation_handle->IsInMainFrame())
126 return kInvalidFrameId; 126 return kInvalidFrameId;
127 127
128 if (navigation_handle->IsParentMainFrame()) 128 if (navigation_handle->IsParentMainFrame())
129 return kTopFrameId; 129 return kTopFrameId;
130 130
131 return navigation_handle->GetParentFrameTreeNodeId(); 131 return navigation_handle->GetParentFrame()->GetFrameTreeNodeId();
132 } 132 }
133 133
134 // static 134 // static
135 content::RenderFrameHost* ExtensionApiFrameIdMap::GetRenderFrameHostById( 135 content::RenderFrameHost* ExtensionApiFrameIdMap::GetRenderFrameHostById(
136 content::WebContents* web_contents, 136 content::WebContents* web_contents,
137 int frame_id) { 137 int frame_id) {
138 // Although it is technically possible to map |frame_id| to a RenderFrameHost 138 // Although it is technically possible to map |frame_id| to a RenderFrameHost
139 // without WebContents, we choose to not do that because in the extension API 139 // without WebContents, we choose to not do that because in the extension API
140 // frameIds are only guaranteed to be meaningful in combination with a tabId. 140 // frameIds are only guaranteed to be meaningful in combination with a tabId.
141 if (!web_contents) 141 if (!web_contents)
142 return nullptr; 142 return nullptr;
143 143
144 if (frame_id == kInvalidFrameId) 144 if (frame_id == kInvalidFrameId)
145 return nullptr; 145 return nullptr;
146 146
147 if (frame_id == kTopFrameId) 147 if (frame_id == kTopFrameId)
148 return web_contents->GetMainFrame(); 148 return web_contents->GetMainFrame();
149 149
150 DCHECK_GE(frame_id, 1); 150 DCHECK_GE(frame_id, 1);
151 return web_contents->FindFrameByFrameTreeNodeId(frame_id); 151
152 // Unfortunately, extension APIs do not know which process to expect for a
153 // given frame ID, so we must use an unsafe API here that could return a
154 // different RenderFrameHost than the caller may have expected (e.g., one that
155 // changed after a cross-process navigation).
156 return web_contents->UnsafeFindFrameByFrameTreeNodeId(frame_id);
152 } 157 }
153 158
154 ExtensionApiFrameIdMap::FrameData ExtensionApiFrameIdMap::KeyToValue( 159 ExtensionApiFrameIdMap::FrameData ExtensionApiFrameIdMap::KeyToValue(
155 const RenderFrameIdKey& key) const { 160 const RenderFrameIdKey& key) const {
156 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( 161 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
157 key.render_process_id, key.frame_routing_id); 162 key.render_process_id, key.frame_routing_id);
158 int tab_id = -1; 163 int tab_id = -1;
159 int window_id = -1; 164 int window_id = -1;
160 if (helper_) 165 if (helper_)
161 helper_->GetTabAndWindowId(rfh, &tab_id, &window_id); 166 helper_->GetTabAndWindowId(rfh, &tab_id, &window_id);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 361 }
357 362
358 void ExtensionApiFrameIdMap::RemoveFrameData(const RenderFrameIdKey& key) { 363 void ExtensionApiFrameIdMap::RemoveFrameData(const RenderFrameIdKey& key) {
359 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 364 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
360 365
361 base::AutoLock lock(frame_data_map_lock_); 366 base::AutoLock lock(frame_data_map_lock_);
362 frame_data_map_.erase(key); 367 frame_data_map_.erase(key);
363 } 368 }
364 369
365 } // namespace extensions 370 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698