Chromium Code Reviews| 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 | 13 |
| 13 ChromeGeolocationPermissionContextAndroid:: | 14 ChromeGeolocationPermissionContextAndroid:: |
| 14 ChromeGeolocationPermissionContextAndroid(Profile* profile) | 15 ChromeGeolocationPermissionContextAndroid(Profile* profile) |
| 15 : ChromeGeolocationPermissionContext(profile), | 16 : ChromeGeolocationPermissionContext(profile), |
| 16 google_location_settings_helper_( | 17 google_location_settings_helper_( |
| 17 GoogleLocationSettingsHelper::Create()) { | 18 GoogleLocationSettingsHelper::Create()) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 ChromeGeolocationPermissionContextAndroid:: | 21 ChromeGeolocationPermissionContextAndroid:: |
| 21 ~ChromeGeolocationPermissionContextAndroid() { | 22 ~ChromeGeolocationPermissionContextAndroid() { |
| 22 } | 23 } |
| 23 | 24 |
| 25 void ChromeGeolocationPermissionContextAndroid::CallSuperDecidePermission( | |
| 26 const PermissionRequestID& id, | |
| 27 const GURL& requesting_frame, | |
| 28 const GURL& embedder, | |
| 29 base::Callback<void(bool)> callback) { | |
| 30 // Super class implementation expects everything in UI thread instead. | |
| 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 32 ChromeGeolocationPermissionContext::DecidePermission( | |
| 33 id, requesting_frame, embedder, callback); | |
| 34 } | |
| 35 | |
| 36 void ChromeGeolocationPermissionContextAndroid::CheckMasterLocation( | |
| 37 const PermissionRequestID& id, | |
| 38 const GURL& requesting_frame, | |
| 39 const GURL& embedder, | |
| 40 base::Callback<void(bool)> callback) { | |
| 41 // Check to see if the feature in its entirety has been disabled. | |
| 42 // This must happen before other services (e.g. tabs, extensions) | |
| 43 // get an opportunity to allow the geolocation request. | |
| 44 bool enabled = | |
| 45 google_location_settings_helper_->IsMasterLocationSettingEnabled(); | |
| 46 | |
| 47 // Regardless of what the master setting is, we still need to | |
| 48 // go back to the UI thread for the rest of the bookkeeping. | |
| 49 if (enabled) { | |
| 50 content::BrowserThread::PostTask( | |
| 51 content::BrowserThread::UI, FROM_HERE, | |
| 52 base::Bind( | |
| 53 &ChromeGeolocationPermissionContextAndroid:: | |
| 54 CallSuperDecidePermission, | |
|
bulach
2013/09/04 18:48:53
is it possible to bind to DecidePermission directl
acleung1
2013/09/05 21:50:16
Yeah. I was struggling with this and couldn't find
| |
| 55 base::Unretained(this), id, requesting_frame, embedder, callback)); | |
| 56 } else { | |
| 57 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 58 base::Bind(&ChromeGeolocationPermissionContextAndroid:: | |
| 59 PermissionDecided, | |
| 60 base::Unretained(this), id, | |
| 61 requesting_frame, embedder, callback, false)); } | |
|
bulach
2013/09/04 18:48:53
nit: move } to the next line..
it maybe slightly
acleung1
2013/09/05 21:50:16
Done.
| |
| 62 } | |
| 63 | |
| 24 void ChromeGeolocationPermissionContextAndroid::DecidePermission( | 64 void ChromeGeolocationPermissionContextAndroid::DecidePermission( |
| 25 const PermissionRequestID& id, | 65 const PermissionRequestID& id, |
| 26 const GURL& requesting_frame, | 66 const GURL& requesting_frame, |
| 27 const GURL& embedder, | 67 const GURL& embedder, |
| 28 base::Callback<void(bool)> callback) { | 68 base::Callback<void(bool)> callback) { |
| 29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 69 // The super class implementation requires this to be in the |
| 30 | 70 // UI thread. We would like the work done else where to avoid |
| 31 // Check to see if the feature in its entirety has been disabled. | 71 // strict mode violations. |
|
bulach
2013/09/04 18:48:53
rather than "the super class implementation requir
acleung1
2013/09/05 21:50:16
Done.
| |
| 32 // This must happen before other services (e.g. tabs, extensions) | 72 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, |
| 33 // get an opportunity to allow the geolocation request. | 73 base::Bind( |
| 34 if (!google_location_settings_helper_->IsMasterLocationSettingEnabled()) { | 74 &ChromeGeolocationPermissionContextAndroid::CheckMasterLocation, |
| 35 PermissionDecided(id, requesting_frame, embedder, callback, false); | 75 base::Unretained(this), id, requesting_frame, embedder, callback)); |
|
bulach
2013/09/04 18:48:53
nit: indentation
acleung1
2013/09/05 21:50:16
Done.
| |
| 36 return; | |
| 37 } | |
| 38 | |
| 39 ChromeGeolocationPermissionContext::DecidePermission(id, requesting_frame, | |
| 40 embedder, callback); | |
| 41 } | 76 } |
| 42 | 77 |
| 43 void ChromeGeolocationPermissionContextAndroid::PermissionDecided( | 78 void ChromeGeolocationPermissionContextAndroid::PermissionDecided( |
| 44 const PermissionRequestID& id, | 79 const PermissionRequestID& id, |
| 45 const GURL& requesting_frame, | 80 const GURL& requesting_frame, |
| 46 const GURL& embedder, | 81 const GURL& embedder, |
| 47 base::Callback<void(bool)> callback, | 82 base::Callback<void(bool)> callback, |
| 48 bool allowed) { | 83 bool allowed) { |
| 49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 50 // If Google Apps Location setting is turned off then we ignore | 84 // If Google Apps Location setting is turned off then we ignore |
| 51 // the 'allow' website setting for this site and instead show | 85 // the 'allow' website setting for this site and instead show |
| 52 // the infobar to go back to the 'settings' to turn it back on. | 86 // the infobar to go back to the 'settings' to turn it back on. |
| 53 if (allowed && | 87 if (allowed && |
| 54 !google_location_settings_helper_->IsGoogleAppsLocationSettingEnabled()) { | 88 !google_location_settings_helper_->IsGoogleAppsLocationSettingEnabled()) { |
| 55 QueueController()->CreateInfoBarRequest(id, requesting_frame, embedder, | 89 QueueController()->CreateInfoBarRequest(id, requesting_frame, embedder, |
| 56 callback); | 90 callback); |
| 57 return; | 91 return; |
| 58 } | 92 } |
| 59 | 93 |
| 60 ChromeGeolocationPermissionContext::PermissionDecided( | 94 ChromeGeolocationPermissionContext::PermissionDecided( |
| 61 id, requesting_frame, embedder, callback, allowed); | 95 id, requesting_frame, embedder, callback, allowed); |
| 62 } | 96 } |
| OLD | NEW |