OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/guest_view/web_view/web_view_permission_helper.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
6 | 6 |
| 7 #include "chrome/browser/content_settings/permission_request_id.h" |
7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
8 #include "chrome/browser/geolocation/geolocation_permission_context.h" | 9 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
9 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | 10 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
10 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 11 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
11 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | 12 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
12 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 13 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
13 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
16 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
| 20 #include "content/public/browser/web_contents.h" |
19 | 21 |
20 using content::BrowserPluginGuestDelegate; | 22 using content::BrowserPluginGuestDelegate; |
21 using content::RenderViewHost; | 23 using content::RenderViewHost; |
22 | 24 |
23 namespace { | 25 namespace { |
24 static std::string PermissionTypeToString(WebViewPermissionType type) { | 26 static std::string PermissionTypeToString(WebViewPermissionType type) { |
25 switch (type) { | 27 switch (type) { |
26 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 28 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
27 return webview::kPermissionTypeDownload; | 29 return webview::kPermissionTypeDownload; |
28 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | 30 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 const std::string& user_input) { | 382 const std::string& user_input) { |
381 // The <webview> embedder has allowed the permission. We now need to make sure | 383 // The <webview> embedder has allowed the permission. We now need to make sure |
382 // that the embedder has geolocation permission. | 384 // that the embedder has geolocation permission. |
383 RemoveBridgeID(bridge_id); | 385 RemoveBridgeID(bridge_id); |
384 | 386 |
385 if (!allow || !web_view_guest_->attached()) { | 387 if (!allow || !web_view_guest_->attached()) { |
386 callback.Run(false); | 388 callback.Run(false); |
387 return; | 389 return; |
388 } | 390 } |
389 | 391 |
| 392 content::WebContents* web_contents = web_view_guest_->embedder_web_contents(); |
| 393 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 394 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
| 395 |
| 396 const PermissionRequestID request_id( |
| 397 render_process_id, |
| 398 render_view_id, |
| 399 // The geolocation permission request here is not initiated |
| 400 // through WebGeolocationPermissionRequest. We are only interested |
| 401 // in the fact whether the embedder/app has geolocation |
| 402 // permission. Therefore we use an invalid |bridge_id|. |
| 403 -1, |
| 404 GURL()); |
390 Profile* profile = Profile::FromBrowserContext( | 405 Profile* profile = Profile::FromBrowserContext( |
391 web_view_guest_->browser_context()); | 406 web_view_guest_->browser_context()); |
392 GeolocationPermissionContextFactory::GetForProfile(profile)-> | 407 GeolocationPermissionContextFactory::GetForProfile(profile)-> |
393 RequestGeolocationPermission( | 408 RequestPermission( |
394 web_view_guest_->embedder_web_contents(), | 409 web_contents, |
395 // The geolocation permission request here is not initiated | 410 request_id, |
396 // through WebGeolocationPermissionRequest. We are only interested | 411 web_view_guest_->embedder_web_contents() |
397 // in the fact whether the embedder/app has geolocation | 412 ->GetLastCommittedURL().GetOrigin(), |
398 // permission. Therefore we use an invalid |bridge_id|. | |
399 -1, | |
400 web_view_guest_->embedder_web_contents()->GetLastCommittedURL(), | |
401 user_gesture, | 413 user_gesture, |
402 callback, | 414 callback); |
403 NULL); | |
404 } | 415 } |
405 | 416 |
406 void WebViewPermissionHelper::CancelGeolocationPermissionRequest( | 417 void WebViewPermissionHelper::CancelGeolocationPermissionRequest( |
407 int bridge_id) { | 418 int bridge_id) { |
408 int request_id = RemoveBridgeID(bridge_id); | 419 int request_id = RemoveBridgeID(bridge_id); |
409 RequestMap::iterator request_itr = | 420 RequestMap::iterator request_itr = |
410 pending_permission_requests_.find(request_id); | 421 pending_permission_requests_.find(request_id); |
411 | 422 |
412 if (request_itr == pending_permission_requests_.end()) | 423 if (request_itr == pending_permission_requests_.end()) |
413 return; | 424 return; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 const PermissionResponseCallback& callback, | 601 const PermissionResponseCallback& callback, |
591 WebViewPermissionType permission_type, | 602 WebViewPermissionType permission_type, |
592 bool allowed_by_default) | 603 bool allowed_by_default) |
593 : callback(callback), | 604 : callback(callback), |
594 permission_type(permission_type), | 605 permission_type(permission_type), |
595 allowed_by_default(allowed_by_default) { | 606 allowed_by_default(allowed_by_default) { |
596 } | 607 } |
597 | 608 |
598 WebViewPermissionHelper::PermissionResponseInfo::~PermissionResponseInfo() { | 609 WebViewPermissionHelper::PermissionResponseInfo::~PermissionResponseInfo() { |
599 } | 610 } |
OLD | NEW |