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_andro
id.h" | 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_andro
id.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/android/google_location_settings_helper.h" | 8 #include "chrome/browser/android/google_location_settings_helper.h" |
| 9 #include "chrome/browser/content_settings/permission_request_id.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 | 14 |
14 ChromeGeolocationPermissionContextAndroid:: | 15 ChromeGeolocationPermissionContextAndroid:: |
15 ChromeGeolocationPermissionContextAndroid(Profile* profile) | 16 ChromeGeolocationPermissionContextAndroid(Profile* profile) |
16 : ChromeGeolocationPermissionContext(profile), | 17 : ChromeGeolocationPermissionContext(profile), |
17 google_location_settings_helper_( | 18 google_location_settings_helper_( |
18 GoogleLocationSettingsHelper::Create()) { | 19 GoogleLocationSettingsHelper::Create()) { |
19 } | 20 } |
20 | 21 |
21 ChromeGeolocationPermissionContextAndroid:: | 22 ChromeGeolocationPermissionContextAndroid:: |
22 ~ChromeGeolocationPermissionContextAndroid() { | 23 ~ChromeGeolocationPermissionContextAndroid() { |
23 } | 24 } |
24 | 25 |
| 26 void ChromeGeolocationPermissionContextAndroid::ProceedDecidePermission( |
| 27 content::WebContents* web_contents, |
| 28 const PermissionRequestID& id, |
| 29 const GURL& requesting_frame, |
| 30 const GURL& embedder, |
| 31 const std::string& accept_button_label, |
| 32 base::Callback<void(bool)> callback) { |
| 33 // Super class implementation expects everything in UI thread instead. |
| 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 35 ChromeGeolocationPermissionContext::DecidePermission( |
| 36 web_contents, id, requesting_frame, embedder, |
| 37 accept_button_label, callback); |
| 38 } |
| 39 |
| 40 void ChromeGeolocationPermissionContextAndroid::CheckMasterLocation( |
| 41 content::WebContents* web_contents, |
| 42 const PermissionRequestID& id, |
| 43 const GURL& requesting_frame, |
| 44 const GURL& embedder, |
| 45 base::Callback<void(bool)> callback) { |
| 46 // Check to see if the feature in its entirety has been disabled. |
| 47 // This must happen before other services (e.g. tabs, extensions) |
| 48 // get an opportunity to allow the geolocation request. |
| 49 bool enabled = |
| 50 google_location_settings_helper_->IsMasterLocationSettingEnabled(); |
| 51 |
| 52 // The flow for geolocation permission on android is: |
| 53 // - ChromeGeolocationPermissionContextAndroid::DecidePermission |
| 54 // intercepts the flow in the UI thread, and posts task |
| 55 // to the blocking pool to CheckMasterLocation (in order to |
| 56 // avoid strict-mode violation). |
| 57 // - At this point the master location permission is either: |
| 58 // -- enabled, in which we case it proceeds the normal flow |
| 59 // via ChromeGeolocationPermissionContext (which may create infobars, etc.). |
| 60 // -- disabled, in which case the permission is already decided. |
| 61 // |
| 62 // In either case, ChromeGeolocationPermissionContext expects these |
| 63 // in the UI thread. |
| 64 base::Closure ui_closure; |
| 65 if (enabled) { |
| 66 bool allow_label = google_location_settings_helper_->IsAllowLabel(); |
| 67 std::string accept_button_label = |
| 68 google_location_settings_helper_->GetAcceptButtonLabel(allow_label); |
| 69 ui_closure = base::Bind( |
| 70 &ChromeGeolocationPermissionContextAndroid::ProceedDecidePermission, |
| 71 this, web_contents, id, requesting_frame, embedder, |
| 72 accept_button_label, callback); |
| 73 } else { |
| 74 ui_closure = base::Bind( |
| 75 &ChromeGeolocationPermissionContextAndroid::PermissionDecided, |
| 76 this, id, requesting_frame, embedder, callback, false); |
| 77 } |
| 78 |
| 79 // This method is executed from the BlockingPool, post the result |
| 80 // back to the UI thread. |
| 81 content::BrowserThread::PostTask( |
| 82 content::BrowserThread::UI, FROM_HERE, ui_closure); |
| 83 } |
| 84 |
25 void ChromeGeolocationPermissionContextAndroid::DecidePermission( | 85 void ChromeGeolocationPermissionContextAndroid::DecidePermission( |
26 content::WebContents* web_contents, | 86 content::WebContents* web_contents, |
27 const PermissionRequestID& id, | 87 const PermissionRequestID& id, |
28 const GURL& requesting_frame, | 88 const GURL& requesting_frame, |
29 const GURL& embedder, | 89 const GURL& embedder, |
| 90 const std::string& accept_button_label, |
30 base::Callback<void(bool)> callback) { | 91 base::Callback<void(bool)> callback) { |
| 92 |
| 93 // Called on the UI thread. However, do the work on a separate thread |
| 94 // to avoid strict mode violation. |
31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 95 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
32 | 96 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, |
33 // Check to see if the feature in its entirety has been disabled. | 97 base::Bind( |
34 // This must happen before other services (e.g. tabs, extensions) | 98 &ChromeGeolocationPermissionContextAndroid::CheckMasterLocation, |
35 // get an opportunity to allow the geolocation request. | 99 this, web_contents, id, requesting_frame, embedder, callback)); |
36 if (!google_location_settings_helper_->IsMasterLocationSettingEnabled()) { | |
37 PermissionDecided(id, requesting_frame, embedder, callback, false); | |
38 return; | |
39 } | |
40 | |
41 ChromeGeolocationPermissionContext::DecidePermission( | |
42 web_contents, id, requesting_frame, embedder, callback); | |
43 } | 100 } |
44 | 101 |
45 void ChromeGeolocationPermissionContextAndroid::PermissionDecided( | 102 void ChromeGeolocationPermissionContextAndroid::PermissionDecided( |
46 const PermissionRequestID& id, | 103 const PermissionRequestID& id, |
47 const GURL& requesting_frame, | 104 const GURL& requesting_frame, |
48 const GURL& embedder, | 105 const GURL& embedder, |
49 base::Callback<void(bool)> callback, | 106 base::Callback<void(bool)> callback, |
50 bool allowed) { | 107 bool allowed) { |
51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
52 // If Google Apps Location setting is turned off then we ignore | 108 // If Google Apps Location setting is turned off then we ignore |
53 // the 'allow' website setting for this site and instead show | 109 // the 'allow' website setting for this site and instead show |
54 // the infobar to go back to the 'settings' to turn it back on. | 110 // the infobar to go back to the 'settings' to turn it back on. |
55 if (allowed && | 111 if (allowed && |
56 !google_location_settings_helper_->IsGoogleAppsLocationSettingEnabled()) { | 112 !google_location_settings_helper_->IsGoogleAppsLocationSettingEnabled()) { |
57 QueueController()->CreateInfoBarRequest(id, requesting_frame, embedder, | 113 QueueController()->CreateInfoBarRequest(id, requesting_frame, embedder, "", |
58 callback); | 114 callback); |
59 return; | 115 return; |
60 } | 116 } |
61 | 117 |
62 ChromeGeolocationPermissionContext::PermissionDecided( | 118 ChromeGeolocationPermissionContext::PermissionDecided( |
63 id, requesting_frame, embedder, callback, allowed); | 119 id, requesting_frame, embedder, callback, allowed); |
64 } | 120 } |
OLD | NEW |