blob: 1a71890a4d1526b36e04818c22af528c73ee6f75 [file] [log] [blame]
[email protected]92d457802013-04-01 19:18:491// 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
dchengcedca5612016-04-09 01:40:158#include <memory>
[email protected]e20b88d2013-04-09 15:28:379#include <string>
10
avi1023d012015-12-25 02:39:1411#include "base/macros.h"
[email protected]92d457802013-04-01 19:18:4912#include "base/supports_user_data.h"
Dmitry Gozman2d871962019-01-08 00:05:0213#include "content/public/common/previews_state.h"
Dmitry Gozman1a2cb242018-12-15 02:51:2914#include "net/nqe/effective_connection_type.h"
Richard Lie6899952018-11-30 08:42:0015#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
[email protected]707e1c42013-07-09 21:18:5816#include "url/gurl.h"
[email protected]e20b88d2013-04-09 15:28:3717
[email protected]180ef242013-11-07 06:50:4618namespace blink {
Takeshi Yoshino41b671a2017-08-01 12:17:5119class WebDocumentLoader;
[email protected]92d457802013-04-01 19:18:4920}
21
22namespace content {
23
[email protected]e20b88d2013-04-09 15:28:3724class DocumentState;
Dmitry Gozman0a527132018-09-21 18:01:0425class NavigationState;
[email protected]e20b88d2013-04-09 15:28:3726
Takeshi Yoshino41b671a2017-08-01 12:17:5127// Stores internal state per WebDocumentLoader.
[email protected]92d457802013-04-01 19:18:4928class InternalDocumentStateData : public base::SupportsUserData::Data {
29 public:
30 InternalDocumentStateData();
avicb129c02017-05-03 06:49:2931 ~InternalDocumentStateData() override;
[email protected]92d457802013-04-01 19:18:4932
Takeshi Yoshino41b671a2017-08-01 12:17:5133 static InternalDocumentStateData* FromDocumentLoader(
34 blink::WebDocumentLoader* document_loader);
[email protected]e20b88d2013-04-09 15:28:3735 static InternalDocumentStateData* FromDocumentState(DocumentState* ds);
[email protected]92d457802013-04-01 19:18:4936
Dmitry Gozman0a527132018-09-21 18:01:0437 void CopyFrom(InternalDocumentStateData* other);
38
[email protected]e20b88d2013-04-09 15:28:3739 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]e20b88d2013-04-09 15:28:3744 // 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 Hirano458b9132017-10-24 15:17:2162 void set_cache_policy_override(blink::mojom::FetchCacheMode cache_policy) {
[email protected]e20b88d2013-04-09 15:28:3763 cache_policy_override_ = cache_policy;
64 cache_policy_override_set_ = true;
65 }
Yutaka Hirano458b9132017-10-24 15:17:2166 blink::mojom::FetchCacheMode cache_policy_override() const {
[email protected]e20b88d2013-04-09 15:28:3767 return cache_policy_override_;
68 }
69 void clear_cache_policy_override() {
70 cache_policy_override_set_ = false;
Yutaka Hirano458b9132017-10-24 15:17:2171 cache_policy_override_ = blink::mojom::FetchCacheMode::kDefault;
[email protected]e20b88d2013-04-09 15:28:3772 }
73 bool is_cache_policy_override_set() const {
74 return cache_policy_override_set_;
75 }
76
Dmitry Gozman1a2cb242018-12-15 02:51:2977 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 Gozman2d871962019-01-08 00:05:0285 PreviewsState previews_state() const { return previews_state_; }
86 void set_previews_state(PreviewsState previews_state) {
87 previews_state_ = previews_state;
88 }
89
Dmitry Gozman00fd5bb2019-01-25 20:25:3390 // 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 Gozman0a527132018-09-21 18:01:0497 NavigationState* navigation_state() { return navigation_state_.get(); }
98 void set_navigation_state(std::unique_ptr<NavigationState> navigation_state);
99
[email protected]92d457802013-04-01 19:18:49100 private:
[email protected]e20b88d2013-04-09 15:28:37101 int http_status_code_;
[email protected]e20b88d2013-04-09 15:28:37102 bool is_overriding_user_agent_;
103 bool must_reset_scroll_and_scale_state_;
104 bool cache_policy_override_set_;
Yutaka Hirano458b9132017-10-24 15:17:21105 blink::mojom::FetchCacheMode cache_policy_override_;
Dmitry Gozman1a2cb242018-12-15 02:51:29106 net::EffectiveConnectionType effective_connection_type_ =
107 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
Dmitry Gozman2d871962019-01-08 00:05:02108 PreviewsState previews_state_ = PREVIEWS_UNSPECIFIED;
Dmitry Gozman00fd5bb2019-01-25 20:25:33109 int request_id_ = -1;
Dmitry Gozman0a527132018-09-21 18:01:04110 std::unique_ptr<NavigationState> navigation_state_;
[email protected]92d457802013-04-01 19:18:49111
112 DISALLOW_COPY_AND_ASSIGN(InternalDocumentStateData);
113};
114
115} // namespace content
116
117#endif // CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_