• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include <string>
9 
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"
14 #include "url/gurl.h"
15 
16 namespace blink {
17 class WebDataSource;
18 }
19 
20 namespace content {
21 
22 class AltErrorPageResourceFetcher;
23 class DocumentState;
24 
25 // Stores internal state per WebDataSource.
26 class InternalDocumentStateData : public base::SupportsUserData::Data {
27  public:
28   InternalDocumentStateData();
29 
30   static InternalDocumentStateData* FromDataSource(blink::WebDataSource* ds);
31   static InternalDocumentStateData* FromDocumentState(DocumentState* ds);
32 
33   // Set to true once RenderViewImpl::didFirstVisuallyNonEmptyLayout() is
34   // invoked.
did_first_visually_non_empty_layout()35   bool did_first_visually_non_empty_layout() const {
36     return did_first_visually_non_empty_layout_;
37   }
set_did_first_visually_non_empty_layout(bool value)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.
did_first_visually_non_empty_paint()45   bool did_first_visually_non_empty_paint() const {
46     return did_first_visually_non_empty_paint_;
47   }
set_did_first_visually_non_empty_paint(bool value)48   void set_did_first_visually_non_empty_paint(bool value) {
49     did_first_visually_non_empty_paint_ = value;
50   }
51 
http_status_code()52   int http_status_code() const { return http_status_code_; }
set_http_status_code(int http_status_code)53   void set_http_status_code(int http_status_code) {
54     http_status_code_ = http_status_code;
55   }
56 
searchable_form_url()57   const GURL& searchable_form_url() const { return searchable_form_url_; }
set_searchable_form_url(const GURL & url)58   void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; }
searchable_form_encoding()59   const std::string& searchable_form_encoding() const {
60     return searchable_form_encoding_;
61   }
set_searchable_form_encoding(const std::string & encoding)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.
use_error_page()68   bool use_error_page() const { return use_error_page_; }
set_use_error_page(bool 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.
is_overriding_user_agent()74   bool is_overriding_user_agent() const { return is_overriding_user_agent_; }
set_is_overriding_user_agent(bool state)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.
must_reset_scroll_and_scale_state()81   bool must_reset_scroll_and_scale_state() const {
82     return must_reset_scroll_and_scale_state_;
83   }
set_must_reset_scroll_and_scale_state(bool state)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.
set_cache_policy_override(blink::WebURLRequest::CachePolicy cache_policy)91   void set_cache_policy_override(
92       blink::WebURLRequest::CachePolicy cache_policy) {
93     cache_policy_override_ = cache_policy;
94     cache_policy_override_set_ = true;
95   }
cache_policy_override()96   blink::WebURLRequest::CachePolicy cache_policy_override() const {
97     return cache_policy_override_;
98   }
clear_cache_policy_override()99   void clear_cache_policy_override() {
100     cache_policy_override_set_ = false;
101     cache_policy_override_ = blink::WebURLRequest::UseProtocolCachePolicy;
102   }
is_cache_policy_override_set()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.
referrer_policy()110   blink::WebReferrerPolicy referrer_policy() const {
111     return referrer_policy_;
112   }
set_referrer_policy(blink::WebReferrerPolicy referrer_policy)113   void set_referrer_policy(blink::WebReferrerPolicy referrer_policy) {
114     referrer_policy_ = referrer_policy;
115     referrer_policy_set_ = true;
116   }
clear_referrer_policy()117   void clear_referrer_policy() {
118     referrer_policy_ = blink::WebReferrerPolicyDefault;
119     referrer_policy_set_ = false;
120   }
is_referrer_policy_set()121   bool is_referrer_policy_set() const { return referrer_policy_set_; }
122 
alt_error_page_fetcher()123   AltErrorPageResourceFetcher* alt_error_page_fetcher() const {
124     return alt_error_page_fetcher_.get();
125   }
126   void set_alt_error_page_fetcher(AltErrorPageResourceFetcher* f);
127 
128  protected:
129   virtual ~InternalDocumentStateData();
130 
131  private:
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   blink::WebURLRequest::CachePolicy cache_policy_override_;
142   bool referrer_policy_set_;
143   blink::WebReferrerPolicy referrer_policy_;
144   scoped_ptr<AltErrorPageResourceFetcher> alt_error_page_fetcher_;
145 
146   DISALLOW_COPY_AND_ASSIGN(InternalDocumentStateData);
147 };
148 
149 }  // namespace content
150 
151 #endif  // CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_
152