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.h" | 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/threading/worker_pool.h" | |
13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
14 #include "chrome/browser/content_settings/permission_request_id.h" | 15 #include "chrome/browser/content_settings/permission_request_id.h" |
15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
18 #include "chrome/browser/extensions/suggest_permission_util.h" | 19 #include "chrome/browser/extensions/suggest_permission_util.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 97 |
97 GURL embedder = web_contents->GetURL(); | 98 GURL embedder = web_contents->GetURL(); |
98 if (!requesting_frame.is_valid() || !embedder.is_valid()) { | 99 if (!requesting_frame.is_valid() || !embedder.is_valid()) { |
99 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " | 100 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " |
100 << requesting_frame << "," << embedder | 101 << requesting_frame << "," << embedder |
101 << " (geolocation is not supported in popups)"; | 102 << " (geolocation is not supported in popups)"; |
102 NotifyPermissionSet(id, requesting_frame, callback, false); | 103 NotifyPermissionSet(id, requesting_frame, callback, false); |
103 return; | 104 return; |
104 } | 105 } |
105 | 106 |
106 DecidePermission(id, requesting_frame, embedder, callback); | 107 // DecidePermission is a bit heavy. Avoid hogging the UI thread |
108 // now that we are done with extension related stuff. | |
109 base::WorkerPool::PostTask(FROM_HERE, | |
joth
2013/08/20 23:07:21
WorkerPool is a bit funny about non-joinable threa
acleung1
2013/08/23 23:13:09
Ok. I removed this and keep the execution of these
| |
110 base::Bind( | |
111 &ChromeGeolocationPermissionContext::DecidePermission, | |
112 this, id, requesting_frame, embedder, callback), true); | |
113 return; | |
107 } | 114 } |
108 | 115 |
109 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( | 116 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
110 int render_process_id, | 117 int render_process_id, |
111 int render_view_id, | 118 int render_view_id, |
112 int bridge_id, | 119 int bridge_id, |
113 const GURL& requesting_frame) { | 120 const GURL& requesting_frame) { |
114 CancelPendingInfoBarRequest(PermissionRequestID( | 121 CancelPendingInfoBarRequest(PermissionRequestID( |
115 render_process_id, render_view_id, bridge_id)); | 122 render_process_id, render_view_id, bridge_id)); |
116 } | 123 } |
117 | 124 |
118 void ChromeGeolocationPermissionContext::DecidePermission( | 125 void ChromeGeolocationPermissionContext::DecidePermission( |
119 const PermissionRequestID& id, | 126 const PermissionRequestID& id, |
120 const GURL& requesting_frame, | 127 const GURL& requesting_frame, |
121 const GURL& embedder, | 128 const GURL& embedder, |
122 base::Callback<void(bool)> callback) { | 129 base::Callback<void(bool)> callback) { |
123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
124 | 130 |
125 ContentSetting content_setting = | 131 ContentSetting content_setting = |
126 profile_->GetHostContentSettingsMap()->GetContentSetting( | 132 profile_->GetHostContentSettingsMap()->GetContentSetting( |
joth
2013/08/20 23:07:21
This looks bad. Pretty sure profile_ is not thread
acleung1
2013/08/23 23:13:09
Fixed. Kept in UI.
| |
127 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION, | 133 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION, |
128 std::string()); | 134 std::string()); |
129 switch (content_setting) { | 135 switch (content_setting) { |
130 case CONTENT_SETTING_BLOCK: | 136 case CONTENT_SETTING_BLOCK: |
131 PermissionDecided(id, requesting_frame, embedder, callback, false); | 137 PermissionDecided(id, requesting_frame, embedder, callback, false); |
132 break; | 138 break; |
133 case CONTENT_SETTING_ALLOW: | 139 case CONTENT_SETTING_ALLOW: |
134 PermissionDecided(id, requesting_frame, embedder, callback, true); | 140 PermissionDecided(id, requesting_frame, embedder, callback, true); |
135 break; | 141 break; |
136 default: | 142 default: |
137 // setting == ask. Prompt the user. | 143 // setting == ask. Prompt the user in the UI thread now. |
144 content::BrowserThread::PostTask( | |
145 content::BrowserThread::UI, FROM_HERE, | |
146 base::Bind( | |
147 &ChromeGeolocationPermissionContext::CreateInfoBarRequest, | |
148 base::Unretained(this), id, requesting_frame, embedder,callback)); | |
joth
2013/08/20 23:07:21
why use Unretained() here but not on line 112?
acleung1
2013/08/23 23:13:09
Removed the early call and kept using unretained h
| |
149 } | |
150 } | |
151 | |
152 void ChromeGeolocationPermissionContext::CreateInfoBarRequest( | |
153 const PermissionRequestID& id, | |
154 const GURL& requesting_frame, | |
155 const GURL& embedder, | |
156 base::Callback<void(bool)> callback) { | |
138 QueueController()->CreateInfoBarRequest( | 157 QueueController()->CreateInfoBarRequest( |
139 id, requesting_frame, embedder, base::Bind( | 158 id, requesting_frame, embedder, base::Bind( |
140 &ChromeGeolocationPermissionContext::NotifyPermissionSet, | 159 &ChromeGeolocationPermissionContext::NotifyPermissionSet, |
141 base::Unretained(this), id, requesting_frame, callback)); | 160 base::Unretained(this), id, requesting_frame, callback)); |
142 } | |
143 } | 161 } |
144 | 162 |
145 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { | 163 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { |
146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 164 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
147 permission_queue_controller_.reset(); | 165 permission_queue_controller_.reset(); |
148 shutting_down_ = true; | 166 shutting_down_ = true; |
149 } | 167 } |
150 | 168 |
151 void ChromeGeolocationPermissionContext::PermissionDecided( | 169 void ChromeGeolocationPermissionContext::PermissionDecided( |
152 const PermissionRequestID& id, | 170 const PermissionRequestID& id, |
153 const GURL& requesting_frame, | 171 const GURL& requesting_frame, |
154 const GURL& embedder, | 172 const GURL& embedder, |
155 base::Callback<void(bool)> callback, | 173 base::Callback<void(bool)> callback, |
156 bool allowed) { | 174 bool allowed) { |
157 NotifyPermissionSet(id, requesting_frame, callback, allowed); | 175 NotifyPermissionSet(id, requesting_frame, callback, allowed); |
158 } | 176 } |
159 | 177 |
160 void ChromeGeolocationPermissionContext::NotifyPermissionSet( | 178 void ChromeGeolocationPermissionContext::NotifyPermissionSet( |
161 const PermissionRequestID& id, | 179 const PermissionRequestID& id, |
162 const GURL& requesting_frame, | 180 const GURL& requesting_frame, |
163 base::Callback<void(bool)> callback, | 181 base::Callback<void(bool)> callback, |
164 bool allowed) { | 182 bool allowed) { |
165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 183 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
joth
2013/08/20 23:07:21
you call this from ChromeGeolocationPermissionCon
acleung1
2013/08/23 23:13:09
Good catch! This should have assert if master loca
| |
166 | 184 |
167 // WebContents may have gone away (or not exists for extension). | 185 // WebContents may have gone away (or not exists for extension). |
168 TabSpecificContentSettings* content_settings = | 186 TabSpecificContentSettings* content_settings = |
169 TabSpecificContentSettings::Get(id.render_process_id(), | 187 TabSpecificContentSettings::Get(id.render_process_id(), |
170 id.render_view_id()); | 188 id.render_view_id()); |
171 if (content_settings) { | 189 if (content_settings) { |
172 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(), | 190 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(), |
173 allowed); | 191 allowed); |
174 } | 192 } |
175 | 193 |
176 callback.Run(allowed); | 194 callback.Run(allowed); |
177 } | 195 } |
178 | 196 |
179 PermissionQueueController* | 197 PermissionQueueController* |
180 ChromeGeolocationPermissionContext::QueueController() { | 198 ChromeGeolocationPermissionContext::QueueController() { |
181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
Michael van Ouwerkerk
2013/08/21 10:24:45
Instead of deleting, could you modify such checks
acleung1
2013/08/23 23:13:09
I am moving this back to the UI thread as well.
A
| |
182 DCHECK(!shutting_down_); | 199 DCHECK(!shutting_down_); |
183 if (!permission_queue_controller_) | 200 if (!permission_queue_controller_) |
184 permission_queue_controller_.reset(CreateQueueController()); | 201 permission_queue_controller_.reset(CreateQueueController()); |
185 return permission_queue_controller_.get(); | 202 return permission_queue_controller_.get(); |
186 } | 203 } |
187 | 204 |
188 PermissionQueueController* | 205 PermissionQueueController* |
189 ChromeGeolocationPermissionContext::CreateQueueController() { | 206 ChromeGeolocationPermissionContext::CreateQueueController() { |
190 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
191 return new PermissionQueueController(profile(), | 207 return new PermissionQueueController(profile(), |
joth
2013/08/20 23:07:21
again using profile on non-UI thread?
acleung1
2013/08/23 23:13:09
fixed.
| |
192 CONTENT_SETTINGS_TYPE_GEOLOCATION); | 208 CONTENT_SETTINGS_TYPE_GEOLOCATION); |
193 } | 209 } |
194 | 210 |
195 void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( | 211 void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( |
196 const PermissionRequestID& id) { | 212 const PermissionRequestID& id) { |
197 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 213 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
198 content::BrowserThread::PostTask( | 214 content::BrowserThread::PostTask( |
199 content::BrowserThread::UI, FROM_HERE, | 215 content::BrowserThread::UI, FROM_HERE, |
200 base::Bind( | 216 base::Bind( |
201 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, | 217 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, |
202 this, id)); | 218 this, id)); |
203 return; | 219 return; |
204 } | 220 } |
205 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 221 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
206 if (shutting_down_) | 222 if (shutting_down_) |
207 return; | 223 return; |
208 QueueController()->CancelInfoBarRequest(id); | 224 QueueController()->CancelInfoBarRequest(id); |
209 } | 225 } |
OLD | NEW |