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

Side by Side Diff: Source/web/WebPluginContainerImpl.cpp

Issue 603193005: Move the Widget hierarchy to the Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Support renderer-less plugin disposal Created 6 years, 2 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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2014 Opera Software ASA. All rights reserved. 3 * Copyright (C) 2014 Opera Software ASA. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 m_webPlugin->updateVisibility(false); 168 m_webPlugin->updateVisibility(false);
169 169
170 Widget::hide(); 170 Widget::hide();
171 } 171 }
172 172
173 void WebPluginContainerImpl::handleEvent(Event* event) 173 void WebPluginContainerImpl::handleEvent(Event* event)
174 { 174 {
175 if (!m_webPlugin->acceptsInputEvents()) 175 if (!m_webPlugin->acceptsInputEvents())
176 return; 176 return;
177 177
178 RefPtr<WebPluginContainerImpl> protector(this); 178 RefPtrWillBeRawPtr<WebPluginContainerImpl> protector(this);
179 // The events we pass are defined at: 179 // The events we pass are defined at:
180 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/struct ures5.html#1000000 180 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/struct ures5.html#1000000
181 // Don't take the documentation as truth, however. There are many cases 181 // Don't take the documentation as truth, however. There are many cases
182 // where mozilla behaves differently than the spec. 182 // where mozilla behaves differently than the spec.
183 if (event->isMouseEvent()) 183 if (event->isMouseEvent())
184 handleMouseEvent(toMouseEvent(event)); 184 handleMouseEvent(toMouseEvent(event));
185 else if (event->isWheelEvent()) 185 else if (event->isWheelEvent())
186 handleWheelEvent(toWheelEvent(event)); 186 handleWheelEvent(toWheelEvent(event));
187 else if (event->isKeyboardEvent()) 187 else if (event->isKeyboardEvent())
188 handleKeyboardEvent(toKeyboardEvent(event)); 188 handleKeyboardEvent(toKeyboardEvent(event));
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (!frame) 432 if (!frame)
433 return v8::Local<v8::Object>(); 433 return v8::Local<v8::Object>();
434 434
435 if (!frame->script().canExecuteScripts(NotAboutToExecuteScript)) 435 if (!frame->script().canExecuteScripts(NotAboutToExecuteScript))
436 return v8::Local<v8::Object>(); 436 return v8::Local<v8::Object>();
437 437
438 ScriptState* scriptState = ScriptState::forMainWorld(frame); 438 ScriptState* scriptState = ScriptState::forMainWorld(frame);
439 if (!scriptState->contextIsValid()) 439 if (!scriptState->contextIsValid())
440 return v8::Local<v8::Object>(); 440 return v8::Local<v8::Object>();
441 441
442 v8::Handle<v8::Value> v8value = toV8(m_element, scriptState->context()->Glob al(), scriptState->isolate()); 442 v8::Handle<v8::Value> v8value = toV8(m_element.get(), scriptState->context() ->Global(), scriptState->isolate());
443 ASSERT(v8value->IsObject()); 443 ASSERT(v8value->IsObject());
444 444
445 return v8::Handle<v8::Object>::Cast(v8value); 445 return v8::Handle<v8::Object>::Cast(v8value);
446 } 446 }
447 447
448 WebString WebPluginContainerImpl::executeScriptURL(const WebURL& url, bool popup sAllowed) 448 WebString WebPluginContainerImpl::executeScriptURL(const WebURL& url, bool popup sAllowed)
449 { 449 {
450 LocalFrame* frame = m_element->document().frame(); 450 LocalFrame* frame = m_element->document().frame();
451 if (!frame) 451 if (!frame)
452 return WebString(); 452 return WebString();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 context->setFillColor(Color(0xCC, 0xCC, 0xCC)); 667 context->setFillColor(Color(0xCC, 0xCC, 0xCC));
668 context->fillRect(intersection(horizontalOverhangArea, dirtyRect)); 668 context->fillRect(intersection(horizontalOverhangArea, dirtyRect));
669 context->fillRect(intersection(verticalOverhangArea, dirtyRect)); 669 context->fillRect(intersection(verticalOverhangArea, dirtyRect));
670 context->restore(); 670 context->restore();
671 return true; 671 return true;
672 } 672 }
673 673
674 // Private methods ------------------------------------------------------------- 674 // Private methods -------------------------------------------------------------
675 675
676 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element, WebPl ugin* webPlugin) 676 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element, WebPl ugin* webPlugin)
677 #if ENABLE(OILPAN)
678 : m_frame(element->document().frame())
679 #else
680 : FrameDestructionObserver(element->document().frame()) 677 : FrameDestructionObserver(element->document().frame())
681 #endif
682 , m_element(element) 678 , m_element(element)
683 , m_webPlugin(webPlugin) 679 , m_webPlugin(webPlugin)
684 , m_webLayer(0) 680 , m_webLayer(nullptr)
685 , m_touchEventRequestType(TouchEventRequestTypeNone) 681 , m_touchEventRequestType(TouchEventRequestTypeNone)
686 , m_wantsWheelEvents(false) 682 , m_wantsWheelEvents(false)
683 #if ENABLE(OILPAN)
684 , m_isAllowedToDisposePlugin(false)
685 #endif
687 { 686 {
688 } 687 }
689 688
690 WebPluginContainerImpl::~WebPluginContainerImpl() 689 WebPluginContainerImpl::~WebPluginContainerImpl()
691 { 690 {
692 #if ENABLE(OILPAN) 691 #if ENABLE(OILPAN)
693 // The element (and its document) are heap allocated and may 692 // The plugin container must have been disposed of already.
694 // have been finalized by now; unsafe to unregister the touch 693 if (m_isAllowedToDisposePlugin)
695 // event handler at this stage. 694 dispose();
696 // 695 ASSERT(!m_webPlugin);
697 // This is acceptable, as the widget will unregister itself if it
698 // is cleanly detached. If an explicit detach doesn't happen, this
699 // container is assumed to have died with the plugin element (and
700 // its document), hence no unregistration step is needed.
701 //
702 m_element = 0;
703 #else 696 #else
704 if (m_touchEventRequestType != TouchEventRequestTypeNone && m_element->docum ent().frameHost()) 697 dispose();
698 #endif
699 }
700
701 void WebPluginContainerImpl::dispose()
702 {
703 if (m_element && m_touchEventRequestType != TouchEventRequestTypeNone && m_e lement->document().frameHost())
705 m_element->document().frameHost()->eventHandlerRegistry().didRemoveEvent Handler(*m_element, EventHandlerRegistry::TouchEvent); 704 m_element->document().frameHost()->eventHandlerRegistry().didRemoveEvent Handler(*m_element, EventHandlerRegistry::TouchEvent);
706 #endif
707 705
708 ScriptForbiddenScope::AllowSuperUnsafeScript thisShouldBeRemoved; 706 ScriptForbiddenScope::AllowSuperUnsafeScript thisShouldBeRemoved;
709 707
710 for (size_t i = 0; i < m_pluginLoadObservers.size(); ++i) 708 for (size_t i = 0; i < m_pluginLoadObservers.size(); ++i)
711 m_pluginLoadObservers[i]->clearPluginContainer(); 709 m_pluginLoadObservers[i]->clearPluginContainer();
712 m_webPlugin->destroy(); 710 m_webPlugin->destroy();
711 m_webPlugin = nullptr;
712
713 if (m_webLayer) 713 if (m_webLayer)
714 GraphicsLayer::unregisterContentsLayer(m_webLayer); 714 GraphicsLayer::unregisterContentsLayer(m_webLayer);
715
716 m_pluginLoadObservers.clear();
717 m_scrollbarGroup.clear();
718 m_element = nullptr;
715 } 719 }
716 720
717 #if ENABLE(OILPAN) 721 #if ENABLE(OILPAN)
718 void WebPluginContainerImpl::detach() 722 void WebPluginContainerImpl::setIsAllowedToDisposePlugin()
719 { 723 {
720 if (m_touchEventRequestType != TouchEventRequestTypeNone && m_element->docum ent().frameHost()) 724 // If the LocalFrame is still alive, but the plugin element isn't, the
721 m_element->document().frameHost()->eventHandlerRegistry().didRemoveEvent Handler(*m_element, EventHandlerRegistry::TouchEvent); 725 // LocalFrame will set m_isAllowedToDisposePlugin via
722 726 // its weak pointer callback. This is a signal that the plugin container
723 setWebLayer(0); 727 // must dispose of its plugin when finalizing. The LocalFrame and
728 // all objects accessible from it can safely be accessed, but not
729 // the plugin element itself.
haraken 2014/10/10 02:50:32 Help me understand: 1) Why can't you simply call
sof 2014/10/10 05:22:19 Unbounded amounts of work and allocation might res
730 ASSERT(!m_isAllowedToDisposePlugin);
731 m_isAllowedToDisposePlugin = true;
732 m_element = nullptr;
724 } 733 }
725 #endif 734 #endif
726 735
736 void WebPluginContainerImpl::trace(Visitor* visitor)
737 {
738 visitor->trace(m_element);
739 FrameDestructionObserver::trace(visitor);
740 PluginView::trace(visitor);
741 }
742
727 void WebPluginContainerImpl::handleMouseEvent(MouseEvent* event) 743 void WebPluginContainerImpl::handleMouseEvent(MouseEvent* event)
728 { 744 {
729 ASSERT(parent()->isFrameView()); 745 ASSERT(parent()->isFrameView());
730 746
731 if (event->isDragEvent()) { 747 if (event->isDragEvent()) {
732 if (m_webPlugin->canProcessDrag()) 748 if (m_webPlugin->canProcessDrag())
733 handleDragEvent(event); 749 handleDragEvent(event);
734 return; 750 return;
735 } 751 }
736 752
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 978
963 return clipRect; 979 return clipRect;
964 } 980 }
965 981
966 bool WebPluginContainerImpl::pluginShouldPersist() const 982 bool WebPluginContainerImpl::pluginShouldPersist() const
967 { 983 {
968 return m_webPlugin->shouldPersist(); 984 return m_webPlugin->shouldPersist();
969 } 985 }
970 986
971 } // namespace blink 987 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698