Index: content/browser/vibration/vibration_message_filter.cc |
diff --git a/content/browser/android/vibration_message_filter.cc b/content/browser/vibration/vibration_message_filter.cc |
similarity index 57% |
rename from content/browser/android/vibration_message_filter.cc |
rename to content/browser/vibration/vibration_message_filter.cc |
index b91e9635c4ef4f7895ae50cb15179b6a28a25c9a..9a6ed0cb2c09d464b4fd81279e80b639e249d56f 100644 |
--- a/content/browser/android/vibration_message_filter.cc |
+++ b/content/browser/vibration/vibration_message_filter.cc |
@@ -2,33 +2,31 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/browser/android/vibration_message_filter.h" |
+#include "content/browser/vibration/vibration_message_filter.h" |
#include <algorithm> |
#include "base/safe_numerics.h" |
#include "content/common/view_messages.h" |
-#include "jni/VibrationMessageFilter_jni.h" |
+#include "content/port/browser/vibration_provider.h" |
+#include "content/public/browser/content_browser_client.h" |
+#include "content/public/common/content_client.h" |
#include "third_party/WebKit/public/platform/WebVibration.h" |
-using base::android::AttachCurrentThread; |
- |
namespace content { |
// Minimum duration of a vibration is 1 millisecond. |
const int64 kMinimumVibrationDurationMs = 1; |
VibrationMessageFilter::VibrationMessageFilter() { |
+ provider_.reset(GetContentClient()->browser()->OverrideVibrationProvider()); |
+ if (!provider_.get()) |
+ provider_.reset(CreateProvider()); |
} |
VibrationMessageFilter::~VibrationMessageFilter() { |
} |
-// static |
-bool VibrationMessageFilter::Register(JNIEnv* env) { |
- return RegisterNativesImpl(env); |
-} |
- |
bool VibrationMessageFilter::OnMessageReceived( |
const IPC::Message& message, |
bool* message_was_ok) { |
@@ -44,30 +42,28 @@ bool VibrationMessageFilter::OnMessageReceived( |
} |
void VibrationMessageFilter::OnVibrate(int64 milliseconds) { |
+ if (!provider_.get()) |
+ return; |
+ |
// Though the Blink implementation already sanitizes vibration times, don't |
// trust any values passed from the renderer. |
- milliseconds = std::max(kMinimumVibrationDurationMs, |
- std::min(milliseconds, |
+ milliseconds = std::max(kMinimumVibrationDurationMs, std::min(milliseconds, |
base::checked_numeric_cast<int64>(blink::kVibrationDurationMax))); |
- if (j_vibration_message_filter_.is_null()) { |
- j_vibration_message_filter_.Reset( |
- Java_VibrationMessageFilter_create( |
- AttachCurrentThread(), |
- base::android::GetApplicationContext())); |
- } |
- Java_VibrationMessageFilter_vibrate(AttachCurrentThread(), |
- j_vibration_message_filter_.obj(), |
- milliseconds); |
+ provider_->Vibrate(milliseconds); |
} |
void VibrationMessageFilter::OnCancelVibration() { |
- // If somehow a cancel message is received before this object was |
- // instantiated, it means there is no current vibration anyway. Just return. |
- if (j_vibration_message_filter_.is_null()) |
+ if (!provider_.get()) |
return; |
- Java_VibrationMessageFilter_cancelVibration(AttachCurrentThread(), |
- j_vibration_message_filter_.obj()); |
+ |
+ provider_->CancelVibration(); |
} |
+#if !defined(OS_ANDROID) |
+// static |
+VibrationProvider* VibrationMessageFilter::CreateProvider() { |
+ return NULL; |
+} |
+#endif |
} // namespace content |