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 = | |
bulach
2014/02/14 11:36:48
nit: unindent here and above
acleung1
2014/02/21 21:18:01
Done.
| |
68 google_location_settings_helper_->GetAcceptButtonLabel(allow_label); | |
69 ui_closure = base::Bind( | |
70 &ChromeGeolocationPermissionContextAndroid::ProceedDecidePermission, | |
71 base::Unretained(this), web_contents, id, requesting_frame, embedder, | |
bulach
2014/02/14 11:36:48
nit: I suppose the base class is RefCountedThreadS
acleung1
2014/02/21 21:18:01
Done.
| |
72 accept_button_label, callback); | |
73 } else { | |
74 ui_closure = base::Bind( | |
75 &ChromeGeolocationPermissionContextAndroid::PermissionDecided, | |
76 base::Unretained(this), id, | |
77 requesting_frame, embedder, callback, false); | |
78 } | |
79 | |
80 // This method is executed from the BlockingPool, post the result | |
81 // back to the UI thread. | |
82 content::BrowserThread::PostTask( | |
83 content::BrowserThread::UI, FROM_HERE, ui_closure); | |
84 } | |
85 | |
25 void ChromeGeolocationPermissionContextAndroid::DecidePermission( | 86 void ChromeGeolocationPermissionContextAndroid::DecidePermission( |
26 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
27 const PermissionRequestID& id, | 88 const PermissionRequestID& id, |
28 const GURL& requesting_frame, | 89 const GURL& requesting_frame, |
29 const GURL& embedder, | 90 const GURL& embedder, |
91 const std::string accept_button_label, | |
30 base::Callback<void(bool)> callback) { | 92 base::Callback<void(bool)> callback) { |
93 | |
94 // Called on the UI thread. However, do the work on a separate thread | |
95 // to avoid strict mode violation. | |
31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
32 | 97 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, |
33 // Check to see if the feature in its entirety has been disabled. | 98 base::Bind( |
34 // This must happen before other services (e.g. tabs, extensions) | 99 &ChromeGeolocationPermissionContextAndroid::CheckMasterLocation, |
35 // get an opportunity to allow the geolocation request. | 100 base::Unretained(this), web_contents, id, |
36 if (!google_location_settings_helper_->IsMasterLocationSettingEnabled()) { | 101 requesting_frame, embedder, callback)); |
37 PermissionDecided(id, requesting_frame, embedder, callback, false); | |
38 return; | |
39 } | |
40 | |
41 ChromeGeolocationPermissionContext::DecidePermission( | |
42 web_contents, id, requesting_frame, embedder, callback); | |
43 } | 102 } |
44 | 103 |
45 void ChromeGeolocationPermissionContextAndroid::PermissionDecided( | 104 void ChromeGeolocationPermissionContextAndroid::PermissionDecided( |
46 const PermissionRequestID& id, | 105 const PermissionRequestID& id, |
47 const GURL& requesting_frame, | 106 const GURL& requesting_frame, |
48 const GURL& embedder, | 107 const GURL& embedder, |
49 base::Callback<void(bool)> callback, | 108 base::Callback<void(bool)> callback, |
50 bool allowed) { | 109 bool allowed) { |
51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
52 // If Google Apps Location setting is turned off then we ignore | 110 // If Google Apps Location setting is turned off then we ignore |
53 // the 'allow' website setting for this site and instead show | 111 // the 'allow' website setting for this site and instead show |
54 // the infobar to go back to the 'settings' to turn it back on. | 112 // the infobar to go back to the 'settings' to turn it back on. |
55 if (allowed && | 113 if (allowed && |
56 !google_location_settings_helper_->IsGoogleAppsLocationSettingEnabled()) { | 114 !google_location_settings_helper_->IsGoogleAppsLocationSettingEnabled()) { |
57 QueueController()->CreateInfoBarRequest(id, requesting_frame, embedder, | 115 QueueController()->CreateInfoBarRequest(id, requesting_frame, embedder, "", |
58 callback); | 116 callback); |
59 return; | 117 return; |
60 } | 118 } |
61 | 119 |
62 ChromeGeolocationPermissionContext::PermissionDecided( | 120 ChromeGeolocationPermissionContext::PermissionDecided( |
63 id, requesting_frame, embedder, callback, allowed); | 121 id, requesting_frame, embedder, callback, allowed); |
64 } | 122 } |
OLD | NEW |