| 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_impl.h" | 5 #include "content/renderer/npapi/webplugin_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 bool WebPluginImpl::initialize(WebPluginContainer* container) { | 92 bool WebPluginImpl::initialize(WebPluginContainer* container) { |
| 93 if (!render_view_.get()) { | 93 if (!render_view_.get()) { |
| 94 LOG(ERROR) << "No RenderView"; | 94 LOG(ERROR) << "No RenderView"; |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( | 98 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( |
| 99 this, mime_type_, render_view_, render_frame_); | 99 this, mime_type_, render_view_, render_frame_); |
| 100 | 100 |
| 101 // Store the plugin's unique identifier, used by the container to track its | |
| 102 // script objects. | |
| 103 npp_ = plugin_delegate->GetPluginNPP(); | |
| 104 | |
| 105 // Set the container before Initialize because the plugin may | 101 // Set the container before Initialize because the plugin may |
| 106 // synchronously call NPN_GetValue to get its container, or make calls | 102 // synchronously call NPN_GetValue to get its container, or make calls |
| 107 // passing script objects that need to be tracked, during initialization. | 103 // passing script objects that need to be tracked, during initialization. |
| 108 SetContainer(container); | 104 SetContainer(container); |
| 109 | 105 |
| 110 bool ok = plugin_delegate->Initialize( | 106 bool ok = plugin_delegate->Initialize( |
| 111 plugin_url_, arg_names_, arg_values_, load_manually_); | 107 plugin_url_, arg_names_, arg_values_, load_manually_); |
| 112 if (!ok) { | 108 if (!ok) { |
| 113 plugin_delegate->PluginDestroyed(); | 109 plugin_delegate->PluginDestroyed(); |
| 114 | 110 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 135 delegate_ = plugin_delegate; | 131 delegate_ = plugin_delegate; |
| 136 | 132 |
| 137 return true; | 133 return true; |
| 138 } | 134 } |
| 139 | 135 |
| 140 void WebPluginImpl::destroy() { | 136 void WebPluginImpl::destroy() { |
| 141 SetContainer(NULL); | 137 SetContainer(NULL); |
| 142 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 138 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 143 } | 139 } |
| 144 | 140 |
| 145 NPObject* WebPluginImpl::scriptableObject() { | |
| 146 if (!delegate_) | |
| 147 return NULL; | |
| 148 | |
| 149 return delegate_->GetPluginScriptableObject(); | |
| 150 } | |
| 151 | |
| 152 NPP WebPluginImpl::pluginNPP() { | |
| 153 return npp_; | |
| 154 } | |
| 155 | |
| 156 bool WebPluginImpl::getFormValue(blink::WebString& value) { | 141 bool WebPluginImpl::getFormValue(blink::WebString& value) { |
| 157 if (!delegate_) | 142 if (!delegate_) |
| 158 return false; | 143 return false; |
| 159 base::string16 form_value; | 144 base::string16 form_value; |
| 160 if (!delegate_->GetFormValue(&form_value)) | 145 if (!delegate_->GetFormValue(&form_value)) |
| 161 return false; | 146 return false; |
| 162 value = form_value; | 147 value = form_value; |
| 163 return true; | 148 return true; |
| 164 } | 149 } |
| 165 | 150 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 WebFrame* webframe, | 248 WebFrame* webframe, |
| 264 const WebPluginParams& params, | 249 const WebPluginParams& params, |
| 265 const base::FilePath& file_path, | 250 const base::FilePath& file_path, |
| 266 const base::WeakPtr<RenderViewImpl>& render_view, | 251 const base::WeakPtr<RenderViewImpl>& render_view, |
| 267 RenderFrameImpl* render_frame) | 252 RenderFrameImpl* render_frame) |
| 268 : render_frame_(render_frame), | 253 : render_frame_(render_frame), |
| 269 render_view_(render_view), | 254 render_view_(render_view), |
| 270 webframe_(webframe), | 255 webframe_(webframe), |
| 271 delegate_(NULL), | 256 delegate_(NULL), |
| 272 container_(NULL), | 257 container_(NULL), |
| 273 npp_(NULL), | |
| 274 plugin_url_(params.url), | 258 plugin_url_(params.url), |
| 275 load_manually_(params.loadManually), | 259 load_manually_(params.loadManually), |
| 276 first_geometry_update_(true), | 260 first_geometry_update_(true), |
| 277 ignore_response_error_(false), | 261 ignore_response_error_(false), |
| 278 file_path_(file_path), | 262 file_path_(file_path), |
| 279 mime_type_(base::ToLowerASCII(base::UTF16ToASCII( | 263 mime_type_(base::ToLowerASCII(base::UTF16ToASCII( |
| 280 base::StringPiece16(params.mimeType)))) { | 264 base::StringPiece16(params.mimeType)))) { |
| 281 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | 265 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); |
| 282 | 266 |
| 283 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | 267 for (size_t i = 0; i < params.attributeNames.size(); ++i) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 // to recover at this point. Break out. | 408 // to recover at this point. Break out. |
| 425 NOTREACHED(); | 409 NOTREACHED(); |
| 426 return ROUTED; | 410 return ROUTED; |
| 427 } | 411 } |
| 428 } | 412 } |
| 429 | 413 |
| 430 container_->loadFrameRequest(request, target_str); | 414 container_->loadFrameRequest(request, target_str); |
| 431 return ROUTED; | 415 return ROUTED; |
| 432 } | 416 } |
| 433 | 417 |
| 434 NPObject* WebPluginImpl::GetWindowScriptNPObject() { | |
| 435 if (!webframe_) { | |
| 436 NOTREACHED(); | |
| 437 return NULL; | |
| 438 } | |
| 439 return webframe_->windowObject(); | |
| 440 } | |
| 441 | |
| 442 NPObject* WebPluginImpl::GetPluginElement() { | |
| 443 return container_->scriptableObjectForElement(); | |
| 444 } | |
| 445 | |
| 446 bool WebPluginImpl::FindProxyForUrl(const GURL& url, std::string* proxy_list) { | 418 bool WebPluginImpl::FindProxyForUrl(const GURL& url, std::string* proxy_list) { |
| 447 // Proxy resolving doesn't work in single-process mode. | 419 // Proxy resolving doesn't work in single-process mode. |
| 448 return false; | 420 return false; |
| 449 } | 421 } |
| 450 | 422 |
| 451 void WebPluginImpl::SetCookie(const GURL& url, | 423 void WebPluginImpl::SetCookie(const GURL& url, |
| 452 const GURL& first_party_for_cookies, | 424 const GURL& first_party_for_cookies, |
| 453 const std::string& cookie) { | 425 const std::string& cookie) { |
| 454 if (!render_view_.get()) | 426 if (!render_view_.get()) |
| 455 return; | 427 return; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 509 |
| 538 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) { | 510 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) { |
| 539 if (container_) | 511 if (container_) |
| 540 container_->invalidateRect(rect); | 512 container_->invalidateRect(rect); |
| 541 } | 513 } |
| 542 | 514 |
| 543 void WebPluginImpl::SetContainer(WebPluginContainer* container) { | 515 void WebPluginImpl::SetContainer(WebPluginContainer* container) { |
| 544 if (!container) | 516 if (!container) |
| 545 TearDownPluginInstance(NULL); | 517 TearDownPluginInstance(NULL); |
| 546 container_ = container; | 518 container_ = container; |
| 547 if (container_) | |
| 548 container_->allowScriptObjects(); | |
| 549 } | 519 } |
| 550 | 520 |
| 551 unsigned long WebPluginImpl::GetNextResourceId() { | 521 unsigned long WebPluginImpl::GetNextResourceId() { |
| 552 if (!webframe_) | 522 if (!webframe_) |
| 553 return 0; | 523 return 0; |
| 554 WebView* view = webframe_->view(); | 524 WebView* view = webframe_->view(); |
| 555 if (!view) | 525 if (!view) |
| 556 return 0; | 526 return 0; |
| 557 return view->createUniqueIdentifierForRequest(); | 527 return view->createUniqueIdentifierForRequest(); |
| 558 } | 528 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 566 |
| 597 // Destroy the current plugin instance. | 567 // Destroy the current plugin instance. |
| 598 TearDownPluginInstance(loader); | 568 TearDownPluginInstance(loader); |
| 599 | 569 |
| 600 container_ = container_widget; | 570 container_ = container_widget; |
| 601 webframe_ = webframe; | 571 webframe_ = webframe; |
| 602 | 572 |
| 603 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( | 573 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( |
| 604 this, mime_type_, render_view_, render_frame_); | 574 this, mime_type_, render_view_, render_frame_); |
| 605 | 575 |
| 606 // Store the plugin's unique identifier, used by the container to track its | |
| 607 // script objects, and enable script objects (since Initialize may use them | |
| 608 // even if it fails). | |
| 609 npp_ = plugin_delegate->GetPluginNPP(); | |
| 610 container_->allowScriptObjects(); | |
| 611 | |
| 612 bool ok = plugin_delegate && plugin_delegate->Initialize( | 576 bool ok = plugin_delegate && plugin_delegate->Initialize( |
| 613 plugin_url_, arg_names_, arg_values_, load_manually_); | 577 plugin_url_, arg_names_, arg_values_, load_manually_); |
| 614 | 578 |
| 615 if (!ok) { | 579 if (!ok) { |
| 616 container_->clearScriptObjects(); | |
| 617 container_ = NULL; | 580 container_ = NULL; |
| 618 // TODO(iyengar) Should we delete the current plugin instance here? | 581 // TODO(iyengar) Should we delete the current plugin instance here? |
| 619 return false; | 582 return false; |
| 620 } | 583 } |
| 621 | 584 |
| 622 delegate_ = plugin_delegate; | 585 delegate_ = plugin_delegate; |
| 623 | 586 |
| 624 // Force a geometry update to occur to ensure that the plugin becomes | 587 // Force a geometry update to occur to ensure that the plugin becomes |
| 625 // visible. | 588 // visible. |
| 626 container_->reportGeometry(); | 589 container_->reportGeometry(); |
| 627 | 590 |
| 628 // The plugin move sequences accumulated via DidMove are sent to the browser | 591 // The plugin move sequences accumulated via DidMove are sent to the browser |
| 629 // whenever the renderer paints. Force a paint here to ensure that changes | 592 // whenever the renderer paints. Force a paint here to ensure that changes |
| 630 // to the plugin window are propagated to the browser. | 593 // to the plugin window are propagated to the browser. |
| 631 container_->invalidate(); | 594 container_->invalidate(); |
| 632 return true; | 595 return true; |
| 633 } | 596 } |
| 634 | 597 |
| 635 void WebPluginImpl::TearDownPluginInstance( | 598 void WebPluginImpl::TearDownPluginInstance( |
| 636 WebURLLoader* loader_to_ignore) { | 599 WebURLLoader* loader_to_ignore) { |
| 637 // JavaScript garbage collection may cause plugin script object references to | 600 // JavaScript garbage collection may cause plugin script object references to |
| 638 // be retained long after the plugin is destroyed. Some plugins won't cope | 601 // be retained long after the plugin is destroyed. Some plugins won't cope |
| 639 // with their objects being released after they've been destroyed, and once | 602 // with their objects being released after they've been destroyed, and once |
| 640 // we've actually unloaded the plugin the object's releaseobject() code may | 603 // we've actually unloaded the plugin the object's releaseobject() code may |
| 641 // no longer be in memory. The container tracks the plugin's objects and lets | 604 // no longer be in memory. The container tracks the plugin's objects and lets |
| 642 // us invalidate them, releasing the references to them held by the JavaScript | 605 // us invalidate them, releasing the references to them held by the JavaScript |
| 643 // runtime. | 606 // runtime. |
| 644 if (container_) { | 607 if (container_) { |
| 645 container_->clearScriptObjects(); | |
| 646 container_->setWebLayer(NULL); | 608 container_->setWebLayer(NULL); |
| 647 } | 609 } |
| 648 | 610 |
| 649 // Call PluginDestroyed() first to prevent the plugin from calling us back | 611 // Call PluginDestroyed() first to prevent the plugin from calling us back |
| 650 // in the middle of tearing down the render tree. | 612 // in the middle of tearing down the render tree. |
| 651 if (delegate_) { | 613 if (delegate_) { |
| 652 // The plugin may call into the browser and pass script objects even during | 614 // The plugin may call into the browser and pass script objects even during |
| 653 // teardown, so temporarily re-enable plugin script objects. | 615 // teardown, so temporarily re-enable plugin script objects. |
| 654 DCHECK(container_); | 616 DCHECK(container_); |
| 655 container_->allowScriptObjects(); | |
| 656 | 617 |
| 657 delegate_->PluginDestroyed(); | 618 delegate_->PluginDestroyed(); |
| 658 delegate_ = NULL; | 619 delegate_ = NULL; |
| 659 | |
| 660 // Invalidate any script objects created during teardown here, before the | |
| 661 // plugin might actually be unloaded. | |
| 662 container_->clearScriptObjects(); | |
| 663 } | 620 } |
| 664 | 621 |
| 665 // This needs to be called now and not in the destructor since the | 622 // This needs to be called now and not in the destructor since the |
| 666 // webframe_ might not be valid anymore. | 623 // webframe_ might not be valid anymore. |
| 667 webframe_ = NULL; | 624 webframe_ = NULL; |
| 668 } | 625 } |
| 669 | 626 |
| 670 void WebPluginImpl::SetReferrer(blink::WebURLRequest* request, | 627 void WebPluginImpl::SetReferrer(blink::WebURLRequest* request, |
| 671 ReferrerValue referrer_flag) { | 628 ReferrerValue referrer_flag) { |
| 672 switch (referrer_flag) { | 629 switch (referrer_flag) { |
| 673 case DOCUMENT_URL: | 630 case DOCUMENT_URL: |
| 674 webframe_->setReferrerForRequest(*request, GURL()); | 631 webframe_->setReferrerForRequest(*request, GURL()); |
| 675 break; | 632 break; |
| 676 | 633 |
| 677 case PLUGIN_SRC: | 634 case PLUGIN_SRC: |
| 678 webframe_->setReferrerForRequest(*request, plugin_url_); | 635 webframe_->setReferrerForRequest(*request, plugin_url_); |
| 679 break; | 636 break; |
| 680 | 637 |
| 681 default: | 638 default: |
| 682 break; | 639 break; |
| 683 } | 640 } |
| 684 } | 641 } |
| 685 | 642 |
| 686 } // namespace content | 643 } // namespace content |
| OLD | NEW |