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/WebServiceWorkerResponseType.h"
18 class NetworkDelegate
;
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
{
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 ResourceType resource_type
,
41 RequestContextType request_context_type
,
42 RequestContextFrameType frame_type
,
43 scoped_refptr
<ResourceRequestBody
> body
);
44 ~ServiceWorkerControlleeRequestHandler() override
;
46 // Called via custom URLRequestJobFactory.
47 net::URLRequestJob
* MaybeCreateJob(
48 net::URLRequest
* request
,
49 net::NetworkDelegate
* network_delegate
,
50 ResourceContext
* resource_context
) override
;
52 void GetExtraResponseInfo(ResourceResponseInfo
* response_info
) const override
;
55 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest
,
56 ActivateWaitingVersion
);
57 typedef ServiceWorkerControlleeRequestHandler self
;
59 // For main resource case.
60 void PrepareForMainResource(const net::URLRequest
* request
);
61 void DidLookupRegistrationForMainResource(
62 ServiceWorkerStatusCode status
,
63 const scoped_refptr
<ServiceWorkerRegistration
>& registration
);
64 void OnVersionStatusChanged(
65 ServiceWorkerRegistration
* registration
,
66 ServiceWorkerVersion
* version
);
68 // For sub resource case.
69 void PrepareForSubResource();
71 bool is_main_resource_load_
;
72 scoped_refptr
<ServiceWorkerURLRequestJob
> job_
;
73 FetchRequestMode request_mode_
;
74 FetchCredentialsMode credentials_mode_
;
75 RequestContextType request_context_type_
;
76 RequestContextFrameType frame_type_
;
77 scoped_refptr
<ResourceRequestBody
> body_
;
78 ResourceContext
* resource_context_
;
80 base::TimeTicks worker_start_time_
;
81 base::TimeTicks worker_ready_time_
;
82 base::WeakPtrFactory
<ServiceWorkerControlleeRequestHandler
> weak_factory_
;
84 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler
);
87 } // namespace content
89 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_