| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 #include "webkit/child/webkitplatformsupport_child_impl.h" | |
| 6 | |
| 7 #include "base/memory/discardable_memory.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/synchronization/waitable_event.h" | |
| 10 #include "third_party/WebKit/public/platform/WebWaitableEvent.h" | |
| 11 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 12 #include "webkit/child/fling_curve_configuration.h" | |
| 13 #include "webkit/child/web_discardable_memory_impl.h" | |
| 14 #include "webkit/child/webthread_impl.h" | |
| 15 #include "webkit/child/worker_task_runner.h" | |
| 16 | |
| 17 #if defined(OS_ANDROID) | |
| 18 #include "webkit/child/fling_animator_impl_android.h" | |
| 19 #endif | |
| 20 | |
| 21 using blink::WebFallbackThemeEngine; | |
| 22 using blink::WebThemeEngine; | |
| 23 | |
| 24 namespace webkit_glue { | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 class WebWaitableEventImpl : public blink::WebWaitableEvent { | |
| 29 public: | |
| 30 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {} | |
| 31 virtual ~WebWaitableEventImpl() {} | |
| 32 | |
| 33 virtual void wait() { impl_->Wait(); } | |
| 34 virtual void signal() { impl_->Signal(); } | |
| 35 | |
| 36 base::WaitableEvent* impl() { | |
| 37 return impl_.get(); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 scoped_ptr<base::WaitableEvent> impl_; | |
| 42 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl); | |
| 43 }; | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 47 WebKitPlatformSupportChildImpl::WebKitPlatformSupportChildImpl() | |
| 48 : current_thread_slot_(&DestroyCurrentThread), | |
| 49 fling_curve_configuration_(new FlingCurveConfiguration) {} | |
| 50 | |
| 51 WebKitPlatformSupportChildImpl::~WebKitPlatformSupportChildImpl() {} | |
| 52 | |
| 53 WebThemeEngine* WebKitPlatformSupportChildImpl::themeEngine() { | |
| 54 return &native_theme_engine_; | |
| 55 } | |
| 56 | |
| 57 WebFallbackThemeEngine* WebKitPlatformSupportChildImpl::fallbackThemeEngine() { | |
| 58 return &fallback_theme_engine_; | |
| 59 } | |
| 60 | |
| 61 void WebKitPlatformSupportChildImpl::SetFlingCurveParameters( | |
| 62 const std::vector<float>& new_touchpad, | |
| 63 const std::vector<float>& new_touchscreen) { | |
| 64 fling_curve_configuration_->SetCurveParameters(new_touchpad, new_touchscreen); | |
| 65 } | |
| 66 | |
| 67 blink::WebGestureCurve* | |
| 68 WebKitPlatformSupportChildImpl::createFlingAnimationCurve( | |
| 69 int device_source, | |
| 70 const blink::WebFloatPoint& velocity, | |
| 71 const blink::WebSize& cumulative_scroll) { | |
| 72 #if defined(OS_ANDROID) | |
| 73 return FlingAnimatorImpl::CreateAndroidGestureCurve(velocity, | |
| 74 cumulative_scroll); | |
| 75 #endif | |
| 76 | |
| 77 if (device_source == blink::WebGestureEvent::Touchscreen) | |
| 78 return fling_curve_configuration_->CreateForTouchScreen(velocity, | |
| 79 cumulative_scroll); | |
| 80 | |
| 81 return fling_curve_configuration_->CreateForTouchPad(velocity, | |
| 82 cumulative_scroll); | |
| 83 } | |
| 84 | |
| 85 blink::WebThread* WebKitPlatformSupportChildImpl::createThread( | |
| 86 const char* name) { | |
| 87 return new WebThreadImpl(name); | |
| 88 } | |
| 89 | |
| 90 blink::WebThread* WebKitPlatformSupportChildImpl::currentThread() { | |
| 91 WebThreadImplForMessageLoop* thread = | |
| 92 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); | |
| 93 if (thread) | |
| 94 return (thread); | |
| 95 | |
| 96 scoped_refptr<base::MessageLoopProxy> message_loop = | |
| 97 base::MessageLoopProxy::current(); | |
| 98 if (!message_loop.get()) | |
| 99 return NULL; | |
| 100 | |
| 101 thread = new WebThreadImplForMessageLoop(message_loop.get()); | |
| 102 current_thread_slot_.Set(thread); | |
| 103 return thread; | |
| 104 } | |
| 105 | |
| 106 blink::WebWaitableEvent* WebKitPlatformSupportChildImpl::createWaitableEvent() { | |
| 107 return new WebWaitableEventImpl(); | |
| 108 } | |
| 109 | |
| 110 blink::WebWaitableEvent* WebKitPlatformSupportChildImpl::waitMultipleEvents( | |
| 111 const blink::WebVector<blink::WebWaitableEvent*>& web_events) { | |
| 112 base::WaitableEvent** events = new base::WaitableEvent*[web_events.size()]; | |
| 113 for (size_t i = 0; i < web_events.size(); ++i) | |
| 114 events[i] = static_cast<WebWaitableEventImpl*>(web_events[i])->impl(); | |
| 115 size_t idx = base::WaitableEvent::WaitMany(events, web_events.size()); | |
| 116 DCHECK_LT(idx, web_events.size()); | |
| 117 return web_events[idx]; | |
| 118 } | |
| 119 | |
| 120 void WebKitPlatformSupportChildImpl::didStartWorkerRunLoop( | |
| 121 const blink::WebWorkerRunLoop& runLoop) { | |
| 122 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); | |
| 123 worker_task_runner->OnWorkerRunLoopStarted(runLoop); | |
| 124 } | |
| 125 | |
| 126 void WebKitPlatformSupportChildImpl::didStopWorkerRunLoop( | |
| 127 const blink::WebWorkerRunLoop& runLoop) { | |
| 128 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); | |
| 129 worker_task_runner->OnWorkerRunLoopStopped(runLoop); | |
| 130 } | |
| 131 | |
| 132 blink::WebDiscardableMemory* | |
| 133 WebKitPlatformSupportChildImpl::allocateAndLockDiscardableMemory(size_t bytes) { | |
| 134 base::DiscardableMemoryType type = | |
| 135 base::DiscardableMemory::GetPreferredType(); | |
| 136 if (type == base::DISCARDABLE_MEMORY_TYPE_EMULATED) | |
| 137 return NULL; | |
| 138 return WebDiscardableMemoryImpl::CreateLockedMemory(bytes).release(); | |
| 139 } | |
| 140 | |
| 141 // static | |
| 142 void WebKitPlatformSupportChildImpl::DestroyCurrentThread(void* thread) { | |
| 143 WebThreadImplForMessageLoop* impl = | |
| 144 static_cast<WebThreadImplForMessageLoop*>(thread); | |
| 145 delete impl; | |
| 146 } | |
| 147 | |
| 148 } // namespace webkit_glue | |
| OLD | NEW |