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

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

Powered by Google App Engine
This is Rietveld 408576698