Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / mojo / services / html_viewer / blink_platform_impl.h
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.
4
5 #ifndef MOJO_SERVICES_HTML_VIEWER_BLINK_PLATFORM_IMPL_H_
6 #define MOJO_SERVICES_HTML_VIEWER_BLINK_PLATFORM_IMPL_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/thread_local_storage.h"
11 #include "base/timer/timer.h"
12 #include "mojo/services/html_viewer/webmimeregistry_impl.h"
13 #include "mojo/services/html_viewer/webthemeengine_impl.h"
14 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
15 #include "third_party/WebKit/public/platform/Platform.h"
16 #include "third_party/WebKit/public/platform/WebScrollbarBehavior.h"
17
18 namespace mojo {
19 class ApplicationImpl;
20 class WebCookieJarImpl;
21
22 class BlinkPlatformImpl : public blink::Platform {
23  public:
24   explicit BlinkPlatformImpl(ApplicationImpl* app);
25   virtual ~BlinkPlatformImpl();
26
27   // blink::Platform methods:
28   virtual blink::WebCookieJar* cookieJar();
29   virtual blink::WebMimeRegistry* mimeRegistry();
30   virtual blink::WebThemeEngine* themeEngine();
31   virtual blink::WebString defaultLocale();
32   virtual double currentTime();
33   virtual double monotonicallyIncreasingTime();
34   virtual void cryptographicallyRandomValues(
35       unsigned char* buffer, size_t length);
36   virtual void setSharedTimerFiredFunction(void (*func)());
37   virtual void setSharedTimerFireInterval(double interval_seconds);
38   virtual void stopSharedTimer();
39   virtual void callOnMainThread(void (*func)(void*), void* context);
40   virtual blink::WebURLLoader* createURLLoader();
41   virtual blink::WebString userAgent();
42   virtual blink::WebData parseDataURL(
43       const blink::WebURL& url, blink::WebString& mime_type,
44       blink::WebString& charset);
45   virtual blink::WebURLError cancelledError(const blink::WebURL& url) const;
46   virtual blink::WebThread* createThread(const char* name);
47   virtual blink::WebThread* currentThread();
48   virtual blink::WebWaitableEvent* createWaitableEvent();
49   virtual blink::WebWaitableEvent* waitMultipleEvents(
50       const blink::WebVector<blink::WebWaitableEvent*>& events);
51   virtual blink::WebScrollbarBehavior* scrollbarBehavior();
52   virtual const unsigned char* getTraceCategoryEnabledFlag(
53       const char* category_name);
54
55  private:
56   void SuspendSharedTimer();
57   void ResumeSharedTimer();
58
59   void DoTimeout() {
60     if (shared_timer_func_ && !shared_timer_suspended_)
61       shared_timer_func_();
62   }
63
64   static void DestroyCurrentThread(void*);
65
66   NetworkServicePtr network_service_;
67   base::MessageLoop* main_loop_;
68   base::OneShotTimer<BlinkPlatformImpl> shared_timer_;
69   void (*shared_timer_func_)();
70   double shared_timer_fire_time_;
71   bool shared_timer_fire_time_was_set_while_suspended_;
72   int shared_timer_suspended_;  // counter
73   base::ThreadLocalStorage::Slot current_thread_slot_;
74   WebThemeEngineImpl theme_engine_;
75   scoped_ptr<WebCookieJarImpl> cookie_jar_;
76   WebMimeRegistryImpl mime_registry_;
77   blink::WebScrollbarBehavior scrollbar_behavior_;
78
79   DISALLOW_COPY_AND_ASSIGN(BlinkPlatformImpl);
80 };
81
82 }  // namespace mojo
83
84 #endif  // MOJO_SERVICES_HTML_VIEWER_BLINK_PLATFORM_IMPL_H_