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

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

Issue 185813004: [Geolocation] Attach user gesture indicator to permission request call. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch android Created 6 years, 8 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
(...skipping 23 matching lines...) Expand all
34 34
35 using extensions::APIPermission; 35 using extensions::APIPermission;
36 using extensions::ExtensionRegistry; 36 using extensions::ExtensionRegistry;
37 37
38 class GeolocationPermissionRequest : public PermissionBubbleRequest { 38 class GeolocationPermissionRequest : public PermissionBubbleRequest {
39 public: 39 public:
40 GeolocationPermissionRequest( 40 GeolocationPermissionRequest(
41 ChromeGeolocationPermissionContext* context, 41 ChromeGeolocationPermissionContext* context,
42 const PermissionRequestID& id, 42 const PermissionRequestID& id,
43 const GURL& requesting_frame, 43 const GURL& requesting_frame,
44 bool user_gesture,
44 base::Callback<void(bool)> callback, 45 base::Callback<void(bool)> callback,
45 const std::string& display_languages); 46 const std::string& display_languages);
46 virtual ~GeolocationPermissionRequest(); 47 virtual ~GeolocationPermissionRequest();
47 48
48 // PermissionBubbleDelegate: 49 // PermissionBubbleDelegate:
49 virtual int GetIconID() const OVERRIDE; 50 virtual int GetIconID() const OVERRIDE;
50 virtual base::string16 GetMessageText() const OVERRIDE; 51 virtual base::string16 GetMessageText() const OVERRIDE;
51 virtual base::string16 GetMessageTextFragment() const OVERRIDE; 52 virtual base::string16 GetMessageTextFragment() const OVERRIDE;
52 virtual bool HasUserGesture() const OVERRIDE; 53 virtual bool HasUserGesture() const OVERRIDE;
53 virtual GURL GetRequestingHostname() const OVERRIDE; 54 virtual GURL GetRequestingHostname() const OVERRIDE;
54 virtual void PermissionGranted() OVERRIDE; 55 virtual void PermissionGranted() OVERRIDE;
55 virtual void PermissionDenied() OVERRIDE; 56 virtual void PermissionDenied() OVERRIDE;
56 virtual void Cancelled() OVERRIDE; 57 virtual void Cancelled() OVERRIDE;
57 virtual void RequestFinished() OVERRIDE; 58 virtual void RequestFinished() OVERRIDE;
58 59
59 private: 60 private:
60 ChromeGeolocationPermissionContext* context_; 61 ChromeGeolocationPermissionContext* context_;
61 PermissionRequestID id_; 62 PermissionRequestID id_;
62 GURL requesting_frame_; 63 GURL requesting_frame_;
64 bool user_gesture_;
63 base::Callback<void(bool)> callback_; 65 base::Callback<void(bool)> callback_;
64 std::string display_languages_; 66 std::string display_languages_;
65 }; 67 };
66 68
67 GeolocationPermissionRequest::GeolocationPermissionRequest( 69 GeolocationPermissionRequest::GeolocationPermissionRequest(
68 ChromeGeolocationPermissionContext* context, 70 ChromeGeolocationPermissionContext* context,
69 const PermissionRequestID& id, 71 const PermissionRequestID& id,
70 const GURL& requesting_frame, 72 const GURL& requesting_frame,
73 bool user_gesture,
71 base::Callback<void(bool)> callback, 74 base::Callback<void(bool)> callback,
72 const std::string& display_languages) 75 const std::string& display_languages)
73 : context_(context), 76 : context_(context),
74 id_(id), 77 id_(id),
75 requesting_frame_(requesting_frame), 78 requesting_frame_(requesting_frame),
79 user_gesture_(user_gesture),
76 callback_(callback), 80 callback_(callback),
77 display_languages_(display_languages) {} 81 display_languages_(display_languages) {}
78 82
79 GeolocationPermissionRequest::~GeolocationPermissionRequest() {} 83 GeolocationPermissionRequest::~GeolocationPermissionRequest() {}
80 84
81 int GeolocationPermissionRequest::GetIconID() const { 85 int GeolocationPermissionRequest::GetIconID() const {
82 return IDR_INFOBAR_GEOLOCATION; 86 return IDR_INFOBAR_GEOLOCATION;
83 } 87 }
84 88
85 base::string16 GeolocationPermissionRequest::GetMessageText() const { 89 base::string16 GeolocationPermissionRequest::GetMessageText() const {
86 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION, 90 return l10n_util::GetStringFUTF16(IDS_GEOLOCATION_INFOBAR_QUESTION,
87 net::FormatUrl(requesting_frame_, display_languages_)); 91 net::FormatUrl(requesting_frame_, display_languages_));
88 } 92 }
89 93
90 base::string16 GeolocationPermissionRequest::GetMessageTextFragment() const { 94 base::string16 GeolocationPermissionRequest::GetMessageTextFragment() const {
91 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT); 95 return l10n_util::GetStringUTF16(IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT);
92 } 96 }
93 97
94 bool GeolocationPermissionRequest::HasUserGesture() const { 98 bool GeolocationPermissionRequest::HasUserGesture() const {
95 // TODO(gbillock): plumb this through from GeolocationDispatcher. 99 return user_gesture_;
96 return false;
97 } 100 }
98 101
99 GURL GeolocationPermissionRequest::GetRequestingHostname() const { 102 GURL GeolocationPermissionRequest::GetRequestingHostname() const {
100 return requesting_frame_; 103 return requesting_frame_;
101 } 104 }
102 105
103 void GeolocationPermissionRequest::PermissionGranted() { 106 void GeolocationPermissionRequest::PermissionGranted() {
104 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true); 107 context_->NotifyPermissionSet(id_, requesting_frame_, callback_, true);
105 } 108 }
106 109
(...skipping 21 matching lines...) Expand all
128 // or the IO thread, but the PermissionQueueController must have been 131 // or the IO thread, but the PermissionQueueController must have been
129 // destroyed on the UI thread. 132 // destroyed on the UI thread.
130 DCHECK(!permission_queue_controller_.get()); 133 DCHECK(!permission_queue_controller_.get());
131 } 134 }
132 135
133 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( 136 void ChromeGeolocationPermissionContext::RequestGeolocationPermission(
134 int render_process_id, 137 int render_process_id,
135 int render_view_id, 138 int render_view_id,
136 int bridge_id, 139 int bridge_id,
137 const GURL& requesting_frame, 140 const GURL& requesting_frame,
141 bool user_gesture,
138 base::Callback<void(bool)> callback) { 142 base::Callback<void(bool)> callback) {
139 GURL requesting_frame_origin = requesting_frame.GetOrigin(); 143 GURL requesting_frame_origin = requesting_frame.GetOrigin();
140 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { 144 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
141 content::BrowserThread::PostTask( 145 content::BrowserThread::PostTask(
142 content::BrowserThread::UI, FROM_HERE, 146 content::BrowserThread::UI, FROM_HERE,
143 base::Bind( 147 base::Bind(
144 &ChromeGeolocationPermissionContext::RequestGeolocationPermission, 148 &ChromeGeolocationPermissionContext::RequestGeolocationPermission,
145 this, render_process_id, render_view_id, bridge_id, 149 this, render_process_id, render_view_id, bridge_id,
146 requesting_frame_origin, callback)); 150 requesting_frame_origin, user_gesture, callback));
147 return; 151 return;
148 } 152 }
149 153
150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
151 if (shutting_down_) 155 if (shutting_down_)
152 return; 156 return;
153 157
154 content::WebContents* web_contents = 158 content::WebContents* web_contents =
155 tab_util::GetWebContentsByID(render_process_id, render_view_id); 159 tab_util::GetWebContentsByID(render_process_id, render_view_id);
156 const PermissionRequestID id(render_process_id, render_view_id, bridge_id, 0); 160 const PermissionRequestID id(render_process_id, render_view_id, bridge_id, 0);
(...skipping 29 matching lines...) Expand all
186 190
187 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin(); 191 GURL embedder = web_contents->GetLastCommittedURL().GetOrigin();
188 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) { 192 if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) {
189 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " 193 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: "
190 << requesting_frame_origin << "," << embedder 194 << requesting_frame_origin << "," << embedder
191 << " (geolocation is not supported in popups)"; 195 << " (geolocation is not supported in popups)";
192 NotifyPermissionSet(id, requesting_frame_origin, callback, false); 196 NotifyPermissionSet(id, requesting_frame_origin, callback, false);
193 return; 197 return;
194 } 198 }
195 199
196 DecidePermission(web_contents, id, requesting_frame_origin, 200 DecidePermission(web_contents, id, requesting_frame_origin, user_gesture,
197 embedder, "", callback); 201 embedder, "", callback);
198 } 202 }
199 203
200 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( 204 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
201 int render_process_id, 205 int render_process_id,
202 int render_view_id, 206 int render_view_id,
203 int bridge_id, 207 int bridge_id,
204 const GURL& requesting_frame) { 208 const GURL& requesting_frame) {
205 // TODO(gbillock): cancel permission bubble request. 209 // TODO(gbillock): cancel permission bubble request.
206 CancelPendingInfobarRequest(PermissionRequestID( 210 CancelPendingInfobarRequest(PermissionRequestID(
207 render_process_id, render_view_id, bridge_id, 0)); 211 render_process_id, render_view_id, bridge_id, 0));
208 } 212 }
209 213
210 void ChromeGeolocationPermissionContext::DecidePermission( 214 void ChromeGeolocationPermissionContext::DecidePermission(
211 content::WebContents* web_contents, 215 content::WebContents* web_contents,
212 const PermissionRequestID& id, 216 const PermissionRequestID& id,
213 const GURL& requesting_frame, 217 const GURL& requesting_frame,
218 bool user_gesture,
214 const GURL& embedder, 219 const GURL& embedder,
215 const std::string& accept_button_label, 220 const std::string& accept_button_label,
216 base::Callback<void(bool)> callback) { 221 base::Callback<void(bool)> callback) {
217 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 222 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
218 223
219 ContentSetting content_setting = 224 ContentSetting content_setting =
220 profile_->GetHostContentSettingsMap()->GetContentSetting( 225 profile_->GetHostContentSettingsMap()->GetContentSetting(
221 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION, 226 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION,
222 std::string()); 227 std::string());
223 switch (content_setting) { 228 switch (content_setting) {
224 case CONTENT_SETTING_BLOCK: 229 case CONTENT_SETTING_BLOCK:
225 PermissionDecided(id, requesting_frame, embedder, callback, false); 230 PermissionDecided(id, requesting_frame, embedder, callback, false);
226 break; 231 break;
227 case CONTENT_SETTING_ALLOW: 232 case CONTENT_SETTING_ALLOW:
228 PermissionDecided(id, requesting_frame, embedder, callback, true); 233 PermissionDecided(id, requesting_frame, embedder, callback, true);
229 break; 234 break;
230 default: 235 default:
231 if (PermissionBubbleManager::Enabled()) { 236 if (PermissionBubbleManager::Enabled()) {
232 PermissionBubbleManager* mgr = 237 PermissionBubbleManager* mgr =
233 PermissionBubbleManager::FromWebContents(web_contents); 238 PermissionBubbleManager::FromWebContents(web_contents);
234 mgr->AddRequest(new GeolocationPermissionRequest( 239 mgr->AddRequest(new GeolocationPermissionRequest(
235 this, id, requesting_frame, callback, 240 this, id, requesting_frame, user_gesture, callback,
236 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); 241 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)));
237 } else { 242 } else {
238 // setting == ask. Prompt the user. 243 // setting == ask. Prompt the user.
239 QueueController()->CreateInfoBarRequest( 244 QueueController()->CreateInfoBarRequest(
240 id, requesting_frame, embedder, accept_button_label, 245 id, requesting_frame, embedder, accept_button_label,
241 base::Bind( 246 base::Bind(
242 &ChromeGeolocationPermissionContext::NotifyPermissionSet, 247 &ChromeGeolocationPermissionContext::NotifyPermissionSet,
243 base::Unretained(this), id, requesting_frame, callback)); 248 base::Unretained(this), id, requesting_frame, callback));
244 } 249 }
245 } 250 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 this, id)); 322 this, id));
318 return; 323 return;
319 } 324 }
320 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 325 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
321 if (shutting_down_) 326 if (shutting_down_)
322 return; 327 return;
323 328
324 // TODO(gbillock): handle permission bubble cancellation. 329 // TODO(gbillock): handle permission bubble cancellation.
325 QueueController()->CancelInfoBarRequest(id); 330 QueueController()->CancelInfoBarRequest(id);
326 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698