Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLPlugInElement.h
1 /*
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.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22
23 #ifndef HTMLPlugInElement_h
24 #define HTMLPlugInElement_h
25
26 #include "bindings/v8/SharedPersistent.h"
27 #include "core/html/HTMLFrameOwnerElement.h"
28
29 struct NPObject;
30
31 namespace WebCore {
32
33 class HTMLImageLoader;
34 class RenderEmbeddedObject;
35 class RenderWidget;
36 class Widget;
37
38 enum PreferPlugInsForImagesOption {
39     ShouldPreferPlugInsForImages,
40     ShouldNotPreferPlugInsForImages
41 };
42
43 class HTMLPlugInElement : public HTMLFrameOwnerElement {
44 public:
45     virtual ~HTMLPlugInElement();
46
47     void resetInstance();
48     SharedPersistent<v8::Object>* pluginWrapper();
49     Widget* pluginWidget() const;
50     NPObject* getNPObject();
51     bool canProcessDrag() const;
52     const String& url() const { return m_url; }
53
54     // Public for FrameView::addWidgetToUpdate()
55     bool needsWidgetUpdate() const { return m_needsWidgetUpdate; }
56     void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; }
57     void updateWidget();
58
59     void requestPluginCreationWithoutRendererIfPossible();
60     void createPluginWithoutRenderer();
61
62 protected:
63     HTMLPlugInElement(const QualifiedName& tagName, Document&, bool createdByParser, PreferPlugInsForImagesOption);
64
65     // Node functions:
66     virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
67
68     // Element functions:
69     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
70     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
71
72     virtual bool useFallbackContent() const;
73     // Create or update the RenderWidget and return it, triggering layout if
74     // necessary.
75     virtual RenderWidget* renderWidgetForJSBindings() const;
76
77     bool isImageType();
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);
83
84     void dispatchErrorEvent();
85
86     String m_serviceType;
87     String m_url;
88     KURL m_loadedUrl;
89     OwnPtr<HTMLImageLoader> m_imageLoader;
90     bool m_isDelayingLoadEvent;
91
92 private:
93     // EventTarget functions:
94     virtual void removeAllEventListeners() OVERRIDE FINAL;
95
96     // Node functions:
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;
103
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;
112
113     // HTMLElement function:
114     virtual bool hasCustomFocusLogic() const OVERRIDE;
115     virtual bool isPluginElement() const OVERRIDE FINAL;
116
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;
121
122     enum DisplayState {
123         Restarting,
124         RestartingWithPendingMouseClick,
125         Playing
126     };
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);
132
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;
139
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;
146 };
147
148 inline bool isHTMLPlugInElement(const Element& element)
149 {
150     return element.isHTMLElement() && toHTMLElement(element).isPluginElement();
151 }
152
153 inline bool isHTMLPlugInElement(const HTMLElement& element)
154 {
155     return element.isPluginElement();
156 }
157
158 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLPlugInElement);
159
160 } // namespace WebCore
161
162 #endif // HTMLPlugInElement_h