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