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

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: Add comment. 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
« content/public/browser/web_contents.h ('K') | « content/public/browser/web_contents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698