summaryrefslogtreecommitdiffstats
path: root/chrome_frame/plugin_url_request.h
blob: 49937703477871f3c4c0a6761e5f440004f1e2d5 (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
// 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_FRAME_PLUGIN_URL_REQUEST_H_
#define CHROME_FRAME_PLUGIN_URL_REQUEST_H_

#include <string>
#include <vector>

#include "base/ref_counted.h"
#include "base/scoped_comptr_win.h"
#include "base/time.h"
#include "chrome_frame/chrome_frame_delegate.h"
#include "chrome_frame/urlmon_upload_data_stream.h"
#include "ipc/ipc_message.h"
#include "net/base/upload_data.h"
#include "net/url_request/url_request_status.h"

class PluginUrlRequest;

// Interface for a class that keeps a collection of outstanding
// reqeusts and offers an outgoing channel.
class PluginRequestHandler
    : public IPC::Message::Sender,
      public base::RefCountedThreadSafe<PluginRequestHandler> {
 public:
  virtual bool AddRequest(PluginUrlRequest* request) = 0;
  virtual void RemoveRequest(PluginUrlRequest* request) = 0;
};

// A reference counting solution whose method's are compatible with
// scoped_refptr and COM's IUnknown.  Don't cast this object directly over to
// IUnknown though since IUnknown's first method is QueryInterface.
class UrlRequestReference {
 public:
  virtual unsigned long API_CALL AddRef() = 0;  // NOLINT
  virtual unsigned long API_CALL Release() = 0;  // NOLINT
};

class PluginUrlRequest : public UrlRequestReference {
 public:
  PluginUrlRequest();
  ~PluginUrlRequest();

  bool Initialize(PluginRequestHandler* handler, int tab,
                  int remote_request_id, const std::string& url,
                  const std::string& method, const std::string& referrer,
                  const std::string& extra_headers,
                  net::UploadData* upload_data,
                  bool intercept_frame_options);

  // Called in response to automation IPCs
  virtual bool Start() = 0;
  virtual void Stop() = 0;
  virtual bool Read(int bytes_to_read) = 0;

  // Persistent cookies are read from the host browser and passed off to Chrome
  // These cookies are sent when we receive a response for every URL request
  // initiated by Chrome. Ideally we should only send cookies for the top level
  // URL and any subframes. However we don't receive information from Chrome
  // about the context for a URL, i.e. whether it is a subframe, etc.
  // Additionally cookies for a URL should be sent once for the page. This
  // is not done now as it is difficult to track URLs, specifically if they
  // are redirected, etc.
  void OnResponseStarted(const char* mime_type, const char* headers, int size,
      base::Time last_modified, const std::string& peristent_cookies,
      const std::string& redirect_url, int redirect_status);

  void OnReadComplete(const void* buffer, int len);
  void OnResponseEnd(const URLRequestStatus& status);

  PluginRequestHandler* request_handler() const {
    return request_handler_;
  }

  int id() const {
    return remote_request_id_;
  }

  const std::string& url() const {
    return url_;
  }

  const std::string& method() const {
    return method_;
  }

  void set_method(const std::string& new_method) {
    method_ = new_method;
  }

  const std::string& referrer() const {
    return referrer_;
  }

  const std::string& extra_headers() const {
    return extra_headers_;
  }

  uint64 post_data_len() const {
    return post_data_len_;
  }

  HRESULT get_upload_data(IStream** ret) {
    DCHECK(ret);
    if (!upload_data_.get())
      return S_FALSE;
    *ret = upload_data_.get();
    (*ret)->AddRef();
    return S_OK;
  }

  void ClearPostData() {
    upload_data_.Release();
    post_data_len_ = 0;
  }

  bool is_done() const {
    return (URLRequestStatus::IO_PENDING != status_);
  }

  void set_url(const std::string& url) {
    url_ = url;
  }

 protected:
  void SendData();
  bool frame_busting_enabled_;

 private:
  scoped_refptr<PluginRequestHandler> request_handler_;
  int tab_;
  int remote_request_id_;
  uint64 post_data_len_;
  std::string url_;
  std::string method_;
  std::string referrer_;
  std::string extra_headers_;
  ScopedComPtr<IStream> upload_data_;
  URLRequestStatus::Status status_;
};

#endif  // CHROME_FRAME_PLUGIN_URL_REQUEST_H_