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

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: Use 'unsigned int' everywhere. 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..3b44774aebfe8512ea01db0af1f3d8f60abd6ac5
--- /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 int kMaximumVibrationDurationMs = 10000;
+
+VibrationMessageFilter::VibrationMessageFilter(
+ scoped_ptr<VibrationService> vibration_service) {
+ // TODO(mvanouwerkerk): Consider instantiating this lazily - crbug.com/250810
+ vibration_service_.reset(vibration_service.release());
bulach 2013/06/21 12:55:54 sorry, I just realized.. this is _always_ going to
Michael van Ouwerkerk 2013/06/21 15:07:41 Done.
+}
+
+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 int 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