Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_android.cc

Issue 441883003: Simplify Android geolocation permission checks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = google_location_settings_helper_->IsSystemLocationEnabled();
49 google_location_settings_helper_->IsMasterLocationSettingEnabled();
50 48
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; 49 base::Closure ui_closure;
64 if (enabled) { 50 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( 51 ui_closure = base::Bind(
69 &GeolocationPermissionContextAndroid::ProceedDecidePermission, 52 &GeolocationPermissionContextAndroid::ProceedDecidePermission,
70 this, web_contents, info, accept_button_label, callback); 53 this, web_contents, info, callback);
71 } else { 54 } else {
72 ui_closure = base::Bind( 55 ui_closure = base::Bind(
73 &GeolocationPermissionContextAndroid::PermissionDecided, 56 &GeolocationPermissionContextAndroid::PermissionDecided,
74 this, info.id, info.requesting_frame, info.embedder, callback, false); 57 this, info.id, info.requesting_frame, info.embedder, callback, false);
75 } 58 }
76 59
77 // This method is executed from the BlockingPool, post the result 60 // This method is executed from the BlockingPool, post the result
78 // back to the UI thread. 61 // back to the UI thread.
79 content::BrowserThread::PostTask( 62 content::BrowserThread::PostTask(
80 content::BrowserThread::UI, FROM_HERE, ui_closure); 63 content::BrowserThread::UI, FROM_HERE, ui_closure);
81 } 64 }
82 65
83 void GeolocationPermissionContextAndroid::DecidePermission( 66 void GeolocationPermissionContextAndroid::DecidePermission(
84 content::WebContents* web_contents, 67 content::WebContents* web_contents,
85 const PermissionRequestID& id, 68 const PermissionRequestID& id,
86 const GURL& requesting_frame, 69 const GURL& requesting_frame,
87 bool user_gesture, 70 bool user_gesture,
88 const GURL& embedder, 71 const GURL& embedder,
89 const std::string& accept_button_label,
90 base::Callback<void(bool)> callback) { 72 base::Callback<void(bool)> callback) {
91 73
92 PermissionRequestInfo info; 74 PermissionRequestInfo info;
93 info.id = id; 75 info.id = id;
94 info.requesting_frame = requesting_frame; 76 info.requesting_frame = requesting_frame;
95 info.user_gesture = user_gesture; 77 info.user_gesture = user_gesture;
96 info.embedder = embedder; 78 info.embedder = embedder;
97 79
98 // Called on the UI thread. However, do the work on a separate thread 80 // Called on the UI thread. However, do the work on a separate thread
99 // to avoid strict mode violation. 81 // to avoid strict mode violation.
100 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
101 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, 83 content::BrowserThread::PostBlockingPoolTask(FROM_HERE,
102 base::Bind( 84 base::Bind(
103 &GeolocationPermissionContextAndroid::CheckMasterLocation, 85 &GeolocationPermissionContextAndroid::CheckSystemLocation,
104 this, web_contents, info, callback)); 86 this, web_contents, info, callback));
105 } 87 }
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698