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 "webkit/plugins/npapi/plugin_instance.h" | 5 #include "webkit/plugins/npapi/plugin_instance.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 PluginInstance::~PluginInstance() { | 72 PluginInstance::~PluginInstance() { |
73 CloseStreams(); | 73 CloseStreams(); |
74 | 74 |
75 if (npp_ != 0) { | 75 if (npp_ != 0) { |
76 delete npp_; | 76 delete npp_; |
77 npp_ = 0; | 77 npp_ = 0; |
78 } | 78 } |
79 | 79 |
80 if (plugin_) | 80 if (plugin_.get()) |
81 plugin_->CloseInstance(); | 81 plugin_->CloseInstance(); |
82 } | 82 } |
83 | 83 |
84 PluginStreamUrl* PluginInstance::CreateStream(unsigned long resource_id, | 84 PluginStreamUrl* PluginInstance::CreateStream(unsigned long resource_id, |
85 const GURL& url, | 85 const GURL& url, |
86 const std::string& mime_type, | 86 const std::string& mime_type, |
87 int notify_id) { | 87 int notify_id) { |
88 | 88 |
89 bool notify; | 89 bool notify; |
90 void* notify_data; | 90 void* notify_data; |
91 GetNotifyData(notify_id, ¬ify, ¬ify_data); | 91 GetNotifyData(notify_id, ¬ify, ¬ify_data); |
92 PluginStreamUrl* stream = new PluginStreamUrl( | 92 PluginStreamUrl* stream = new PluginStreamUrl( |
93 resource_id, url, this, notify, notify_data); | 93 resource_id, url, this, notify, notify_data); |
94 | 94 |
95 AddStream(stream); | 95 AddStream(stream); |
96 return stream; | 96 return stream; |
97 } | 97 } |
98 | 98 |
99 void PluginInstance::AddStream(PluginStream* stream) { | 99 void PluginInstance::AddStream(PluginStream* stream) { |
100 open_streams_.push_back(make_scoped_refptr(stream)); | 100 open_streams_.push_back(make_scoped_refptr(stream)); |
101 } | 101 } |
102 | 102 |
103 void PluginInstance::RemoveStream(PluginStream* stream) { | 103 void PluginInstance::RemoveStream(PluginStream* stream) { |
104 if (in_close_streams_) | 104 if (in_close_streams_) |
105 return; | 105 return; |
106 | 106 |
107 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | 107 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; |
108 for (stream_index = open_streams_.begin(); | 108 for (stream_index = open_streams_.begin(); |
109 stream_index != open_streams_.end(); ++stream_index) { | 109 stream_index != open_streams_.end(); ++stream_index) { |
110 if (*stream_index == stream) { | 110 if (stream_index->get() == stream) { |
111 open_streams_.erase(stream_index); | 111 open_streams_.erase(stream_index); |
112 break; | 112 break; |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 bool PluginInstance::IsValidStream(const NPStream* stream) { | 117 bool PluginInstance::IsValidStream(const NPStream* stream) { |
118 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | 118 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; |
119 for (stream_index = open_streams_.begin(); | 119 for (stream_index = open_streams_.begin(); |
120 stream_index != open_streams_.end(); ++stream_index) { | 120 stream_index != open_streams_.end(); ++stream_index) { |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 while (range_list) { | 527 while (range_list) { |
528 range_info += base::IntToString(range_list->offset); | 528 range_info += base::IntToString(range_list->offset); |
529 range_info.push_back('-'); | 529 range_info.push_back('-'); |
530 range_info += | 530 range_info += |
531 base::IntToString(range_list->offset + range_list->length - 1); | 531 base::IntToString(range_list->offset + range_list->length - 1); |
532 range_list = range_list->next; | 532 range_list = range_list->next; |
533 if (range_list) | 533 if (range_list) |
534 range_info.push_back(','); | 534 range_info.push_back(','); |
535 } | 535 } |
536 | 536 |
537 if (plugin_data_stream_) { | 537 if (plugin_data_stream_.get()) { |
538 if (plugin_data_stream_->stream() == stream) { | 538 if (plugin_data_stream_->stream() == stream) { |
539 webplugin_->CancelDocumentLoad(); | 539 webplugin_->CancelDocumentLoad(); |
540 plugin_data_stream_ = NULL; | 540 plugin_data_stream_ = NULL; |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 // The lifetime of a NPStream instance depends on the PluginStream instance | 544 // The lifetime of a NPStream instance depends on the PluginStream instance |
545 // which owns it. When a plugin invokes NPN_RequestRead on a seekable stream, | 545 // which owns it. When a plugin invokes NPN_RequestRead on a seekable stream, |
546 // we don't want to create a new stream when the corresponding response is | 546 // we don't want to create a new stream when the corresponding response is |
547 // received. We send over a cookie which represents the PluginStream | 547 // received. We send over a cookie which represents the PluginStream |
548 // instance which is sent back from the renderer when the response is | 548 // instance which is sent back from the renderer when the response is |
549 // received. | 549 // received. |
550 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | 550 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; |
551 for (stream_index = open_streams_.begin(); | 551 for (stream_index = open_streams_.begin(); |
552 stream_index != open_streams_.end(); ++stream_index) { | 552 stream_index != open_streams_.end(); ++stream_index) { |
553 PluginStream* plugin_stream = *stream_index; | 553 PluginStream* plugin_stream = stream_index->get(); |
554 if (plugin_stream->stream() == stream) { | 554 if (plugin_stream->stream() == stream) { |
555 // A stream becomes seekable the first time NPN_RequestRead | 555 // A stream becomes seekable the first time NPN_RequestRead |
556 // is called on it. | 556 // is called on it. |
557 plugin_stream->set_seekable(true); | 557 plugin_stream->set_seekable(true); |
558 | 558 |
559 pending_range_requests_[++next_range_request_id_] = plugin_stream; | 559 pending_range_requests_[++next_range_request_id_] = plugin_stream; |
560 webplugin_->InitiateHTTPRangeRequest( | 560 webplugin_->InitiateHTTPRangeRequest( |
561 stream->url, range_info.c_str(), next_range_request_id_); | 561 stream->url, range_info.c_str(), next_range_request_id_); |
562 return; | 562 return; |
563 } | 563 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 *notify = false; | 664 *notify = false; |
665 *notify_data = NULL; | 665 *notify_data = NULL; |
666 } | 666 } |
667 } | 667 } |
668 | 668 |
669 void PluginInstance::URLRedirectResponse(bool allow, void* notify_data) { | 669 void PluginInstance::URLRedirectResponse(bool allow, void* notify_data) { |
670 // The notify_data passed in allows us to identify the matching stream. | 670 // The notify_data passed in allows us to identify the matching stream. |
671 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | 671 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; |
672 for (stream_index = open_streams_.begin(); | 672 for (stream_index = open_streams_.begin(); |
673 stream_index != open_streams_.end(); ++stream_index) { | 673 stream_index != open_streams_.end(); ++stream_index) { |
674 PluginStream* plugin_stream = *stream_index; | 674 PluginStream* plugin_stream = stream_index->get(); |
675 if (plugin_stream->notify_data() == notify_data) { | 675 if (plugin_stream->notify_data() == notify_data) { |
676 WebPluginResourceClient* resource_client = | 676 WebPluginResourceClient* resource_client = |
677 plugin_stream->AsResourceClient(); | 677 plugin_stream->AsResourceClient(); |
678 webplugin_->URLRedirectResponse(allow, resource_client->ResourceId()); | 678 webplugin_->URLRedirectResponse(allow, resource_client->ResourceId()); |
679 if (allow) { | 679 if (allow) { |
680 plugin_stream->UpdateUrl( | 680 plugin_stream->UpdateUrl( |
681 plugin_stream->pending_redirect_url().c_str()); | 681 plugin_stream->pending_redirect_url().c_str()); |
682 } | 682 } |
683 break; | 683 break; |
684 } | 684 } |
685 } | 685 } |
686 } | 686 } |
687 | 687 |
688 } // namespace npapi | 688 } // namespace npapi |
689 } // namespace webkit | 689 } // namespace webkit |
OLD | NEW |