Service workers: Allow HTTPS pages arrived at via HTTP redirect to use SW
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_controllee_request_handler.h
blobdbe09907706ca6da2a1d59bcb72f63ac866a1e12
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_
8 #include "base/gtest_prod_util.h"
9 #include "content/browser/service_worker/service_worker_request_handler.h"
10 #include "content/common/service_worker/service_worker_types.h"
11 #include "content/public/common/request_context_frame_type.h"
12 #include "content/public/common/request_context_type.h"
13 #include "content/public/common/resource_type.h"
14 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerResponseType.h"
15 #include "url/gurl.h"
17 namespace net {
18 class NetworkDelegate;
19 class URLRequest;
22 namespace content {
24 class ResourceRequestBody;
25 class ServiceWorkerRegistration;
26 class ServiceWorkerURLRequestJob;
27 class ServiceWorkerVersion;
29 // A request handler derivative used to handle requests from
30 // controlled documents.
31 class CONTENT_EXPORT ServiceWorkerControlleeRequestHandler
32 : public ServiceWorkerRequestHandler {
33 public:
34 ServiceWorkerControlleeRequestHandler(
35 base::WeakPtr<ServiceWorkerContextCore> context,
36 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
37 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
38 FetchRequestMode request_mode,
39 FetchCredentialsMode credentials_mode,
40 FetchRedirectMode redirect_mode,
41 ResourceType resource_type,
42 RequestContextType request_context_type,
43 RequestContextFrameType frame_type,
44 scoped_refptr<ResourceRequestBody> body);
45 ~ServiceWorkerControlleeRequestHandler() override;
47 // Called via custom URLRequestJobFactory.
48 net::URLRequestJob* MaybeCreateJob(
49 net::URLRequest* request,
50 net::NetworkDelegate* network_delegate,
51 ResourceContext* resource_context) override;
53 void GetExtraResponseInfo(ResourceResponseInfo* response_info) const override;
55 private:
56 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
57 ActivateWaitingVersion);
58 typedef ServiceWorkerControlleeRequestHandler self;
60 // For main resource case.
61 void PrepareForMainResource(const net::URLRequest* request);
62 void DidLookupRegistrationForMainResource(
63 ServiceWorkerStatusCode status,
64 const scoped_refptr<ServiceWorkerRegistration>& registration);
65 void OnVersionStatusChanged(
66 ServiceWorkerRegistration* registration,
67 ServiceWorkerVersion* version);
69 // For sub resource case.
70 void PrepareForSubResource();
72 void FallbackToNetwork();
74 bool is_main_resource_load_;
75 scoped_refptr<ServiceWorkerURLRequestJob> job_;
76 FetchRequestMode request_mode_;
77 FetchCredentialsMode credentials_mode_;
78 FetchRedirectMode redirect_mode_;
79 RequestContextType request_context_type_;
80 RequestContextFrameType frame_type_;
81 scoped_refptr<ResourceRequestBody> body_;
82 ResourceContext* resource_context_;
83 GURL stripped_url_;
84 base::TimeTicks worker_start_time_;
85 base::TimeTicks worker_ready_time_;
86 bool skip_service_worker_;
87 base::WeakPtrFactory<ServiceWorkerControlleeRequestHandler> weak_factory_;
89 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler);
92 } // namespace content
94 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_