OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/renderer/npapi/webplugin_delegate_proxy.h" | 5 #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 // Proxy for WebPluginResourceClient. The object owns itself after creation, | 95 // Proxy for WebPluginResourceClient. The object owns itself after creation, |
96 // deleting itself after its callback has been called. | 96 // deleting itself after its callback has been called. |
97 class ResourceClientProxy : public WebPluginResourceClient { | 97 class ResourceClientProxy : public WebPluginResourceClient { |
98 public: | 98 public: |
99 ResourceClientProxy(PluginChannelHost* channel, int instance_id) | 99 ResourceClientProxy(PluginChannelHost* channel, int instance_id) |
100 : channel_(channel), instance_id_(instance_id), resource_id_(0), | 100 : channel_(channel), instance_id_(instance_id), resource_id_(0), |
101 multibyte_response_expected_(false) { | 101 multibyte_response_expected_(false) { |
102 } | 102 } |
103 | 103 |
104 virtual ~ResourceClientProxy() { | 104 ~ResourceClientProxy() override {} |
105 } | |
106 | 105 |
107 void Initialize(unsigned long resource_id, const GURL& url, int notify_id) { | 106 void Initialize(unsigned long resource_id, const GURL& url, int notify_id) { |
108 resource_id_ = resource_id; | 107 resource_id_ = resource_id; |
109 channel_->Send(new PluginMsg_HandleURLRequestReply( | 108 channel_->Send(new PluginMsg_HandleURLRequestReply( |
110 instance_id_, resource_id, url, notify_id)); | 109 instance_id_, resource_id, url, notify_id)); |
111 } | 110 } |
112 | 111 |
113 void InitializeForSeekableStream(unsigned long resource_id, | 112 void InitializeForSeekableStream(unsigned long resource_id, |
114 int range_request_id) { | 113 int range_request_id) { |
115 resource_id_ = resource_id; | 114 resource_id_ = resource_id; |
116 multibyte_response_expected_ = true; | 115 multibyte_response_expected_ = true; |
117 channel_->Send(new PluginMsg_HTTPRangeRequestReply( | 116 channel_->Send(new PluginMsg_HTTPRangeRequestReply( |
118 instance_id_, resource_id, range_request_id)); | 117 instance_id_, resource_id, range_request_id)); |
119 } | 118 } |
120 | 119 |
121 // PluginResourceClient implementation: | 120 // PluginResourceClient implementation: |
122 virtual void WillSendRequest(const GURL& url, int http_status_code) override { | 121 void WillSendRequest(const GURL& url, int http_status_code) override { |
123 DCHECK(channel_.get() != NULL); | 122 DCHECK(channel_.get() != NULL); |
124 channel_->Send(new PluginMsg_WillSendRequest( | 123 channel_->Send(new PluginMsg_WillSendRequest( |
125 instance_id_, resource_id_, url, http_status_code)); | 124 instance_id_, resource_id_, url, http_status_code)); |
126 } | 125 } |
127 | 126 |
128 virtual void DidReceiveResponse(const std::string& mime_type, | 127 void DidReceiveResponse(const std::string& mime_type, |
129 const std::string& headers, | 128 const std::string& headers, |
130 uint32 expected_length, | 129 uint32 expected_length, |
131 uint32 last_modified, | 130 uint32 last_modified, |
132 bool request_is_seekable) override { | 131 bool request_is_seekable) override { |
133 DCHECK(channel_.get() != NULL); | 132 DCHECK(channel_.get() != NULL); |
134 PluginMsg_DidReceiveResponseParams params; | 133 PluginMsg_DidReceiveResponseParams params; |
135 params.id = resource_id_; | 134 params.id = resource_id_; |
136 params.mime_type = mime_type; | 135 params.mime_type = mime_type; |
137 params.headers = headers; | 136 params.headers = headers; |
138 params.expected_length = expected_length; | 137 params.expected_length = expected_length; |
139 params.last_modified = last_modified; | 138 params.last_modified = last_modified; |
140 params.request_is_seekable = request_is_seekable; | 139 params.request_is_seekable = request_is_seekable; |
141 // Grab a reference on the underlying channel so it does not get | 140 // Grab a reference on the underlying channel so it does not get |
142 // deleted from under us. | 141 // deleted from under us. |
143 scoped_refptr<PluginChannelHost> channel_ref(channel_); | 142 scoped_refptr<PluginChannelHost> channel_ref(channel_); |
144 channel_->Send(new PluginMsg_DidReceiveResponse(instance_id_, params)); | 143 channel_->Send(new PluginMsg_DidReceiveResponse(instance_id_, params)); |
145 } | 144 } |
146 | 145 |
147 virtual void DidReceiveData(const char* buffer, | 146 void DidReceiveData(const char* buffer, |
148 int length, | 147 int length, |
149 int data_offset) override { | 148 int data_offset) override { |
150 DCHECK(channel_.get() != NULL); | 149 DCHECK(channel_.get() != NULL); |
151 DCHECK_GT(length, 0); | 150 DCHECK_GT(length, 0); |
152 std::vector<char> data; | 151 std::vector<char> data; |
153 data.resize(static_cast<size_t>(length)); | 152 data.resize(static_cast<size_t>(length)); |
154 memcpy(&data.front(), buffer, length); | 153 memcpy(&data.front(), buffer, length); |
155 // Grab a reference on the underlying channel so it does not get | 154 // Grab a reference on the underlying channel so it does not get |
156 // deleted from under us. | 155 // deleted from under us. |
157 scoped_refptr<PluginChannelHost> channel_ref(channel_); | 156 scoped_refptr<PluginChannelHost> channel_ref(channel_); |
158 channel_->Send(new PluginMsg_DidReceiveData(instance_id_, resource_id_, | 157 channel_->Send(new PluginMsg_DidReceiveData(instance_id_, resource_id_, |
159 data, data_offset)); | 158 data, data_offset)); |
160 } | 159 } |
161 | 160 |
162 virtual void DidFinishLoading(unsigned long resource_id) override { | 161 void DidFinishLoading(unsigned long resource_id) override { |
163 DCHECK(channel_.get() != NULL); | 162 DCHECK(channel_.get() != NULL); |
164 DCHECK_EQ(resource_id, resource_id_); | 163 DCHECK_EQ(resource_id, resource_id_); |
165 channel_->Send(new PluginMsg_DidFinishLoading(instance_id_, resource_id_)); | 164 channel_->Send(new PluginMsg_DidFinishLoading(instance_id_, resource_id_)); |
166 channel_ = NULL; | 165 channel_ = NULL; |
167 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 166 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
168 } | 167 } |
169 | 168 |
170 virtual void DidFail(unsigned long resource_id) override { | 169 void DidFail(unsigned long resource_id) override { |
171 DCHECK(channel_.get() != NULL); | 170 DCHECK(channel_.get() != NULL); |
172 DCHECK_EQ(resource_id, resource_id_); | 171 DCHECK_EQ(resource_id, resource_id_); |
173 channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_)); | 172 channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_)); |
174 channel_ = NULL; | 173 channel_ = NULL; |
175 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 174 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
176 } | 175 } |
177 | 176 |
178 virtual bool IsMultiByteResponseExpected() override { | 177 bool IsMultiByteResponseExpected() override { |
179 return multibyte_response_expected_; | 178 return multibyte_response_expected_; |
180 } | 179 } |
181 | 180 |
182 virtual int ResourceId() override { | 181 int ResourceId() override { return resource_id_; } |
183 return resource_id_; | |
184 } | |
185 | 182 |
186 private: | 183 private: |
187 scoped_refptr<PluginChannelHost> channel_; | 184 scoped_refptr<PluginChannelHost> channel_; |
188 int instance_id_; | 185 int instance_id_; |
189 unsigned long resource_id_; | 186 unsigned long resource_id_; |
190 // Set to true if the response expected is a multibyte response. | 187 // Set to true if the response expected is a multibyte response. |
191 // For e.g. response for a HTTP byte range request. | 188 // For e.g. response for a HTTP byte range request. |
192 bool multibyte_response_expected_; | 189 bool multibyte_response_expected_; |
193 }; | 190 }; |
194 | 191 |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 | 1237 |
1241 plugin_->URLRedirectResponse(allow, resource_id); | 1238 plugin_->URLRedirectResponse(allow, resource_id); |
1242 } | 1239 } |
1243 | 1240 |
1244 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, | 1241 void WebPluginDelegateProxy::OnCheckIfRunInsecureContent(const GURL& url, |
1245 bool* result) { | 1242 bool* result) { |
1246 *result = plugin_->CheckIfRunInsecureContent(url); | 1243 *result = plugin_->CheckIfRunInsecureContent(url); |
1247 } | 1244 } |
1248 | 1245 |
1249 } // namespace content | 1246 } // namespace content |
OLD | NEW |