blob: ff6c4291f19a2ef62e8792cc89ff68c4101d7e18 [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
[email protected]e20b88d2013-04-09 15:28:378#include <string>
9
10#include "base/memory/scoped_ptr.h"
[email protected]92d457802013-04-01 19:18:4911#include "base/supports_user_data.h"
[email protected]e20b88d2013-04-09 15:28:3712#include "googleurl/src/gurl.h"
[email protected]5c30b5e02013-05-30 03:46:0813#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
14#include "third_party/WebKit/public/platform/WebURLRequest.h"
[email protected]e20b88d2013-04-09 15:28:3715
[email protected]92d457802013-04-01 19:18:4916namespace WebKit {
17class WebDataSource;
18}
19
20namespace content {
21
[email protected]f8c700ba2013-05-14 08:25:4922class AltErrorPageResourceFetcher;
[email protected]e20b88d2013-04-09 15:28:3723class DocumentState;
24
[email protected]92d457802013-04-01 19:18:4925// Stores internal state per WebDataSource.
26class InternalDocumentStateData : public base::SupportsUserData::Data {
27 public:
28 InternalDocumentStateData();
29
30 static InternalDocumentStateData* FromDataSource(WebKit::WebDataSource* ds);
[email protected]e20b88d2013-04-09 15:28:3731 static InternalDocumentStateData* FromDocumentState(DocumentState* ds);
[email protected]92d457802013-04-01 19:18:4932
33 // Set to true once RenderViewImpl::didFirstVisuallyNonEmptyLayout() is
34 // invoked.
35 bool did_first_visually_non_empty_layout() const {
36 return did_first_visually_non_empty_layout_;
37 }
38 void set_did_first_visually_non_empty_layout(bool value) {
39 did_first_visually_non_empty_layout_ = value;
40 }
41
42 // Set to true once RenderViewImpl::DidFlushPaint() is inovked after
43 // RenderViewImpl::didFirstVisuallyNonEmptyLayout(). In other words after the
44 // page has painted something.
45 bool did_first_visually_non_empty_paint() const {
46 return did_first_visually_non_empty_paint_;
47 }
48 void set_did_first_visually_non_empty_paint(bool value) {
49 did_first_visually_non_empty_paint_ = value;
50 }
51
[email protected]e20b88d2013-04-09 15:28:3752 int http_status_code() const { return http_status_code_; }
53 void set_http_status_code(int http_status_code) {
54 http_status_code_ = http_status_code;
55 }
56
57 const GURL& searchable_form_url() const { return searchable_form_url_; }
58 void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; }
59 const std::string& searchable_form_encoding() const {
60 return searchable_form_encoding_;
61 }
62 void set_searchable_form_encoding(const std::string& encoding) {
63 searchable_form_encoding_ = encoding;
64 }
65
66 // True if an error page should be used, if the http status code also
67 // indicates an error.
68 bool use_error_page() const { return use_error_page_; }
69 void set_use_error_page(bool use_error_page) {
70 use_error_page_ = use_error_page;
71 }
72
73 // True if the user agent was overridden for this page.
74 bool is_overriding_user_agent() const { return is_overriding_user_agent_; }
75 void set_is_overriding_user_agent(bool state) {
76 is_overriding_user_agent_ = state;
77 }
78
79 // True if we have to reset the scroll and scale state of the page
80 // after the provisional load has been committed.
81 bool must_reset_scroll_and_scale_state() const {
82 return must_reset_scroll_and_scale_state_;
83 }
84 void set_must_reset_scroll_and_scale_state(bool state) {
85 must_reset_scroll_and_scale_state_ = state;
86 }
87
88 // Sets the cache policy. The cache policy is only used if explicitly set and
89 // by default is not set. You can mark a NavigationState as not having a cache
90 // state by way of clear_cache_policy_override.
91 void set_cache_policy_override(
92 WebKit::WebURLRequest::CachePolicy cache_policy) {
93 cache_policy_override_ = cache_policy;
94 cache_policy_override_set_ = true;
95 }
96 WebKit::WebURLRequest::CachePolicy cache_policy_override() const {
97 return cache_policy_override_;
98 }
99 void clear_cache_policy_override() {
100 cache_policy_override_set_ = false;
101 cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy;
102 }
103 bool is_cache_policy_override_set() const {
104 return cache_policy_override_set_;
105 }
106
107 // Sets the referrer policy to use. This is only used for browser initiated
108 // navigations, otherwise, the referrer policy is defined by the frame's
109 // document.
110 WebKit::WebReferrerPolicy referrer_policy() const {
111 return referrer_policy_;
112 }
113 void set_referrer_policy(WebKit::WebReferrerPolicy referrer_policy) {
114 referrer_policy_ = referrer_policy;
115 referrer_policy_set_ = true;
116 }
117 void clear_referrer_policy() {
118 referrer_policy_ = WebKit::WebReferrerPolicyDefault;
119 referrer_policy_set_ = false;
120 }
121 bool is_referrer_policy_set() const { return referrer_policy_set_; }
122
[email protected]f8c700ba2013-05-14 08:25:49123 AltErrorPageResourceFetcher* alt_error_page_fetcher() const {
[email protected]e20b88d2013-04-09 15:28:37124 return alt_error_page_fetcher_.get();
125 }
[email protected]f8c700ba2013-05-14 08:25:49126 void set_alt_error_page_fetcher(AltErrorPageResourceFetcher* f);
[email protected]e20b88d2013-04-09 15:28:37127
[email protected]92d457802013-04-01 19:18:49128 protected:
129 virtual ~InternalDocumentStateData();
130
131 private:
132 bool did_first_visually_non_empty_layout_;
133 bool did_first_visually_non_empty_paint_;
[email protected]e20b88d2013-04-09 15:28:37134 int http_status_code_;
135 GURL searchable_form_url_;
136 std::string searchable_form_encoding_;
137 bool use_error_page_;
138 bool is_overriding_user_agent_;
139 bool must_reset_scroll_and_scale_state_;
140 bool cache_policy_override_set_;
141 WebKit::WebURLRequest::CachePolicy cache_policy_override_;
142 bool referrer_policy_set_;
143 WebKit::WebReferrerPolicy referrer_policy_;
[email protected]f8c700ba2013-05-14 08:25:49144 scoped_ptr<AltErrorPageResourceFetcher> alt_error_page_fetcher_;
[email protected]92d457802013-04-01 19:18:49145
146 DISALLOW_COPY_AND_ASSIGN(InternalDocumentStateData);
147};
148
149} // namespace content
150
151#endif // CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_