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(
53 bool* was_fetched_via_service_worker
,
54 bool* was_fallback_required_by_service_worker
,
55 GURL
* original_url_via_service_worker
,
56 blink::WebServiceWorkerResponseType
* response_type_via_service_worker
,
57 base::TimeTicks
* fetch_start_time
,
58 base::TimeTicks
* fetch_ready_time
,
59 base::TimeTicks
* fetch_end_time
) const override
;
62 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest
,
63 ActivateWaitingVersion
);
64 typedef ServiceWorkerControlleeRequestHandler self
;
66 // For main resource case.
67 void PrepareForMainResource(const net::URLRequest
* request
);
68 void DidLookupRegistrationForMainResource(
69 ServiceWorkerStatusCode status
,
70 const scoped_refptr
<ServiceWorkerRegistration
>& registration
);
71 void OnVersionStatusChanged(
72 ServiceWorkerRegistration
* registration
,
73 ServiceWorkerVersion
* version
);
75 // For sub resource case.
76 void PrepareForSubResource();
78 bool is_main_resource_load_
;
79 scoped_refptr
<ServiceWorkerURLRequestJob
> job_
;
80 FetchRequestMode request_mode_
;
81 FetchCredentialsMode credentials_mode_
;
82 RequestContextType request_context_type_
;
83 RequestContextFrameType frame_type_
;
84 scoped_refptr
<ResourceRequestBody
> body_
;
85 ResourceContext
* resource_context_
;
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_