| 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 "content/browser/fileapi/chrome_blob_storage_context.h" |
| 7 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 9 #include "content/browser/service_worker/service_worker_provider_host.h" | 10 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 11 #include "content/browser/service_worker/service_worker_registration.h" |
| 11 #include "content/browser/service_worker/service_worker_url_request_job.h" | 12 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 12 #include "content/browser/service_worker/service_worker_utils.h" | 13 #include "content/browser/service_worker/service_worker_utils.h" |
| 13 #include "content/common/service_worker/service_worker_types.h" | 14 #include "content/common/service_worker/service_worker_types.h" |
| 14 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 int kUserDataKey; // Key value is not important. | 21 int kUserDataKey; // Key value is not important. |
| 21 | 22 |
| 22 class ServiceWorkerRequestInterceptor | 23 class ServiceWorkerRequestInterceptor |
| 23 : public net::URLRequestJobFactory::ProtocolHandler { | 24 : public net::URLRequestJobFactory::ProtocolHandler { |
| 24 public: | 25 public: |
| 25 ServiceWorkerRequestInterceptor() {} | 26 ServiceWorkerRequestInterceptor( |
| 27 ChromeBlobStorageContext* blob_storage_context) |
| 28 : blob_storage_context_(blob_storage_context) {} |
| 26 virtual ~ServiceWorkerRequestInterceptor() {} | 29 virtual ~ServiceWorkerRequestInterceptor() {} |
| 27 virtual net::URLRequestJob* MaybeCreateJob( | 30 virtual net::URLRequestJob* MaybeCreateJob( |
| 28 net::URLRequest* request, | 31 net::URLRequest* request, |
| 29 net::NetworkDelegate* network_delegate) const OVERRIDE { | 32 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 30 ServiceWorkerRequestHandler* handler = | 33 ServiceWorkerRequestHandler* handler = |
| 31 ServiceWorkerRequestHandler::GetHandler(request); | 34 ServiceWorkerRequestHandler::GetHandler(request); |
| 32 if (!handler) | 35 if (!handler) |
| 33 return NULL; | 36 return NULL; |
| 34 return handler->MaybeCreateJob(request, network_delegate); | 37 return handler->MaybeCreateJob( |
| 38 request, network_delegate, blob_storage_context_); |
| 35 } | 39 } |
| 36 | 40 |
| 37 private: | 41 private: |
| 42 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 43 |
| 38 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); | 44 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); |
| 39 }; | 45 }; |
| 40 | 46 |
| 41 bool IsMethodSupported(const std::string& method) { | 47 bool IsMethodSupported(const std::string& method) { |
| 42 return (method == "GET") || (method == "HEAD"); | 48 return (method == "GET") || (method == "HEAD"); |
| 43 } | 49 } |
| 44 | 50 |
| 45 bool IsSchemeAndMethodSupported(const net::URLRequest* request) { | 51 bool IsSchemeAndMethodSupported(const net::URLRequest* request) { |
| 46 return request->url().SchemeIsHTTPOrHTTPS() && | 52 return request->url().SchemeIsHTTPOrHTTPS() && |
| 47 IsMethodSupported(request->method()); | 53 IsMethodSupported(request->method()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 78 request->SetUserData(&kUserDataKey, handler.release()); | 84 request->SetUserData(&kUserDataKey, handler.release()); |
| 79 } | 85 } |
| 80 | 86 |
| 81 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 87 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
| 82 net::URLRequest* request) { | 88 net::URLRequest* request) { |
| 83 return reinterpret_cast<ServiceWorkerRequestHandler*>( | 89 return reinterpret_cast<ServiceWorkerRequestHandler*>( |
| 84 request->GetUserData(&kUserDataKey)); | 90 request->GetUserData(&kUserDataKey)); |
| 85 } | 91 } |
| 86 | 92 |
| 87 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 93 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 88 ServiceWorkerRequestHandler::CreateInterceptor() { | 94 ServiceWorkerRequestHandler::CreateInterceptor( |
| 95 ChromeBlobStorageContext* blob_storage_context) { |
| 89 return make_scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 96 return make_scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 90 new ServiceWorkerRequestInterceptor); | 97 new ServiceWorkerRequestInterceptor(blob_storage_context)); |
| 91 } | 98 } |
| 92 | 99 |
| 93 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { | 100 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { |
| 94 } | 101 } |
| 95 | 102 |
| 96 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( | 103 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( |
| 97 base::WeakPtr<ServiceWorkerContextCore> context, | 104 base::WeakPtr<ServiceWorkerContextCore> context, |
| 98 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 105 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 99 ResourceType::Type resource_type) | 106 ResourceType::Type resource_type) |
| 100 : context_(context), | 107 : context_(context), |
| 101 provider_host_(provider_host), | 108 provider_host_(provider_host), |
| 102 resource_type_(resource_type) { | 109 resource_type_(resource_type) { |
| 103 } | 110 } |
| 104 | 111 |
| 105 } // namespace content | 112 } // namespace content |
| OLD | NEW |