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

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

Powered by Google App Engine
This is Rietveld 408576698