OLD | NEW |
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 m_webPlugin->updateVisibility(false); | 167 m_webPlugin->updateVisibility(false); |
168 | 168 |
169 Widget::hide(); | 169 Widget::hide(); |
170 } | 170 } |
171 | 171 |
172 void WebPluginContainerImpl::handleEvent(Event* event) | 172 void WebPluginContainerImpl::handleEvent(Event* event) |
173 { | 173 { |
174 if (!m_webPlugin->acceptsInputEvents()) | 174 if (!m_webPlugin->acceptsInputEvents()) |
175 return; | 175 return; |
176 | 176 |
177 RefPtr<WebPluginContainerImpl> protector(this); | 177 RefPtrWillBeRawPtr<WebPluginContainerImpl> protector(this); |
178 // The events we pass are defined at: | 178 // The events we pass are defined at: |
179 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/struct
ures5.html#1000000 | 179 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/struct
ures5.html#1000000 |
180 // Don't take the documentation as truth, however. There are many cases | 180 // Don't take the documentation as truth, however. There are many cases |
181 // where mozilla behaves differently than the spec. | 181 // where mozilla behaves differently than the spec. |
182 if (event->isMouseEvent()) | 182 if (event->isMouseEvent()) |
183 handleMouseEvent(toMouseEvent(event)); | 183 handleMouseEvent(toMouseEvent(event)); |
184 else if (event->isWheelEvent()) | 184 else if (event->isWheelEvent()) |
185 handleWheelEvent(toWheelEvent(event)); | 185 handleWheelEvent(toWheelEvent(event)); |
186 else if (event->isKeyboardEvent()) | 186 else if (event->isKeyboardEvent()) |
187 handleKeyboardEvent(toKeyboardEvent(event)); | 187 handleKeyboardEvent(toKeyboardEvent(event)); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 if (!frame) | 431 if (!frame) |
432 return v8::Local<v8::Object>(); | 432 return v8::Local<v8::Object>(); |
433 | 433 |
434 if (!frame->script().canExecuteScripts(NotAboutToExecuteScript)) | 434 if (!frame->script().canExecuteScripts(NotAboutToExecuteScript)) |
435 return v8::Local<v8::Object>(); | 435 return v8::Local<v8::Object>(); |
436 | 436 |
437 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 437 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
438 if (!scriptState->contextIsValid()) | 438 if (!scriptState->contextIsValid()) |
439 return v8::Local<v8::Object>(); | 439 return v8::Local<v8::Object>(); |
440 | 440 |
441 v8::Handle<v8::Value> v8value = toV8(m_element, scriptState->context()->Glob
al(), scriptState->isolate()); | 441 v8::Handle<v8::Value> v8value = toV8(m_element.get(), scriptState->context()
->Global(), scriptState->isolate()); |
442 ASSERT(v8value->IsObject()); | 442 ASSERT(v8value->IsObject()); |
443 | 443 |
444 return v8::Handle<v8::Object>::Cast(v8value); | 444 return v8::Handle<v8::Object>::Cast(v8value); |
445 } | 445 } |
446 | 446 |
447 WebString WebPluginContainerImpl::executeScriptURL(const WebURL& url, bool popup
sAllowed) | 447 WebString WebPluginContainerImpl::executeScriptURL(const WebURL& url, bool popup
sAllowed) |
448 { | 448 { |
449 LocalFrame* frame = m_element->document().frame(); | 449 LocalFrame* frame = m_element->document().frame(); |
450 if (!frame) | 450 if (!frame) |
451 return WebString(); | 451 return WebString(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 context->setFillColor(Color(0xCC, 0xCC, 0xCC)); | 666 context->setFillColor(Color(0xCC, 0xCC, 0xCC)); |
667 context->fillRect(intersection(horizontalOverhangArea, dirtyRect)); | 667 context->fillRect(intersection(horizontalOverhangArea, dirtyRect)); |
668 context->fillRect(intersection(verticalOverhangArea, dirtyRect)); | 668 context->fillRect(intersection(verticalOverhangArea, dirtyRect)); |
669 context->restore(); | 669 context->restore(); |
670 return true; | 670 return true; |
671 } | 671 } |
672 | 672 |
673 // Private methods ------------------------------------------------------------- | 673 // Private methods ------------------------------------------------------------- |
674 | 674 |
675 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element, WebPl
ugin* webPlugin) | 675 WebPluginContainerImpl::WebPluginContainerImpl(HTMLPlugInElement* element, WebPl
ugin* webPlugin) |
676 #if ENABLE(OILPAN) | |
677 : m_frame(element->document().frame()) | |
678 #else | |
679 : FrameDestructionObserver(element->document().frame()) | 676 : FrameDestructionObserver(element->document().frame()) |
680 #endif | |
681 , m_element(element) | 677 , m_element(element) |
682 , m_webPlugin(webPlugin) | 678 , m_webPlugin(webPlugin) |
683 , m_webLayer(0) | 679 , m_webLayer(nullptr) |
684 , m_touchEventRequestType(TouchEventRequestTypeNone) | 680 , m_touchEventRequestType(TouchEventRequestTypeNone) |
685 , m_wantsWheelEvents(false) | 681 , m_wantsWheelEvents(false) |
| 682 #if ENABLE(OILPAN) |
| 683 , m_shouldDisposePlugin(false) |
| 684 #endif |
686 { | 685 { |
687 } | 686 } |
688 | 687 |
689 WebPluginContainerImpl::~WebPluginContainerImpl() | 688 WebPluginContainerImpl::~WebPluginContainerImpl() |
690 { | 689 { |
691 #if ENABLE(OILPAN) | 690 #if ENABLE(OILPAN) |
692 // The element (and its document) are heap allocated and may | 691 if (m_shouldDisposePlugin) |
693 // have been finalized by now; unsafe to unregister the touch | 692 dispose(); |
694 // event handler at this stage. | 693 // The plugin container must have been disposed of by now. |
695 // | 694 ASSERT(!m_webPlugin); |
696 // This is acceptable, as the widget will unregister itself if it | |
697 // is cleanly detached. If an explicit detach doesn't happen, this | |
698 // container is assumed to have died with the plugin element (and | |
699 // its document), hence no unregistration step is needed. | |
700 // | |
701 m_element = 0; | |
702 #else | 695 #else |
703 if (m_touchEventRequestType != TouchEventRequestTypeNone && m_element->docum
ent().frameHost()) | 696 dispose(); |
| 697 #endif |
| 698 } |
| 699 |
| 700 void WebPluginContainerImpl::dispose() |
| 701 { |
| 702 if (m_element && m_touchEventRequestType != TouchEventRequestTypeNone && m_e
lement->document().frameHost()) |
704 m_element->document().frameHost()->eventHandlerRegistry().didRemoveEvent
Handler(*m_element, EventHandlerRegistry::TouchEvent); | 703 m_element->document().frameHost()->eventHandlerRegistry().didRemoveEvent
Handler(*m_element, EventHandlerRegistry::TouchEvent); |
705 #endif | |
706 | 704 |
707 ScriptForbiddenScope::AllowSuperUnsafeScript thisShouldBeRemoved; | 705 ScriptForbiddenScope::AllowSuperUnsafeScript thisShouldBeRemoved; |
708 | 706 |
709 for (size_t i = 0; i < m_pluginLoadObservers.size(); ++i) | 707 for (size_t i = 0; i < m_pluginLoadObservers.size(); ++i) |
710 m_pluginLoadObservers[i]->clearPluginContainer(); | 708 m_pluginLoadObservers[i]->clearPluginContainer(); |
711 m_webPlugin->destroy(); | 709 m_webPlugin->destroy(); |
| 710 m_webPlugin = nullptr; |
| 711 |
712 if (m_webLayer) | 712 if (m_webLayer) |
713 GraphicsLayer::unregisterContentsLayer(m_webLayer); | 713 GraphicsLayer::unregisterContentsLayer(m_webLayer); |
| 714 |
| 715 m_pluginLoadObservers.clear(); |
| 716 m_scrollbarGroup.clear(); |
| 717 m_element = nullptr; |
714 } | 718 } |
715 | 719 |
716 #if ENABLE(OILPAN) | 720 #if ENABLE(OILPAN) |
717 void WebPluginContainerImpl::detach() | 721 void WebPluginContainerImpl::shouldDisposePlugin() |
718 { | 722 { |
719 if (m_touchEventRequestType != TouchEventRequestTypeNone && m_element->docum
ent().frameHost()) | 723 // If the LocalFrame is still alive, but the plugin element isn't, the |
720 m_element->document().frameHost()->eventHandlerRegistry().didRemoveEvent
Handler(*m_element, EventHandlerRegistry::TouchEvent); | 724 // LocalFrame will set m_shouldDisposePlugin via its weak pointer |
721 | 725 // callback. This is a signal that the plugin container |
722 setWebLayer(0); | 726 // must dispose of its plugin when finalizing. The LocalFrame and |
| 727 // all objects accessible from it can safely be accessed, but not |
| 728 // the plugin element itself. |
| 729 ASSERT(!m_shouldDisposePlugin); |
| 730 m_shouldDisposePlugin = true; |
| 731 m_element = nullptr; |
723 } | 732 } |
724 #endif | 733 #endif |
725 | 734 |
| 735 void WebPluginContainerImpl::trace(Visitor* visitor) |
| 736 { |
| 737 visitor->trace(m_element); |
| 738 FrameDestructionObserver::trace(visitor); |
| 739 PluginView::trace(visitor); |
| 740 } |
| 741 |
726 void WebPluginContainerImpl::handleMouseEvent(MouseEvent* event) | 742 void WebPluginContainerImpl::handleMouseEvent(MouseEvent* event) |
727 { | 743 { |
728 ASSERT(parent()->isFrameView()); | 744 ASSERT(parent()->isFrameView()); |
729 | 745 |
730 if (event->isDragEvent()) { | 746 if (event->isDragEvent()) { |
731 if (m_webPlugin->canProcessDrag()) | 747 if (m_webPlugin->canProcessDrag()) |
732 handleDragEvent(event); | 748 handleDragEvent(event); |
733 return; | 749 return; |
734 } | 750 } |
735 | 751 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 977 |
962 return clipRect; | 978 return clipRect; |
963 } | 979 } |
964 | 980 |
965 bool WebPluginContainerImpl::pluginShouldPersist() const | 981 bool WebPluginContainerImpl::pluginShouldPersist() const |
966 { | 982 { |
967 return m_webPlugin->shouldPersist(); | 983 return m_webPlugin->shouldPersist(); |
968 } | 984 } |
969 | 985 |
970 } // namespace blink | 986 } // namespace blink |
OLD | NEW |