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

Side by Side Diff: content/browser/vibration/vibration_dispatcher_host.cc

Issue 23496051: Make VibrationMessageFilter available to other platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased patch Created 7 years, 2 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 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_dispatcher_host.h"
6
7 #include <algorithm>
8
9 #include "base/safe_numerics.h"
10 #include "content/common/view_messages.h"
11 #include "content/port/browser/vibration_provider.h"
12 #include "content/public/browser/content_browser_client.h"
13 #include "content/public/common/content_client.h"
14 #include "third_party/WebKit/public/platform/WebVibration.h"
15
16 #if defined(OS_ANDROID)
17 #include "content/browser/vibration/vibration_provider_android.h"
18 #endif
19
20 namespace content {
21
22 class VibrationDispatcherHostImpl
23 : public VibrationDispatcherHost {
24 public:
25 VibrationDispatcherHostImpl();
26
27 // BrowserMessageFilter implementation.
28 virtual bool OnMessageReceived(const IPC::Message& message,
29 bool* message_was_ok) OVERRIDE;
30
31 void OnVibrate(int64 milliseconds);
32 void OnCancelVibration();
33
34 private:
35 virtual ~VibrationDispatcherHostImpl();
36
37 VibrationProvider* provider_;
38 DISALLOW_COPY_AND_ASSIGN(VibrationDispatcherHostImpl);
39 };
40
41 // Minimum duration of a vibration is 1 millisecond.
42 const int64 kMinimumVibrationDurationMs = 1;
43
44 VibrationDispatcherHostImpl::VibrationDispatcherHostImpl() {
45 provider_ = GetContentClient()->browser()->OverrideVibrationProvider();
46 #if defined(OS_ANDROID)
47 if (!provider_)
48 provider_ = new VibrationProviderAndroid();
49 #endif
50 }
51
52 VibrationDispatcherHostImpl::~VibrationDispatcherHostImpl() {
53 }
54
55 bool VibrationDispatcherHostImpl::OnMessageReceived(
56 const IPC::Message& message,
57 bool* message_was_ok) {
58 bool handled = true;
59 IPC_BEGIN_MESSAGE_MAP_EX(VibrationDispatcherHostImpl,
60 message,
61 *message_was_ok)
62 IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate)
63 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration)
64 IPC_MESSAGE_UNHANDLED(handled = false)
65 IPC_END_MESSAGE_MAP_EX()
66 return handled;
67 }
68
69 void VibrationDispatcherHostImpl::OnVibrate(int64 milliseconds) {
70 if (!provider_) return;
71
72 // Though the Blink implementation already sanitizes vibration times, don't
73 // trust any values passed from the renderer.
74 milliseconds = std::max(kMinimumVibrationDurationMs, std::min(milliseconds,
75 base::checked_numeric_cast<int64>(WebKit::kVibrationDurationMax)));
76
77 provider_->OnVibrate(milliseconds);
78 }
79
80 void VibrationDispatcherHostImpl::OnCancelVibration() {
81 if (!provider_) return;
82
83 provider_->OnCancelVibration();
84 }
85
86 // static
87 VibrationDispatcherHost* VibrationDispatcherHost::New() {
88 return new VibrationDispatcherHostImpl();
89 }
90
91 VibrationDispatcherHost::VibrationDispatcherHost() {
92 }
93
94 VibrationDispatcherHost::~VibrationDispatcherHost() {
95 }
96
97 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698