| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 21 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 27 #include "extensions/browser/process_map.h" | 27 #include "extensions/browser/process_map.h" |
| 28 #include "extensions/browser/view_type_utils.h" | 28 #include "extensions/browser/view_type_utils.h" |
| 29 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 31 #include "grit/theme_resources.h" |
| 31 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 | 34 |
| 34 using extensions::APIPermission; | 35 using extensions::APIPermission; |
| 35 using extensions::ExtensionRegistry; | 36 using extensions::ExtensionRegistry; |
| 36 | 37 |
| 37 class GeolocationPermissionRequest : public PermissionBubbleRequest { | 38 class GeolocationPermissionRequest : public PermissionBubbleRequest { |
| 38 public: | 39 public: |
| 39 GeolocationPermissionRequest( | 40 GeolocationPermissionRequest( |
| 40 ChromeGeolocationPermissionContext* context, | 41 ChromeGeolocationPermissionContext* context, |
| 41 const PermissionRequestID& id, | 42 const PermissionRequestID& id, |
| 42 const GURL& requesting_frame, | 43 const GURL& requesting_frame, |
| 43 base::Callback<void(bool)> callback, | 44 base::Callback<void(bool)> callback, |
| 44 const std::string& display_languages); | 45 const std::string& display_languages); |
| 45 virtual ~GeolocationPermissionRequest(); | 46 virtual ~GeolocationPermissionRequest(); |
| 46 | 47 |
| 47 // PermissionBubbleDelegate: | 48 // PermissionBubbleDelegate: |
| 49 virtual int GetIconID() const OVERRIDE; |
| 48 virtual base::string16 GetMessageText() const OVERRIDE; | 50 virtual base::string16 GetMessageText() const OVERRIDE; |
| 49 virtual base::string16 GetMessageTextFragment() const OVERRIDE; | 51 virtual base::string16 GetMessageTextFragment() const OVERRIDE; |
| 50 virtual base::string16 GetAlternateAcceptButtonText() const OVERRIDE; | 52 virtual bool HasUserGesture() const OVERRIDE; |
| 51 virtual base::string16 GetAlternateDenyButtonText() const OVERRIDE; | 53 virtual GURL GetRequestingHostname() const OVERRIDE; |
| 52 virtual void PermissionGranted() OVERRIDE; | 54 virtual void PermissionGranted() OVERRIDE; |
| 53 virtual void PermissionDenied() OVERRIDE; | 55 virtual void PermissionDenied() OVERRIDE; |
| 54 virtual void Cancelled() OVERRIDE; | 56 virtual void Cancelled() OVERRIDE; |
| 55 virtual void RequestFinished() OVERRIDE; | 57 virtual void RequestFinished() OVERRIDE; |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 ChromeGeolocationPermissionContext* context_; | 60 ChromeGeolocationPermissionContext* context_; |
| 59 PermissionRequestID id_; | 61 PermissionRequestID id_; |
| 60 GURL requesting_frame_; | 62 GURL requesting_frame_; |
| 61 base::Callback<void(bool)> callback_; | 63 base::Callback<void(bool)> callback_; |
| 62 std::string display_languages_; | 64 std::string display_languages_; |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 GeolocationPermissionRequest::GeolocationPermissionRequest( | 67 GeolocationPermissionRequest::GeolocationPermissionRequest( |
| 66 ChromeGeolocationPermissionContext* context, | 68 ChromeGeolocationPermissionContext* context, |
| 67 const PermissionRequestID& id, | 69 const PermissionRequestID& id, |
| 68 const GURL& requesting_frame, | 70 const GURL& requesting_frame, |
| 69 base::Callback<void(bool)> callback, | 71 base::Callback<void(bool)> callback, |
| 70 const std::string& display_languages) | 72 const std::string& display_languages) |
| 71 : context_(context), | 73 : context_(context), |
| 72 id_(id), | 74 id_(id), |
| 73 requesting_frame_(requesting_frame), | 75 requesting_frame_(requesting_frame), |
| 74 callback_(callback), | 76 callback_(callback), |
| 75 display_languages_(display_languages) {} | 77 display_languages_(display_languages) {} |
| 76 | 78 |
| 77 GeolocationPermissionRequest::~GeolocationPermissionRequest() {} | 79 GeolocationPermissionRequest::~GeolocationPermissionRequest() {} |
| 78 | 80 |
| 81 int GeolocationPermissionRequest::GetIconID() const { |
| 82 return IDR_GEOLOCATION_INFOBAR_ICON; |
| 83 } |
| 84 |
| 79 base::string16 GeolocationPermissionRequest::GetMessageText() const { | 85 base::string16 GeolocationPermissionRequest::GetMessageText() const { |
| 80 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, | 86 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, |
| 81 net::FormatUrl(requesting_frame_, display_languages_)); | 87 net::FormatUrl(requesting_frame_, display_languages_)); |
| 82 } | 88 } |
| 83 | 89 |
| 84 base::string16 GeolocationPermissionRequest::GetMessageTextFragment() const { | 90 base::string16 GeolocationPermissionRequest::GetMessageTextFragment() const { |
| 85 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT); | 91 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT); |
| 86 } | 92 } |
| 87 | 93 |
| 88 base::string16 | 94 bool GeolocationPermissionRequest::HasUserGesture() const { |
| 89 GeolocationPermissionRequest::GetAlternateAcceptButtonText() const { | 95 // TODO(gbillock): plumb this through from GeolocationDispatcher. |
| 90 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_ALLOW_BUTTON); | 96 return false; |
| 91 } | 97 } |
| 92 | 98 |
| 93 base::string16 | 99 GURL GeolocationPermissionRequest::GetRequestingHostname() const { |
| 94 GeolocationPermissionRequest::GetAlternateDenyButtonText() const { | 100 return requesting_frame_; |
| 95 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_DENY_BUTTON); | |
| 96 } | 101 } |
| 97 | 102 |
| 98 void GeolocationPermissionRequest::PermissionGranted() { | 103 void GeolocationPermissionRequest::PermissionGranted() { |
| 99 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); | 104 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void GeolocationPermissionRequest::PermissionDenied() { | 107 void GeolocationPermissionRequest::PermissionDenied() { |
| 103 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); | 108 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false); |
| 104 } | 109 } |
| 105 | 110 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 195 |
| 191 DecidePermission(web_contents, id, requesting_frame_origin, | 196 DecidePermission(web_contents, id, requesting_frame_origin, |
| 192 embedder, callback); | 197 embedder, callback); |
| 193 } | 198 } |
| 194 | 199 |
| 195 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( | 200 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
| 196 int render_process_id, | 201 int render_process_id, |
| 197 int render_view_id, | 202 int render_view_id, |
| 198 int bridge_id, | 203 int bridge_id, |
| 199 const GURL& requesting_frame) { | 204 const GURL& requesting_frame) { |
| 205 // TODO(gbillock): cancel permission bubble request. |
| 200 CancelPendingInfobarRequest(PermissionRequestID( | 206 CancelPendingInfobarRequest(PermissionRequestID( |
| 201 render_process_id, render_view_id, bridge_id, 0)); | 207 render_process_id, render_view_id, bridge_id, 0)); |
| 202 } | 208 } |
| 203 | 209 |
| 204 void ChromeGeolocationPermissionContext::DecidePermission( | 210 void ChromeGeolocationPermissionContext::DecidePermission( |
| 205 content::WebContents* web_contents, | 211 content::WebContents* web_contents, |
| 206 const PermissionRequestID& id, | 212 const PermissionRequestID& id, |
| 207 const GURL& requesting_frame, | 213 const GURL& requesting_frame, |
| 208 const GURL& embedder, | 214 const GURL& embedder, |
| 209 base::Callback<void(bool)> callback) { | 215 base::Callback<void(bool)> callback) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 this, id)); | 303 this, id)); |
| 298 return; | 304 return; |
| 299 } | 305 } |
| 300 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 306 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 301 if (shutting_down_) | 307 if (shutting_down_) |
| 302 return; | 308 return; |
| 303 | 309 |
| 304 // TODO(gbillock): handle permission bubble cancellation. | 310 // TODO(gbillock): handle permission bubble cancellation. |
| 305 QueueController()->CancelInfoBarRequest(id); | 311 QueueController()->CancelInfoBarRequest(id); |
| 306 } | 312 } |
| OLD | NEW |