OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Samsung Electronics | 2 * Copyright (C) 2012 Samsung Electronics |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "modules/vibration/NavigatorVibration.h" | 20 #include "modules/vibration/NavigatorVibration.h" |
21 | 21 |
| 22 #include "core/dom/Document.h" |
22 #include "core/frame/LocalFrame.h" | 23 #include "core/frame/LocalFrame.h" |
23 #include "core/frame/Navigator.h" | 24 #include "core/frame/Navigator.h" |
24 #include "core/frame/UseCounter.h" | 25 #include "core/frame/UseCounter.h" |
25 #include "core/page/Page.h" | 26 #include "core/page/Page.h" |
26 #include "modules/vibration/VibrationController.h" | 27 #include "modules/vibration/VibrationController.h" |
27 #include "platform/Histogram.h" | 28 #include "platform/Histogram.h" |
28 #include "platform/UserGestureIndicator.h" | 29 #include "platform/UserGestureIndicator.h" |
29 | 30 |
30 namespace blink { | 31 namespace blink { |
31 | 32 |
32 NavigatorVibration::NavigatorVibration(Navigator& navigator) | 33 NavigatorVibration::NavigatorVibration(Navigator& navigator) |
33 : DOMWindowProperty(navigator.frame()) | 34 : ContextLifecycleObserver(navigator.frame()->document()) |
34 { | 35 { |
35 } | 36 } |
36 | 37 |
37 NavigatorVibration::~NavigatorVibration() | 38 NavigatorVibration::~NavigatorVibration() |
38 { | 39 { |
39 } | 40 } |
40 | 41 |
41 // static | 42 // static |
42 NavigatorVibration& NavigatorVibration::from(Navigator& navigator) | 43 NavigatorVibration& NavigatorVibration::from(Navigator& navigator) |
43 { | 44 { |
(...skipping 29 matching lines...) Expand all Loading... |
73 if (!frame) | 74 if (!frame) |
74 return false; | 75 return false; |
75 collectHistogramMetrics(*frame); | 76 collectHistogramMetrics(*frame); |
76 | 77 |
77 DCHECK(frame->document()); | 78 DCHECK(frame->document()); |
78 DCHECK(frame->page()); | 79 DCHECK(frame->page()); |
79 | 80 |
80 if (!frame->page()->isPageVisible()) | 81 if (!frame->page()->isPageVisible()) |
81 return false; | 82 return false; |
82 | 83 |
83 return NavigatorVibration::from(navigator).controller()->vibrate(pattern); | 84 return NavigatorVibration::from(navigator).controller(*frame)->vibrate(patte
rn); |
84 } | 85 } |
85 | 86 |
86 // static | 87 // static |
87 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) | 88 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) |
88 { | 89 { |
89 NavigatorVibrationType type; | 90 NavigatorVibrationType type; |
90 bool userGesture = UserGestureIndicator::processingUserGesture(); | 91 bool userGesture = UserGestureIndicator::processingUserGesture(); |
91 UseCounter::count(&frame, UseCounter::NavigatorVibrate); | 92 UseCounter::count(&frame, UseCounter::NavigatorVibrate); |
92 if (!frame.isMainFrame()) { | 93 if (!frame.isMainFrame()) { |
93 UseCounter::count(&frame, UseCounter::NavigatorVibrateSubFrame); | 94 UseCounter::count(&frame, UseCounter::NavigatorVibrateSubFrame); |
(...skipping 11 matching lines...) Expand all Loading... |
105 } else { | 106 } else { |
106 if (userGesture) | 107 if (userGesture) |
107 type = NavigatorVibrationType::MainFrameWithUserGesture; | 108 type = NavigatorVibrationType::MainFrameWithUserGesture; |
108 else | 109 else |
109 type = NavigatorVibrationType::MainFrameNoUserGesture; | 110 type = NavigatorVibrationType::MainFrameNoUserGesture; |
110 } | 111 } |
111 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, ("Vibra
tion.Context", NavigatorVibrationType::EnumMax)); | 112 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, ("Vibra
tion.Context", NavigatorVibrationType::EnumMax)); |
112 NavigatorVibrateHistogram.count(type); | 113 NavigatorVibrateHistogram.count(type); |
113 } | 114 } |
114 | 115 |
115 VibrationController* NavigatorVibration::controller() | 116 VibrationController* NavigatorVibration::controller(const LocalFrame& frame) |
116 { | 117 { |
117 if (!m_controller && frame()) | 118 if (!m_controller) |
118 m_controller = new VibrationController(*frame()->document()); | 119 m_controller = new VibrationController(*frame.document()); |
119 | 120 |
120 return m_controller.get(); | 121 return m_controller.get(); |
121 } | 122 } |
122 | 123 |
123 void NavigatorVibration::willDetachGlobalObjectFromFrame() | 124 void NavigatorVibration::contextDestroyed() |
124 { | 125 { |
125 if (m_controller) { | 126 if (m_controller) { |
126 m_controller->cancel(); | 127 m_controller->cancel(); |
127 m_controller = nullptr; | 128 m_controller = nullptr; |
128 } | 129 } |
129 } | 130 } |
130 | 131 |
131 DEFINE_TRACE(NavigatorVibration) | 132 DEFINE_TRACE(NavigatorVibration) |
132 { | 133 { |
133 visitor->trace(m_controller); | 134 visitor->trace(m_controller); |
134 Supplement<Navigator>::trace(visitor); | 135 Supplement<Navigator>::trace(visitor); |
135 DOMWindowProperty::trace(visitor); | 136 ContextLifecycleObserver::trace(visitor); |
136 } | 137 } |
137 | 138 |
138 } // namespace blink | 139 } // namespace blink |
OLD | NEW |