OLD | NEW |
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 "android_webview/browser/aw_permission_manager.h" | 5 #include "android_webview/browser/aw_permission_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "android_webview/browser/aw_browser_permission_request_delegate.h" | 9 #include "android_webview/browser/aw_browser_permission_request_delegate.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "content/public/browser/permission_type.h" | 14 #include "content/public/browser/permission_type.h" |
| 15 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/render_view_host.h" | |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 | 18 |
19 using content::PermissionStatus; | 19 using content::PermissionStatus; |
20 using content::PermissionType; | 20 using content::PermissionType; |
21 | 21 |
22 namespace android_webview { | 22 namespace android_webview { |
23 | 23 |
24 class LastRequestResultCache { | 24 class LastRequestResultCache { |
25 public: | 25 public: |
26 LastRequestResultCache() : weak_factory_(this) {} | 26 LastRequestResultCache() : weak_factory_(this) {} |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 161 |
162 AwPermissionManager::AwPermissionManager() | 162 AwPermissionManager::AwPermissionManager() |
163 : content::PermissionManager(), result_cache_(new LastRequestResultCache) { | 163 : content::PermissionManager(), result_cache_(new LastRequestResultCache) { |
164 } | 164 } |
165 | 165 |
166 AwPermissionManager::~AwPermissionManager() { | 166 AwPermissionManager::~AwPermissionManager() { |
167 } | 167 } |
168 | 168 |
169 void AwPermissionManager::RequestPermission( | 169 void AwPermissionManager::RequestPermission( |
170 PermissionType permission, | 170 PermissionType permission, |
171 content::WebContents* web_contents, | 171 content::RenderFrameHost* render_frame_host, |
172 int request_id, | 172 int request_id, |
173 const GURL& origin, | 173 const GURL& origin, |
174 bool user_gesture, | 174 bool user_gesture, |
175 const base::Callback<void(PermissionStatus)>& callback) { | 175 const base::Callback<void(PermissionStatus)>& callback) { |
176 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 176 int render_process_id = render_frame_host->GetProcess()->GetID(); |
177 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 177 int render_frame_id = render_frame_host->GetRoutingID(); |
178 AwBrowserPermissionRequestDelegate* delegate = | 178 AwBrowserPermissionRequestDelegate* delegate = |
179 AwBrowserPermissionRequestDelegate::FromID(render_process_id, | 179 AwBrowserPermissionRequestDelegate::FromID(render_process_id, |
180 render_view_id); | 180 render_frame_id); |
181 if (!delegate) { | 181 if (!delegate) { |
182 DVLOG(0) << "Dropping permission request for " | 182 DVLOG(0) << "Dropping permission request for " |
183 << static_cast<int>(permission); | 183 << static_cast<int>(permission); |
184 callback.Run(content::PERMISSION_STATUS_DENIED); | 184 callback.Run(content::PERMISSION_STATUS_DENIED); |
185 return; | 185 return; |
186 } | 186 } |
187 | 187 |
188 const GURL& embedding_origin = | 188 const GURL& embedding_origin = |
189 web_contents->GetLastCommittedURL().GetOrigin(); | 189 content::WebContents::FromRenderFrameHost(render_frame_host) |
| 190 ->GetLastCommittedURL().GetOrigin(); |
190 | 191 |
191 switch (permission) { | 192 switch (permission) { |
192 case PermissionType::GEOLOCATION: | 193 case PermissionType::GEOLOCATION: |
193 delegate->RequestGeolocationPermission( | 194 delegate->RequestGeolocationPermission( |
194 origin, base::Bind(&CallbackPermisisonStatusWrapper, | 195 origin, base::Bind(&CallbackPermisisonStatusWrapper, |
195 result_cache_->GetWeakPtr(), callback, permission, | 196 result_cache_->GetWeakPtr(), callback, permission, |
196 origin, embedding_origin)); | 197 origin, embedding_origin)); |
197 break; | 198 break; |
198 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 199 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
199 delegate->RequestProtectedMediaIdentifierPermission( | 200 delegate->RequestProtectedMediaIdentifierPermission( |
(...skipping 10 matching lines...) Expand all Loading... |
210 break; | 211 break; |
211 case PermissionType::NUM: | 212 case PermissionType::NUM: |
212 NOTREACHED() << "PermissionType::NUM was not expected here."; | 213 NOTREACHED() << "PermissionType::NUM was not expected here."; |
213 callback.Run(content::PERMISSION_STATUS_DENIED); | 214 callback.Run(content::PERMISSION_STATUS_DENIED); |
214 break; | 215 break; |
215 } | 216 } |
216 } | 217 } |
217 | 218 |
218 void AwPermissionManager::CancelPermissionRequest( | 219 void AwPermissionManager::CancelPermissionRequest( |
219 PermissionType permission, | 220 PermissionType permission, |
220 content::WebContents* web_contents, | 221 content::RenderFrameHost* render_frame_host, |
221 int request_id, | 222 int request_id, |
222 const GURL& origin) { | 223 const GURL& origin) { |
223 // The caller is canceling (presumably) the most recent request. Assuming the | 224 // The caller is canceling (presumably) the most recent request. Assuming the |
224 // request did not complete, the user did not respond to the requset. | 225 // request did not complete, the user did not respond to the requset. |
225 // Thus, assume we do not know the result. | 226 // Thus, assume we do not know the result. |
226 const GURL& embedding_origin = | 227 const GURL& embedding_origin = |
227 web_contents->GetLastCommittedURL().GetOrigin(); | 228 content::WebContents::FromRenderFrameHost(render_frame_host) |
| 229 ->GetLastCommittedURL().GetOrigin(); |
228 result_cache_->ClearResult(permission, origin, embedding_origin); | 230 result_cache_->ClearResult(permission, origin, embedding_origin); |
229 | 231 |
230 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | 232 int render_process_id = render_frame_host->GetProcess()->GetID(); |
231 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 233 int render_frame_id = render_frame_host->GetRoutingID(); |
232 AwBrowserPermissionRequestDelegate* delegate = | 234 AwBrowserPermissionRequestDelegate* delegate = |
233 AwBrowserPermissionRequestDelegate::FromID(render_process_id, | 235 AwBrowserPermissionRequestDelegate::FromID(render_process_id, |
234 render_view_id); | 236 render_frame_id); |
235 if (!delegate) | 237 if (!delegate) |
236 return; | 238 return; |
237 | 239 |
238 switch (permission) { | 240 switch (permission) { |
239 case PermissionType::GEOLOCATION: | 241 case PermissionType::GEOLOCATION: |
240 delegate->CancelGeolocationPermissionRequests(origin); | 242 delegate->CancelGeolocationPermissionRequests(origin); |
241 break; | 243 break; |
242 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 244 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
243 delegate->CancelProtectedMediaIdentifierPermissionRequests(origin); | 245 delegate->CancelProtectedMediaIdentifierPermissionRequests(origin); |
244 break; | 246 break; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 const GURL& embedding_origin, | 287 const GURL& embedding_origin, |
286 const base::Callback<void(PermissionStatus)>& callback) { | 288 const base::Callback<void(PermissionStatus)>& callback) { |
287 return -1; | 289 return -1; |
288 } | 290 } |
289 | 291 |
290 void AwPermissionManager::UnsubscribePermissionStatusChange( | 292 void AwPermissionManager::UnsubscribePermissionStatusChange( |
291 int subscription_id) { | 293 int subscription_id) { |
292 } | 294 } |
293 | 295 |
294 } // namespace android_webview | 296 } // namespace android_webview |
OLD | NEW |