Home | History | Annotate | Download | only in public
      1 /*
      2  * Copyright (C) 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 WebKitClient_h
     32 #define WebKitClient_h
     33 
     34 #include "WebCommon.h"
     35 #include "WebData.h"
     36 #include "WebLocalizedString.h"
     37 #include "WebString.h"
     38 #include "WebURL.h"
     39 #include "WebVector.h"
     40 
     41 #include <time.h>
     42 
     43 #ifdef WIN32
     44 typedef void *HANDLE;
     45 #endif
     46 
     47 namespace WebKit {
     48 
     49 class WebApplicationCacheHost;
     50 class WebApplicationCacheHostClient;
     51 class WebClipboard;
     52 class WebMessagePortChannel;
     53 class WebMimeRegistry;
     54 class WebPluginListBuilder;
     55 class WebSandboxSupport;
     56 class WebSharedWorkerRepository;
     57 class WebSocketStreamHandle;
     58 class WebStorageNamespace;
     59 class WebThemeEngine;
     60 class WebURLLoader;
     61 struct WebCookie;
     62 template <typename T> class WebVector;
     63 
     64 class WebKitClient {
     65 public:
     66     // Must return non-null.
     67     virtual WebClipboard* clipboard() { return 0; }
     68 
     69     // Must return non-null.
     70     virtual WebMimeRegistry* mimeRegistry() { return 0; }
     71 
     72     // May return null if sandbox support is not necessary
     73     virtual WebSandboxSupport* sandboxSupport() { return 0; }
     74 
     75     // May return null on some platforms.
     76     virtual WebThemeEngine* themeEngine() { return 0; }
     77 
     78 
     79     // Application Cache --------------------------------------------
     80 
     81     // May return null if the process type doesn't involve appcaching.
     82     virtual WebApplicationCacheHost* createApplicationCacheHost(WebApplicationCacheHostClient*) { return 0; }
     83 
     84 
     85     // DOM Storage --------------------------------------------------
     86 
     87     // Return a LocalStorage namespace that corresponds to the following path.
     88     virtual WebStorageNamespace* createLocalStorageNamespace(const WebString& path, unsigned quota) { return 0; }
     89 
     90     // Return a new SessionStorage namespace.
     91     // THIS IS DEPRECATED.  WebViewClient::getSessionStorageNamespace() is the new way to access this.
     92     virtual WebStorageNamespace* createSessionStorageNamespace() { return 0; }
     93 
     94     // Called when storage events fire.
     95     virtual void dispatchStorageEvent(const WebString& key, const WebString& oldValue,
     96                                       const WebString& newValue, const WebString& origin,
     97                                       const WebURL& url, bool isLocalStorage) { }
     98 
     99 
    100     // File ----------------------------------------------------------------
    101 
    102     // Various file/directory related functions.  These map 1:1 with
    103     // functions in WebCore's FileSystem.h.
    104     virtual bool fileExists(const WebString& path) { return false; }
    105     virtual bool deleteFile(const WebString& path) { return false; }
    106     virtual bool deleteEmptyDirectory(const WebString& path) { return false; }
    107     virtual bool getFileSize(const WebString& path, long long& result) { return false; }
    108     virtual bool getFileModificationTime(const WebString& path, time_t& result) { return false; }
    109     virtual WebString directoryName(const WebString& path) { return WebString(); }
    110     virtual WebString pathByAppendingComponent(const WebString& path, const WebString& component) { return WebString(); }
    111     virtual bool makeAllDirectories(const WebString& path) { return false; }
    112     virtual WebString getAbsolutePath(const WebString& path) { return WebString(); }
    113     virtual bool isDirectory(const WebString& path) { return false; }
    114     virtual WebURL filePathToURL(const WebString& path) { return WebURL(); }
    115 
    116 
    117     // History -------------------------------------------------------------
    118 
    119     // Returns the hash for the given canonicalized URL for use in visited
    120     // link coloring.
    121     virtual unsigned long long visitedLinkHash(
    122         const char* canonicalURL, size_t length) { return 0; }
    123 
    124     // Returns whether the given link hash is in the user's history.  The
    125     // hash must have been generated by calling VisitedLinkHash().
    126     virtual bool isLinkVisited(unsigned long long linkHash) { return false; }
    127 
    128 
    129     // Database ------------------------------------------------------------
    130 
    131 #ifdef WIN32
    132     typedef HANDLE FileHandle;
    133 #else
    134     typedef int FileHandle;
    135 #endif
    136 
    137     // Opens a database file; dirHandle should be 0 if the caller does not need
    138     // a handle to the directory containing this file
    139     virtual FileHandle databaseOpenFile(
    140         const WebString& vfsFileName, int desiredFlags, FileHandle* dirHandle) { return FileHandle(); }
    141 
    142     // Deletes a database file and returns the error code
    143     virtual int databaseDeleteFile(const WebString& vfsFileName, bool syncDir) { return 0; }
    144 
    145     // Returns the attributes of the given database file
    146     virtual long databaseGetFileAttributes(const WebString& vfsFileName) { return 0; }
    147 
    148     // Returns the size of the given database file
    149     virtual long long databaseGetFileSize(const WebString& vfsFileName) { return 0; }
    150 
    151 
    152     // Keygen --------------------------------------------------------------
    153 
    154     // Handle the <keygen> tag for generating client certificates
    155     // Returns a base64 encoded signed copy of a public key from a newly
    156     // generated key pair and the supplied challenge string. keySizeindex
    157     // specifies the strength of the key.
    158     virtual WebString signedPublicKeyAndChallengeString(unsigned keySizeIndex,
    159                                                         const WebKit::WebString& challenge,
    160                                                         const WebKit::WebURL& url) { return WebString(); }
    161 
    162 
    163 
    164     // Memory --------------------------------------------------------------
    165 
    166     // Returns the current space allocated for the pagefile, in MB.
    167     // That is committed size for Windows and virtual memory size for POSIX
    168     virtual size_t memoryUsageMB() { return 0; }
    169 
    170 
    171     // Message Ports -------------------------------------------------------
    172 
    173     // Creates a Message Port Channel.  This can be called on any thread.
    174     // The returned object should only be used on the thread it was created on.
    175     virtual WebMessagePortChannel* createMessagePortChannel() { return 0; }
    176 
    177 
    178     // Network -------------------------------------------------------------
    179 
    180     virtual void setCookies(
    181         const WebURL& url, const WebURL& firstPartyForCookies, const WebString& cookies) { }
    182     virtual WebString cookies(const WebURL& url, const WebURL& firstPartyForCookies) { return WebString(); }
    183     virtual bool rawCookies(const WebURL& url, const WebURL& firstPartyForCookies, WebVector<WebCookie>*) { return false; }
    184     virtual void deleteCookie(const WebURL& url, const WebString& cookieName) { }
    185     virtual bool cookiesEnabled(const WebURL& url, const WebURL& firstPartyForCookies) { return true; }
    186 
    187     // A suggestion to prefetch IP information for the given hostname.
    188     virtual void prefetchHostName(const WebString&) { }
    189 
    190     // Returns a new WebURLLoader instance.
    191     virtual WebURLLoader* createURLLoader() { return 0; }
    192 
    193     // Returns a new WebSocketStreamHandle instance.
    194     virtual WebSocketStreamHandle* createSocketStreamHandle() { return 0; }
    195 
    196     // Returns the User-Agent string that should be used for the given URL.
    197     virtual WebString userAgent(const WebURL&) { return WebString(); }
    198 
    199 
    200     // Plugins -------------------------------------------------------------
    201 
    202     // If refresh is true, then cached information should not be used to
    203     // satisfy this call.
    204     virtual void getPluginList(bool refresh, WebPluginListBuilder*) { }
    205 
    206 
    207     // Profiling -----------------------------------------------------------
    208 
    209     virtual void decrementStatsCounter(const char* name) { }
    210     virtual void incrementStatsCounter(const char* name) { }
    211 
    212     // An event is identified by the pair (name, id).  The extra parameter
    213     // specifies additional data to log with the event.
    214     virtual void traceEventBegin(const char* name, void* id, const char* extra) { }
    215     virtual void traceEventEnd(const char* name, void* id, const char* extra) { }
    216 
    217     // Generic callback for reporting histogram data. Range is identified by the min, max pair.
    218     // By default, histogram is exponential, so that min=1, max=1000000, bucketCount=50 would do. Setting
    219     // linear to true would require bucket count to cover whole min-max range.
    220     virtual void histogramCounts(const WebString& name, int sample, int min, int max, int bucketCount, bool linear) { }
    221 
    222 
    223     // Resources -----------------------------------------------------------
    224 
    225     // Returns a blob of data corresponding to the named resource.
    226     virtual WebData loadResource(const char* name) { return WebData(); }
    227 
    228     // Returns a localized string resource (with an optional numeric
    229     // parameter value).
    230     virtual WebString queryLocalizedString(WebLocalizedString::Name) { return WebString(); }
    231     virtual WebString queryLocalizedString(WebLocalizedString::Name, int numericValue) { return WebString(); }
    232 
    233 
    234     // Sandbox ------------------------------------------------------------
    235 
    236     // In some browsers, a "sandbox" restricts what operations a program
    237     // is allowed to preform.  Such operations are typically abstracted out
    238     // via this API, but sometimes (like in HTML 5 database opening) WebKit
    239     // needs to behave differently based on whether it's restricted or not.
    240     // In these cases (and these cases only) you can call this function.
    241     // It's OK for this value to be conservitive (i.e. true even if the
    242     // sandbox isn't active).
    243     virtual bool sandboxEnabled() { return false; }
    244 
    245 
    246     // Shared Workers ------------------------------------------------------
    247 
    248     virtual WebSharedWorkerRepository* sharedWorkerRepository() { return 0; }
    249 
    250     // Sudden Termination --------------------------------------------------
    251 
    252     // Disable/Enable sudden termination.
    253     virtual void suddenTerminationChanged(bool enabled) { }
    254 
    255 
    256     // System --------------------------------------------------------------
    257 
    258     // Returns a value such as "en-US".
    259     virtual WebString defaultLocale() { return WebString(); }
    260 
    261     // Wall clock time in seconds since the epoch.
    262     virtual double currentTime() { return 0; }
    263 
    264     // Delayed work is driven by a shared timer.
    265     virtual void setSharedTimerFiredFunction(void (*func)()) { }
    266     virtual void setSharedTimerFireTime(double fireTime) { }
    267     virtual void stopSharedTimer() { }
    268 
    269     // Callable from a background WebKit thread.
    270     virtual void callOnMainThread(void (*func)()) { }
    271 
    272 protected:
    273     ~WebKitClient() { }
    274 };
    275 
    276 } // namespace WebKit
    277 
    278 #endif
    279