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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_service_impl.cc

Issue 1701313002: Partial implementation of subscription restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Integrated code review comments Created 4 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
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 "chrome/browser/push_messaging/push_messaging_service_impl.h" 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 25 matching lines...) Expand all
36 #include "components/rappor/rappor_utils.h" 36 #include "components/rappor/rappor_utils.h"
37 #include "content/public/browser/browser_context.h" 37 #include "content/public/browser/browser_context.h"
38 #include "content/public/browser/permission_type.h" 38 #include "content/public/browser/permission_type.h"
39 #include "content/public/browser/render_frame_host.h" 39 #include "content/public/browser/render_frame_host.h"
40 #include "content/public/browser/service_worker_context.h" 40 #include "content/public/browser/service_worker_context.h"
41 #include "content/public/browser/storage_partition.h" 41 #include "content/public/browser/storage_partition.h"
42 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
43 #include "content/public/common/child_process_host.h" 43 #include "content/public/common/child_process_host.h"
44 #include "content/public/common/content_switches.h" 44 #include "content/public/common/content_switches.h"
45 #include "content/public/common/push_messaging_status.h" 45 #include "content/public/common/push_messaging_status.h"
46 #include "content/public/common/push_subscription_options.h"
46 #include "ui/base/l10n/l10n_util.h" 47 #include "ui/base/l10n/l10n_util.h"
47 48
48 #if defined(ENABLE_BACKGROUND) 49 #if defined(ENABLE_BACKGROUND)
49 #include "chrome/browser/background/background_mode_manager.h" 50 #include "chrome/browser/background/background_mode_manager.h"
50 #endif 51 #endif
51 52
52 namespace { 53 namespace {
53 const int kMaxRegistrations = 1000000; 54 const int kMaxRegistrations = 1000000;
54 55
55 // Chrome does not yet support silent push messages, and requires websites to 56 // Chrome does not yet support silent push messages, and requires websites to
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 GURL PushMessagingServiceImpl::GetPushEndpoint() { 338 GURL PushMessagingServiceImpl::GetPushEndpoint() {
338 return GURL(std::string(kPushMessagingEndpoint)); 339 return GURL(std::string(kPushMessagingEndpoint));
339 } 340 }
340 341
341 // Subscribe and GetPermissionStatus methods ----------------------------------- 342 // Subscribe and GetPermissionStatus methods -----------------------------------
342 343
343 void PushMessagingServiceImpl::SubscribeFromDocument( 344 void PushMessagingServiceImpl::SubscribeFromDocument(
344 const GURL& requesting_origin, 345 const GURL& requesting_origin,
345 int64_t service_worker_registration_id, 346 int64_t service_worker_registration_id,
346 const std::string& sender_id,
347 int renderer_id, 347 int renderer_id,
348 int render_frame_id, 348 int render_frame_id,
349 bool user_visible, 349 const content::PushSubscriptionOptions& options,
350 const content::PushMessagingService::RegisterCallback& callback) { 350 const content::PushMessagingService::RegisterCallback& callback) {
351 PushMessagingAppIdentifier app_identifier = 351 PushMessagingAppIdentifier app_identifier =
352 PushMessagingAppIdentifier::Generate(requesting_origin, 352 PushMessagingAppIdentifier::Generate(requesting_origin,
353 service_worker_registration_id); 353 service_worker_registration_id);
354 354
355 if (push_subscription_count_ + pending_push_subscription_count_ >= 355 if (push_subscription_count_ + pending_push_subscription_count_ >=
356 kMaxRegistrations) { 356 kMaxRegistrations) {
357 SubscribeEndWithError(callback, 357 SubscribeEndWithError(callback,
358 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED); 358 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED);
359 return; 359 return;
360 } 360 }
361 361
362 content::RenderFrameHost* render_frame_host = 362 content::RenderFrameHost* render_frame_host =
363 content::RenderFrameHost::FromID(renderer_id, render_frame_id); 363 content::RenderFrameHost::FromID(renderer_id, render_frame_id);
364 content::WebContents* web_contents = 364 content::WebContents* web_contents =
365 content::WebContents::FromRenderFrameHost(render_frame_host); 365 content::WebContents::FromRenderFrameHost(render_frame_host);
366 if (!web_contents) 366 if (!web_contents)
367 return; 367 return;
368 368
369 if (!user_visible) { 369 if (!options.user_visible_only) {
370 web_contents->GetMainFrame()->AddMessageToConsole( 370 web_contents->GetMainFrame()->AddMessageToConsole(
371 content::CONSOLE_MESSAGE_LEVEL_ERROR, kSilentPushUnsupportedMessage); 371 content::CONSOLE_MESSAGE_LEVEL_ERROR, kSilentPushUnsupportedMessage);
372 372
373 SubscribeEndWithError(callback, 373 SubscribeEndWithError(callback,
374 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); 374 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
375 return; 375 return;
376 } 376 }
377 377
378 // Push does not allow permission requests from iframes. 378 // Push does not allow permission requests from iframes.
379 profile_->GetPermissionManager()->RequestPermission( 379 profile_->GetPermissionManager()->RequestPermission(
380 content::PermissionType::PUSH_MESSAGING, web_contents->GetMainFrame(), 380 content::PermissionType::PUSH_MESSAGING, web_contents->GetMainFrame(),
381 requesting_origin, 381 requesting_origin,
382 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, 382 base::Bind(&PushMessagingServiceImpl::DidRequestPermission,
383 weak_factory_.GetWeakPtr(), app_identifier, sender_id, 383 weak_factory_.GetWeakPtr(), app_identifier, options,
384 callback)); 384 callback));
385 } 385 }
386 386
387 void PushMessagingServiceImpl::SubscribeFromWorker( 387 void PushMessagingServiceImpl::SubscribeFromWorker(
388 const GURL& requesting_origin, 388 const GURL& requesting_origin,
389 int64_t service_worker_registration_id, 389 int64_t service_worker_registration_id,
390 const std::string& sender_id, 390 const content::PushSubscriptionOptions& options,
391 bool user_visible,
392 const content::PushMessagingService::RegisterCallback& register_callback) { 391 const content::PushMessagingService::RegisterCallback& register_callback) {
393 PushMessagingAppIdentifier app_identifier = 392 PushMessagingAppIdentifier app_identifier =
394 PushMessagingAppIdentifier::Generate(requesting_origin, 393 PushMessagingAppIdentifier::Generate(requesting_origin,
395 service_worker_registration_id); 394 service_worker_registration_id);
396 395
397 if (push_subscription_count_ + pending_push_subscription_count_ >= 396 if (push_subscription_count_ + pending_push_subscription_count_ >=
398 kMaxRegistrations) { 397 kMaxRegistrations) {
399 SubscribeEndWithError(register_callback, 398 SubscribeEndWithError(register_callback,
400 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED); 399 content::PUSH_REGISTRATION_STATUS_LIMIT_REACHED);
401 return; 400 return;
402 } 401 }
403 402
404 blink::WebPushPermissionStatus permission_status = 403 blink::WebPushPermissionStatus permission_status =
405 PushMessagingServiceImpl::GetPermissionStatus(requesting_origin, 404 PushMessagingServiceImpl::GetPermissionStatus(requesting_origin,
406 user_visible); 405 options.user_visible_only);
407 406
408 if (permission_status != blink::WebPushPermissionStatusGranted) { 407 if (permission_status != blink::WebPushPermissionStatusGranted) {
409 SubscribeEndWithError(register_callback, 408 SubscribeEndWithError(register_callback,
410 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); 409 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
411 return; 410 return;
412 } 411 }
413 412
414 IncreasePushSubscriptionCount(1, true /* is_pending */); 413 IncreasePushSubscriptionCount(1, true /* is_pending */);
415 std::vector<std::string> sender_ids(1, sender_id); 414 std::vector<std::string> sender_ids(1, options.sender_info);
416 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids, 415 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids,
417 base::Bind(&PushMessagingServiceImpl::DidSubscribe, 416 base::Bind(&PushMessagingServiceImpl::DidSubscribe,
418 weak_factory_.GetWeakPtr(), 417 weak_factory_.GetWeakPtr(),
419 app_identifier, register_callback)); 418 app_identifier, register_callback));
420 } 419 }
421 420
422 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( 421 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
423 const GURL& origin, 422 const GURL& origin,
424 bool user_visible) { 423 bool user_visible) {
425 if (!user_visible) 424 if (!user_visible)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 IncreasePushSubscriptionCount(1, false /* is_pending */); 507 IncreasePushSubscriptionCount(1, false /* is_pending */);
509 508
510 SubscribeEnd(callback, subscription_id, 509 SubscribeEnd(callback, subscription_id,
511 std::vector<uint8_t>(p256dh.begin(), p256dh.end()), 510 std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
512 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()), 511 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()),
513 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); 512 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE);
514 } 513 }
515 514
516 void PushMessagingServiceImpl::DidRequestPermission( 515 void PushMessagingServiceImpl::DidRequestPermission(
517 const PushMessagingAppIdentifier& app_identifier, 516 const PushMessagingAppIdentifier& app_identifier,
518 const std::string& sender_id, 517 const content::PushSubscriptionOptions& options,
519 const content::PushMessagingService::RegisterCallback& register_callback, 518 const content::PushMessagingService::RegisterCallback& register_callback,
520 content::PermissionStatus permission_status) { 519 content::PermissionStatus permission_status) {
521 if (permission_status != content::PermissionStatus::GRANTED) { 520 if (permission_status != content::PermissionStatus::GRANTED) {
522 SubscribeEndWithError(register_callback, 521 SubscribeEndWithError(register_callback,
523 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); 522 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
524 return; 523 return;
525 } 524 }
526 525
527 IncreasePushSubscriptionCount(1, true /* is_pending */); 526 IncreasePushSubscriptionCount(1, true /* is_pending */);
528 std::vector<std::string> sender_ids(1, sender_id); 527 std::vector<std::string> sender_ids(1, options.sender_info);
529 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids, 528 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids,
530 base::Bind(&PushMessagingServiceImpl::DidSubscribe, 529 base::Bind(&PushMessagingServiceImpl::DidSubscribe,
531 weak_factory_.GetWeakPtr(), 530 weak_factory_.GetWeakPtr(),
532 app_identifier, register_callback)); 531 app_identifier, register_callback));
533 } 532 }
534 533
535 // GetEncryptionInfo methods --------------------------------------------------- 534 // GetEncryptionInfo methods ---------------------------------------------------
536 535
537 void PushMessagingServiceImpl::GetEncryptionInfo( 536 void PushMessagingServiceImpl::GetEncryptionInfo(
538 const GURL& origin, 537 const GURL& origin,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 blink::WebPushPermissionStatusGranted; 753 blink::WebPushPermissionStatusGranted;
755 } 754 }
756 755
757 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { 756 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const {
758 gcm::GCMProfileService* gcm_profile_service = 757 gcm::GCMProfileService* gcm_profile_service =
759 gcm::GCMProfileServiceFactory::GetForProfile(profile_); 758 gcm::GCMProfileServiceFactory::GetForProfile(profile_);
760 CHECK(gcm_profile_service); 759 CHECK(gcm_profile_service);
761 CHECK(gcm_profile_service->driver()); 760 CHECK(gcm_profile_service->driver());
762 return gcm_profile_service->driver(); 761 return gcm_profile_service->driver();
763 } 762 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698