Home | History | Annotate | Download | only in child
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef WEBKIT_CHILD_WEBKITPLATFORMSUPPORT_IMPL_H_
      6 #define WEBKIT_CHILD_WEBKITPLATFORMSUPPORT_IMPL_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "base/debug/trace_event.h"
     10 #include "base/platform_file.h"
     11 #include "base/timer/timer.h"
     12 #include "third_party/WebKit/public/platform/Platform.h"
     13 #include "third_party/WebKit/public/platform/WebURLError.h"
     14 #include "ui/base/layout.h"
     15 #include "webkit/child/resource_loader_bridge.h"
     16 #include "webkit/child/webkit_child_export.h"
     17 
     18 namespace base {
     19 class MessageLoop;
     20 }
     21 
     22 namespace WebKit {
     23 class WebSocketStreamHandle;
     24 }
     25 
     26 namespace webkit_glue {
     27 
     28 class WebSocketStreamHandleDelegate;
     29 class WebSocketStreamHandleBridge;
     30 
     31 class WEBKIT_CHILD_EXPORT WebKitPlatformSupportImpl :
     32     NON_EXPORTED_BASE(public WebKit::Platform) {
     33  public:
     34   WebKitPlatformSupportImpl();
     35   virtual ~WebKitPlatformSupportImpl();
     36 
     37   // Platform methods (partial implementation):
     38   virtual base::PlatformFile databaseOpenFile(
     39       const WebKit::WebString& vfs_file_name, int desired_flags);
     40   virtual int databaseDeleteFile(const WebKit::WebString& vfs_file_name,
     41                                  bool sync_dir);
     42   virtual long databaseGetFileAttributes(
     43       const WebKit::WebString& vfs_file_name);
     44   virtual long long databaseGetFileSize(const WebKit::WebString& vfs_file_name);
     45   virtual long long databaseGetSpaceAvailableForOrigin(
     46       const WebKit::WebString& origin_identifier);
     47   virtual WebKit::WebString signedPublicKeyAndChallengeString(
     48       unsigned key_size_index, const WebKit::WebString& challenge,
     49       const WebKit::WebURL& url);
     50   virtual size_t memoryUsageMB();
     51   virtual size_t actualMemoryUsageMB();
     52 
     53   virtual void startHeapProfiling(const WebKit::WebString& prefix);
     54   virtual void stopHeapProfiling() OVERRIDE;
     55   virtual void dumpHeapProfiling(const WebKit::WebString& reason);
     56   virtual WebKit::WebString getHeapProfile() OVERRIDE;
     57 
     58   virtual bool processMemorySizesInBytes(size_t* private_bytes,
     59                                          size_t* shared_bytes);
     60   virtual bool memoryAllocatorWasteInBytes(size_t* size);
     61   virtual WebKit::WebURLLoader* createURLLoader();
     62   virtual WebKit::WebSocketStreamHandle* createSocketStreamHandle();
     63   virtual WebKit::WebString userAgent(const WebKit::WebURL& url);
     64   virtual WebKit::WebData parseDataURL(
     65       const WebKit::WebURL& url, WebKit::WebString& mimetype,
     66       WebKit::WebString& charset);
     67   virtual WebKit::WebURLError cancelledError(const WebKit::WebURL& url) const;
     68   virtual void decrementStatsCounter(const char* name);
     69   virtual void incrementStatsCounter(const char* name);
     70   virtual void histogramCustomCounts(
     71     const char* name, int sample, int min, int max, int bucket_count);
     72   virtual void histogramEnumeration(
     73     const char* name, int sample, int boundary_value);
     74   virtual void histogramSparse(const char* name, int sample);
     75   virtual const unsigned char* getTraceCategoryEnabledFlag(
     76       const char* category_name);
     77   virtual long* getTraceSamplingState(const unsigned thread_bucket);
     78   virtual void addTraceEvent(
     79       char phase,
     80       const unsigned char* category_group_enabled,
     81       const char* name,
     82       unsigned long long id,
     83       int num_args,
     84       const char** arg_names,
     85       const unsigned char* arg_types,
     86       const unsigned long long* arg_values,
     87       unsigned char flags);
     88   virtual WebKit::WebData loadResource(const char* name);
     89   virtual WebKit::WebString queryLocalizedString(
     90       WebKit::WebLocalizedString::Name name);
     91   virtual WebKit::WebString queryLocalizedString(
     92       WebKit::WebLocalizedString::Name name, int numeric_value);
     93   virtual WebKit::WebString queryLocalizedString(
     94       WebKit::WebLocalizedString::Name name, const WebKit::WebString& value);
     95   virtual WebKit::WebString queryLocalizedString(
     96       WebKit::WebLocalizedString::Name name,
     97       const WebKit::WebString& value1, const WebKit::WebString& value2);
     98   virtual void suddenTerminationChanged(bool enabled) { }
     99   virtual double currentTime();
    100   virtual double monotonicallyIncreasingTime();
    101   virtual void cryptographicallyRandomValues(
    102       unsigned char* buffer, size_t length);
    103   virtual void setSharedTimerFiredFunction(void (*func)());
    104   virtual void setSharedTimerFireInterval(double interval_seconds);
    105   virtual void stopSharedTimer();
    106   virtual void callOnMainThread(void (*func)(void*), void* context);
    107 
    108 
    109   // Embedder functions. The following are not implemented by the glue layer and
    110   // need to be specialized by the embedder.
    111 
    112   // Gets a localized string given a message id.  Returns an empty string if the
    113   // message id is not found.
    114   virtual base::string16 GetLocalizedString(int message_id) = 0;
    115 
    116   // Returns the raw data for a resource.  This resource must have been
    117   // specified as BINDATA in the relevant .rc file.
    118   virtual base::StringPiece GetDataResource(int resource_id,
    119                                             ui::ScaleFactor scale_factor) = 0;
    120 
    121   // Creates a ResourceLoaderBridge.
    122   virtual ResourceLoaderBridge* CreateResourceLoader(
    123       const ResourceLoaderBridge::RequestInfo& request_info) = 0;
    124   // Creates a WebSocketStreamHandleBridge.
    125   virtual WebSocketStreamHandleBridge* CreateWebSocketBridge(
    126       WebKit::WebSocketStreamHandle* handle,
    127       WebSocketStreamHandleDelegate* delegate) = 0;
    128 
    129   void SuspendSharedTimer();
    130   void ResumeSharedTimer();
    131   virtual void OnStartSharedTimer(base::TimeDelta delay) {}
    132 
    133  private:
    134   void DoTimeout() {
    135     if (shared_timer_func_ && !shared_timer_suspended_)
    136       shared_timer_func_();
    137   }
    138 
    139   base::MessageLoop* main_loop_;
    140   base::OneShotTimer<WebKitPlatformSupportImpl> shared_timer_;
    141   void (*shared_timer_func_)();
    142   double shared_timer_fire_time_;
    143   bool shared_timer_fire_time_was_set_while_suspended_;
    144   int shared_timer_suspended_;  // counter
    145 };
    146 
    147 }  // namespace webkit_glue
    148 
    149 #endif  // WEBKIT_CHILD_WEBKITPLATFORMSUPPORT_IMPL_H_
    150