Fix the no password save issue for ajax login
[chromium-blink-merge.git] / content / public / renderer / document_state.h
blobd13be7f4b726dcbeeeca72e65160f900c08e2b32
1 // Copyright (c) 2012 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_PUBLIC_RENDERER_DOCUMENT_STATE_H_
6 #define CONTENT_PUBLIC_RENDERER_DOCUMENT_STATE_H_
8 #include <string>
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
17 namespace webkit_glue {
18 class AltErrorPageResourceFetcher;
21 namespace content {
23 class NavigationState;
24 struct PasswordForm;
26 // The RenderView stores an instance of this class in the "extra data" of each
27 // WebDataSource (see RenderView::DidCreateDataSource).
28 class DocumentState : public WebKit::WebDataSource::ExtraData {
29 public:
30 // The exact values of this enum are used in histograms, so new values must be
31 // added to the end.
32 enum LoadType {
33 UNDEFINED_LOAD, // Not yet initialized.
34 RELOAD, // User pressed reload.
35 HISTORY_LOAD, // Back or forward.
36 NORMAL_LOAD, // User entered URL, or omnibox search.
37 LINK_LOAD, // (deprecated) Included next 4 categories.
38 LINK_LOAD_NORMAL, // Commonly following of link.
39 LINK_LOAD_RELOAD, // JS/link directed reload.
40 LINK_LOAD_CACHE_STALE_OK, // back/forward or encoding change.
41 LINK_LOAD_CACHE_ONLY, // Allow stale data (avoid doing a re-post)
42 kLoadTypeMax // Bounding value for this enum.
45 DocumentState();
46 virtual ~DocumentState();
48 static DocumentState* FromDataSource(WebKit::WebDataSource* ds) {
49 return static_cast<DocumentState*>(ds->extraData());
52 // The time that this navigation was requested.
53 const base::Time& request_time() const {
54 return request_time_;
56 void set_request_time(const base::Time& value) {
57 DCHECK(start_load_time_.is_null());
58 request_time_ = value;
61 // The time that the document load started.
62 const base::Time& start_load_time() const {
63 return start_load_time_;
65 void set_start_load_time(const base::Time& value) {
66 // TODO(jar): This should not be set twice.
67 // DCHECK(!start_load_time_.is_null());
68 DCHECK(finish_document_load_time_.is_null());
69 start_load_time_ = value;
72 // The time that the document load was committed.
73 const base::Time& commit_load_time() const {
74 return commit_load_time_;
76 void set_commit_load_time(const base::Time& value) {
77 commit_load_time_ = value;
80 // The time that the document finished loading.
81 const base::Time& finish_document_load_time() const {
82 return finish_document_load_time_;
84 void set_finish_document_load_time(const base::Time& value) {
85 // TODO(jar): Some unittests break the following DCHECK, and don't have
86 // DCHECK(!start_load_time_.is_null());
87 DCHECK(!value.is_null());
88 // TODO(jar): Double setting does happen, but probably shouldn't.
89 // DCHECK(finish_document_load_time_.is_null());
90 // TODO(jar): We should guarantee this order :-(.
91 // DCHECK(finish_load_time_.is_null());
92 finish_document_load_time_ = value;
95 // The time that the document and all subresources finished loading.
96 const base::Time& finish_load_time() const { return finish_load_time_; }
97 void set_finish_load_time(const base::Time& value) {
98 DCHECK(!value.is_null());
99 DCHECK(finish_load_time_.is_null());
100 // The following is not already set in all cases :-(
101 // DCHECK(!finish_document_load_time_.is_null());
102 finish_load_time_ = value;
105 // The time that painting first happened after a new navigation.
106 const base::Time& first_paint_time() const { return first_paint_time_; }
107 void set_first_paint_time(const base::Time& value) {
108 first_paint_time_ = value;
111 // The time that painting first happened after the document loaded.
112 const base::Time& first_paint_after_load_time() const {
113 return first_paint_after_load_time_;
115 void set_first_paint_after_load_time(const base::Time& value) {
116 first_paint_after_load_time_ = value;
119 // True iff the histograms for the associated frame have been dumped.
120 bool load_histograms_recorded() const { return load_histograms_recorded_; }
121 void set_load_histograms_recorded(bool value) {
122 load_histograms_recorded_ = value;
125 bool web_timing_histograms_recorded() const {
126 return web_timing_histograms_recorded_;
128 void set_web_timing_histograms_recorded(bool value) {
129 web_timing_histograms_recorded_ = value;
132 int http_status_code() const { return http_status_code_; }
133 void set_http_status_code(int http_status_code) {
134 http_status_code_ = http_status_code;
137 // Indicator if SPDY was used as part of this page load.
138 bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; }
139 void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; }
141 bool was_npn_negotiated() const { return was_npn_negotiated_; }
142 void set_was_npn_negotiated(bool value) { was_npn_negotiated_ = value; }
144 const std::string& npn_negotiated_protocol() const {
145 return npn_negotiated_protocol_;
147 void set_npn_negotiated_protocol(const std::string& value) {
148 npn_negotiated_protocol_ = value;
151 bool was_alternate_protocol_available() const {
152 return was_alternate_protocol_available_;
154 void set_was_alternate_protocol_available(bool value) {
155 was_alternate_protocol_available_ = value;
158 bool was_fetched_via_proxy() const { return was_fetched_via_proxy_; }
159 void set_was_fetched_via_proxy(bool value) {
160 was_fetched_via_proxy_ = value;
163 const GURL& searchable_form_url() const { return searchable_form_url_; }
164 void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; }
165 const std::string& searchable_form_encoding() const {
166 return searchable_form_encoding_;
168 void set_searchable_form_encoding(const std::string& encoding) {
169 searchable_form_encoding_ = encoding;
172 // If set, contains the PasswordForm that we believe triggered the current
173 // navigation (there is some ambiguity in the case of javascript initiated
174 // navigations). This information is used by the PasswordManager to determine
175 // if the user should be prompted to save their password.
177 // Note that setting this field doesn't affect where the data is sent or what
178 // origin we associate it with, only whether we prompt the user to save it.
179 // That is, a false positive is a usability issue (e.g. may try to save a
180 // mis-typed password) not a security issue.
181 PasswordForm* password_form_data() const {
182 return password_form_data_.get();
184 void set_password_form_data(scoped_ptr<PasswordForm> data);
186 const std::string& security_info() const { return security_info_; }
187 void set_security_info(const std::string& security_info) {
188 security_info_ = security_info;
191 // True if an error page should be used, if the http status code also
192 // indicates an error.
193 bool use_error_page() const { return use_error_page_; }
194 void set_use_error_page(bool use_error_page) {
195 use_error_page_ = use_error_page;
198 // True if the user agent was overridden for this page.
199 bool is_overriding_user_agent() const { return is_overriding_user_agent_; }
200 void set_is_overriding_user_agent(bool state) {
201 is_overriding_user_agent_ = state;
204 // True if we have to reset the scroll and scale state of the page
205 // after the provisional load has been committed.
206 bool must_reset_scroll_and_scale_state() const {
207 return must_reset_scroll_and_scale_state_;
209 void set_must_reset_scroll_and_scale_state(bool state) {
210 must_reset_scroll_and_scale_state_ = state;
213 void set_was_prefetcher(bool value) { was_prefetcher_ = value; }
214 bool was_prefetcher() const { return was_prefetcher_; }
216 void set_was_referred_by_prefetcher(bool value) {
217 was_referred_by_prefetcher_ = value;
219 bool was_referred_by_prefetcher() const {
220 return was_referred_by_prefetcher_;
223 // Record the nature of this load, for use when histogramming page load times.
224 LoadType load_type() const { return load_type_; }
225 void set_load_type(LoadType load_type) { load_type_ = load_type; }
227 // Sets the cache policy. The cache policy is only used if explicitly set and
228 // by default is not set. You can mark a NavigationState as not having a cache
229 // state by way of clear_cache_policy_override.
230 void set_cache_policy_override(
231 WebKit::WebURLRequest::CachePolicy cache_policy) {
232 cache_policy_override_ = cache_policy;
233 cache_policy_override_set_ = true;
235 WebKit::WebURLRequest::CachePolicy cache_policy_override() const {
236 return cache_policy_override_;
238 void clear_cache_policy_override() {
239 cache_policy_override_set_ = false;
240 cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy;
242 bool is_cache_policy_override_set() const {
243 return cache_policy_override_set_;
246 // Sets the referrer policy to use. This is only used for browser initiated
247 // navigations, otherwise, the referrer policy is defined by the frame's
248 // document.
249 WebKit::WebReferrerPolicy referrer_policy() const {
250 return referrer_policy_;
252 void set_referrer_policy(WebKit::WebReferrerPolicy referrer_policy) {
253 referrer_policy_ = referrer_policy;
254 referrer_policy_set_ = true;
256 void clear_referrer_policy() {
257 referrer_policy_ = WebKit::WebReferrerPolicyDefault;
258 referrer_policy_set_ = false;
260 bool is_referrer_policy_set() const { return referrer_policy_set_; }
262 webkit_glue::AltErrorPageResourceFetcher* alt_error_page_fetcher() const {
263 return alt_error_page_fetcher_.get();
265 void set_alt_error_page_fetcher(webkit_glue::AltErrorPageResourceFetcher* f);
267 NavigationState* navigation_state() { return navigation_state_.get(); }
268 void set_navigation_state(NavigationState* navigation_state);
270 bool can_load_local_resources() const { return can_load_local_resources_; }
271 void set_can_load_local_resources(bool can_load) {
272 can_load_local_resources_ = can_load;
275 private:
276 base::Time request_time_;
277 base::Time start_load_time_;
278 base::Time commit_load_time_;
279 base::Time finish_document_load_time_;
280 base::Time finish_load_time_;
281 base::Time first_paint_time_;
282 base::Time first_paint_after_load_time_;
283 bool load_histograms_recorded_;
284 bool web_timing_histograms_recorded_;
285 int http_status_code_;
286 bool was_fetched_via_spdy_;
287 bool was_npn_negotiated_;
288 std::string npn_negotiated_protocol_;
289 bool was_alternate_protocol_available_;
290 bool was_fetched_via_proxy_;
292 GURL searchable_form_url_;
293 std::string searchable_form_encoding_;
294 scoped_ptr<PasswordForm> password_form_data_;
295 std::string security_info_;
297 bool use_error_page_;
299 bool is_overriding_user_agent_;
300 bool must_reset_scroll_and_scale_state_;
302 // A prefetcher is a page that contains link rel=prefetch elements.
303 bool was_prefetcher_;
304 bool was_referred_by_prefetcher_;
306 LoadType load_type_;
308 bool cache_policy_override_set_;
309 WebKit::WebURLRequest::CachePolicy cache_policy_override_;
311 bool referrer_policy_set_;
312 WebKit::WebReferrerPolicy referrer_policy_;
314 scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_;
316 scoped_ptr<NavigationState> navigation_state_;
318 bool can_load_local_resources_;
321 #endif // CONTENT_PUBLIC_RENDERER_DOCUMENT_STATE_H_
323 } // namespace content