Upstream version 5.34.104.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 protected:
60     HTMLPlugInElement(const QualifiedName& tagName, Document&, bool createdByParser, PreferPlugInsForImagesOption);
61
62     // Node functions:
63     virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
64     virtual bool dispatchBeforeLoadEvent(const String& sourceURL) OVERRIDE FINAL;
65
66     // Element functions:
67     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
68     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
69
70     virtual bool useFallbackContent() const;
71     // Create or update the RenderWidget and return it, triggering layout if
72     // necessary.
73     virtual RenderWidget* renderWidgetForJSBindings() const;
74
75     bool isImageType();
76     bool shouldPreferPlugInsForImages() const { return m_shouldPreferPlugInsForImages; }
77     RenderEmbeddedObject* renderEmbeddedObject() const;
78     bool allowedToLoadFrameURL(const String& url);
79     bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues);
80     bool shouldUsePlugin(const KURL&, const String& mimeType, bool hasFallback, bool& useFallback);
81
82     void dispatchErrorEvent();
83
84     String m_serviceType;
85     String m_url;
86     KURL m_loadedUrl;
87     OwnPtr<HTMLImageLoader> m_imageLoader;
88     bool m_isDelayingLoadEvent;
89
90 private:
91     // EventTarget functions:
92     virtual void removeAllEventListeners() OVERRIDE FINAL;
93
94     // Node functions:
95     virtual bool canContainRangeEndPoint() const OVERRIDE { return false; }
96     virtual bool willRespondToMouseClickEvents() OVERRIDE FINAL;
97     virtual void defaultEventHandler(Event*) OVERRIDE FINAL;
98     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
99     virtual void detach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
100     virtual void finishParsingChildren() OVERRIDE FINAL;
101     virtual bool isPluginElement() const OVERRIDE FINAL;
102
103     // Element functions:
104     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
105     virtual void willRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
106     virtual bool supportsFocus() const OVERRIDE FINAL { return true; }
107     virtual bool rendererIsFocusable() const OVERRIDE FINAL;
108     virtual bool isKeyboardFocusable() const OVERRIDE FINAL;
109     virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE FINAL;
110     virtual void didAddShadowRoot(ShadowRoot&) OVERRIDE FINAL;
111
112     // HTMLElement function:
113     virtual bool hasCustomFocusLogic() const OVERRIDE;
114
115     // Return any existing RenderWidget without triggering relayout, or 0 if it
116     // doesn't yet exist.
117     virtual RenderWidget* existingRenderWidget() const = 0;
118     virtual void updateWidgetInternal() = 0;
119
120     enum DisplayState {
121         Restarting,
122         RestartingWithPendingMouseClick,
123         Playing
124     };
125     DisplayState displayState() const { return m_displayState; }
126     void setDisplayState(DisplayState state) { m_displayState = state; }
127     const String loadedMimeType() const;
128     bool loadPlugin(const KURL&, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback);
129     bool pluginIsLoadable(const KURL&, const String& mimeType);
130     bool wouldLoadAsNetscapePlugin(const String& url, const String& serviceType);
131
132     mutable RefPtr<SharedPersistent<v8::Object> > m_pluginWrapper;
133     NPObject* m_NPObject;
134     bool m_isCapturingMouseEvents;
135     bool m_inBeforeLoadEventHandler;
136     bool m_needsWidgetUpdate;
137     bool m_shouldPreferPlugInsForImages;
138     DisplayState m_displayState;
139 };
140
141 DEFINE_NODE_TYPE_CASTS(HTMLPlugInElement, isPluginElement());
142
143 } // namespace WebCore
144
145 #endif // HTMLPlugInElement_h