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/containers/scoped_ptr_hash_map.h"
10 #include "base/threading/thread_local_storage.h"
11 #include "base/timer/timer.h"
12 #include "base/trace_event/trace_event.h"
13 #include "components/webcrypto/webcrypto_impl.h"
14 #include "content/child/webfallbackthemeengine_impl.h"
15 #include "content/common/content_export.h"
16 #include "third_party/WebKit/public/platform/Platform.h"
17 #include "third_party/WebKit/public/platform/WebGestureDevice.h"
18 #include "third_party/WebKit/public/platform/WebURLError.h"
19 #include "ui/base/layout.h"
21 #if defined(USE_DEFAULT_RENDER_THEME)
22 #include "content/child/webthemeengine_impl_default.h"
24 #include "content/child/webthemeengine_impl_win.h"
25 #elif defined(OS_MACOSX)
26 #include "content/child/webthemeengine_impl_mac.h"
27 #elif defined(OS_ANDROID)
28 #include "content/child/webthemeengine_impl_android.h"
36 class BackgroundSyncProvider
;
37 class FlingCurveConfiguration
;
38 class NotificationDispatcher
;
39 class PermissionDispatcher
;
41 class ThreadSafeSender
;
43 class WebGeofencingProviderImpl
;
44 class WebMemoryDumpProviderAdapter
;
46 class CONTENT_EXPORT BlinkPlatformImpl
47 : NON_EXPORTED_BASE(public blink::Platform
) {
50 explicit BlinkPlatformImpl(
51 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
);
52 virtual ~BlinkPlatformImpl();
54 // Platform methods (partial implementation):
55 virtual blink::WebThemeEngine
* themeEngine();
56 virtual blink::WebFallbackThemeEngine
* fallbackThemeEngine();
57 virtual blink::Platform::FileHandle
databaseOpenFile(
58 const blink::WebString
& vfs_file_name
, int desired_flags
);
59 virtual int databaseDeleteFile(const blink::WebString
& vfs_file_name
,
61 virtual long databaseGetFileAttributes(
62 const blink::WebString
& vfs_file_name
);
63 virtual long long databaseGetFileSize(const blink::WebString
& vfs_file_name
);
64 virtual long long databaseGetSpaceAvailableForOrigin(
65 const blink::WebString
& origin_identifier
);
66 virtual bool databaseSetFileSize(
67 const blink::WebString
& vfs_file_name
, long long size
);
68 virtual blink::WebString
signedPublicKeyAndChallengeString(
69 unsigned key_size_index
, const blink::WebString
& challenge
,
70 const blink::WebURL
& url
);
71 virtual size_t memoryUsageMB();
72 virtual size_t actualMemoryUsageMB();
73 virtual size_t physicalMemoryMB();
74 virtual size_t virtualMemoryLimitMB();
75 virtual size_t numberOfProcessors();
77 virtual bool processMemorySizesInBytes(size_t* private_bytes
,
78 size_t* shared_bytes
);
79 virtual bool memoryAllocatorWasteInBytes(size_t* size
);
80 virtual blink::WebDiscardableMemory
* allocateAndLockDiscardableMemory(
82 virtual size_t maxDecodedImageBytes();
83 virtual uint32_t getUniqueIdForProcess();
84 virtual blink::WebURLLoader
* createURLLoader();
85 virtual blink::WebSocketHandle
* createWebSocketHandle();
86 virtual blink::WebString
userAgent();
87 virtual blink::WebData
parseDataURL(
88 const blink::WebURL
& url
, blink::WebString
& mimetype
,
89 blink::WebString
& charset
);
90 virtual blink::WebURLError
cancelledError(const blink::WebURL
& url
) const;
91 virtual bool isReservedIPAddress(const blink::WebString
& host
) const;
92 virtual bool portAllowed(const blink::WebURL
& url
) const;
93 virtual blink::WebThread
* createThread(const char* name
);
94 virtual blink::WebThread
* currentThread();
95 virtual void yieldCurrentThread();
96 virtual blink::WebWaitableEvent
* createWaitableEvent(
97 blink::WebWaitableEvent::ResetPolicy policy
,
98 blink::WebWaitableEvent::InitialState state
);
99 virtual blink::WebWaitableEvent
* waitMultipleEvents(
100 const blink::WebVector
<blink::WebWaitableEvent
*>& events
);
101 virtual void decrementStatsCounter(const char* name
);
102 virtual void incrementStatsCounter(const char* name
);
103 virtual void histogramCustomCounts(
104 const char* name
, int sample
, int min
, int max
, int bucket_count
);
105 virtual void histogramEnumeration(
106 const char* name
, int sample
, int boundary_value
);
107 virtual void histogramSparse(const char* name
, int sample
);
108 virtual const unsigned char* getTraceCategoryEnabledFlag(
109 const char* category_name
);
110 virtual TraceEventAPIAtomicWord
* getTraceSamplingState(
111 const unsigned thread_bucket
);
112 virtual TraceEventHandle
addTraceEvent(
114 const unsigned char* category_group_enabled
,
116 unsigned long long id
,
119 const char** arg_names
,
120 const unsigned char* arg_types
,
121 const unsigned long long* arg_values
,
122 unsigned char flags
);
123 virtual TraceEventHandle
addTraceEvent(
125 const unsigned char* category_group_enabled
,
127 unsigned long long id
,
130 const char** arg_names
,
131 const unsigned char* arg_types
,
132 const unsigned long long* arg_values
,
133 blink::WebConvertableToTraceFormat
* convertable_values
,
134 unsigned char flags
);
135 virtual void updateTraceEventDuration(
136 const unsigned char* category_group_enabled
,
139 virtual void registerMemoryDumpProvider(blink::WebMemoryDumpProvider
* wmdp
);
140 virtual void unregisterMemoryDumpProvider(blink::WebMemoryDumpProvider
* wmdp
);
141 virtual blink::WebProcessMemoryDump
* createProcessMemoryDump();
142 virtual blink::Platform::WebMemoryAllocatorDumpGuid
143 createWebMemoryAllocatorDumpGuid(const blink::WebString
& guidStr
);
145 virtual blink::WebData
loadResource(const char* name
);
146 virtual blink::WebString
queryLocalizedString(
147 blink::WebLocalizedString::Name name
);
148 virtual blink::WebString
queryLocalizedString(
149 blink::WebLocalizedString::Name name
, int numeric_value
);
150 virtual blink::WebString
queryLocalizedString(
151 blink::WebLocalizedString::Name name
, const blink::WebString
& value
);
152 virtual blink::WebString
queryLocalizedString(
153 blink::WebLocalizedString::Name name
,
154 const blink::WebString
& value1
, const blink::WebString
& value2
);
155 virtual void suddenTerminationChanged(bool enabled
) { }
156 virtual double currentTime();
157 virtual double monotonicallyIncreasingTime();
158 virtual double systemTraceTime();
159 virtual void cryptographicallyRandomValues(
160 unsigned char* buffer
, size_t length
);
161 virtual blink::WebGestureCurve
* createFlingAnimationCurve(
162 blink::WebGestureDevice device_source
,
163 const blink::WebFloatPoint
& velocity
,
164 const blink::WebSize
& cumulative_scroll
);
165 virtual void didStartWorkerRunLoop();
166 virtual void didStopWorkerRunLoop();
167 virtual blink::WebCrypto
* crypto();
168 virtual blink::WebGeofencingProvider
* geofencingProvider();
169 virtual blink::WebNotificationManager
* notificationManager();
170 virtual blink::WebPushProvider
* pushProvider();
171 virtual blink::WebServicePortProvider
* createServicePortProvider(
172 blink::WebServicePortProviderClient
*);
173 virtual blink::WebPermissionClient
* permissionClient();
174 virtual blink::WebSyncProvider
* backgroundSyncProvider();
176 virtual blink::WebString
domCodeStringFromEnum(int dom_code
);
177 virtual int domEnumFromCodeString(const blink::WebString
& codeString
);
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::ThreadLocalStorage::Slot current_thread_slot_
;
191 webcrypto::WebCryptoImpl web_crypto_
;
192 scoped_ptr
<WebGeofencingProviderImpl
> geofencing_provider_
;
193 base::ScopedPtrHashMap
<blink::WebMemoryDumpProvider
*,
194 scoped_ptr
<WebMemoryDumpProviderAdapter
>>
195 memory_dump_providers_
;
197 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
198 scoped_refptr
<NotificationDispatcher
> notification_dispatcher_
;
199 scoped_refptr
<PushDispatcher
> push_dispatcher_
;
200 scoped_ptr
<PermissionDispatcher
> permission_client_
;
201 scoped_ptr
<BackgroundSyncProvider
> sync_provider_
;
204 } // namespace content
206 #endif // CONTENT_CHILD_BLINK_PLATFORM_IMPL_H_