Fix link in German terms of service.
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_push_messaging_service.cc
blobdfdd8ef449036ac9e1118f93062ae6518fed1e60
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"
14 namespace content {
16 namespace {
18 blink::WebPushPermissionStatus ToWebPushPermissionStatus(
19 PermissionStatus status) {
20 switch (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;
29 NOTREACHED();
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,
49 int renderer_id,
50 int render_frame_id,
51 bool user_visible,
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,
61 bool user_visible,
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);
67 } else {
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,
76 bool user_visible) {
77 return ToWebPushPermissionStatus(LayoutTestContentBrowserClient::Get()
78 ->GetLayoutTestBrowserContext()
79 ->GetLayoutTestPermissionManager()
80 ->GetPermissionStatus(PermissionType::PUSH_MESSAGING,
81 requesting_origin,
82 embedding_origin));
85 bool LayoutTestPushMessagingService::SupportNonVisibleMessages() {
86 return false;
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