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 "third_party/WebKit/public/web/WebInputEvent.h" 9 #include "webkit/child/fling_curve_configuration.h" 10 #include "webkit/child/web_discardable_memory_impl.h" 11 #include "webkit/child/webthread_impl.h" 12 #include "webkit/child/worker_task_runner.h" 13 14 #if defined(OS_ANDROID) 15 #include "webkit/child/fling_animator_impl_android.h" 16 #endif 17 18 using WebKit::WebFallbackThemeEngine; 19 using WebKit::WebThemeEngine; 20 21 namespace webkit_glue { 22 23 WebKitPlatformSupportChildImpl::WebKitPlatformSupportChildImpl() 24 : current_thread_slot_(&DestroyCurrentThread), 25 fling_curve_configuration_(new FlingCurveConfiguration) {} 26 27 WebKitPlatformSupportChildImpl::~WebKitPlatformSupportChildImpl() {} 28 29 WebThemeEngine* WebKitPlatformSupportChildImpl::themeEngine() { 30 return &native_theme_engine_; 31 } 32 33 WebFallbackThemeEngine* WebKitPlatformSupportChildImpl::fallbackThemeEngine() { 34 return &fallback_theme_engine_; 35 } 36 37 void WebKitPlatformSupportChildImpl::SetFlingCurveParameters( 38 const std::vector<float>& new_touchpad, 39 const std::vector<float>& new_touchscreen) { 40 fling_curve_configuration_->SetCurveParameters(new_touchpad, new_touchscreen); 41 } 42 43 WebKit::WebGestureCurve* 44 WebKitPlatformSupportChildImpl::createFlingAnimationCurve( 45 int device_source, 46 const WebKit::WebFloatPoint& velocity, 47 const WebKit::WebSize& cumulative_scroll) { 48 #if defined(OS_ANDROID) 49 return FlingAnimatorImpl::CreateAndroidGestureCurve(velocity, 50 cumulative_scroll); 51 #endif 52 53 if (device_source == WebKit::WebGestureEvent::Touchscreen) 54 return fling_curve_configuration_->CreateForTouchScreen(velocity, 55 cumulative_scroll); 56 57 return fling_curve_configuration_->CreateForTouchPad(velocity, 58 cumulative_scroll); 59 } 60 61 WebKit::WebThread* WebKitPlatformSupportChildImpl::createThread( 62 const char* name) { 63 return new WebThreadImpl(name); 64 } 65 66 WebKit::WebThread* WebKitPlatformSupportChildImpl::currentThread() { 67 WebThreadImplForMessageLoop* thread = 68 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); 69 if (thread) 70 return (thread); 71 72 scoped_refptr<base::MessageLoopProxy> message_loop = 73 base::MessageLoopProxy::current(); 74 if (!message_loop.get()) 75 return NULL; 76 77 thread = new WebThreadImplForMessageLoop(message_loop.get()); 78 current_thread_slot_.Set(thread); 79 return thread; 80 } 81 82 void WebKitPlatformSupportChildImpl::didStartWorkerRunLoop( 83 const WebKit::WebWorkerRunLoop& runLoop) { 84 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); 85 worker_task_runner->OnWorkerRunLoopStarted(runLoop); 86 } 87 88 void WebKitPlatformSupportChildImpl::didStopWorkerRunLoop( 89 const WebKit::WebWorkerRunLoop& runLoop) { 90 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance(); 91 worker_task_runner->OnWorkerRunLoopStopped(runLoop); 92 } 93 94 WebKit::WebDiscardableMemory* 95 WebKitPlatformSupportChildImpl::allocateAndLockDiscardableMemory(size_t bytes) { 96 if (!base::DiscardableMemory::Supported()) 97 return NULL; 98 scoped_ptr<WebDiscardableMemoryImpl> discardable( 99 new WebDiscardableMemoryImpl()); 100 if (discardable->InitializeAndLock(bytes)) 101 return discardable.release(); 102 return NULL; 103 } 104 105 // static 106 void WebKitPlatformSupportChildImpl::DestroyCurrentThread(void* thread) { 107 WebThreadImplForMessageLoop* impl = 108 static_cast<WebThreadImplForMessageLoop*>(thread); 109 delete impl; 110 } 111 112 } // namespace webkit_glue 113