summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/navigation_state.h
blob: d17b542056364a9e798f7822c9940fcf86697afb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_NAVIGATION_STATE_H_
#define CHROME_RENDERER_NAVIGATION_STATE_H_

#include "base/scoped_ptr.h"
#include "base/time.h"
#include "chrome/common/page_transition_types.h"
#include "chrome/renderer/user_script_idle_scheduler.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
#include "webkit/glue/alt_error_page_resource_fetcher.h"
#include "webkit/glue/password_form.h"

// The RenderView stores an instance of this class in the "extra data" of each
// WebDataSource (see RenderView::DidCreateDataSource).
class NavigationState : public WebKit::WebDataSource::ExtraData {
 public:
  enum LoadType {
    UNDEFINED_LOAD,            // Not yet initialized.
    RELOAD,                    // User pressed reload.
    HISTORY_LOAD,              // Back or forward.
    NORMAL_LOAD,               // User entered URL, or omnibox search.
    LINK_LOAD,                 // (deprecated) Included next 4 categories.
    LINK_LOAD_NORMAL,          // Commonly following of link.
    LINK_LOAD_RELOAD,          // JS/link directed reload.
    LINK_LOAD_CACHE_STALE_OK,  // back/forward or encoding change.
    LINK_LOAD_CACHE_ONLY,      // Allow stale data (avoid doing a re-post)
    kLoadTypeMax               // Bounding value for this enum.
  };

  static NavigationState* CreateBrowserInitiated(
      int32 pending_page_id,
      PageTransition::Type transition_type,
      base::Time request_time) {
    return new NavigationState(transition_type, request_time, false,
                               pending_page_id);
  }

  static NavigationState* CreateContentInitiated() {
    // We assume navigations initiated by content are link clicks.
    return new NavigationState(PageTransition::LINK, base::Time(), true, -1);
  }

  static NavigationState* FromDataSource(WebKit::WebDataSource* ds) {
    return static_cast<NavigationState*>(ds->extraData());
  }

  UserScriptIdleScheduler* user_script_idle_scheduler() {
    return user_script_idle_scheduler_.get();
  }
  void set_user_script_idle_scheduler(UserScriptIdleScheduler* scheduler) {
    user_script_idle_scheduler_.reset(scheduler);
  }

  // Contains the page_id for this navigation or -1 if there is none yet.
  int32 pending_page_id() const { return pending_page_id_; }

  // Contains the transition type that the browser specified when it
  // initiated the load.
  PageTransition::Type transition_type() const { return transition_type_; }
  void set_transition_type(PageTransition::Type type) {
    transition_type_ = type;
  }

  // Record the nature of this load, for use when histogramming page load times.
  LoadType load_type() const { return load_type_; }
  void set_load_type(LoadType load_type) { load_type_ = load_type; }

  // The time that this navigation was requested.
  const base::Time& request_time() const {
    return request_time_;
  }
  void set_request_time(const base::Time& value) {
    request_time_ = value;
  }

  // The time that the document load started.
  const base::Time& start_load_time() const {
    return start_load_time_;
  }
  void set_start_load_time(const base::Time& value) {
    start_load_time_ = value;
  }

  // The time that the document load was committed.
  const base::Time& commit_load_time() const {
    return commit_load_time_;
  }
  void set_commit_load_time(const base::Time& value) {
    commit_load_time_ = value;
  }

  // The time that the document finished loading.
  const base::Time& finish_document_load_time() const {
    return finish_document_load_time_;
  }
  void set_finish_document_load_time(const base::Time& value) {
    finish_document_load_time_ = value;
  }

  // The time that the document and all subresources finished loading.
  const base::Time& finish_load_time() const {
    return finish_load_time_;
  }
  void set_finish_load_time(const base::Time& value) {
    finish_load_time_ = value;
  }

  // The time that painting first happened after a new navigation.
  const base::Time& first_paint_time() const {
    return first_paint_time_;
  }
  void set_first_paint_time(const base::Time& value) {
    first_paint_time_ = value;
  }

  // The time that painting first happened after the document finished loading.
  const base::Time& first_paint_after_load_time() const {
    return first_paint_after_load_time_;
  }
  void set_first_paint_after_load_time(const base::Time& value) {
    first_paint_after_load_time_ = value;
  }

  // True iff the histograms for the associated frame have been dumped.
  bool load_histograms_recorded() const {
    return load_histograms_recorded_;
  }
  void set_load_histograms_recorded(bool value) {
    load_histograms_recorded_ = value;
  }

  // True if we have already processed the "DidCommitLoad" event for this
  // request.  Used by session history.
  bool request_committed() const { return request_committed_; }
  void set_request_committed(bool value) { request_committed_ = value; }

