Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1360)

Side by Side Diff: content/public/renderer/navigation_state.h

Issue 8404018: chrome.loadTimes() shouldn't be affected by in-document navigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/renderer/document_state.cc ('k') | content/public/renderer/navigation_state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ 5 #ifndef CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
6 #define CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ 6 #define CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string>
10
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h"
14 #include "content/public/common/page_transition_types.h" 9 #include "content/public/common/page_transition_types.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
17
18 namespace webkit_glue {
19 struct PasswordForm;
20 class AltErrorPageResourceFetcher;
21 }
22 10
23 namespace content { 11 namespace content {
24 12
25 // The RenderView stores an instance of this class in the "extra data" of each 13 // NavigationState is the portion of DocumentState that is affected by
26 // WebDataSource (see RenderView::DidCreateDataSource). 14 // in-document navigation.
27 class NavigationState : public WebKit::WebDataSource::ExtraData { 15 // TODO(simonjam): Move this to HistoryItem's ExtraData.
16 class NavigationState {
28 public: 17 public:
29 // The exact values of this enum are used in histograms, so new values must be
30 // added to the end.
31 enum LoadType {
32 UNDEFINED_LOAD, // Not yet initialized.
33 RELOAD, // User pressed reload.
34 HISTORY_LOAD, // Back or forward.
35 NORMAL_LOAD, // User entered URL, or omnibox search.
36 LINK_LOAD, // (deprecated) Included next 4 categories.
37 LINK_LOAD_NORMAL, // Commonly following of link.
38 LINK_LOAD_RELOAD, // JS/link directed reload.
39 LINK_LOAD_CACHE_STALE_OK, // back/forward or encoding change.
40 LINK_LOAD_CACHE_ONLY, // Allow stale data (avoid doing a re-post)
41 kLoadTypeMax // Bounding value for this enum.
42 };
43
44 virtual ~NavigationState(); 18 virtual ~NavigationState();
45 19
46 static NavigationState* CreateBrowserInitiated( 20 static NavigationState* CreateBrowserInitiated(
47 int32 pending_page_id, 21 int32 pending_page_id,
48 int pending_history_list_offset, 22 int pending_history_list_offset,
49 content::PageTransition transition_type, 23 content::PageTransition transition_type) {
50 base::Time request_time) { 24 return new NavigationState(transition_type, false, pending_page_id,
51 return new NavigationState(transition_type, request_time, false,
52 pending_page_id,
53 pending_history_list_offset); 25 pending_history_list_offset);
54 } 26 }
55 27
56 static NavigationState* CreateContentInitiated() { 28 static NavigationState* CreateContentInitiated() {
57 // We assume navigations initiated by content are link clicks. 29 return new NavigationState(content::PAGE_TRANSITION_LINK, true, -1, -1);
58 return new NavigationState(
59 content::PAGE_TRANSITION_LINK, base::Time(), true, -1, -1);
60 }
61
62 static NavigationState* FromDataSource(WebKit::WebDataSource* ds) {
63 return static_cast<NavigationState*>(ds->extraData());
64 } 30 }
65 31
66 // Contains the page_id for this navigation or -1 if there is none yet. 32 // Contains the page_id for this navigation or -1 if there is none yet.
67 int32 pending_page_id() const { return pending_page_id_; } 33 int32 pending_page_id() const { return pending_page_id_; }
68 34
69 // If pending_page_id() is not -1, then this contains the corresponding 35 // If pending_page_id() is not -1, then this contains the corresponding
70 // offset of the page in the back/forward history list. 36 // offset of the page in the back/forward history list.
71 int pending_history_list_offset() const { 37 int pending_history_list_offset() const {
72 return pending_history_list_offset_; 38 return pending_history_list_offset_;
73 } 39 }
74 40
75 // Contains the transition type that the browser specified when it 41 // Contains the transition type that the browser specified when it
76 // initiated the load. 42 // initiated the load.
77 content::PageTransition transition_type() const { return transition_type_; } 43 content::PageTransition transition_type() const { return transition_type_; }
78 void set_transition_type(content::PageTransition type) { 44 void set_transition_type(content::PageTransition type) {
79 transition_type_ = type; 45 transition_type_ = type;
80 } 46 }
81 47
82 // Record the nature of this load, for use when histogramming page load times.
83 LoadType load_type() const { return load_type_; }
84 void set_load_type(LoadType load_type) { load_type_ = load_type; }
85
86 // The time that this navigation was requested.
87 const base::Time& request_time() const {
88 return request_time_;
89 }
90 void set_request_time(const base::Time& value) {
91 DCHECK(start_load_time_.is_null());
92 request_time_ = value;
93 }
94
95 // The time that the document load started.
96 const base::Time& start_load_time() const {
97 return start_load_time_;
98 }
99 void set_start_load_time(const base::Time& value) {
100 // TODO(jar): This should not be set twice.
101 // DCHECK(!start_load_time_.is_null());
102 DCHECK(finish_document_load_time_.is_null());
103 start_load_time_ = value;
104 }
105
106 // The time that the document load was committed.
107 const base::Time& commit_load_time() const {
108 return commit_load_time_;
109 }
110 void set_commit_load_time(const base::Time& value) {
111 commit_load_time_ = value;
112 }
113
114 // The time that the document finished loading.
115 const base::Time& finish_document_load_time() const {
116 return finish_document_load_time_;
117 }
118 void set_finish_document_load_time(const base::Time& value) {
119 // TODO(jar): Some unittests break the following DCHECK, and don't have
120 // DCHECK(!start_load_time_.is_null());
121 DCHECK(!value.is_null());
122 // TODO(jar): Double setting does happen, but probably shouldn't.
123 // DCHECK(finish_document_load_time_.is_null());
124 // TODO(jar): We should guarantee this order :-(.
125 // DCHECK(finish_load_time_.is_null());
126 finish_document_load_time_ = value;
127 }
128
129 // The time that the document and all subresources finished loading.
130 const base::Time& finish_load_time() const { return finish_load_time_; }
131 void set_finish_load_time(const base::Time& value) {
132 DCHECK(!value.is_null());
133 DCHECK(finish_load_time_.is_null());
134 // The following is not already set in all cases :-(
135 // DCHECK(!finish_document_load_time_.is_null());
136 finish_load_time_ = value;
137 }
138
139 // The time that painting first happened after a new navigation.
140 const base::Time& first_paint_time() const { return first_paint_time_; }
141 void set_first_paint_time(const base::Time& value) {
142 first_paint_time_ = value;
143 }
144
145 // The time that painting first happened after the document finished loading.
146 const base::Time& first_paint_after_load_time() const {
147 return first_paint_after_load_time_;
148 }
149 void set_first_paint_after_load_time(const base::Time& value) {
150 first_paint_after_load_time_ = value;
151 }
152
153 // True iff the histograms for the associated frame have been dumped.
154 bool load_histograms_recorded() const { return load_histograms_recorded_; }
155 void set_load_histograms_recorded(bool value) {
156 load_histograms_recorded_ = value;
157 }
158
159 bool web_timing_histograms_recorded() const {
160 return web_timing_histograms_recorded_;
161 }
162 void set_web_timing_histograms_recorded(bool value) {
163 web_timing_histograms_recorded_ = value;
164 }
165
166 // True if we have already processed the "DidCommitLoad" event for this 48 // True if we have already processed the "DidCommitLoad" event for this
167 // request. Used by session history. 49 // request. Used by session history.
168 bool request_committed() const { return request_committed_; } 50 bool request_committed() const { return request_committed_; }
169 void set_request_committed(bool value) { request_committed_ = value; } 51 void set_request_committed(bool value) { request_committed_ = value; }
170 52
171 // True if this navigation was not initiated via WebFrame::LoadRequest. 53 // True if this navigation was not initiated via WebFrame::LoadRequest.
172 bool is_content_initiated() const { return is_content_initiated_; } 54 bool is_content_initiated() const { return is_content_initiated_; }
173 55
174 const GURL& searchable_form_url() const { return searchable_form_url_; }
175 void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; }
176 const std::string& searchable_form_encoding() const {
177 return searchable_form_encoding_;
178 }
179 void set_searchable_form_encoding(const std::string& encoding) {
180 searchable_form_encoding_ = encoding;
181 }
182
183 webkit_glue::PasswordForm* password_form_data() const {
184 return password_form_data_.get();
185 }
186 void set_password_form_data(webkit_glue::PasswordForm* data);
187
188 webkit_glue::AltErrorPageResourceFetcher* alt_error_page_fetcher() const {
189 return alt_error_page_fetcher_.get();
190 }
191 void set_alt_error_page_fetcher(webkit_glue::AltErrorPageResourceFetcher* f);
192
193 const std::string& security_info() const { return security_info_; }
194 void set_security_info(const std::string& security_info) {
195 security_info_ = security_info;
196 }
197
198 // True if an error page should be used, if the http status code also
199 // indicates an error.
200 bool use_error_page() const { return use_error_page_; }
201 void set_use_error_page(bool use_error_page) {
202 use_error_page_ = use_error_page;
203 }
204
205 int http_status_code() const { return http_status_code_; }
206 void set_http_status_code(int http_status_code) {
207 http_status_code_ = http_status_code;
208 }
209
210 // Sets the cache policy. The cache policy is only used if explicitly set and
211 // by default is not set. You can mark a NavigationState as not having a cache
212 // state by way of clear_cache_policy_override.
213 void set_cache_policy_override(
214 WebKit::WebURLRequest::CachePolicy cache_policy) {
215 cache_policy_override_ = cache_policy;
216 cache_policy_override_set_ = true;
217 }
218 WebKit::WebURLRequest::CachePolicy cache_policy_override() const {
219 return cache_policy_override_;
220 }
221 void clear_cache_policy_override() {
222 cache_policy_override_set_ = false;
223 cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy;
224 }
225 bool is_cache_policy_override_set() const {
226 return cache_policy_override_set_;
227 }
228
229 // Indicator if SPDY was used as part of this page load.
230 void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; }
231 bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; }
232
233 void set_was_npn_negotiated(bool value) { was_npn_negotiated_ = value; }
234 bool was_npn_negotiated() const { return was_npn_negotiated_; }
235
236 void set_was_alternate_protocol_available(bool value) {
237 was_alternate_protocol_available_ = value;
238 }
239 bool was_alternate_protocol_available() const {
240 return was_alternate_protocol_available_;
241 }
242
243 void set_was_fetched_via_proxy(bool value) {
244 was_fetched_via_proxy_ = value;
245 }
246 bool was_fetched_via_proxy() const { return was_fetched_via_proxy_; }
247
248 // Whether the frame text contents was translated to a different language.
249 void set_was_translated(bool value) { was_translated_ = value; }
250 bool was_translated() const { return was_translated_; }
251
252 // True iff the frame's navigation was within the same page. 56 // True iff the frame's navigation was within the same page.
253 void set_was_within_same_page(bool value) { was_within_same_page_ = value; } 57 void set_was_within_same_page(bool value) { was_within_same_page_ = value; }
254 bool was_within_same_page() const { return was_within_same_page_; } 58 bool was_within_same_page() const { return was_within_same_page_; }
255 59
256 void set_was_prefetcher(bool value) { was_prefetcher_ = value; }
257 bool was_prefetcher() const { return was_prefetcher_; }
258
259 void set_was_referred_by_prefetcher(bool value) {
260 was_referred_by_prefetcher_ = value;
261 }
262 bool was_referred_by_prefetcher() const {
263 return was_referred_by_prefetcher_;
264 }
265
266 private: 60 private:
267 NavigationState(content::PageTransition transition_type, 61 NavigationState(content::PageTransition transition_type,
268 const base::Time& request_time,
269 bool is_content_initiated, 62 bool is_content_initiated,
270 int32 pending_page_id, 63 int32 pending_page_id,
271 int pending_history_list_offset); 64 int pending_history_list_offset);
272 65
273 content::PageTransition transition_type_; 66 content::PageTransition transition_type_;
274 LoadType load_type_;
275 base::Time request_time_;
276 base::Time start_load_time_;
277 base::Time commit_load_time_;
278 base::Time finish_document_load_time_;
279 base::Time finish_load_time_;
280 base::Time first_paint_time_;
281 base::Time first_paint_after_load_time_;
282 bool load_histograms_recorded_;
283 bool web_timing_histograms_recorded_;
284 bool request_committed_; 67 bool request_committed_;
285 bool is_content_initiated_; 68 bool is_content_initiated_;
286 int32 pending_page_id_; 69 int32 pending_page_id_;
287 int pending_history_list_offset_; 70 int pending_history_list_offset_;
288 GURL searchable_form_url_;
289 std::string searchable_form_encoding_;
290 scoped_ptr<webkit_glue::PasswordForm> password_form_data_;
291 scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_;
292 std::string security_info_;
293 71
294 bool use_error_page_;
295
296 bool cache_policy_override_set_;
297 WebKit::WebURLRequest::CachePolicy cache_policy_override_;
298
299 int http_status_code_;
300
301 bool was_fetched_via_spdy_;
302 bool was_npn_negotiated_;
303 bool was_alternate_protocol_available_;
304 bool was_fetched_via_proxy_;
305 bool was_translated_;
306 bool was_within_same_page_; 72 bool was_within_same_page_;
307 73
308 // A prefetcher is a page that contains link rel=prefetch elements.
309 bool was_prefetcher_;
310 bool was_referred_by_prefetcher_;
311
312 DISALLOW_COPY_AND_ASSIGN(NavigationState); 74 DISALLOW_COPY_AND_ASSIGN(NavigationState);
313 }; 75 };
314 76
315 #endif // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ 77 #endif // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
316 78
317 } // namespace content 79 } // namespace content
OLDNEW
« no previous file with comments | « content/public/renderer/document_state.cc ('k') | content/public/renderer/navigation_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698