Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: content/renderer/npapi/webplugin_impl.cc

Issue 1483733002: Remove support for NPObjects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 25 matching lines...) Expand all
140 delegate_ = plugin_delegate; 136 delegate_ = plugin_delegate;
141 137
142 return true; 138 return true;
143 } 139 }
144 140
145 void WebPluginImpl::destroy() { 141 void WebPluginImpl::destroy() {
146 SetContainer(NULL); 142 SetContainer(NULL);
147 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 143 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
148 } 144 }
149 145
150 NPObject* WebPluginImpl::scriptableObject() {
151 if (!delegate_)
152 return NULL;
153
154 return delegate_->GetPluginScriptableObject();
155 }
156
157 NPP WebPluginImpl::pluginNPP() {
158 return npp_;
159 }
160
161 bool WebPluginImpl::getFormValue(blink::WebString& value) { 146 bool WebPluginImpl::getFormValue(blink::WebString& value) {
162 if (!delegate_) 147 if (!delegate_)
163 return false; 148 return false;
164 base::string16 form_value; 149 base::string16 form_value;
165 if (!delegate_->GetFormValue(&form_value)) 150 if (!delegate_->GetFormValue(&form_value))
166 return false; 151 return false;
167 value = form_value; 152 value = form_value;
168 return true; 153 return true;
169 } 154 }
170 155
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 WebFrame* webframe, 253 WebFrame* webframe,
269 const WebPluginParams& params, 254 const WebPluginParams& params,
270 const base::FilePath& file_path, 255 const base::FilePath& file_path,
271 const base::WeakPtr<RenderViewImpl>& render_view, 256 const base::WeakPtr<RenderViewImpl>& render_view,
272 RenderFrameImpl* render_frame) 257 RenderFrameImpl* render_frame)
273 : render_frame_(render_frame), 258 : render_frame_(render_frame),
274 render_view_(render_view), 259 render_view_(render_view),
275 webframe_(webframe), 260 webframe_(webframe),
276 delegate_(NULL), 261 delegate_(NULL),
277 container_(NULL), 262 container_(NULL),
278 npp_(NULL),
279 plugin_url_(params.url), 263 plugin_url_(params.url),
280 load_manually_(params.loadManually), 264 load_manually_(params.loadManually),
281 first_geometry_update_(true), 265 first_geometry_update_(true),
282 ignore_response_error_(false), 266 ignore_response_error_(false),
283 file_path_(file_path), 267 file_path_(file_path),
284 mime_type_(base::ToLowerASCII(base::UTF16ToASCII( 268 mime_type_(base::ToLowerASCII(base::UTF16ToASCII(
285 base::StringPiece16(params.mimeType)))) { 269 base::StringPiece16(params.mimeType)))) {
286 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); 270 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
287 271
288 for (size_t i = 0; i < params.attributeNames.size(); ++i) { 272 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // to recover at this point. Break out. 413 // to recover at this point. Break out.
430 NOTREACHED(); 414 NOTREACHED();
431 return ROUTED; 415 return ROUTED;
432 } 416 }
433 } 417 }
434 418
435 container_->loadFrameRequest(request, target_str); 419 container_->loadFrameRequest(request, target_str);
436 return ROUTED; 420 return ROUTED;
437 } 421 }
438 422
439 NPObject* WebPluginImpl::GetWindowScriptNPObject() {
440 if (!webframe_) {
441 NOTREACHED();
442 return NULL;
443 }
444 return webframe_->windowObject();
445 }
446
447 NPObject* WebPluginImpl::GetPluginElement() {
448 return container_->scriptableObjectForElement();
449 }
450
451 bool WebPluginImpl::FindProxyForUrl(const GURL& url, std::string* proxy_list) { 423 bool WebPluginImpl::FindProxyForUrl(const GURL& url, std::string* proxy_list) {
452 // Proxy resolving doesn't work in single-process mode. 424 // Proxy resolving doesn't work in single-process mode.
453 return false; 425 return false;
454 } 426 }
455 427
456 void WebPluginImpl::SetCookie(const GURL& url, 428 void WebPluginImpl::SetCookie(const GURL& url,
457 const GURL& first_party_for_cookies, 429 const GURL& first_party_for_cookies,
458 const std::string& cookie) { 430 const std::string& cookie) {
459 if (!render_view_.get()) 431 if (!render_view_.get())
460 return; 432 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 514
543 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) { 515 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) {
544 if (container_) 516 if (container_)
545 container_->invalidateRect(rect); 517 container_->invalidateRect(rect);
546 } 518 }
547 519
548 void WebPluginImpl::SetContainer(WebPluginContainer* container) { 520 void WebPluginImpl::SetContainer(WebPluginContainer* container) {
549 if (!container) 521 if (!container)
550 TearDownPluginInstance(NULL); 522 TearDownPluginInstance(NULL);
551 container_ = container; 523 container_ = container;
552 if (container_)
553 container_->allowScriptObjects();
554 } 524 }
555 525
556 unsigned long WebPluginImpl::GetNextResourceId() { 526 unsigned long WebPluginImpl::GetNextResourceId() {
557 if (!webframe_) 527 if (!webframe_)
558 return 0; 528 return 0;
559 WebView* view = webframe_->view(); 529 WebView* view = webframe_->view();
560 if (!view) 530 if (!view)
561 return 0; 531 return 0;
562 return view->createUniqueIdentifierForRequest(); 532 return view->createUniqueIdentifierForRequest();
563 } 533 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 571
602 // Destroy the current plugin instance. 572 // Destroy the current plugin instance.
603 TearDownPluginInstance(loader); 573 TearDownPluginInstance(loader);
604 574
605 container_ = container_widget; 575 container_ = container_widget;
606 webframe_ = webframe; 576 webframe_ = webframe;
607 577
608 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( 578 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy(
609 this, mime_type_, render_view_, render_frame_); 579 this, mime_type_, render_view_, render_frame_);
610 580
611 // Store the plugin's unique identifier, used by the container to track its
612 // script objects, and enable script objects (since Initialize may use them
613 // even if it fails).
614 npp_ = plugin_delegate->GetPluginNPP();
615 container_->allowScriptObjects();
616
617 bool ok = plugin_delegate && plugin_delegate->Initialize( 581 bool ok = plugin_delegate && plugin_delegate->Initialize(
618 plugin_url_, arg_names_, arg_values_, load_manually_); 582 plugin_url_, arg_names_, arg_values_, load_manually_);
619 583
620 if (!ok) { 584 if (!ok) {
621 container_->clearScriptObjects();
622 container_ = NULL; 585 container_ = NULL;
623 // TODO(iyengar) Should we delete the current plugin instance here? 586 // TODO(iyengar) Should we delete the current plugin instance here?
624 return false; 587 return false;
625 } 588 }
626 589
627 delegate_ = plugin_delegate; 590 delegate_ = plugin_delegate;
628 591
629 // Force a geometry update to occur to ensure that the plugin becomes 592 // Force a geometry update to occur to ensure that the plugin becomes
630 // visible. 593 // visible.
631 container_->reportGeometry(); 594 container_->reportGeometry();
632 595
633 // The plugin move sequences accumulated via DidMove are sent to the browser 596 // The plugin move sequences accumulated via DidMove are sent to the browser
634 // whenever the renderer paints. Force a paint here to ensure that changes 597 // whenever the renderer paints. Force a paint here to ensure that changes
635 // to the plugin window are propagated to the browser. 598 // to the plugin window are propagated to the browser.
636 container_->invalidate(); 599 container_->invalidate();
637 return true; 600 return true;
638 } 601 }
639 602
640 void WebPluginImpl::TearDownPluginInstance( 603 void WebPluginImpl::TearDownPluginInstance(
641 WebURLLoader* loader_to_ignore) { 604 WebURLLoader* loader_to_ignore) {
642 // JavaScript garbage collection may cause plugin script object references to 605 // JavaScript garbage collection may cause plugin script object references to
643 // be retained long after the plugin is destroyed. Some plugins won't cope 606 // be retained long after the plugin is destroyed. Some plugins won't cope
644 // with their objects being released after they've been destroyed, and once 607 // with their objects being released after they've been destroyed, and once
645 // we've actually unloaded the plugin the object's releaseobject() code may 608 // we've actually unloaded the plugin the object's releaseobject() code may
646 // no longer be in memory. The container tracks the plugin's objects and lets 609 // no longer be in memory. The container tracks the plugin's objects and lets
647 // us invalidate them, releasing the references to them held by the JavaScript 610 // us invalidate them, releasing the references to them held by the JavaScript
648 // runtime. 611 // runtime.
649 if (container_) { 612 if (container_) {
650 container_->clearScriptObjects();
651 container_->setWebLayer(NULL); 613 container_->setWebLayer(NULL);
652 } 614 }
653 615
654 // Call PluginDestroyed() first to prevent the plugin from calling us back 616 // Call PluginDestroyed() first to prevent the plugin from calling us back
655 // in the middle of tearing down the render tree. 617 // in the middle of tearing down the render tree.
656 if (delegate_) { 618 if (delegate_) {
657 // The plugin may call into the browser and pass script objects even during 619 // The plugin may call into the browser and pass script objects even during
658 // teardown, so temporarily re-enable plugin script objects. 620 // teardown, so temporarily re-enable plugin script objects.
659 DCHECK(container_); 621 DCHECK(container_);
660 container_->allowScriptObjects();
661 622
662 delegate_->PluginDestroyed(); 623 delegate_->PluginDestroyed();
663 delegate_ = NULL; 624 delegate_ = NULL;
664
665 // Invalidate any script objects created during teardown here, before the
666 // plugin might actually be unloaded.
667 container_->clearScriptObjects();
668 } 625 }
669 626
670 // This needs to be called now and not in the destructor since the 627 // This needs to be called now and not in the destructor since the
671 // webframe_ might not be valid anymore. 628 // webframe_ might not be valid anymore.
672 webframe_ = NULL; 629 webframe_ = NULL;
673 } 630 }
674 631
675 void WebPluginImpl::SetReferrer(blink::WebURLRequest* request, 632 void WebPluginImpl::SetReferrer(blink::WebURLRequest* request,
676 ReferrerValue referrer_flag) { 633 ReferrerValue referrer_flag) {
677 switch (referrer_flag) { 634 switch (referrer_flag) {
678 case DOCUMENT_URL: 635 case DOCUMENT_URL:
679 webframe_->setReferrerForRequest(*request, GURL()); 636 webframe_->setReferrerForRequest(*request, GURL());
680 break; 637 break;
681 638
682 case PLUGIN_SRC: 639 case PLUGIN_SRC:
683 webframe_->setReferrerForRequest(*request, plugin_url_); 640 webframe_->setReferrerForRequest(*request, plugin_url_);
684 break; 641 break;
685 642
686 default: 643 default:
687 break; 644 break;
688 } 645 }
689 } 646 }
690 647
691 } // namespace content 648 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/npapi/webplugin_impl.h ('k') | content/renderer/pepper/host_var_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698