Service Worker: Obey content settings when deciding to control a page
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_controllee_request_handler.h
blobfaa8f128bfa545553927d4f068c8a67ae82993d6
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"
15 namespace net {
16 class NetworkDelegate;
17 class URLRequest;
20 namespace content {
22 class ResourceRequestBody;
23 class ServiceWorkerRegistration;
24 class ServiceWorkerURLRequestJob;
25 class ServiceWorkerVersion;
27 // A request handler derivative used to handle requests from
28 // controlled documents.
29 class CONTENT_EXPORT ServiceWorkerControlleeRequestHandler
30 : public ServiceWorkerRequestHandler {
31 public:
32 ServiceWorkerControlleeRequestHandler(
33 base::WeakPtr<ServiceWorkerContextCore> context,
34 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
35 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
36 FetchRequestMode request_mode,
37 FetchCredentialsMode credentials_mode,
38 ResourceType resource_type,
39 RequestContextType request_context_type,
40 RequestContextFrameType frame_type,
41 scoped_refptr<ResourceRequestBody> body);
42 virtual ~ServiceWorkerControlleeRequestHandler();
44 // Called via custom URLRequestJobFactory.
45 virtual net::URLRequestJob* MaybeCreateJob(
46 net::URLRequest* request,
47 net::NetworkDelegate* network_delegate,
48 ResourceContext* resource_context) override;
50 virtual void GetExtraResponseInfo(
51 bool* was_fetched_via_service_worker,
52 bool* was_fallback_required_by_service_worker,
53 GURL* original_url_via_service_worker,
54 base::TimeTicks* fetch_start_time,
55 base::TimeTicks* fetch_ready_time,
56 base::TimeTicks* fetch_end_time) const override;
58 private:
59 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
60 ActivateWaitingVersion);
61 typedef ServiceWorkerControlleeRequestHandler self;
63 // For main resource case.
64 void PrepareForMainResource(const net::URLRequest* request);
65 void DidLookupRegistrationForMainResource(
66 ServiceWorkerStatusCode status,
67 const scoped_refptr<ServiceWorkerRegistration>& registration);
68 void OnVersionStatusChanged(
69 ServiceWorkerRegistration* registration,
70 ServiceWorkerVersion* version);
72 // For sub resource case.
73 void PrepareForSubResource();
75 bool is_main_resource_load_;
76 scoped_refptr<ServiceWorkerURLRequestJob> job_;
77 FetchRequestMode request_mode_;
78 FetchCredentialsMode credentials_mode_;
79 RequestContextType request_context_type_;
80 RequestContextFrameType frame_type_;
81 scoped_refptr<ResourceRequestBody> body_;
82 ResourceContext* resource_context_;
83 base::WeakPtrFactory<ServiceWorkerControlleeRequestHandler> weak_factory_;
85 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler);
88 } // namespace content
90 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_