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 "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 11 #include "content/browser/service_worker/service_worker_provider_host.h" | 11 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 12 #include "content/browser/service_worker/service_worker_registration.h" | 12 #include "content/browser/service_worker/service_worker_registration.h" |
| 13 #include "content/browser/service_worker/service_worker_url_request_job.h" | 13 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 14 #include "content/browser/service_worker/service_worker_utils.h" | 14 #include "content/browser/service_worker/service_worker_utils.h" |
| 15 #include "content/common/resource_request_body.h" | 15 #include "content/common/resource_request_body.h" |
| 16 #include "content/common/service_worker/service_worker_types.h" | 16 #include "content/common/service_worker/service_worker_types.h" |
| 17 #include "content/public/browser/resource_context.h" | |
| 17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 18 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_interceptor.h" | 20 #include "net/url_request/url_request_interceptor.h" |
| 20 #include "storage/browser/blob/blob_storage_context.h" | 21 #include "storage/browser/blob/blob_storage_context.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 int kUserDataKey; // Key value is not important. | 27 int kUserDataKey; // Key value is not important. |
| 27 | 28 |
| 28 class ServiceWorkerRequestInterceptor | 29 class ServiceWorkerRequestInterceptor |
| 29 : public net::URLRequestInterceptor { | 30 : public net::URLRequestInterceptor { |
| 30 public: | 31 public: |
| 31 ServiceWorkerRequestInterceptor() {} | 32 ServiceWorkerRequestInterceptor(ResourceContext* resource_context) |
|
jochen (gone - plz use gerrit)
2014/10/15 15:26:10
explicit
| |
| 33 : resource_context_(resource_context) {} | |
| 32 virtual ~ServiceWorkerRequestInterceptor() {} | 34 virtual ~ServiceWorkerRequestInterceptor() {} |
| 33 virtual net::URLRequestJob* MaybeInterceptRequest( | 35 virtual net::URLRequestJob* MaybeInterceptRequest( |
| 34 net::URLRequest* request, | 36 net::URLRequest* request, |
| 35 net::NetworkDelegate* network_delegate) const override { | 37 net::NetworkDelegate* network_delegate) const override { |
| 36 ServiceWorkerRequestHandler* handler = | 38 ServiceWorkerRequestHandler* handler = |
| 37 ServiceWorkerRequestHandler::GetHandler(request); | 39 ServiceWorkerRequestHandler::GetHandler(request); |
| 38 if (!handler) | 40 if (!handler) |
| 39 return NULL; | 41 return NULL; |
| 40 return handler->MaybeCreateJob(request, network_delegate); | 42 return handler->MaybeCreateJob( |
| 43 request, network_delegate, resource_context_); | |
| 41 } | 44 } |
| 42 | 45 |
| 43 private: | 46 private: |
| 47 ResourceContext* resource_context_; | |
| 44 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); | 48 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 // This is work around to avoid hijacking CORS preflight. | 51 // This is work around to avoid hijacking CORS preflight. |
| 48 // TODO(horo): Remove this check when we implement "HTTP fetch" correctly. | 52 // TODO(horo): Remove this check when we implement "HTTP fetch" correctly. |
| 49 // http://fetch.spec.whatwg.org/#concept-http-fetch | 53 // http://fetch.spec.whatwg.org/#concept-http-fetch |
| 50 bool IsMethodSupportedForServiceWroker(const std::string& method) { | 54 bool IsMethodSupportedForServiceWroker(const std::string& method) { |
| 51 return method != "OPTIONS"; | 55 return method != "OPTIONS"; |
| 52 } | 56 } |
| 53 | 57 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 request->SetUserData(&kUserDataKey, handler.release()); | 107 request->SetUserData(&kUserDataKey, handler.release()); |
| 104 } | 108 } |
| 105 | 109 |
| 106 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 110 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
| 107 net::URLRequest* request) { | 111 net::URLRequest* request) { |
| 108 return static_cast<ServiceWorkerRequestHandler*>( | 112 return static_cast<ServiceWorkerRequestHandler*>( |
| 109 request->GetUserData(&kUserDataKey)); | 113 request->GetUserData(&kUserDataKey)); |
| 110 } | 114 } |
| 111 | 115 |
| 112 scoped_ptr<net::URLRequestInterceptor> | 116 scoped_ptr<net::URLRequestInterceptor> |
| 113 ServiceWorkerRequestHandler::CreateInterceptor() { | 117 ServiceWorkerRequestHandler::CreateInterceptor( |
| 118 ResourceContext* resource_context) { | |
| 114 return scoped_ptr<net::URLRequestInterceptor>( | 119 return scoped_ptr<net::URLRequestInterceptor>( |
| 115 new ServiceWorkerRequestInterceptor); | 120 new ServiceWorkerRequestInterceptor(resource_context)); |
| 116 } | 121 } |
| 117 | 122 |
| 118 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { | 123 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { |
| 119 } | 124 } |
| 120 | 125 |
| 121 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( | 126 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( |
| 122 base::WeakPtr<ServiceWorkerContextCore> context, | 127 base::WeakPtr<ServiceWorkerContextCore> context, |
| 123 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 128 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 124 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 129 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| 125 ResourceType resource_type) | 130 ResourceType resource_type) |
| 126 : context_(context), | 131 : context_(context), |
| 127 provider_host_(provider_host), | 132 provider_host_(provider_host), |
| 128 blob_storage_context_(blob_storage_context), | 133 blob_storage_context_(blob_storage_context), |
| 129 resource_type_(resource_type) { | 134 resource_type_(resource_type) { |
| 130 } | 135 } |
| 131 | 136 |
| 132 } // namespace content | 137 } // namespace content |
| OLD | NEW |