Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2009 Google Inc. All rights reserved.
      3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are
      7  * met:
      8  *
      9  *     * Redistributions of source code must retain the above copyright
     10  * notice, this list of conditions and the following disclaimer.
     11  *     * Redistributions in binary form must reproduce the above
     12  * copyright notice, this list of conditions and the following disclaimer
     13  * in the documentation and/or other materials provided with the
     14  * distribution.
     15  *     * Neither the name of Google Inc. nor the names of its
     16  * contributors may be used to endorse or promote products derived from
     17  * this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef ChromeClientImpl_h
     33 #define ChromeClientImpl_h
     34 
     35 #include "WebNavigationPolicy.h"
     36 #include "core/page/ChromeClient.h"
     37 #include "core/platform/PopupMenu.h"
     38 #include "modules/navigatorcontentutils/NavigatorContentUtilsClient.h"
     39 #include "public/platform/WebColor.h"
     40 #include "wtf/PassOwnPtr.h"
     41 
     42 namespace WebCore {
     43 class AccessibilityObject;
     44 class ColorChooser;
     45 class ColorChooserClient;
     46 class Element;
     47 class FileChooser;
     48 class GraphicsLayerFactory;
     49 class PopupContainer;
     50 class PopupMenuClient;
     51 class RenderBox;
     52 class SecurityOrigin;
     53 class DateTimeChooser;
     54 class DateTimeChooserClient;
     55 struct WindowFeatures;
     56 }
     57 
     58 namespace WebKit {
     59 class WebColorChooser;
     60 class WebColorChooserClient;
     61 class WebViewImpl;
     62 struct WebCursorInfo;
     63 struct WebPopupMenuInfo;
     64 
     65 // Handles window-level notifications from WebCore on behalf of a WebView.
     66 class ChromeClientImpl : public WebCore::ChromeClient {
     67 public:
     68     explicit ChromeClientImpl(WebViewImpl* webView);
     69     virtual ~ChromeClientImpl();
     70 
     71     virtual void* webView() const;
     72 
     73     // ChromeClient methods:
     74     virtual void chromeDestroyed();
     75     virtual void setWindowRect(const WebCore::FloatRect&);
     76     virtual WebCore::FloatRect windowRect();
     77     virtual WebCore::FloatRect pageRect();
     78     virtual void focus();
     79     virtual void unfocus();
     80     virtual bool canTakeFocus(WebCore::FocusDirection);
     81     virtual void takeFocus(WebCore::FocusDirection);
     82     virtual void focusedNodeChanged(WebCore::Node*);
     83     virtual WebCore::Page* createWindow(
     84         WebCore::Frame*, const WebCore::FrameLoadRequest&, const WebCore::WindowFeatures&, const WebCore::NavigationAction&, WebCore::NavigationPolicy);
     85     virtual void show(WebCore::NavigationPolicy);
     86     virtual bool canRunModal();
     87     virtual void runModal();
     88     virtual void setToolbarsVisible(bool);
     89     virtual bool toolbarsVisible();
     90     virtual void setStatusbarVisible(bool);
     91     virtual bool statusbarVisible();
     92     virtual void setScrollbarsVisible(bool);
     93     virtual bool scrollbarsVisible();
     94     virtual void setMenubarVisible(bool);
     95     virtual bool menubarVisible();
     96     virtual void setResizable(bool);
     97     virtual void addMessageToConsole(
     98         WebCore::MessageSource, WebCore::MessageLevel,
     99         const WTF::String& message, unsigned lineNumber,
    100         const WTF::String& sourceID);
    101     virtual bool canRunBeforeUnloadConfirmPanel();
    102     virtual bool runBeforeUnloadConfirmPanel(
    103         const WTF::String& message, WebCore::Frame*);
    104     virtual void closeWindowSoon();
    105     virtual void runJavaScriptAlert(WebCore::Frame*, const WTF::String&);
    106     virtual bool runJavaScriptConfirm(WebCore::Frame*, const WTF::String&);
    107     virtual bool runJavaScriptPrompt(
    108         WebCore::Frame*, const WTF::String& message,
    109         const WTF::String& defaultValue, WTF::String& result);
    110     virtual void setStatusbarText(const WTF::String& message);
    111     virtual bool tabsToLinks();
    112     virtual WebCore::IntRect windowResizerRect() const;
    113     virtual void invalidateContentsAndRootView(const WebCore::IntRect&);
    114     virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&);
    115     virtual void scheduleAnimation();
    116     virtual void scroll(
    117         const WebCore::IntSize& scrollDelta, const WebCore::IntRect& rectToScroll,
    118         const WebCore::IntRect& clipRect);
    119     virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const;
    120     virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const;
    121     virtual WebScreenInfo screenInfo() const;
    122     virtual void contentsSizeChanged(WebCore::Frame*, const WebCore::IntSize&) const;
    123     virtual void deviceOrPageScaleFactorChanged() const;
    124     virtual void didProgrammaticallyScroll(WebCore::Frame*, const WebCore::IntPoint&) const;
    125     virtual void layoutUpdated(WebCore::Frame*) const;
    126     virtual void mouseDidMoveOverElement(
    127         const WebCore::HitTestResult& result, unsigned modifierFlags);
    128     virtual void setToolTip(const WTF::String& tooltipText, WebCore::TextDirection);
    129     virtual void dispatchViewportPropertiesDidChange(const WebCore::ViewportArguments&) const;
    130     virtual void print(WebCore::Frame*);
    131     virtual void annotatedRegionsChanged();
    132     virtual bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&);
    133     virtual PassOwnPtr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient*, const WebCore::Color&) OVERRIDE;
    134     PassOwnPtr<WebColorChooser> createWebColorChooser(WebColorChooserClient*, const WebColor&);
    135     virtual PassRefPtr<WebCore::DateTimeChooser> openDateTimeChooser(WebCore::DateTimeChooserClient*, const WebCore::DateTimeChooserParameters&) OVERRIDE;
    136     virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
    137     virtual void enumerateChosenDirectory(WebCore::FileChooser*);
    138     virtual void setCursor(const WebCore::Cursor&);
    139     virtual void formStateDidChange(const WebCore::Node*);
    140     virtual void needTouchEvents(bool needTouchEvents) OVERRIDE;
    141 
    142     virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() const OVERRIDE;
    143 
    144     // Pass 0 as the GraphicsLayer to detatch the root layer.
    145     virtual void attachRootGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*);
    146 
    147     // Sets a flag to specify that the view needs to be updated, so we need
    148     // to do an eager layout before the drawing.
    149     virtual void scheduleCompositingLayerFlush();
    150 
    151     virtual CompositingTriggerFlags allowedCompositingTriggers() const;
    152 
    153     virtual void enterFullScreenForElement(WebCore::Element*);
    154     virtual void exitFullScreenForElement(WebCore::Element*);
    155 
    156     // ChromeClient methods:
    157     virtual void popupOpened(WebCore::PopupContainer* popupContainer,
    158                              const WebCore::IntRect& bounds,
    159                              bool handleExternally);
    160     virtual void popupClosed(WebCore::PopupContainer* popupContainer);
    161     virtual void postAccessibilityNotification(WebCore::AccessibilityObject*, WebCore::AXObjectCache::AXNotification);
    162     virtual String acceptLanguages() OVERRIDE;
    163 
    164     // ChromeClientImpl:
    165     void setCursorForPlugin(const WebCursorInfo&);
    166     void setNewWindowNavigationPolicy(WebNavigationPolicy);
    167 
    168     virtual bool hasOpenedPopup() const OVERRIDE;
    169     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::Frame&, WebCore::PopupMenuClient*) const;
    170     virtual WebCore::PagePopup* openPagePopup(WebCore::PagePopupClient*, const WebCore::IntRect&) OVERRIDE;
    171     virtual void closePagePopup(WebCore::PagePopup*) OVERRIDE;
    172     virtual void setPagePopupDriver(WebCore::PagePopupDriver*) OVERRIDE;
    173     virtual void resetPagePopupDriver() OVERRIDE;
    174 
    175     virtual bool isPasswordGenerationEnabled() const OVERRIDE;
    176     virtual void openPasswordGenerator(WebCore::HTMLInputElement*) OVERRIDE;
    177 
    178     virtual bool shouldRunModalDialogDuringPageDismissal(const DialogType&, const String& dialogMessage, WebCore::FrameLoader::PageDismissalType) const;
    179 
    180     virtual bool shouldRubberBandInDirection(WebCore::ScrollDirection) const;
    181     virtual void numWheelEventHandlersChanged(unsigned);
    182 
    183     virtual bool requestPointerLock();
    184     virtual void requestPointerUnlock();
    185     virtual bool isPointerLocked();
    186 
    187     virtual void didAssociateFormControls(const Vector<RefPtr<WebCore::Element> >&) OVERRIDE;
    188 
    189 private:
    190     WebNavigationPolicy getNavigationPolicy();
    191     void getPopupMenuInfo(WebCore::PopupContainer*, WebPopupMenuInfo*);
    192     void setCursor(const WebCursorInfo&);
    193 
    194     WebViewImpl* m_webView;  // weak pointer
    195     bool m_toolbarsVisible;
    196     bool m_statusbarVisible;
    197     bool m_scrollbarsVisible;
    198     bool m_menubarVisible;
    199     bool m_resizable;
    200 
    201     WebCore::PagePopupDriver* m_pagePopupDriver;
    202 };
    203 
    204 #if ENABLE(NAVIGATOR_CONTENT_UTILS)
    205 class NavigatorContentUtilsClientImpl : public WebCore::NavigatorContentUtilsClient {
    206 public:
    207     static PassOwnPtr<NavigatorContentUtilsClientImpl> create(WebViewImpl*);
    208     ~NavigatorContentUtilsClientImpl() { }
    209 
    210     virtual void registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title) OVERRIDE;
    211 
    212 private:
    213     explicit NavigatorContentUtilsClientImpl(WebViewImpl*);
    214 
    215     WebViewImpl* m_webView;
    216 };
    217 #endif
    218 
    219 } // namespace WebKit
    220 
    221 #endif
    222