| 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 #include "webkit/glue/plugins/plugin_instance.h" | 5 #include "webkit/glue/plugins/plugin_instance.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/thread_local_storage.h" | 9 #include "base/thread_local_storage.h" |
| 10 #include "webkit/glue/glue_util.h" | 10 #include "webkit/glue/glue_util.h" |
| 11 #include "webkit/glue/webplugin.h" | 11 #include "webkit/glue/webplugin.h" |
| 12 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
| 13 #include "webkit/glue/plugins/plugin_data_stream.h" | |
| 14 #include "webkit/glue/plugins/plugin_host.h" | 13 #include "webkit/glue/plugins/plugin_host.h" |
| 15 #include "webkit/glue/plugins/plugin_lib.h" | 14 #include "webkit/glue/plugins/plugin_lib.h" |
| 16 #include "webkit/glue/plugins/plugin_stream_url.h" | 15 #include "webkit/glue/plugins/plugin_stream_url.h" |
| 17 #include "webkit/glue/plugins/plugin_string_stream.h" | 16 #include "webkit/glue/plugins/plugin_string_stream.h" |
| 18 #include "webkit/glue/plugins/mozilla_extensions.h" | 17 #include "webkit/glue/plugins/mozilla_extensions.h" |
| 19 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
| 20 | 19 |
| 21 namespace NPAPI | 20 namespace NPAPI |
| 22 { | 21 { |
| 23 | 22 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void PluginInstance::AddStream(PluginStream* stream) { | 85 void PluginInstance::AddStream(PluginStream* stream) { |
| 87 open_streams_.push_back(stream); | 86 open_streams_.push_back(stream); |
| 88 } | 87 } |
| 89 | 88 |
| 90 void PluginInstance::RemoveStream(PluginStream* stream) { | 89 void PluginInstance::RemoveStream(PluginStream* stream) { |
| 91 if (in_close_streams_) | 90 if (in_close_streams_) |
| 92 return; | 91 return; |
| 93 | 92 |
| 94 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | 93 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; |
| 95 for (stream_index = open_streams_.begin(); | 94 for (stream_index = open_streams_.begin(); |
| 96 stream_index != open_streams_.end(); ++stream_index) { | 95 stream_index != open_streams_.end(); ++stream_index) { |
| 97 if (*stream_index == stream) { | 96 if (*stream_index == stream) { |
| 98 open_streams_.erase(stream_index); | 97 open_streams_.erase(stream_index); |
| 99 break; | 98 break; |
| 100 } | 99 } |
| 101 } | 100 } |
| 102 } | 101 } |
| 103 | 102 |
| 104 bool PluginInstance::IsValidStream(const NPStream* stream) { | 103 bool PluginInstance::IsValidStream(const NPStream* stream) { |
| 105 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | 104 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; |
| 106 for (stream_index = open_streams_.begin(); | 105 for (stream_index = open_streams_.begin(); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 const std::string& mime_type, | 348 const std::string& mime_type, |
| 350 const std::string& headers, | 349 const std::string& headers, |
| 351 uint32 expected_length, | 350 uint32 expected_length, |
| 352 uint32 last_modified) { | 351 uint32 last_modified) { |
| 353 DCHECK(load_manually_); | 352 DCHECK(load_manually_); |
| 354 std::string response_url = url; | 353 std::string response_url = url; |
| 355 if (response_url.empty()) { | 354 if (response_url.empty()) { |
| 356 response_url = instance_url_.spec(); | 355 response_url = instance_url_.spec(); |
| 357 } | 356 } |
| 358 | 357 |
| 359 plugin_data_stream_ = new PluginDataStream(this, response_url, mime_type, | 358 bool cancel = false; |
| 360 headers, expected_length, | 359 |
| 361 last_modified); | 360 plugin_data_stream_ = CreateStream(-1, url, mime_type, false, NULL); |
| 361 |
| 362 plugin_data_stream_->DidReceiveResponse(mime_type, headers, expected_length, |
| 363 last_modified, &cancel); |
| 362 AddStream(plugin_data_stream_.get()); | 364 AddStream(plugin_data_stream_.get()); |
| 363 } | 365 } |
| 364 | 366 |
| 365 void PluginInstance::DidReceiveManualData(const char* buffer, int length) { | 367 void PluginInstance::DidReceiveManualData(const char* buffer, int length) { |
| 366 DCHECK(load_manually_); | 368 DCHECK(load_manually_); |
| 367 DCHECK(plugin_data_stream_.get() != NULL); | 369 if (plugin_data_stream_.get() != NULL) { |
| 368 plugin_data_stream_->SendToPlugin(buffer, length); | 370 plugin_data_stream_->DidReceiveData(buffer, length, 0); |
| 371 } |
| 369 } | 372 } |
| 370 | 373 |
| 371 void PluginInstance::DidFinishManualLoading() { | 374 void PluginInstance::DidFinishManualLoading() { |
| 372 DCHECK(load_manually_); | 375 DCHECK(load_manually_); |
| 373 DCHECK(plugin_data_stream_); | 376 if (plugin_data_stream_.get() != NULL) { |
| 374 plugin_data_stream_->Close(NPRES_DONE); | 377 plugin_data_stream_->DidFinishLoading(); |
| 375 RemoveStream(plugin_data_stream_.get()); | 378 plugin_data_stream_->Close(NPRES_DONE); |
| 376 plugin_data_stream_ = NULL; | 379 plugin_data_stream_ = NULL; |
| 380 } |
| 377 } | 381 } |
| 378 | 382 |
| 379 void PluginInstance::DidManualLoadFail() { | 383 void PluginInstance::DidManualLoadFail() { |
| 380 DCHECK(load_manually_); | 384 DCHECK(load_manually_); |
| 381 DCHECK(plugin_data_stream_); | 385 if (plugin_data_stream_.get() != NULL) { |
| 382 plugin_data_stream_->Close(NPRES_NETWORK_ERR); | 386 plugin_data_stream_->DidFail(); |
| 383 RemoveStream(plugin_data_stream_.get()); | 387 plugin_data_stream_ = NULL; |
| 384 plugin_data_stream_ = NULL; | 388 } |
| 385 } | 389 } |
| 386 | 390 |
| 387 void PluginInstance::PluginThreadAsyncCall(void (*func)(void *), | 391 void PluginInstance::PluginThreadAsyncCall(void (*func)(void *), |
| 388 void *userData) { | 392 void *userData) { |
| 389 message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 393 message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 390 this, &PluginInstance::OnPluginThreadAsyncCall, func, userData)); | 394 this, &PluginInstance::OnPluginThreadAsyncCall, func, userData)); |
| 391 } | 395 } |
| 392 | 396 |
| 393 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void *), | 397 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void *), |
| 394 void *userData) { | 398 void *userData) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 433 } |
| 430 | 434 |
| 431 void PluginInstance::PushPopupsEnabledState(bool enabled) { | 435 void PluginInstance::PushPopupsEnabledState(bool enabled) { |
| 432 popups_enabled_stack_.push(enabled); | 436 popups_enabled_stack_.push(enabled); |
| 433 } | 437 } |
| 434 | 438 |
| 435 void PluginInstance::PopPopupsEnabledState() { | 439 void PluginInstance::PopPopupsEnabledState() { |
| 436 popups_enabled_stack_.pop(); | 440 popups_enabled_stack_.pop(); |
| 437 } | 441 } |
| 438 | 442 |
| 443 void PluginInstance::RequestRead(NPStream* stream, NPByteRange* range_list) { |
| 444 std::string range_info = "bytes="; |
| 445 |
| 446 while (range_list) { |
| 447 range_info += IntToString(range_list->offset); |
| 448 range_info += "-"; |
| 449 range_info += IntToString(range_list->offset + range_list->length - 1); |
| 450 range_list = range_list->next; |
| 451 if (range_list) { |
| 452 range_info += ","; |
| 453 } |
| 454 } |
| 455 |
| 456 if (plugin_data_stream_) { |
| 457 if (plugin_data_stream_->stream() == stream) { |
| 458 webplugin_->CancelDocumentLoad(); |
| 459 plugin_data_stream_ = NULL; |
| 460 } |
| 461 } |
| 462 |
| 463 // The lifetime of a NPStream instance depends on the PluginStream instance |
| 464 // which owns it. When a plugin invokes NPN_RequestRead on a seekable stream, |
| 465 // we don't want to create a new stream when the corresponding response is |
| 466 // received. We send over a cookie which represents the PluginStream |
| 467 // instance which is sent back from the renderer when the response is |
| 468 // received. |
| 469 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; |
| 470 for (stream_index = open_streams_.begin(); |
| 471 stream_index != open_streams_.end(); ++stream_index) { |
| 472 PluginStream* plugin_stream = *stream_index; |
| 473 if (plugin_stream->stream() == stream) { |
| 474 // A stream becomes seekable the first time NPN_RequestRead |
| 475 // is called on it. |
| 476 plugin_stream->set_seekable(true); |
| 477 |
| 478 webplugin_->InitiateHTTPRangeRequest( |
| 479 stream->url, range_info.c_str(), |
| 480 plugin_stream, |
| 481 plugin_stream->notify_needed(), |
| 482 plugin_stream->notify_data()); |
| 483 break; |
| 484 } |
| 485 } |
| 486 } |
| 487 |
| 439 } // namespace NPAPI | 488 } // namespace NPAPI |
| 440 | 489 |
| OLD | NEW |