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