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

Side by Side Diff: content/browser/push_messaging/push_messaging_manager.cc

Issue 2935333003: Propagate the user gesture bit when requesting push messaging permission. (Closed)
Patch Set: ThreadSafe user gesture check Created 3 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/push_messaging/push_messaging_manager.h" 5 #include "content/browser/push_messaging/push_messaging_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 struct PushMessagingManager::RegisterData { 104 struct PushMessagingManager::RegisterData {
105 RegisterData(); 105 RegisterData();
106 RegisterData(RegisterData&& other) = default; 106 RegisterData(RegisterData&& other) = default;
107 bool FromDocument() const; 107 bool FromDocument() const;
108 GURL requesting_origin; 108 GURL requesting_origin;
109 int64_t service_worker_registration_id; 109 int64_t service_worker_registration_id;
110 PushSubscriptionOptions options; 110 PushSubscriptionOptions options;
111 SubscribeCallback callback; 111 SubscribeCallback callback;
112 // The following member should only be read if FromDocument() is true. 112 // The following member should only be read if FromDocument() is true.
113 int render_frame_id; 113 int render_frame_id;
114
115 // True if the call to register was made with a user gesture.
116 bool user_gesture;
114 }; 117 };
115 118
116 // Inner core of the PushMessagingManager which lives on the UI thread. 119 // Inner core of the PushMessagingManager which lives on the UI thread.
117 class PushMessagingManager::Core { 120 class PushMessagingManager::Core {
118 public: 121 public:
119 Core(const base::WeakPtr<PushMessagingManager>& io_parent, 122 Core(const base::WeakPtr<PushMessagingManager>& io_parent,
120 int render_process_id); 123 int render_process_id);
121 124
122 // Public Register methods on UI thread -------------------------------------- 125 // Public Register methods on UI thread --------------------------------------
123 126
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 bindings_.AddBinding(this, std::move(request)); 277 bindings_.AddBinding(this, std::move(request));
275 } 278 }
276 279
277 // Subscribe methods on both IO and UI threads, merged in order of use from 280 // Subscribe methods on both IO and UI threads, merged in order of use from
278 // PushMessagingManager and Core. 281 // PushMessagingManager and Core.
279 // ----------------------------------------------------------------------------- 282 // -----------------------------------------------------------------------------
280 283
281 void PushMessagingManager::Subscribe(int32_t render_frame_id, 284 void PushMessagingManager::Subscribe(int32_t render_frame_id,
282 int64_t service_worker_registration_id, 285 int64_t service_worker_registration_id,
283 const PushSubscriptionOptions& options, 286 const PushSubscriptionOptions& options,
287 bool user_gesture,
284 SubscribeCallback callback) { 288 SubscribeCallback callback) {
285 DCHECK_CURRENTLY_ON(BrowserThread::IO); 289 DCHECK_CURRENTLY_ON(BrowserThread::IO);
286 // TODO(mvanouwerkerk): Validate arguments? 290 // TODO(mvanouwerkerk): Validate arguments?
287 RegisterData data; 291 RegisterData data;
288 292
289 // Will be ChildProcessHost::kInvalidUniqueID in requests from Service Worker. 293 // Will be ChildProcessHost::kInvalidUniqueID in requests from Service Worker.
290 data.render_frame_id = render_frame_id; 294 data.render_frame_id = render_frame_id;
291 295
292 data.service_worker_registration_id = service_worker_registration_id; 296 data.service_worker_registration_id = service_worker_registration_id;
293 data.callback = std::move(callback); 297 data.callback = std::move(callback);
294 data.options = options; 298 data.options = options;
299 data.user_gesture = user_gesture;
295 300
296 ServiceWorkerRegistration* service_worker_registration = 301 ServiceWorkerRegistration* service_worker_registration =
297 service_worker_context_->GetLiveRegistration( 302 service_worker_context_->GetLiveRegistration(
298 data.service_worker_registration_id); 303 data.service_worker_registration_id);
299 if (!service_worker_registration || 304 if (!service_worker_registration ||
300 !service_worker_registration->active_version()) { 305 !service_worker_registration->active_version()) {
301 SendSubscriptionError(std::move(data), 306 SendSubscriptionError(std::move(data),
302 PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER); 307 PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER);
303 return; 308 return;
304 } 309 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 502
498 return; 503 return;
499 } 504 }
500 505
501 // Request push messaging permission (which will fail, since 506 // Request push messaging permission (which will fail, since
502 // notifications aren't supported in incognito), so the website can't 507 // notifications aren't supported in incognito), so the website can't
503 // detect whether incognito is active. 508 // detect whether incognito is active.
504 GURL requesting_origin = data.requesting_origin; 509 GURL requesting_origin = data.requesting_origin;
505 browser_context->GetPermissionManager()->RequestPermission( 510 browser_context->GetPermissionManager()->RequestPermission(
506 PermissionType::PUSH_MESSAGING, render_frame_host, 511 PermissionType::PUSH_MESSAGING, render_frame_host,
507 requesting_origin, false /* user_gesture */, 512 requesting_origin, data.user_gesture,
508 base::Bind( 513 base::Bind(
509 &PushMessagingManager::Core::DidRequestPermissionInIncognito, 514 &PushMessagingManager::Core::DidRequestPermissionInIncognito,
510 weak_factory_ui_to_ui_.GetWeakPtr(), base::Passed(&data))); 515 weak_factory_ui_to_ui_.GetWeakPtr(), base::Passed(&data)));
511 } 516 }
512 } 517 }
513 } 518 }
514 return; 519 return;
515 } 520 }
516 521
517 int64_t registration_id = data.service_worker_registration_id; 522 int64_t registration_id = data.service_worker_registration_id;
518 GURL requesting_origin = data.requesting_origin; 523 GURL requesting_origin = data.requesting_origin;
519 PushSubscriptionOptions options = data.options; 524 PushSubscriptionOptions options = data.options;
520 int render_frame_id = data.render_frame_id; 525 int render_frame_id = data.render_frame_id;
521 if (data.FromDocument()) { 526 if (data.FromDocument()) {
522 push_service->SubscribeFromDocument( 527 push_service->SubscribeFromDocument(
523 requesting_origin, registration_id, render_process_id_, render_frame_id, 528 requesting_origin, registration_id, render_process_id_, render_frame_id,
524 options, 529 options, data.user_gesture,
525 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), 530 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(),
526 base::Passed(&data))); 531 base::Passed(&data)));
527 } else { 532 } else {
528 push_service->SubscribeFromWorker( 533 push_service->SubscribeFromWorker(
529 requesting_origin, registration_id, options, 534 requesting_origin, registration_id, options,
530 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), 535 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(),
531 base::Passed(&data))); 536 base::Passed(&data)));
532 } 537 }
533 } 538 }
534 539
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 : nullptr; 1038 : nullptr;
1034 } 1039 }
1035 1040
1036 base::WeakPtr<PushMessagingManager::Core> 1041 base::WeakPtr<PushMessagingManager::Core>
1037 PushMessagingManager::Core::GetWeakPtrFromIOParentConstructor() { 1042 PushMessagingManager::Core::GetWeakPtrFromIOParentConstructor() {
1038 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1043 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1039 return weak_factory_ui_to_ui_.GetWeakPtr(); 1044 return weak_factory_ui_to_ui_.GetWeakPtr();
1040 } 1045 }
1041 1046
1042 } // namespace content 1047 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/push_messaging/push_messaging_manager.h ('k') | content/child/push_messaging/push_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698