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

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: 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 23 matching lines...) Expand all
34 #include "components/pref_registry/pref_registry_syncable.h" 34 #include "components/pref_registry/pref_registry_syncable.h"
35 #include "components/prefs/pref_service.h" 35 #include "components/prefs/pref_service.h"
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_push_subscription_options.h"
44 #include "content/public/common/content_switches.h" 45 #include "content/public/common/content_switches.h"
45 #include "content/public/common/push_messaging_status.h" 46 #include "content/public/common/push_messaging_status.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;
(...skipping 282 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::ContentPushSubscriptionOptions& 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, true /* user_gesture */, 381 requesting_origin, true /* user_gesture */,
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::ContentPushSubscriptionOptions& 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 GURL embedding_origin = requesting_origin; 403 GURL embedding_origin = requesting_origin;
405 blink::WebPushPermissionStatus permission_status = 404 blink::WebPushPermissionStatus permission_status =
406 PushMessagingServiceImpl::GetPermissionStatus( 405 PushMessagingServiceImpl::GetPermissionStatus(
407 requesting_origin, embedding_origin, user_visible); 406 requesting_origin, embedding_origin, options.user_visible_only);
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& requesting_origin, 422 const GURL& requesting_origin,
424 const GURL& embedding_origin, 423 const GURL& embedding_origin,
425 bool user_visible) { 424 bool user_visible) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 IncreasePushSubscriptionCount(1, false /* is_pending */); 514 IncreasePushSubscriptionCount(1, false /* is_pending */);
516 515
517 SubscribeEnd(callback, subscription_id, 516 SubscribeEnd(callback, subscription_id,
518 std::vector<uint8_t>(p256dh.begin(), p256dh.end()), 517 std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
519 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()), 518 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()),
520 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); 519 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE);
521 } 520 }
522 521
523 void PushMessagingServiceImpl::DidRequestPermission( 522 void PushMessagingServiceImpl::DidRequestPermission(
524 const PushMessagingAppIdentifier& app_identifier, 523 const PushMessagingAppIdentifier& app_identifier,
525 const std::string& sender_id, 524 const content::ContentPushSubscriptionOptions& options,
526 const content::PushMessagingService::RegisterCallback& register_callback, 525 const content::PushMessagingService::RegisterCallback& register_callback,
527 content::PermissionStatus permission_status) { 526 content::PermissionStatus permission_status) {
528 if (permission_status != content::PermissionStatus::GRANTED) { 527 if (permission_status != content::PermissionStatus::GRANTED) {
529 SubscribeEndWithError(register_callback, 528 SubscribeEndWithError(register_callback,
530 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); 529 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
531 return; 530 return;
532 } 531 }
533 532
534 IncreasePushSubscriptionCount(1, true /* is_pending */); 533 IncreasePushSubscriptionCount(1, true /* is_pending */);
535 std::vector<std::string> sender_ids(1, sender_id); 534 std::vector<std::string> sender_ids(1, options.sender_info);
536 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids, 535 GetGCMDriver()->Register(app_identifier.app_id(), sender_ids,
537 base::Bind(&PushMessagingServiceImpl::DidSubscribe, 536 base::Bind(&PushMessagingServiceImpl::DidSubscribe,
538 weak_factory_.GetWeakPtr(), 537 weak_factory_.GetWeakPtr(),
539 app_identifier, register_callback)); 538 app_identifier, register_callback));
540 } 539 }
541 540
542 // GetEncryptionInfo methods --------------------------------------------------- 541 // GetEncryptionInfo methods ---------------------------------------------------
543 542
544 void PushMessagingServiceImpl::GetEncryptionInfo( 543 void PushMessagingServiceImpl::GetEncryptionInfo(
545 const GURL& origin, 544 const GURL& origin,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 switches::kEnableExperimentalWebPlatformFeatures); 772 switches::kEnableExperimentalWebPlatformFeatures);
774 } 773 }
775 774
776 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { 775 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const {
777 gcm::GCMProfileService* gcm_profile_service = 776 gcm::GCMProfileService* gcm_profile_service =
778 gcm::GCMProfileServiceFactory::GetForProfile(profile_); 777 gcm::GCMProfileServiceFactory::GetForProfile(profile_);
779 CHECK(gcm_profile_service); 778 CHECK(gcm_profile_service);
780 CHECK(gcm_profile_service->driver()); 779 CHECK(gcm_profile_service->driver());
781 return gcm_profile_service->driver(); 780 return gcm_profile_service->driver();
782 } 781 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698