Chromium Code Reviews| 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" | |
| 13 #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" | 14 #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" |
| 14 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/renderer_host/render_process_host.h" | 16 #include "chrome/browser/renderer_host/render_process_host.h" |
| 16 #include "chrome/browser/renderer_host/render_view_host.h" | 17 #include "chrome/browser/renderer_host/render_view_host.h" |
| 17 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" | 18 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" |
| 18 #include "chrome/browser/tab_contents/infobar_delegate.h" | 19 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 21 #include "chrome/common/json_value_serializer.h" | 22 #include "chrome/common/json_value_serializer.h" |
| 22 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 Profile* profile) | 110 Profile* profile) |
| 110 : profile_(profile) { | 111 : profile_(profile) { |
| 111 } | 112 } |
| 112 | 113 |
| 113 GeolocationPermissionContext::~GeolocationPermissionContext() { | 114 GeolocationPermissionContext::~GeolocationPermissionContext() { |
| 114 } | 115 } |
| 115 | 116 |
| 116 void GeolocationPermissionContext::RequestGeolocationPermission( | 117 void GeolocationPermissionContext::RequestGeolocationPermission( |
| 117 int render_process_id, int render_view_id, int bridge_id, | 118 int render_process_id, int render_view_id, int bridge_id, |
| 118 const GURL& requesting_frame) { | 119 const GURL& requesting_frame) { |
| 119 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 120 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| 120 RequestPermissionFromUI(render_process_id, render_view_id, bridge_id, | 121 ChromeThread::PostTask( |
| 121 requesting_frame); | 122 ChromeThread::UI, FROM_HERE, |
| 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 } | |
| 122 } | 156 } |
| 123 | 157 |
| 124 void GeolocationPermissionContext::SetPermission( | 158 void GeolocationPermissionContext::SetPermission( |
| 125 int render_process_id, int render_view_id, int bridge_id, | 159 int render_process_id, int render_view_id, int bridge_id, |
| 126 const GURL& requesting_frame, bool allowed) { | 160 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); | |
|
joth
2010/03/26 13:53:06
should we have a check / if on tab_contents here?
bulach
2010/03/26 14:22:04
I don't think it's needed: this is called by the i
| |
| 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); | |
| 127 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 169 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 128 requesting_frame, allowed); | 170 requesting_frame, allowed); |
| 129 } | 171 } |
| 130 | 172 |
| 131 GeolocationArbitrator* GeolocationPermissionContext::StartUpdatingRequested( | 173 GeolocationArbitrator* GeolocationPermissionContext::StartUpdatingRequested( |
| 132 int render_process_id, int render_view_id, int bridge_id, | 174 int render_process_id, int render_view_id, int bridge_id, |
| 133 const GURL& requesting_frame) { | 175 const GURL& requesting_frame) { |
| 134 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 176 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 135 // TODO(joth): Use requesting_frame parameter to short-circuit the latched | 177 // TODO(joth): Use requesting_frame parameter to short-circuit the latched |
| 136 // permission-denied case, and so avoid starting up location arbitrator. | 178 // permission-denied case, and so avoid starting up location arbitrator. |
| 137 if (!location_arbitrator_) | 179 if (!location_arbitrator_) |
| 138 location_arbitrator_ = GeolocationArbitrator::GetInstance(); | 180 location_arbitrator_ = GeolocationArbitrator::GetInstance(); |
| 139 return location_arbitrator_; | 181 return location_arbitrator_; |
| 140 } | 182 } |
| 141 | 183 |
| 142 void GeolocationPermissionContext::RequestPermissionFromUI( | 184 void GeolocationPermissionContext::RequestPermissionFromUI( |
| 143 int render_process_id, int render_view_id, int bridge_id, | 185 int render_process_id, int render_view_id, int bridge_id, |
| 144 const GURL& requesting_frame) { | 186 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 } | |
| 153 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 187 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 154 | 188 |
| 155 TabContents* tab_contents = | 189 TabContents* tab_contents = |
| 156 tab_util::GetTabContentsByID(render_process_id, render_view_id); | 190 tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| 157 if (!tab_contents) { | 191 if (!tab_contents) { |
| 158 // The tab may have gone away, or the request may not be from a tab at all. | 192 // The tab may have gone away, or the request may not be from a tab at all. |
| 159 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " | 193 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " |
| 160 << render_process_id << "," << render_view_id << "," << bridge_id | 194 << render_process_id << "," << render_view_id << "," << bridge_id |
| 161 << " (geolocation is not supported in extensions)"; | 195 << " (geolocation is not supported in extensions)"; |
| 162 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, | 196 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, |
| 163 requesting_frame, false); | 197 requesting_frame, false); |
| 164 return; | 198 return; |
| 165 } | 199 } |
| 166 tab_contents->AddInfoBar(new GeolocationConfirmInfoBarDelegate(tab_contents, | 200 tab_contents->AddInfoBar(new GeolocationConfirmInfoBarDelegate(tab_contents, |
| 167 this, render_process_id, render_view_id, bridge_id, requesting_frame)); | 201 this, render_process_id, render_view_id, bridge_id, requesting_frame)); |
| 168 } | 202 } |
| 169 | 203 |
| 170 void GeolocationPermissionContext::NotifyPermissionSet( | 204 void GeolocationPermissionContext::NotifyPermissionSet( |
| 171 int render_process_id, int render_view_id, int bridge_id, | 205 int render_process_id, int render_view_id, int bridge_id, |
| 172 const GURL& requesting_frame, bool allowed) { | 206 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 } | |
| 182 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 207 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 183 | 208 |
| 184 RenderViewHostDelegate::Resource* resource = | 209 RenderViewHostDelegate::Resource* resource = |
| 185 tab_util::GetTabContentsByID(render_process_id, render_view_id); | 210 tab_util::GetTabContentsByID(render_process_id, render_view_id); |
| 186 // TabContents may have gone away (or not exists for extension). | 211 // TabContents may have gone away (or not exists for extension). |
| 187 if (resource) | 212 if (resource) |
| 188 resource->OnGeolocationPermissionSet(requesting_frame, allowed); | 213 resource->OnGeolocationPermissionSet(requesting_frame, allowed); |
| 189 | 214 |
| 190 CallRenderViewHost( | 215 CallRenderViewHost( |
| 191 render_process_id, render_view_id, | 216 render_process_id, render_view_id, |
| 192 &RenderViewHost::Send, | 217 &RenderViewHost::Send, |
| 193 new ViewMsg_Geolocation_PermissionSet(render_view_id, bridge_id, | 218 new ViewMsg_Geolocation_PermissionSet(render_view_id, bridge_id, |
| 194 allowed)); | 219 allowed)); |
| 195 } | 220 } |
| OLD | NEW |