[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 1 | // Copyright (c) 2013 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. | ||||
4 | |||||
5 | #ifndef CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_ | ||||
6 | #define CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_ | ||||
7 | |||||
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 8 | #include <memory> |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 9 | #include <string> |
10 | |||||
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 12 | #include "base/supports_user_data.h" |
Dmitry Gozman | 2d87196 | 2019-01-08 00:05:02 | [diff] [blame] | 13 | #include "content/public/common/previews_state.h" |
Dmitry Gozman | 1a2cb24 | 2018-12-15 02:51:29 | [diff] [blame] | 14 | #include "net/nqe/effective_connection_type.h" |
Richard Li | e689995 | 2018-11-30 08:42:00 | [diff] [blame] | 15 | #include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 16 | #include "url/gurl.h" |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 17 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 18 | namespace blink { |
Takeshi Yoshino | 41b671a | 2017-08-01 12:17:51 | [diff] [blame] | 19 | class WebDocumentLoader; |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 20 | } |
21 | |||||
22 | namespace content { | ||||
23 | |||||
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 24 | class DocumentState; |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 25 | class NavigationState; |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 26 | |
Takeshi Yoshino | 41b671a | 2017-08-01 12:17:51 | [diff] [blame] | 27 | // Stores internal state per WebDocumentLoader. |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 28 | class InternalDocumentStateData : public base::SupportsUserData::Data { |
29 | public: | ||||
30 | InternalDocumentStateData(); | ||||
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 31 | ~InternalDocumentStateData() override; |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 32 | |
Takeshi Yoshino | 41b671a | 2017-08-01 12:17:51 | [diff] [blame] | 33 | static InternalDocumentStateData* FromDocumentLoader( |
34 | blink::WebDocumentLoader* document_loader); | ||||
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 35 | static InternalDocumentStateData* FromDocumentState(DocumentState* ds); |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 36 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 37 | void CopyFrom(InternalDocumentStateData* other); |
38 | |||||
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 39 | int http_status_code() const { return http_status_code_; } |
40 | void set_http_status_code(int http_status_code) { | ||||
41 | http_status_code_ = http_status_code; | ||||
42 | } | ||||
43 | |||||
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 44 | // True if the user agent was overridden for this page. |
45 | bool is_overriding_user_agent() const { return is_overriding_user_agent_; } | ||||
46 | void set_is_overriding_user_agent(bool state) { | ||||
47 | is_overriding_user_agent_ = state; | ||||
48 | } | ||||
49 | |||||
50 | // True if we have to reset the scroll and scale state of the page | ||||
51 | // after the provisional load has been committed. | ||||
52 | bool must_reset_scroll_and_scale_state() const { | ||||
53 | return must_reset_scroll_and_scale_state_; | ||||
54 | } | ||||
55 | void set_must_reset_scroll_and_scale_state(bool state) { | ||||
56 | must_reset_scroll_and_scale_state_ = state; | ||||
57 | } | ||||
58 | |||||
59 | // Sets the cache policy. The cache policy is only used if explicitly set and | ||||
60 | // by default is not set. You can mark a NavigationState as not having a cache | ||||
61 | // state by way of clear_cache_policy_override. | ||||
Yutaka Hirano | 458b913 | 2017-10-24 15:17:21 | [diff] [blame] | 62 | void set_cache_policy_override(blink::mojom::FetchCacheMode cache_policy) { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 63 | cache_policy_override_ = cache_policy; |
64 | cache_policy_override_set_ = true; | ||||
65 | } | ||||
Yutaka Hirano | 458b913 | 2017-10-24 15:17:21 | [diff] [blame] | 66 | blink::mojom::FetchCacheMode cache_policy_override() const { |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 67 | return cache_policy_override_; |
68 | } | ||||
69 | void clear_cache_policy_override() { | ||||
70 | cache_policy_override_set_ = false; | ||||
Yutaka Hirano | 458b913 | 2017-10-24 15:17:21 | [diff] [blame] | 71 | cache_policy_override_ = blink::mojom::FetchCacheMode::kDefault; |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 72 | } |
73 | bool is_cache_policy_override_set() const { | ||||
74 | return cache_policy_override_set_; | ||||
75 | } | ||||
76 | |||||
Dmitry Gozman | 1a2cb24 | 2018-12-15 02:51:29 | [diff] [blame] | 77 | net::EffectiveConnectionType effective_connection_type() const { |
78 | return effective_connection_type_; | ||||
79 | } | ||||
80 | void set_effective_connection_type( | ||||
81 | net::EffectiveConnectionType effective_connection_type) { | ||||
82 | effective_connection_type_ = effective_connection_type; | ||||
83 | } | ||||
84 | |||||
Dmitry Gozman | 2d87196 | 2019-01-08 00:05:02 | [diff] [blame] | 85 | PreviewsState previews_state() const { return previews_state_; } |
86 | void set_previews_state(PreviewsState previews_state) { | ||||
87 | previews_state_ = previews_state; | ||||
88 | } | ||||
89 | |||||
Dmitry Gozman | 00fd5bb | 2019-01-25 20:25:33 | [diff] [blame^] | 90 | // This is a fake navigation request id, which we send to the browser process |
91 | // together with metrics. Note that renderer does not actually issue a request | ||||
92 | // for navigation (browser does it instead), but still reports metrics for it. | ||||
93 | // See content::mojom::ResourceLoadInfo. | ||||
94 | int request_id() const { return request_id_; } | ||||
95 | void set_request_id(int request_id) { request_id_ = request_id; } | ||||
96 | |||||
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 97 | NavigationState* navigation_state() { return navigation_state_.get(); } |
98 | void set_navigation_state(std::unique_ptr<NavigationState> navigation_state); | ||||
99 | |||||
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 100 | private: |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 101 | int http_status_code_; |
[email protected] | e20b88d | 2013-04-09 15:28:37 | [diff] [blame] | 102 | bool is_overriding_user_agent_; |
103 | bool must_reset_scroll_and_scale_state_; | ||||
104 | bool cache_policy_override_set_; | ||||
Yutaka Hirano | 458b913 | 2017-10-24 15:17:21 | [diff] [blame] | 105 | blink::mojom::FetchCacheMode cache_policy_override_; |
Dmitry Gozman | 1a2cb24 | 2018-12-15 02:51:29 | [diff] [blame] | 106 | net::EffectiveConnectionType effective_connection_type_ = |
107 | net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | ||||
Dmitry Gozman | 2d87196 | 2019-01-08 00:05:02 | [diff] [blame] | 108 | PreviewsState previews_state_ = PREVIEWS_UNSPECIFIED; |
Dmitry Gozman | 00fd5bb | 2019-01-25 20:25:33 | [diff] [blame^] | 109 | int request_id_ = -1; |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 110 | std::unique_ptr<NavigationState> navigation_state_; |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 111 | |
112 | DISALLOW_COPY_AND_ASSIGN(InternalDocumentStateData); | ||||
113 | }; | ||||
114 | |||||
115 | } // namespace content | ||||
116 | |||||
117 | #endif // CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_ |