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