Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp

Issue 2146343002: Revert of Remove DOMWindowProperty::willDetachGlobalObjectFromFrame Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
23 #include "core/frame/LocalFrame.h" 22 #include "core/frame/LocalFrame.h"
24 #include "core/frame/Navigator.h" 23 #include "core/frame/Navigator.h"
25 #include "core/frame/UseCounter.h" 24 #include "core/frame/UseCounter.h"
26 #include "core/page/Page.h" 25 #include "core/page/Page.h"
27 #include "modules/vibration/VibrationController.h" 26 #include "modules/vibration/VibrationController.h"
28 #include "platform/Histogram.h" 27 #include "platform/Histogram.h"
29 #include "platform/UserGestureIndicator.h" 28 #include "platform/UserGestureIndicator.h"
30 29
31 namespace blink { 30 namespace blink {
32 31
33 NavigatorVibration::NavigatorVibration(Navigator& navigator) 32 NavigatorVibration::NavigatorVibration(Navigator& navigator)
34 : ContextLifecycleObserver(navigator.frame()->document()) 33 : DOMWindowProperty(navigator.frame())
35 { 34 {
36 } 35 }
37 36
38 NavigatorVibration::~NavigatorVibration() 37 NavigatorVibration::~NavigatorVibration()
39 { 38 {
40 } 39 }
41 40
42 // static 41 // static
43 NavigatorVibration& NavigatorVibration::from(Navigator& navigator) 42 NavigatorVibration& NavigatorVibration::from(Navigator& navigator)
44 { 43 {
(...skipping 29 matching lines...) Expand all
74 if (!frame) 73 if (!frame)
75 return false; 74 return false;
76 collectHistogramMetrics(*frame); 75 collectHistogramMetrics(*frame);
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(*frame)->vibrate(patte rn); 83 return NavigatorVibration::from(navigator).controller()->vibrate(pattern);
85 } 84 }
86 85
87 // static 86 // static
88 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame) 87 void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame)
89 { 88 {
90 NavigatorVibrationType type; 89 NavigatorVibrationType type;
91 bool userGesture = UserGestureIndicator::processingUserGesture(); 90 bool userGesture = UserGestureIndicator::processingUserGesture();
92 UseCounter::count(&frame, UseCounter::NavigatorVibrate); 91 UseCounter::count(&frame, UseCounter::NavigatorVibrate);
93 if (!frame.isMainFrame()) { 92 if (!frame.isMainFrame()) {
94 UseCounter::count(&frame, UseCounter::NavigatorVibrateSubFrame); 93 UseCounter::count(&frame, UseCounter::NavigatorVibrateSubFrame);
(...skipping 11 matching lines...) Expand all
106 } else { 105 } else {
107 if (userGesture) 106 if (userGesture)
108 type = NavigatorVibrationType::MainFrameWithUserGesture; 107 type = NavigatorVibrationType::MainFrameWithUserGesture;
109 else 108 else
110 type = NavigatorVibrationType::MainFrameNoUserGesture; 109 type = NavigatorVibrationType::MainFrameNoUserGesture;
111 } 110 }
112 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, ("Vibra tion.Context", NavigatorVibrationType::EnumMax)); 111 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, ("Vibra tion.Context", NavigatorVibrationType::EnumMax));
113 NavigatorVibrateHistogram.count(type); 112 NavigatorVibrateHistogram.count(type);
114 } 113 }
115 114
116 VibrationController* NavigatorVibration::controller(const LocalFrame& frame) 115 VibrationController* NavigatorVibration::controller()
117 { 116 {
118 if (!m_controller) 117 if (!m_controller && frame())
119 m_controller = new VibrationController(*frame.document()); 118 m_controller = new VibrationController(*frame()->document());
120 119
121 return m_controller.get(); 120 return m_controller.get();
122 } 121 }
123 122
124 void NavigatorVibration::contextDestroyed() 123 void NavigatorVibration::willDetachGlobalObjectFromFrame()
125 { 124 {
126 if (m_controller) { 125 if (m_controller) {
127 m_controller->cancel(); 126 m_controller->cancel();
128 m_controller = nullptr; 127 m_controller = nullptr;
129 } 128 }
130 } 129 }
131 130
132 DEFINE_TRACE(NavigatorVibration) 131 DEFINE_TRACE(NavigatorVibration)
133 { 132 {
134 visitor->trace(m_controller); 133 visitor->trace(m_controller);
135 Supplement<Navigator>::trace(visitor); 134 Supplement<Navigator>::trace(visitor);
136 ContextLifecycleObserver::trace(visitor); 135 DOMWindowProperty::trace(visitor);
137 } 136 }
138 137
139 } // namespace blink 138 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698