Commit c7034143 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Simplify network provider creation since PlzNavigate is always on.

And some minor refactoring.

Bug: 789577
Change-Id: I365024a2e29b71e8aaa3cfecabe4f70eb31c8808
Reviewed-on: https://chromium-review.googlesource.com/965661Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543655}
parent a46b62e9
...@@ -833,18 +833,12 @@ void NavigationRequest::OnResponseStarted( ...@@ -833,18 +833,12 @@ void NavigationRequest::OnResponseStarted(
if (!response_should_be_rendered_) if (!response_should_be_rendered_)
navigation_handle_->set_net_error_code(net::ERR_ABORTED); navigation_handle_->set_net_error_code(net::ERR_ABORTED);
// Update the service worker params of the request params. // Update the service worker and AppCache params of the request params.
bool did_create_service_worker_host =
navigation_handle_->service_worker_handle() &&
navigation_handle_->service_worker_handle()
->service_worker_provider_host_id() !=
kInvalidServiceWorkerProviderId;
request_params_.service_worker_provider_id = request_params_.service_worker_provider_id =
did_create_service_worker_host navigation_handle_->service_worker_handle()
? navigation_handle_->service_worker_handle() ? navigation_handle_->service_worker_handle()
->service_worker_provider_host_id() ->service_worker_provider_host_id()
: kInvalidServiceWorkerProviderId; : kInvalidServiceWorkerProviderId;
request_params_.appcache_host_id = request_params_.appcache_host_id =
navigation_handle_->appcache_handle() navigation_handle_->appcache_handle()
? navigation_handle_->appcache_handle()->appcache_host_id() ? navigation_handle_->appcache_handle()->appcache_host_id()
......
...@@ -28,12 +28,12 @@ class ServiceWorkerNavigationHandleCore; ...@@ -28,12 +28,12 @@ class ServiceWorkerNavigationHandleCore;
// pointer to the ServiceWorkerNavigationHandleCore. // pointer to the ServiceWorkerNavigationHandleCore.
// //
// 3) If we pre-create a ServiceWorkerProviderHost for this navigation, its // 3) If we pre-create a ServiceWorkerProviderHost for this navigation, its
// ownershipped is passed to the ServiceWorkerNavigationHandleCore. The // ownership is passed to the ServiceWorkerNavigationHandleCore. The
// ServiceWorkerNavigationHandleCore id is updated. // ServiceWorkerNavigationHandleCore id is updated.
// //
// 4) The ServiceWorkerNavigationHandleCore informs the // 4) The ServiceWorkerNavigationHandleCore informs the
// ServiceWorkerNavigationHandle on the UI that the service worker provider // ServiceWorkerNavigationHandle on the UI thread that the service worker
// id was updated. // provider id was updated.
// //
// 5) When the navigation is ready to commit, the NavigationRequest will // 5) When the navigation is ready to commit, the NavigationRequest will
// update the RequestNavigationParams based on the id from the // update the RequestNavigationParams based on the id from the
......
...@@ -179,9 +179,6 @@ void SharedWorkerServiceImpl::CreateWorker( ...@@ -179,9 +179,6 @@ void SharedWorkerServiceImpl::CreateWorker(
host->Start(std::move(factory), pause_on_start, devtools_worker_token); host->Start(std::move(factory), pause_on_start, devtools_worker_token);
host->AddClient(std::move(client), process_id, frame_id, message_port); host->AddClient(std::move(client), process_id, frame_id, message_port);
const GURL url = host->instance()->url();
const std::string name = host->instance()->name();
worker_hosts_.insert(std::move(host)); worker_hosts_.insert(std::move(host));
} }
......
...@@ -149,58 +149,46 @@ ServiceWorkerNetworkProvider::CreateForNavigation( ...@@ -149,58 +149,46 @@ ServiceWorkerNetworkProvider::CreateForNavigation(
bool content_initiated, bool content_initiated,
mojom::ControllerServiceWorkerInfoPtr controller_info, mojom::ControllerServiceWorkerInfoPtr controller_info,
scoped_refptr<network::SharedURLLoaderFactory> default_loader_factory) { scoped_refptr<network::SharedURLLoaderFactory> default_loader_factory) {
bool browser_side_navigation = IsBrowserSideNavigationEnabled(); std::unique_ptr<ServiceWorkerNetworkProvider> provider;
bool should_create_provider_for_window = false;
int service_worker_provider_id = kInvalidServiceWorkerProviderId;
std::unique_ptr<ServiceWorkerNetworkProvider> network_provider;
// Determine if a ServiceWorkerNetworkProvider should be created and properly // Determine if a ServiceWorkerNetworkProvider should be created and properly
// initialized for the navigation. A default ServiceWorkerNetworkProvider // initialized for the navigation. A default ServiceWorkerNetworkProvider
// will always be created since it is expected in a certain number of places, // will always be created since it is expected in a certain number of places,
// however it will have an invalid id. // however it will have an invalid id.
// PlzNavigate: |service_worker_provider_id| can be sent by the browser, if bool should_create_provider = false;
// it already created the SeviceWorkerProviderHost. int provider_id = kInvalidServiceWorkerProviderId;
if (browser_side_navigation && !content_initiated) { if (content_initiated) {
should_create_provider_for_window = should_create_provider =
request_params.should_create_service_worker;
service_worker_provider_id = request_params.service_worker_provider_id;
DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(
service_worker_provider_id) ||
service_worker_provider_id == kInvalidServiceWorkerProviderId);
} else {
should_create_provider_for_window =
((frame->EffectiveSandboxFlags() & blink::WebSandboxFlags::kOrigin) != ((frame->EffectiveSandboxFlags() & blink::WebSandboxFlags::kOrigin) !=
blink::WebSandboxFlags::kOrigin); blink::WebSandboxFlags::kOrigin);
} else {
should_create_provider = request_params.should_create_service_worker;
provider_id = request_params.service_worker_provider_id;
} }
// Now create the ServiceWorkerNetworkProvider (with invalid id if needed). // Now create the ServiceWorkerNetworkProvider (with invalid id if needed).
if (should_create_provider_for_window) { if (should_create_provider) {
// Ideally Document::isSecureContext would be called here, but the document // Ideally Document::IsSecureContext would be called here, but the document
// is not created yet, and due to redirects the URL may change. So pass // is not created yet, and due to redirects the URL may change. So pass
// is_parent_frame_secure to the browser process, so it can determine the // is_parent_frame_secure to the browser process, so it can determine the
// context security when deciding whether to allow a service worker to // context security when deciding whether to allow a service worker to
// control the document. // control the document.
const bool is_parent_frame_secure = IsFrameSecure(frame->Parent()); const bool is_parent_frame_secure = IsFrameSecure(frame->Parent());
if (service_worker_provider_id == kInvalidServiceWorkerProviderId) { DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id) ||
network_provider = base::WrapUnique(new ServiceWorkerNetworkProvider( provider_id == kInvalidServiceWorkerProviderId);
route_id, blink::mojom::ServiceWorkerProviderType::kForWindow, if (provider_id == kInvalidServiceWorkerProviderId)
GetNextProviderId(), is_parent_frame_secure, provider_id = GetNextProviderId();
std::move(controller_info), std::move(default_loader_factory)));
} else { provider = base::WrapUnique(new ServiceWorkerNetworkProvider(
CHECK(browser_side_navigation); route_id, blink::mojom::ServiceWorkerProviderType::kForWindow,
DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId( provider_id, is_parent_frame_secure, std::move(controller_info),
service_worker_provider_id)); std::move(default_loader_factory)));
network_provider = base::WrapUnique(new ServiceWorkerNetworkProvider(
route_id, blink::mojom::ServiceWorkerProviderType::kForWindow,
service_worker_provider_id, is_parent_frame_secure,
std::move(controller_info), std::move(default_loader_factory)));
}
} else { } else {
network_provider = base::WrapUnique(new ServiceWorkerNetworkProvider()); provider = base::WrapUnique(new ServiceWorkerNetworkProvider());
} }
return std::make_unique<WebServiceWorkerNetworkProviderForFrame>( return std::make_unique<WebServiceWorkerNetworkProviderForFrame>(
std::move(network_provider)); std::move(provider));
} }
// static // static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment