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 blink {
     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 blink::Platform) {
     33  public:
     34   WebKitPlatformSupportImpl();
     35   virtual ~WebKitPlatformSupportImpl();
     36 
     37   // Platform methods (partial implementation):
     38   virtual base::PlatformFile databaseOpenFile(
     39       const blink::WebString& vfs_file_name, int desired_flags);
     40   virtual int databaseDeleteFile(const blink::WebString& vfs_file_name,
     41                                  bool sync_dir);
     42   virtual long databaseGetFileAttributes(
     43       const blink::WebString& vfs_file_name);
     44   virtual long long databaseGetFileSize(const blink::WebString& vfs_file_name);
     45   virtual long long databaseGetSpaceAvailableForOrigin(
     46       const blink::WebString& origin_identifier);
     47   virtual blink::WebString signedPublicKeyAndChallengeString(
     48       unsigned key_size_index, const blink::WebString& challenge,
     49       const blink::WebURL& url);
     50   virtual size_t memoryUsageMB();
     51   virtual size_t actualMemoryUsageMB();
     52   virtual size_t physicalMemoryMB();
     53   virtual size_t numberOfProcessors();
     54 
     55   virtual void startHeapProfiling(const blink::WebString& prefix);
     56   virtual void stopHeapProfiling() OVERRIDE;
     57   virtual void dumpHeapProfiling(const blink::WebString& reason);
     58   virtual blink::WebString getHeapProfile() OVERRIDE;
     59 
     60   virtual bool processMemorySizesInBytes(size_t* private_bytes,
     61                                          size_t* shared_bytes);
     62   virtual bool memoryAllocatorWasteInBytes(size_t* size);
     63   virtual size_t maxDecodedImageBytes() OVERRIDE;
     64   virtual blink::WebURLLoader* createURLLoader();
     65   virtual blink::WebSocketStreamHandle* createSocketStreamHandle();
     66   virtual blink::WebString userAgent(const blink::WebURL& url);
     67   virtual blink::WebData parseDataURL(
     68       const blink::WebURL& url, blink::WebString& mimetype,
     69       blink::WebString& charset);
     70   virtual blink::WebURLError cancelledError(const blink::WebURL& url) const;
     71   virtual void decrementStatsCounter(const char* name);
     72   virtual void incrementStatsCounter(const char* name);
     73   virtual void histogramCustomCounts(
     74     const char* name, int sample, int min, int max, int bucket_count);
     75   virtual void histogramEnumeration(
     76     const char* name, int sample, int boundary_value);
     77   virtual void histogramSparse(const char* name, int sample);
     78   virtual const unsigned char* getTraceCategoryEnabledFlag(
     79       const char* category_name);
     80   virtual long* getTraceSamplingState(const unsigned thread_bucket);
     81   virtual TraceEventHandle addTraceEvent(
     82       char phase,
     83       const unsigned char* category_group_enabled,
     84       const char* name,
     85       unsigned long long id,
     86       int num_args,
     87       const char** arg_names,
     88       const unsigned char* arg_types,
     89       const unsigned long long* arg_values,
     90       unsigned char flags);
     91   virtual void updateTraceEventDuration(
     92       const unsigned char* category_group_enabled,
     93       const char* name,
     94       TraceEventHandle);
     95   virtual blink::WebData loadResource(const char* name);
     96   virtual blink::WebString queryLocalizedString(
     97       blink::WebLocalizedString::Name name);
     98   virtual blink::WebString queryLocalizedString(
     99       blink::WebLocalizedString::Name name, int numeric_value);
    100   virtual blink::WebString queryLocalizedString(
    101       blink::WebLocalizedString::Name name, const blink::WebString& value);
    102   virtual blink::WebString queryLocalizedString(
    103       blink::WebLocalizedString::Name name,
    104       const blink::WebString& value1, const blink::WebString& value2);
    105   virtual void suddenTerminationChanged(bool enabled) { }
    106   virtual double currentTime();
    107   virtual double monotonicallyIncreasingTime();
    108   virtual void cryptographicallyRandomValues(
    109       unsigned char* buffer, size_t length);
    110   virtual void setSharedTimerFiredFunction(void (*func)());
    111   virtual void setSharedTimerFireInterval(double interval_seconds);
    112   virtual void stopSharedTimer();
    113   virtual void callOnMainThread(void (*func)(void*), void* context);
    114 
    115 
    116   // Embedder functions. The following are not implemented by the glue layer and
    117   // need to be specialized by the embedder.
    118 
    119   // Gets a localized string given a message id.  Returns an empty string if the
    120   // message id is not found.
    121   virtual base::string16 GetLocalizedString(int message_id) = 0;
    122 
    123   // Returns the raw data for a resource.  This resource must have been
    124   // specified as BINDATA in the relevant .rc file.
    125   virtual base::StringPiece GetDataResource(int resource_id,
    126                                             ui::ScaleFactor scale_factor) = 0;
    127 
    128   // Creates a ResourceLoaderBridge.
    129   virtual ResourceLoaderBridge* CreateResourceLoader(
    130       const ResourceLoaderBridge::RequestInfo& request_info) = 0;
    131   // Creates a WebSocketStreamHandleBridge.
    132   virtual WebSocketStreamHandleBridge* CreateWebSocketStreamBridge(
    133       blink::WebSocketStreamHandle* handle,
    134       WebSocketStreamHandleDelegate* delegate) = 0;
    135 
    136   void SuspendSharedTimer();
    137   void ResumeSharedTimer();
    138   virtual void OnStartSharedTimer(base::TimeDelta delay) {}
    139 
    140  private:
    141   void DoTimeout() {
    142     if (shared_timer_func_ && !shared_timer_suspended_)
    143       shared_timer_func_();
    144   }
    145 
    146   base::MessageLoop* main_loop_;
    147   base::OneShotTimer<WebKitPlatformSupportImpl> shared_timer_;
    148   void (*shared_timer_func_)();
    149   double shared_timer_fire_time_;
    150   bool shared_timer_fire_time_was_set_while_suspended_;
    151   int shared_timer_suspended_;  // counter
    152 };
    153 
    154 }  // namespace webkit_glue
    155 
    156 #endif  // WEBKIT_CHILD_WEBKITPLATFORMSUPPORT_IMPL_H_
    157