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

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

Issue 625433002: Pages controlled by ServiceWorkers should not participate in AppCaching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
(...skipping 29 matching lines...) Expand all
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 ResourceType resource_type, 63 ResourceType resource_type,
64 scoped_refptr<ResourceRequestBody> body) { 64 scoped_refptr<ResourceRequestBody> body) {
65 if (!request->url().SchemeIsHTTPOrHTTPS() || 65 if (!request->url().SchemeIsHTTPOrHTTPS() ||
66 !IsMethodSupportedForServiceWroker(request->method())) { 66 !IsMethodSupportedForServiceWorker(request->method())) {
67 return; 67 return;
68 } 68 }
69 69
70 if (!context_wrapper || !context_wrapper->context() || 70 if (!context_wrapper || !context_wrapper->context() ||
71 provider_id == kInvalidServiceWorkerProviderId) { 71 provider_id == kInvalidServiceWorkerProviderId) {
72 return; 72 return;
73 } 73 }
74 74
75 ServiceWorkerProviderHost* provider_host = 75 ServiceWorkerProviderHost* provider_host =
76 context_wrapper->context()->GetProviderHost(process_id, provider_id); 76 context_wrapper->context()->GetProviderHost(process_id, provider_id);
(...skipping 20 matching lines...) Expand all
97 return reinterpret_cast<ServiceWorkerRequestHandler*>( 97 return reinterpret_cast<ServiceWorkerRequestHandler*>(
98 request->GetUserData(&kUserDataKey)); 98 request->GetUserData(&kUserDataKey));
99 } 99 }
100 100
101 scoped_ptr<net::URLRequestInterceptor> 101 scoped_ptr<net::URLRequestInterceptor>
102 ServiceWorkerRequestHandler::CreateInterceptor() { 102 ServiceWorkerRequestHandler::CreateInterceptor() {
103 return scoped_ptr<net::URLRequestInterceptor>( 103 return scoped_ptr<net::URLRequestInterceptor>(
104 new ServiceWorkerRequestInterceptor); 104 new ServiceWorkerRequestInterceptor);
105 } 105 }
106 106
107 bool ServiceWorkerRequestHandler::IsControlledByServiceWorker(
108 net::URLRequest* request) {
109 ServiceWorkerRequestHandler* handler = GetHandler(request);
110 if (!handler || !handler->provider_host_)
111 return false;
112 return handler->provider_host_->associated_registration() ||
113 handler->provider_host_->running_hosted_version();
114 }
115
107 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() { 116 ServiceWorkerRequestHandler::~ServiceWorkerRequestHandler() {
108 } 117 }
109 118
110 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler( 119 ServiceWorkerRequestHandler::ServiceWorkerRequestHandler(
111 base::WeakPtr<ServiceWorkerContextCore> context, 120 base::WeakPtr<ServiceWorkerContextCore> context,
112 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 121 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
113 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 122 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
114 ResourceType resource_type) 123 ResourceType resource_type)
115 : context_(context), 124 : context_(context),
116 provider_host_(provider_host), 125 provider_host_(provider_host),
117 blob_storage_context_(blob_storage_context), 126 blob_storage_context_(blob_storage_context),
118 resource_type_(resource_type) { 127 resource_type_(resource_type) {
119 } 128 }
120 129
121 } // namespace content 130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698