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.
5 #ifndef CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_
6 #define CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/supports_user_data.h"
12 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
13 #include "third_party/WebKit/public/platform/WebURLRequest.h"
22 class AltErrorPageResourceFetcher
;
25 // Stores internal state per WebDataSource.
26 class InternalDocumentStateData
: public base::SupportsUserData::Data
{
28 InternalDocumentStateData();
30 static InternalDocumentStateData
* FromDataSource(WebKit::WebDataSource
* ds
);
31 static InternalDocumentStateData
* FromDocumentState(DocumentState
* ds
);
33 // Set to true once RenderViewImpl::didFirstVisuallyNonEmptyLayout() is
35 bool did_first_visually_non_empty_layout() const {
36 return did_first_visually_non_empty_layout_
;
38 void set_did_first_visually_non_empty_layout(bool value
) {
39 did_first_visually_non_empty_layout_
= value
;
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_
;
48 void set_did_first_visually_non_empty_paint(bool value
) {
49 did_first_visually_non_empty_paint_
= value
;
52 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
;
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_
;
62 void set_searchable_form_encoding(const std::string
& encoding
) {
63 searchable_form_encoding_
= encoding
;
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
;
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
;
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_
;
84 void set_must_reset_scroll_and_scale_state(bool state
) {
85 must_reset_scroll_and_scale_state_
= state
;
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;
96 WebKit::WebURLRequest::CachePolicy
cache_policy_override() const {
97 return cache_policy_override_
;
99 void clear_cache_policy_override() {
100 cache_policy_override_set_
= false;
101 cache_policy_override_
= WebKit::WebURLRequest::UseProtocolCachePolicy
;
103 bool is_cache_policy_override_set() const {
104 return cache_policy_override_set_
;
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
110 WebKit::WebReferrerPolicy
referrer_policy() const {
111 return referrer_policy_
;
113 void set_referrer_policy(WebKit::WebReferrerPolicy referrer_policy
) {
114 referrer_policy_
= referrer_policy
;
115 referrer_policy_set_
= true;
117 void clear_referrer_policy() {
118 referrer_policy_
= WebKit::WebReferrerPolicyDefault
;
119 referrer_policy_set_
= false;
121 bool is_referrer_policy_set() const { return referrer_policy_set_
; }
123 AltErrorPageResourceFetcher
* alt_error_page_fetcher() const {
124 return alt_error_page_fetcher_
.get();
126 void set_alt_error_page_fetcher(AltErrorPageResourceFetcher
* f
);
129 virtual ~InternalDocumentStateData();
132 bool did_first_visually_non_empty_layout_
;
133 bool did_first_visually_non_empty_paint_
;
134 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_
;
144 scoped_ptr
<AltErrorPageResourceFetcher
> alt_error_page_fetcher_
;
146 DISALLOW_COPY_AND_ASSIGN(InternalDocumentStateData
);
149 } // namespace content
151 #endif // CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_