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