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