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(
if (!response_should_be_rendered_)
navigation_handle_->set_net_error_code(net::ERR_ABORTED);
// Update the service worker 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;
// Update the service worker and AppCache params of the request params.
request_params_.service_worker_provider_id =
did_create_service_worker_host
navigation_handle_->service_worker_handle()
? navigation_handle_->service_worker_handle()
->service_worker_provider_host_id()
: kInvalidServiceWorkerProviderId;
request_params_.appcache_host_id =
navigation_handle_->appcache_handle()
? navigation_handle_->appcache_handle()->appcache_host_id()
......
......@@ -28,12 +28,12 @@ class ServiceWorkerNavigationHandleCore;
// pointer to the ServiceWorkerNavigationHandleCore.
//
// 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.
//
// 4) The ServiceWorkerNavigationHandleCore informs the
// ServiceWorkerNavigationHandle on the UI that the service worker provider
// id was updated.
// ServiceWorkerNavigationHandle on the UI thread that the service worker
// provider id was updated.
//
// 5) When the navigation is ready to commit, the NavigationRequest will
// update the RequestNavigationParams based on the id from the
......
......@@ -179,9 +179,6 @@ void SharedWorkerServiceImpl::CreateWorker(
host->Start(std::move(factory), pause_on_start, devtools_worker_token);
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));
}
......
......@@ -149,58 +149,46 @@ ServiceWorkerNetworkProvider::CreateForNavigation(
bool content_initiated,
mojom::ControllerServiceWorkerInfoPtr controller_info,
scoped_refptr<network::SharedURLLoaderFactory> default_loader_factory) {
bool browser_side_navigation = IsBrowserSideNavigationEnabled();
bool should_create_provider_for_window = false;
int service_worker_provider_id = kInvalidServiceWorkerProviderId;
std::unique_ptr<ServiceWorkerNetworkProvider> network_provider;
std::unique_ptr<ServiceWorkerNetworkProvider> provider;
// Determine if a ServiceWorkerNetworkProvider should be created and properly
// initialized for the navigation. A default ServiceWorkerNetworkProvider
// will always be created since it is expected in a certain number of places,
// however it will have an invalid id.
// PlzNavigate: |service_worker_provider_id| can be sent by the browser, if
// it already created the SeviceWorkerProviderHost.
if (browser_side_navigation && !content_initiated) {
should_create_provider_for_window =
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 =
bool should_create_provider = false;
int provider_id = kInvalidServiceWorkerProviderId;
if (content_initiated) {
should_create_provider =
((frame->EffectiveSandboxFlags() & 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).
if (should_create_provider_for_window) {
// Ideally Document::isSecureContext would be called here, but the document
if (should_create_provider) {
// 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_parent_frame_secure to the browser process, so it can determine the
// context security when deciding whether to allow a service worker to
// control the document.
const bool is_parent_frame_secure = IsFrameSecure(frame->Parent());
if (service_worker_provider_id == kInvalidServiceWorkerProviderId) {
network_provider = base::WrapUnique(new ServiceWorkerNetworkProvider(
route_id, blink::mojom::ServiceWorkerProviderType::kForWindow,
GetNextProviderId(), is_parent_frame_secure,
std::move(controller_info), std::move(default_loader_factory)));
} else {
CHECK(browser_side_navigation);
DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(
service_worker_provider_id));
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)));
}
DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id) ||
provider_id == kInvalidServiceWorkerProviderId);
if (provider_id == kInvalidServiceWorkerProviderId)
provider_id = GetNextProviderId();
provider = base::WrapUnique(new ServiceWorkerNetworkProvider(
route_id, blink::mojom::ServiceWorkerProviderType::kForWindow,
provider_id, is_parent_frame_secure, std::move(controller_info),
std::move(default_loader_factory)));
} else {
network_provider = base::WrapUnique(new ServiceWorkerNetworkProvider());
provider = base::WrapUnique(new ServiceWorkerNetworkProvider());
}
return std::make_unique<WebServiceWorkerNetworkProviderForFrame>(
std::move(network_provider));
std::move(provider));
}
// 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