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/mock_web_blob_registry_impl.h"
13 #include "components/html_viewer/web_mime_registry_impl.h"
14 #include "components/html_viewer/web_notification_manager_impl.h"
15 #include "components/html_viewer/web_theme_engine_impl.h"
16 #include "components/webcrypto/webcrypto_impl.h"
17 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
18 #include "mojo/services/network/public/interfaces/web_socket_factory.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 bool isThreadedCompositingEnabled();
55 virtual blink::WebCompositorSupport
* compositorSupport();
56 uint32_t getUniqueIdForProcess() override
;
57 void createMessageChannel(blink::WebMessagePortChannel
** channel1
,
58 blink::WebMessagePortChannel
** channel2
) override
;
59 virtual blink::WebURLLoader
* createURLLoader();
60 virtual blink::WebSocketHandle
* createWebSocketHandle();
61 virtual blink::WebString
userAgent();
62 virtual blink::WebData
parseDataURL(
63 const blink::WebURL
& url
, blink::WebString
& mime_type
,
64 blink::WebString
& charset
);
65 virtual bool isReservedIPAddress(const blink::WebString
& host
) const;
66 virtual blink::WebURLError
cancelledError(const blink::WebURL
& url
) const;
67 virtual blink::WebThread
* createThread(const char* name
);
68 virtual blink::WebThread
* currentThread();
69 virtual void yieldCurrentThread();
70 virtual blink::WebWaitableEvent
* createWaitableEvent(
71 blink::WebWaitableEvent::ResetPolicy policy
,
72 blink::WebWaitableEvent::InitialState state
);
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::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
79 const blink::WebGraphicsContext3D::Attributes
& attributes
,
80 blink::WebGraphicsContext3D
* share_context
);
81 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
82 const blink::WebGraphicsContext3D::Attributes
& attributes
,
83 blink::WebGraphicsContext3D
* share_context
,
84 blink::WebGLInfo
* gl_info
);
85 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
86 const blink::WebGraphicsContext3D::Attributes
& attributes
);
87 virtual blink::WebGraphicsContext3DProvider
*
88 createSharedOffscreenGraphicsContext3DProvider();
89 virtual blink::WebData
loadResource(const char* name
);
90 virtual blink::WebGestureCurve
* createFlingAnimationCurve(
91 blink::WebGestureDevice device_source
,
92 const blink::WebFloatPoint
& velocity
,
93 const blink::WebSize
& cumulative_scroll
);
94 virtual blink::WebCrypto
* crypto();
95 virtual blink::WebNotificationManager
* notificationManager();
98 void UpdateWebThreadTLS(blink::WebThread
* thread
);
100 static void DestroyCurrentThread(void*);
102 mojo::ApplicationImpl
* app_
;
103 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
104 scoped_ptr
<scheduler::WebThreadImplForRendererScheduler
> main_thread_
;
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 mojo::WebSocketFactoryPtr web_socket_factory_
;
113 mojo::URLLoaderFactoryPtr url_loader_factory_
;
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_