Home | History | Annotate | Download | only in chromium
      1 /*
      2  * Copyright (c) 2008, 2009, Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef ChromiumBridge_h
     32 #define ChromiumBridge_h
     33 
     34 #include "FileSystem.h"
     35 #include "ImageSource.h"
     36 #include "LinkHash.h"
     37 #include "PassRefPtr.h"
     38 #include "PasteboardPrivate.h"
     39 
     40 #include <wtf/Vector.h>
     41 
     42 typedef struct NPObject NPObject;
     43 typedef struct _NPP NPP_t;
     44 typedef NPP_t* NPP;
     45 
     46 #if OS(WINDOWS)
     47 typedef struct HFONT__* HFONT;
     48 #endif
     49 
     50 namespace WebCore {
     51 
     52     class Color;
     53     class Cursor;
     54     class Document;
     55     class Frame;
     56     class GraphicsContext;
     57     class Image;
     58     class IntRect;
     59     class KURL;
     60     class String;
     61     class Widget;
     62 
     63     struct Cookie;
     64     struct PluginInfo;
     65 
     66     // An interface to the embedding layer, which has the ability to answer
     67     // questions about the system and so on...
     68 
     69     class ChromiumBridge {
     70     public:
     71         // Clipboard ----------------------------------------------------------
     72         static bool clipboardIsFormatAvailable(PasteboardPrivate::ClipboardFormat, PasteboardPrivate::ClipboardBuffer);
     73 
     74         static String clipboardReadPlainText(PasteboardPrivate::ClipboardBuffer);
     75         static void clipboardReadHTML(PasteboardPrivate::ClipboardBuffer, String*, KURL*);
     76 
     77         // Only the clipboardRead functions take a buffer argument because
     78         // Chromium currently uses a different technique to write to alternate
     79         // clipboard buffers.
     80         static void clipboardWriteSelection(const String&, const KURL&, const String&, bool);
     81         static void clipboardWritePlainText(const String&);
     82         static void clipboardWriteURL(const KURL&, const String&);
     83         static void clipboardWriteImage(NativeImagePtr, const KURL&, const String&);
     84 
     85         // Cookies ------------------------------------------------------------
     86         static void setCookies(const KURL& url, const KURL& firstPartyForCookies, const String& value);
     87         static String cookies(const KURL& url, const KURL& firstPartyForCookies);
     88         static String cookieRequestHeaderFieldValue(const KURL& url, const KURL& firstPartyForCookies);
     89         static bool rawCookies(const KURL& url, const KURL& firstPartyForCookies, Vector<Cookie>*);
     90         static void deleteCookie(const KURL& url, const String& cookieName);
     91         static bool cookiesEnabled(const KURL& url, const KURL& firstPartyForCookies);
     92 
     93         // DNS ----------------------------------------------------------------
     94         static void prefetchDNS(const String& hostname);
     95 
     96         // File ---------------------------------------------------------------
     97         static bool fileExists(const String&);
     98         static bool deleteFile(const String&);
     99         static bool deleteEmptyDirectory(const String&);
    100         static bool getFileSize(const String&, long long& result);
    101         static bool getFileModificationTime(const String&, time_t& result);
    102         static String directoryName(const String& path);
    103         static String pathByAppendingComponent(const String& path, const String& component);
    104         static bool makeAllDirectories(const String& path);
    105         static String getAbsolutePath(const String&);
    106         static bool isDirectory(const String&);
    107         static KURL filePathToURL(const String&);
    108 
    109         // Font ---------------------------------------------------------------
    110 #if OS(WINDOWS)
    111         static bool ensureFontLoaded(HFONT font);
    112 #endif
    113 #if OS(LINUX)
    114         static String getFontFamilyForCharacters(const UChar*, size_t numCharacters);
    115 #endif
    116 
    117         // Forms --------------------------------------------------------------
    118         static void notifyFormStateChanged(const Document*);
    119 
    120         // HTML5 DB -----------------------------------------------------------
    121 #if ENABLE(DATABASE)
    122         // Returns a handle to the DB file and ooptionally a handle to its containing directory
    123         static PlatformFileHandle databaseOpenFile(const String& vfsFleName, int desiredFlags, PlatformFileHandle* dirHandle = 0);
    124         // Returns a SQLite code (SQLITE_OK = 0, on success)
    125         static int databaseDeleteFile(const String& vfsFileName, bool syncDir = false);
    126         // Returns the attributes of the DB file
    127         static long databaseGetFileAttributes(const String& vfsFileName);
    128         // Returns the size of the DB file
    129         static long long databaseGetFileSize(const String& vfsFileName);
    130 #endif
    131 
    132         // JavaScript ---------------------------------------------------------
    133         static void notifyJSOutOfMemory(Frame*);
    134         static bool allowScriptDespiteSettings(const KURL& documentURL);
    135 
    136         // Keygen -------------------------------------------------------------
    137         static String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& challenge, const KURL& url);
    138 
    139         // Language -----------------------------------------------------------
    140         static String computedDefaultLanguage();
    141 
    142         // LayoutTestMode -----------------------------------------------------
    143         static bool layoutTestMode();
    144 
    145         // Memory -------------------------------------------------------------
    146         // Returns the current space allocated for the pagefile, in MB.
    147         // That is committed size for Windows and virtual memory size for POSIX
    148         static int memoryUsageMB();
    149 
    150         // MimeType -----------------------------------------------------------
    151         static bool isSupportedImageMIMEType(const String& mimeType);
    152         static bool isSupportedJavaScriptMIMEType(const String& mimeType);
    153         static bool isSupportedNonImageMIMEType(const String& mimeType);
    154         static String mimeTypeForExtension(const String& fileExtension);
    155         static String mimeTypeFromFile(const String& filePath);
    156         static String preferredExtensionForMIMEType(const String& mimeType);
    157 
    158         // Plugin -------------------------------------------------------------
    159         static bool plugins(bool refresh, Vector<PluginInfo*>*);
    160         static NPObject* pluginScriptableObject(Widget*);
    161         static bool popupsAllowed(NPP);
    162 
    163         // Resources ----------------------------------------------------------
    164         static PassRefPtr<Image> loadPlatformImageResource(const char* name);
    165 
    166         // Sandbox ------------------------------------------------------------
    167         static bool sandboxEnabled();
    168 
    169         // Screen -------------------------------------------------------------
    170         static int screenDepth(Widget*);
    171         static int screenDepthPerComponent(Widget*);
    172         static bool screenIsMonochrome(Widget*);
    173         static IntRect screenRect(Widget*);
    174         static IntRect screenAvailableRect(Widget*);
    175 
    176         // SharedTimers -------------------------------------------------------
    177         static void setSharedTimerFiredFunction(void (*func)());
    178         static void setSharedTimerFireTime(double fireTime);
    179         static void stopSharedTimer();
    180 
    181         // StatsCounters ------------------------------------------------------
    182         static void decrementStatsCounter(const char* name);
    183         static void incrementStatsCounter(const char* name);
    184 
    185         // Sudden Termination
    186         static void suddenTerminationChanged(bool enabled);
    187 
    188         // SystemTime ---------------------------------------------------------
    189         static double currentTime();
    190 
    191         // Theming ------------------------------------------------------------
    192 #if OS(WINDOWS)
    193         static void paintButton(
    194             GraphicsContext*, int part, int state, int classicState, const IntRect&);
    195         static void paintMenuList(
    196             GraphicsContext*, int part, int state, int classicState, const IntRect&);
    197         static void paintScrollbarArrow(
    198             GraphicsContext*, int state, int classicState, const IntRect&);
    199         static void paintScrollbarThumb(
    200             GraphicsContext*, int part, int state, int classicState, const IntRect&);
    201         static void paintScrollbarTrack(
    202             GraphicsContext*, int part, int state, int classicState, const IntRect&, const IntRect& alignRect);
    203         static void paintTextField(
    204             GraphicsContext*, int part, int state, int classicState, const IntRect&, const Color&, bool fillContentArea, bool drawEdges);
    205         static void paintTrackbar(
    206             GraphicsContext*, int part, int state, int classicState, const IntRect&);
    207 #endif
    208 
    209         // Trace Event --------------------------------------------------------
    210         static void traceEventBegin(const char* name, void* id, const char* extra);
    211         static void traceEventEnd(const char* name, void* id, const char* extra);
    212 
    213         // Visited links ------------------------------------------------------
    214         static LinkHash visitedLinkHash(const UChar* url, unsigned length);
    215         static LinkHash visitedLinkHash(const KURL& base, const AtomicString& attributeURL);
    216         static bool isLinkVisited(LinkHash);
    217 
    218         // Widget -------------------------------------------------------------
    219         static void widgetSetCursor(Widget*, const Cursor&);
    220         static void widgetSetFocus(Widget*);
    221     };
    222 
    223 } // namespace WebCore
    224 
    225 #endif
    226