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 "content/browser/vibration/vibration_provider_android.h" 6 7 #include <algorithm> 8 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" 13 14 using base::android::AttachCurrentThread; 15 16 namespace content { 17 18 VibrationProviderAndroid::VibrationProviderAndroid() { 19 } 20 21 VibrationProviderAndroid::~VibrationProviderAndroid() { 22 } 23 24 // static 25 bool VibrationProviderAndroid::Register(JNIEnv* env) { 26 return RegisterNativesImpl(env); 27 } 28 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())); 35 } 36 Java_VibrationProvider_vibrate(AttachCurrentThread(), 37 j_vibration_provider_.obj(), 38 milliseconds); 39 } 40 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()) 45 return; 46 47 Java_VibrationProvider_cancelVibration(AttachCurrentThread(), 48 j_vibration_provider_.obj()); 49 } 50 51 // static 52 VibrationProvider* VibrationMessageFilter::CreateProvider() { 53 return new VibrationProviderAndroid(); 54 } 55 56 } // namespace content 57