| 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/service_worker/service_worker_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 context_ = helper_->context(); | 50 context_ = helper_->context(); |
| 51 script_url_ = GURL("https://www.example.com/service_worker.js"); | 51 script_url_ = GURL("https://www.example.com/service_worker.js"); |
| 52 registration1_ = new ServiceWorkerRegistration( | 52 registration1_ = new ServiceWorkerRegistration( |
| 53 GURL("https://www.example.com/"), 1L, context_->AsWeakPtr()); | 53 GURL("https://www.example.com/"), 1L, context_->AsWeakPtr()); |
| 54 registration2_ = new ServiceWorkerRegistration( | 54 registration2_ = new ServiceWorkerRegistration( |
| 55 GURL("https://www.example.com/example"), 2L, context_->AsWeakPtr()); | 55 GURL("https://www.example.com/example"), 2L, context_->AsWeakPtr()); |
| 56 registration3_ = new ServiceWorkerRegistration( | 56 registration3_ = new ServiceWorkerRegistration( |
| 57 GURL("https://other.example.com/"), 3L, context_->AsWeakPtr()); | 57 GURL("https://other.example.com/"), 3L, context_->AsWeakPtr()); |
| 58 | 58 |
| 59 // Prepare provider hosts (for the same process). | 59 // Prepare provider hosts (for the same process). |
| 60 std::unique_ptr<ServiceWorkerProviderHost> host1( | 60 std::unique_ptr<ServiceWorkerProviderHost> host1 = |
| 61 new ServiceWorkerProviderHost( | 61 ServiceWorkerProviderHost::CreateForTesting( |
| 62 helper_->mock_render_process_id(), MSG_ROUTING_NONE, | 62 helper_->mock_render_process_id(), 1 /* provider_id */, |
| 63 1 /* provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 63 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 64 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, | 64 helper_->context()->AsWeakPtr()); |
| 65 context_->AsWeakPtr(), NULL)); | 65 host1->set_parent_frame_secure(true); |
| 66 host1->SetDocumentUrl(GURL("https://www.example.com/example1.html")); | 66 host1->SetDocumentUrl(GURL("https://www.example.com/example1.html")); |
| 67 std::unique_ptr<ServiceWorkerProviderHost> host2( | 67 std::unique_ptr<ServiceWorkerProviderHost> host2 = |
| 68 new ServiceWorkerProviderHost( | 68 ServiceWorkerProviderHost::CreateForTesting( |
| 69 helper_->mock_render_process_id(), MSG_ROUTING_NONE, | 69 helper_->mock_render_process_id(), 2 /* provider_id */, |
| 70 2 /* provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 70 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 71 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, | 71 helper_->context()->AsWeakPtr()); |
| 72 context_->AsWeakPtr(), NULL)); | 72 host2->set_parent_frame_secure(true); |
| 73 host2->SetDocumentUrl(GURL("https://www.example.com/example2.html")); | 73 host2->SetDocumentUrl(GURL("https://www.example.com/example2.html")); |
| 74 provider_host1_ = host1->AsWeakPtr(); | 74 provider_host1_ = host1->AsWeakPtr(); |
| 75 provider_host2_ = host2->AsWeakPtr(); | 75 provider_host2_ = host2->AsWeakPtr(); |
| 76 context_->AddProviderHost(base::WrapUnique(host1.release())); | 76 context_->AddProviderHost(base::WrapUnique(host1.release())); |
| 77 context_->AddProviderHost(base::WrapUnique(host2.release())); | 77 context_->AddProviderHost(base::WrapUnique(host2.release())); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void TearDown() override { | 80 void TearDown() override { |
| 81 registration1_ = 0; | 81 registration1_ = 0; |
| 82 registration2_ = 0; | 82 registration2_ = 0; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 EXPECT_FALSE(IsOriginSecure(url)); | 198 EXPECT_FALSE(IsOriginSecure(url)); |
| 199 EXPECT_TRUE(OriginCanAccessServiceWorkers(url)); | 199 EXPECT_TRUE(OriginCanAccessServiceWorkers(url)); |
| 200 EXPECT_TRUE(provider_host1_->IsContextSecureForServiceWorker()); | 200 EXPECT_TRUE(provider_host1_->IsContextSecureForServiceWorker()); |
| 201 | 201 |
| 202 // Exceptional service worker scheme with insecure parent frame. | 202 // Exceptional service worker scheme with insecure parent frame. |
| 203 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::INSECURE; | 203 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::INSECURE; |
| 204 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker()); | 204 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker()); |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace content | 207 } // namespace content |
| OLD | NEW |