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

Side by Side Diff: third_party/WebKit/Source/modules/gamepad/NavigatorGamepad.cpp

Issue 2138003002: Remove DOMWindowProperty::willDetachGlobalObjectFromFrame (Closed) 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) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 sampleGamepads<Gamepad>(m_gamepads.get()); 100 sampleGamepads<Gamepad>(m_gamepads.get());
101 return m_gamepads.get(); 101 return m_gamepads.get();
102 } 102 }
103 103
104 DEFINE_TRACE(NavigatorGamepad) 104 DEFINE_TRACE(NavigatorGamepad)
105 { 105 {
106 visitor->trace(m_gamepads); 106 visitor->trace(m_gamepads);
107 visitor->trace(m_pendingEvents); 107 visitor->trace(m_pendingEvents);
108 visitor->trace(m_dispatchOneEventRunner); 108 visitor->trace(m_dispatchOneEventRunner);
109 Supplement<Navigator>::trace(visitor); 109 Supplement<Navigator>::trace(visitor);
110 DOMWindowProperty::trace(visitor); 110 ContextLifecycleObserver::trace(visitor);
111 PlatformEventController::trace(visitor); 111 PlatformEventController::trace(visitor);
112 DOMWindowLifecycleObserver::trace(visitor); 112 DOMWindowLifecycleObserver::trace(visitor);
113 } 113 }
114 114
115 bool NavigatorGamepad::startUpdatingIfAttached() 115 bool NavigatorGamepad::startUpdatingIfAttached()
116 { 116 {
117 Document* document = static_cast<Document*>(getExecutionContext());
117 // The frame must be attached to start updating. 118 // The frame must be attached to start updating.
118 if (frame() && frame()->host()) { 119 if (document && document->frame() && document->frame()->host()) {
dcheng 2016/07/11 13:38:20 I wonder if it's possible to have document->frame(
119 startUpdating(); 120 startUpdating();
120 return true; 121 return true;
121 } 122 }
122 return false; 123 return false;
123 } 124 }
124 125
125 void NavigatorGamepad::didUpdateData() 126 void NavigatorGamepad::didUpdateData()
126 { 127 {
127 // We should stop listening once we detached. 128 // We should stop listening once we detached.
128 ASSERT(frame()); 129 Document* document = static_cast<Document*>(getExecutionContext());
129 ASSERT(frame()->domWindow()); 130 DCHECK(document->frame());
131 DCHECK(document->frame()->domWindow());
130 132
131 // We register to the dispatcher before sampling gamepads so we need to chec k if we actually have an event listener. 133 // We register to the dispatcher before sampling gamepads so we need to chec k if we actually have an event listener.
132 if (!m_hasEventListener) 134 if (!m_hasEventListener)
133 return; 135 return;
134 136
135 Document* document = frame()->domWindow()->document();
136 if (document->activeDOMObjectsAreStopped() || document->activeDOMObjectsAreS uspended()) 137 if (document->activeDOMObjectsAreStopped() || document->activeDOMObjectsAreS uspended())
137 return; 138 return;
138 139
139 const GamepadDispatcher::ConnectionChange& change = GamepadDispatcher::insta nce().latestConnectionChange(); 140 const GamepadDispatcher::ConnectionChange& change = GamepadDispatcher::insta nce().latestConnectionChange();
140 141
141 if (!m_gamepads) 142 if (!m_gamepads)
142 m_gamepads = GamepadList::create(); 143 m_gamepads = GamepadList::create();
143 144
144 Gamepad* gamepad = m_gamepads->item(change.index); 145 Gamepad* gamepad = m_gamepads->item(change.index);
145 if (!gamepad) 146 if (!gamepad)
146 gamepad = Gamepad::create(); 147 gamepad = Gamepad::create();
147 sampleGamepad(change.index, *gamepad, change.pad); 148 sampleGamepad(change.index, *gamepad, change.pad);
148 m_gamepads->set(change.index, gamepad); 149 m_gamepads->set(change.index, gamepad);
149 150
150 m_pendingEvents.append(gamepad); 151 m_pendingEvents.append(gamepad);
151 m_dispatchOneEventRunner->runAsync(); 152 m_dispatchOneEventRunner->runAsync();
152 } 153 }
153 154
154 void NavigatorGamepad::dispatchOneEvent() 155 void NavigatorGamepad::dispatchOneEvent()
155 { 156 {
156 ASSERT(frame()); 157 Document* document = static_cast<Document*>(getExecutionContext());
157 ASSERT(frame()->domWindow()); 158 DCHECK(document->frame());
158 ASSERT(!m_pendingEvents.isEmpty()); 159 DCHECK(document->frame()->domWindow());
160 DCHECK(!m_pendingEvents.isEmpty());
159 161
160 Gamepad* gamepad = m_pendingEvents.takeFirst(); 162 Gamepad* gamepad = m_pendingEvents.takeFirst();
161 const AtomicString& eventName = gamepad->connected() ? EventTypeNames::gamep adconnected : EventTypeNames::gamepaddisconnected; 163 const AtomicString& eventName = gamepad->connected() ? EventTypeNames::gamep adconnected : EventTypeNames::gamepaddisconnected;
162 frame()->domWindow()->dispatchEvent(GamepadEvent::create(eventName, false, t rue, gamepad)); 164 document->frame()->domWindow()->dispatchEvent(GamepadEvent::create(eventName , false, true, gamepad));
163 165
164 if (!m_pendingEvents.isEmpty()) 166 if (!m_pendingEvents.isEmpty())
165 m_dispatchOneEventRunner->runAsync(); 167 m_dispatchOneEventRunner->runAsync();
166 } 168 }
167 169
168 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) 170 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame)
169 : DOMWindowProperty(frame) 171 : ContextLifecycleObserver(frame->document())
170 , PlatformEventController(frame ? frame->page() : 0) 172 , PlatformEventController(frame ? frame->page() : 0)
171 , DOMWindowLifecycleObserver(frame ? frame->localDOMWindow() : 0) 173 , DOMWindowLifecycleObserver(frame ? frame->localDOMWindow() : 0)
172 , m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorGamepad>::create(this, &NavigatorGamepad::dispatchOneEvent)) 174 , m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorGamepad>::create(this, &NavigatorGamepad::dispatchOneEvent))
173 { 175 {
174 } 176 }
175 177
176 NavigatorGamepad::~NavigatorGamepad() 178 NavigatorGamepad::~NavigatorGamepad()
177 { 179 {
178 } 180 }
179 181
180 const char* NavigatorGamepad::supplementName() 182 const char* NavigatorGamepad::supplementName()
181 { 183 {
182 return "NavigatorGamepad"; 184 return "NavigatorGamepad";
183 } 185 }
184 186
185 void NavigatorGamepad::willDestroyGlobalObjectInFrame() 187 void NavigatorGamepad::contextDestroyed()
186 { 188 {
187 stopUpdating(); 189 stopUpdating();
188 DOMWindowProperty::willDestroyGlobalObjectInFrame();
189 }
190
191 void NavigatorGamepad::willDetachGlobalObjectFromFrame()
192 {
193 stopUpdating();
194 DOMWindowProperty::willDetachGlobalObjectFromFrame();
195 } 190 }
196 191
197 void NavigatorGamepad::registerWithDispatcher() 192 void NavigatorGamepad::registerWithDispatcher()
198 { 193 {
199 GamepadDispatcher::instance().addController(this); 194 GamepadDispatcher::instance().addController(this);
200 m_dispatchOneEventRunner->resume(); 195 m_dispatchOneEventRunner->resume();
201 } 196 }
202 197
203 void NavigatorGamepad::unregisterWithDispatcher() 198 void NavigatorGamepad::unregisterWithDispatcher()
204 { 199 {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 stopUpdating(); 252 stopUpdating();
258 253
259 if (!visible || !m_hasEventListener) 254 if (!visible || !m_hasEventListener)
260 return; 255 return;
261 256
262 // Tell the page what has changed. m_gamepads contains the state before we b ecame hidden. 257 // Tell the page what has changed. m_gamepads contains the state before we b ecame hidden.
263 // We create a new snapshot and compare them. 258 // We create a new snapshot and compare them.
264 GamepadList* oldGamepads = m_gamepads.release(); 259 GamepadList* oldGamepads = m_gamepads.release();
265 gamepads(); 260 gamepads();
266 GamepadList* newGamepads = m_gamepads.get(); 261 GamepadList* newGamepads = m_gamepads.get();
267 ASSERT(newGamepads); 262 DCHECK(newGamepads);
268 263
269 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { 264 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
270 Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0; 265 Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0;
271 Gamepad* newGamepad = newGamepads->item(i); 266 Gamepad* newGamepad = newGamepads->item(i);
272 bool oldWasConnected = oldGamepad && oldGamepad->connected(); 267 bool oldWasConnected = oldGamepad && oldGamepad->connected();
273 bool newIsConnected = newGamepad && newGamepad->connected(); 268 bool newIsConnected = newGamepad && newGamepad->connected();
274 bool connectedGamepadChanged = oldWasConnected && newIsConnected && oldG amepad->id() != newGamepad->id(); 269 bool connectedGamepadChanged = oldWasConnected && newIsConnected && oldG amepad->id() != newGamepad->id();
275 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) { 270 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) {
276 oldGamepad->setConnected(false); 271 oldGamepad->setConnected(false);
277 m_pendingEvents.append(oldGamepad); 272 m_pendingEvents.append(oldGamepad);
278 } 273 }
279 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { 274 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) {
280 m_pendingEvents.append(newGamepad); 275 m_pendingEvents.append(newGamepad);
281 } 276 }
282 } 277 }
283 278
284 if (!m_pendingEvents.isEmpty()) 279 if (!m_pendingEvents.isEmpty())
285 m_dispatchOneEventRunner->runAsync(); 280 m_dispatchOneEventRunner->runAsync();
286 } 281 }
287 282
288 } // namespace blink 283 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698