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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 private: | 46 private: |
47 ResourceContext* resource_context_; | 47 ResourceContext* resource_context_; |
48 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); | 48 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); |
49 }; | 49 }; |
50 | 50 |
51 // This is work around to avoid hijacking CORS preflight. | 51 // This is work around to avoid hijacking CORS preflight. |
52 // TODO(horo): Remove this check when we implement "HTTP fetch" correctly. | 52 // TODO(horo): Remove this check when we implement "HTTP fetch" correctly. |
53 // http://fetch.spec.whatwg.org/#concept-http-fetch | 53 // http://fetch.spec.whatwg.org/#concept-http-fetch |
54 bool IsMethodSupportedForServiceWroker(const std::string& method) { | 54 bool IsMethodSupportedForServiceWorker(const std::string& method) { |
55 return method != "OPTIONS"; | 55 return method != "OPTIONS"; |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 void ServiceWorkerRequestHandler::InitializeHandler( | 60 void ServiceWorkerRequestHandler::InitializeHandler( |
61 net::URLRequest* request, | 61 net::URLRequest* request, |
62 ServiceWorkerContextWrapper* context_wrapper, | 62 ServiceWorkerContextWrapper* context_wrapper, |
63 storage::BlobStorageContext* blob_storage_context, | 63 storage::BlobStorageContext* blob_storage_context, |
64 int process_id, | 64 int process_id, |
65 int provider_id, | 65 int provider_id, |
66 bool skip_service_worker, | 66 bool skip_service_worker, |
67 FetchRequestMode request_mode, | 67 FetchRequestMode request_mode, |
68 FetchCredentialsMode credentials_mode, | 68 FetchCredentialsMode credentials_mode, |
69 ResourceType resource_type, | 69 ResourceType resource_type, |
70 RequestContextType request_context_type, | 70 RequestContextType request_context_type, |
71 RequestContextFrameType frame_type, | 71 RequestContextFrameType frame_type, |
72 scoped_refptr<ResourceRequestBody> body) { | 72 scoped_refptr<ResourceRequestBody> body) { |
73 if (!request->url().SchemeIsHTTPOrHTTPS() || | 73 if (!request->url().SchemeIsHTTPOrHTTPS() || |
74 !IsMethodSupportedForServiceWroker(request->method())) { | 74 !IsMethodSupportedForServiceWorker(request->method())) { |
75 return; | 75 return; |
76 } | 76 } |
77 | 77 |
78 if (!context_wrapper || !context_wrapper->context() || | 78 if (!context_wrapper || !context_wrapper->context() || |
79 provider_id == kInvalidServiceWorkerProviderId) { | 79 provider_id == kInvalidServiceWorkerProviderId) { |
80 return; | 80 return; |
81 } | 81 } |
82 | 82 |
83 ServiceWorkerProviderHost* provider_host = | 83 ServiceWorkerProviderHost* provider_host = |
84 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 84 context_wrapper->context()->GetProviderHost(process_id, provider_id); |
(...skipping 28 matching lines...) Expand all Loading... |
113 request->GetUserData(&kUserDataKey)); | 113 request->GetUserData(&kUserDataKey)); |
114 } | 114 } |
115 | 115 |
116 scoped_ptr<net::URLRequestInterceptor> | 116 scoped_ptr<net::URLRequestInterceptor> |
117 ServiceWorkerRequestHandler::CreateInterceptor( | 117 ServiceWorkerRequestHandler::CreateInterceptor( |
118 ResourceContext* resource_context) { | 118 ResourceContext* resource_context) { |
119 return scoped_ptr<net::URLRequestInterceptor>( | 119 return scoped_ptr<net::URLRequestInterceptor>( |
120 new ServiceWorkerRequestInterceptor(resource_context)); | 120 new ServiceWorkerRequestInterceptor(resource_context)); |
121 } | 121 } |
122 | 122 |
| 123 bool ServiceWorkerRequestHandler::IsControlledByServiceWorker( |
| 124 net::URLRequest* request) { |
| 125 ServiceWorkerRequestHandler* handler = GetHandler(request); |
| 126 if (!handler || !handler->provider_host_) |
| 127 return false; |
| 128 return handler->provider_host_->associated_registration() || |
| 129 handler->provider_host_->running_hosted_version(); |
| 130 } |
| 131 |
123 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { | 132 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { |
124 } | 133 } |
125 | 134 |
126 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( | 135 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( |
127 base::WeakPtr<ServiceWorkerContextCore> context, | 136 base::WeakPtr<ServiceWorkerContextCore> context, |
128 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 137 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
129 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 138 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
130 ResourceType resource_type) | 139 ResourceType resource_type) |
131 : context_(context), | 140 : context_(context), |
132 provider_host_(provider_host), | 141 provider_host_(provider_host), |
133 blob_storage_context_(blob_storage_context), | 142 blob_storage_context_(blob_storage_context), |
134 resource_type_(resource_type) { | 143 resource_type_(resource_type) { |
135 } | 144 } |
136 | 145 |
137 } // namespace content | 146 } // namespace content |
OLD | NEW |