| 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/shell/browser/layout_test/layout_test_push_messaging_service.h
" | 5 #include "content/shell/browser/layout_test/layout_test_push_messaging_service.h
" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/public/browser/permission_type.h" | 10 #include "content/public/browser/permission_type.h" |
| 11 #include "content/public/common/push_subscription_options.h" |
| 11 #include "content/shell/browser/layout_test/layout_test_browser_context.h" | 12 #include "content/shell/browser/layout_test/layout_test_browser_context.h" |
| 12 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h
" | 13 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h
" |
| 13 #include "content/shell/browser/layout_test/layout_test_permission_manager.h" | 14 #include "content/shell/browser/layout_test/layout_test_permission_manager.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // NIST P-256 public key made available to layout tests. Must be an uncompressed | 20 // NIST P-256 public key made available to layout tests. Must be an uncompressed |
| 20 // point in accordance with SEC1 2.3.3. | 21 // point in accordance with SEC1 2.3.3. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 LayoutTestPushMessagingService::~LayoutTestPushMessagingService() { | 61 LayoutTestPushMessagingService::~LayoutTestPushMessagingService() { |
| 61 } | 62 } |
| 62 | 63 |
| 63 GURL LayoutTestPushMessagingService::GetPushEndpoint() { | 64 GURL LayoutTestPushMessagingService::GetPushEndpoint() { |
| 64 return GURL("https://example.com/LayoutTestEndpoint"); | 65 return GURL("https://example.com/LayoutTestEndpoint"); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void LayoutTestPushMessagingService::SubscribeFromDocument( | 68 void LayoutTestPushMessagingService::SubscribeFromDocument( |
| 68 const GURL& requesting_origin, | 69 const GURL& requesting_origin, |
| 69 int64_t service_worker_registration_id, | 70 int64_t service_worker_registration_id, |
| 70 const std::string& sender_id, | |
| 71 int renderer_id, | 71 int renderer_id, |
| 72 int render_frame_id, | 72 int render_frame_id, |
| 73 bool user_visible, | 73 const PushSubscriptionOptions& options, |
| 74 const PushMessagingService::RegisterCallback& callback) { | 74 const PushMessagingService::RegisterCallback& callback) { |
| 75 SubscribeFromWorker(requesting_origin, service_worker_registration_id, | 75 SubscribeFromWorker(requesting_origin, service_worker_registration_id, |
| 76 sender_id, user_visible, callback); | 76 options, callback); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void LayoutTestPushMessagingService::SubscribeFromWorker( | 79 void LayoutTestPushMessagingService::SubscribeFromWorker( |
| 80 const GURL& requesting_origin, | 80 const GURL& requesting_origin, |
| 81 int64_t service_worker_registration_id, | 81 int64_t service_worker_registration_id, |
| 82 const std::string& sender_id, | 82 const PushSubscriptionOptions& options, |
| 83 bool user_visible, | |
| 84 const PushMessagingService::RegisterCallback& callback) { | 83 const PushMessagingService::RegisterCallback& callback) { |
| 85 if (GetPermissionStatus(requesting_origin, user_visible) == | 84 if (GetPermissionStatus(requesting_origin, options.user_visible_only) == |
| 86 blink::WebPushPermissionStatusGranted) { | 85 blink::WebPushPermissionStatusGranted) { |
| 87 std::vector<uint8_t> p256dh( | 86 std::vector<uint8_t> p256dh( |
| 88 kTestP256Key, kTestP256Key + arraysize(kTestP256Key)); | 87 kTestP256Key, kTestP256Key + arraysize(kTestP256Key)); |
| 89 std::vector<uint8_t> auth( | 88 std::vector<uint8_t> auth( |
| 90 kAuthentication, kAuthentication + arraysize(kAuthentication)); | 89 kAuthentication, kAuthentication + arraysize(kAuthentication)); |
| 91 | 90 |
| 92 callback.Run("layoutTestRegistrationId", p256dh, auth, | 91 callback.Run("layoutTestRegistrationId", p256dh, auth, |
| 93 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); | 92 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); |
| 94 } else { | 93 } else { |
| 95 callback.Run("registration_id", std::vector<uint8_t>() /* p256dh */, | 94 callback.Run("registration_id", std::vector<uint8_t>() /* p256dh */, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 125 | 124 |
| 126 void LayoutTestPushMessagingService::Unsubscribe( | 125 void LayoutTestPushMessagingService::Unsubscribe( |
| 127 const GURL& requesting_origin, | 126 const GURL& requesting_origin, |
| 128 int64_t service_worker_registration_id, | 127 int64_t service_worker_registration_id, |
| 129 const std::string& sender_id, | 128 const std::string& sender_id, |
| 130 const UnregisterCallback& callback) { | 129 const UnregisterCallback& callback) { |
| 131 callback.Run(PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED); | 130 callback.Run(PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED); |
| 132 } | 131 } |
| 133 | 132 |
| 134 } // namespace content | 133 } // namespace content |
| OLD | NEW |