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