| 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/frame/LocalFrame.h" | 22 #include "core/frame/LocalFrame.h" |
| 23 #include "core/frame/Navigator.h" | 23 #include "core/frame/Navigator.h" |
| 24 #include "core/frame/UseCounter.h" | 24 #include "core/frame/UseCounter.h" |
| 25 #include "core/page/Page.h" | 25 #include "core/page/Page.h" |
| 26 #include "modules/vibration/VibrationController.h" | 26 #include "modules/vibration/VibrationController.h" |
| 27 #include "platform/Histogram.h" |
| 28 #include "platform/UserGestureIndicator.h" |
| 27 | 29 |
| 28 namespace blink { | 30 namespace blink { |
| 29 | 31 |
| 30 NavigatorVibration::NavigatorVibration(Navigator& navigator) | 32 NavigatorVibration::NavigatorVibration(Navigator& navigator) |
| 31 : DOMWindowProperty(navigator.frame()) | 33 : DOMWindowProperty(navigator.frame()) |
| 32 { | 34 { |
| 33 } | 35 } |
| 34 | 36 |
| 35 NavigatorVibration::~NavigatorVibration() | 37 NavigatorVibration::~NavigatorVibration() |
| 36 { | 38 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 // static | 66 // static |
| 65 bool NavigatorVibration::vibrate(Navigator& navigator, const VibrationPattern& p
attern) | 67 bool NavigatorVibration::vibrate(Navigator& navigator, const VibrationPattern& p
attern) |
| 66 { | 68 { |
| 67 LocalFrame* frame = navigator.frame(); | 69 LocalFrame* frame = navigator.frame(); |
| 68 | 70 |
| 69 // There will be no frame if the window has been closed, but a JavaScript | 71 // There will be no frame if the window has been closed, but a JavaScript |
| 70 // reference to |window| or |navigator| was retained in another window. | 72 // reference to |window| or |navigator| was retained in another window. |
| 71 if (!frame) | 73 if (!frame) |
| 72 return false; | 74 return false; |
| 73 | 75 collectHistogramMetrics(*frame); |
| 74 UseCounter::count(frame, UseCounter::NavigatorVibrate); | |
| 75 if (!frame->isMainFrame()) | |
| 76 UseCounter::count(frame, UseCounter::NavigatorVibrateSubFrame); | |
| 77 | 76 |
| 78 DCHECK(frame->document()); | 77 DCHECK(frame->document()); |
| 79 DCHECK(frame->page()); | 78 DCHECK(frame->page()); |
| 80 | 79 |
| 81 if (!frame->page()->isPageVisible()) | 80 if (!frame->page()->isPageVisible()) |
| 82 return false; | 81 return false; |
| 83 | 82 |
| 84 return NavigatorVibration::from(navigator).controller()->vibrate(pattern); | 83 return NavigatorVibration::from(navigator).controller()->vibrate(pattern); |
| 85 } | 84 } |
| 86 | 85 |
| 86 // static |
| 87 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) |
| 88 { |
| 89 NavigatorVibrationType type; |
| 90 bool userGesture = UserGestureIndicator::processingUserGesture(); |
| 91 UseCounter::count(&frame, UseCounter::NavigatorVibrate); |
| 92 if (!frame.isMainFrame()) { |
| 93 UseCounter::count(&frame, UseCounter::NavigatorVibrateSubFrame); |
| 94 if (frame.isCrossOrigin()) { |
| 95 if (userGesture) |
| 96 type = NavigatorVibrationType::CrossOriginSubFrameWithUserGestur
e; |
| 97 else |
| 98 type = NavigatorVibrationType::CrossOriginSubFrameNoUserGesture; |
| 99 } else { |
| 100 if (userGesture) |
| 101 type = NavigatorVibrationType::SameOriginSubFrameWithUserGesture
; |
| 102 else |
| 103 type = NavigatorVibrationType::SameOriginSubFrameNoUserGesture; |
| 104 } |
| 105 } else { |
| 106 if (userGesture) |
| 107 type = NavigatorVibrationType::MainFrameWithUserGesture; |
| 108 else |
| 109 type = NavigatorVibrationType::MainFrameNoUserGesture; |
| 110 } |
| 111 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, ("Vibra
tion.Context", NavigatorVibrationType::EnumMax)); |
| 112 NavigatorVibrateHistogram.count(type); |
| 113 } |
| 114 |
| 87 VibrationController* NavigatorVibration::controller() | 115 VibrationController* NavigatorVibration::controller() |
| 88 { | 116 { |
| 89 if (!m_controller && frame()) | 117 if (!m_controller && frame()) |
| 90 m_controller = new VibrationController(*frame()->document()); | 118 m_controller = new VibrationController(*frame()->document()); |
| 91 | 119 |
| 92 return m_controller.get(); | 120 return m_controller.get(); |
| 93 } | 121 } |
| 94 | 122 |
| 95 void NavigatorVibration::willDetachGlobalObjectFromFrame() | 123 void NavigatorVibration::willDetachGlobalObjectFromFrame() |
| 96 { | 124 { |
| 97 if (m_controller) { | 125 if (m_controller) { |
| 98 m_controller->cancel(); | 126 m_controller->cancel(); |
| 99 m_controller = nullptr; | 127 m_controller = nullptr; |
| 100 } | 128 } |
| 101 } | 129 } |
| 102 | 130 |
| 103 DEFINE_TRACE(NavigatorVibration) | 131 DEFINE_TRACE(NavigatorVibration) |
| 104 { | 132 { |
| 105 visitor->trace(m_controller); | 133 visitor->trace(m_controller); |
| 106 Supplement<Navigator>::trace(visitor); | 134 Supplement<Navigator>::trace(visitor); |
| 107 DOMWindowProperty::trace(visitor); | 135 DOMWindowProperty::trace(visitor); |
| 108 } | 136 } |
| 109 | 137 |
| 110 } // namespace blink | 138 } // namespace blink |
| OLD | NEW |