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/child/npapi/plugin_stream_url.h" | 5 #include "content/child/npapi/plugin_stream_url.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
| 9 #include "base/strings/string_util.h" |
9 #include "content/child/npapi/plugin_host.h" | 10 #include "content/child/npapi/plugin_host.h" |
10 #include "content/child/npapi/plugin_instance.h" | 11 #include "content/child/npapi/plugin_instance.h" |
11 #include "content/child/npapi/plugin_lib.h" | 12 #include "content/child/npapi/plugin_lib.h" |
| 13 #include "content/child/npapi/plugin_url_fetcher.h" |
12 #include "content/child/npapi/webplugin.h" | 14 #include "content/child/npapi/webplugin.h" |
13 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
14 | 16 |
15 namespace content { | 17 namespace content { |
16 | 18 |
17 PluginStreamUrl::PluginStreamUrl( | 19 PluginStreamUrl::PluginStreamUrl( |
18 unsigned long resource_id, | 20 unsigned long resource_id, |
19 const GURL &url, | 21 const GURL &url, |
20 PluginInstance *instance, | 22 PluginInstance *instance, |
21 bool notify_needed, | 23 bool notify_needed, |
22 void *notify_data) | 24 void *notify_data) |
23 : PluginStream(instance, url.spec().c_str(), notify_needed, notify_data), | 25 : PluginStream(instance, url.spec().c_str(), notify_needed, notify_data), |
24 url_(url), | 26 url_(url), |
25 id_(resource_id) { | 27 id_(resource_id) { |
26 } | 28 } |
27 | 29 |
| 30 void PluginStreamUrl::SetPluginURLFetcher(PluginURLFetcher* fetcher) { |
| 31 plugin_url_fetcher_.reset(fetcher); |
| 32 } |
| 33 |
| 34 void PluginStreamUrl::URLRedirectResponse(bool allow) { |
| 35 if (plugin_url_fetcher_.get()) { |
| 36 plugin_url_fetcher_->URLRedirectResponse(allow); |
| 37 } else { |
| 38 instance()->webplugin()->URLRedirectResponse(allow, id_); |
| 39 } |
| 40 |
| 41 if (allow) |
| 42 UpdateUrl(pending_redirect_url_.c_str()); |
| 43 } |
| 44 |
28 bool PluginStreamUrl::Close(NPReason reason) { | 45 bool PluginStreamUrl::Close(NPReason reason) { |
29 // Protect the stream against it being destroyed or the whole plugin instance | 46 // Protect the stream against it being destroyed or the whole plugin instance |
30 // being destroyed within the destroy stream handler. | 47 // being destroyed within the destroy stream handler. |
31 scoped_refptr<PluginStream> protect(this); | 48 scoped_refptr<PluginStream> protect(this); |
32 CancelRequest(); | 49 CancelRequest(); |
33 bool result = PluginStream::Close(reason); | 50 bool result = PluginStream::Close(reason); |
34 instance()->RemoveStream(this); | 51 instance()->RemoveStream(this); |
35 return result; | 52 return result; |
36 } | 53 } |
37 | 54 |
38 WebPluginResourceClient* PluginStreamUrl::AsResourceClient() { | 55 WebPluginResourceClient* PluginStreamUrl::AsResourceClient() { |
39 return static_cast<WebPluginResourceClient*>(this); | 56 return static_cast<WebPluginResourceClient*>(this); |
40 } | 57 } |
41 | 58 |
42 void PluginStreamUrl::CancelRequest() { | 59 void PluginStreamUrl::CancelRequest() { |
43 if (id_ > 0) { | 60 if (id_ > 0) { |
44 if (instance()->webplugin()) { | 61 if (plugin_url_fetcher_.get()) { |
45 instance()->webplugin()->CancelResource(id_); | 62 plugin_url_fetcher_->Cancel(); |
| 63 } else { |
| 64 if (instance()->webplugin()) { |
| 65 instance()->webplugin()->CancelResource(id_); |
| 66 } |
46 } | 67 } |
47 id_ = 0; | 68 id_ = 0; |
48 } | 69 } |
49 if (instance()->webplugin()) { | 70 if (instance()->webplugin()) { |
50 for (size_t i = 0; i < range_requests_.size(); ++i) | 71 for (size_t i = 0; i < range_requests_.size(); ++i) |
51 instance()->webplugin()->CancelResource(range_requests_[i]); | 72 instance()->webplugin()->CancelResource(range_requests_[i]); |
52 } | 73 } |
53 range_requests_.clear(); | 74 range_requests_.clear(); |
54 } | 75 } |
55 | 76 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 155 |
135 bool PluginStreamUrl::IsMultiByteResponseExpected() { | 156 bool PluginStreamUrl::IsMultiByteResponseExpected() { |
136 return seekable(); | 157 return seekable(); |
137 } | 158 } |
138 | 159 |
139 int PluginStreamUrl::ResourceId() { | 160 int PluginStreamUrl::ResourceId() { |
140 return id_; | 161 return id_; |
141 } | 162 } |
142 | 163 |
143 PluginStreamUrl::~PluginStreamUrl() { | 164 PluginStreamUrl::~PluginStreamUrl() { |
144 if (instance() && instance()->webplugin()) { | 165 if (!plugin_url_fetcher_.get() && instance() && instance()->webplugin()) { |
145 instance()->webplugin()->ResourceClientDeleted(AsResourceClient()); | 166 instance()->webplugin()->ResourceClientDeleted(AsResourceClient()); |
146 } | 167 } |
147 } | 168 } |
148 | 169 |
149 void PluginStreamUrl::AddRangeRequestResourceId(unsigned long resource_id) { | 170 void PluginStreamUrl::AddRangeRequestResourceId(unsigned long resource_id) { |
150 DCHECK_NE(resource_id, 0u); | 171 DCHECK_NE(resource_id, 0u); |
151 range_requests_.push_back(resource_id); | 172 range_requests_.push_back(resource_id); |
152 } | 173 } |
153 | 174 |
154 void PluginStreamUrl::SetDeferLoading(bool value) { | 175 void PluginStreamUrl::SetDeferLoading(bool value) { |
155 if (id_ > 0) | 176 if (id_ > 0) |
156 instance()->webplugin()->SetDeferResourceLoading(id_, value); | 177 instance()->webplugin()->SetDeferResourceLoading(id_, value); |
157 for (size_t i = 0; i < range_requests_.size(); ++i) | 178 for (size_t i = 0; i < range_requests_.size(); ++i) |
158 instance()->webplugin()->SetDeferResourceLoading(range_requests_[i], | 179 instance()->webplugin()->SetDeferResourceLoading(range_requests_[i], |
159 value); | 180 value); |
160 } | 181 } |
161 | 182 |
| 183 void PluginStreamUrl::UpdateUrl(const char* url) { |
| 184 DCHECK(!open()); |
| 185 free(const_cast<char*>(stream()->url)); |
| 186 stream()->url = base::strdup(url); |
| 187 pending_redirect_url_.clear(); |
| 188 } |
| 189 |
162 } // namespace content | 190 } // namespace content |
OLD | NEW |