| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 |
| 5 #include "webkit/glue/plugins/plugin_stream_url.h" | 6 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 6 | 7 |
| 7 #include "webkit/glue/glue_util.h" | 8 #include "webkit/glue/glue_util.h" |
| 8 #include "webkit/glue/webplugin.h" | 9 #include "webkit/glue/webplugin.h" |
| 9 #include "webkit/glue/plugins/plugin_host.h" | 10 #include "webkit/glue/plugins/plugin_host.h" |
| 10 #include "webkit/glue/plugins/plugin_instance.h" | 11 #include "webkit/glue/plugins/plugin_instance.h" |
| 11 | 12 |
| 12 namespace NPAPI { | 13 namespace NPAPI { |
| 13 | 14 |
| 14 PluginStreamUrl::PluginStreamUrl( | 15 PluginStreamUrl::PluginStreamUrl( |
| 15 int resource_id, | 16 int resource_id, |
| 16 const GURL &url, | 17 const GURL &url, |
| 17 PluginInstance *instance, | 18 PluginInstance *instance, |
| 18 bool notify_needed, | 19 bool notify_needed, |
| 19 void *notify_data) | 20 void *notify_data) |
| 20 : PluginStream(instance, url.spec().c_str(), notify_needed, notify_data), | 21 : PluginStream(instance, url.spec().c_str(), notify_needed, notify_data), |
| 21 url_(url), | 22 url_(url), |
| 22 id_(resource_id) { | 23 id_(resource_id) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 PluginStreamUrl::~PluginStreamUrl() { | 26 PluginStreamUrl::~PluginStreamUrl() { |
| 26 } | 27 } |
| 27 | 28 |
| 28 bool PluginStreamUrl::Close(NPReason reason) { | 29 bool PluginStreamUrl::Close(NPReason reason) { |
| 29 if (id_ != 0) { | 30 CancelRequest(); |
| 30 if (instance()->webplugin()) { | |
| 31 instance()->webplugin()->CancelResource(id_); | |
| 32 } | |
| 33 | |
| 34 id_ = 0; | |
| 35 } | |
| 36 | |
| 37 bool result = PluginStream::Close(reason); | 31 bool result = PluginStream::Close(reason); |
| 38 instance()->RemoveStream(this); | 32 instance()->RemoveStream(this); |
| 39 return result; | 33 return result; |
| 40 } | 34 } |
| 41 | 35 |
| 42 void PluginStreamUrl::WillSendRequest(const GURL& url) { | 36 void PluginStreamUrl::WillSendRequest(const GURL& url) { |
| 43 url_ = url; | 37 url_ = url; |
| 44 UpdateUrl(url.spec().c_str()); | 38 UpdateUrl(url.spec().c_str()); |
| 45 } | 39 } |
| 46 | 40 |
| 47 void PluginStreamUrl::DidReceiveResponse(const std::string& mime_type, | 41 void PluginStreamUrl::DidReceiveResponse(const std::string& mime_type, |
| 48 const std::string& headers, | 42 const std::string& headers, |
| 49 uint32 expected_length, | 43 uint32 expected_length, |
| 50 uint32 last_modified, | 44 uint32 last_modified, |
| 51 bool* cancel) { | 45 bool* cancel) { |
| 52 | |
| 53 bool opened = Open(mime_type, | 46 bool opened = Open(mime_type, |
| 54 headers, | 47 headers, |
| 55 expected_length, | 48 expected_length, |
| 56 last_modified); | 49 last_modified); |
| 57 if (!opened) { | 50 if (!opened) { |
| 58 instance()->RemoveStream(this); | 51 instance()->RemoveStream(this); |
| 59 *cancel = true; | 52 *cancel = true; |
| 60 } | 53 } |
| 61 } | 54 } |
| 62 | 55 |
| 63 void PluginStreamUrl::DidReceiveData(const char* buffer, int length) { | 56 void PluginStreamUrl::DidReceiveData(const char* buffer, int length, |
| 57 int data_offset) { |
| 64 if (!open()) | 58 if (!open()) |
| 65 return; | 59 return; |
| 66 | 60 |
| 67 if (length > 0) | 61 if (length > 0) |
| 68 Write(const_cast<char*>(buffer), length); | 62 Write(const_cast<char*>(buffer), length, data_offset); |
| 69 } | 63 } |
| 70 | 64 |
| 71 void PluginStreamUrl::DidFinishLoading() { | 65 void PluginStreamUrl::DidFinishLoading() { |
| 72 Close(NPRES_DONE); | 66 if (!seekable()) { |
| 67 Close(NPRES_DONE); |
| 68 } |
| 73 } | 69 } |
| 74 | 70 |
| 75 void PluginStreamUrl::DidFail() { | 71 void PluginStreamUrl::DidFail() { |
| 76 Close(NPRES_NETWORK_ERR); | 72 Close(NPRES_NETWORK_ERR); |
| 77 } | 73 } |
| 78 | 74 |
| 75 void PluginStreamUrl::CancelRequest() { |
| 76 if (id_ > 0) { |
| 77 if (instance()->webplugin()) { |
| 78 instance()->webplugin()->CancelResource(id_); |
| 79 } |
| 80 id_ = 0; |
| 81 } |
| 82 } |
| 83 |
| 79 } // namespace NPAPI | 84 } // namespace NPAPI |
| 80 | 85 |
| OLD | NEW |