OLD | NEW |
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 "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" | 16 #include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" |
17 #include "chrome/browser/prefs/pref_service.h" | |
18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/tab_contents/tab_util.h" | 18 #include "chrome/browser/tab_contents/tab_util.h" |
20 #include "chrome/browser/view_type_utils.h" | 19 #include "chrome/browser/view_type_utils.h" |
21 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/common/pref_names.h" | |
23 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
28 | 26 |
29 using WebKit::WebSecurityOrigin; | 27 using WebKit::WebSecurityOrigin; |
30 using content::BrowserThread; | 28 using content::BrowserThread; |
31 using content::WebContents; | 29 using content::WebContents; |
32 | 30 |
33 // GeolocationPermissionContext ----------------------------------------------- | 31 // GeolocationPermissionContext ----------------------------------------------- |
34 | 32 |
35 ChromeGeolocationPermissionContext* ChromeGeolocationPermissionContext::Create( | |
36 Profile* profile) { | |
37 return new ChromeGeolocationPermissionContext(profile); | |
38 } | |
39 | |
40 void ChromeGeolocationPermissionContext::RegisterUserPrefs( | |
41 PrefService *user_prefs) { | |
42 #if defined(OS_ANDROID) | |
43 user_prefs->RegisterBooleanPref(prefs::kGeolocationEnabled, true, | |
44 PrefService::UNSYNCABLE_PREF); | |
45 #endif | |
46 } | |
47 | |
48 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( | 33 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( |
49 Profile* profile) | 34 Profile* profile) |
50 : profile_(profile) { | 35 : profile_(profile) { |
51 } | 36 } |
52 | 37 |
53 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { | 38 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { |
54 } | 39 } |
55 | 40 |
56 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( | 41 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( |
57 int render_process_id, int render_view_id, int bridge_id, | 42 int render_process_id, int render_view_id, int bridge_id, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 const GURL& requesting_frame) { | 88 const GURL& requesting_frame) { |
104 CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); | 89 CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); |
105 } | 90 } |
106 | 91 |
107 void ChromeGeolocationPermissionContext::DecidePermission( | 92 void ChromeGeolocationPermissionContext::DecidePermission( |
108 int render_process_id, int render_view_id, int bridge_id, | 93 int render_process_id, int render_view_id, int bridge_id, |
109 const GURL& requesting_frame, const GURL& embedder, | 94 const GURL& requesting_frame, const GURL& embedder, |
110 base::Callback<void(bool)> callback) { | 95 base::Callback<void(bool)> callback) { |
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
112 | 97 |
113 #if defined(OS_ANDROID) | |
114 // Check to see if the feature in its entirety has been disabled. | |
115 // This must happen before other services (e.g. tabs, extensions) | |
116 // get an opportunity to allow the geolocation request. | |
117 if (!profile()->GetPrefs()->GetBoolean(prefs::kGeolocationEnabled)) { | |
118 PermissionDecided(render_process_id, render_view_id, bridge_id, | |
119 requesting_frame, embedder, callback, false); | |
120 return; | |
121 } | |
122 #endif | |
123 | |
124 ExtensionService* extension_service = profile_->GetExtensionService(); | 98 ExtensionService* extension_service = profile_->GetExtensionService(); |
125 if (extension_service) { | 99 if (extension_service) { |
126 const extensions::Extension* extension = | 100 const extensions::Extension* extension = |
127 extension_service->extensions()->GetExtensionOrAppByURL( | 101 extension_service->extensions()->GetExtensionOrAppByURL( |
128 ExtensionURLInfo( | 102 ExtensionURLInfo( |
129 WebSecurityOrigin::createFromString( | 103 WebSecurityOrigin::createFromString( |
130 UTF8ToUTF16(requesting_frame.spec())), | 104 UTF8ToUTF16(requesting_frame.spec())), |
131 requesting_frame)); | 105 requesting_frame)); |
132 if (extension && | 106 if (extension && |
133 extension->HasAPIPermission(extensions::APIPermission::kGeolocation)) { | 107 extension->HasAPIPermission(extensions::APIPermission::kGeolocation)) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, | 199 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, |
226 this, render_process_id, render_view_id, bridge_id)); | 200 this, render_process_id, render_view_id, bridge_id)); |
227 return; | 201 return; |
228 } | 202 } |
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
230 QueueController()->CancelInfoBarRequest( | 204 QueueController()->CancelInfoBarRequest( |
231 render_process_id, | 205 render_process_id, |
232 render_view_id, | 206 render_view_id, |
233 bridge_id); | 207 bridge_id); |
234 } | 208 } |
OLD | NEW |