| 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // destroyed on the UI thread. | 38 // destroyed on the UI thread. |
| 39 DCHECK(!permission_queue_controller_.get()); | 39 DCHECK(!permission_queue_controller_.get()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( | 42 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( |
| 43 int render_process_id, | 43 int render_process_id, |
| 44 int render_view_id, | 44 int render_view_id, |
| 45 int bridge_id, | 45 int bridge_id, |
| 46 const GURL& requesting_frame, | 46 const GURL& requesting_frame, |
| 47 base::Callback<void(bool)> callback) { | 47 base::Callback<void(bool)> callback) { |
| 48 GURL requesting_frame_origin = requesting_frame.GetOrigin(); |
| 48 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 49 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 49 content::BrowserThread::PostTask( | 50 content::BrowserThread::PostTask( |
| 50 content::BrowserThread::UI, FROM_HERE, | 51 content::BrowserThread::UI, FROM_HERE, |
| 51 base::Bind( | 52 base::Bind( |
| 52 &ChromeGeolocationPermissionContext::RequestGeolocationPermission, | 53 &ChromeGeolocationPermissionContext::RequestGeolocationPermission, |
| 53 this, render_process_id, render_view_id, bridge_id, | 54 this, render_process_id, render_view_id, bridge_id, |
| 54 requesting_frame, callback)); | 55 requesting_frame_origin, callback)); |
| 55 return; | 56 return; |
| 56 } | 57 } |
| 57 | 58 |
| 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 59 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 59 if (shutting_down_) | 60 if (shutting_down_) |
| 60 return; | 61 return; |
| 61 | 62 |
| 62 content::WebContents* web_contents = | 63 content::WebContents* web_contents = |
| 63 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 64 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 64 const PermissionRequestID id(render_process_id, render_view_id, | 65 const PermissionRequestID id(render_process_id, render_view_id, |
| 65 bridge_id); | 66 bridge_id); |
| 66 ExtensionService* extension_service = | 67 ExtensionService* extension_service = |
| 67 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 68 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 68 if (extension_service) { | 69 if (extension_service) { |
| 69 const extensions::Extension* extension = | 70 const extensions::Extension* extension = |
| 70 extension_service->extensions()->GetExtensionOrAppByURL( | 71 extension_service->extensions()->GetExtensionOrAppByURL( |
| 71 requesting_frame); | 72 requesting_frame_origin); |
| 72 if (IsExtensionWithPermissionOrSuggestInConsole(APIPermission::kGeolocation, | 73 if (IsExtensionWithPermissionOrSuggestInConsole(APIPermission::kGeolocation, |
| 73 extension, | 74 extension, |
| 74 profile_)) { | 75 profile_)) { |
| 75 // Make sure the extension is in the calling process. | 76 // Make sure the extension is in the calling process. |
| 76 if (extension_service->process_map()->Contains(extension->id(), | 77 if (extension_service->process_map()->Contains(extension->id(), |
| 77 id.render_process_id())) { | 78 id.render_process_id())) { |
| 78 NotifyPermissionSet(id, requesting_frame, callback, true); | 79 NotifyPermissionSet(id, requesting_frame_origin, callback, true); |
| 79 return; | 80 return; |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 | 84 |
| 84 if (extensions::GetViewType(web_contents) != | 85 if (extensions::GetViewType(web_contents) != |
| 85 extensions::VIEW_TYPE_TAB_CONTENTS) { | 86 extensions::VIEW_TYPE_TAB_CONTENTS) { |
| 86 // The tab may have gone away, or the request may not be from a tab at all. | 87 // The tab may have gone away, or the request may not be from a tab at all. |
| 87 // TODO(mpcomplete): the request could be from a background page or | 88 // TODO(mpcomplete): the request could be from a background page or |
| 88 // extension popup (web_contents will have a different ViewType). But why do | 89 // extension popup (web_contents will have a different ViewType). But why do |
| 89 // we care? Shouldn't we still put an infobar up in the current tab? | 90 // we care? Shouldn't we still put an infobar up in the current tab? |
| 90 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " | 91 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " |
| 91 << id.ToString() | 92 << id.ToString() |
| 92 << " (can't prompt user without a visible tab)"; | 93 << " (can't prompt user without a visible tab)"; |
| 93 NotifyPermissionSet(id, requesting_frame, callback, false); | 94 NotifyPermissionSet(id, requesting_frame_origin, callback, false); |
| 94 return; | 95 return; |
| 95 } | 96 } |
| 96 | 97 |
| 97 GURL embedder = web_contents->GetURL(); | 98 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); |
| 98 if (!requesting_frame.is_valid() || !embedder.is_valid()) { | 99 if (!requesting_frame_origin.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_origin << "," << 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_origin, callback, false); |
| 103 return; | 104 return; |
| 104 } | 105 } |
| 105 | 106 |
| 106 DecidePermission(id, requesting_frame, embedder, callback); | 107 DecidePermission(id, requesting_frame_origin, embedder, callback); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( | 110 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
| 110 int render_process_id, | 111 int render_process_id, |
| 111 int render_view_id, | 112 int render_view_id, |
| 112 int bridge_id, | 113 int bridge_id, |
| 113 const GURL& requesting_frame) { | 114 const GURL& requesting_frame) { |
| 114 CancelPendingInfoBarRequest(PermissionRequestID( | 115 CancelPendingInfoBarRequest(PermissionRequestID( |
| 115 render_process_id, render_view_id, bridge_id)); | 116 render_process_id, render_view_id, bridge_id)); |
| 116 } | 117 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 base::Bind( | 201 base::Bind( |
| 201 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, | 202 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, |
| 202 this, id)); | 203 this, id)); |
| 203 return; | 204 return; |
| 204 } | 205 } |
| 205 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 206 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 206 if (shutting_down_) | 207 if (shutting_down_) |
| 207 return; | 208 return; |
| 208 QueueController()->CancelInfoBarRequest(id); | 209 QueueController()->CancelInfoBarRequest(id); |
| 209 } | 210 } |
| OLD | NEW |