Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / public / renderer / document_state.h
blobd3d8c54064a449998b9715bcf0833510bfc9ebb1
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/supports_user_data.h"
13 #include "base/time/time.h"
14 #include "content/common/content_export.h"
15 #include "net/http/http_response_info.h"
16 #include "third_party/WebKit/public/web/WebDataSource.h"
18 namespace content {
20 class NavigationState;
22 // The RenderView stores an instance of this class in the "extra data" of each
23 // WebDataSource (see RenderView::DidCreateDataSource).
24 class CONTENT_EXPORT DocumentState
25 : NON_EXPORTED_BASE(public blink::WebDataSource::ExtraData),
26 public base::SupportsUserData {
27 public:
28 // The exact values of this enum are used in histograms, so new values must be
29 // added to the end.
30 enum LoadType {
31 UNDEFINED_LOAD, // Not yet initialized.
32 RELOAD, // User pressed reload.
33 HISTORY_LOAD, // Back or forward.
34 NORMAL_LOAD, // User entered URL, or omnibox search.
35 LINK_LOAD, // (deprecated) Included next 4 categories.
36 LINK_LOAD_NORMAL, // Commonly following of link.
37 LINK_LOAD_RELOAD, // JS/link directed reload.
38 LINK_LOAD_CACHE_STALE_OK, // back/forward or encoding change.
39 LINK_LOAD_CACHE_ONLY, // Allow stale data (avoid doing a re-post)
40 kLoadTypeMax // Bounding value for this enum.
43 DocumentState();
44 virtual ~DocumentState();
46 static DocumentState* FromDataSource(blink::WebDataSource* ds) {
47 return static_cast<DocumentState*>(ds->extraData());
50 // The time that this navigation was requested.
51 const base::Time& request_time() const {
52 return request_time_;
54 void set_request_time(const base::Time& value) {
55 DCHECK(start_load_time_.is_null());
56 request_time_ = value;
59 // The time that the document load started.
60 const base::Time& start_load_time() const {
61 return start_load_time_;
63 void set_start_load_time(const base::Time& value) {
64 // TODO(jar): This should not be set twice.
65 // DCHECK(!start_load_time_.is_null());
66 DCHECK(finish_document_load_time_.is_null());
67 start_load_time_ = value;
70 // The time that the document load was committed.
71 const base::Time& commit_load_time() const {
72 return commit_load_time_;
74 void set_commit_load_time(const base::Time& value) {
75 commit_load_time_ = value;
78 // The time that the document finished loading.
79 const base::Time& finish_document_load_time() const {
80 return finish_document_load_time_;
82 void set_finish_document_load_time(const base::Time& value) {
83 // TODO(jar): Some unittests break the following DCHECK, and don't have
84 // DCHECK(!start_load_time_.is_null());
85 DCHECK(!value.is_null());
86 // TODO(jar): Double setting does happen, but probably shouldn't.
87 // DCHECK(finish_document_load_time_.is_null());
88 // TODO(jar): We should guarantee this order :-(.
89 // DCHECK(finish_load_time_.is_null());
90 finish_document_load_time_ = value;
93 // The time that the document and all subresources finished loading.
94 const base::Time& finish_load_time() const { return finish_load_time_; }
95 void set_finish_load_time(const base::Time& value) {
96 DCHECK(!value.is_null());
97 DCHECK(finish_load_time_.is_null());
98 // The following is not already set in all cases :-(
99 // DCHECK(!finish_document_load_time_.is_null());
100 finish_load_time_ = value;
103 // The time that painting first happened after a new navigation.
104 const base::Time& first_paint_time() const { return first_paint_time_; }
105 void set_first_paint_time(const base::Time& value) {
106 first_paint_time_ = value;
109 // The time that painting first happened after the document loaded.
110 const base::Time& first_paint_after_load_time() const {
111 return first_paint_after_load_time_;
113 void set_first_paint_after_load_time(const base::Time& value) {
114 first_paint_after_load_time_ = value;
117 // True iff the histograms for the associated frame have been dumped.
118 bool load_histograms_recorded() const { return load_histograms_recorded_; }
119 void set_load_histograms_recorded(bool value) {
120 load_histograms_recorded_ = value;
123 bool web_timing_histograms_recorded() const {
124 return web_timing_histograms_recorded_;
126 void set_web_timing_histograms_recorded(bool value) {
127 web_timing_histograms_recorded_ = value;
130 // Indicator if SPDY was used as part of this page load.
131 bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; }
132 void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; }
134 bool was_npn_negotiated() const { return was_npn_negotiated_; }
135 void set_was_npn_negotiated(bool value) { was_npn_negotiated_ = value; }
137 const std::string& npn_negotiated_protocol() const {
138 return npn_negotiated_protocol_;
140 void set_npn_negotiated_protocol(const std::string& value) {
141 npn_negotiated_protocol_ = value;
144 bool was_alternate_protocol_available() const {
145 return was_alternate_protocol_available_;
147 void set_was_alternate_protocol_available(bool value) {
148 was_alternate_protocol_available_ = value;
151 net::HttpResponseInfo::ConnectionInfo connection_info() const {
152 return connection_info_;
154 void set_connection_info(
155 net::HttpResponseInfo::ConnectionInfo connection_info) {
156 connection_info_ = connection_info;
159 bool was_fetched_via_proxy() const { return was_fetched_via_proxy_; }
160 void set_was_fetched_via_proxy(bool value) {
161 was_fetched_via_proxy_ = value;
164 const net::HostPortPair& proxy_server() const { return proxy_server_; }
165 void set_proxy_server(const net::HostPortPair& proxy_server) {
166 proxy_server_ = proxy_server;
169 void set_was_prefetcher(bool value) { was_prefetcher_ = value; }
170 bool was_prefetcher() const { return was_prefetcher_; }
172 void set_was_referred_by_prefetcher(bool value) {
173 was_referred_by_prefetcher_ = value;
175 bool was_referred_by_prefetcher() const {
176 return was_referred_by_prefetcher_;
179 void set_was_after_preconnect_request(bool value) {
180 was_after_preconnect_request_ = value;
182 bool was_after_preconnect_request() { return was_after_preconnect_request_; }
184 // Record the nature of this load, for use when histogramming page load times.
185 LoadType load_type() const { return load_type_; }
186 void set_load_type(LoadType load_type) { load_type_ = load_type; }
188 NavigationState* navigation_state() { return navigation_state_.get(); }
189 void set_navigation_state(NavigationState* navigation_state);
191 bool can_load_local_resources() const { return can_load_local_resources_; }
192 void set_can_load_local_resources(bool can_load) {
193 can_load_local_resources_ = can_load;
196 private:
197 base::Time request_time_;
198 base::Time start_load_time_;
199 base::Time commit_load_time_;
200 base::Time finish_document_load_time_;
201 base::Time finish_load_time_;
202 base::Time first_paint_time_;
203 base::Time first_paint_after_load_time_;
204 bool load_histograms_recorded_;
205 bool web_timing_histograms_recorded_;
206 bool was_fetched_via_spdy_;
207 bool was_npn_negotiated_;
208 std::string npn_negotiated_protocol_;
209 bool was_alternate_protocol_available_;
210 net::HttpResponseInfo::ConnectionInfo connection_info_;
211 bool was_fetched_via_proxy_;
212 net::HostPortPair proxy_server_;
214 // A prefetcher is a page that contains link rel=prefetch elements.
215 bool was_prefetcher_;
216 bool was_referred_by_prefetcher_;
217 bool was_after_preconnect_request_;
219 LoadType load_type_;
221 scoped_ptr<NavigationState> navigation_state_;
223 bool can_load_local_resources_;
226 #endif // CONTENT_PUBLIC_RENDERER_DOCUMENT_STATE_H_
228 } // namespace content