2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef HTMLPlugInElement_h
24 #define HTMLPlugInElement_h
26 #include "bindings/v8/SharedPersistent.h"
27 #include "core/html/HTMLFrameOwnerElement.h"
33 class HTMLImageLoader;
34 class RenderEmbeddedObject;
38 enum PreferPlugInsForImagesOption {
39 ShouldPreferPlugInsForImages,
40 ShouldNotPreferPlugInsForImages
43 class HTMLPlugInElement : public HTMLFrameOwnerElement {
45 virtual ~HTMLPlugInElement();
48 SharedPersistent<v8::Object>* pluginWrapper();
49 Widget* pluginWidget() const;
50 NPObject* getNPObject();
51 bool canProcessDrag() const;
52 const String& url() const { return m_url; }
54 // Public for FrameView::addWidgetToUpdate()
55 bool needsWidgetUpdate() const { return m_needsWidgetUpdate; }
56 void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; }
59 void requestPluginCreationWithoutRendererIfPossible();
60 void createPluginWithoutRenderer();
63 HTMLPlugInElement(const QualifiedName& tagName, Document&, bool createdByParser, PreferPlugInsForImagesOption);
66 virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
69 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
70 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
72 virtual bool useFallbackContent() const;
73 // Create or update the RenderWidget and return it, triggering layout if
75 virtual RenderWidget* renderWidgetForJSBindings() const;
78 bool shouldPreferPlugInsForImages() const { return m_shouldPreferPlugInsForImages; }
79 RenderEmbeddedObject* renderEmbeddedObject() const;
80 bool allowedToLoadFrameURL(const String& url);
81 bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues);
82 bool shouldUsePlugin(const KURL&, const String& mimeType, bool hasFallback, bool& useFallback);
84 void dispatchErrorEvent();
89 OwnPtr<HTMLImageLoader> m_imageLoader;
90 bool m_isDelayingLoadEvent;
93 // EventTarget functions:
94 virtual void removeAllEventListeners() OVERRIDE FINAL;
97 virtual bool canContainRangeEndPoint() const OVERRIDE { return false; }
98 virtual bool willRespondToMouseClickEvents() OVERRIDE FINAL;
99 virtual void defaultEventHandler(Event*) OVERRIDE FINAL;
100 virtual void attach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
101 virtual void detach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
102 virtual void finishParsingChildren() OVERRIDE FINAL;
104 // Element functions:
105 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
106 virtual void willRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
107 virtual bool supportsFocus() const OVERRIDE FINAL { return true; }
108 virtual bool rendererIsFocusable() const OVERRIDE FINAL;
109 virtual bool isKeyboardFocusable() const OVERRIDE FINAL;
110 virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE FINAL;
111 virtual void willAddFirstAuthorShadowRoot() OVERRIDE FINAL;
113 // HTMLElement function:
114 virtual bool hasCustomFocusLogic() const OVERRIDE;
115 virtual bool isPluginElement() const OVERRIDE FINAL;
117 // Return any existing RenderWidget without triggering relayout, or 0 if it
118 // doesn't yet exist.
119 virtual RenderWidget* existingRenderWidget() const = 0;
120 virtual void updateWidgetInternal() = 0;
124 RestartingWithPendingMouseClick,
127 DisplayState displayState() const { return m_displayState; }
128 void setDisplayState(DisplayState state) { m_displayState = state; }
129 bool loadPlugin(const KURL&, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback, bool requireRenderer);
130 bool pluginIsLoadable(const KURL&, const String& mimeType);
131 bool wouldLoadAsNetscapePlugin(const String& url, const String& serviceType);
133 mutable RefPtr<SharedPersistent<v8::Object> > m_pluginWrapper;
134 NPObject* m_NPObject;
135 bool m_isCapturingMouseEvents;
136 bool m_needsWidgetUpdate;
137 bool m_shouldPreferPlugInsForImages;
138 DisplayState m_displayState;
140 // Normally the Widget is stored in HTMLFrameOwnerElement::m_widget.
141 // However, plugins can persist even when not rendered. In order to
142 // prevent confusing code which may assume that widget() != null
143 // means the frame is active, we save off m_widget here while
144 // the plugin is persisting but not being displayed.
145 RefPtr<Widget> m_persistedPluginWidget;
148 inline bool isHTMLPlugInElement(const Element& element)
150 return element.isHTMLElement() && toHTMLElement(element).isPluginElement();
153 inline bool isHTMLPlugInElement(const HTMLElement& element)
155 return element.isPluginElement();
158 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLPlugInElement);
160 } // namespace WebCore
162 #endif // HTMLPlugInElement_h