Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: content/browser/android/vibration_message_filter.cc

Issue 16781002: Vibration API: plumbing from Blink to Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/vibration_message_filter.cc
diff --git a/content/browser/android/vibration_message_filter.cc b/content/browser/android/vibration_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e8d293e8a620b413956329935085063e564effb1
--- /dev/null
+++ b/content/browser/android/vibration_message_filter.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// 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 <algorithm>
+
+#include "base/safe_numerics.h"
+#include "content/common/view_messages.h"
+#include "jni/VibrationMessageFilter_jni.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() {
+}
+
+VibrationMessageFilter::~VibrationMessageFilter() {
+}
+
+// static
+bool VibrationMessageFilter::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+bool VibrationMessageFilter::OnMessageReceived(
+ const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(VibrationMessageFilter,
+ message,
+ *message_was_ok)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+ return handled;
+}
+
+void VibrationMessageFilter::OnVibrate(int64 milliseconds) {
+ // Though the Blink implementation already sanitizes vibration times, don't
+ // trust any values passed from the renderer.
+ milliseconds = std::max(kMinimumVibrationDurationMs,
+ std::min(milliseconds,
+ base::checked_numeric_cast<int64>(WebKit::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);
+}
+
+void VibrationMessageFilter::OnCancelVibration() {
+ Java_VibrationMessageFilter_cancelVibration(AttachCurrentThread(),
+ j_vibration_message_filter_.obj());
+}
+
+} // namespace content
« no previous file with comments | « content/browser/android/vibration_message_filter.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698