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