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 "modules/navigatorcontentutils/NavigatorContentUtilsClient.h"
     38 #include "platform/PopupMenu.h"
     39 #include "public/platform/WebColor.h"
     40 #include "wtf/PassOwnPtr.h"
     41 
     42 namespace WebCore {
     43 class AXObject;
     44 class ColorChooser;
     45 class ColorChooserClient;
     46 class Element;
     47 class FileChooser;
     48 class GraphicsLayerFactory;
     49 class HTMLInputElement;
     50 class KeyboardEvent;
     51 class PopupContainer;
     52 class PopupMenuClient;
     53 class RenderBox;
     54 class SecurityOrigin;
     55 class DateTimeChooser;
     56 class DateTimeChooserClient;
     57 struct WindowFeatures;
     58 }
     59 
     60 namespace blink {
     61 class WebColorChooser;
     62 class WebColorChooserClient;
     63 class WebViewImpl;
     64 struct WebCursorInfo;
     65 struct WebPopupMenuInfo;
     66 
     67 // Handles window-level notifications from WebCore on behalf of a WebView.
     68 class ChromeClientImpl : public WebCore::ChromeClient {
     69 public:
     70     explicit ChromeClientImpl(WebViewImpl* webView);
     71     virtual ~ChromeClientImpl();
     72 
     73     virtual void* webView() const;
     74 
     75     // ChromeClient methods:
     76     virtual void chromeDestroyed();
     77     virtual void setWindowRect(const WebCore::FloatRect&);
     78     virtual WebCore::FloatRect windowRect();
     79     virtual WebCore::FloatRect pageRect();
     80     virtual void focus();
     81     virtual void unfocus();
     82     virtual bool canTakeFocus(WebCore::FocusDirection);
     83     virtual void takeFocus(WebCore::FocusDirection);
     84     virtual void focusedNodeChanged(WebCore::Node*);
     85     virtual WebCore::Page* createWindow(
     86         WebCore::Frame*, const WebCore::FrameLoadRequest&, const WebCore::WindowFeatures&, WebCore::NavigationPolicy, WebCore::ShouldSendReferrer);
     87     virtual void show(WebCore::NavigationPolicy);
     88     virtual bool canRunModal();
     89     virtual void runModal();
     90     virtual void setToolbarsVisible(bool);
     91     virtual bool toolbarsVisible();
     92     virtual void setStatusbarVisible(bool);
     93     virtual bool statusbarVisible();
     94     virtual void setScrollbarsVisible(bool);
     95     virtual bool scrollbarsVisible();
     96     virtual void setMenubarVisible(bool);
     97     virtual bool menubarVisible();
     98     virtual void setResizable(bool);
     99     virtual bool shouldReportDetailedMessageForSource(const WTF::String&);
    100     virtual void addMessageToConsole(
    101         WebCore::MessageSource, WebCore::MessageLevel,
    102         const WTF::String& message, unsigned lineNumber,
    103         const WTF::String& sourceID, const WTF::String& stackTrace);
    104     virtual bool canRunBeforeUnloadConfirmPanel();
    105     virtual bool runBeforeUnloadConfirmPanel(
    106         const WTF::String& message, WebCore::Frame*);
    107     virtual void closeWindowSoon();
    108     virtual void runJavaScriptAlert(WebCore::Frame*, const WTF::String&);
    109     virtual bool runJavaScriptConfirm(WebCore::Frame*, const WTF::String&);
    110     virtual bool runJavaScriptPrompt(
    111         WebCore::Frame*, const WTF::String& message,
    112         const WTF::String& defaultValue, WTF::String& result);
    113     virtual void setStatusbarText(const WTF::String& message);
    114     virtual bool tabsToLinks();
    115     virtual WebCore::IntRect windowResizerRect() const;
    116     virtual void invalidateContentsAndRootView(const WebCore::IntRect&);
    117     virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&);
    118     virtual void scheduleAnimation();
    119     virtual bool isCompositorFramePending() const OVERRIDE;
    120     virtual void scroll(
    121         const WebCore::IntSize& scrollDelta, const WebCore::IntRect& rectToScroll,
    122         const WebCore::IntRect& clipRect);
    123     virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const;
    124     virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const;
    125     virtual WebScreenInfo screenInfo() const;
    126     virtual void contentsSizeChanged(WebCore::Frame*, const WebCore::IntSize&) const;
    127     virtual void deviceOrPageScaleFactorChanged() const;
    128     virtual void layoutUpdated(WebCore::Frame*) const;
    129     virtual void mouseDidMoveOverElement(
    130         const WebCore::HitTestResult& result, unsigned modifierFlags);
    131     virtual void setToolTip(const WTF::String& tooltipText, WebCore::TextDirection);
    132     virtual void dispatchViewportPropertiesDidChange(const WebCore::ViewportDescription&) const;
    133     virtual void print(WebCore::Frame*);
    134     virtual void annotatedRegionsChanged();
    135     virtual bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&);
    136     virtual PassOwnPtr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient*, const WebCore::Color&) OVERRIDE;
    137     virtual PassRefPtr<WebCore::DateTimeChooser> openDateTimeChooser(WebCore::DateTimeChooserClient*, const WebCore::DateTimeChooserParameters&) OVERRIDE;
    138     virtual void openTextDataListChooser(WebCore::HTMLInputElement&) OVERRIDE;
    139     virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
    140     virtual void enumerateChosenDirectory(WebCore::FileChooser*);
    141     virtual void setCursor(const WebCore::Cursor&);
    142     virtual void formStateDidChange(const WebCore::Node*);
    143     virtual void needTouchEvents(bool needTouchEvents) OVERRIDE;
    144     virtual void setTouchAction(WebCore::TouchAction) OVERRIDE;
    145 
    146     virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() const OVERRIDE;
    147 
    148     // Pass 0 as the GraphicsLayer to detatch the root layer.
    149     virtual void attachRootGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*);
    150 
    151     // Sets a flag to specify that the view needs to be updated, so we need
    152     // to do an eager layout before the drawing.
    153     virtual void scheduleCompositingLayerFlush();
    154 
    155     virtual CompositingTriggerFlags allowedCompositingTriggers() const;
    156 
    157     virtual void enterFullScreenForElement(WebCore::Element*);
    158     virtual void exitFullScreenForElement(WebCore::Element*);
    159 
    160     // ChromeClient methods:
    161     virtual void popupOpened(WebCore::PopupContainer* popupContainer,
    162                              const WebCore::IntRect& bounds,
    163                              bool handleExternally);
    164     virtual void popupClosed(WebCore::PopupContainer* popupContainer);
    165     virtual void postAccessibilityNotification(WebCore::AXObject*, WebCore::AXObjectCache::AXNotification);
    166     virtual String acceptLanguages() OVERRIDE;
    167 
    168     // ChromeClientImpl:
    169     void setCursorForPlugin(const WebCursorInfo&);
    170     void setNewWindowNavigationPolicy(WebNavigationPolicy);
    171 
    172     virtual bool hasOpenedPopup() const OVERRIDE;
    173     virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::Frame&, WebCore::PopupMenuClient*) const;
    174     virtual WebCore::PagePopup* openPagePopup(WebCore::PagePopupClient*, const WebCore::IntRect&) OVERRIDE;
    175     virtual void closePagePopup(WebCore::PagePopup*) OVERRIDE;
    176     virtual void setPagePopupDriver(WebCore::PagePopupDriver*) OVERRIDE;
    177     virtual void resetPagePopupDriver() OVERRIDE;
    178 
    179     virtual bool isPasswordGenerationEnabled() const OVERRIDE;
    180     virtual void openPasswordGenerator(WebCore::HTMLInputElement*) OVERRIDE;
    181 
    182     virtual bool shouldRunModalDialogDuringPageDismissal(const DialogType&, const String& dialogMessage, WebCore::Document::PageDismissalType) const;
    183 
    184     virtual bool shouldRubberBandInDirection(WebCore::ScrollDirection) const;
    185     virtual void numWheelEventHandlersChanged(unsigned);
    186 
    187     virtual bool requestPointerLock();
    188     virtual void requestPointerUnlock();
    189     virtual bool isPointerLocked();
    190 
    191     virtual void didAssociateFormControls(const Vector<RefPtr<WebCore::Element> >&) OVERRIDE;
    192     virtual void didChangeValueInTextField(WebCore::HTMLInputElement&) OVERRIDE;
    193     virtual void didEndEditingOnTextField(WebCore::HTMLInputElement&) OVERRIDE;
    194     virtual void handleKeyboardEventOnTextField(WebCore::HTMLInputElement&, WebCore::KeyboardEvent&) OVERRIDE;
    195 
    196     virtual void didCancelCompositionOnSelectionChange() OVERRIDE;
    197     virtual void willSetInputMethodState() OVERRIDE;
    198 
    199 private:
    200     virtual bool isChromeClientImpl() const OVERRIDE { return true; }
    201 
    202     WebNavigationPolicy getNavigationPolicy();
    203     void getPopupMenuInfo(WebCore::PopupContainer*, WebPopupMenuInfo*);
    204     void setCursor(const WebCursorInfo&);
    205 
    206     WebViewImpl* m_webView;  // weak pointer
    207     bool m_toolbarsVisible;
    208     bool m_statusbarVisible;
    209     bool m_scrollbarsVisible;
    210     bool m_menubarVisible;
    211     bool m_resizable;
    212 
    213     WebCore::PagePopupDriver* m_pagePopupDriver;
    214 };
    215 
    216 #if ENABLE(NAVIGATOR_CONTENT_UTILS)
    217 class NavigatorContentUtilsClientImpl : public WebCore::NavigatorContentUtilsClient {
    218 public:
    219     static PassOwnPtr<NavigatorContentUtilsClientImpl> create(WebViewImpl*);
    220     ~NavigatorContentUtilsClientImpl() { }
    221 
    222     virtual void registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title) OVERRIDE;
    223 
    224 private:
    225     explicit NavigatorContentUtilsClientImpl(WebViewImpl*);
    226 
    227     WebViewImpl* m_webView;
    228 };
    229 #endif
    230 
    231 inline ChromeClientImpl* toChromeClientImpl(WebCore::ChromeClient& client)
    232 {
    233     ASSERT_WITH_SECURITY_IMPLICATION(client.isChromeClientImpl());
    234     return static_cast<ChromeClientImpl*>(&client);
    235 }
    236 
    237 } // namespace blink
    238 
    239 #endif
    240