• 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/WebURLRequest.h"
13 #include "url/gurl.h"
14 
15 namespace blink {
16 class WebDataSource;
17 }
18 
19 namespace content {
20 
21 class DocumentState;
22 
23 // Stores internal state per WebDataSource.
24 class InternalDocumentStateData : public base::SupportsUserData::Data {
25  public:
26   InternalDocumentStateData();
27 
28   static InternalDocumentStateData* FromDataSource(blink::WebDataSource* ds);
29   static InternalDocumentStateData* FromDocumentState(DocumentState* ds);
30 
31   // Set to true once RenderViewImpl::didFirstVisuallyNonEmptyLayout() is
32   // invoked.
did_first_visually_non_empty_layout()33   bool did_first_visually_non_empty_layout() const {
34     return did_first_visually_non_empty_layout_;
35   }
set_did_first_visually_non_empty_layout(bool value)36   void set_did_first_visually_non_empty_layout(bool value) {
37     did_first_visually_non_empty_layout_ = value;
38   }
39 
http_status_code()40   int http_status_code() const { return http_status_code_; }
set_http_status_code(int http_status_code)41   void set_http_status_code(int http_status_code) {
42     http_status_code_ = http_status_code;
43   }
44 
searchable_form_url()45   const GURL& searchable_form_url() const { return searchable_form_url_; }
set_searchable_form_url(const GURL & url)46   void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; }
searchable_form_encoding()47   const std::string& searchable_form_encoding() const {
48     return searchable_form_encoding_;
49   }
set_searchable_form_encoding(const std::string & encoding)50   void set_searchable_form_encoding(const std::string& encoding) {
51     searchable_form_encoding_ = encoding;
52   }
53 
54   // True if an error page should be used, if the http status code also
55   // indicates an error.
use_error_page()56   bool use_error_page() const { return use_error_page_; }
set_use_error_page(bool use_error_page)57   void set_use_error_page(bool use_error_page) {
58     use_error_page_ = use_error_page;
59   }
60 
61   // True if the user agent was overridden for this page.
is_overriding_user_agent()62   bool is_overriding_user_agent() const { return is_overriding_user_agent_; }
set_is_overriding_user_agent(bool state)63   void set_is_overriding_user_agent(bool state) {
64     is_overriding_user_agent_ = state;
65   }
66 
67   // True if we have to reset the scroll and scale state of the page
68   // after the provisional load has been committed.
must_reset_scroll_and_scale_state()69   bool must_reset_scroll_and_scale_state() const {
70     return must_reset_scroll_and_scale_state_;
71   }
set_must_reset_scroll_and_scale_state(bool state)72   void set_must_reset_scroll_and_scale_state(bool state) {
73     must_reset_scroll_and_scale_state_ = state;
74   }
75 
76   // Sets the cache policy. The cache policy is only used if explicitly set and
77   // by default is not set. You can mark a NavigationState as not having a cache
78   // state by way of clear_cache_policy_override.
set_cache_policy_override(blink::WebURLRequest::CachePolicy cache_policy)79   void set_cache_policy_override(
80       blink::WebURLRequest::CachePolicy cache_policy) {
81     cache_policy_override_ = cache_policy;
82     cache_policy_override_set_ = true;
83   }
cache_policy_override()84   blink::WebURLRequest::CachePolicy cache_policy_override() const {
85     return cache_policy_override_;
86   }
clear_cache_policy_override()87   void clear_cache_policy_override() {
88     cache_policy_override_set_ = false;
89     cache_policy_override_ = blink::WebURLRequest::UseProtocolCachePolicy;
90   }
is_cache_policy_override_set()91   bool is_cache_policy_override_set() const {
92     return cache_policy_override_set_;
93   }
94 
95  protected:
96   virtual ~InternalDocumentStateData();
97 
98  private:
99   bool did_first_visually_non_empty_layout_;
100   bool did_first_visually_non_empty_paint_;
101   int http_status_code_;
102   GURL searchable_form_url_;
103   std::string searchable_form_encoding_;
104   bool use_error_page_;
105   bool is_overriding_user_agent_;
106   bool must_reset_scroll_and_scale_state_;
107   bool cache_policy_override_set_;
108   blink::WebURLRequest::CachePolicy cache_policy_override_;
109 
110   DISALLOW_COPY_AND_ASSIGN(InternalDocumentStateData);
111 };
112 
113 }  // namespace content
114 
115 #endif  // CONTENT_RENDERER_INTERNAL_DOCUMENT_STATE_DATA_H_
116