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

Side by Side Diff: content/shell/renderer/test_runner/accessibility_controller.cc

Issue 1113783002: Use Local instead of Handle in src/content/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/renderer/test_runner/accessibility_controller.h" 5 #include "content/shell/renderer/test_runner/accessibility_controller.h"
6 6
7 #include "gin/handle.h" 7 #include "gin/handle.h"
8 #include "gin/object_template_builder.h" 8 #include "gin/object_template_builder.h"
9 #include "gin/wrappable.h" 9 #include "gin/wrappable.h"
10 #include "third_party/WebKit/public/web/WebElement.h" 10 #include "third_party/WebKit/public/web/WebElement.h"
(...skipping 15 matching lines...) Expand all
26 private: 26 private:
27 explicit AccessibilityControllerBindings( 27 explicit AccessibilityControllerBindings(
28 base::WeakPtr<AccessibilityController> controller); 28 base::WeakPtr<AccessibilityController> controller);
29 ~AccessibilityControllerBindings() override; 29 ~AccessibilityControllerBindings() override;
30 30
31 // gin::Wrappable: 31 // gin::Wrappable:
32 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( 32 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
33 v8::Isolate* isolate) override; 33 v8::Isolate* isolate) override;
34 34
35 void LogAccessibilityEvents(); 35 void LogAccessibilityEvents();
36 void SetNotificationListener(v8::Handle<v8::Function> callback); 36 void SetNotificationListener(v8::Local<v8::Function> callback);
37 void UnsetNotificationListener(); 37 void UnsetNotificationListener();
38 v8::Handle<v8::Object> FocusedElement(); 38 v8::Local<v8::Object> FocusedElement();
39 v8::Handle<v8::Object> RootElement(); 39 v8::Local<v8::Object> RootElement();
40 v8::Handle<v8::Object> AccessibleElementById(const std::string& id); 40 v8::Local<v8::Object> AccessibleElementById(const std::string& id);
41 41
42 base::WeakPtr<AccessibilityController> controller_; 42 base::WeakPtr<AccessibilityController> controller_;
43 43
44 DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerBindings); 44 DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerBindings);
45 }; 45 };
46 46
47 gin::WrapperInfo AccessibilityControllerBindings::kWrapperInfo = { 47 gin::WrapperInfo AccessibilityControllerBindings::kWrapperInfo = {
48 gin::kEmbedderNativeGin}; 48 gin::kEmbedderNativeGin};
49 49
50 // static 50 // static
51 void AccessibilityControllerBindings::Install( 51 void AccessibilityControllerBindings::Install(
52 base::WeakPtr<AccessibilityController> controller, 52 base::WeakPtr<AccessibilityController> controller,
53 blink::WebFrame* frame) { 53 blink::WebFrame* frame) {
54 v8::Isolate* isolate = blink::mainThreadIsolate(); 54 v8::Isolate* isolate = blink::mainThreadIsolate();
55 v8::HandleScope handle_scope(isolate); 55 v8::HandleScope handle_scope(isolate);
56 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 56 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
57 if (context.IsEmpty()) 57 if (context.IsEmpty())
58 return; 58 return;
59 59
60 v8::Context::Scope context_scope(context); 60 v8::Context::Scope context_scope(context);
61 61
62 gin::Handle<AccessibilityControllerBindings> bindings = 62 gin::Handle<AccessibilityControllerBindings> bindings =
63 gin::CreateHandle(isolate, 63 gin::CreateHandle(isolate,
64 new AccessibilityControllerBindings(controller)); 64 new AccessibilityControllerBindings(controller));
65 if (bindings.IsEmpty()) 65 if (bindings.IsEmpty())
66 return; 66 return;
67 v8::Handle<v8::Object> global = context->Global(); 67 v8::Local<v8::Object> global = context->Global();
68 global->Set(gin::StringToV8(isolate, "accessibilityController"), 68 global->Set(gin::StringToV8(isolate, "accessibilityController"),
69 bindings.ToV8()); 69 bindings.ToV8());
70 } 70 }
71 71
72 AccessibilityControllerBindings::AccessibilityControllerBindings( 72 AccessibilityControllerBindings::AccessibilityControllerBindings(
73 base::WeakPtr<AccessibilityController> controller) 73 base::WeakPtr<AccessibilityController> controller)
74 : controller_(controller) { 74 : controller_(controller) {
75 } 75 }
76 76
77 AccessibilityControllerBindings::~AccessibilityControllerBindings() { 77 AccessibilityControllerBindings::~AccessibilityControllerBindings() {
(...skipping 22 matching lines...) Expand all
100 .SetMethod("removeNotificationListener", 100 .SetMethod("removeNotificationListener",
101 &AccessibilityControllerBindings::UnsetNotificationListener); 101 &AccessibilityControllerBindings::UnsetNotificationListener);
102 } 102 }
103 103
104 void AccessibilityControllerBindings::LogAccessibilityEvents() { 104 void AccessibilityControllerBindings::LogAccessibilityEvents() {
105 if (controller_) 105 if (controller_)
106 controller_->LogAccessibilityEvents(); 106 controller_->LogAccessibilityEvents();
107 } 107 }
108 108
109 void AccessibilityControllerBindings::SetNotificationListener( 109 void AccessibilityControllerBindings::SetNotificationListener(
110 v8::Handle<v8::Function> callback) { 110 v8::Local<v8::Function> callback) {
111 if (controller_) 111 if (controller_)
112 controller_->SetNotificationListener(callback); 112 controller_->SetNotificationListener(callback);
113 } 113 }
114 114
115 void AccessibilityControllerBindings::UnsetNotificationListener() { 115 void AccessibilityControllerBindings::UnsetNotificationListener() {
116 if (controller_) 116 if (controller_)
117 controller_->UnsetNotificationListener(); 117 controller_->UnsetNotificationListener();
118 } 118 }
119 119
120 v8::Handle<v8::Object> AccessibilityControllerBindings::FocusedElement() { 120 v8::Local<v8::Object> AccessibilityControllerBindings::FocusedElement() {
121 return controller_ ? controller_->FocusedElement() : v8::Handle<v8::Object>(); 121 return controller_ ? controller_->FocusedElement() : v8::Local<v8::Object>();
122 } 122 }
123 123
124 v8::Handle<v8::Object> AccessibilityControllerBindings::RootElement() { 124 v8::Local<v8::Object> AccessibilityControllerBindings::RootElement() {
125 return controller_ ? controller_->RootElement() : v8::Handle<v8::Object>(); 125 return controller_ ? controller_->RootElement() : v8::Local<v8::Object>();
126 } 126 }
127 127
128 v8::Handle<v8::Object> AccessibilityControllerBindings::AccessibleElementById( 128 v8::Local<v8::Object> AccessibilityControllerBindings::AccessibleElementById(
129 const std::string& id) { 129 const std::string& id) {
130 return controller_ ? controller_->AccessibleElementById(id) 130 return controller_ ? controller_->AccessibleElementById(id)
131 : v8::Handle<v8::Object>(); 131 : v8::Local<v8::Object>();
132 } 132 }
133 133
134 AccessibilityController::AccessibilityController() 134 AccessibilityController::AccessibilityController()
135 : log_accessibility_events_(false), 135 : log_accessibility_events_(false),
136 weak_factory_(this) { 136 weak_factory_(this) {
137 } 137 }
138 138
139 AccessibilityController::~AccessibilityController() {} 139 AccessibilityController::~AccessibilityController() {}
140 140
141 void AccessibilityController::Reset() { 141 void AccessibilityController::Reset() {
(...skipping 22 matching lines...) Expand all
164 164
165 void AccessibilityController::NotificationReceived( 165 void AccessibilityController::NotificationReceived(
166 const blink::WebAXObject& target, const std::string& notification_name) { 166 const blink::WebAXObject& target, const std::string& notification_name) {
167 v8::Isolate* isolate = blink::mainThreadIsolate(); 167 v8::Isolate* isolate = blink::mainThreadIsolate();
168 v8::HandleScope handle_scope(isolate); 168 v8::HandleScope handle_scope(isolate);
169 169
170 blink::WebFrame* frame = web_view_->mainFrame(); 170 blink::WebFrame* frame = web_view_->mainFrame();
171 if (!frame || frame->isWebRemoteFrame()) 171 if (!frame || frame->isWebRemoteFrame())
172 return; 172 return;
173 173
174 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 174 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
175 if (context.IsEmpty()) 175 if (context.IsEmpty())
176 return; 176 return;
177 177
178 v8::Context::Scope context_scope(context); 178 v8::Context::Scope context_scope(context);
179 179
180 // Call notification listeners on the element. 180 // Call notification listeners on the element.
181 v8::Handle<v8::Object> element_handle = elements_.GetOrCreate(target); 181 v8::Local<v8::Object> element_handle = elements_.GetOrCreate(target);
182 if (element_handle.IsEmpty()) 182 if (element_handle.IsEmpty())
183 return; 183 return;
184 184
185 WebAXObjectProxy* element; 185 WebAXObjectProxy* element;
186 bool result = gin::ConvertFromV8(isolate, element_handle, &element); 186 bool result = gin::ConvertFromV8(isolate, element_handle, &element);
187 DCHECK(result); 187 DCHECK(result);
188 element->NotificationReceived(frame, notification_name); 188 element->NotificationReceived(frame, notification_name);
189 189
190 if (notification_callback_.IsEmpty()) 190 if (notification_callback_.IsEmpty())
191 return; 191 return;
192 192
193 // Call global notification listeners. 193 // Call global notification listeners.
194 v8::Handle<v8::Value> argv[] = { 194 v8::Local<v8::Value> argv[] = {
195 element_handle, 195 element_handle,
196 v8::String::NewFromUtf8(isolate, notification_name.data(), 196 v8::String::NewFromUtf8(isolate, notification_name.data(),
197 v8::String::kNormalString, 197 v8::String::kNormalString,
198 notification_name.size()), 198 notification_name.size()),
199 }; 199 };
200 frame->callFunctionEvenIfScriptDisabled( 200 frame->callFunctionEvenIfScriptDisabled(
201 v8::Local<v8::Function>::New(isolate, notification_callback_), 201 v8::Local<v8::Function>::New(isolate, notification_callback_),
202 context->Global(), 202 context->Global(),
203 arraysize(argv), 203 arraysize(argv),
204 argv); 204 argv);
205 } 205 }
206 206
207 void AccessibilityController::SetDelegate(WebTestDelegate* delegate) { 207 void AccessibilityController::SetDelegate(WebTestDelegate* delegate) {
208 delegate_ = delegate; 208 delegate_ = delegate;
209 } 209 }
210 210
211 void AccessibilityController::SetWebView(blink::WebView* web_view) { 211 void AccessibilityController::SetWebView(blink::WebView* web_view) {
212 web_view_ = web_view; 212 web_view_ = web_view;
213 } 213 }
214 214
215 void AccessibilityController::LogAccessibilityEvents() { 215 void AccessibilityController::LogAccessibilityEvents() {
216 log_accessibility_events_ = true; 216 log_accessibility_events_ = true;
217 } 217 }
218 218
219 void AccessibilityController::SetNotificationListener( 219 void AccessibilityController::SetNotificationListener(
220 v8::Handle<v8::Function> callback) { 220 v8::Local<v8::Function> callback) {
221 v8::Isolate* isolate = blink::mainThreadIsolate(); 221 v8::Isolate* isolate = blink::mainThreadIsolate();
222 notification_callback_.Reset(isolate, callback); 222 notification_callback_.Reset(isolate, callback);
223 } 223 }
224 224
225 void AccessibilityController::UnsetNotificationListener() { 225 void AccessibilityController::UnsetNotificationListener() {
226 notification_callback_.Reset(); 226 notification_callback_.Reset();
227 } 227 }
228 228
229 v8::Handle<v8::Object> AccessibilityController::FocusedElement() { 229 v8::Local<v8::Object> AccessibilityController::FocusedElement() {
230 if (focused_element_.isNull()) 230 if (focused_element_.isNull())
231 focused_element_ = web_view_->accessibilityObject(); 231 focused_element_ = web_view_->accessibilityObject();
232 return elements_.GetOrCreate(focused_element_); 232 return elements_.GetOrCreate(focused_element_);
233 } 233 }
234 234
235 v8::Handle<v8::Object> AccessibilityController::RootElement() { 235 v8::Local<v8::Object> AccessibilityController::RootElement() {
236 if (root_element_.isNull()) 236 if (root_element_.isNull())
237 root_element_ = web_view_->accessibilityObject(); 237 root_element_ = web_view_->accessibilityObject();
238 return elements_.GetOrCreate(root_element_); 238 return elements_.GetOrCreate(root_element_);
239 } 239 }
240 240
241 v8::Handle<v8::Object> 241 v8::Local<v8::Object>
242 AccessibilityController::AccessibleElementById(const std::string& id) { 242 AccessibilityController::AccessibleElementById(const std::string& id) {
243 if (root_element_.isNull()) 243 if (root_element_.isNull())
244 root_element_ = web_view_->accessibilityObject(); 244 root_element_ = web_view_->accessibilityObject();
245 245
246 if (!root_element_.updateLayoutAndCheckValidity()) 246 if (!root_element_.updateLayoutAndCheckValidity())
247 return v8::Handle<v8::Object>(); 247 return v8::Local<v8::Object>();
248 248
249 return FindAccessibleElementByIdRecursive( 249 return FindAccessibleElementByIdRecursive(
250 root_element_, blink::WebString::fromUTF8(id.c_str())); 250 root_element_, blink::WebString::fromUTF8(id.c_str()));
251 } 251 }
252 252
253 v8::Handle<v8::Object> 253 v8::Local<v8::Object>
254 AccessibilityController::FindAccessibleElementByIdRecursive( 254 AccessibilityController::FindAccessibleElementByIdRecursive(
255 const blink::WebAXObject& obj, const blink::WebString& id) { 255 const blink::WebAXObject& obj, const blink::WebString& id) {
256 if (obj.isNull() || obj.isDetached()) 256 if (obj.isNull() || obj.isDetached())
257 return v8::Handle<v8::Object>(); 257 return v8::Local<v8::Object>();
258 258
259 blink::WebNode node = obj.node(); 259 blink::WebNode node = obj.node();
260 if (!node.isNull() && node.isElementNode()) { 260 if (!node.isNull() && node.isElementNode()) {
261 blink::WebElement element = node.to<blink::WebElement>(); 261 blink::WebElement element = node.to<blink::WebElement>();
262 element.getAttribute("id"); 262 element.getAttribute("id");
263 if (element.getAttribute("id") == id) 263 if (element.getAttribute("id") == id)
264 return elements_.GetOrCreate(obj); 264 return elements_.GetOrCreate(obj);
265 } 265 }
266 266
267 unsigned childCount = obj.childCount(); 267 unsigned childCount = obj.childCount();
268 for (unsigned i = 0; i < childCount; i++) { 268 for (unsigned i = 0; i < childCount; i++) {
269 v8::Handle<v8::Object> result = 269 v8::Local<v8::Object> result =
270 FindAccessibleElementByIdRecursive(obj.childAt(i), id); 270 FindAccessibleElementByIdRecursive(obj.childAt(i), id);
271 if (*result) 271 if (*result)
272 return result; 272 return result;
273 } 273 }
274 274
275 return v8::Handle<v8::Object>(); 275 return v8::Local<v8::Object>();
276 } 276 }
277 277
278 } // namespace content 278 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/accessibility_controller.h ('k') | content/shell/renderer/test_runner/event_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698