Chromium Code Reviews| 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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "bindings/core/v8/ConditionalFeatures.h" | 22 #include "bindings/core/v8/ConditionalFeatures.h" |
| 23 #include "core/dom/Document.h" | 23 #include "core/dom/Document.h" |
| 24 #include "core/frame/LocalDOMWindow.h" | 24 #include "core/frame/LocalDOMWindow.h" |
| 25 #include "core/frame/LocalFrame.h" | 25 #include "core/frame/LocalFrame.h" |
| 26 #include "core/frame/Navigator.h" | 26 #include "core/frame/Navigator.h" |
| 27 #include "core/frame/UseCounter.h" | 27 #include "core/frame/UseCounter.h" |
| 28 #include "core/page/Page.h" | 28 #include "core/page/Page.h" |
| 29 #include "modules/vibration/VibrationController.h" | 29 #include "modules/vibration/VibrationController.h" |
| 30 #include "platform/Histogram.h" | 30 #include "platform/Histogram.h" |
| 31 #include "platform/UserGestureIndicator.h" | 31 #include "platform/UserGestureIndicator.h" |
| 32 #include "public/platform/site_engagement.mojom-blink.h" | |
| 32 | 33 |
| 33 namespace blink { | 34 namespace blink { |
| 34 | 35 |
| 35 NavigatorVibration::NavigatorVibration(Navigator& navigator) | 36 NavigatorVibration::NavigatorVibration(Navigator& navigator) |
| 36 : ContextLifecycleObserver(navigator.frame()->document()) {} | 37 : ContextLifecycleObserver(navigator.frame()->document()) {} |
| 37 | 38 |
| 38 NavigatorVibration::~NavigatorVibration() {} | 39 NavigatorVibration::~NavigatorVibration() {} |
| 39 | 40 |
| 40 // static | 41 // static |
| 41 NavigatorVibration& NavigatorVibration::from(Navigator& navigator) { | 42 NavigatorVibration& NavigatorVibration::from(Navigator& navigator) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 } | 118 } |
| 118 } else { | 119 } else { |
| 119 if (userGesture) | 120 if (userGesture) |
| 120 type = NavigatorVibrationType::MainFrameWithUserGesture; | 121 type = NavigatorVibrationType::MainFrameWithUserGesture; |
| 121 else | 122 else |
| 122 type = NavigatorVibrationType::MainFrameNoUserGesture; | 123 type = NavigatorVibrationType::MainFrameNoUserGesture; |
| 123 } | 124 } |
| 124 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, | 125 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, |
| 125 ("Vibration.Context", NavigatorVibrationType::EnumMax)); | 126 ("Vibration.Context", NavigatorVibrationType::EnumMax)); |
| 126 NavigatorVibrateHistogram.count(type); | 127 NavigatorVibrateHistogram.count(type); |
| 128 | |
| 129 mojom::blink::EngagementLevel level = frame.document()->getEngagementLevel(); | |
| 130 if (level == mojom::blink::EngagementLevel::NONE) | |
|
haraken
2017/01/06 00:56:27
Shall we use a switch statement?
dominickn
2017/01/06 01:38:34
Done - though it's a bit more verbose as a result.
| |
| 131 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementNone); | |
| 132 else if (level == mojom::blink::EngagementLevel::MINIMAL) | |
| 133 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementMinimal); | |
| 134 else if (level == mojom::blink::EngagementLevel::LOW) | |
| 135 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementLow); | |
| 136 else if (level == mojom::blink::EngagementLevel::MEDIUM) | |
| 137 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementMedium); | |
| 138 else if (level == mojom::blink::EngagementLevel::HIGH) | |
| 139 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementHigh); | |
| 140 else if (level == mojom::blink::EngagementLevel::MAX) | |
| 141 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementMax); | |
| 142 else | |
| 143 NOTREACHED(); | |
| 127 } | 144 } |
| 128 | 145 |
| 129 VibrationController* NavigatorVibration::controller(const LocalFrame& frame) { | 146 VibrationController* NavigatorVibration::controller(const LocalFrame& frame) { |
| 130 if (!m_controller) | 147 if (!m_controller) |
| 131 m_controller = new VibrationController(*frame.document()); | 148 m_controller = new VibrationController(*frame.document()); |
| 132 | 149 |
| 133 return m_controller.get(); | 150 return m_controller.get(); |
| 134 } | 151 } |
| 135 | 152 |
| 136 void NavigatorVibration::contextDestroyed() { | 153 void NavigatorVibration::contextDestroyed() { |
| 137 if (m_controller) { | 154 if (m_controller) { |
| 138 m_controller->cancel(); | 155 m_controller->cancel(); |
| 139 m_controller = nullptr; | 156 m_controller = nullptr; |
| 140 } | 157 } |
| 141 } | 158 } |
| 142 | 159 |
| 143 DEFINE_TRACE(NavigatorVibration) { | 160 DEFINE_TRACE(NavigatorVibration) { |
| 144 visitor->trace(m_controller); | 161 visitor->trace(m_controller); |
| 145 Supplement<Navigator>::trace(visitor); | 162 Supplement<Navigator>::trace(visitor); |
| 146 ContextLifecycleObserver::trace(visitor); | 163 ContextLifecycleObserver::trace(visitor); |
| 147 } | 164 } |
| 148 | 165 |
| 149 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |