| OLD | NEW |
| 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 callback, data, | 415 callback, data, |
| 416 PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED)); | 416 PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED)); |
| 417 } else { | 417 } else { |
| 418 RenderFrameHost* render_frame_host = | 418 RenderFrameHost* render_frame_host = |
| 419 RenderFrameHost::FromID(render_process_id_, data.render_frame_id); | 419 RenderFrameHost::FromID(render_process_id_, data.render_frame_id); |
| 420 WebContents* web_contents = | 420 WebContents* web_contents = |
| 421 WebContents::FromRenderFrameHost(render_frame_host); | 421 WebContents::FromRenderFrameHost(render_frame_host); |
| 422 if (web_contents) { | 422 if (web_contents) { |
| 423 web_contents->GetMainFrame()->AddMessageToConsole( | 423 web_contents->GetMainFrame()->AddMessageToConsole( |
| 424 CONSOLE_MESSAGE_LEVEL_ERROR, kIncognitoPushUnsupportedMessage); | 424 CONSOLE_MESSAGE_LEVEL_ERROR, kIncognitoPushUnsupportedMessage); |
| 425 |
| 426 BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 427 |
| 428 // It's valid for embedders to return a null permission manager. |
| 429 // Immediately reject the permission request when this happens. |
| 430 if (!browser_context->GetPermissionManager()) { |
| 431 BrowserThread::PostTask( |
| 432 BrowserThread::IO, FROM_HERE, |
| 433 base::Bind( |
| 434 &PushMessagingManager::SendSubscriptionError, io_parent_, |
| 435 callback, data, |
| 436 PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED)); |
| 437 |
| 438 return; |
| 439 } |
| 440 |
| 425 // Request push messaging permission (which will fail, since | 441 // Request push messaging permission (which will fail, since |
| 426 // notifications aren't supported in incognito), so the website can't | 442 // notifications aren't supported in incognito), so the website can't |
| 427 // detect whether incognito is active. | 443 // detect whether incognito is active. |
| 428 web_contents->GetBrowserContext() | 444 browser_context->GetPermissionManager()->RequestPermission( |
| 429 ->GetPermissionManager() | 445 PermissionType::PUSH_MESSAGING, render_frame_host, |
| 430 ->RequestPermission( | 446 data.requesting_origin, false /* user_gesture */, |
| 431 PermissionType::PUSH_MESSAGING, render_frame_host, | 447 base::Bind( |
| 432 data.requesting_origin, false /* user_gesture */, | 448 &PushMessagingManager::Core::DidRequestPermissionInIncognito, |
| 433 base::Bind(&PushMessagingManager::Core:: | 449 weak_factory_ui_to_ui_.GetWeakPtr(), callback, data)); |
| 434 DidRequestPermissionInIncognito, | |
| 435 weak_factory_ui_to_ui_.GetWeakPtr(), callback, | |
| 436 data)); | |
| 437 } | 450 } |
| 438 } | 451 } |
| 439 } | 452 } |
| 440 return; | 453 return; |
| 441 } | 454 } |
| 442 | 455 |
| 443 if (data.FromDocument()) { | 456 if (data.FromDocument()) { |
| 444 push_service->SubscribeFromDocument( | 457 push_service->SubscribeFromDocument( |
| 445 data.requesting_origin, data.service_worker_registration_id, | 458 data.requesting_origin, data.service_worker_registration_id, |
| 446 render_process_id_, data.render_frame_id, data.options, | 459 render_process_id_, data.render_frame_id, data.options, |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 PushMessagingService* PushMessagingManager::Core::service() { | 916 PushMessagingService* PushMessagingManager::Core::service() { |
| 904 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 917 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 905 RenderProcessHost* process_host = | 918 RenderProcessHost* process_host = |
| 906 RenderProcessHost::FromID(render_process_id_); | 919 RenderProcessHost::FromID(render_process_id_); |
| 907 return process_host | 920 return process_host |
| 908 ? process_host->GetBrowserContext()->GetPushMessagingService() | 921 ? process_host->GetBrowserContext()->GetPushMessagingService() |
| 909 : nullptr; | 922 : nullptr; |
| 910 } | 923 } |
| 911 | 924 |
| 912 } // namespace content | 925 } // namespace content |
| OLD | NEW |