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

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: Remove UI thread DCHECKs. 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 bool ExtensionApiFrameIdMap::RenderFrameIdKey::operator==( 58 bool ExtensionApiFrameIdMap::RenderFrameIdKey::operator==(
58 const RenderFrameIdKey& other) const { 59 const RenderFrameIdKey& other) const {
59 return render_process_id == other.render_process_id && 60 return render_process_id == other.render_process_id &&
60 frame_routing_id == other.frame_routing_id; 61 frame_routing_id == other.frame_routing_id;
61 } 62 }
62 63
63 ExtensionApiFrameIdMap::ExtensionApiFrameIdMap() {} 64 ExtensionApiFrameIdMap::ExtensionApiFrameIdMap() {}
64 65
65 ExtensionApiFrameIdMap::~ExtensionApiFrameIdMap() {} 66 ExtensionApiFrameIdMap::~ExtensionApiFrameIdMap() {}
66 67
68 // static
67 ExtensionApiFrameIdMap* ExtensionApiFrameIdMap::Get() { 69 ExtensionApiFrameIdMap* ExtensionApiFrameIdMap::Get() {
68 return g_map_instance.Pointer(); 70 return g_map_instance.Pointer();
69 } 71 }
70 72
73 // static
71 int ExtensionApiFrameIdMap::GetFrameId(content::RenderFrameHost* rfh) { 74 int ExtensionApiFrameIdMap::GetFrameId(content::RenderFrameHost* rfh) {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73
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
82 // static
83 int ExtensionApiFrameIdMap::GetFrameId(
84 content::NavigationHandle* navigation_handle) {
85 return navigation_handle->IsInMainFrame()
86 ? 0
87 : navigation_handle->GetFrameTreeNodeId();
88 }
89
90 // static
81 int ExtensionApiFrameIdMap::GetParentFrameId(content::RenderFrameHost* rfh) { 91 int ExtensionApiFrameIdMap::GetParentFrameId(content::RenderFrameHost* rfh) {
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83
84 return rfh ? GetFrameId(rfh->GetParent()) : kInvalidFrameId; 92 return rfh ? GetFrameId(rfh->GetParent()) : kInvalidFrameId;
85 } 93 }
86 94
95 // static
96 int ExtensionApiFrameIdMap::GetParentFrameId(
97 content::NavigationHandle* navigation_handle) {
98 if (navigation_handle->IsInMainFrame())
99 return -1;
100
101 if (navigation_handle->IsParentMainFrame())
102 return 0;
103
104 return navigation_handle->GetParentFrameTreeNodeId();
105 }
106
107 // static
87 content::RenderFrameHost* ExtensionApiFrameIdMap::GetRenderFrameHostById( 108 content::RenderFrameHost* ExtensionApiFrameIdMap::GetRenderFrameHostById(
88 content::WebContents* web_contents, 109 content::WebContents* web_contents,
89 int frame_id) { 110 int frame_id) {
90 // Although it is technically possible to map |frame_id| to a RenderFrameHost 111 // 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 112 // 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. 113 // frameIds are only guaranteed to be meaningful in combination with a tabId.
93 if (!web_contents) 114 if (!web_contents)
94 return nullptr; 115 return nullptr;
95 116
96 if (frame_id == kInvalidFrameId) 117 if (frame_id == kInvalidFrameId)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 257 }
237 258
238 void ExtensionApiFrameIdMap::RemoveFrameId(const RenderFrameIdKey& key) { 259 void ExtensionApiFrameIdMap::RemoveFrameId(const RenderFrameIdKey& key) {
239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
240 261
241 base::AutoLock lock(frame_id_map_lock_); 262 base::AutoLock lock(frame_id_map_lock_);
242 frame_id_map_.erase(key); 263 frame_id_map_.erase(key);
243 } 264 }
244 265
245 } // namespace extensions 266 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_api_frame_id_map.h ('k') | testing/buildbot/filters/isolate-extensions.browser_tests.filter » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698