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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 ServiceWorkerRequestHandler::GetHandler(request); | 31 ServiceWorkerRequestHandler::GetHandler(request); |
32 if (!handler) | 32 if (!handler) |
33 return NULL; | 33 return NULL; |
34 return handler->MaybeCreateJob(request, network_delegate); | 34 return handler->MaybeCreateJob(request, network_delegate); |
35 } | 35 } |
36 | 36 |
37 private: | 37 private: |
38 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); | 38 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); |
39 }; | 39 }; |
40 | 40 |
| 41 bool IsSchemeSupported(const GURL& url) { |
| 42 // TODO(michaeln): https only |
| 43 return url.SchemeIs("http") || url.SchemeIs("https"); |
| 44 } |
| 45 |
| 46 bool IsMethodSupported(const std::string& method) { |
| 47 return (method == "GET") || (method == "HEAD"); |
| 48 } |
| 49 |
| 50 bool IsSchemeAndMethodSupported(const net::URLRequest* request) { |
| 51 return IsSchemeSupported(request->url()) && |
| 52 IsMethodSupported(request->method()); |
| 53 } |
| 54 |
41 } // namespace | 55 } // namespace |
42 | 56 |
43 void ServiceWorkerRequestHandler::InitializeHandler( | 57 void ServiceWorkerRequestHandler::InitializeHandler( |
44 net::URLRequest* request, | 58 net::URLRequest* request, |
45 ServiceWorkerContextWrapper* context_wrapper, | 59 ServiceWorkerContextWrapper* context_wrapper, |
46 int process_id, | 60 int process_id, |
47 int provider_id, | 61 int provider_id, |
48 ResourceType::Type resource_type) { | 62 ResourceType::Type resource_type) { |
49 if (!ServiceWorkerUtils::IsFeatureEnabled()) | 63 if (!ServiceWorkerUtils::IsFeatureEnabled() || |
| 64 !IsSchemeAndMethodSupported(request)) { |
50 return; | 65 return; |
| 66 } |
51 | 67 |
52 if (!context_wrapper || !context_wrapper->context() || | 68 if (!context_wrapper || !context_wrapper->context() || |
53 provider_id == kInvalidServiceWorkerProviderId) { | 69 provider_id == kInvalidServiceWorkerProviderId) { |
54 return; | 70 return; |
55 } | 71 } |
56 | 72 |
57 ServiceWorkerProviderHost* provider_host = | 73 ServiceWorkerProviderHost* provider_host = |
58 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 74 context_wrapper->context()->GetProviderHost(process_id, provider_id); |
59 if (!provider_host) | 75 if (!provider_host) |
60 return; | 76 return; |
(...skipping 24 matching lines...) Expand all Loading... |
85 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( | 101 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( |
86 base::WeakPtr<ServiceWorkerContextCore> context, | 102 base::WeakPtr<ServiceWorkerContextCore> context, |
87 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 103 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
88 ResourceType::Type resource_type) | 104 ResourceType::Type resource_type) |
89 : context_(context), | 105 : context_(context), |
90 provider_host_(provider_host), | 106 provider_host_(provider_host), |
91 resource_type_(resource_type) { | 107 resource_type_(resource_type) { |
92 } | 108 } |
93 | 109 |
94 } // namespace content | 110 } // namespace content |
OLD | NEW |