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