1 /* 2 * Copyright (C) 2008, 2009, 2011, 2012 Apple Inc. All rights reserved. 3 * 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. 8 * 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. 13 * 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. 18 * 19 */ 20 21 #ifndef HTMLPlugInImageElement_h 22 #define HTMLPlugInImageElement_h 23 24 #include "core/html/HTMLPlugInElement.h" 25 26 #include "core/platform/MIMETypeFromURL.h" 27 #include "core/rendering/style/RenderStyle.h" 28 #include "wtf/OwnPtr.h" 29 30 namespace WebCore { 31 32 class HTMLImageLoader; 33 class FrameLoader; 34 class Image; 35 class MouseEvent; 36 class Widget; 37 38 enum PluginCreationOption { 39 CreateAnyWidgetType, 40 CreateOnlyNonNetscapePlugins, 41 }; 42 43 enum PreferPlugInsForImagesOption { 44 ShouldPreferPlugInsForImages, 45 ShouldNotPreferPlugInsForImages 46 }; 47 48 // Base class for HTMLObjectElement and HTMLEmbedElement 49 class HTMLPlugInImageElement : public HTMLPlugInElement { 50 public: 51 virtual ~HTMLPlugInImageElement(); 52 53 RenderEmbeddedObject* renderEmbeddedObject() const; 54 55 virtual void setDisplayState(DisplayState) OVERRIDE; 56 57 virtual void updateWidget(PluginCreationOption) = 0; 58 59 const String& serviceType() const { return m_serviceType; } 60 const String& url() const { return m_url; } 61 const KURL& loadedUrl() const { return m_loadedUrl; } 62 63 const String loadedMimeType() const 64 { 65 String mimeType = serviceType(); 66 if (mimeType.isEmpty()) 67 mimeType = mimeTypeFromURL(m_loadedUrl); 68 return mimeType; 69 } 70 71 bool shouldPreferPlugInsForImages() const { return m_shouldPreferPlugInsForImages; } 72 73 // Public for FrameView::addWidgetToUpdate() 74 bool needsWidgetUpdate() const { return m_needsWidgetUpdate; } 75 void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; } 76 77 protected: 78 HTMLPlugInImageElement(const QualifiedName& tagName, Document*, bool createdByParser, PreferPlugInsForImagesOption); 79 80 bool isImageType(); 81 82 OwnPtr<HTMLImageLoader> m_imageLoader; 83 String m_serviceType; 84 String m_url; 85 KURL m_loadedUrl; 86 87 static void updateWidgetCallback(Node*); 88 virtual void attach(const AttachContext& = AttachContext()) OVERRIDE; 89 virtual void detach(const AttachContext& = AttachContext()) OVERRIDE; 90 91 bool allowedToLoadFrameURL(const String& url); 92 bool wouldLoadAsNetscapePlugin(const String& url, const String& serviceType); 93 94 virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE; 95 96 bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues); 97 bool shouldUsePlugin(const KURL&, const String& mimeType, bool hasFallback, bool& useFallback); 98 99 private: 100 virtual RenderObject* createRenderer(RenderStyle*); 101 virtual void willRecalcStyle(StyleChange) OVERRIDE FINAL; 102 103 virtual void finishParsingChildren(); 104 105 void updateWidgetIfNecessary(); 106 107 void swapRendererTimerFired(Timer<HTMLPlugInImageElement>*); 108 109 void restartSimilarPlugIns(); 110 111 bool loadPlugin(const KURL&, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback); 112 bool pluginIsLoadable(const KURL&, const String& mimeType); 113 114 virtual bool isPlugInImageElement() const OVERRIDE { return true; } 115 116 bool m_needsWidgetUpdate; 117 bool m_shouldPreferPlugInsForImages; 118 bool m_createdDuringUserGesture; 119 }; 120 121 inline HTMLPlugInImageElement* toHTMLPlugInImageElement(Node* node) 122 { 123 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isPluginElement()); 124 HTMLPlugInElement* plugInElement = static_cast<HTMLPlugInElement*>(node); 125 ASSERT_WITH_SECURITY_IMPLICATION(plugInElement->isPlugInImageElement()); 126 return static_cast<HTMLPlugInImageElement*>(plugInElement); 127 } 128 129 inline const HTMLPlugInImageElement* toHTMLPlugInImageElement(const Node* node) 130 { 131 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isPluginElement()); 132 const HTMLPlugInElement* plugInElement = static_cast<const HTMLPlugInElement*>(node); 133 ASSERT_WITH_SECURITY_IMPLICATION(plugInElement->isPlugInImageElement()); 134 return static_cast<const HTMLPlugInImageElement*>(plugInElement); 135 } 136 137 // This will catch anyone doing an unnecessary cast. 138 void toHTMLPlugInImageElement(const HTMLPlugInImageElement*); 139 140 } // namespace WebCore 141 142 #endif // HTMLPlugInImageElement_h 143