Home | History | Annotate | Download | only in public
      1 /*
      2  * Copyright (C) 2010 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 "WebAudioBus.h"
     35 #include "WebAudioDevice.h"
     36 #include "WebCommon.h"
     37 #include "WebData.h"
     38 #include "WebLocalizedString.h"
     39 #include "WebSerializedScriptValue.h"
     40 #include "WebString.h"
     41 #include "WebVector.h"
     42 #include "WebURL.h"
     43 
     44 #include <time.h>
     45 
     46 #ifdef WIN32
     47 typedef void *HANDLE;
     48 #endif
     49 
     50 namespace WebKit {
     51 
     52 class WebApplicationCacheHost;
     53 class WebApplicationCacheHostClient;
     54 class WebBlobRegistry;
     55 class WebClipboard;
     56 class WebCookieJar;
     57 class WebFileSystem;
     58 class WebFileUtilities;
     59 class WebGraphicsContext3D;
     60 class WebIDBFactory;
     61 class WebIDBKey;
     62 class WebMessagePortChannel;
     63 class WebMimeRegistry;
     64 class WebPluginListBuilder;
     65 class WebSandboxSupport;
     66 class WebSharedWorkerRepository;
     67 class WebSocketStreamHandle;
     68 class WebStorageNamespace;
     69 class WebThemeEngine;
     70 class WebURLLoader;
     71 
     72 class WebKitClient {
     73 public:
     74     // Must return non-null.
     75     virtual WebClipboard* clipboard() { return 0; }
     76 
     77     // Must return non-null.
     78     virtual WebMimeRegistry* mimeRegistry() { return 0; }
     79 
     80     // Must return non-null.
     81     virtual WebFileUtilities* fileUtilities() { return 0; }
     82 
     83     // May return null if sandbox support is not necessary
     84     virtual WebSandboxSupport* sandboxSupport() { return 0; }
     85 
     86     // May return null on some platforms.
     87     virtual WebThemeEngine* themeEngine() { return 0; }
     88 
     89     // May return null.
     90     virtual WebCookieJar* cookieJar() { return 0; }
     91 
     92     // Blob ----------------------------------------------------------------
     93 
     94     // Must return non-null.
     95     virtual WebBlobRegistry* blobRegistry() { return 0; }
     96 
     97     // DOM Storage --------------------------------------------------
     98 
     99     // Return a LocalStorage namespace that corresponds to the following path.
    100     virtual WebStorageNamespace* createLocalStorageNamespace(const WebString& path, unsigned quota) { return 0; }
    101 
    102     // Called when storage events fire.
    103     virtual void dispatchStorageEvent(const WebString& key, const WebString& oldValue,
    104                                       const WebString& newValue, const WebString& origin,
    105                                       const WebURL& url, bool isLocalStorage) { }
    106 
    107 
    108     // History -------------------------------------------------------------
    109 
    110     // Returns the hash for the given canonicalized URL for use in visited
    111     // link coloring.
    112     virtual unsigned long long visitedLinkHash(
    113         const char* canonicalURL, size_t length) { return 0; }
    114 
    115     // Returns whether the given link hash is in the user's history.  The
    116     // hash must have been generated by calling VisitedLinkHash().
    117     virtual bool isLinkVisited(unsigned long long linkHash) { return false; }
    118 
    119 
    120     // HTML5 Database ------------------------------------------------------
    121 
    122 #ifdef WIN32
    123     typedef HANDLE FileHandle;
    124 #else
    125     typedef int FileHandle;
    126 #endif
    127 
    128     // Opens a database file; dirHandle should be 0 if the caller does not need
    129     // a handle to the directory containing this file
    130     virtual FileHandle databaseOpenFile(
    131         const WebString& vfsFileName, int desiredFlags) { return FileHandle(); }
    132 
    133     // Deletes a database file and returns the error code
    134     virtual int databaseDeleteFile(const WebString& vfsFileName, bool syncDir) { return 0; }
    135 
    136     // Returns the attributes of the given database file
    137     virtual long databaseGetFileAttributes(const WebString& vfsFileName) { return 0; }
    138 
    139     // Returns the size of the given database file
    140     virtual long long databaseGetFileSize(const WebString& vfsFileName) { return 0; }
    141 
    142 
    143     // Indexed Database ----------------------------------------------------
    144 
    145     virtual WebIDBFactory* idbFactory() { return 0; }
    146     virtual void createIDBKeysFromSerializedValuesAndKeyPath(const WebVector<WebSerializedScriptValue>& values,  const WebString& keyPath, WebVector<WebIDBKey>& keys) { }
    147     virtual WebSerializedScriptValue injectIDBKeyIntoSerializedValue(const WebIDBKey& key, const WebSerializedScriptValue& value, const WebString& keyPath) { return WebSerializedScriptValue(); }
    148 
    149 
    150     // Keygen --------------------------------------------------------------
    151 
    152     // Handle the <keygen> tag for generating client certificates
    153     // Returns a base64 encoded signed copy of a public key from a newly
    154     // generated key pair and the supplied challenge string. keySizeindex
    155     // specifies the strength of the key.
    156     virtual WebString signedPublicKeyAndChallengeString(unsigned keySizeIndex,
    157                                                         const WebKit::WebString& challenge,
    158                                                         const WebKit::WebURL& url) { return WebString(); }
    159 
    160 
    161 
    162     // Memory --------------------------------------------------------------
    163 
    164     // Returns the current space allocated for the pagefile, in MB.
    165     // That is committed size for Windows and virtual memory size for POSIX
    166     virtual size_t memoryUsageMB() { return 0; }
    167 
    168     // Same as above, but always returns actual value, without any caches.
    169     virtual size_t actualMemoryUsageMB() { return 0; }
    170 
    171 
    172     // Message Ports -------------------------------------------------------
    173 
    174     // Creates a Message Port Channel.  This can be called on any thread.
    175     // The returned object should only be used on the thread it was created on.
    176     virtual WebMessagePortChannel* createMessagePortChannel() { return 0; }
    177 
    178 
    179     // Network -------------------------------------------------------------
    180 
    181     // A suggestion to prefetch IP information for the given hostname.
    182     virtual void prefetchHostName(const WebString&) { }
    183 
    184     // Returns a new WebURLLoader instance.
    185     virtual WebURLLoader* createURLLoader() { return 0; }
    186 
    187     // Returns a new WebSocketStreamHandle instance.
    188     virtual WebSocketStreamHandle* createSocketStreamHandle() { return 0; }
    189 
    190     // Returns the User-Agent string that should be used for the given URL.
    191     virtual WebString userAgent(const WebURL&) { return WebString(); }
    192 
    193     // A suggestion to cache this metadata in association with this URL.
    194     virtual void cacheMetadata(const WebURL&, double responseTime, const char* data, size_t dataSize) { }
    195 
    196 
    197     // Plugins -------------------------------------------------------------
    198 
    199     // If refresh is true, then cached information should not be used to
    200     // satisfy this call.
    201     virtual void getPluginList(bool refresh, WebPluginListBuilder*) { }
    202 
    203 
    204     // Profiling -----------------------------------------------------------
    205 
    206     virtual void decrementStatsCounter(const char* name) { }
    207     virtual void incrementStatsCounter(const char* name) { }
    208 
    209     // An event is identified by the pair (name, id).  The extra parameter
    210     // specifies additional data to log with the event.
    211     virtual void traceEventBegin(const char* name, void* id, const char* extra) { }
    212     virtual void traceEventEnd(const char* name, void* id, const char* extra) { }
    213 
    214     // Callbacks for reporting histogram data.
    215     // CustomCounts histogram has exponential bucket sizes, so that min=1, max=1000000, bucketCount=50 would do.
    216     virtual void histogramCustomCounts(const char* name, int sample, int min, int max, int bucketCount) { }
    217     // Enumeration histogram buckets are linear, boundaryValue should be larger than any possible sample value.
    218     virtual void histogramEnumeration(const char* name, int sample, int boundaryValue) { }
    219 
    220 
    221     // Resources -----------------------------------------------------------
    222 
    223     // Returns a blob of data corresponding to the named resource.
    224     virtual WebData loadResource(const char* name) { return WebData(); }
    225 
    226     // Decodes the in-memory audio file data and returns the linear PCM audio data in the destinationBus.
    227     // A sample-rate conversion to sampleRate will occur if the file data is at a different sample-rate.
    228     // Returns true on success.
    229     virtual bool loadAudioResource(WebAudioBus* destinationBus, const char* audioFileData, size_t dataSize, double sampleRate) { return false; }
    230 
    231     // Returns a localized string resource (with substitution parameters).
    232     virtual WebString queryLocalizedString(WebLocalizedString::Name) { return WebString(); }
    233     virtual WebString queryLocalizedString(WebLocalizedString::Name, const WebString& parameter) { return WebString(); }
    234     virtual WebString queryLocalizedString(WebLocalizedString::Name, const WebString& parameter1, const WebString& parameter2) { return WebString(); }
    235 
    236 
    237     // Sandbox ------------------------------------------------------------
    238 
    239     // In some browsers, a "sandbox" restricts what operations a program
    240     // is allowed to preform.  Such operations are typically abstracted out
    241     // via this API, but sometimes (like in HTML 5 database opening) WebKit
    242     // needs to behave differently based on whether it's restricted or not.
    243     // In these cases (and these cases only) you can call this function.
    244     // It's OK for this value to be conservitive (i.e. true even if the
    245     // sandbox isn't active).
    246     virtual bool sandboxEnabled() { return false; }
    247 
    248 
    249     // Shared Workers ------------------------------------------------------
    250 
    251     virtual WebSharedWorkerRepository* sharedWorkerRepository() { return 0; }
    252 
    253     // Sudden Termination --------------------------------------------------
    254 
    255     // Disable/Enable sudden termination.
    256     virtual void suddenTerminationChanged(bool enabled) { }
    257 
    258 
    259     // System --------------------------------------------------------------
    260 
    261     // Returns a value such as "en-US".
    262     virtual WebString defaultLocale() { return WebString(); }
    263 
    264     // Wall clock time in seconds since the epoch.
    265     virtual double currentTime() { return 0; }
    266 
    267     virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length)
    268     {
    269         // WebKit clients must implement this funcion if they use cryptographic randomness.
    270         WEBKIT_ASSERT_NOT_REACHED();
    271     }
    272 
    273     // Delayed work is driven by a shared timer.
    274     virtual void setSharedTimerFiredFunction(void (*func)()) { }
    275     virtual void setSharedTimerFireTime(double fireTime) { }
    276     virtual void stopSharedTimer() { }
    277 
    278     // Callable from a background WebKit thread.
    279     virtual void callOnMainThread(void (*func)(void*), void* context) { }
    280 
    281     // WebGL --------------------------------------------------------------
    282 
    283     // May return null if WebGL is not supported.
    284     // Returns newly allocated WebGraphicsContext3D instance.
    285     virtual WebGraphicsContext3D* createGraphicsContext3D() { return 0; }
    286 
    287     // Audio --------------------------------------------------------------
    288 
    289     virtual double audioHardwareSampleRate() { return 0; }
    290     virtual WebAudioDevice* createAudioDevice(size_t bufferSize, unsigned numberOfChannels, double sampleRate, WebAudioDevice::RenderCallback*) { return 0; }
    291 
    292     // FileSystem ----------------------------------------------------------
    293 
    294     // Must return non-null.
    295     virtual WebFileSystem* fileSystem() { return 0; }
    296 
    297 protected:
    298     ~WebKitClient() { }
    299 };
    300 
    301 } // namespace WebKit
    302 
    303 #endif
    304