2 * Copyright (C) 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #ifndef HTMLPlugInImageElement_h
22 #define HTMLPlugInImageElement_h
24 #include "HTMLPlugInElement.h"
26 #include "RenderStyle.h"
27 #include <wtf/OwnPtr.h>
28 #include <wtf/RefPtr.h>
32 class HTMLImageLoader;
38 enum PluginCreationOption {
40 CreateOnlyNonNetscapePlugins,
43 enum PreferPlugInsForImagesOption {
44 ShouldPreferPlugInsForImages,
45 ShouldNotPreferPlugInsForImages
48 // Base class for HTMLObjectElement and HTMLEmbedElement
49 class HTMLPlugInImageElement : public HTMLPlugInElement {
51 virtual ~HTMLPlugInImageElement();
53 RenderEmbeddedObject* renderEmbeddedObject() const;
55 virtual void setDisplayState(DisplayState) OVERRIDE;
57 virtual void updateWidget(PluginCreationOption) = 0;
59 const String& serviceType() const { return m_serviceType; }
60 const String& url() const { return m_url; }
61 const KURL& loadedUrl() const { return m_loadedUrl; }
63 const String loadedMimeType() const
65 String mimeType = serviceType();
66 if (mimeType.isEmpty())
67 mimeType = mimeTypeFromURL(m_loadedUrl);
71 bool shouldPreferPlugInsForImages() const { return m_shouldPreferPlugInsForImages; }
73 // Public for FrameView::addWidgetToUpdate()
74 bool needsWidgetUpdate() const { return m_needsWidgetUpdate; }
75 void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; }
77 void userDidClickSnapshot(PassRefPtr<MouseEvent>, bool forwardEvent);
78 void checkSnapshotStatus();
79 Image* snapshotImage() const { return m_snapshotImage.get(); }
81 // Plug-in URL might not be the same as url() with overriding parameters.
82 void subframeLoaderWillCreatePlugIn(const KURL& plugInURL);
83 void subframeLoaderDidCreatePlugIn(const Widget*);
85 void setIsPrimarySnapshottedPlugIn(bool);
86 bool partOfSnapshotLabel(Node*);
88 bool needsCheckForSizeChange() const { return m_needsCheckForSizeChange; }
89 void setNeedsCheckForSizeChange() { m_needsCheckForSizeChange = true; }
90 void checkSizeChangeForSnapshotting();
92 enum SnapshotDecision {
93 SnapshotNotYetDecided,
96 MaySnapshotWhenResized
98 SnapshotDecision snapshotDecision() const { return m_snapshotDecision; }
101 HTMLPlugInImageElement(const QualifiedName& tagName, Document*, bool createdByParser, PreferPlugInsForImagesOption);
105 OwnPtr<HTMLImageLoader> m_imageLoader;
106 String m_serviceType;
110 static void updateWidgetCallback(Node*, unsigned = 0);
111 virtual void attach();
112 virtual void detach();
114 bool allowedToLoadFrameURL(const String& url);
115 bool wouldLoadAsNetscapePlugin(const String& url, const String& serviceType);
117 virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
119 virtual void documentWillSuspendForPageCache() OVERRIDE;
120 virtual void documentDidResumeFromPageCache() OVERRIDE;
122 virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE;
124 void restartSnapshottedPlugIn();
125 virtual bool restartedPlugin() const OVERRIDE { return m_restartedPlugin; }
128 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
129 virtual bool willRecalcStyle(StyleChange);
131 void didAddUserAgentShadowRoot(ShadowRoot*) OVERRIDE;
133 virtual void finishParsingChildren();
135 void updateWidgetIfNecessary();
137 virtual void updateSnapshot(PassRefPtr<Image>) OVERRIDE;
138 virtual void dispatchPendingMouseClick() OVERRIDE;
139 void simulatedMouseClickTimerFired(DeferrableOneShotTimer<HTMLPlugInImageElement>*);
141 void swapRendererTimerFired(Timer<HTMLPlugInImageElement>*);
143 void restartSimilarPlugIns();
145 virtual bool isPlugInImageElement() const OVERRIDE { return true; }
147 void removeSnapshotTimerFired(Timer<HTMLPlugInImageElement>*);
149 bool m_needsWidgetUpdate;
150 bool m_shouldPreferPlugInsForImages;
151 bool m_needsDocumentActivationCallbacks;
152 RefPtr<RenderStyle> m_customStyleForPageCache;
153 RefPtr<MouseEvent> m_pendingClickEventFromSnapshot;
154 DeferrableOneShotTimer<HTMLPlugInImageElement> m_simulatedMouseClickTimer;
155 Timer<HTMLPlugInImageElement> m_swapRendererTimer;
156 Timer<HTMLPlugInImageElement> m_removeSnapshotTimer;
157 RefPtr<Image> m_snapshotImage;
158 RefPtr<Element> m_shadowContainer;
159 RefPtr<Element> m_snapshotLabel;
160 bool m_createdDuringUserGesture;
161 bool m_restartedPlugin;
162 bool m_needsCheckForSizeChange;
163 IntSize m_sizeWhenSnapshotted;
164 SnapshotDecision m_snapshotDecision;
167 inline HTMLPlugInImageElement* toHTMLPlugInImageElement(Node* node)
169 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isPluginElement());
170 HTMLPlugInElement* plugInElement = static_cast<HTMLPlugInElement*>(node);
171 ASSERT_WITH_SECURITY_IMPLICATION(plugInElement->isPlugInImageElement());
172 return static_cast<HTMLPlugInImageElement*>(plugInElement);
175 inline const HTMLPlugInImageElement* toHTMLPlugInImageElement(const Node* node)
177 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isPluginElement());
178 const HTMLPlugInElement* plugInElement = static_cast<const HTMLPlugInElement*>(node);
179 ASSERT_WITH_SECURITY_IMPLICATION(plugInElement->isPlugInImageElement());
180 return static_cast<const HTMLPlugInImageElement*>(plugInElement);
183 // This will catch anyone doing an unnecessary cast.
184 void toHTMLPlugInImageElement(const HTMLPlugInImageElement*);
186 } // namespace WebCore
188 #endif // HTMLPlugInImageElement_h