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