OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/vibration/vibration_message_filter.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "content/common/view_messages.h" | |
10 | |
11 namespace content { | |
12 | |
13 // Maximum duration of a vibration is 10 seconds. | |
14 const unsigned int kMaximumVibrationDurationMs = 10000; | |
15 | |
16 VibrationMessageFilter::~VibrationMessageFilter() { | |
17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
18 if (vibration_service_.get()) | |
19 vibration_service_->CancelVibration(); | |
20 } | |
21 | |
22 bool VibrationMessageFilter::OnMessageReceived( | |
23 const IPC::Message& message, | |
24 bool* message_was_ok) { | |
25 bool handled = true; | |
26 IPC_BEGIN_MESSAGE_MAP_EX(VibrationMessageFilter, | |
27 message, | |
28 *message_was_ok) | |
29 IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate) | |
30 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration) | |
31 IPC_MESSAGE_UNHANDLED(handled = false) | |
32 IPC_END_MESSAGE_MAP_EX() | |
33 return handled; | |
34 } | |
35 | |
36 void VibrationMessageFilter::OnVibrate(unsigned int milliseconds) { | |
palmer
2013/06/21 18:17:40
int64_t
Michael van Ouwerkerk
2013/06/24 13:46:57
Done.
| |
37 if (!vibration_service_.get()) { | |
38 vibration_service_.reset(VibrationService::Create().release()); | |
39 } | |
40 if (vibration_service_.get()) { | |
41 // Though the Blink implementation rejects vibration times that are too | |
42 // long, don't trust the values passed from the renderer. | |
43 milliseconds = std::min(milliseconds, kMaximumVibrationDurationMs); | |
palmer
2013/06/21 18:17:40
You'll want to ensure milliseconds > 0 as well, si
Michael van Ouwerkerk
2013/06/24 13:46:57
Done.
| |
44 vibration_service_->Vibrate(milliseconds); | |
45 } | |
46 } | |
47 | |
48 void VibrationMessageFilter::OnCancelVibration() { | |
49 if (!vibration_service_.get()) { | |
50 vibration_service_.reset(VibrationService::Create().release()); | |
51 } | |
52 if (vibration_service_.get()) | |
53 vibration_service_->CancelVibration(); | |
54 } | |
55 | |
56 } // namespace content | |
OLD | NEW |