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/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
9 #include "content/browser/service_worker/service_worker_provider_host.h" | 9 #include "content/browser/service_worker/service_worker_provider_host.h" |
10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
11 #include "content/browser/service_worker/service_worker_url_request_job.h" | 11 #include "content/browser/service_worker/service_worker_url_request_job.h" |
12 #include "content/browser/service_worker/service_worker_utils.h" | 12 #include "content/browser/service_worker/service_worker_utils.h" |
13 #include "content/common/service_worker/service_worker_types.h" | 13 #include "content/common/service_worker/service_worker_types.h" |
14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 15 #include "webkit/browser/blob/blob_storage_context.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: |
(...skipping 20 matching lines...) Expand all Loading... |
45 bool IsSchemeAndMethodSupported(const net::URLRequest* request) { | 46 bool IsSchemeAndMethodSupported(const net::URLRequest* request) { |
46 return request->url().SchemeIsHTTPOrHTTPS() && | 47 return request->url().SchemeIsHTTPOrHTTPS() && |
47 IsMethodSupported(request->method()); | 48 IsMethodSupported(request->method()); |
48 } | 49 } |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 void ServiceWorkerRequestHandler::InitializeHandler( | 53 void ServiceWorkerRequestHandler::InitializeHandler( |
53 net::URLRequest* request, | 54 net::URLRequest* request, |
54 ServiceWorkerContextWrapper* context_wrapper, | 55 ServiceWorkerContextWrapper* context_wrapper, |
| 56 webkit_blob::BlobStorageContext* blob_storage_context, |
55 int process_id, | 57 int process_id, |
56 int provider_id, | 58 int provider_id, |
57 ResourceType::Type resource_type) { | 59 ResourceType::Type resource_type) { |
58 if (!ServiceWorkerUtils::IsFeatureEnabled() || | 60 if (!ServiceWorkerUtils::IsFeatureEnabled() || |
59 !IsSchemeAndMethodSupported(request)) { | 61 !IsSchemeAndMethodSupported(request)) { |
60 return; | 62 return; |
61 } | 63 } |
62 | 64 |
63 if (!context_wrapper || !context_wrapper->context() || | 65 if (!context_wrapper || !context_wrapper->context() || |
64 provider_id == kInvalidServiceWorkerProviderId) { | 66 provider_id == kInvalidServiceWorkerProviderId) { |
65 return; | 67 return; |
66 } | 68 } |
67 | 69 |
68 ServiceWorkerProviderHost* provider_host = | 70 ServiceWorkerProviderHost* provider_host = |
69 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 71 context_wrapper->context()->GetProviderHost(process_id, provider_id); |
70 if (!provider_host) | 72 if (!provider_host) |
71 return; | 73 return; |
72 | 74 |
73 scoped_ptr<ServiceWorkerRequestHandler> handler( | 75 scoped_ptr<ServiceWorkerRequestHandler> handler( |
74 provider_host->CreateRequestHandler(resource_type)); | 76 provider_host->CreateRequestHandler(resource_type, |
| 77 blob_storage_context->AsWeakPtr())); |
75 if (!handler) | 78 if (!handler) |
76 return; | 79 return; |
77 | 80 |
78 request->SetUserData(&kUserDataKey, handler.release()); | 81 request->SetUserData(&kUserDataKey, handler.release()); |
79 } | 82 } |
80 | 83 |
81 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 84 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
82 net::URLRequest* request) { | 85 net::URLRequest* request) { |
83 return reinterpret_cast<ServiceWorkerRequestHandler*>( | 86 return reinterpret_cast<ServiceWorkerRequestHandler*>( |
84 request->GetUserData(&kUserDataKey)); | 87 request->GetUserData(&kUserDataKey)); |
85 } | 88 } |
86 | 89 |
87 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 90 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
88 ServiceWorkerRequestHandler::CreateInterceptor() { | 91 ServiceWorkerRequestHandler::CreateInterceptor() { |
89 return make_scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 92 return make_scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
90 new ServiceWorkerRequestInterceptor); | 93 new ServiceWorkerRequestInterceptor); |
91 } | 94 } |
92 | 95 |
93 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { | 96 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { |
94 } | 97 } |
95 | 98 |
96 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( | 99 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( |
97 base::WeakPtr<ServiceWorkerContextCore> context, | 100 base::WeakPtr<ServiceWorkerContextCore> context, |
98 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 101 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 102 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context, |
99 ResourceType::Type resource_type) | 103 ResourceType::Type resource_type) |
100 : context_(context), | 104 : context_(context), |
101 provider_host_(provider_host), | 105 provider_host_(provider_host), |
| 106 blob_storage_context_(blob_storage_context), |
102 resource_type_(resource_type) { | 107 resource_type_(resource_type) { |
103 } | 108 } |
104 | 109 |
105 } // namespace content | 110 } // namespace content |
OLD | NEW |