summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webdatasource_impl.h
blob: 90f8313a22243a33bfc7ac87322eb52a74c296a7 (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
// Copyright (c) 2006-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 WEBKIT_GLUE_WEBDATASOURCE_IMPL_H_
#define WEBKIT_GLUE_WEBDATASOURCE_IMPL_H_

#include "DocumentLoader.h"

#include "base/scoped_ptr.h"
#include "base/time.h"
#include "webkit/glue/searchable_form_data.h"
#include "webkit/glue/webdatasource.h"
#include "webkit/glue/webresponse_impl.h"
#include "webkit/glue/weburlrequest_impl.h"

class WebFrameImpl;
class WebDocumentLoaderImpl;

class WebDataSourceImpl : public WebCore::DocumentLoader, public WebDataSource {
 public:
  static PassRefPtr<WebDataSourceImpl> Create(const WebCore::ResourceRequest&,
                                              const WebCore::SubstituteData&);

  static WebDataSourceImpl* FromLoader(WebCore::DocumentLoader* loader) {
    return static_cast<WebDataSourceImpl*>(loader);
  }

  // WebDataSource methods:
  virtual WebFrame* GetWebFrame();
  virtual const WebRequest& GetInitialRequest() const;
  virtual const WebRequest& GetRequest() const;
  virtual const WebResponse& GetResponse() const;
  virtual GURL GetUnreachableURL() const;
  virtual bool HasUnreachableURL() const;
  virtual const std::vector<GURL>& GetRedirectChain() const;
  virtual const SearchableFormData* GetSearchableFormData() const;
  virtual const PasswordForm* GetPasswordFormData() const;
  virtual bool IsFormSubmit() const;
  virtual string16 GetPageTitle() const;
  virtual base::Time GetRequestTime() const;
  virtual void SetRequestTime(base::Time time);
  virtual base::Time GetStartLoadTime() const;
  virtual base::Time GetFinishDocumentLoadTime() const;
  virtual base::Time GetFinishLoadTime() const;
  virtual WebNavigationType GetNavigationType() const;

  static WebNavigationType NavigationTypeToWebNavigationType(
      WebCore::NavigationType type);

  // Called after creating a new data source if there is request info
  // available. Since we store copies of the WebRequests, the original
  // WebRequest that the embedder created was lost, and the exra data would
  // go with it. This preserves the request info so retrieving the requests
  // later will have the same data.
  void SetExtraData(WebRequest::ExtraData* extra);

  void ClearRedirectChain();
  void AppendRedirect(const GURL& url);

  // Sets the SearchableFormData for this DocumentLoader.
  // WebDocumentLoaderImpl will own the SearchableFormData.
  void set_searchable_form_data(SearchableFormData* searchable_form_data) {
    searchable_form_data_.reset(searchable_form_data);
  }
  // Returns the SearchableFormData for this DocumentLoader.
  // WebDocumentLoaderImpl owns the returned SearchableFormData.
  const SearchableFormData* searchable_form_data() const {
    return searchable_form_data_.get();
  }

  // Sets the PasswordFormData for this DocumentLoader.
  // WebDocumentLoaderImpl will own the PasswordFormData.
  void set_password_form_data(PasswordForm* password_form_data) {
    password_form_data_.reset(password_form_data);
  }
  // Returns the PasswordFormData for this DocumentLoader.
  // WebDocumentLoaderImpl owns the returned PasswordFormData.
  const PasswordForm* password_form_data() const {
    return password_form_data_.get();
  }

  void set_form_submit(bool value) {
    form_submit_ = value;
  }
  bool is_form_submit() const {
    return form_submit_;
  }

  void set_request_time(base::Time request_time) {
    request_time_ = request_time;
  }

  void set_start_load_time(base::Time start_load_time) {
    start_load_time_ = start_load_time;
  }

  void set_finish_document_load_time(base::Time finish_document_load_time) {
    finish_document_load_time_ = finish_document_load_time;
  }

  void set_finish_load_time(base::Time finish_load_time) {
    finish_load_time_ = finish_load_time;
  }

 private:
  WebDataSourceImpl(const WebCore::ResourceRequest&,
                    const WebCore::SubstituteData&);
  ~WebDataSourceImpl();

  // Mutable because the const getters will magically sync these to the
  // latest version from WebKit.
  mutable WebRequestImpl initial_request_;
  mutable WebRequestImpl request_;
  mutable WebResponseImpl response_;

  // Lists all intermediate URLs that have redirected for the current
  // provisional load. See WebFrameLoaderClient::
  // dispatchDidReceiveServerRedirectForProvisionalLoad for a description of
  // who modifies this when to keep it up to date.
  std::vector<GURL> redirect_chain_;

  scoped_ptr<const SearchableFormData> searchable_form_data_;
  scoped_ptr<const PasswordForm> password_form_data_;

  bool form_submit_;

  // See webdatasource.h for a description of these time stamps.
  base::Time request_time_;
  base::Time start_load_time_;
  base::Time finish_document_load_time_;
  base::Time finish_load_time_;

  DISALLOW_COPY_AND_ASSIGN(WebDataSourceImpl);
};

#endif  // WEBKIT_GLUE_WEBDATASOURCE_IMPL_H_