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 COMPONENTS_HTML_VIEWER_BLINK_PLATFORM_IMPL_H_
6 #define COMPONENTS_HTML_VIEWER_BLINK_PLATFORM_IMPL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/threading/thread_local_storage.h"
10 #include "base/timer/timer.h"
11 #include "cc/blink/web_compositor_support_impl.h"
12 #include "components/html_viewer/blink_resource_map.h"
13 #include "components/html_viewer/mock_web_blob_registry_impl.h"
14 #include "components/html_viewer/web_mime_registry_impl.h"
15 #include "components/html_viewer/web_notification_manager_impl.h"
16 #include "components/html_viewer/web_theme_engine_impl.h"
17 #include "components/webcrypto/webcrypto_impl.h"
18 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
19 #include "third_party/WebKit/public/platform/Platform.h"
20 #include "third_party/WebKit/public/platform/WebScrollbarBehavior.h"
23 class RendererScheduler
;
24 class WebThreadImplForRendererScheduler
;
28 class ApplicationImpl
;
31 namespace html_viewer
{
33 class WebClipboardImpl
;
34 class WebCookieJarImpl
;
36 class BlinkPlatformImpl
: public blink::Platform
{
38 // |app| may be null in tests.
39 BlinkPlatformImpl(mojo::ApplicationImpl
* app
,
40 scheduler::RendererScheduler
* renderer_scheduler
);
41 virtual ~BlinkPlatformImpl();
43 // blink::Platform methods:
44 virtual blink::WebCookieJar
* cookieJar();
45 virtual blink::WebClipboard
* clipboard();
46 virtual blink::WebMimeRegistry
* mimeRegistry();
47 virtual blink::WebThemeEngine
* themeEngine();
48 virtual blink::WebString
defaultLocale();
49 virtual blink::WebBlobRegistry
* blobRegistry();
50 virtual double currentTime();
51 virtual double monotonicallyIncreasingTime();
52 virtual void cryptographicallyRandomValues(unsigned char* buffer
,
54 virtual void setSharedTimerFiredFunction(void (*func
)());
55 virtual void setSharedTimerFireInterval(double interval_seconds
);
56 virtual void stopSharedTimer();
57 virtual bool isThreadedCompositingEnabled();
58 virtual blink::WebCompositorSupport
* compositorSupport();
59 void createMessageChannel(blink::WebMessagePortChannel
** channel1
,
60 blink::WebMessagePortChannel
** channel2
) override
;
61 virtual blink::WebURLLoader
* createURLLoader();
62 virtual blink::WebSocketHandle
* createWebSocketHandle();
63 virtual blink::WebString
userAgent();
64 virtual blink::WebData
parseDataURL(
65 const blink::WebURL
& url
, blink::WebString
& mime_type
,
66 blink::WebString
& charset
);
67 virtual bool isReservedIPAddress(const blink::WebString
& host
) const;
68 virtual blink::WebURLError
cancelledError(const blink::WebURL
& url
) const;
69 virtual blink::WebThread
* createThread(const char* name
);
70 virtual blink::WebThread
* currentThread();
71 virtual void yieldCurrentThread();
72 virtual blink::WebWaitableEvent
* createWaitableEvent();
73 virtual blink::WebWaitableEvent
* waitMultipleEvents(
74 const blink::WebVector
<blink::WebWaitableEvent
*>& events
);
75 virtual blink::WebScrollbarBehavior
* scrollbarBehavior();
76 virtual const unsigned char* getTraceCategoryEnabledFlag(
77 const char* category_name
);
78 virtual blink::WebData
loadResource(const char* name
);
79 virtual blink::WebGestureCurve
* createFlingAnimationCurve(
80 blink::WebGestureDevice device_source
,
81 const blink::WebFloatPoint
& velocity
,
82 const blink::WebSize
& cumulative_scroll
);
83 virtual blink::WebCrypto
* crypto();
84 virtual blink::WebNotificationManager
* notificationManager();
87 void SuspendSharedTimer();
88 void ResumeSharedTimer();
89 void UpdateWebThreadTLS(blink::WebThread
* thread
);
92 if (shared_timer_func_
&& !shared_timer_suspended_
)
96 static void DestroyCurrentThread(void*);
98 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
99 scoped_ptr
<scheduler::WebThreadImplForRendererScheduler
> main_thread_
;
100 base::OneShotTimer
<BlinkPlatformImpl
> shared_timer_
;
101 void (*shared_timer_func_
)();
102 double shared_timer_fire_time_
;
103 bool shared_timer_fire_time_was_set_while_suspended_
;
104 int shared_timer_suspended_
; // counter
105 base::ThreadLocalStorage::Slot current_thread_slot_
;
106 cc_blink::WebCompositorSupportImpl compositor_support_
;
107 WebThemeEngineImpl theme_engine_
;
108 WebMimeRegistryImpl mime_registry_
;
109 webcrypto::WebCryptoImpl web_crypto_
;
110 WebNotificationManagerImpl web_notification_manager_
;
111 blink::WebScrollbarBehavior scrollbar_behavior_
;
112 BlinkResourceMap blink_resource_map_
;
113 mojo::NetworkServicePtr network_service_
;
114 MockWebBlobRegistryImpl blob_registry_
;
115 scoped_ptr
<WebCookieJarImpl
> cookie_jar_
;
116 scoped_ptr
<WebClipboardImpl
> clipboard_
;
118 DISALLOW_COPY_AND_ASSIGN(BlinkPlatformImpl
);
121 } // namespace html_viewer
123 #endif // COMPONENTS_HTML_VIEWER_BLINK_PLATFORM_IMPL_H_