1 // Copyright 2014 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 CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_ 6 #define CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/debug/trace_event.h" 10 #include "base/threading/thread_local_storage.h" 11 #include "base/timer/timer.h" 12 #include "content/child/webcrypto/webcrypto_impl.h" 13 #include "content/child/webfallbackthemeengine_impl.h" 14 #include "content/common/content_export.h" 15 #include "third_party/WebKit/public/platform/Platform.h" 16 #include "third_party/WebKit/public/platform/WebGestureDevice.h" 17 #include "third_party/WebKit/public/platform/WebURLError.h" 18 #include "ui/base/layout.h" 19 20 #if defined(USE_DEFAULT_RENDER_THEME) 21 #include "content/child/webthemeengine_impl_default.h" 22 #elif defined(OS_WIN) 23 #include "content/child/webthemeengine_impl_win.h" 24 #elif defined(OS_MACOSX) 25 #include "content/child/webthemeengine_impl_mac.h" 26 #elif defined(OS_ANDROID) 27 #include "content/child/webthemeengine_impl_android.h" 28 #endif 29 30 namespace base { 31 class MessageLoop; 32 } 33 34 namespace content { 35 class FlingCurveConfiguration; 36 class WebCryptoImpl; 37 38 class CONTENT_EXPORT BlinkPlatformImpl NON_EXPORTED_BASE(public blink::Platform)39 : NON_EXPORTED_BASE(public blink::Platform) { 40 public: 41 BlinkPlatformImpl(); 42 virtual ~BlinkPlatformImpl(); 43 44 // Platform methods (partial implementation): 45 virtual blink::WebThemeEngine* themeEngine(); 46 virtual blink::WebFallbackThemeEngine* fallbackThemeEngine(); 47 virtual blink::Platform::FileHandle databaseOpenFile( 48 const blink::WebString& vfs_file_name, int desired_flags); 49 virtual int databaseDeleteFile(const blink::WebString& vfs_file_name, 50 bool sync_dir); 51 virtual long databaseGetFileAttributes( 52 const blink::WebString& vfs_file_name); 53 virtual long long databaseGetFileSize(const blink::WebString& vfs_file_name); 54 virtual long long databaseGetSpaceAvailableForOrigin( 55 const blink::WebString& origin_identifier); 56 virtual blink::WebString signedPublicKeyAndChallengeString( 57 unsigned key_size_index, const blink::WebString& challenge, 58 const blink::WebURL& url); 59 virtual size_t memoryUsageMB(); 60 virtual size_t actualMemoryUsageMB(); 61 virtual size_t physicalMemoryMB(); 62 virtual size_t virtualMemoryLimitMB(); 63 virtual size_t numberOfProcessors(); 64 65 virtual void startHeapProfiling(const blink::WebString& prefix); 66 virtual void stopHeapProfiling() OVERRIDE; 67 virtual void dumpHeapProfiling(const blink::WebString& reason); 68 virtual blink::WebString getHeapProfile() OVERRIDE; 69 70 virtual bool processMemorySizesInBytes(size_t* private_bytes, 71 size_t* shared_bytes); 72 virtual bool memoryAllocatorWasteInBytes(size_t* size); 73 virtual blink::WebDiscardableMemory* allocateAndLockDiscardableMemory( 74 size_t bytes); 75 virtual size_t maxDecodedImageBytes() OVERRIDE; 76 virtual blink::WebURLLoader* createURLLoader(); 77 virtual blink::WebSocketStreamHandle* createSocketStreamHandle(); 78 virtual blink::WebSocketHandle* createWebSocketHandle() OVERRIDE; 79 virtual blink::WebString userAgent(); 80 virtual blink::WebData parseDataURL( 81 const blink::WebURL& url, blink::WebString& mimetype, 82 blink::WebString& charset); 83 virtual blink::WebURLError cancelledError(const blink::WebURL& url) const; 84 virtual bool isReservedIPAddress( 85 const blink::WebSecurityOrigin&) const OVERRIDE; 86 virtual bool isReservedIPAddress(const blink::WebURL&) const OVERRIDE; 87 virtual blink::WebThread* createThread(const char* name); 88 virtual blink::WebThread* currentThread(); 89 virtual void yieldCurrentThread(); 90 virtual blink::WebWaitableEvent* createWaitableEvent(); 91 virtual blink::WebWaitableEvent* waitMultipleEvents( 92 const blink::WebVector<blink::WebWaitableEvent*>& events); 93 virtual void decrementStatsCounter(const char* name); 94 virtual void incrementStatsCounter(const char* name); 95 virtual void histogramCustomCounts( 96 const char* name, int sample, int min, int max, int bucket_count); 97 virtual void histogramEnumeration( 98 const char* name, int sample, int boundary_value); 99 virtual void histogramSparse(const char* name, int sample); 100 virtual const unsigned char* getTraceCategoryEnabledFlag( 101 const char* category_name); 102 virtual long* getTraceSamplingState(const unsigned thread_bucket); 103 virtual TraceEventHandle addTraceEvent( 104 char phase, 105 const unsigned char* category_group_enabled, 106 const char* name, 107 unsigned long long id, 108 int num_args, 109 const char** arg_names, 110 const unsigned char* arg_types, 111 const unsigned long long* arg_values, 112 unsigned char flags); 113 virtual TraceEventHandle addTraceEvent( 114 char phase, 115 const unsigned char* category_group_enabled, 116 const char* name, 117 unsigned long long id, 118 int num_args, 119 const char** arg_names, 120 const unsigned char* arg_types, 121 const unsigned long long* arg_values, 122 const blink::WebConvertableToTraceFormat* convertable_values, 123 unsigned char flags); 124 virtual void updateTraceEventDuration( 125 const unsigned char* category_group_enabled, 126 const char* name, 127 TraceEventHandle); 128 virtual blink::WebData loadResource(const char* name); 129 virtual blink::WebString queryLocalizedString( 130 blink::WebLocalizedString::Name name); 131 virtual blink::WebString queryLocalizedString( 132 blink::WebLocalizedString::Name name, int numeric_value); 133 virtual blink::WebString queryLocalizedString( 134 blink::WebLocalizedString::Name name, const blink::WebString& value); 135 virtual blink::WebString queryLocalizedString( 136 blink::WebLocalizedString::Name name, 137 const blink::WebString& value1, const blink::WebString& value2); 138 virtual void suddenTerminationChanged(bool enabled) { } 139 virtual double currentTime(); 140 virtual double monotonicallyIncreasingTime(); 141 virtual void cryptographicallyRandomValues( 142 unsigned char* buffer, size_t length); 143 virtual void setSharedTimerFiredFunction(void (*func)()); 144 virtual void setSharedTimerFireInterval(double interval_seconds); 145 virtual void stopSharedTimer(); 146 virtual void callOnMainThread(void (*func)(void*), void* context); 147 virtual blink::WebGestureCurve* createFlingAnimationCurve( 148 blink::WebGestureDevice device_source, 149 const blink::WebFloatPoint& velocity, 150 const blink::WebSize& cumulative_scroll) OVERRIDE; 151 virtual void didStartWorkerRunLoop( 152 const blink::WebWorkerRunLoop& runLoop) OVERRIDE; 153 virtual void didStopWorkerRunLoop( 154 const blink::WebWorkerRunLoop& runLoop) OVERRIDE; 155 virtual blink::WebCrypto* crypto() OVERRIDE; 156 157 void SuspendSharedTimer(); 158 void ResumeSharedTimer(); 159 virtual void OnStartSharedTimer(base::TimeDelta delay) {} 160 161 private: 162 static void DestroyCurrentThread(void*); 163 164 void DoTimeout() { 165 if (shared_timer_func_ && !shared_timer_suspended_) 166 shared_timer_func_(); 167 } 168 169 WebThemeEngineImpl native_theme_engine_; 170 WebFallbackThemeEngineImpl fallback_theme_engine_; 171 base::MessageLoop* main_loop_; 172 base::OneShotTimer<BlinkPlatformImpl> shared_timer_; 173 void (*shared_timer_func_)(); 174 double shared_timer_fire_time_; 175 bool shared_timer_fire_time_was_set_while_suspended_; 176 int shared_timer_suspended_; // counter 177 base::ThreadLocalStorage::Slot current_thread_slot_; 178 WebCryptoImpl web_crypto_; 179 }; 180 181 } // namespace content 182 183 #endif // CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_ 184