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

Side by Side Diff: content/shell/test_runner/gamepad_controller.cc

Issue 2923053002: Move MainWorldScriptContext accessor/method from WebFrame to WebLocalFrame. (Closed)
Patch Set: Rebasing... Created 3 years, 6 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/shell/test_runner/gamepad_controller.h" 5 #include "content/shell/test_runner/gamepad_controller.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "content/shell/test_runner/web_test_delegate.h" 10 #include "content/shell/test_runner/web_test_delegate.h"
11 #include "gin/arguments.h" 11 #include "gin/arguments.h"
12 #include "gin/handle.h" 12 #include "gin/handle.h"
13 #include "gin/object_template_builder.h" 13 #include "gin/object_template_builder.h"
14 #include "gin/wrappable.h" 14 #include "gin/wrappable.h"
15 #include "third_party/WebKit/public/platform/WebGamepadListener.h" 15 #include "third_party/WebKit/public/platform/WebGamepadListener.h"
16 #include "third_party/WebKit/public/web/WebFrame.h"
17 #include "third_party/WebKit/public/web/WebKit.h" 16 #include "third_party/WebKit/public/web/WebKit.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "v8/include/v8.h" 18 #include "v8/include/v8.h"
19 19
20 using blink::WebFrame;
21 using device::Gamepad; 20 using device::Gamepad;
22 using device::Gamepads; 21 using device::Gamepads;
23 22
24 namespace test_runner { 23 namespace test_runner {
25 24
26 class GamepadControllerBindings 25 class GamepadControllerBindings
27 : public gin::Wrappable<GamepadControllerBindings> { 26 : public gin::Wrappable<GamepadControllerBindings> {
28 public: 27 public:
29 static gin::WrapperInfo kWrapperInfo; 28 static gin::WrapperInfo kWrapperInfo;
30 29
31 static void Install(base::WeakPtr<GamepadController> controller, 30 static void Install(base::WeakPtr<GamepadController> controller,
32 blink::WebFrame* frame); 31 blink::WebLocalFrame* frame);
33 32
34 private: 33 private:
35 explicit GamepadControllerBindings( 34 explicit GamepadControllerBindings(
36 base::WeakPtr<GamepadController> controller); 35 base::WeakPtr<GamepadController> controller);
37 ~GamepadControllerBindings() override; 36 ~GamepadControllerBindings() override;
38 37
39 // gin::Wrappable. 38 // gin::Wrappable.
40 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( 39 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
41 v8::Isolate* isolate) override; 40 v8::Isolate* isolate) override;
42 41
(...skipping 10 matching lines...) Expand all
53 52
54 DISALLOW_COPY_AND_ASSIGN(GamepadControllerBindings); 53 DISALLOW_COPY_AND_ASSIGN(GamepadControllerBindings);
55 }; 54 };
56 55
57 gin::WrapperInfo GamepadControllerBindings::kWrapperInfo = { 56 gin::WrapperInfo GamepadControllerBindings::kWrapperInfo = {
58 gin::kEmbedderNativeGin}; 57 gin::kEmbedderNativeGin};
59 58
60 // static 59 // static
61 void GamepadControllerBindings::Install( 60 void GamepadControllerBindings::Install(
62 base::WeakPtr<GamepadController> controller, 61 base::WeakPtr<GamepadController> controller,
63 WebFrame* frame) { 62 blink::WebLocalFrame* frame) {
64 v8::Isolate* isolate = blink::MainThreadIsolate(); 63 v8::Isolate* isolate = blink::MainThreadIsolate();
65 v8::HandleScope handle_scope(isolate); 64 v8::HandleScope handle_scope(isolate);
66 v8::Local<v8::Context> context = frame->MainWorldScriptContext(); 65 v8::Local<v8::Context> context = frame->MainWorldScriptContext();
67 if (context.IsEmpty()) 66 if (context.IsEmpty())
68 return; 67 return;
69 68
70 v8::Context::Scope context_scope(context); 69 v8::Context::Scope context_scope(context);
71 70
72 gin::Handle<GamepadControllerBindings> bindings = 71 gin::Handle<GamepadControllerBindings> bindings =
73 gin::CreateHandle(isolate, new GamepadControllerBindings(controller)); 72 gin::CreateHandle(isolate, new GamepadControllerBindings(controller));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 : listener_(nullptr), weak_factory_(this) { 153 : listener_(nullptr), weak_factory_(this) {
155 Reset(); 154 Reset();
156 } 155 }
157 156
158 GamepadController::~GamepadController() {} 157 GamepadController::~GamepadController() {}
159 158
160 void GamepadController::Reset() { 159 void GamepadController::Reset() {
161 memset(&gamepads_, 0, sizeof(gamepads_)); 160 memset(&gamepads_, 0, sizeof(gamepads_));
162 } 161 }
163 162
164 void GamepadController::Install(WebFrame* frame) { 163 void GamepadController::Install(blink::WebLocalFrame* frame) {
165 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); 164 GamepadControllerBindings::Install(weak_factory_.GetWeakPtr(), frame);
166 } 165 }
167 166
168 void GamepadController::SampleGamepads(Gamepads& gamepads) { 167 void GamepadController::SampleGamepads(Gamepads& gamepads) {
169 memcpy(&gamepads, &gamepads_, sizeof(Gamepads)); 168 memcpy(&gamepads, &gamepads_, sizeof(Gamepads));
170 } 169 }
171 170
172 void GamepadController::SetListener(blink::WebGamepadListener* listener) { 171 void GamepadController::SetListener(blink::WebGamepadListener* listener) {
173 listener_ = listener; 172 listener_ = listener;
174 } 173 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 232
234 void GamepadController::SetAxisData(int index, int axis, double data) { 233 void GamepadController::SetAxisData(int index, int axis, double data) {
235 if (index < 0 || index >= static_cast<int>(Gamepads::kItemsLengthCap)) 234 if (index < 0 || index >= static_cast<int>(Gamepads::kItemsLengthCap))
236 return; 235 return;
237 if (axis < 0 || axis >= static_cast<int>(Gamepad::kAxesLengthCap)) 236 if (axis < 0 || axis >= static_cast<int>(Gamepad::kAxesLengthCap))
238 return; 237 return;
239 gamepads_.items[index].axes[axis] = data; 238 gamepads_.items[index].axes[axis] = data;
240 } 239 }
241 240
242 } // namespace test_runner 241 } // namespace test_runner
OLDNEW
« no previous file with comments | « content/shell/test_runner/gamepad_controller.h ('k') | content/shell/test_runner/gc_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698