Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/geolocation/chrome_geolocation_permission_context.cc

Issue 147543004: [Geolocation] Add permission bubble client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android, rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_manager.h"
21 #include "chrome/browser/ui/website_settings/permission_bubble_request.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 GeolocationPermissionRequest : public PermissionBubbleRequest {
38 public:
39 GeolocationPermissionRequest(
40 ChromeGeolocationPermissionContext* context,
41 const PermissionRequestID& id,
42 const GURL& requesting_frame,
43 base::Callback<void(bool)> callback,
44 const std::string& display_languages);
45 virtual ~GeolocationPermissionRequest();
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 GeolocationPermissionRequest::GeolocationPermissionRequest(
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 GeolocationPermissionRequest::~GeolocationPermissionRequest() {}
78
79 base::string16 GeolocationPermissionRequest::GetMessageText() const {
80 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION,
81 net::FormatUrl(requesting_frame_, display_languages_));
82 }
83
84 base::string16 GeolocationPermissionRequest::GetMessageTextFragment() const {
85 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT);
86 }
87
88 base::string16
89 GeolocationPermissionRequest::GetAlternateAcceptButtonText() const {
90 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_ALLOW_BUTTON);
91 }
92
93 base::string16
94 GeolocationPermissionRequest::GetAlternateDenyButtonText() const {
95 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_DENY_BUTTON);
96 }
97
98 void GeolocationPermissionRequest::PermissionGranted() {
99 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true);
100 }
101
102 void GeolocationPermissionRequest::PermissionDenied() {
103 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
104 }
105
106 void GeolocationPermissionRequest::Cancelled() {
107 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
108 }
109
110 void GeolocationPermissionRequest::RequestFinished() {
111 delete this;
112 }
113
114
30 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( 115 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext(
31 Profile* profile) 116 Profile* profile)
32 : profile_(profile), 117 : profile_(profile),
33 shutting_down_(false) { 118 shutting_down_(false) {
34 } 119 }
35 120
36 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { 121 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() {
37 // ChromeGeolocationPermissionContext may be destroyed on either the UI thread 122 // ChromeGeolocationPermissionContext may be destroyed on either the UI thread
38 // or the IO thread, but the PermissionQueueController must have been 123 // or the IO thread, but the PermissionQueueController must have been
39 // destroyed on the UI thread. 124 // destroyed on the UI thread.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 181
97 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); 182 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin();
98 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) { 183 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) {
99 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " 184 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: "
100 << requesting_frame_origin << "," << embedder 185 << requesting_frame_origin << "," << embedder
101 << " (geolocation is not supported in popups)"; 186 << " (geolocation is not supported in popups)";
102 NotifyPermissionSet(id, requesting_frame_origin, callback, false); 187 NotifyPermissionSet(id, requesting_frame_origin, callback, false);
103 return; 188 return;
104 } 189 }
105 190
106 DecidePermission(id, requesting_frame_origin, embedder, callback); 191 DecidePermission(web_contents, id, requesting_frame_origin,
192 embedder, callback);
107 } 193 }
108 194
109 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( 195 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
110 int render_process_id, 196 int render_process_id,
111 int render_view_id, 197 int render_view_id,
112 int bridge_id, 198 int bridge_id,
113 const GURL& requesting_frame) { 199 const GURL& requesting_frame) {
114 CancelPendingInfobarRequest(PermissionRequestID( 200 CancelPendingInfobarRequest(PermissionRequestID(
115 render_process_id, render_view_id, bridge_id, 0)); 201 render_process_id, render_view_id, bridge_id, 0));
116 } 202 }
117 203
118 void ChromeGeolocationPermissionContext::DecidePermission( 204 void ChromeGeolocationPermissionContext::DecidePermission(
205 content::WebContents* web_contents,
119 const PermissionRequestID& id, 206 const PermissionRequestID& id,
120 const GURL& requesting_frame, 207 const GURL& requesting_frame,
121 const GURL& embedder, 208 const GURL& embedder,
122 base::Callback<void(bool)> callback) { 209 base::Callback<void(bool)> callback) {
123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 210 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
124 211
125 ContentSetting content_setting = 212 ContentSetting content_setting =
126 profile_->GetHostContentSettingsMap()->GetContentSetting( 213 profile_->GetHostContentSettingsMap()->GetContentSetting(
127 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION, 214 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION,
128 std::string()); 215 std::string());
129 switch (content_setting) { 216 switch (content_setting) {
130 case CONTENT_SETTING_BLOCK: 217 case CONTENT_SETTING_BLOCK:
131 PermissionDecided(id, requesting_frame, embedder, callback, false); 218 PermissionDecided(id, requesting_frame, embedder, callback, false);
132 break; 219 break;
133 case CONTENT_SETTING_ALLOW: 220 case CONTENT_SETTING_ALLOW:
134 PermissionDecided(id, requesting_frame, embedder, callback, true); 221 PermissionDecided(id, requesting_frame, embedder, callback, true);
135 break; 222 break;
136 default: 223 default:
137 // setting == ask. Prompt the user. 224 if (PermissionBubbleManager::Enabled()) {
138 QueueController()->CreateInfoBarRequest( 225 PermissionBubbleManager* mgr =
139 id, requesting_frame, embedder, base::Bind( 226 PermissionBubbleManager::FromWebContents(web_contents);
140 &ChromeGeolocationPermissionContext::NotifyPermissionSet, 227 mgr->AddRequest(new GeolocationPermissionRequest(
141 base::Unretained(this), id, requesting_frame, callback)); 228 this, id, requesting_frame, callback,
229 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)));
230 } else {
231 // setting == ask. Prompt the user.
232 QueueController()->CreateInfoBarRequest(
233 id, requesting_frame, embedder, base::Bind(
234 &ChromeGeolocationPermissionContext::NotifyPermissionSet,
235 base::Unretained(this), id, requesting_frame, callback));
236 }
142 } 237 }
143 } 238 }
144 239
145 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { 240 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() {
146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 241 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
147 permission_queue_controller_.reset(); 242 permission_queue_controller_.reset();
148 shutting_down_ = true; 243 shutting_down_ = true;
149 } 244 }
150 245
151 void ChromeGeolocationPermissionContext::PermissionDecided( 246 void ChromeGeolocationPermissionContext::PermissionDecided(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 content::BrowserThread::PostTask( 293 content::BrowserThread::PostTask(
199 content::BrowserThread::UI, FROM_HERE, 294 content::BrowserThread::UI, FROM_HERE,
200 base::Bind( 295 base::Bind(
201 &ChromeGeolocationPermissionContext::CancelPendingInfobarRequest, 296 &ChromeGeolocationPermissionContext::CancelPendingInfobarRequest,
202 this, id)); 297 this, id));
203 return; 298 return;
204 } 299 }
205 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 300 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
206 if (shutting_down_) 301 if (shutting_down_)
207 return; 302 return;
303
304 // TODO(gbillock): handle permission bubble cancellation.
208 QueueController()->CancelInfoBarRequest(id); 305 QueueController()->CancelInfoBarRequest(id);
209 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698