Chromium Code Reviews| 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 56% |
| rename from content/browser/android/vibration_message_filter.cc |
| rename to content/browser/vibration/vibration_message_filter.cc |
| index b91e9635c4ef4f7895ae50cb15179b6a28a25c9a..24684ae528c882a91cb6095849c1607544e87664 100644 |
| --- a/content/browser/android/vibration_message_filter.cc |
| +++ b/content/browser/vibration/vibration_message_filter.cc |
| @@ -2,16 +2,20 @@ |
| // 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; |
| +#if defined(OS_ANDROID) |
| +#include "content/browser/vibration/vibration_provider_android.h" |
| +#endif |
| namespace content { |
| @@ -19,16 +23,16 @@ namespace content { |
| const int64 kMinimumVibrationDurationMs = 1; |
| VibrationMessageFilter::VibrationMessageFilter() { |
| + provider_.reset(GetContentClient()->browser()->OverrideVibrationProvider()); |
| +#if defined(OS_ANDROID) |
| + if (!provider_.get()) |
| + provider_.reset(new VibrationProviderAndroid()); |
| +#endif |
| } |
| VibrationMessageFilter::~VibrationMessageFilter() { |
| } |
| -// static |
| -bool VibrationMessageFilter::Register(JNIEnv* env) { |
| - return RegisterNativesImpl(env); |
| -} |
| - |
| bool VibrationMessageFilter::OnMessageReceived( |
| const IPC::Message& message, |
| bool* message_was_ok) { |
| @@ -44,30 +48,20 @@ bool VibrationMessageFilter::OnMessageReceived( |
| } |
| void VibrationMessageFilter::OnVibrate(int64 milliseconds) { |
| + if (!provider_.get()) return; |
|
Avi (use Gerrit)
2013/11/18 18:56:31
I have never seen the same-line if style in Chrome
ostap
2013/11/18 21:47:18
Done.
|
| + |
| // 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()) |
| - return; |
| - Java_VibrationMessageFilter_cancelVibration(AttachCurrentThread(), |
| - j_vibration_message_filter_.obj()); |
| + if (!provider_.get()) return; |
|
Avi (use Gerrit)
2013/11/18 18:56:31
ditto
ostap
2013/11/18 21:47:18
Done.
|
| + |
| + provider_->CancelVibration(); |
| } |
| } // namespace content |