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.
5 #ifndef CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_
6 #define CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/threading/thread_local_storage.h"
10 #include "base/timer/timer.h"
11 #include "base/trace_event/trace_event.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"
20 #if defined(USE_DEFAULT_RENDER_THEME)
21 #include "content/child/webthemeengine_impl_default.h"
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"
35 class WebWorkerRunLoop
;
39 class FlingCurveConfiguration
;
40 class NotificationDispatcher
;
42 class ThreadSafeSender
;
43 class WebBluetoothImpl
;
45 class WebGeofencingProviderImpl
;
47 class CONTENT_EXPORT BlinkPlatformImpl
48 : NON_EXPORTED_BASE(public blink::Platform
) {
51 explicit BlinkPlatformImpl(
52 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
);
53 virtual ~BlinkPlatformImpl();
55 // Platform methods (partial implementation):
56 virtual blink::WebThemeEngine
* themeEngine();
57 virtual blink::WebFallbackThemeEngine
* fallbackThemeEngine();
58 virtual blink::Platform::FileHandle
databaseOpenFile(
59 const blink::WebString
& vfs_file_name
, int desired_flags
);
60 virtual int databaseDeleteFile(const blink::WebString
& vfs_file_name
,
62 virtual long databaseGetFileAttributes(
63 const blink::WebString
& vfs_file_name
);
64 virtual long long databaseGetFileSize(const blink::WebString
& vfs_file_name
);
65 virtual long long databaseGetSpaceAvailableForOrigin(
66 const blink::WebString
& origin_identifier
);
67 virtual blink::WebString
signedPublicKeyAndChallengeString(
68 unsigned key_size_index
, const blink::WebString
& challenge
,
69 const blink::WebURL
& url
);
70 virtual size_t memoryUsageMB();
71 virtual size_t actualMemoryUsageMB();
72 virtual size_t physicalMemoryMB();
73 virtual size_t virtualMemoryLimitMB();
74 virtual size_t numberOfProcessors();
76 virtual bool processMemorySizesInBytes(size_t* private_bytes
,
77 size_t* shared_bytes
);
78 virtual bool memoryAllocatorWasteInBytes(size_t* size
);
79 virtual blink::WebDiscardableMemory
* allocateAndLockDiscardableMemory(
81 virtual size_t maxDecodedImageBytes();
82 virtual blink::WebURLLoader
* createURLLoader();
83 virtual blink::WebSocketHandle
* createWebSocketHandle();
84 virtual blink::WebString
userAgent();
85 virtual blink::WebData
parseDataURL(
86 const blink::WebURL
& url
, blink::WebString
& mimetype
,
87 blink::WebString
& charset
);
88 virtual blink::WebURLError
cancelledError(const blink::WebURL
& url
) const;
89 virtual bool isReservedIPAddress(const blink::WebString
& host
) const;
90 virtual blink::WebThread
* createThread(const char* name
);
91 virtual blink::WebThread
* currentThread();
92 virtual void yieldCurrentThread();
93 virtual blink::WebWaitableEvent
* createWaitableEvent();
94 virtual blink::WebWaitableEvent
* waitMultipleEvents(
95 const blink::WebVector
<blink::WebWaitableEvent
*>& events
);
96 virtual void decrementStatsCounter(const char* name
);
97 virtual void incrementStatsCounter(const char* name
);
98 virtual void histogramCustomCounts(
99 const char* name
, int sample
, int min
, int max
, int bucket_count
);
100 virtual void histogramEnumeration(
101 const char* name
, int sample
, int boundary_value
);
102 virtual void histogramSparse(const char* name
, int sample
);
103 virtual const unsigned char* getTraceCategoryEnabledFlag(
104 const char* category_name
);
105 virtual long* getTraceSamplingState(const unsigned thread_bucket
);
106 virtual TraceEventHandle
addTraceEvent(
108 const unsigned char* category_group_enabled
,
110 unsigned long long id
,
113 const char** arg_names
,
114 const unsigned char* arg_types
,
115 const unsigned long long* arg_values
,
116 unsigned char flags
);
117 virtual TraceEventHandle
addTraceEvent(
119 const unsigned char* category_group_enabled
,
121 unsigned long long id
,
124 const char** arg_names
,
125 const unsigned char* arg_types
,
126 const unsigned long long* arg_values
,
127 const blink::WebConvertableToTraceFormat
* convertable_values
,
128 unsigned char flags
);
129 virtual void updateTraceEventDuration(
130 const unsigned char* category_group_enabled
,
133 virtual blink::WebData
loadResource(const char* name
);
134 virtual blink::WebString
queryLocalizedString(
135 blink::WebLocalizedString::Name name
);
136 virtual blink::WebString
queryLocalizedString(
137 blink::WebLocalizedString::Name name
, int numeric_value
);
138 virtual blink::WebString
queryLocalizedString(
139 blink::WebLocalizedString::Name name
, const blink::WebString
& value
);
140 virtual blink::WebString
queryLocalizedString(
141 blink::WebLocalizedString::Name name
,
142 const blink::WebString
& value1
, const blink::WebString
& value2
);
143 virtual void suddenTerminationChanged(bool enabled
) { }
144 virtual double currentTime();
145 virtual double monotonicallyIncreasingTime();
146 virtual void cryptographicallyRandomValues(
147 unsigned char* buffer
, size_t length
);
148 virtual void setSharedTimerFiredFunction(void (*func
)());
149 virtual void setSharedTimerFireInterval(double interval_seconds
);
150 virtual void stopSharedTimer();
151 virtual void callOnMainThread(void (*func
)(void*), void* context
);
152 virtual blink::WebGestureCurve
* createFlingAnimationCurve(
153 blink::WebGestureDevice device_source
,
154 const blink::WebFloatPoint
& velocity
,
155 const blink::WebSize
& cumulative_scroll
);
156 virtual void didStartWorkerRunLoop(
157 const blink::WebWorkerRunLoop
& runLoop
);
158 virtual void didStopWorkerRunLoop(
159 const blink::WebWorkerRunLoop
& runLoop
);
160 virtual void didStartWorkerRunLoop();
161 virtual void didStopWorkerRunLoop();
162 virtual blink::WebCrypto
* crypto();
163 virtual blink::WebGeofencingProvider
* geofencingProvider();
164 virtual blink::WebBluetooth
* bluetooth();
165 virtual blink::WebNotificationManager
* notificationManager();
166 virtual blink::WebPushProvider
* pushProvider();
167 virtual blink::WebNavigatorConnectProvider
* navigatorConnectProvider();
169 void SuspendSharedTimer();
170 void ResumeSharedTimer();
171 virtual void OnStartSharedTimer(base::TimeDelta delay
) {}
173 WebBluetoothImpl
* BluetoothImplForTesting() { return bluetooth_
.get(); }
175 virtual blink::WebString
domCodeStringFromEnum(int dom_code
);
176 virtual int domEnumFromCodeString(const blink::WebString
& codeString
);
179 static void DestroyCurrentThread(void*);
182 if (shared_timer_func_
&& !shared_timer_suspended_
)
183 shared_timer_func_();
188 scoped_refptr
<base::SingleThreadTaskRunner
> MainTaskRunnerForCurrentThread();
190 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
191 WebThemeEngineImpl native_theme_engine_
;
192 WebFallbackThemeEngineImpl fallback_theme_engine_
;
193 base::OneShotTimer
<BlinkPlatformImpl
> shared_timer_
;
194 void (*shared_timer_func_
)();
195 double shared_timer_fire_time_
;
196 bool shared_timer_fire_time_was_set_while_suspended_
;
197 int shared_timer_suspended_
; // counter
198 base::ThreadLocalStorage::Slot current_thread_slot_
;
199 WebCryptoImpl web_crypto_
;
200 scoped_ptr
<WebGeofencingProviderImpl
> geofencing_provider_
;
201 scoped_ptr
<WebBluetoothImpl
> bluetooth_
;
203 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
204 scoped_refptr
<NotificationDispatcher
> notification_dispatcher_
;
205 scoped_refptr
<PushDispatcher
> push_dispatcher_
;
208 } // namespace content
210 #endif // CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_