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.
5 #include "content/browser/vibration/vibration_provider_android.h"
9 #include "content/browser/vibration/vibration_message_filter.h"
10 #include "content/common/view_messages.h"
11 #include "jni/VibrationProvider_jni.h"
12 #include "third_party/WebKit/public/platform/WebVibration.h"
14 using base::android::AttachCurrentThread
;
18 VibrationProviderAndroid::VibrationProviderAndroid() {
21 VibrationProviderAndroid::~VibrationProviderAndroid() {
25 bool VibrationProviderAndroid::Register(JNIEnv
* env
) {
26 return RegisterNativesImpl(env
);
29 void VibrationProviderAndroid::Vibrate(int64 milliseconds
) {
30 if (j_vibration_provider_
.is_null()) {
31 j_vibration_provider_
.Reset(
32 Java_VibrationProvider_create(
33 AttachCurrentThread(),
34 base::android::GetApplicationContext()));
36 Java_VibrationProvider_vibrate(AttachCurrentThread(),
37 j_vibration_provider_
.obj(),
41 void VibrationProviderAndroid::CancelVibration() {
42 // If somehow a cancel message is received before this object was
43 // instantiated, it means there is no current vibration anyway. Just return.
44 if (j_vibration_provider_
.is_null())
47 Java_VibrationProvider_cancelVibration(AttachCurrentThread(),
48 j_vibration_provider_
.obj());
52 VibrationProvider
* VibrationMessageFilter::CreateProvider() {
53 return new VibrationProviderAndroid();
56 } // namespace content