| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_test_utils.h" | 5 #include "content/browser/service_worker/service_worker_test_utils.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/browser/service_worker/service_worker_provider_host.h" | 9 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 10 #include "content/common/service_worker/service_worker_provider.mojom.h" |
| 11 #include "content/public/common/child_process_host.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 | 14 |
| 13 ServiceWorkerRemoteProviderEndpoint::ServiceWorkerRemoteProviderEndpoint() {} | 15 ServiceWorkerRemoteProviderEndpoint::ServiceWorkerRemoteProviderEndpoint() {} |
| 14 ServiceWorkerRemoteProviderEndpoint::ServiceWorkerRemoteProviderEndpoint( | 16 ServiceWorkerRemoteProviderEndpoint::ServiceWorkerRemoteProviderEndpoint( |
| 15 ServiceWorkerRemoteProviderEndpoint&& other) | 17 ServiceWorkerRemoteProviderEndpoint&& other) |
| 16 : host_ptr_(std::move(other.host_ptr_)), | 18 : host_ptr_(std::move(other.host_ptr_)), |
| 17 client_request_(std::move(other.client_request_)) {} | 19 client_request_(std::move(other.client_request_)) {} |
| 18 | 20 |
| 19 ServiceWorkerRemoteProviderEndpoint::~ServiceWorkerRemoteProviderEndpoint() {} | 21 ServiceWorkerRemoteProviderEndpoint::~ServiceWorkerRemoteProviderEndpoint() {} |
| 20 | 22 |
| 21 void ServiceWorkerRemoteProviderEndpoint::BindWithProviderHostInfo( | 23 void ServiceWorkerRemoteProviderEndpoint::BindWithProviderHostInfo( |
| 22 content::ServiceWorkerProviderHostInfo* info) { | 24 content::ServiceWorkerProviderHostInfo* info) { |
| 23 mojom::ServiceWorkerProviderAssociatedPtr client_ptr; | 25 mojom::ServiceWorkerProviderAssociatedPtr client_ptr; |
| 24 client_request_ = mojo::MakeIsolatedRequest(&client_ptr); | 26 client_request_ = mojo::MakeIsolatedRequest(&client_ptr); |
| 25 info->client_ptr_info = client_ptr.PassInterface(); | 27 info->client_ptr_info = client_ptr.PassInterface(); |
| 26 info->host_request = mojo::MakeIsolatedRequest(&host_ptr_); | 28 info->host_request = mojo::MakeIsolatedRequest(&host_ptr_); |
| 27 } | 29 } |
| 28 | 30 |
| 31 void ServiceWorkerRemoteProviderEndpoint::BindWithProviderInfo( |
| 32 mojom::ServiceWorkerProviderInfoForStartWorkerPtr info) { |
| 33 client_request_ = std::move(info->client_request); |
| 34 host_ptr_.Bind(std::move(info->host_ptr_info)); |
| 35 } |
| 36 |
| 29 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostForWindow( | 37 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostForWindow( |
| 30 int process_id, | 38 int process_id, |
| 31 int provider_id, | 39 int provider_id, |
| 32 bool is_parent_frame_secure, | 40 bool is_parent_frame_secure, |
| 33 base::WeakPtr<ServiceWorkerContextCore> context, | 41 base::WeakPtr<ServiceWorkerContextCore> context, |
| 34 ServiceWorkerRemoteProviderEndpoint* output_endpoint) { | 42 ServiceWorkerRemoteProviderEndpoint* output_endpoint) { |
| 35 ServiceWorkerProviderHostInfo info(provider_id, 1 /* route_id */, | 43 ServiceWorkerProviderHostInfo info(provider_id, 1 /* route_id */, |
| 36 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 44 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 37 is_parent_frame_secure); | 45 is_parent_frame_secure); |
| 38 output_endpoint->BindWithProviderHostInfo(&info); | 46 output_endpoint->BindWithProviderHostInfo(&info); |
| 39 return ServiceWorkerProviderHost::Create(process_id, std::move(info), | 47 return ServiceWorkerProviderHost::Create(process_id, std::move(info), |
| 40 std::move(context), nullptr); | 48 std::move(context), nullptr); |
| 41 } | 49 } |
| 42 | 50 |
| 43 std::unique_ptr<ServiceWorkerProviderHost> | 51 std::unique_ptr<ServiceWorkerProviderHost> |
| 44 CreateProviderHostForServiceWorkerContext( | 52 CreateProviderHostForServiceWorkerContext( |
| 45 int process_id, | 53 int process_id, |
| 46 int provider_id, | |
| 47 bool is_parent_frame_secure, | 54 bool is_parent_frame_secure, |
| 55 ServiceWorkerVersion* hosted_version, |
| 48 base::WeakPtr<ServiceWorkerContextCore> context, | 56 base::WeakPtr<ServiceWorkerContextCore> context, |
| 49 ServiceWorkerRemoteProviderEndpoint* output_endpoint) { | 57 ServiceWorkerRemoteProviderEndpoint* output_endpoint) { |
| 50 ServiceWorkerProviderHostInfo info(provider_id, MSG_ROUTING_NONE, | 58 ServiceWorkerProviderHostInfo info( |
| 51 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | 59 kInvalidServiceWorkerProviderId, MSG_ROUTING_NONE, |
| 52 is_parent_frame_secure); | 60 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, is_parent_frame_secure); |
| 53 output_endpoint->BindWithProviderHostInfo(&info); | 61 std::unique_ptr<ServiceWorkerProviderHost> host = |
| 54 return ServiceWorkerProviderHost::Create(process_id, std::move(info), | 62 ServiceWorkerProviderHost::PreCreateForController(std::move(context)); |
| 55 std::move(context), nullptr); | 63 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info = |
| 64 host->CompleteStartWorkerPreparation(process_id, hosted_version); |
| 65 output_endpoint->BindWithProviderInfo(std::move(provider_info)); |
| 66 return host; |
| 56 } | 67 } |
| 57 | 68 |
| 58 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostWithDispatcherHost( | 69 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostWithDispatcherHost( |
| 59 int process_id, | 70 int process_id, |
| 60 int provider_id, | 71 int provider_id, |
| 61 base::WeakPtr<ServiceWorkerContextCore> context, | 72 base::WeakPtr<ServiceWorkerContextCore> context, |
| 62 int route_id, | 73 int route_id, |
| 63 ServiceWorkerDispatcherHost* dispatcher_host, | 74 ServiceWorkerDispatcherHost* dispatcher_host, |
| 64 ServiceWorkerRemoteProviderEndpoint* output_endpoint) { | 75 ServiceWorkerRemoteProviderEndpoint* output_endpoint) { |
| 65 ServiceWorkerProviderHostInfo info(provider_id, route_id, | 76 ServiceWorkerProviderHostInfo info(provider_id, route_id, |
| 66 SERVICE_WORKER_PROVIDER_FOR_WINDOW, true); | 77 SERVICE_WORKER_PROVIDER_FOR_WINDOW, true); |
| 67 output_endpoint->BindWithProviderHostInfo(&info); | 78 output_endpoint->BindWithProviderHostInfo(&info); |
| 68 return ServiceWorkerProviderHost::Create(process_id, std::move(info), | 79 return ServiceWorkerProviderHost::Create(process_id, std::move(info), |
| 69 std::move(context), dispatcher_host); | 80 std::move(context), dispatcher_host); |
| 70 } | 81 } |
| 71 | 82 |
| 72 } // namespace content | 83 } // namespace content |
| OLD | NEW |