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

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

Issue 1670673003: Refactor the implementation of the webNavigation extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Bug-532666-NavigationHandleAPI
Patch Set: Reverting the workaround from https://codereview.chromium.org/1656613002. Remove tests from exclusi… Created 4 years, 10 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 "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_frame_host.h" 11 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/child_process_host.h" 14 #include "content/public/common/child_process_host.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 namespace { 18 namespace {
18 19
19 // The map is accessed on the IO and UI thread, so construct it once and never 20 // The map is accessed on the IO and UI thread, so construct it once and never
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 71
71 int ExtensionApiFrameIdMap::GetFrameId(content::RenderFrameHost* rfh) { 72 int ExtensionApiFrameIdMap::GetFrameId(content::RenderFrameHost* rfh) {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 73 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73 74
74 if (!rfh) 75 if (!rfh)
75 return kInvalidFrameId; 76 return kInvalidFrameId;
76 if (rfh->GetParent()) 77 if (rfh->GetParent())
77 return rfh->GetFrameTreeNodeId(); 78 return rfh->GetFrameTreeNodeId();
78 return 0; // Main frame. 79 return 0; // Main frame.
79 } 80 }
80 81
Devlin 2016/02/09 17:35:40 nit: add // static (if you could also do this for
nasko 2016/02/09 17:53:54 Done.
82 int ExtensionApiFrameIdMap::GetFrameId(
83 content::NavigationHandle* navigation_handle) {
84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Devlin 2016/02/09 17:35:40 Do these actually need to be done on the UI thread
nasko 2016/02/09 17:53:54 All the other Get* methods that access RFH also do
Devlin 2016/02/09 18:01:15 Let's remove it for all static methods, where by d
85
86 return navigation_handle->IsInMainFrame()
87 ? 0
88 : navigation_handle->GetFrameTreeNodeId();
89 }
90
81 int ExtensionApiFrameIdMap::GetParentFrameId(content::RenderFrameHost* rfh) { 91 int ExtensionApiFrameIdMap::GetParentFrameId(content::RenderFrameHost* rfh) {
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83 93
84 return rfh ? GetFrameId(rfh->GetParent()) : kInvalidFrameId; 94 return rfh ? GetFrameId(rfh->GetParent()) : kInvalidFrameId;
85 } 95 }
86 96
97 int ExtensionApiFrameIdMap::GetParentFrameId(
98 content::NavigationHandle* navigation_handle) {
99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
100
101 if (navigation_handle->IsInMainFrame())
102 return -1;
103
104 if (navigation_handle->IsParentMainFrame())
105 return 0;
106
107 return navigation_handle->GetParentFrameTreeNodeId();
108 }
109
87 content::RenderFrameHost* ExtensionApiFrameIdMap::GetRenderFrameHostById( 110 content::RenderFrameHost* ExtensionApiFrameIdMap::GetRenderFrameHostById(
88 content::WebContents* web_contents, 111 content::WebContents* web_contents,
89 int frame_id) { 112 int frame_id) {
90 // Although it is technically possible to map |frame_id| to a RenderFrameHost 113 // Although it is technically possible to map |frame_id| to a RenderFrameHost
91 // without WebContents, we choose to not do that because in the extension API 114 // without WebContents, we choose to not do that because in the extension API
92 // frameIds are only guaranteed to be meaningful in combination with a tabId. 115 // frameIds are only guaranteed to be meaningful in combination with a tabId.
93 if (!web_contents) 116 if (!web_contents)
94 return nullptr; 117 return nullptr;
95 118
96 if (frame_id == kInvalidFrameId) 119 if (frame_id == kInvalidFrameId)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 259 }
237 260
238 void ExtensionApiFrameIdMap::RemoveFrameId(const RenderFrameIdKey& key) { 261 void ExtensionApiFrameIdMap::RemoveFrameId(const RenderFrameIdKey& key) {
239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 262 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
240 263
241 base::AutoLock lock(frame_id_map_lock_); 264 base::AutoLock lock(frame_id_map_lock_);
242 frame_id_map_.erase(key); 265 frame_id_map_.erase(key);
243 } 266 }
244 267
245 } // namespace extensions 268 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698