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

Side by Side 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 int64, not int64_t. 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 unified diff | Download patch
OLDNEW
(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 // Minimum duration of a vibration is 1 millisecond.
14 const int64 kMinimumVibrationDurationMs = 1;
15
16 // Maximum duration of a vibration is 10 seconds.
17 const int64 kMaximumVibrationDurationMs = 10000;
18
19 VibrationMessageFilter::VibrationMessageFilter() {
20 }
21
22 VibrationMessageFilter::~VibrationMessageFilter() {
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
24 if (vibration_service_.get())
25 vibration_service_->CancelVibration();
26 }
27
28 bool VibrationMessageFilter::OnMessageReceived(
29 const IPC::Message& message,
30 bool* message_was_ok) {
31 bool handled = true;
32 IPC_BEGIN_MESSAGE_MAP_EX(VibrationMessageFilter,
33 message,
34 *message_was_ok)
35 IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate)
36 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration)
37 IPC_MESSAGE_UNHANDLED(handled = false)
38 IPC_END_MESSAGE_MAP_EX()
39 return handled;
40 }
41
42 void VibrationMessageFilter::OnVibrate(int64 milliseconds) {
43 if (!vibration_service_.get()) {
44 vibration_service_.reset(VibrationService::Create().release());
45 }
46 if (vibration_service_.get()) {
47 // Though the Blink implementation already sanitizes vibration times, don't
48 // 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
49 milliseconds = std::max(kMinimumVibrationDurationMs,
50 std::min(milliseconds, kMaximumVibrationDurationMs));
51 vibration_service_->Vibrate(milliseconds);
52 }
53 }
54
55 void VibrationMessageFilter::OnCancelVibration() {
56 if (!vibration_service_.get()) {
57 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
58 }
59 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
60 vibration_service_->CancelVibration();
61 }
62
63 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698