Home | History | Annotate | Download | only in WebCoreSupport
      1 /*
      2  * Copyright 2007, The Android Open Source Project
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *  * Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  *  * Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef ChromeClientAndroid_h
     27 #define ChromeClientAndroid_h
     28 
     29 #include "ChromeClient.h"
     30 
     31 #include "GeolocationPermissions.h"
     32 #include "PopupMenu.h"
     33 #include "SearchPopupMenu.h"
     34 #include "Timer.h"
     35 #include <wtf/PassRefPtr.h>
     36 #include <wtf/Threading.h>
     37 
     38 namespace WebCore {
     39 class PopupMenuClient;
     40 class Geolocation;
     41 }
     42 
     43 using namespace WebCore;
     44 
     45 namespace android {
     46     class WebFrame;
     47 
     48     class ChromeClientAndroid : public ChromeClient {
     49     public:
     50         ChromeClientAndroid() : m_webFrame(0), m_geolocationPermissions(0)
     51 #if USE(ACCELERATED_COMPOSITING)
     52                                 , m_rootGraphicsLayer(0)
     53                                 , m_needsLayerSync(false)
     54 #endif
     55                                 , m_triedToReclaimDBQuota(false)
     56                                 { }
     57         virtual void chromeDestroyed();
     58 
     59         virtual void setWindowRect(const FloatRect&);
     60         virtual FloatRect windowRect();
     61 
     62         virtual FloatRect pageRect();
     63 
     64         virtual float scaleFactor();
     65 
     66         virtual void focus();
     67         virtual void unfocus();
     68         virtual void formDidBlur(const WebCore::Node*);
     69         virtual bool canTakeFocus(FocusDirection);
     70         virtual void takeFocus(FocusDirection);
     71 
     72         virtual void focusedNodeChanged(Node*);
     73         virtual void focusedFrameChanged(Frame*);
     74 
     75         // The Frame pointer provides the ChromeClient with context about which
     76         // Frame wants to create the new Page.  Also, the newly created window
     77         // should not be shown to the user until the ChromeClient of the newly
     78         // created Page has its show method called.
     79         virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&);
     80         virtual void show();
     81 
     82         virtual bool canRunModal();
     83         virtual void runModal();
     84 
     85         virtual void setToolbarsVisible(bool);
     86         virtual bool toolbarsVisible();
     87 
     88         virtual void setStatusbarVisible(bool);
     89         virtual bool statusbarVisible();
     90 
     91         virtual void setScrollbarsVisible(bool);
     92         virtual bool scrollbarsVisible();
     93 
     94         virtual void setMenubarVisible(bool);
     95         virtual bool menubarVisible();
     96 
     97         virtual void setResizable(bool);
     98 
     99         virtual void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned int lineNumber, const String& sourceID);
    100 
    101         virtual bool canRunBeforeUnloadConfirmPanel();
    102         virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame);
    103 
    104         virtual void closeWindowSoon();
    105 
    106         virtual void runJavaScriptAlert(Frame*, const String&);
    107         virtual bool runJavaScriptConfirm(Frame*, const String&);
    108         virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result);
    109         virtual void setStatusbarText(const String&);
    110         virtual bool shouldInterruptJavaScript();
    111         virtual KeyboardUIMode keyboardUIMode();
    112 
    113         virtual IntRect windowResizerRect() const;
    114 
    115         // Methods used by HostWindow.
    116         virtual void invalidateWindow(const WebCore::IntRect&, bool);
    117         virtual void invalidateContentsAndWindow(const WebCore::IntRect&, bool);
    118         virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&, bool);
    119         virtual void scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect);
    120         virtual IntPoint screenToWindow(const IntPoint&) const;
    121         virtual IntRect windowToScreen(const IntRect&) const;
    122         virtual PlatformPageClient platformPageClient() const;
    123         virtual void contentsSizeChanged(Frame*, const IntSize&) const;
    124         virtual void scrollRectIntoView(const IntRect&, const ScrollView*) const;
    125         // End methods used by HostWindow.
    126 
    127         virtual void dispatchViewportDataDidChange(const ViewportArguments&) const;
    128 
    129         virtual void scrollbarsModeDidChange() const;
    130         virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned int);
    131 
    132         virtual void setToolTip(const String&, TextDirection);
    133 
    134         virtual void print(Frame*);
    135 #if ENABLE(DATABASE)
    136         virtual void exceededDatabaseQuota(Frame*, const String&);
    137 #endif
    138 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
    139         virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
    140         virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*);
    141 #endif
    142 
    143 	virtual void populateVisitedLinks();
    144 
    145 #if ENABLE(TOUCH_EVENTS)
    146         virtual void needTouchEvents(bool);
    147 #endif
    148 
    149         // Methods used to request and provide Geolocation permissions.
    150         virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
    151         virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*);
    152         // Android-specific
    153         void provideGeolocationPermissions(const String &origin, bool allow, bool remember);
    154         void storeGeolocationPermissions();
    155         void onMainFrameLoadStarted();
    156 
    157         virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
    158         virtual void setCursor(const Cursor&);
    159         virtual void chooseIconForFiles(const WTF::Vector<WTF::String>&, FileChooser*);
    160 
    161         // Notification that the given form element has changed. This function
    162         // will be called frequently, so handling should be very fast.
    163         virtual void formStateDidChange(const Node*);
    164 
    165         // Android-specific
    166         void setWebFrame(android::WebFrame* webframe);
    167         android::WebFrame* webFrame() { return m_webFrame; }
    168         void wakeUpMainThreadWithNewQuota(long long newQuota);
    169 
    170 #if USE(ACCELERATED_COMPOSITING)
    171         virtual void attachRootGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer* g);
    172         virtual void setNeedsOneShotDrawingSynchronization();
    173         virtual void scheduleCompositingLayerSync();
    174         virtual bool allowsAcceleratedCompositing() const { return true; }
    175         WebCore::GraphicsLayer* layersSync();
    176 #endif
    177 
    178         virtual bool selectItemWritingDirectionIsNatural();
    179         virtual bool selectItemAlignmentFollowsMenuWritingDirection();
    180         virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const;
    181         virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const;
    182 
    183 #if ENABLE(CONTEXT_MENUS)
    184         virtual void showContextMenu();
    185 #endif
    186 
    187 #if ENABLE(ANDROID_INSTALLABLE_WEB_APPS)
    188         virtual void webAppCanBeInstalled();
    189 #endif
    190 
    191 #if ENABLE(FULLSCREEN_API)
    192         virtual void exitFullScreenForElement(Element*);
    193 #endif
    194 
    195 #if ENABLE(VIDEO)
    196         virtual bool supportsFullscreenForNode(const WebCore::Node*);
    197         virtual void enterFullscreenForNode(WebCore::Node*);
    198         virtual void exitFullscreenForNode(WebCore::Node*);
    199 #endif
    200 
    201         virtual void* webView() const { return 0; }
    202 
    203     private:
    204         android::WebFrame* m_webFrame;
    205         // The Geolocation permissions manager.
    206         OwnPtr<GeolocationPermissions> m_geolocationPermissions;
    207 #if USE(ACCELERATED_COMPOSITING)
    208         WebCore::GraphicsLayer* m_rootGraphicsLayer;
    209         bool m_needsLayerSync;
    210 #endif
    211         WTF::ThreadCondition m_quotaThreadCondition;
    212         WTF::Mutex m_quotaThreadLock;
    213         unsigned long long m_newQuota;
    214         bool m_isNewQuotaSet;
    215         bool m_triedToReclaimDBQuota;
    216     };
    217 
    218 }
    219 
    220 #endif
    221