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..9ca18f2420d5b7d8b8ca18de3ff972cc5d8385ac |
--- /dev/null |
+++ b/content/browser/vibration/vibration_message_filter.cc |
@@ -0,0 +1,63 @@ |
+// 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 { |
+ |
+// Minimum duration of a vibration is 1 millisecond. |
+const int64 kMinimumVibrationDurationMs = 1; |
+ |
+// Maximum duration of a vibration is 10 seconds. |
+const int64 kMaximumVibrationDurationMs = 10000; |
+ |
+VibrationMessageFilter::VibrationMessageFilter() { |
+} |
+ |
+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(int64 milliseconds) { |
+ if (!vibration_service_.get()) { |
+ vibration_service_.reset(VibrationService::Create().release()); |
+ } |
+ if (vibration_service_.get()) { |
+ // Though the Blink implementation already sanitizes vibration times, don't |
+ // trust any values passed from the renderer. |
jam
2013/07/01 18:14:40
hmm, where is the sanitization happening there? se
Michael van Ouwerkerk
2013/07/02 17:52:39
It's in third_party/WebKit/Source/modules/vibratio
jam
2013/07/02 22:11:15
you can put them in a public file in the WebKit AP
|
+ milliseconds = std::max(kMinimumVibrationDurationMs, |
+ std::min(milliseconds, kMaximumVibrationDurationMs)); |
+ vibration_service_->Vibrate(milliseconds); |
+ } |
+} |
+ |
+void VibrationMessageFilter::OnCancelVibration() { |
+ if (!vibration_service_.get()) { |
+ vibration_service_.reset(VibrationService::Create().release()); |
jam
2013/07/01 18:14:40
when would this condition occur? i.e. that a vibra
Michael van Ouwerkerk
2013/07/02 17:52:39
I've changed this. The implementation was such tha
|
+ } |
+ if (vibration_service_.get()) |
jam
2013/07/01 18:14:40
what's the point of this line, since you're creati
Michael van Ouwerkerk
2013/07/02 17:52:39
I've changed this. The implementation was such tha
|
+ vibration_service_->CancelVibration(); |
+} |
+ |
+} // namespace content |