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