| 1 | /* |
| 2 | * Copyright (C) 2008-2017 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 | #pragma once |
| 22 | |
| 23 | #include "HTMLPlugInElement.h" |
| 24 | |
| 25 | namespace WebCore { |
| 26 | |
| 27 | class HTMLImageLoader; |
| 28 | class MouseEvent; |
| 29 | |
| 30 | enum class CreatePlugins { No, Yes }; |
| 31 | |
| 32 | // Base class for HTMLAppletElement, HTMLEmbedElement, and HTMLObjectElement. |
| 33 | // FIXME: Perhaps HTMLAppletElement should inherit from HTMLPlugInElement directly instead. |
| 34 | class HTMLPlugInImageElement : public HTMLPlugInElement { |
| 35 | WTF_MAKE_ISO_ALLOCATED(HTMLPlugInImageElement); |
| 36 | public: |
| 37 | virtual ~HTMLPlugInImageElement(); |
| 38 | |
| 39 | RenderEmbeddedObject* renderEmbeddedObject() const; |
| 40 | |
| 41 | virtual void updateWidget(CreatePlugins) = 0; |
| 42 | |
| 43 | const String& serviceType() const { return m_serviceType; } |
| 44 | const String& url() const { return m_url; } |
| 45 | const URL& loadedUrl() const { return m_loadedUrl; } |
| 46 | |
| 47 | // Public for FrameView::addWidgetToUpdate() |
| 48 | bool needsWidgetUpdate() const { return m_needsWidgetUpdate; } |
| 49 | void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; } |
| 50 | |
| 51 | void userDidClickSnapshot(MouseEvent&, bool forwardEvent); |
| 52 | void checkSnapshotStatus(); |
| 53 | Image* snapshotImage() const { return m_snapshotImage.get(); } |
| 54 | WEBCORE_EXPORT void restartSnapshottedPlugIn(); |
| 55 | |
| 56 | // Plug-in URL might not be the same as url() with overriding parameters. |
| 57 | void subframeLoaderWillCreatePlugIn(const URL& plugInURL); |
| 58 | void subframeLoaderDidCreatePlugIn(const Widget&); |
| 59 | |
| 60 | WEBCORE_EXPORT void setIsPrimarySnapshottedPlugIn(bool); |
| 61 | bool partOfSnapshotOverlay(const EventTarget*) const; |
| 62 | |
| 63 | bool needsCheckForSizeChange() const { return m_needsCheckForSizeChange; } |
| 64 | void setNeedsCheckForSizeChange() { m_needsCheckForSizeChange = true; } |
| 65 | void checkSizeChangeForSnapshotting(); |
| 66 | |
| 67 | enum SnapshotDecision { |
| 68 | SnapshotNotYetDecided, |
| 69 | NeverSnapshot, |
| 70 | Snapshotted, |
| 71 | MaySnapshotWhenResized, |
| 72 | MaySnapshotWhenContentIsSet |
| 73 | }; |
| 74 | SnapshotDecision snapshotDecision() const { return m_snapshotDecision; } |
| 75 | |
| 76 | protected: |
| 77 | HTMLPlugInImageElement(const QualifiedName& tagName, Document&); |
| 78 | void finishCreating(); |
| 79 | |
| 80 | void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override; |
| 81 | |
| 82 | bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues) final; |
| 83 | |
| 84 | bool isImageType(); |
| 85 | HTMLImageLoader* imageLoader() { return m_imageLoader.get(); } |
| 86 | void updateImageLoaderWithNewURLSoon(); |
| 87 | |
| 88 | bool allowedToLoadFrameURL(const String& url); |
| 89 | bool wouldLoadAsPlugIn(const String& url, const String& serviceType); |
| 90 | |
| 91 | void scheduleUpdateForAfterStyleResolution(); |
| 92 | |
| 93 | String m_serviceType; |
| 94 | String m_url; |
| 95 | |
| 96 | private: |
| 97 | bool isPlugInImageElement() const final { return true; } |
| 98 | bool isRestartedPlugin() const final { return m_isRestartedPlugin; } |
| 99 | |
| 100 | bool allowedToLoadPluginContent(const String& url, const String& mimeType) const; |
| 101 | |
| 102 | void didAddUserAgentShadowRoot(ShadowRoot&) final; |
| 103 | |
| 104 | RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override; |
| 105 | bool childShouldCreateRenderer(const Node&) const override; |
| 106 | void willRecalcStyle(Style::Change) final; |
| 107 | void didRecalcStyle(Style::Change) final; |
| 108 | void didAttachRenderers() final; |
| 109 | void willDetachRenderers() final; |
| 110 | |
| 111 | void prepareForDocumentSuspension() final; |
| 112 | void resumeFromDocumentSuspension() final; |
| 113 | |
| 114 | void defaultEventHandler(Event&) final; |
| 115 | void dispatchPendingMouseClick() final; |
| 116 | |
| 117 | void updateSnapshot(Image*) final; |
| 118 | |
| 119 | void updateAfterStyleResolution(); |
| 120 | |
| 121 | void simulatedMouseClickTimerFired(); |
| 122 | |
| 123 | void restartSimilarPlugIns(); |
| 124 | void removeSnapshotTimerFired(); |
| 125 | bool isTopLevelFullPagePlugin(const RenderEmbeddedObject&) const; |
| 126 | |
| 127 | void setDisplayState(DisplayState) final; |
| 128 | |
| 129 | URL m_loadedUrl; |
| 130 | bool m_needsWidgetUpdate { false }; |
| 131 | bool m_needsDocumentActivationCallbacks { false }; |
| 132 | RefPtr<MouseEvent> m_pendingClickEventFromSnapshot; |
| 133 | DeferrableOneShotTimer m_simulatedMouseClickTimer; |
| 134 | Timer m_removeSnapshotTimer; |
| 135 | RefPtr<Image> m_snapshotImage; |
| 136 | bool m_createdDuringUserGesture { false }; |
| 137 | bool m_isRestartedPlugin { false }; |
| 138 | bool m_needsCheckForSizeChange { false }; |
| 139 | bool m_plugInWasCreated { false }; |
| 140 | bool m_deferredPromotionToPrimaryPlugIn { false }; |
| 141 | IntSize m_sizeWhenSnapshotted; |
| 142 | SnapshotDecision m_snapshotDecision { SnapshotNotYetDecided }; |
| 143 | bool m_plugInDimensionsSpecified { false }; |
| 144 | std::unique_ptr<HTMLImageLoader> m_imageLoader; |
| 145 | bool m_needsImageReload { false }; |
| 146 | bool m_hasUpdateScheduledForAfterStyleResolution { false }; |
| 147 | }; |
| 148 | |
| 149 | } // namespace WebCore |
| 150 | |
| 151 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLPlugInImageElement) |
| 152 | static bool isType(const WebCore::HTMLPlugInElement& element) { return element.isPlugInImageElement(); } |
| 153 | static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLPlugInElement>(node) && isType(downcast<WebCore::HTMLPlugInElement>(node)); } |
| 154 | SPECIALIZE_TYPE_TRAITS_END() |
| 155 | |