| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/gamepad_shared_memory_reader.h" | 5 #include "content/renderer/gamepad_shared_memory_reader.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "content/common/gamepad_user_gesture.h" | 9 #include "content/common/gamepad_user_gesture.h" |
| 10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // We failed to successfully read, presumably because the hardware | 94 // We failed to successfully read, presumably because the hardware |
| 95 // thread was taking unusually long. Don't copy the data to the output | 95 // thread was taking unusually long. Don't copy the data to the output |
| 96 // buffer, and simply leave what was there before. | 96 // buffer, and simply leave what was there before. |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 | 99 |
| 100 // New data was read successfully, copy it into the output buffer. | 100 // New data was read successfully, copy it into the output buffer. |
| 101 memcpy(&gamepads, &read_into, sizeof(gamepads)); | 101 memcpy(&gamepads, &read_into, sizeof(gamepads)); |
| 102 | 102 |
| 103 if (!ever_interacted_with_) { | 103 if (!ever_interacted_with_) { |
| 104 if (GamepadsHaveUserGesture(gamepads)) { | 104 // Clear the connected flag if the user hasn't interacted with any of the |
| 105 ever_interacted_with_ = true; | 105 // gamepads to prevent fingerprinting. The actual data is not cleared. |
| 106 } else { | 106 // WebKit will only copy out data into the JS buffers for connected |
| 107 // Clear the connected flag if the user hasn't interacted with any of the | 107 // gamepads so this is sufficient. |
| 108 // gamepads to prevent fingerprinting. The actual data is not cleared. | 108 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; i++) |
| 109 // WebKit will only copy out data into the JS buffers for connected | 109 gamepads.items[i].connected = false; |
| 110 // gamepads so this is sufficient. | |
| 111 for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; i++) | |
| 112 gamepads.items[i].connected = false; | |
| 113 } | |
| 114 } | 110 } |
| 115 } | 111 } |
| 116 | 112 |
| 117 void GamepadSharedMemoryReader::SetGamepadListener( | 113 void GamepadSharedMemoryReader::SetGamepadListener( |
| 118 blink::WebGamepadListener* listener) { | 114 blink::WebGamepadListener* listener) { |
| 119 gamepad_listener_ = listener; | 115 gamepad_listener_ = listener; |
| 120 if (gamepad_listener_) { | 116 if (gamepad_listener_) { |
| 121 // Polling has to be started rigth now and not just on the first sampling | 117 // Polling has to be started rigth now and not just on the first sampling |
| 122 // because want to get connection events from now. | 118 // because want to get connection events from now. |
| 123 StartPollingIfNecessary(); | 119 StartPollingIfNecessary(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 137 IPC_MESSAGE_HANDLER(GamepadMsg_GamepadConnected, OnGamepadConnected) | 133 IPC_MESSAGE_HANDLER(GamepadMsg_GamepadConnected, OnGamepadConnected) |
| 138 IPC_MESSAGE_HANDLER(GamepadMsg_GamepadDisconnected, OnGamepadDisconnected) | 134 IPC_MESSAGE_HANDLER(GamepadMsg_GamepadDisconnected, OnGamepadDisconnected) |
| 139 IPC_MESSAGE_UNHANDLED(handled = false) | 135 IPC_MESSAGE_UNHANDLED(handled = false) |
| 140 IPC_END_MESSAGE_MAP() | 136 IPC_END_MESSAGE_MAP() |
| 141 return handled; | 137 return handled; |
| 142 } | 138 } |
| 143 | 139 |
| 144 void GamepadSharedMemoryReader::OnGamepadConnected( | 140 void GamepadSharedMemoryReader::OnGamepadConnected( |
| 145 int index, | 141 int index, |
| 146 const blink::WebGamepad& gamepad) { | 142 const blink::WebGamepad& gamepad) { |
| 143 // The browser already checks if the user actually interacted with a device. |
| 144 ever_interacted_with_ = true; |
| 145 |
| 147 if (gamepad_listener_) | 146 if (gamepad_listener_) |
| 148 gamepad_listener_->didConnectGamepad(index, gamepad); | 147 gamepad_listener_->didConnectGamepad(index, gamepad); |
| 149 } | 148 } |
| 150 | 149 |
| 151 void GamepadSharedMemoryReader::OnGamepadDisconnected( | 150 void GamepadSharedMemoryReader::OnGamepadDisconnected( |
| 152 int index, | 151 int index, |
| 153 const blink::WebGamepad& gamepad) { | 152 const blink::WebGamepad& gamepad) { |
| 154 if (gamepad_listener_) | 153 if (gamepad_listener_) |
| 155 gamepad_listener_->didDisconnectGamepad(index, gamepad); | 154 gamepad_listener_->didDisconnectGamepad(index, gamepad); |
| 156 } | 155 } |
| 157 | 156 |
| 158 } // namespace content | 157 } // namespace content |
| OLD | NEW |