Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) 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 #include <v8.h>
     29 
     30 struct NPObject;
     31 
     32 namespace WebCore {
     33 
     34 class HTMLImageLoader;
     35 class RenderEmbeddedObject;
     36 class RenderWidget;
     37 class Widget;
     38 
     39 enum PreferPlugInsForImagesOption {
     40     ShouldPreferPlugInsForImages,
     41     ShouldNotPreferPlugInsForImages
     42 };
     43 
     44 class HTMLPlugInElement : public HTMLFrameOwnerElement {
     45 public:
     46     virtual ~HTMLPlugInElement();
     47     virtual void trace(Visitor*) OVERRIDE;
     48 
     49     void resetInstance();
     50     SharedPersistent<v8::Object>* pluginWrapper();
     51     Widget* pluginWidget() const;
     52     NPObject* getNPObject();
     53     bool canProcessDrag() const;
     54     const String& url() const { return m_url; }
     55 
     56     // Public for FrameView::addWidgetToUpdate()
     57     bool needsWidgetUpdate() const { return m_needsWidgetUpdate; }
     58     void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; }
     59     void updateWidget();
     60 
     61     bool shouldAccelerate() const;
     62 
     63     void requestPluginCreationWithoutRendererIfPossible();
     64     void createPluginWithoutRenderer();
     65 
     66 protected:
     67     HTMLPlugInElement(const QualifiedName& tagName, Document&, bool createdByParser, PreferPlugInsForImagesOption);
     68 
     69     // Node functions:
     70     virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
     71 
     72     // Element functions:
     73     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
     74     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
     75 
     76     virtual bool hasFallbackContent() const;
     77     virtual bool useFallbackContent() const;
     78     // Create or update the RenderWidget and return it, triggering layout if
     79     // necessary.
     80     virtual RenderWidget* renderWidgetForJSBindings() const;
     81 
     82     bool isImageType();
     83     bool shouldPreferPlugInsForImages() const { return m_shouldPreferPlugInsForImages; }
     84     RenderEmbeddedObject* renderEmbeddedObject() const;
     85     bool allowedToLoadFrameURL(const String& url);
     86     bool requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues);
     87     bool shouldUsePlugin(const KURL&, const String& mimeType, bool hasFallback, bool& useFallback);
     88 
     89     void dispatchErrorEvent();
     90 
     91     String m_serviceType;
     92     String m_url;
     93     KURL m_loadedUrl;
     94     OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader;
     95     bool m_isDelayingLoadEvent;
     96 
     97 private:
     98     // EventTarget functions:
     99     virtual void removeAllEventListeners() OVERRIDE FINAL;
    100 
    101     // Node functions:
    102     virtual bool canContainRangeEndPoint() const OVERRIDE { return false; }
    103     virtual bool willRespondToMouseClickEvents() OVERRIDE FINAL;
    104     virtual void defaultEventHandler(Event*) OVERRIDE FINAL;
    105     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
    106     virtual void detach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
    107     virtual void finishParsingChildren() OVERRIDE FINAL;
    108 
    109     // Element functions:
    110     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
    111     virtual void willRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
    112     virtual bool supportsFocus() const OVERRIDE FINAL { return true; }
    113     virtual bool rendererIsFocusable() const OVERRIDE FINAL;
    114     virtual bool isKeyboardFocusable() const OVERRIDE FINAL;
    115     virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE FINAL;
    116     virtual void willAddFirstAuthorShadowRoot() OVERRIDE FINAL;
    117 
    118     // HTMLElement function:
    119     virtual bool hasCustomFocusLogic() const OVERRIDE;
    120     virtual bool isPluginElement() const OVERRIDE FINAL;
    121 
    122     // Return any existing RenderWidget without triggering relayout, or 0 if it
    123     // doesn't yet exist.
    124     virtual RenderWidget* existingRenderWidget() const = 0;
    125     virtual void updateWidgetInternal() = 0;
    126 
    127     enum DisplayState {
    128         Restarting,
    129         RestartingWithPendingMouseClick,
    130         Playing
    131     };
    132     DisplayState displayState() const { return m_displayState; }
    133     void setDisplayState(DisplayState state) { m_displayState = state; }
    134     bool loadPlugin(const KURL&, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback, bool requireRenderer);
    135     bool pluginIsLoadable(const KURL&, const String& mimeType);
    136     bool wouldLoadAsNetscapePlugin(const String& url, const String& serviceType);
    137 
    138     mutable RefPtr<SharedPersistent<v8::Object> > m_pluginWrapper;
    139     NPObject* m_NPObject;
    140     bool m_isCapturingMouseEvents;
    141     bool m_needsWidgetUpdate;
    142     bool m_shouldPreferPlugInsForImages;
    143     DisplayState m_displayState;
    144 
    145     // Normally the Widget is stored in HTMLFrameOwnerElement::m_widget.
    146     // However, plugins can persist even when not rendered. In order to
    147     // prevent confusing code which may assume that widget() != null
    148     // means the frame is active, we save off m_widget here while
    149     // the plugin is persisting but not being displayed.
    150     RefPtr<Widget> m_persistedPluginWidget;
    151 };
    152 
    153 inline bool isHTMLPlugInElement(const Element& element)
    154 {
    155     return element.isHTMLElement() && toHTMLElement(element).isPluginElement();
    156 }
    157 
    158 inline bool isHTMLPlugInElement(const HTMLElement& element)
    159 {
    160     return element.isPluginElement();
    161 }
    162 
    163 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLPlugInElement);
    164 
    165 } // namespace WebCore
    166 
    167 #endif // HTMLPlugInElement_h
    168