1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #pragma once
  27 
  28 #include "ChromeClient.h"
  29 #include <wtf/java/JavaEnv.h>
  30 
  31 namespace WebCore {
  32 
  33 class ChromeClientJava final : public ChromeClient {
  34 public:
  35     ChromeClientJava(const JLObject &webPage);
  36     void chromeDestroyed() override;
  37 
  38     bool isJavaChromeClient() const override { return true; }
  39     void setWindowRect(const FloatRect&) override;
  40     FloatRect windowRect() override;
  41 
  42     FloatRect pageRect() override;
  43 
  44     void focus() override;
  45     void unfocus() override;
  46 
  47     bool canTakeFocus(FocusDirection) override;
  48     void takeFocus(FocusDirection) override;
  49 
  50     void focusedElementChanged(Element*) override;
  51     void focusedFrameChanged(Frame*) override;
  52 
  53     // The Frame pointer provides the ChromeClient with context about which
  54     // Frame wants to create the new Page. Also, the newly created window
  55     // should not be shown to the user until the ChromeClient of the newly
  56     // created Page has its show method called.
  57     // The FrameLoadRequest parameter is only for ChromeClient to check if the
  58     // request could be fulfilled. The ChromeClient should not load the request.
  59     Page* createWindow(Frame&, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&) override;
  60     void show() override;
  61 
  62     bool canRunModal() override;
  63     void runModal() override;
  64 
  65     void setToolbarsVisible(bool) override;
  66     bool toolbarsVisible() override;
  67 
  68     void setStatusbarVisible(bool) override;
  69     bool statusbarVisible() override;
  70 
  71     void setScrollbarsVisible(bool) override;
  72     bool scrollbarsVisible() override;
  73 
  74     void setMenubarVisible(bool) override;
  75     bool menubarVisible() override;
  76 
  77     void setResizable(bool) override;
  78 
  79     void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) override;
  80     bool canRunBeforeUnloadConfirmPanel() override;
  81     bool runBeforeUnloadConfirmPanel(const String& message, Frame&) override;
  82 
  83     void closeWindowSoon() override;
  84 
  85     void runJavaScriptAlert(Frame&, const String&) override;
  86     bool runJavaScriptConfirm(Frame&, const String&) override;
  87     bool runJavaScriptPrompt(Frame&, const String& message, const String& defaultValue, String& result) override;
  88     void setStatusbarText(const String&) override;
  89     KeyboardUIMode keyboardUIMode() override;
  90 
  91     // Methods used by HostWindow.
  92     //
  93     void invalidateRootView(const IntRect&) override;
  94     void invalidateContentsAndRootView(const IntRect&) override;
  95     void invalidateContentsForSlowScroll(const IntRect&) override;
  96     void scroll(const IntSize&, const IntRect&, const IntRect&) override;
  97 #if USE(TILED_BACKING_STORE)
  98     void delegatedScrollRequested(const IntPoint&) override;
  99 #endif
 100     IntPoint screenToRootView(const IntPoint&) const override;
 101     IntRect rootViewToScreen(const IntRect&) const override;
 102     PlatformPageClient platformPageClient() const override;
 103     void setCursor(const Cursor&) override;
 104     void setCursorHiddenUntilMouseMoves(bool) override;
 105     // End methods used by HostWindow.
 106 
 107     void contentsSizeChanged(Frame&, const IntSize&) const override;
 108     void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) override;
 109 
 110     void setToolTip(const String&, TextDirection) override;
 111 
 112     void print(Frame&) override;
 113 
 114     void exceededDatabaseQuota(Frame&, const String& databaseName, DatabaseDetails) override;
 115 
 116     // Callback invoked when the application cache fails to save a cache object
 117     // because storing it would grow the database file past its defined maximum
 118     // size or past the amount of free space on the device.
 119     // The chrome client would need to take some action such as evicting some
 120     // old caches.
 121     void reachedMaxAppCacheSize(int64_t spaceNeeded) override;
 122 
 123     // Callback invoked when the application cache origin quota is reached. This
 124     // means that the resources attempting to be cached via the manifest are
 125     // more than allowed on this origin. This callback allows the chrome clieMediaPlayerPrivateJava.cpp:314nt
 126     // to take action, such as prompting the user to ask to increase the quota
 127     // for this origin. The totalSpaceNeeded parameter is the total amount of
 128     // storage, in bytes, needed to store the new cache along with all of the
 129     // other existing caches for the origin that would not be replaced by
 130     // the new cache.
 131     void reachedApplicationCacheOriginQuota(SecurityOrigin&, int64_t totalSpaceNeeded) override;
 132 
 133 #if ENABLE(INPUT_TYPE_COLOR)
 134     std::unique_ptr<ColorChooser> createColorChooser(ColorChooserClient&, const Color&) override;
 135 #endif
 136 
 137     void runOpenPanel(Frame&, FileChooser&) override;
 138     // Asynchronous request to load an icon for specified filenames.
 139     void loadIconForFiles(const Vector<String>&, FileIconLoader&) override;
 140 
 141 #if ENABLE(DIRECTORY_UPLOAD)
 142     // Asychronous request to enumerate all files in a directory chosen by the user.
 143     void enumerateChosenDirectory(FileChooser*) override;
 144 #endif
 145 
 146 #if USE(ACCELERATED_COMPOSITING)
 147     // Allows ports to customize the type of graphics layers created by this page.
 148     GraphicsLayerFactory* graphicsLayerFactory() const { return 0; }
 149 
 150     // Pass 0 as the GraphicsLayer to detatch the root layer.
 151     void attachRootGraphicsLayer(Frame*, GraphicsLayer*) override;
 152     // Sets a flag to specify that the next time content is drawn to the window,
 153     // the changes appear on the screen in synchrony with updates to GraphicsLayers.
 154     void setNeedsOneShotDrawingSynchronization() override;
 155     // Sets a flag to specify that the view needs to be updated, so we need
 156     // to do an eager layout before the drawing.
 157     void scheduleCompositingLayerFlush() override;
 158 #else //XXX: implement?
 159     void attachRootGraphicsLayer(Frame&, GraphicsLayer*) override {}
 160     void setNeedsOneShotDrawingSynchronization() override {}
 161     void scheduleCompositingLayerFlush() override {}
 162 #endif
 163     void attachViewOverlayGraphicsLayer(Frame&, GraphicsLayer*) override;
 164 
 165 #if ENABLE(TOUCH_EVENTS)
 166     void needTouchEvents(bool) override {};
 167 #endif
 168 
 169     bool selectItemWritingDirectionIsNatural() override;
 170     bool selectItemAlignmentFollowsMenuWritingDirection() override;
 171     RefPtr<PopupMenu> createPopupMenu(PopupMenuClient&) const override;
 172     RefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient&) const override;
 173 
 174     void wheelEventHandlersChanged(bool) override {};
 175 
 176     RefPtr<Icon> createIconForFiles(const Vector<String>&) override;
 177 
 178     JLObject platformPage() { return m_webPage; } //utatodo:check usage
 179 
 180 
 181 private:
 182     void repaint(const IntRect&);
 183     JGObject m_webPage;
 184 };
 185 
 186 } // namespace WebCore