| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/vibration/vibration_message_filter.h" | 5 #include "content/browser/vibration/vibration_message_filter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 : BrowserMessageFilter(ViewMsgStart) { | 22 : BrowserMessageFilter(ViewMsgStart) { |
| 23 provider_.reset(GetContentClient()->browser()->OverrideVibrationProvider()); | 23 provider_.reset(GetContentClient()->browser()->OverrideVibrationProvider()); |
| 24 if (!provider_.get()) | 24 if (!provider_.get()) |
| 25 provider_.reset(CreateProvider()); | 25 provider_.reset(CreateProvider()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 VibrationMessageFilter::~VibrationMessageFilter() { | 28 VibrationMessageFilter::~VibrationMessageFilter() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool VibrationMessageFilter::OnMessageReceived( | 31 bool VibrationMessageFilter::OnMessageReceived( |
| 32 const IPC::Message& message, | 32 const IPC::Message& message) { |
| 33 bool* message_was_ok) { | |
| 34 bool handled = true; | 33 bool handled = true; |
| 35 IPC_BEGIN_MESSAGE_MAP_EX(VibrationMessageFilter, | 34 IPC_BEGIN_MESSAGE_MAP(VibrationMessageFilter, message) |
| 36 message, | |
| 37 *message_was_ok) | |
| 38 IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate) | 35 IPC_MESSAGE_HANDLER(ViewHostMsg_Vibrate, OnVibrate) |
| 39 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration) | 36 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelVibration, OnCancelVibration) |
| 40 IPC_MESSAGE_UNHANDLED(handled = false) | 37 IPC_MESSAGE_UNHANDLED(handled = false) |
| 41 IPC_END_MESSAGE_MAP_EX() | 38 IPC_END_MESSAGE_MAP() |
| 42 return handled; | 39 return handled; |
| 43 } | 40 } |
| 44 | 41 |
| 45 void VibrationMessageFilter::OnVibrate(int64 milliseconds) { | 42 void VibrationMessageFilter::OnVibrate(int64 milliseconds) { |
| 46 if (!provider_.get()) | 43 if (!provider_.get()) |
| 47 return; | 44 return; |
| 48 | 45 |
| 49 // Though the Blink implementation already sanitizes vibration times, don't | 46 // Though the Blink implementation already sanitizes vibration times, don't |
| 50 // trust any values passed from the renderer. | 47 // trust any values passed from the renderer. |
| 51 milliseconds = std::max(kMinimumVibrationDurationMs, std::min(milliseconds, | 48 milliseconds = std::max(kMinimumVibrationDurationMs, std::min(milliseconds, |
| 52 base::checked_cast<int64>(blink::kVibrationDurationMax))); | 49 base::checked_cast<int64>(blink::kVibrationDurationMax))); |
| 53 | 50 |
| 54 provider_->Vibrate(milliseconds); | 51 provider_->Vibrate(milliseconds); |
| 55 } | 52 } |
| 56 | 53 |
| 57 void VibrationMessageFilter::OnCancelVibration() { | 54 void VibrationMessageFilter::OnCancelVibration() { |
| 58 if (!provider_.get()) | 55 if (!provider_.get()) |
| 59 return; | 56 return; |
| 60 | 57 |
| 61 provider_->CancelVibration(); | 58 provider_->CancelVibration(); |
| 62 } | 59 } |
| 63 | 60 |
| 64 #if !defined(OS_ANDROID) | 61 #if !defined(OS_ANDROID) |
| 65 // static | 62 // static |
| 66 VibrationProvider* VibrationMessageFilter::CreateProvider() { | 63 VibrationProvider* VibrationMessageFilter::CreateProvider() { |
| 67 return NULL; | 64 return NULL; |
| 68 } | 65 } |
| 69 #endif | 66 #endif |
| 70 } // namespace content | 67 } // namespace content |
| OLD | NEW |