Chromium Code Reviews| 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/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 14 #include "chrome/browser/content_settings/permission_request_id.h" | 15 #include "chrome/browser/content_settings/permission_request_id.h" |
| 15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 16 #include "chrome/browser/extensions/suggest_permission_util.h" | 17 #include "chrome/browser/extensions/suggest_permission_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/tab_contents/tab_util.h" | 19 #include "chrome/browser/tab_contents/tab_util.h" |
| 20 #include "chrome/browser/ui/website_settings/permission_bubble_delegate.h" | |
| 21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 22 #include "chrome/common/pref_names.h" | |
| 19 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 22 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 23 #include "extensions/browser/process_map.h" | 27 #include "extensions/browser/process_map.h" |
| 24 #include "extensions/browser/view_type_utils.h" | 28 #include "extensions/browser/view_type_utils.h" |
| 25 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "grit/generated_resources.h" | |
| 31 #include "net/base/net_util.h" | |
| 32 #include "ui/base/l10n/l10n_util.h" | |
| 26 | 33 |
| 27 using extensions::APIPermission; | 34 using extensions::APIPermission; |
| 28 using extensions::ExtensionRegistry; | 35 using extensions::ExtensionRegistry; |
| 29 | 36 |
| 37 class GeolocationPermissionBubbleDelegate : public PermissionBubbleDelegate { | |
| 38 public: | |
| 39 GeolocationPermissionBubbleDelegate( | |
| 40 ChromeGeolocationPermissionContext* context, | |
|
timvolodine
2014/02/05 12:26:15
indent 4 spaces
Greg Billock
2014/02/05 16:46:38
Done.
| |
| 41 const PermissionRequestID& id, | |
| 42 const GURL& requesting_frame, | |
| 43 base::Callback<void(bool)> callback, | |
| 44 const std::string& display_languages); | |
| 45 virtual ~GeolocationPermissionBubbleDelegate(); | |
| 46 | |
| 47 // PermissionBubbleDelegate: | |
| 48 virtual base::string16 GetMessageText() const OVERRIDE; | |
| 49 virtual base::string16 GetMessageTextFragment() const OVERRIDE; | |
| 50 virtual base::string16 GetAlternateAcceptButtonText() const OVERRIDE; | |
| 51 virtual base::string16 GetAlternateDenyButtonText() const OVERRIDE; | |
| 52 virtual void PermissionGranted() OVERRIDE; | |
| 53 virtual void PermissionDenied() OVERRIDE; | |
| 54 virtual void Cancelled() OVERRIDE; | |
| 55 virtual void RequestFinished() OVERRIDE; | |
| 56 | |
| 57 private: | |
| 58 ChromeGeolocationPermissionContext* context_; | |
| 59 PermissionRequestID id_; | |
| 60 GURL requesting_frame_; | |
| 61 base::Callback<void(bool)> callback_; | |
| 62 std::string display_languages_; | |
| 63 }; | |
| 64 | |
| 65 GeolocationPermissionBubbleDelegate::GeolocationPermissionBubbleDelegate( | |
| 66 ChromeGeolocationPermissionContext* context, | |
| 67 const PermissionRequestID& id, | |
| 68 const GURL& requesting_frame, | |
| 69 base::Callback<void(bool)> callback, | |
| 70 const std::string& display_languages) | |
| 71 : context_(context), | |
| 72 id_(id), | |
| 73 requesting_frame_(requesting_frame), | |
| 74 callback_(callback), | |
| 75 display_languages_(display_languages) {} | |
| 76 | |
| 77 GeolocationPermissionBubbleDelegate::~GeolocationPermissionBubbleDelegate() {} | |
| 78 | |
| 79 base::string16 GeolocationPermissionBubbleDelegate::GetMessageText() const { | |
| 80 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, | |
| 81 net::FormatUrl(requesting_frame_, display_languages_)); | |
| 82 } | |
| 83 | |
| 84 base::string16 | |
| 85 GeolocationPermissionBubbleDelegate::GetMessageTextFragment() const { | |
| 86 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT); | |
| 87 } | |
| 88 | |
| 89 base::string16 | |
| 90 GeolocationPermissionBubbleDelegate::GetAlternateAcceptButtonText() const { | |
| 91 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_ALLOW_BUTTON); | |
| 92 } | |
| 93 | |
| 94 base::string16 | |
| 95 GeolocationPermissionBubbleDelegate::GetAlternateDenyButtonText() const { | |
| 96 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_DENY_BUTTON); | |
| 97 } | |
| 98 | |
| 99 void GeolocationPermissionBubbleDelegate::PermissionGranted() { | |
| 100 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); | |
| 101 } | |
| 102 | |
| 103 void GeolocationPermissionBubbleDelegate::PermissionDenied() { | |
| 104 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); | |
| 105 } | |
| 106 | |
| 107 void GeolocationPermissionBubbleDelegate::Cancelled() { | |
| 108 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); | |
| 109 } | |
| 110 | |
| 111 void GeolocationPermissionBubbleDelegate::RequestFinished() { | |
| 112 delete this; | |
| 113 } | |
| 114 | |
| 115 | |
| 30 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( | 116 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( |
| 31 Profile* profile) | 117 Profile* profile) |
| 32 : profile_(profile), | 118 : profile_(profile), |
| 33 shutting_down_(false) { | 119 shutting_down_(false) { |
| 34 } | 120 } |
| 35 | 121 |
| 36 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { | 122 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { |
| 37 // ChromeGeolocationPermissionContext may be destroyed on either the UI thread | 123 // ChromeGeolocationPermissionContext may be destroyed on either the UI thread |
| 38 // or the IO thread, but the PermissionQueueController must have been | 124 // or the IO thread, but the PermissionQueueController must have been |
| 39 // destroyed on the UI thread. | 125 // destroyed on the UI thread. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 182 |
| 97 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); | 183 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); |
| 98 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) { | 184 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) { |
| 99 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " | 185 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " |
| 100 << requesting_frame_origin << "," << embedder | 186 << requesting_frame_origin << "," << embedder |
| 101 << " (geolocation is not supported in popups)"; | 187 << " (geolocation is not supported in popups)"; |
| 102 NotifyPermissionSet(id, requesting_frame_origin, callback, false); | 188 NotifyPermissionSet(id, requesting_frame_origin, callback, false); |
| 103 return; | 189 return; |
| 104 } | 190 } |
| 105 | 191 |
| 106 DecidePermission(id, requesting_frame_origin, embedder, callback); | 192 DecidePermission(web_contents, id, requesting_frame_origin, |
| 193 embedder, callback); | |
| 107 } | 194 } |
| 108 | 195 |
| 109 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( | 196 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
| 110 int render_process_id, | 197 int render_process_id, |
| 111 int render_view_id, | 198 int render_view_id, |
| 112 int bridge_id, | 199 int bridge_id, |
| 113 const GURL& requesting_frame) { | 200 const GURL& requesting_frame) { |
| 114 CancelPendingInfobarRequest(PermissionRequestID( | 201 CancelPendingInfobarRequest(PermissionRequestID( |
| 115 render_process_id, render_view_id, bridge_id, 0)); | 202 render_process_id, render_view_id, bridge_id, 0)); |
| 116 } | 203 } |
| 117 | 204 |
| 118 void ChromeGeolocationPermissionContext::DecidePermission( | 205 void ChromeGeolocationPermissionContext::DecidePermission( |
| 206 content::WebContents* web_contents, | |
| 119 const PermissionRequestID& id, | 207 const PermissionRequestID& id, |
| 120 const GURL& requesting_frame, | 208 const GURL& requesting_frame, |
| 121 const GURL& embedder, | 209 const GURL& embedder, |
| 122 base::Callback<void(bool)> callback) { | 210 base::Callback<void(bool)> callback) { |
| 123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 211 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 124 | 212 |
| 125 ContentSetting content_setting = | 213 ContentSetting content_setting = |
| 126 profile_->GetHostContentSettingsMap()->GetContentSetting( | 214 profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 127 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION, | 215 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 128 std::string()); | 216 std::string()); |
| 129 switch (content_setting) { | 217 switch (content_setting) { |
| 130 case CONTENT_SETTING_BLOCK: | 218 case CONTENT_SETTING_BLOCK: |
| 131 PermissionDecided(id, requesting_frame, embedder, callback, false); | 219 PermissionDecided(id, requesting_frame, embedder, callback, false); |
| 132 break; | 220 break; |
| 133 case CONTENT_SETTING_ALLOW: | 221 case CONTENT_SETTING_ALLOW: |
| 134 PermissionDecided(id, requesting_frame, embedder, callback, true); | 222 PermissionDecided(id, requesting_frame, embedder, callback, true); |
| 135 break; | 223 break; |
| 136 default: | 224 default: |
| 137 // setting == ask. Prompt the user. | 225 if (PermissionBubbleManager::Enabled()) { |
| 138 QueueController()->CreateInfoBarRequest( | 226 PermissionBubbleManager* mgr = |
| 139 id, requesting_frame, embedder, base::Bind( | 227 PermissionBubbleManager::FromWebContents(web_contents); |
| 140 &ChromeGeolocationPermissionContext::NotifyPermissionSet, | 228 mgr->AddPermissionBubbleDelegate( |
| 141 base::Unretained(this), id, requesting_frame, callback)); | 229 new GeolocationPermissionBubbleDelegate( |
| 230 this, id, requesting_frame, callback, | |
| 231 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); | |
| 232 } else { | |
| 233 // setting == ask. Prompt the user. | |
| 234 QueueController()->CreateInfoBarRequest( | |
| 235 id, requesting_frame, embedder, base::Bind( | |
| 236 &ChromeGeolocationPermissionContext::NotifyPermissionSet, | |
| 237 base::Unretained(this), id, requesting_frame, callback)); | |
| 238 } | |
| 142 } | 239 } |
| 143 } | 240 } |
| 144 | 241 |
| 145 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { | 242 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { |
| 146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 243 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 147 permission_queue_controller_.reset(); | 244 permission_queue_controller_.reset(); |
| 148 shutting_down_ = true; | 245 shutting_down_ = true; |
| 149 } | 246 } |
| 150 | 247 |
| 151 void ChromeGeolocationPermissionContext::PermissionDecided( | 248 void ChromeGeolocationPermissionContext::PermissionDecided( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 base::Bind( | 297 base::Bind( |
| 201 &ChromeGeolocationPermissionContext::CancelPendingInfobarRequest, | 298 &ChromeGeolocationPermissionContext::CancelPendingInfobarRequest, |
| 202 this, id)); | 299 this, id)); |
| 203 return; | 300 return; |
| 204 } | 301 } |
| 205 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 302 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 206 if (shutting_down_) | 303 if (shutting_down_) |
| 207 return; | 304 return; |
| 208 QueueController()->CancelInfoBarRequest(id); | 305 QueueController()->CancelInfoBarRequest(id); |
| 209 } | 306 } |
| OLD | NEW |