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