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/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
15 #include "chrome/browser/content_settings/permission_request_id.h" | 15 #include "chrome/browser/content_settings/permission_request_id.h" |
16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
17 #include "chrome/browser/extensions/suggest_permission_util.h" | 17 #include "chrome/browser/extensions/suggest_permission_util.h" |
| 18 #include "chrome/browser/guestview/webview/webview_guest.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
20 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
21 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 22 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "extensions/browser/extension_registry.h" | 27 #include "extensions/browser/extension_registry.h" |
27 #include "extensions/browser/process_map.h" | 28 #include "extensions/browser/process_map.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 requesting_frame_origin, user_gesture, callback)); | 151 requesting_frame_origin, user_gesture, callback)); |
151 return; | 152 return; |
152 } | 153 } |
153 | 154 |
154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
155 if (shutting_down_) | 156 if (shutting_down_) |
156 return; | 157 return; |
157 | 158 |
158 content::WebContents* web_contents = | 159 content::WebContents* web_contents = |
159 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 160 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 161 |
| 162 WebViewGuest* guest = WebViewGuest::FromWebContents(web_contents); |
| 163 if (guest) { |
| 164 guest->RequestGeolocationPermission(bridge_id, |
| 165 requesting_frame, |
| 166 user_gesture, |
| 167 callback); |
| 168 return; |
| 169 } |
160 const PermissionRequestID id(render_process_id, render_view_id, bridge_id, 0); | 170 const PermissionRequestID id(render_process_id, render_view_id, bridge_id, 0); |
161 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); | 171 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); |
162 if (extension_registry) { | 172 if (extension_registry) { |
163 const extensions::Extension* extension = | 173 const extensions::Extension* extension = |
164 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | 174 extension_registry->enabled_extensions().GetExtensionOrAppByURL( |
165 requesting_frame_origin); | 175 requesting_frame_origin); |
166 if (IsExtensionWithPermissionOrSuggestInConsole(APIPermission::kGeolocation, | 176 if (IsExtensionWithPermissionOrSuggestInConsole(APIPermission::kGeolocation, |
167 extension, | 177 extension, |
168 profile_)) { | 178 profile_)) { |
169 // Make sure the extension is in the calling process. | 179 // Make sure the extension is in the calling process. |
(...skipping 29 matching lines...) Expand all Loading... |
199 | 209 |
200 DecidePermission(web_contents, id, requesting_frame_origin, user_gesture, | 210 DecidePermission(web_contents, id, requesting_frame_origin, user_gesture, |
201 embedder, "", callback); | 211 embedder, "", callback); |
202 } | 212 } |
203 | 213 |
204 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( | 214 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
205 int render_process_id, | 215 int render_process_id, |
206 int render_view_id, | 216 int render_view_id, |
207 int bridge_id, | 217 int bridge_id, |
208 const GURL& requesting_frame) { | 218 const GURL& requesting_frame) { |
| 219 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 220 content::BrowserThread::PostTask( |
| 221 content::BrowserThread::UI, FROM_HERE, |
| 222 base::Bind( |
| 223 &ChromeGeolocationPermissionContext:: |
| 224 CancelGeolocationPermissionRequest, |
| 225 this, |
| 226 render_process_id, |
| 227 render_view_id, |
| 228 bridge_id, |
| 229 requesting_frame)); |
| 230 return; |
| 231 } |
| 232 |
| 233 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 234 content::WebContents* web_contents = |
| 235 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 236 WebViewGuest* guest = |
| 237 web_contents ? WebViewGuest::FromWebContents(web_contents) : NULL; |
| 238 if (guest) { |
| 239 guest->CancelGeolocationPermissionRequest(bridge_id); |
| 240 return; |
| 241 } |
209 // TODO(gbillock): cancel permission bubble request. | 242 // TODO(gbillock): cancel permission bubble request. |
210 CancelPendingInfobarRequest(PermissionRequestID( | 243 CancelPendingInfobarRequest(PermissionRequestID( |
211 render_process_id, render_view_id, bridge_id, 0)); | 244 render_process_id, render_view_id, bridge_id, 0)); |
212 } | 245 } |
213 | 246 |
214 void ChromeGeolocationPermissionContext::DecidePermission( | 247 void ChromeGeolocationPermissionContext::DecidePermission( |
215 content::WebContents* web_contents, | 248 content::WebContents* web_contents, |
216 const PermissionRequestID& id, | 249 const PermissionRequestID& id, |
217 const GURL& requesting_frame, | 250 const GURL& requesting_frame, |
218 bool user_gesture, | 251 bool user_gesture, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 340 |
308 PermissionQueueController* | 341 PermissionQueueController* |
309 ChromeGeolocationPermissionContext::CreateQueueController() { | 342 ChromeGeolocationPermissionContext::CreateQueueController() { |
310 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 343 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
311 return new PermissionQueueController(profile(), | 344 return new PermissionQueueController(profile(), |
312 CONTENT_SETTINGS_TYPE_GEOLOCATION); | 345 CONTENT_SETTINGS_TYPE_GEOLOCATION); |
313 } | 346 } |
314 | 347 |
315 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest( | 348 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest( |
316 const PermissionRequestID& id) { | 349 const PermissionRequestID& id) { |
317 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
318 content::BrowserThread::PostTask( | |
319 content::BrowserThread::UI, FROM_HERE, | |
320 base::Bind( | |
321 &ChromeGeolocationPermissionContext::CancelPendingInfobarRequest, | |
322 this, id)); | |
323 return; | |
324 } | |
325 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 350 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
326 if (shutting_down_) | 351 if (shutting_down_) |
327 return; | 352 return; |
328 | 353 |
329 // TODO(gbillock): handle permission bubble cancellation. | 354 // TODO(gbillock): handle permission bubble cancellation. |
330 QueueController()->CancelInfoBarRequest(id); | 355 QueueController()->CancelInfoBarRequest(id); |
331 } | 356 } |
OLD | NEW |