1/*
2 *  Copyright (C) 2012 Samsung Electronics
3 *
4 *  This library is free software; you can redistribute it and/or
5 *  modify it under the terms of the GNU Library General Public
6 *  License as published by the Free Software Foundation; either
7 *  version 2 of the License, or (at your option) any later version.
8 *
9 *  This library is distributed in the hope that it will be useful,
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 *  Library General Public License for more details.
13 *
14 *  You should have received a copy of the GNU Library General Public License
15 *  along with this library; see the file COPYING.LIB.  If not, write to
16 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 *  Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "NavigatorVibration.h"
22
23#if ENABLE(VIBRATION)
24
25#include "ExceptionCode.h"
26#include "Frame.h"
27#include "Navigator.h"
28#include "Page.h"
29#include "Vibration.h"
30#include <wtf/Uint32Array.h>
31
32namespace WebCore {
33
34NavigatorVibration::NavigatorVibration()
35{
36}
37
38NavigatorVibration::~NavigatorVibration()
39{
40}
41
42void NavigatorVibration::vibrate(Navigator* navigator, unsigned time, ExceptionCode& ec)
43{
44    if (!navigator->frame()->page())
45        return;
46
47#if ENABLE(PAGE_VISIBILITY_API)
48    if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidden)
49        return;
50#endif
51
52    if (!Vibration::isActive(navigator->frame()->page())) {
53        ec = NOT_SUPPORTED_ERR;
54        return;
55    }
56
57    Vibration::from(navigator->frame()->page())->vibrate(time);
58}
59
60void NavigatorVibration::vibrate(Navigator* navigator, const VibrationPattern& pattern, ExceptionCode& ec)
61{
62    if (!navigator->frame()->page())
63        return;
64
65#if ENABLE(PAGE_VISIBILITY_API)
66    if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidden)
67        return;
68#endif
69
70    if (!Vibration::isActive(navigator->frame()->page())) {
71        ec = NOT_SUPPORTED_ERR;
72        return;
73    }
74
75    Vibration::from(navigator->frame()->page())->vibrate(pattern);
76}
77
78} // namespace WebCore
79
80#endif // ENABLE(VIBRATION)
81
82