| Index: Source/modules/vibration/NavigatorVibration.cpp
|
| diff --git a/Source/modules/vibration/NavigatorVibration.cpp b/Source/modules/vibration/NavigatorVibration.cpp
|
| index b8fd026b8522b4fe913424749140cd41d38e458a..e43606838d30cbb807e3076b70c4e329f0153689 100644
|
| --- a/Source/modules/vibration/NavigatorVibration.cpp
|
| +++ b/Source/modules/vibration/NavigatorVibration.cpp
|
| @@ -20,6 +20,7 @@
|
| #include "config.h"
|
| #include "modules/vibration/NavigatorVibration.h"
|
|
|
| +#include "bindings/modules/v8/UnionTypesModules.h"
|
| #include "core/frame/LocalFrame.h"
|
| #include "core/frame/Navigator.h"
|
| #include "core/page/PageVisibilityState.h"
|
| @@ -47,30 +48,11 @@ NavigatorVibration::~NavigatorVibration()
|
|
|
| bool NavigatorVibration::vibrate(const VibrationPattern& pattern)
|
| {
|
| - VibrationPattern sanitized = pattern;
|
| - size_t length = sanitized.size();
|
| -
|
| - // If the pattern is too long then truncate it.
|
| - if (length > kVibrationPatternLengthMax) {
|
| - sanitized.shrink(kVibrationPatternLengthMax);
|
| - length = kVibrationPatternLengthMax;
|
| - }
|
| -
|
| - // If any pattern entry is too long then truncate it.
|
| - for (size_t i = 0; i < length; ++i) {
|
| - if (sanitized[i] > kVibrationDurationMax)
|
| - sanitized[i] = kVibrationDurationMax;
|
| - }
|
| -
|
| - // If the last item in the pattern is a pause then discard it.
|
| - if (length && !(length % 2))
|
| - sanitized.removeLast();
|
| -
|
| // Cancelling clears the stored pattern so do it before setting the new one.
|
| if (m_isVibrating)
|
| cancelVibration();
|
|
|
| - m_pattern = sanitized;
|
| + m_pattern = sanitizeVibrationPattern(pattern);
|
|
|
| if (m_timerStart.isActive())
|
| m_timerStart.stop();
|
| @@ -168,6 +150,42 @@ NavigatorVibration& NavigatorVibration::from(Page& page)
|
| return *navigatorVibration;
|
| }
|
|
|
| +NavigatorVibration::VibrationPattern NavigatorVibration::sanitizeVibrationPattern(const UnsignedLongOrUnsignedLongSequence& pattern)
|
| +{
|
| + VibrationPattern sanitized;
|
| +
|
| + if (pattern.isUnsignedLong())
|
| + sanitized.append(pattern.getAsUnsignedLong());
|
| + else if (pattern.isUnsignedLongSequence())
|
| + sanitized = pattern.getAsUnsignedLongSequence();
|
| +
|
| + return sanitizeVibrationPattern(sanitized);
|
| +}
|
| +
|
| +NavigatorVibration::VibrationPattern NavigatorVibration::sanitizeVibrationPattern(const VibrationPattern& pattern)
|
| +{
|
| + VibrationPattern sanitized = pattern;
|
| + size_t length = sanitized.size();
|
| +
|
| + // If the pattern is too long then truncate it.
|
| + if (length > kVibrationPatternLengthMax) {
|
| + sanitized.shrink(kVibrationPatternLengthMax);
|
| + length = kVibrationPatternLengthMax;
|
| + }
|
| +
|
| + // If any pattern entry is too long then truncate it.
|
| + for (size_t i = 0; i < length; ++i) {
|
| + if (sanitized[i] > kVibrationDurationMax)
|
| + sanitized[i] = kVibrationDurationMax;
|
| + }
|
| +
|
| + // If the last item in the pattern is a pause then discard it.
|
| + if (length && !(length % 2))
|
| + sanitized.removeLast();
|
| +
|
| + return sanitized;
|
| +}
|
| +
|
| const char* NavigatorVibration::supplementName()
|
| {
|
| return "NavigatorVibration";
|
|
|