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 
     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;
     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     String m_serviceType;
     83     String m_url;
     84     KURL m_loadedUrl;
     85     OwnPtr<HTMLImageLoader> m_imageLoader;
     86     bool m_isDelayingLoadEvent;
     87 
     88 private:
     89     // EventTarget functions:
     90     virtual void removeAllEventListeners() OVERRIDE FINAL;
     91 
     92     // Node functions:
     93     virtual bool canContainRangeEndPoint() const OVERRIDE { return false; }
     94     virtual bool willRespondToMouseClickEvents() OVERRIDE;
     95     virtual void defaultEventHandler(Event*) OVERRIDE;
     96     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
     97     virtual void detach(const AttachContext& = AttachContext()) OVERRIDE;
     98     virtual void finishParsingChildren() OVERRIDE;
     99     virtual bool isPluginElement() const OVERRIDE;
    100 
    101     // Element functions:
    102     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
    103     virtual void willRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
    104     virtual bool supportsFocus() const OVERRIDE { return true; };
    105     virtual bool rendererIsFocusable() const OVERRIDE;
    106     virtual bool isKeyboardFocusable() const OVERRIDE;
    107     virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE;
    108     virtual void didAddShadowRoot(ShadowRoot&) OVERRIDE;
    109 
    110     // HTMLElement function:
    111     virtual bool hasCustomFocusLogic() const OVERRIDE;
    112 
    113     // Return any existing RenderWidget without triggering relayout, or 0 if it
    114     // doesn't yet exist.
    115     virtual RenderWidget* existingRenderWidget() const = 0;
    116     virtual void updateWidgetInternal() = 0;
    117 
    118     enum DisplayState {
    119         Restarting,
    120         RestartingWithPendingMouseClick,
    121         Playing
    122     };
    123     DisplayState displayState() const { return m_displayState; }
    124     void setDisplayState(DisplayState state) { m_displayState = state; }
    125     const String loadedMimeType() const;
    126     bool loadPlugin(const KURL&, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback);
    127     bool pluginIsLoadable(const KURL&, const String& mimeType);
    128     bool wouldLoadAsNetscapePlugin(const String& url, const String& serviceType);
    129 
    130     mutable RefPtr<SharedPersistent<v8::Object> > m_pluginWrapper;
    131     NPObject* m_NPObject;
    132     bool m_isCapturingMouseEvents;
    133     bool m_inBeforeLoadEventHandler;
    134     bool m_needsWidgetUpdate;
    135     bool m_shouldPreferPlugInsForImages;
    136     DisplayState m_displayState;
    137 };
    138 
    139 DEFINE_NODE_TYPE_CASTS(HTMLPlugInElement, isPluginElement());
    140 
    141 } // namespace WebCore
    142 
    143 #endif // HTMLPlugInElement_h
    144