OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_H_ | 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_H_ |
6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_H_ | 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "content/common/service_worker/service_worker_types.h" | 17 #include "content/common/service_worker/service_worker_types.h" |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 class WebDataSource; | 20 class WebDataSource; |
21 class WebLocalFrame; | 21 class WebLocalFrame; |
22 } // namespace blink | 22 } // namespace blink |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 class ServiceWorkerProviderContext; | 26 class ServiceWorkerProviderContext; |
27 struct RequestNavigationParams; | |
28 | 27 |
29 // A unique provider_id is generated for each instance. | 28 // A unique provider_id is generated for each instance. |
30 // Instantiated prior to the main resource load being started and remains | 29 // Instantiated prior to the main resource load being started and remains |
31 // allocated until after the last subresource load has occurred. | 30 // allocated until after the last subresource load has occurred. |
32 // This is used to track the lifetime of a Document to create | 31 // This is used to track the lifetime of a Document to create |
33 // and dispose the ServiceWorkerProviderHost in the browser process | 32 // and dispose the ServiceWorkerProviderHost in the browser process |
34 // to match its lifetime. Each request coming from the Document is | 33 // to match its lifetime. Each request coming from the Document is |
35 // tagged with this id in willSendRequest. | 34 // tagged with this id in willSendRequest. |
36 // | 35 // |
37 // Basically, it's a scoped integer that sends an ipc upon construction | 36 // Basically, it's a scoped integer that sends an ipc upon construction |
38 // and destruction. | 37 // and destruction. |
39 class CONTENT_EXPORT ServiceWorkerNetworkProvider | 38 class CONTENT_EXPORT ServiceWorkerNetworkProvider |
40 : public base::SupportsUserData::Data { | 39 : public base::SupportsUserData::Data { |
41 public: | 40 public: |
42 // Ownership is transferred to the DocumentState. | 41 // Ownership is transferred to the DocumentState. |
43 static void AttachToDocumentState( | 42 static void AttachToDocumentState( |
44 base::SupportsUserData* document_state, | 43 base::SupportsUserData* document_state, |
45 std::unique_ptr<ServiceWorkerNetworkProvider> network_provider); | 44 std::unique_ptr<ServiceWorkerNetworkProvider> network_provider); |
46 | 45 |
47 static ServiceWorkerNetworkProvider* FromDocumentState( | 46 static ServiceWorkerNetworkProvider* FromDocumentState( |
48 base::SupportsUserData* document_state); | 47 base::SupportsUserData* document_state); |
49 | 48 |
50 static std::unique_ptr<ServiceWorkerNetworkProvider> CreateForNavigation( | 49 static std::unique_ptr<ServiceWorkerNetworkProvider> CreateForNavigation( |
51 int route_id, | 50 int route_id, |
52 const RequestNavigationParams& request_params, | |
53 blink::WebLocalFrame* frame, | 51 blink::WebLocalFrame* frame, |
54 bool content_initiated); | 52 bool content_initiated); |
55 | 53 |
56 // PlzNavigate | |
57 // The |browser_provider_id| is initialized by the browser for navigations. | |
58 ServiceWorkerNetworkProvider(int route_id, | |
59 ServiceWorkerProviderType type, | |
60 int browser_provider_id, | |
61 bool is_parent_frame_secure); | |
62 ServiceWorkerNetworkProvider(int route_id, | 54 ServiceWorkerNetworkProvider(int route_id, |
63 ServiceWorkerProviderType type, | 55 ServiceWorkerProviderType type, |
64 bool is_parent_frame_secure); | 56 bool is_parent_frame_secure); |
65 ServiceWorkerNetworkProvider(); | 57 ServiceWorkerNetworkProvider(); |
66 ~ServiceWorkerNetworkProvider() override; | 58 ~ServiceWorkerNetworkProvider() override; |
67 | 59 |
68 int provider_id() const { return provider_id_; } | 60 int provider_id() const { return provider_id_; } |
69 ServiceWorkerProviderContext* context() const { return context_.get(); } | 61 ServiceWorkerProviderContext* context() const { return context_.get(); } |
70 | 62 |
71 // This method is called for a provider that's associated with a | 63 // This method is called for a provider that's associated with a |
72 // running service worker script. The version_id indicates which | 64 // running service worker script. The version_id indicates which |
73 // ServiceWorkerVersion should be used. | 65 // ServiceWorkerVersion should be used. |
74 void SetServiceWorkerVersionId(int64_t version_id); | 66 void SetServiceWorkerVersionId(int64_t version_id); |
75 | 67 |
76 bool IsControlledByServiceWorker() const; | 68 bool IsControlledByServiceWorker() const; |
77 | 69 |
78 private: | 70 private: |
79 const int provider_id_; | 71 const int provider_id_; |
80 scoped_refptr<ServiceWorkerProviderContext> context_; | 72 scoped_refptr<ServiceWorkerProviderContext> context_; |
81 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerNetworkProvider); | 73 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerNetworkProvider); |
82 }; | 74 }; |
83 | 75 |
84 } // namespace content | 76 } // namespace content |
85 | 77 |
86 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_H_ | 78 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_NETWORK_PROVIDER_H_ |
OLD | NEW |