  // True if this navigation was not initiated via WebFrame::LoadRequest.
  bool is_content_initiated() const { return is_content_initiated_; }

  const GURL& searchable_form_url() const { return searchable_form_url_; }
  void set_searchable_form_url(const GURL& url) { searchable_form_url_ = url; }
  const std::string& searchable_form_encoding() const {
    return searchable_form_encoding_;
  }
  void set_searchable_form_encoding(const std::string& encoding) {
    searchable_form_encoding_ = encoding;
  }

  webkit_glue::PasswordForm* password_form_data() const {
    return password_form_data_.get();
  }
  void set_password_form_data(webkit_glue::PasswordForm* data) {
    password_form_data_.reset(data);
  }

  webkit_glue::AltErrorPageResourceFetcher* alt_error_page_fetcher() const {
    return alt_error_page_fetcher_.get();
  }
  void set_alt_error_page_fetcher(webkit_glue::AltErrorPageResourceFetcher* f) {
    alt_error_page_fetcher_.reset(f);
  }

  const std::string& security_info() const {
    return security_info_;
  }
  void set_security_info(const std::string& security_info) {
    security_info_ = security_info;
  }

  bool postpone_loading_data() const {
    return postpone_loading_data_;
  }
  void set_postpone_loading_data(bool postpone_loading_data) {
    postpone_loading_data_ = postpone_loading_data;
  }

  void clear_postponed_data() {
    postponed_data_.clear();
  }
  void append_postponed_data(const char* data, size_t data_len) {
    postponed_data_.append(data, data_len);
  }
  const std::string& postponed_data() const {
    return postponed_data_;
  }

  // Sets the cache policy. The cache policy is only used if explicitly set and
  // by default is not set. You can mark a NavigationState as not having a cache
  // state by way of clear_cache_policy_override.
  void set_cache_policy_override(
      WebKit::WebURLRequest::CachePolicy cache_policy) {
    cache_policy_override_ = cache_policy;
    cache_policy_override_set_ = true;
  }
  WebKit::WebURLRequest::CachePolicy cache_policy_override() const {
    return cache_policy_override_;
  }
  void clear_cache_policy_override() {
    cache_policy_override_set_ = false;
    cache_policy_override_ = WebKit::WebURLRequest::UseProtocolCachePolicy;
  }
  bool is_cache_policy_override_set() const {
    return cache_policy_override_set_;
  }

  // Indicator if SPDY was used as part of this page load.
  void set_was_fetched_via_spdy(bool value) { was_fetched_via_spdy_ = value; }
  bool was_fetched_via_spdy() const { return was_fetched_via_spdy_; }

  // Whether the frame text contents was translated to a different language.
  void set_was_translated(bool value) { was_translated_ = value; }
  bool was_translated() const { return was_translated_; }

 private:
  NavigationState(PageTransition::Type transition_type,
                  const base::Time& request_time,
                  bool is_content_initiated,
                  int32 pending_page_id)
      : transition_type_(transition_type),
        load_type_(UNDEFINED_LOAD),
        request_time_(request_time),
        load_histograms_recorded_(false),
        request_committed_(false),
        is_content_initiated_(is_content_initiated),
        pending_page_id_(pending_page_id),
        postpone_loading_data_(false),
        cache_policy_override_set_(false),
        cache_policy_override_(WebKit::WebURLRequest::UseProtocolCachePolicy),
        user_script_idle_scheduler_(NULL),
        was_fetched_via_spdy_(false),
        was_translated_(false) {
  }

  PageTransition::Type transition_type_;
  LoadType load_type_;
  base::Time request_time_;
  base::Time start_load_time_;
  base::Time commit_load_time_;
  base::Time finish_document_load_time_;
  base::Time finish_load_time_;
  base::Time first_paint_time_;
  base::Time first_paint_after_load_time_;
  bool load_histograms_recorded_;
  bool request_committed_;
  bool is_content_initiated_;
  int32 pending_page_id_;
  GURL searchable_form_url_;
  std::string searchable_form_encoding_;
  scoped_ptr<webkit_glue::PasswordForm> password_form_data_;
  scoped_ptr<webkit_glue::AltErrorPageResourceFetcher> alt_error_page_fetcher_;
  std::string security_info_;
  bool postpone_loading_data_;
  std::string postponed_data_;

  bool cache_policy_override_set_;
  WebKit::WebURLRequest::CachePolicy cache_policy_override_;

  scoped_ptr<UserScriptIdleScheduler> user_script_idle_scheduler_;

  bool was_fetched_via_spdy_;

  bool was_translated_;

  DISALLOW_COPY_AND_ASSIGN(NavigationState);
};

#endif  // CHROME_RENDERER_NAVIGATION_STATE_H_