| 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/geolocation/geolocation_permission_context_extensions.h
" | 5 #include "chrome/browser/geolocation/geolocation_permission_context_extensions.h
" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 | 8 |
| 9 #if defined(ENABLE_EXTENSIONS) | 9 #if defined(ENABLE_EXTENSIONS) |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "components/content_settings/core/common/permission_request_id.h" | 11 #include "components/content_settings/core/common/permission_request_id.h" |
| 12 #include "extensions/browser/extension_registry.h" | 12 #include "extensions/browser/extension_registry.h" |
| 13 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 13 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 14 #include "extensions/browser/process_map.h" | 14 #include "extensions/browser/process_map.h" |
| 15 #include "extensions/browser/suggest_permission_util.h" | 15 #include "extensions/browser/suggest_permission_util.h" |
| 16 #include "extensions/browser/view_type_utils.h" | 16 #include "extensions/browser/view_type_utils.h" |
| 17 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 18 | 18 |
| 19 using extensions::APIPermission; | 19 using extensions::APIPermission; |
| 20 using extensions::ExtensionRegistry; | 20 using extensions::ExtensionRegistry; |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 namespace { |
| 24 |
| 25 void CallbackContentSettingWrapper( |
| 26 const base::Callback<void(ContentSetting)>& callback, |
| 27 bool allowed) { |
| 28 callback.Run(allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 29 } |
| 30 |
| 31 } // anonymous namespace |
| 32 |
| 23 GeolocationPermissionContextExtensions:: | 33 GeolocationPermissionContextExtensions:: |
| 24 GeolocationPermissionContextExtensions(Profile* profile) | 34 GeolocationPermissionContextExtensions(Profile* profile) |
| 25 : profile_(profile) { | 35 : profile_(profile) { |
| 26 } | 36 } |
| 27 | 37 |
| 28 GeolocationPermissionContextExtensions:: | 38 GeolocationPermissionContextExtensions:: |
| 29 ~GeolocationPermissionContextExtensions() { | 39 ~GeolocationPermissionContextExtensions() { |
| 30 } | 40 } |
| 31 | 41 |
| 32 bool GeolocationPermissionContextExtensions::RequestPermission( | 42 bool GeolocationPermissionContextExtensions::RequestPermission( |
| 33 content::WebContents* web_contents, | 43 content::WebContents* web_contents, |
| 34 const PermissionRequestID& request_id, | 44 const PermissionRequestID& request_id, |
| 35 int bridge_id, | 45 int bridge_id, |
| 36 const GURL& requesting_frame, | 46 const GURL& requesting_frame, |
| 37 bool user_gesture, | 47 bool user_gesture, |
| 38 base::Callback<void(bool)> callback, | 48 const base::Callback<void(ContentSetting)>& callback, |
| 39 bool* permission_set, | 49 bool* permission_set, |
| 40 bool* new_permission) { | 50 bool* new_permission) { |
| 41 #if defined(ENABLE_EXTENSIONS) | 51 #if defined(ENABLE_EXTENSIONS) |
| 42 GURL requesting_frame_origin = requesting_frame.GetOrigin(); | 52 GURL requesting_frame_origin = requesting_frame.GetOrigin(); |
| 43 | 53 |
| 44 extensions::WebViewPermissionHelper* web_view_permission_helper = | 54 extensions::WebViewPermissionHelper* web_view_permission_helper = |
| 45 extensions::WebViewPermissionHelper::FromWebContents(web_contents); | 55 extensions::WebViewPermissionHelper::FromWebContents(web_contents); |
| 46 if (web_view_permission_helper) { | 56 if (web_view_permission_helper) { |
| 47 web_view_permission_helper->RequestGeolocationPermission( | 57 web_view_permission_helper->RequestGeolocationPermission( |
| 48 bridge_id, requesting_frame, user_gesture, callback); | 58 bridge_id, requesting_frame, user_gesture, |
| 59 base::Bind(&CallbackContentSettingWrapper, callback)); |
| 49 *permission_set = false; | 60 *permission_set = false; |
| 50 *new_permission = false; | 61 *new_permission = false; |
| 51 return true; | 62 return true; |
| 52 } | 63 } |
| 53 | 64 |
| 54 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); | 65 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); |
| 55 if (extension_registry) { | 66 if (extension_registry) { |
| 56 const extensions::Extension* extension = | 67 const extensions::Extension* extension = |
| 57 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | 68 extension_registry->enabled_extensions().GetExtensionOrAppByURL( |
| 58 requesting_frame_origin); | 69 requesting_frame_origin); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 web_contents ? | 105 web_contents ? |
| 95 extensions::WebViewPermissionHelper::FromWebContents(web_contents) | 106 extensions::WebViewPermissionHelper::FromWebContents(web_contents) |
| 96 : NULL; | 107 : NULL; |
| 97 if (web_view_permission_helper) { | 108 if (web_view_permission_helper) { |
| 98 web_view_permission_helper->CancelGeolocationPermissionRequest(bridge_id); | 109 web_view_permission_helper->CancelGeolocationPermissionRequest(bridge_id); |
| 99 return true; | 110 return true; |
| 100 } | 111 } |
| 101 #endif // defined(ENABLE_EXTENSIONS) | 112 #endif // defined(ENABLE_EXTENSIONS) |
| 102 return false; | 113 return false; |
| 103 } | 114 } |
| OLD | NEW |