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
3 // found in the LICENSE file.
5 #include "content/shell/browser/layout_test/layout_test_push_messaging_service.h"
7 #include "base/callback.h"
8 #include "base/logging.h"
9 #include "content/public/browser/permission_type.h"
10 #include "content/shell/browser/layout_test/layout_test_browser_context.h"
11 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h"
12 #include "content/shell/browser/layout_test/layout_test_permission_manager.h"
18 blink::WebPushPermissionStatus
ToWebPushPermissionStatus(
19 PermissionStatus status
) {
21 case PERMISSION_STATUS_GRANTED
:
22 return blink::WebPushPermissionStatusGranted
;
23 case PERMISSION_STATUS_DENIED
:
24 return blink::WebPushPermissionStatusDenied
;
25 case PERMISSION_STATUS_ASK
:
26 return blink::WebPushPermissionStatusPrompt
;
30 return blink::WebPushPermissionStatusLast
;
33 } // anonymous namespace
35 LayoutTestPushMessagingService::LayoutTestPushMessagingService() {
38 LayoutTestPushMessagingService::~LayoutTestPushMessagingService() {
41 GURL
LayoutTestPushMessagingService::GetPushEndpoint() {
42 return GURL("https://example.com/LayoutTestEndpoint");
45 void LayoutTestPushMessagingService::SubscribeFromDocument(
46 const GURL
& requesting_origin
,
47 int64 service_worker_registration_id
,
48 const std::string
& sender_id
,
52 const PushMessagingService::RegisterCallback
& callback
) {
53 SubscribeFromWorker(requesting_origin
, service_worker_registration_id
,
54 sender_id
, user_visible
, callback
);
57 void LayoutTestPushMessagingService::SubscribeFromWorker(
58 const GURL
& requesting_origin
,
59 int64 service_worker_registration_id
,
60 const std::string
& sender_id
,
62 const PushMessagingService::RegisterCallback
& callback
) {
63 if (GetPermissionStatus(requesting_origin
, requesting_origin
, user_visible
) ==
64 blink::WebPushPermissionStatusGranted
) {
65 callback
.Run("layoutTestRegistrationId",
66 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE
);
68 callback
.Run("registration_id", PUSH_REGISTRATION_STATUS_PERMISSION_DENIED
);
72 blink::WebPushPermissionStatus
73 LayoutTestPushMessagingService::GetPermissionStatus(
74 const GURL
& requesting_origin
,
75 const GURL
& embedding_origin
,
77 return ToWebPushPermissionStatus(LayoutTestContentBrowserClient::Get()
78 ->GetLayoutTestBrowserContext()
79 ->GetLayoutTestPermissionManager()
80 ->GetPermissionStatus(PermissionType::PUSH_MESSAGING
,
85 bool LayoutTestPushMessagingService::SupportNonVisibleMessages() {
89 void LayoutTestPushMessagingService::Unsubscribe(
90 const GURL
& requesting_origin
,
91 int64 service_worker_registration_id
,
92 const std::string
& sender_id
,
93 const UnregisterCallback
& callback
) {
94 callback
.Run(PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED
);
97 } // namespace content