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"
17 class NetworkDelegate
;
23 class ResourceRequestBody
;
24 class ServiceWorkerRegistration
;
25 class ServiceWorkerURLRequestJob
;
26 class ServiceWorkerVersion
;
28 // A request handler derivative used to handle requests from
29 // controlled documents.
30 class CONTENT_EXPORT ServiceWorkerControlleeRequestHandler
31 : public ServiceWorkerRequestHandler
{
33 ServiceWorkerControlleeRequestHandler(
34 base::WeakPtr
<ServiceWorkerContextCore
> context
,
35 base::WeakPtr
<ServiceWorkerProviderHost
> provider_host
,
36 base::WeakPtr
<storage::BlobStorageContext
> blob_storage_context
,
37 FetchRequestMode request_mode
,
38 FetchCredentialsMode credentials_mode
,
39 ResourceType resource_type
,
40 RequestContextType request_context_type
,
41 RequestContextFrameType frame_type
,
42 scoped_refptr
<ResourceRequestBody
> body
);
43 ~ServiceWorkerControlleeRequestHandler() override
;
45 // Called via custom URLRequestJobFactory.
46 net::URLRequestJob
* MaybeCreateJob(
47 net::URLRequest
* request
,
48 net::NetworkDelegate
* network_delegate
,
49 ResourceContext
* resource_context
) override
;
51 void GetExtraResponseInfo(
52 bool* was_fetched_via_service_worker
,
53 bool* was_fallback_required_by_service_worker
,
54 GURL
* original_url_via_service_worker
,
55 blink::WebServiceWorkerResponseType
* response_type_via_service_worker
,
56 base::TimeTicks
* fetch_start_time
,
57 base::TimeTicks
* fetch_ready_time
,
58 base::TimeTicks
* fetch_end_time
) const override
;
61 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest
,
62 ActivateWaitingVersion
);
63 typedef ServiceWorkerControlleeRequestHandler self
;
65 // For main resource case.
66 void PrepareForMainResource(const net::URLRequest
* request
);
67 void DidLookupRegistrationForMainResource(
68 ServiceWorkerStatusCode status
,
69 const scoped_refptr
<ServiceWorkerRegistration
>& registration
);
70 void OnVersionStatusChanged(
71 ServiceWorkerRegistration
* registration
,
72 ServiceWorkerVersion
* version
);
74 // For sub resource case.
75 void PrepareForSubResource();
77 bool is_main_resource_load_
;
78 scoped_refptr
<ServiceWorkerURLRequestJob
> job_
;
79 FetchRequestMode request_mode_
;
80 FetchCredentialsMode credentials_mode_
;
81 RequestContextType request_context_type_
;
82 RequestContextFrameType frame_type_
;
83 scoped_refptr
<ResourceRequestBody
> body_
;
84 ResourceContext
* resource_context_
;
85 base::WeakPtrFactory
<ServiceWorkerControlleeRequestHandler
> weak_factory_
;
87 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler
);
90 } // namespace content
92 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_