| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
| 13 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | |
| 14 #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" | 13 #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" |
| 15 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 16 #include "chrome/browser/renderer_host/render_process_host.h" | 15 #include "chrome/browser/renderer_host/render_process_host.h" |
| 17 #include "chrome/browser/renderer_host/render_view_host.h" | 16 #include "chrome/browser/renderer_host/render_view_host.h" |
| 18 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" | 17 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" |
| 19 #include "chrome/browser/tab_contents/infobar_delegate.h" | 18 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 22 #include "chrome/common/json_value_serializer.h" | 21 #include "chrome/common/json_value_serializer.h" |
| 23 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Profile* profile) | 109 Profile* profile) |
| 111 : profile_(profile) { | 110 : profile_(profile) { |
| 112 } | 111 } |
| 113 | 112 |
| 114 GeolocationPermissionContext::~GeolocationPermissionContext() { | 113 GeolocationPermissionContext::~GeolocationPermissionContext() { |
| 115 } | 114 } |
| 116 | 115 |
| 117 void GeolocationPermissionContext::RequestGeolocationPermission( | 116 void GeolocationPermissionContext::RequestGeolocationPermission( |
| 118 int render_process_id, int render_view_id, int bridge_id, | 117 int render_process_id, int render_view_id, int bridge_id, |
| 119 const GURL& requesting_frame) { | 118 const GURL& requesting_frame) { |
| 120 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { | 119 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 121 ChromeThread::PostTask( | 120 RequestPermissionFromUI(render_process_id, render_view_id, bridge_id, |
| 122 ChromeThread::UI, FROM_HERE, | 121 requesting_frame); |
| 123 NewRunnableMethod(this, | |
| 124 &GeolocationPermissionContext::RequestGeolocationPermission, | |
| 125 render_process_id, render_view_id, bridge_id, requesting_frame)); | |
| 126 return; | |
| 127 } | |
| 128 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 129 | |
| 130 TabContents* tab_contents = | |
| 131 tab_util::GetTabContentsByID(render_process_id, render_view_id); | |
| 132 if (!tab_contents) { | |
| 133 // The tab may have gone away, or the request may not be from a tab at all. | |
| 134 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " | |
| 135 << render_process_id << "," << render_view_id << "," << bridge_id | |
| 136 << " (geolocation is not supported in extensions)"; | |
| 137 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | |
| 138 requesting_frame, false); | |
| 139 return; | |
| 140 } | |
| 141 | |
| 142 GURL embedder = tab_contents->GetURL(); | |
| 143 ContentSetting content_setting = | |
| 144 profile_->GetGeolocationContentSettingsMap()->GetContentSetting( | |
| 145 requesting_frame, embedder); | |
| 146 if (content_setting == CONTENT_SETTING_BLOCK) { | |
| 147 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | |
| 148 requesting_frame, false); | |
| 149 } else if (content_setting == CONTENT_SETTING_ALLOW) { | |
| 150 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | |
| 151 requesting_frame, true); | |
| 152 } else { // setting == ask. Prompt the user. | |
| 153 RequestPermissionFromUI(render_process_id, render_view_id, bridge_id, | |
| 154 requesting_frame); | |
| 155 } | |
| 156 } | 122 } |
| 157 | 123 |
| 158 void GeolocationPermissionContext::SetPermission( | 124 void GeolocationPermissionContext::SetPermission( |
| 159 int render_process_id, int render_view_id, int bridge_id, | 125 int render_process_id, int render_view_id, int bridge_id, |
| 160 const GURL& requesting_frame, bool allowed) { | 126 const GURL& requesting_frame, bool allowed) { |
| 161 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 162 TabContents* tab_contents = | |
| 163 tab_util::GetTabContentsByID(render_process_id, render_view_id); | |
| 164 GURL embedder = tab_contents->GetURL(); | |
| 165 ContentSetting content_setting = | |
| 166 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | |
| 167 profile_->GetGeolocationContentSettingsMap()->SetContentSetting( | |
| 168 requesting_frame.GetOrigin(), embedder.GetOrigin(), content_setting); | |
| 169 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 127 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 170 requesting_frame, allowed); | 128 requesting_frame, allowed); |
| 171 } | 129 } |
| 172 | 130 |
| 173 GeolocationArbitrator* GeolocationPermissionContext::StartUpdatingRequested( | 131 GeolocationArbitrator* GeolocationPermissionContext::StartUpdatingRequested( |
| 174 int render_process_id, int render_view_id, int bridge_id, | 132 int render_process_id, int render_view_id, int bridge_id, |
| 175 const GURL& requesting_frame) { | 133 const GURL& requesting_frame) { |
| 176 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 134 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 177 // TODO(joth): Use requesting_frame parameter to short-circuit the latched | 135 // TODO(joth): Use requesting_frame parameter to short-circuit the latched |
| 178 // permission-denied case, and so avoid starting up location arbitrator. | 136 // permission-denied case, and so avoid starting up location arbitrator. |
| 179 if (!location_arbitrator_) | 137 if (!location_arbitrator_) |
| 180 location_arbitrator_ = GeolocationArbitrator::GetInstance(); | 138 location_arbitrator_ = GeolocationArbitrator::GetInstance(); |
| 181 return location_arbitrator_; | 139 return location_arbitrator_; |
| 182 } | 140 } |
| 183 | 141 |
| 184 void GeolocationPermissionContext::RequestPermissionFromUI( | 142 void GeolocationPermissionContext::RequestPermissionFromUI( |
| 185 int render_process_id, int render_view_id, int bridge_id, | 143 int render_process_id, int render_view_id, int bridge_id, |
| 186 const GURL& requesting_frame) { | 144 const GURL& requesting_frame) { |
| 145 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| 146 ChromeThread::PostTask( |
| 147 ChromeThread::UI, FROM_HERE, |
| 148 NewRunnableMethod(this, |
| 149 &GeolocationPermissionContext::RequestPermissionFromUI, |
| 150 render_process_id, render_view_id, bridge_id, requesting_frame)); |
| 151 return; |
| 152 } |
| 187 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 153 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 188 | 154 |
| 189 TabContents* tab_contents = | 155 TabContents* tab_contents = |
| 190 tab_util::GetTabContentsByID(render_process_id, render_view_id); | 156 tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| 191 if (!tab_contents) { | 157 if (!tab_contents) { |
| 192 // The tab may have gone away, or the request may not be from a tab at all. | 158 // The tab may have gone away, or the request may not be from a tab at all. |
| 193 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " | 159 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " |
| 194 << render_process_id << "," << render_view_id << "," << bridge_id | 160 << render_process_id << "," << render_view_id << "," << bridge_id |
| 195 << " (geolocation is not supported in extensions)"; | 161 << " (geolocation is not supported in extensions)"; |
| 196 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 162 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 197 requesting_frame, false); | 163 requesting_frame, false); |
| 198 return; | 164 return; |
| 199 } | 165 } |
| 200 tab_contents->AddInfoBar(new GeolocationConfirmInfoBarDelegate(tab_contents, | 166 tab_contents->AddInfoBar(new GeolocationConfirmInfoBarDelegate(tab_contents, |
| 201 this, render_process_id, render_view_id, bridge_id, requesting_frame)); | 167 this, render_process_id, render_view_id, bridge_id, requesting_frame)); |
| 202 } | 168 } |
| 203 | 169 |
| 204 void GeolocationPermissionContext::NotifyPermissionSet( | 170 void GeolocationPermissionContext::NotifyPermissionSet( |
| 205 int render_process_id, int render_view_id, int bridge_id, | 171 int render_process_id, int render_view_id, int bridge_id, |
| 206 const GURL& requesting_frame, bool allowed) { | 172 const GURL& requesting_frame, bool allowed) { |
| 173 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| 174 ChromeThread::PostTask( |
| 175 ChromeThread::UI, FROM_HERE, |
| 176 NewRunnableMethod(this, |
| 177 &GeolocationPermissionContext::NotifyPermissionSet, |
| 178 render_process_id, render_view_id, bridge_id, requesting_frame, |
| 179 allowed)); |
| 180 return; |
| 181 } |
| 207 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 182 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 208 | 183 |
| 209 RenderViewHostDelegate::Resource* resource = | 184 RenderViewHostDelegate::Resource* resource = |
| 210 tab_util::GetTabContentsByID(render_process_id, render_view_id); | 185 tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| 211 // TabContents may have gone away (or not exists for extension). | 186 // TabContents may have gone away (or not exists for extension). |
| 212 if (resource) | 187 if (resource) |
| 213 resource->OnGeolocationPermissionSet(requesting_frame, allowed); | 188 resource->OnGeolocationPermissionSet(requesting_frame, allowed); |
| 214 | 189 |
| 215 CallRenderViewHost( | 190 CallRenderViewHost( |
| 216 render_process_id, render_view_id, | 191 render_process_id, render_view_id, |
| 217 &RenderViewHost::Send, | 192 &RenderViewHost::Send, |
| 218 new ViewMsg_Geolocation_PermissionSet(render_view_id, bridge_id, | 193 new ViewMsg_Geolocation_PermissionSet(render_view_id, bridge_id, |
| 219 allowed)); | 194 allowed)); |
| 220 } | 195 } |
| OLD | NEW |