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 #if ENABLE_EXTENSIONS |
| 26 void CallbackContentSettingWrapper( |
| 27 const base::Callback<void(ContentSetting)>& callback, |
| 28 bool allowed) { |
| 29 callback.Run(allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 30 } |
| 31 #endif // ENABLE_EXTENSIONS |
| 32 |
| 33 } // anonymous namespace |
| 34 |
23 GeolocationPermissionContextExtensions:: | 35 GeolocationPermissionContextExtensions:: |
24 GeolocationPermissionContextExtensions(Profile* profile) | 36 GeolocationPermissionContextExtensions(Profile* profile) |
25 : profile_(profile) { | 37 : profile_(profile) { |
26 } | 38 } |
27 | 39 |
28 GeolocationPermissionContextExtensions:: | 40 GeolocationPermissionContextExtensions:: |
29 ~GeolocationPermissionContextExtensions() { | 41 ~GeolocationPermissionContextExtensions() { |
30 } | 42 } |
31 | 43 |
32 bool GeolocationPermissionContextExtensions::RequestPermission( | 44 bool GeolocationPermissionContextExtensions::RequestPermission( |
33 content::WebContents* web_contents, | 45 content::WebContents* web_contents, |
34 const PermissionRequestID& request_id, | 46 const PermissionRequestID& request_id, |
35 int bridge_id, | 47 int bridge_id, |
36 const GURL& requesting_frame, | 48 const GURL& requesting_frame, |
37 bool user_gesture, | 49 bool user_gesture, |
38 base::Callback<void(bool)> callback, | 50 const base::Callback<void(ContentSetting)>& callback, |
39 bool* permission_set, | 51 bool* permission_set, |
40 bool* new_permission) { | 52 bool* new_permission) { |
41 #if defined(ENABLE_EXTENSIONS) | 53 #if defined(ENABLE_EXTENSIONS) |
42 GURL requesting_frame_origin = requesting_frame.GetOrigin(); | 54 GURL requesting_frame_origin = requesting_frame.GetOrigin(); |
43 | 55 |
44 extensions::WebViewPermissionHelper* web_view_permission_helper = | 56 extensions::WebViewPermissionHelper* web_view_permission_helper = |
45 extensions::WebViewPermissionHelper::FromWebContents(web_contents); | 57 extensions::WebViewPermissionHelper::FromWebContents(web_contents); |
46 if (web_view_permission_helper) { | 58 if (web_view_permission_helper) { |
47 web_view_permission_helper->RequestGeolocationPermission( | 59 web_view_permission_helper->RequestGeolocationPermission( |
48 bridge_id, requesting_frame, user_gesture, callback); | 60 bridge_id, requesting_frame, user_gesture, |
| 61 base::Bind(&CallbackContentSettingWrapper, callback)); |
49 *permission_set = false; | 62 *permission_set = false; |
50 *new_permission = false; | 63 *new_permission = false; |
51 return true; | 64 return true; |
52 } | 65 } |
53 | 66 |
54 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); | 67 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); |
55 if (extension_registry) { | 68 if (extension_registry) { |
56 const extensions::Extension* extension = | 69 const extensions::Extension* extension = |
57 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | 70 extension_registry->enabled_extensions().GetExtensionOrAppByURL( |
58 requesting_frame_origin); | 71 requesting_frame_origin); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 web_contents ? | 107 web_contents ? |
95 extensions::WebViewPermissionHelper::FromWebContents(web_contents) | 108 extensions::WebViewPermissionHelper::FromWebContents(web_contents) |
96 : NULL; | 109 : NULL; |
97 if (web_view_permission_helper) { | 110 if (web_view_permission_helper) { |
98 web_view_permission_helper->CancelGeolocationPermissionRequest(bridge_id); | 111 web_view_permission_helper->CancelGeolocationPermissionRequest(bridge_id); |
99 return true; | 112 return true; |
100 } | 113 } |
101 #endif // defined(ENABLE_EXTENSIONS) | 114 #endif // defined(ENABLE_EXTENSIONS) |
102 return false; | 115 return false; |
103 } | 116 } |
OLD | NEW |