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

Unified Diff: content/browser/vibration/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, 6 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/vibration/vibration_message_filter.cc
diff --git a/content/browser/vibration/vibration_message_filter.cc b/content/browser/vibration/vibration_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7d8698e90317785b184417359948c9ee9655008
--- /dev/null
+++ b/content/browser/vibration/vibration_message_filter.cc
@@ -0,0 +1,56 @@
+// 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/vibration/vibration_message_filter.h"
+
+#include <algorithm>
+
+#include "content/common/view_messages.h"
+
+namespace content {
+
+// Maximum duration of a vibration is 10 seconds.
+const unsigned kMaximumVibrationDurationMs = 10000;
bulach 2013/06/20 14:21:04 nit: int
Michael van Ouwerkerk 2013/06/20 17:34:09 Why int? Did you mean 'unsigned int'? The vibratio
bulach 2013/06/20 18:11:47 sorry, I should've been clearer: "unsigned int" ra
Michael van Ouwerkerk 2013/06/21 09:53:38 Done in the whole patch.
+
+VibrationMessageFilter::VibrationMessageFilter(
+ VibrationService* vibration_service) {
+ // TODO(mvanouwerkerk): Consider instantiating this lazily - crbug.com/250810
+ vibration_service_.reset(vibration_service);
+}
+
+VibrationMessageFilter::~VibrationMessageFilter() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (vibration_service_.get())
+ vibration_service_->CancelVibration();
+}
+
+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(unsigned milliseconds) {
+ // Though the Blink implementation rejects vibration times that are too long,
+ // don't trust the values passed from the renderer.
+ if (vibration_service_.get()) {
+ vibration_service_->Vibrate(
+ std::min(milliseconds, kMaximumVibrationDurationMs));
+ }
+}
+
+void VibrationMessageFilter::OnCancelVibration() {
+ if (vibration_service_.get())
+ vibration_service_->CancelVibration();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698