Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: content/browser/service_worker/service_worker_request_handler.cc

Issue 637243003: Service Worker: Obey content settings when deciding to control a page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@content
Patch Set: explicit, and better log Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/browser/service_worker/service_worker_provider_host.h" 11 #include "content/browser/service_worker/service_worker_provider_host.h"
12 #include "content/browser/service_worker/service_worker_registration.h" 12 #include "content/browser/service_worker/service_worker_registration.h"
13 #include "content/browser/service_worker/service_worker_url_request_job.h" 13 #include "content/browser/service_worker/service_worker_url_request_job.h"
14 #include "content/browser/service_worker/service_worker_utils.h" 14 #include "content/browser/service_worker/service_worker_utils.h"
15 #include "content/common/resource_request_body.h" 15 #include "content/common/resource_request_body.h"
16 #include "content/common/service_worker/service_worker_types.h" 16 #include "content/common/service_worker/service_worker_types.h"
17 #include "content/public/browser/resource_context.h"
17 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
18 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
19 #include "net/url_request/url_request_interceptor.h" 20 #include "net/url_request/url_request_interceptor.h"
20 #include "storage/browser/blob/blob_storage_context.h" 21 #include "storage/browser/blob/blob_storage_context.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 namespace { 25 namespace {
25 26
26 int kUserDataKey; // Key value is not important. 27 int kUserDataKey; // Key value is not important.
27 28
28 class ServiceWorkerRequestInterceptor 29 class ServiceWorkerRequestInterceptor
29 : public net::URLRequestInterceptor { 30 : public net::URLRequestInterceptor {
30 public: 31 public:
31 ServiceWorkerRequestInterceptor() {} 32 explicit ServiceWorkerRequestInterceptor(ResourceContext* resource_context)
33 : resource_context_(resource_context) {}
32 virtual ~ServiceWorkerRequestInterceptor() {} 34 virtual ~ServiceWorkerRequestInterceptor() {}
33 virtual net::URLRequestJob* MaybeInterceptRequest( 35 virtual net::URLRequestJob* MaybeInterceptRequest(
34 net::URLRequest* request, 36 net::URLRequest* request,
35 net::NetworkDelegate* network_delegate) const override { 37 net::NetworkDelegate* network_delegate) const override {
36 ServiceWorkerRequestHandler* handler = 38 ServiceWorkerRequestHandler* handler =
37 ServiceWorkerRequestHandler::GetHandler(request); 39 ServiceWorkerRequestHandler::GetHandler(request);
38 if (!handler) 40 if (!handler)
39 return NULL; 41 return NULL;
40 return handler->MaybeCreateJob(request, network_delegate); 42 return handler->MaybeCreateJob(
43 request, network_delegate, resource_context_);
41 } 44 }
42 45
43 private: 46 private:
47 ResourceContext* resource_context_;
44 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor); 48 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor);
45 }; 49 };
46 50
47 // This is work around to avoid hijacking CORS preflight. 51 // This is work around to avoid hijacking CORS preflight.
48 // TODO(horo): Remove this check when we implement "HTTP fetch" correctly. 52 // TODO(horo): Remove this check when we implement "HTTP fetch" correctly.
49 // http://fetch.spec.whatwg.org/#concept-http-fetch 53 // http://fetch.spec.whatwg.org/#concept-http-fetch
50 bool IsMethodSupportedForServiceWroker(const std::string& method) { 54 bool IsMethodSupportedForServiceWroker(const std::string& method) {
51 return method != "OPTIONS"; 55 return method != "OPTIONS";
52 } 56 }
53 57
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 request->SetUserData(&kUserDataKey, handler.release()); 107 request->SetUserData(&kUserDataKey, handler.release());
104 } 108 }
105 109
106 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( 110 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler(
107 net::URLRequest* request) { 111 net::URLRequest* request) {
108 return static_cast<ServiceWorkerRequestHandler*>( 112 return static_cast<ServiceWorkerRequestHandler*>(
109 request->GetUserData(&kUserDataKey)); 113 request->GetUserData(&kUserDataKey));
110 } 114 }
111 115
112 scoped_ptr<net::URLRequestInterceptor> 116 scoped_ptr<net::URLRequestInterceptor>
113 ServiceWorkerRequestHandler::CreateInterceptor() { 117 ServiceWorkerRequestHandler::CreateInterceptor(
118 ResourceContext* resource_context) {
114 return scoped_ptr<net::URLRequestInterceptor>( 119 return scoped_ptr<net::URLRequestInterceptor>(
115 new ServiceWorkerRequestInterceptor); 120 new ServiceWorkerRequestInterceptor(resource_context));
116 } 121 }
117 122
118 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { 123 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() {
119 } 124 }
120 125
121 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( 126 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler(
122 base::WeakPtr<ServiceWorkerContextCore> context, 127 base::WeakPtr<ServiceWorkerContextCore> context,
123 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 128 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
124 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 129 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
125 ResourceType resource_type) 130 ResourceType resource_type)
126 : context_(context), 131 : context_(context),
127 provider_host_(provider_host), 132 provider_host_(provider_host),
128 blob_storage_context_(blob_storage_context), 133 blob_storage_context_(blob_storage_context),
129 resource_type_(resource_type) { 134 resource_type_(resource_type) {
130 } 135 }
131 136
132 } // namespace content 137 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_request_handler.h ('k') | content/browser/storage_partition_impl_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698