Chromium Code Reviews| 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_request_handler.h" | 5 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | |
| 10 #include "content/browser/loader/navigation_url_loader_impl_core.h" | |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 11 #include "content/browser/service_worker/service_worker_provider_host.h" | 13 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 12 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
| 13 #include "content/browser/service_worker/service_worker_url_request_job.h" | 15 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 14 #include "content/browser/service_worker/service_worker_utils.h" | 16 #include "content/browser/service_worker/service_worker_utils.h" |
| 15 #include "content/common/resource_request_body.h" | 17 #include "content/common/resource_request_body.h" |
| 16 #include "content/common/service_worker/service_worker_types.h" | 18 #include "content/common/service_worker/service_worker_types.h" |
| 17 #include "content/public/browser/resource_context.h" | 19 #include "content/public/browser/resource_context.h" |
| 20 #include "content/public/common/content_switches.h" | |
| 18 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 19 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_interceptor.h" | 23 #include "net/url_request/url_request_interceptor.h" |
| 21 #include "storage/browser/blob/blob_storage_context.h" | 24 #include "storage/browser/blob/blob_storage_context.h" |
| 22 | |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 int kUserDataKey; // Key value is not important. | 29 int kUserDataKey; // Key value is not important. |
| 28 | 30 |
| 29 class ServiceWorkerRequestInterceptor | 31 class ServiceWorkerRequestInterceptor |
| 30 : public net::URLRequestInterceptor { | 32 : public net::URLRequestInterceptor { |
| 31 public: | 33 public: |
| 32 explicit ServiceWorkerRequestInterceptor(ResourceContext* resource_context) | 34 explicit ServiceWorkerRequestInterceptor(ResourceContext* resource_context) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 56 storage::BlobStorageContext* blob_storage_context, | 58 storage::BlobStorageContext* blob_storage_context, |
| 57 int process_id, | 59 int process_id, |
| 58 int provider_id, | 60 int provider_id, |
| 59 bool skip_service_worker, | 61 bool skip_service_worker, |
| 60 FetchRequestMode request_mode, | 62 FetchRequestMode request_mode, |
| 61 FetchCredentialsMode credentials_mode, | 63 FetchCredentialsMode credentials_mode, |
| 62 ResourceType resource_type, | 64 ResourceType resource_type, |
| 63 RequestContextType request_context_type, | 65 RequestContextType request_context_type, |
| 64 RequestContextFrameType frame_type, | 66 RequestContextFrameType frame_type, |
| 65 scoped_refptr<ResourceRequestBody> body) { | 67 scoped_refptr<ResourceRequestBody> body) { |
| 68 // PlzNavigate: | |
| 69 if (request->url().SchemeIsBlob()) { | |
|
michaeln
2015/07/24 22:22:27
Is there a more direct way of identifying plznavig
horo
2015/07/27 09:11:17
Removed these code from ServiceWorkerRequestHandle
| |
| 70 scoped_ptr<ServiceWorkerProviderHost> navigation_provider_host( | |
| 71 context_wrapper->context()->TakeNavigationProviderHost(request->url())); | |
| 72 if (navigation_provider_host) { | |
| 73 context_wrapper->context()->TransferProviderHostIn( | |
| 74 process_id, provider_id, navigation_provider_host.Pass()); | |
| 75 } | |
| 76 } | |
| 66 if (!request->url().SchemeIsHTTPOrHTTPS()) | 77 if (!request->url().SchemeIsHTTPOrHTTPS()) |
| 67 return; | 78 return; |
| 68 | 79 |
| 69 if (!context_wrapper || !context_wrapper->context() || | 80 if (!context_wrapper || !context_wrapper->context() || |
| 70 provider_id == kInvalidServiceWorkerProviderId) { | 81 provider_id == kInvalidServiceWorkerProviderId) { |
| 71 return; | 82 return; |
| 72 } | 83 } |
| 73 | 84 |
| 74 ServiceWorkerProviderHost* provider_host = | 85 ServiceWorkerProviderHost* provider_host = |
| 75 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 86 context_wrapper->context()->GetProviderHost(process_id, provider_id); |
| 76 if (!provider_host || !provider_host->IsContextAlive()) | 87 if (!provider_host || !provider_host->IsContextAlive()) |
| 77 return; | 88 return; |
| 78 | 89 |
| 79 if (skip_service_worker) { | 90 if (skip_service_worker) { |
| 80 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) { | 91 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) { |
| 81 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); | 92 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); |
| 82 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); | 93 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); |
| 83 // A page load with skip_service_worker should be triggered by | 94 // A page load with skip_service_worker should be triggered by |
| 84 // shift-reload, so retain all live matching registrations. | 95 // shift-reload, so retain all live matching registrations. |
| 85 provider_host->AddAllMatchingRegistrations(); | 96 provider_host->AddAllMatchingRegistrations(); |
| 86 } | 97 } |
| 87 return; | 98 return; |
| 88 } | 99 } |
| 89 | |
| 90 scoped_ptr<ServiceWorkerRequestHandler> handler( | 100 scoped_ptr<ServiceWorkerRequestHandler> handler( |
| 91 provider_host->CreateRequestHandler(request_mode, | 101 provider_host->CreateRequestHandler(request_mode, |
| 92 credentials_mode, | 102 credentials_mode, |
| 93 resource_type, | 103 resource_type, |
| 94 request_context_type, | 104 request_context_type, |
| 95 frame_type, | 105 frame_type, |
| 96 blob_storage_context->AsWeakPtr(), | 106 blob_storage_context->AsWeakPtr(), |
| 97 body)); | 107 body)); |
| 98 if (!handler) | 108 if (!handler) |
| 99 return; | 109 return; |
| 100 | 110 |
| 101 request->SetUserData(&kUserDataKey, handler.release()); | 111 request->SetUserData(&kUserDataKey, handler.release()); |
| 102 } | 112 } |
| 103 | 113 |
| 114 void ServiceWorkerRequestHandler::InitializeNavigationHandler( | |
| 115 net::URLRequest* request, | |
| 116 ServiceWorkerContextWrapper* context_wrapper, | |
| 117 storage::BlobStorageContext* blob_storage_context, | |
| 118 bool skip_service_worker, | |
| 119 bool is_main_frame, | |
| 120 scoped_refptr<ResourceRequestBody> body, | |
| 121 NavigationURLLoaderImplCore* loader) { | |
| 122 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 123 switches::kEnableBrowserSideNavigation)); | |
| 124 if (!request->url().SchemeIsHTTPOrHTTPS()) | |
| 125 return; | |
| 126 if (!context_wrapper || !context_wrapper->context()) | |
| 127 return; | |
| 128 scoped_ptr<ServiceWorkerProviderHost> provider_host( | |
| 129 context_wrapper->context()->CreateNavigationProviderHost()); | |
| 130 loader->SetServiceWorkerProviderHost(provider_host.Pass()); | |
| 131 if (skip_service_worker) { | |
| 132 // TODO(horo): Does it work correctly?. | |
| 133 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); | |
| 134 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); | |
| 135 provider_host->AddAllMatchingRegistrations(); | |
| 136 return; | |
| 137 } | |
| 138 scoped_ptr<ServiceWorkerRequestHandler> handler( | |
| 139 loader->service_worker_provider_host()->CreateRequestHandler( | |
| 140 FETCH_REQUEST_MODE_NO_CORS, FETCH_CREDENTIALS_MODE_SAME_ORIGIN, | |
| 141 is_main_frame ? RESOURCE_TYPE_MAIN_FRAME : RESOURCE_TYPE_SUB_FRAME, | |
| 142 REQUEST_CONTEXT_TYPE_LOCATION, // TODO(horo): pass in | |
| 143 // FrameHostMsg_BeginNavigation | |
| 144 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, // TODO(horo): pass in | |
| 145 // FrameHostMsg_BeginNavigation | |
| 146 blob_storage_context->AsWeakPtr(), body)); | |
| 147 if (!handler) | |
| 148 return; | |
| 149 request->SetUserData(&kUserDataKey, handler.release()); | |
| 150 } | |
| 151 | |
| 104 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 152 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
| 105 net::URLRequest* request) { | 153 net::URLRequest* request) { |
| 106 return static_cast<ServiceWorkerRequestHandler*>( | 154 return static_cast<ServiceWorkerRequestHandler*>( |
| 107 request->GetUserData(&kUserDataKey)); | 155 request->GetUserData(&kUserDataKey)); |
| 108 } | 156 } |
| 109 | 157 |
| 110 scoped_ptr<net::URLRequestInterceptor> | 158 scoped_ptr<net::URLRequestInterceptor> |
| 111 ServiceWorkerRequestHandler::CreateInterceptor( | 159 ServiceWorkerRequestHandler::CreateInterceptor( |
| 112 ResourceContext* resource_context) { | 160 ResourceContext* resource_context) { |
| 113 return scoped_ptr<net::URLRequestInterceptor>( | 161 return scoped_ptr<net::URLRequestInterceptor>( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 ResourceType resource_type) | 214 ResourceType resource_type) |
| 167 : context_(context), | 215 : context_(context), |
| 168 provider_host_(provider_host), | 216 provider_host_(provider_host), |
| 169 blob_storage_context_(blob_storage_context), | 217 blob_storage_context_(blob_storage_context), |
| 170 resource_type_(resource_type), | 218 resource_type_(resource_type), |
| 171 old_process_id_(0), | 219 old_process_id_(0), |
| 172 old_provider_id_(kInvalidServiceWorkerProviderId) { | 220 old_provider_id_(kInvalidServiceWorkerProviderId) { |
| 173 } | 221 } |
| 174 | 222 |
| 175 } // namespace content | 223 } // namespace content |
| OLD | NEW |