| 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/guest_view/web_view/web_view_guest.h" | 18 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 22 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 22 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/browser/process_map.h" | 29 #include "extensions/browser/process_map.h" |
| 29 #include "extensions/browser/view_type_utils.h" | 30 #include "extensions/browser/view_type_utils.h" |
| 30 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 33 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 129 } |
| 129 | 130 |
| 130 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { | 131 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { |
| 131 // ChromeGeolocationPermissionContext may be destroyed on either the UI thread | 132 // ChromeGeolocationPermissionContext may be destroyed on either the UI thread |
| 132 // or the IO thread, but the PermissionQueueController must have been | 133 // or the IO thread, but the PermissionQueueController must have been |
| 133 // destroyed on the UI thread. | 134 // destroyed on the UI thread. |
| 134 DCHECK(!permission_queue_controller_.get()); | 135 DCHECK(!permission_queue_controller_.get()); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( | 138 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( |
| 138 int render_process_id, | 139 content::WebContents* web_contents, |
| 139 int render_view_id, | |
| 140 int bridge_id, | 140 int bridge_id, |
| 141 const GURL& requesting_frame, | 141 const GURL& requesting_frame, |
| 142 bool user_gesture, | 142 bool user_gesture, |
| 143 base::Callback<void(bool)> callback) { | 143 base::Callback<void(bool)> callback) { |
| 144 GURL requesting_frame_origin = requesting_frame.GetOrigin(); | 144 GURL requesting_frame_origin = requesting_frame.GetOrigin(); |
| 145 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
| 146 content::BrowserThread::PostTask( | |
| 147 content::BrowserThread::UI, FROM_HERE, | |
| 148 base::Bind( | |
| 149 &ChromeGeolocationPermissionContext::RequestGeolocationPermission, | |
| 150 this, render_process_id, render_view_id, bridge_id, | |
| 151 requesting_frame_origin, user_gesture, callback)); | |
| 152 return; | |
| 153 } | |
| 154 | |
| 155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 156 if (shutting_down_) | 145 if (shutting_down_) |
| 157 return; | 146 return; |
| 158 | 147 |
| 159 content::WebContents* web_contents = | |
| 160 tab_util::GetWebContentsByID(render_process_id, render_view_id); | |
| 161 | |
| 162 WebViewGuest* guest = WebViewGuest::FromWebContents(web_contents); | 148 WebViewGuest* guest = WebViewGuest::FromWebContents(web_contents); |
| 163 if (guest) { | 149 if (guest) { |
| 164 guest->RequestGeolocationPermission(bridge_id, | 150 guest->RequestGeolocationPermission(bridge_id, |
| 165 requesting_frame, | 151 requesting_frame, |
| 166 user_gesture, | 152 user_gesture, |
| 167 callback); | 153 callback); |
| 168 return; | 154 return; |
| 169 } | 155 } |
| 156 |
| 157 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 158 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
| 170 const PermissionRequestID id(render_process_id, render_view_id, bridge_id, 0); | 159 const PermissionRequestID id(render_process_id, render_view_id, bridge_id, 0); |
| 171 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); | 160 ExtensionRegistry* extension_registry = ExtensionRegistry::Get(profile_); |
| 172 if (extension_registry) { | 161 if (extension_registry) { |
| 173 const extensions::Extension* extension = | 162 const extensions::Extension* extension = |
| 174 extension_registry->enabled_extensions().GetExtensionOrAppByURL( | 163 extension_registry->enabled_extensions().GetExtensionOrAppByURL( |
| 175 requesting_frame_origin); | 164 requesting_frame_origin); |
| 176 if (IsExtensionWithPermissionOrSuggestInConsole( | 165 if (IsExtensionWithPermissionOrSuggestInConsole( |
| 177 APIPermission::kGeolocation, extension, | 166 APIPermission::kGeolocation, extension, |
| 178 web_contents->GetRenderViewHost())) { | 167 web_contents->GetRenderViewHost())) { |
| 179 // Make sure the extension is in the calling process. | 168 // Make sure the extension is in the calling process. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 205 << " (geolocation is not supported in popups)"; | 194 << " (geolocation is not supported in popups)"; |
| 206 NotifyPermissionSet(id, requesting_frame_origin, callback, false); | 195 NotifyPermissionSet(id, requesting_frame_origin, callback, false); |
| 207 return; | 196 return; |
| 208 } | 197 } |
| 209 | 198 |
| 210 DecidePermission(web_contents, id, requesting_frame_origin, user_gesture, | 199 DecidePermission(web_contents, id, requesting_frame_origin, user_gesture, |
| 211 embedder, "", callback); | 200 embedder, "", callback); |
| 212 } | 201 } |
| 213 | 202 |
| 214 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( | 203 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
| 215 int render_process_id, | 204 content::WebContents* web_contents, |
| 216 int render_view_id, | |
| 217 int bridge_id, | 205 int bridge_id, |
| 218 const GURL& requesting_frame) { | 206 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 = | 207 WebViewGuest* guest = |
| 237 web_contents ? WebViewGuest::FromWebContents(web_contents) : NULL; | 208 web_contents ? WebViewGuest::FromWebContents(web_contents) : NULL; |
| 238 if (guest) { | 209 if (guest) { |
| 239 guest->CancelGeolocationPermissionRequest(bridge_id); | 210 guest->CancelGeolocationPermissionRequest(bridge_id); |
| 240 return; | 211 return; |
| 241 } | 212 } |
| 242 // TODO(gbillock): cancel permission bubble request. | 213 // TODO(gbillock): cancel permission bubble request. |
| 214 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 215 int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
| 243 CancelPendingInfobarRequest(PermissionRequestID( | 216 CancelPendingInfobarRequest(PermissionRequestID( |
| 244 render_process_id, render_view_id, bridge_id, 0)); | 217 render_process_id, render_view_id, bridge_id, 0)); |
| 245 } | 218 } |
| 246 | 219 |
| 247 void ChromeGeolocationPermissionContext::DecidePermission( | 220 void ChromeGeolocationPermissionContext::DecidePermission( |
| 248 content::WebContents* web_contents, | 221 content::WebContents* web_contents, |
| 249 const PermissionRequestID& id, | 222 const PermissionRequestID& id, |
| 250 const GURL& requesting_frame, | 223 const GURL& requesting_frame, |
| 251 bool user_gesture, | 224 bool user_gesture, |
| 252 const GURL& embedder, | 225 const GURL& embedder, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 320 |
| 348 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest( | 321 void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest( |
| 349 const PermissionRequestID& id) { | 322 const PermissionRequestID& id) { |
| 350 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 323 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 351 if (shutting_down_) | 324 if (shutting_down_) |
| 352 return; | 325 return; |
| 353 | 326 |
| 354 // TODO(gbillock): handle permission bubble cancellation. | 327 // TODO(gbillock): handle permission bubble cancellation. |
| 355 QueueController()->CancelInfoBarRequest(id); | 328 QueueController()->CancelInfoBarRequest(id); |
| 356 } | 329 } |
| OLD | NEW |