| OLD | NEW |
| 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_DOCUMENT_STATE_H_ |
| 6 #define CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ | 6 #define CONTENT_PUBLIC_RENDERER_DOCUMENT_STATE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "content/public/common/page_transition_types.h" | |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 17 | 16 |
| 18 namespace webkit_glue { | 17 namespace webkit_glue { |
| 19 struct PasswordForm; | 18 struct PasswordForm; |
| 20 class AltErrorPageResourceFetcher; | 19 class AltErrorPageResourceFetcher; |
| 21 } | 20 } |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 | 23 |
| 24 class NavigationState; |
| 25 |
| 25 // The RenderView stores an instance of this class in the "extra data" of each | 26 // The RenderView stores an instance of this class in the "extra data" of each |
| 26 // WebDataSource (see RenderView::DidCreateDataSource). | 27 // WebDataSource (see RenderView::DidCreateDataSource). |
| 27 class NavigationState : public WebKit::WebDataSource::ExtraData { | 28 class DocumentState : public WebKit::WebDataSource::ExtraData { |
| 28 public: | 29 public: |
| 29 // The exact values of this enum are used in histograms, so new values must be | 30 // The exact values of this enum are used in histograms, so new values must be |
| 30 // added to the end. | 31 // added to the end. |
| 31 enum LoadType { | 32 enum LoadType { |
| 32 UNDEFINED_LOAD, // Not yet initialized. | 33 UNDEFINED_LOAD, // Not yet initialized. |
| 33 RELOAD, // User pressed reload. | 34 RELOAD, // User pressed reload. |
| 34 HISTORY_LOAD, // Back or forward. | 35 HISTORY_LOAD, // Back or forward. |
| 35 NORMAL_LOAD, // User entered URL, or omnibox search. | 36 NORMAL_LOAD, // User entered URL, or omnibox search. |
| 36 LINK_LOAD, // (deprecated) Included next 4 categories. | 37 LINK_LOAD, // (deprecated) Included next 4 categories. |
| 37 LINK_LOAD_NORMAL, // Commonly following of link. | 38 LINK_LOAD_NORMAL, // Commonly following of link. |
| 38 LINK_LOAD_RELOAD, // JS/link directed reload. | 39 LINK_LOAD_RELOAD, // JS/link directed reload. |
| 39 LINK_LOAD_CACHE_STALE_OK, // back/forward or encoding change. | 40 LINK_LOAD_CACHE_STALE_OK, // back/forward or encoding change. |
| 40 LINK_LOAD_CACHE_ONLY, // Allow stale data (avoid doing a re-post) | 41 LINK_LOAD_CACHE_ONLY, // Allow stale data (avoid doing a re-post) |
| 41 kLoadTypeMax // Bounding value for this enum. | 42 kLoadTypeMax // Bounding value for this enum. |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 virtual ~NavigationState(); | 45 DocumentState(); |
| 46 virtual ~DocumentState(); |
| 45 | 47 |
| 46 static NavigationState* CreateBrowserInitiated( | 48 static DocumentState* FromDataSource(WebKit::WebDataSource* ds) { |
| 47 int32 pending_page_id, | 49 return static_cast<DocumentState*>(ds->extraData()); |
| 48 int pending_history_list_offset, | |
| 49 content::PageTransition transition_type, | |
| 50 base::Time request_time) { | |
| 51 return new NavigationState(transition_type, request_time, false, | |
| 52 pending_page_id, | |
| 53 pending_history_list_offset); | |
| 54 } | 50 } |
| 55 | 51 |
| 56 static NavigationState* CreateContentInitiated() { | |
| 57 // We assume navigations initiated by content are link clicks. | |
| 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 } | |
| 65 | |
| 66 // Contains the page_id for this navigation or -1 if there is none yet. | |
| 67 int32 pending_page_id() const { return pending_page_id_; } | |
| 68 | |
| 69 // If pending_page_id() is not -1, then this contains the corresponding | |
| 70 // offset of the page in the back/forward history list. | |
| 71 int pending_history_list_offset() const { | |
| 72 return pending_history_list_offset_; | |
| 73 } | |
| 74 | |
| 75 // Contains the transition type that the browser specified when it | |
| 76 // initiated the load. | |
| 77 content::PageTransition transition_type() const { return transition_type_; } | |
| 78 void set_transition_type(content::PageTransition type) { | |
| 79 transition_type_ = type; | |
| 80 } | |
| 81 | |
| 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. | 52 // The time that this navigation was requested. |
| 87 const base::Time& request_time() const { | 53 const base::Time& request_time() const { |
| 88 return request_time_; | 54 return request_time_; |
| 89 } | 55 } |
| 90 void set_request_time(const base::Time& value) { | 56 void set_request_time(const base::Time& value) { |
| 91 DCHECK(start_load_time_.is_null()); | 57 DCHECK(start_load_time_.is_null()); |
| 92 request_time_ = value; | 58 request_time_ = value; |
| 93 } | 59 } |
| 94 | 60 |
| 95 // The time that the document load started. | 61 // The time that the document load started. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // DCHECK(!finish_document_load_time_.is_null()); | 101 // DCHECK(!finish_document_load_time_.is_null()); |
| 136 finish_load_time_ = value; | 102 finish_load_time_ = value; |
| 137 } | 103 } |
| 138 | 104 |
| 139 // The time that painting first happened after a new navigation. | 105 // The time that painting first happened after a new navigation. |
| 140 const base::Time& first_paint_time() const { return first_paint_time_; } | 106 const base::Time& first_paint_time() const { return first_paint_time_; } |
| 141 void set_first_paint_time(const base::Time& value) { | 107 void set_first_paint_time(const base::Time& value) { |
| 142 first_paint_time_ = value; | 108 first_paint_time_ = value; |
| 143 } | 109 } |
| 144 | 110 |
| 145 // The time that painting first happened after the document finished loading. | 111 // The time that painting first happened after the document loaded. |
| 146 const base::Time& first_paint_after_load_time() const { | 112 const base::Time& first_paint_after_load_time() const { |
| 147 return first_paint_after_load_time_; | 113 return first_paint_after_load_time_; |
| 148 } | 114 } |
| 149 void set_first_paint_after_load_time(const base::Time& value) { | 115 void set_first_paint_after_load_time(const base::Time& value) { |
| 150 first_paint_after_load_time_ = value; | 116 first_paint_after_load_time_ = value; |
| 151 } | 117 } |
| 152 | 118 |
| 153 // True iff the histograms for the associated frame have been dumped. | 119 // True iff the histograms for the associated frame have been dumped. |
| 154 bool load_histograms_recorded() const { return load_histograms_recorded_; } | 120 bool load_histograms_recorded() const { return load_histograms_recorded_; } |
| 155 void set_load_histograms_recorded(bool value) { | 121 void set_load_histograms_recorded(bool value) { |
| 156 load_histograms_recorded_ = value; | 122 load_histograms_recorded_ = value; |
| 157 } | 123 } |
| 158 | 124 |
| 159 bool web_timing_histograms_recorded() const { | 125 bool web_timing_histograms_recorded() const { |
| 160 return web_timing_histograms_recorded_; | 126 return web_timing_histograms_recorded_; |
| 161 } | 127 } |
| 162 void set_web_timing_histograms_recorded(bool value) { | 128 void set_web_timing_histograms_recorded(bool value) { |
| 163 web_timing_histograms_recorded_ = value; | 129 web_timing_histograms_recorded_ = value; |
| 164 } | 130 } |
| 165 | 131 |
| 166 // True if we have already processed the "DidCommitLoad" event for this | 132 int http_status_code() const { return http_status_code_; } |
| 167 // request. Used by session history. | 133 void set_http_status_code(int http_status_code) { |
| 168 bool request_committed() const { return request_committed_; } | 134 http_status_code_ = http_status_code; |
| 169 void set_request_committed(bool value) { request_committed_ = value; } | 135 } |
| 170 | 136 |
| 171 // True if this navigation was not initiated via WebFrame::LoadRequest. | 137 // Indicator if SPDY was used as part of this page load. |
| 172 bool is_content_initiated() const { return is_content_initiated_; } | 138 void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; } |
| 139 bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; } |
| 140 |
| 141 void set_was_npn_negotiated(bool value) { was_npn_negotiated_ = value; } |
| 142 bool was_npn_negotiated() const { return was_npn_negotiated_; } |
| 143 |
| 144 void set_was_alternate_protocol_available(bool value) { |
| 145 was_alternate_protocol_available_ = value; |
| 146 } |
| 147 bool was_alternate_protocol_available() const { |
| 148 return was_alternate_protocol_available_; |
| 149 } |
| 150 |
| 151 void set_was_fetched_via_proxy(bool value) { |
| 152 was_fetched_via_proxy_ = value; |
| 153 } |
| 154 bool was_fetched_via_proxy() const { return was_fetched_via_proxy_; } |
| 173 | 155 |
| 174 const GURL& searchable_form_url() const { return searchable_form_url_; } | 156 const GURL& searchable_form_url() const { return searchable_form_url_; } |
| 175 void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; } | 157 void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; } |
| 176 const std::string& searchable_form_encoding() const { | 158 const std::string& searchable_form_encoding() const { |
| 177 return searchable_form_encoding_; | 159 return searchable_form_encoding_; |
| 178 } | 160 } |
| 179 void set_searchable_form_encoding(const std::string& encoding) { | 161 void set_searchable_form_encoding(const std::string& encoding) { |
| 180 searchable_form_encoding_ = encoding; | 162 searchable_form_encoding_ = encoding; |
| 181 } | 163 } |
| 182 | 164 |
| 183 webkit_glue::PasswordForm* password_form_data() const { | 165 webkit_glue::PasswordForm* password_form_data() const { |
| 184 return password_form_data_.get(); | 166 return password_form_data_.get(); |
| 185 } | 167 } |
| 186 void set_password_form_data(webkit_glue::PasswordForm* data); | 168 void set_password_form_data(webkit_glue::PasswordForm* data); |
| 187 | 169 |
| 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_; } | 170 const std::string& security_info() const { return security_info_; } |
| 194 void set_security_info(const std::string& security_info) { | 171 void set_security_info(const std::string& security_info) { |
| 195 security_info_ = security_info; | 172 security_info_ = security_info; |
| 196 } | 173 } |
| 197 | 174 |
| 198 // True if an error page should be used, if the http status code also | 175 // True if an error page should be used, if the http status code also |
| 199 // indicates an error. | 176 // indicates an error. |
| 200 bool use_error_page() const { return use_error_page_; } | 177 bool use_error_page() const { return use_error_page_; } |
| 201 void set_use_error_page(bool use_error_page) { | 178 void set_use_error_page(bool use_error_page) { |
| 202 use_error_page_ = use_error_page; | 179 use_error_page_ = use_error_page; |
| 203 } | 180 } |
| 204 | 181 |
| 205 int http_status_code() const { return http_status_code_; } | 182 void set_was_prefetcher(bool value) { was_prefetcher_ = value; } |
| 206 void set_http_status_code(int http_status_code) { | 183 bool was_prefetcher() const { return was_prefetcher_; } |
| 207 http_status_code_ = http_status_code; | 184 |
| 185 void set_was_referred_by_prefetcher(bool value) { |
| 186 was_referred_by_prefetcher_ = value; |
| 208 } | 187 } |
| 188 bool was_referred_by_prefetcher() const { |
| 189 return was_referred_by_prefetcher_; |
| 190 } |
| 191 |
| 192 // Record the nature of this load, for use when histogramming page load times. |
| 193 LoadType load_type() const { return load_type_; } |
| 194 void set_load_type(LoadType load_type) { load_type_ = load_type; } |
| 209 | 195 |
| 210 // Sets the cache policy. The cache policy is only used if explicitly set and | 196 // 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 | 197 // by default is not set. You can mark a NavigationState as not having a cache |
| 212 // state by way of clear_cache_policy_override. | 198 // state by way of clear_cache_policy_override. |
| 213 void set_cache_policy_override( | 199 void set_cache_policy_override( |
| 214 WebKit::WebURLRequest::CachePolicy cache_policy) { | 200 WebKit::WebURLRequest::CachePolicy cache_policy) { |
| 215 cache_policy_override_ = cache_policy; | 201 cache_policy_override_ = cache_policy; |
| 216 cache_policy_override_set_ = true; | 202 cache_policy_override_set_ = true; |
| 217 } | 203 } |
| 218 WebKit::WebURLRequest::CachePolicy cache_policy_override() const { | 204 WebKit::WebURLRequest::CachePolicy cache_policy_override() const { |
| 219 return cache_policy_override_; | 205 return cache_policy_override_; |
| 220 } | 206 } |
| 221 void clear_cache_policy_override() { | 207 void clear_cache_policy_override() { |
| 222 cache_policy_override_set_ = false; | 208 cache_policy_override_set_ = false; |
| 223 cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy; | 209 cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy; |
| 224 } | 210 } |
| 225 bool is_cache_policy_override_set() const { | 211 bool is_cache_policy_override_set() const { |
| 226 return cache_policy_override_set_; | 212 return cache_policy_override_set_; |
| 227 } | 213 } |
| 228 | 214 |
| 229 // Indicator if SPDY was used as part of this page load. | 215 webkit_glue::AltErrorPageResourceFetcher* alt_error_page_fetcher() const { |
| 230 void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; } | 216 return alt_error_page_fetcher_.get(); |
| 231 bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; } | 217 } |
| 218 void set_alt_error_page_fetcher(webkit_glue::AltErrorPageResourceFetcher* f); |
| 232 | 219 |
| 233 void set_was_npn_negotiated(bool value) { was_npn_negotiated_ = value; } | 220 NavigationState* navigation_state() { return navigation_state_.get(); } |
| 234 bool was_npn_negotiated() const { return was_npn_negotiated_; } | 221 void set_navigation_state(NavigationState* navigation_state); |
| 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. | |
| 253 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_; } | |
| 255 | |
| 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 | 222 |
| 266 private: | 223 private: |
| 267 NavigationState(content::PageTransition transition_type, | |
| 268 const base::Time& request_time, | |
| 269 bool is_content_initiated, | |
| 270 int32 pending_page_id, | |
| 271 int pending_history_list_offset); | |
| 272 | |
| 273 content::PageTransition transition_type_; | |
| 274 LoadType load_type_; | |
| 275 base::Time request_time_; | 224 base::Time request_time_; |
| 276 base::Time start_load_time_; | 225 base::Time start_load_time_; |
| 277 base::Time commit_load_time_; | 226 base::Time commit_load_time_; |
| 278 base::Time finish_document_load_time_; | 227 base::Time finish_document_load_time_; |
| 279 base::Time finish_load_time_; | 228 base::Time finish_load_time_; |
| 280 base::Time first_paint_time_; | 229 base::Time first_paint_time_; |
| 281 base::Time first_paint_after_load_time_; | 230 base::Time first_paint_after_load_time_; |
| 282 bool load_histograms_recorded_; | 231 bool load_histograms_recorded_; |
| 283 bool web_timing_histograms_recorded_; | 232 bool web_timing_histograms_recorded_; |
| 284 bool request_committed_; | |
| 285 bool is_content_initiated_; | |
| 286 int32 pending_page_id_; | |
| 287 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 | |
| 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_; | 233 int http_status_code_; |
| 300 | |
| 301 bool was_fetched_via_spdy_; | 234 bool was_fetched_via_spdy_; |
| 302 bool was_npn_negotiated_; | 235 bool was_npn_negotiated_; |
| 303 bool was_alternate_protocol_available_; | 236 bool was_alternate_protocol_available_; |
| 304 bool was_fetched_via_proxy_; | 237 bool was_fetched_via_proxy_; |
| 305 bool was_translated_; | 238 |
| 306 bool was_within_same_page_; | 239 GURL searchable_form_url_; |
| 240 std::string searchable_form_encoding_; |
| 241 scoped_ptr<webkit_glue::PasswordForm> password_form_data_; |
| 242 std::string security_info_; |
| 243 |
| 244 bool use_error_page_; |
| 307 | 245 |
| 308 // A prefetcher is a page that contains link rel=prefetch elements. | 246 // A prefetcher is a page that contains link rel=prefetch elements. |
| 309 bool was_prefetcher_; | 247 bool was_prefetcher_; |
| 310 bool was_referred_by_prefetcher_; | 248 bool was_referred_by_prefetcher_; |
| 311 | 249 |
| 312 DISALLOW_COPY_AND_ASSIGN(NavigationState); | 250 LoadType load_type_; |
| 251 |
| 252 bool cache_policy_override_set_; |
| 253 WebKit::WebURLRequest::CachePolicy cache_policy_override_; |
| 254 |
| 255 scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_; |
| 256 |
| 257 scoped_ptr<NavigationState> navigation_state_; |
| 313 }; | 258 }; |
| 314 | 259 |
| 315 #endif // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_ | 260 #endif // CONTENT_PUBLIC_RENDERER_DOCUMENT_STATE_H_ |
| 316 | 261 |
| 317 } // namespace content | 262 } // namespace content |
| OLD | NEW |