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

Side by Side Diff: android_webview/native/aw_contents_io_thread_client_impl.cc

Issue 2737663004: Introduce a secondary map for enabling plznavigate (Closed)
Patch Set: address jam review Created 3 years, 9 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
« no previous file with comments | « android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "android_webview/native/aw_contents_io_thread_client_impl.h" 5 #include "android_webview/native/aw_contents_io_thread_client_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 JavaObjectWeakGlobalRef io_thread_client; 50 JavaObjectWeakGlobalRef io_thread_client;
51 51
52 IoThreadClientData(); 52 IoThreadClientData();
53 }; 53 };
54 54
55 IoThreadClientData::IoThreadClientData() : pending_association(false) {} 55 IoThreadClientData::IoThreadClientData() : pending_association(false) {}
56 56
57 typedef map<pair<int, int>, IoThreadClientData> 57 typedef map<pair<int, int>, IoThreadClientData>
58 RenderFrameHostToIoThreadClientType; 58 RenderFrameHostToIoThreadClientType;
59 59
60 // When browser side navigation is enabled, RenderFrameIDs do not have
61 // valid render process host and render frame ids for frame navigations.
62 // We need to identify these by using Frame Tree Node ids.
63 typedef map<int, IoThreadClientData> FrameTreeNodeToIoThreadClientType;
64
60 static pair<int, int> GetRenderFrameHostIdPair(RenderFrameHost* rfh) { 65 static pair<int, int> GetRenderFrameHostIdPair(RenderFrameHost* rfh) {
61 return pair<int, int>(rfh->GetProcess()->GetID(), rfh->GetRoutingID()); 66 return pair<int, int>(rfh->GetProcess()->GetID(), rfh->GetRoutingID());
62 } 67 }
63 68
64 // RfhToIoThreadClientMap ----------------------------------------------------- 69 // RfhToIoThreadClientMap -----------------------------------------------------
65 class RfhToIoThreadClientMap { 70 class RfhToIoThreadClientMap {
66 public: 71 public:
67 static RfhToIoThreadClientMap* GetInstance(); 72 static RfhToIoThreadClientMap* GetInstance();
68 void Set(pair<int, int> rfh_id, const IoThreadClientData& client); 73 void Set(pair<int, int> rfh_id, const IoThreadClientData& client);
69 bool Get(pair<int, int> rfh_id, IoThreadClientData* client); 74 bool Get(pair<int, int> rfh_id, IoThreadClientData* client);
70 void Erase(pair<int, int> rfh_id); 75 void Erase(pair<int, int> rfh_id);
71 76
77 void Set(int frame_tree_node_id, const IoThreadClientData& client);
78 bool Get(int frame_tree_node_id, IoThreadClientData* client);
79 void Erase(int frame_tree_node_id);
80
72 private: 81 private:
73 base::Lock map_lock_; 82 base::Lock map_lock_;
74 RenderFrameHostToIoThreadClientType rfh_to_io_thread_client_; 83 RenderFrameHostToIoThreadClientType rfh_to_io_thread_client_;
84 FrameTreeNodeToIoThreadClientType frame_tree_node_to_io_thread_client_;
75 }; 85 };
76 86
77 // static 87 // static
78 LazyInstance<RfhToIoThreadClientMap>::DestructorAtExit g_instance_ = 88 LazyInstance<RfhToIoThreadClientMap>::DestructorAtExit g_instance_ =
79 LAZY_INSTANCE_INITIALIZER; 89 LAZY_INSTANCE_INITIALIZER;
80 90
81 // static 91 // static
82 LazyInstance<JavaObjectWeakGlobalRef>::DestructorAtExit g_sw_instance_ = 92 LazyInstance<JavaObjectWeakGlobalRef>::DestructorAtExit g_sw_instance_ =
83 LAZY_INSTANCE_INITIALIZER; 93 LAZY_INSTANCE_INITIALIZER;
84 94
(...skipping 18 matching lines...) Expand all
103 113
104 *client = iterator->second; 114 *client = iterator->second;
105 return true; 115 return true;
106 } 116 }
107 117
108 void RfhToIoThreadClientMap::Erase(pair<int, int> rfh_id) { 118 void RfhToIoThreadClientMap::Erase(pair<int, int> rfh_id) {
109 base::AutoLock lock(map_lock_); 119 base::AutoLock lock(map_lock_);
110 rfh_to_io_thread_client_.erase(rfh_id); 120 rfh_to_io_thread_client_.erase(rfh_id);
111 } 121 }
112 122
123 void RfhToIoThreadClientMap::Set(int frame_tree_node_id,
124 const IoThreadClientData& client) {
125 base::AutoLock lock(map_lock_);
126 frame_tree_node_to_io_thread_client_[frame_tree_node_id] = client;
127 }
128
129 bool RfhToIoThreadClientMap::Get(int frame_tree_node_id,
130 IoThreadClientData* client) {
131 base::AutoLock lock(map_lock_);
132 FrameTreeNodeToIoThreadClientType::iterator iterator =
133 frame_tree_node_to_io_thread_client_.find(frame_tree_node_id);
134 if (iterator == frame_tree_node_to_io_thread_client_.end())
135 return false;
136
137 *client = iterator->second;
138 return true;
139 }
140
141 void RfhToIoThreadClientMap::Erase(int frame_tree_node_id) {
142 base::AutoLock lock(map_lock_);
143 frame_tree_node_to_io_thread_client_.erase(frame_tree_node_id);
144 }
145
113 // ClientMapEntryUpdater ------------------------------------------------------ 146 // ClientMapEntryUpdater ------------------------------------------------------
114 147
115 class ClientMapEntryUpdater : public content::WebContentsObserver { 148 class ClientMapEntryUpdater : public content::WebContentsObserver {
116 public: 149 public:
117 ClientMapEntryUpdater(JNIEnv* env, WebContents* web_contents, 150 ClientMapEntryUpdater(JNIEnv* env, WebContents* web_contents,
118 jobject jdelegate); 151 jobject jdelegate);
119 152
120 void RenderFrameCreated(RenderFrameHost* render_frame_host) override; 153 void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
121 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; 154 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
122 void WebContentsDestroyed() override; 155 void WebContentsDestroyed() override;
(...skipping 11 matching lines...) Expand all
134 DCHECK(jdelegate); 167 DCHECK(jdelegate);
135 168
136 if (web_contents->GetMainFrame()) 169 if (web_contents->GetMainFrame())
137 RenderFrameCreated(web_contents->GetMainFrame()); 170 RenderFrameCreated(web_contents->GetMainFrame());
138 } 171 }
139 172
140 void ClientMapEntryUpdater::RenderFrameCreated(RenderFrameHost* rfh) { 173 void ClientMapEntryUpdater::RenderFrameCreated(RenderFrameHost* rfh) {
141 IoThreadClientData client_data; 174 IoThreadClientData client_data;
142 client_data.io_thread_client = jdelegate_; 175 client_data.io_thread_client = jdelegate_;
143 client_data.pending_association = false; 176 client_data.pending_association = false;
144 RfhToIoThreadClientMap::GetInstance()->Set( 177 RfhToIoThreadClientMap::GetInstance()->Set(GetRenderFrameHostIdPair(rfh),
145 GetRenderFrameHostIdPair(rfh), client_data); 178 client_data);
179 RfhToIoThreadClientMap::GetInstance()->Set(rfh->GetFrameTreeNodeId(),
180 client_data);
146 } 181 }
147 182
148 void ClientMapEntryUpdater::RenderFrameDeleted(RenderFrameHost* rfh) { 183 void ClientMapEntryUpdater::RenderFrameDeleted(RenderFrameHost* rfh) {
149 RfhToIoThreadClientMap::GetInstance()->Erase(GetRenderFrameHostIdPair(rfh)); 184 RfhToIoThreadClientMap::GetInstance()->Erase(GetRenderFrameHostIdPair(rfh));
185 RfhToIoThreadClientMap::GetInstance()->Erase(rfh->GetFrameTreeNodeId());
150 } 186 }
151 187
152 void ClientMapEntryUpdater::WebContentsDestroyed() { 188 void ClientMapEntryUpdater::WebContentsDestroyed() {
153 delete this; 189 delete this;
154 } 190 }
155 191
156 } // namespace 192 } // namespace
157 193
158 // AwContentsIoThreadClientImpl ----------------------------------------------- 194 // AwContentsIoThreadClientImpl -----------------------------------------------
159 195
160 // static 196 // static
161 std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID( 197 std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID(
162 int render_process_id, 198 int render_process_id,
163 int render_frame_id) { 199 int render_frame_id) {
164 pair<int, int> rfh_id(render_process_id, render_frame_id); 200 pair<int, int> rfh_id(render_process_id, render_frame_id);
165 IoThreadClientData client_data; 201 IoThreadClientData client_data;
166 if (!RfhToIoThreadClientMap::GetInstance()->Get(rfh_id, &client_data)) 202 if (!RfhToIoThreadClientMap::GetInstance()->Get(rfh_id, &client_data))
167 return std::unique_ptr<AwContentsIoThreadClient>(); 203 return std::unique_ptr<AwContentsIoThreadClient>();
168 204
169 JNIEnv* env = AttachCurrentThread(); 205 JNIEnv* env = AttachCurrentThread();
170 ScopedJavaLocalRef<jobject> java_delegate = 206 ScopedJavaLocalRef<jobject> java_delegate =
171 client_data.io_thread_client.get(env); 207 client_data.io_thread_client.get(env);
172 DCHECK(!client_data.pending_association || java_delegate.is_null()); 208 DCHECK(!client_data.pending_association || java_delegate.is_null());
173 return std::unique_ptr<AwContentsIoThreadClient>( 209 return std::unique_ptr<AwContentsIoThreadClient>(
174 new AwContentsIoThreadClientImpl(client_data.pending_association, 210 new AwContentsIoThreadClientImpl(client_data.pending_association,
175 java_delegate)); 211 java_delegate));
176 } 212 }
177 213
214 std::unique_ptr<AwContentsIoThreadClient> AwContentsIoThreadClient::FromID(
215 int frame_tree_node_id) {
216 IoThreadClientData client_data;
217 if (!RfhToIoThreadClientMap::GetInstance()->Get(frame_tree_node_id,
218 &client_data))
219 return std::unique_ptr<AwContentsIoThreadClient>();
220
221 JNIEnv* env = AttachCurrentThread();
222 ScopedJavaLocalRef<jobject> java_delegate =
223 client_data.io_thread_client.get(env);
224 DCHECK(!client_data.pending_association || java_delegate.is_null());
225 return std::unique_ptr<AwContentsIoThreadClient>(
226 new AwContentsIoThreadClientImpl(client_data.pending_association,
227 java_delegate));
228 }
229
178 // static 230 // static
179 void AwContentsIoThreadClient::SubFrameCreated(int render_process_id, 231 void AwContentsIoThreadClient::SubFrameCreated(int render_process_id,
180 int parent_render_frame_id, 232 int parent_render_frame_id,
181 int child_render_frame_id) { 233 int child_render_frame_id) {
182 pair<int, int> parent_rfh_id(render_process_id, parent_render_frame_id); 234 pair<int, int> parent_rfh_id(render_process_id, parent_render_frame_id);
183 pair<int, int> child_rfh_id(render_process_id, child_render_frame_id); 235 pair<int, int> child_rfh_id(render_process_id, child_render_frame_id);
184 IoThreadClientData client_data; 236 IoThreadClientData client_data;
185 if (!RfhToIoThreadClientMap::GetInstance()->Get(parent_rfh_id, 237 if (!RfhToIoThreadClientMap::GetInstance()->Get(parent_rfh_id,
186 &client_data)) { 238 &client_data)) {
187 NOTREACHED(); 239 NOTREACHED();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 DCHECK_CURRENTLY_ON(BrowserThread::IO); 398 DCHECK_CURRENTLY_ON(BrowserThread::IO);
347 if (java_object_.is_null()) 399 if (java_object_.is_null())
348 return false; 400 return false;
349 401
350 JNIEnv* env = AttachCurrentThread(); 402 JNIEnv* env = AttachCurrentThread();
351 return Java_AwContentsIoThreadClient_shouldBlockNetworkLoads(env, 403 return Java_AwContentsIoThreadClient_shouldBlockNetworkLoads(env,
352 java_object_); 404 java_object_);
353 } 405 }
354 406
355 } // namespace android_webview 407 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698