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

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

Issue 2707183003: Move //components/test_runner back into //content/shell (Closed)
Patch Set: Trim DEPS Created 3 years, 10 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 "components/test_runner/accessibility_controller.h" 5 #include "content/shell/test_runner/accessibility_controller.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "components/test_runner/web_view_test_proxy.h" 8 #include "content/shell/test_runner/web_view_test_proxy.h"
9 #include "gin/handle.h" 9 #include "gin/handle.h"
10 #include "gin/object_template_builder.h" 10 #include "gin/object_template_builder.h"
11 #include "gin/wrappable.h" 11 #include "gin/wrappable.h"
12 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebDocument.h"
13 #include "third_party/WebKit/public/web/WebElement.h" 13 #include "third_party/WebKit/public/web/WebElement.h"
14 #include "third_party/WebKit/public/web/WebFrame.h" 14 #include "third_party/WebKit/public/web/WebFrame.h"
15 #include "third_party/WebKit/public/web/WebKit.h" 15 #include "third_party/WebKit/public/web/WebKit.h"
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" 16 #include "third_party/WebKit/public/web/WebLocalFrame.h"
17 #include "third_party/WebKit/public/web/WebSettings.h" 17 #include "third_party/WebKit/public/web/WebSettings.h"
18 #include "third_party/WebKit/public/web/WebView.h" 18 #include "third_party/WebKit/public/web/WebView.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 base::WeakPtr<AccessibilityController> controller, 56 base::WeakPtr<AccessibilityController> controller,
57 blink::WebLocalFrame* frame) { 57 blink::WebLocalFrame* frame) {
58 v8::Isolate* isolate = blink::mainThreadIsolate(); 58 v8::Isolate* isolate = blink::mainThreadIsolate();
59 v8::HandleScope handle_scope(isolate); 59 v8::HandleScope handle_scope(isolate);
60 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 60 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
61 if (context.IsEmpty()) 61 if (context.IsEmpty())
62 return; 62 return;
63 63
64 v8::Context::Scope context_scope(context); 64 v8::Context::Scope context_scope(context);
65 65
66 gin::Handle<AccessibilityControllerBindings> bindings = 66 gin::Handle<AccessibilityControllerBindings> bindings = gin::CreateHandle(
67 gin::CreateHandle(isolate, 67 isolate, new AccessibilityControllerBindings(controller));
68 new AccessibilityControllerBindings(controller));
69 if (bindings.IsEmpty()) 68 if (bindings.IsEmpty())
70 return; 69 return;
71 v8::Local<v8::Object> global = context->Global(); 70 v8::Local<v8::Object> global = context->Global();
72 global->Set(gin::StringToV8(isolate, "accessibilityController"), 71 global->Set(gin::StringToV8(isolate, "accessibilityController"),
73 bindings.ToV8()); 72 bindings.ToV8());
74 } 73 }
75 74
76 AccessibilityControllerBindings::AccessibilityControllerBindings( 75 AccessibilityControllerBindings::AccessibilityControllerBindings(
77 base::WeakPtr<AccessibilityController> controller) 76 base::WeakPtr<AccessibilityController> controller)
78 : controller_(controller) { 77 : controller_(controller) {}
79 }
80 78
81 AccessibilityControllerBindings::~AccessibilityControllerBindings() { 79 AccessibilityControllerBindings::~AccessibilityControllerBindings() {}
82 }
83 80
84 gin::ObjectTemplateBuilder 81 gin::ObjectTemplateBuilder
85 AccessibilityControllerBindings::GetObjectTemplateBuilder( 82 AccessibilityControllerBindings::GetObjectTemplateBuilder(
86 v8::Isolate* isolate) { 83 v8::Isolate* isolate) {
87 return gin::Wrappable<AccessibilityControllerBindings>:: 84 return gin::Wrappable<
88 GetObjectTemplateBuilder(isolate) 85 AccessibilityControllerBindings>::GetObjectTemplateBuilder(isolate)
89 .SetMethod("logAccessibilityEvents", 86 .SetMethod("logAccessibilityEvents",
90 &AccessibilityControllerBindings::LogAccessibilityEvents) 87 &AccessibilityControllerBindings::LogAccessibilityEvents)
91 .SetMethod("setNotificationListener", 88 .SetMethod("setNotificationListener",
92 &AccessibilityControllerBindings::SetNotificationListener) 89 &AccessibilityControllerBindings::SetNotificationListener)
93 .SetMethod("unsetNotificationListener", 90 .SetMethod("unsetNotificationListener",
94 &AccessibilityControllerBindings::UnsetNotificationListener) 91 &AccessibilityControllerBindings::UnsetNotificationListener)
95 .SetProperty("focusedElement", 92 .SetProperty("focusedElement",
96 &AccessibilityControllerBindings::FocusedElement) 93 &AccessibilityControllerBindings::FocusedElement)
97 .SetProperty("rootElement", 94 .SetProperty("rootElement", &AccessibilityControllerBindings::RootElement)
98 &AccessibilityControllerBindings::RootElement)
99 .SetMethod("accessibleElementById", 95 .SetMethod("accessibleElementById",
100 &AccessibilityControllerBindings::AccessibleElementById) 96 &AccessibilityControllerBindings::AccessibleElementById)
101 // TODO(hajimehoshi): These are for backward compatibility. Remove them. 97 // TODO(hajimehoshi): These are for backward compatibility. Remove them.
102 .SetMethod("addNotificationListener", 98 .SetMethod("addNotificationListener",
103 &AccessibilityControllerBindings::SetNotificationListener) 99 &AccessibilityControllerBindings::SetNotificationListener)
104 .SetMethod("removeNotificationListener", 100 .SetMethod("removeNotificationListener",
105 &AccessibilityControllerBindings::UnsetNotificationListener); 101 &AccessibilityControllerBindings::UnsetNotificationListener);
106 } 102 }
107 103
108 void AccessibilityControllerBindings::LogAccessibilityEvents() { 104 void AccessibilityControllerBindings::LogAccessibilityEvents() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 frame->view()->settings()->setInlineTextBoxAccessibilityEnabled(true); 150 frame->view()->settings()->setInlineTextBoxAccessibilityEnabled(true);
155 151
156 AccessibilityControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); 152 AccessibilityControllerBindings::Install(weak_factory_.GetWeakPtr(), frame);
157 } 153 }
158 154
159 bool AccessibilityController::ShouldLogAccessibilityEvents() { 155 bool AccessibilityController::ShouldLogAccessibilityEvents() {
160 return log_accessibility_events_; 156 return log_accessibility_events_;
161 } 157 }
162 158
163 void AccessibilityController::NotificationReceived( 159 void AccessibilityController::NotificationReceived(
164 const blink::WebAXObject& target, const std::string& notification_name) { 160 const blink::WebAXObject& target,
161 const std::string& notification_name) {
165 v8::Isolate* isolate = blink::mainThreadIsolate(); 162 v8::Isolate* isolate = blink::mainThreadIsolate();
166 v8::HandleScope handle_scope(isolate); 163 v8::HandleScope handle_scope(isolate);
167 164
168 blink::WebFrame* frame = web_view()->mainFrame(); 165 blink::WebFrame* frame = web_view()->mainFrame();
169 if (!frame || frame->isWebRemoteFrame()) 166 if (!frame || frame->isWebRemoteFrame())
170 return; 167 return;
171 168
172 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); 169 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
173 if (context.IsEmpty()) 170 if (context.IsEmpty())
174 return; 171 return;
175 172
176 v8::Context::Scope context_scope(context); 173 v8::Context::Scope context_scope(context);
177 174
178 // Call notification listeners on the element. 175 // Call notification listeners on the element.
179 v8::Local<v8::Object> element_handle = elements_.GetOrCreate(target); 176 v8::Local<v8::Object> element_handle = elements_.GetOrCreate(target);
180 if (element_handle.IsEmpty()) 177 if (element_handle.IsEmpty())
181 return; 178 return;
182 179
183 WebAXObjectProxy* element; 180 WebAXObjectProxy* element;
184 bool result = gin::ConvertFromV8(isolate, element_handle, &element); 181 bool result = gin::ConvertFromV8(isolate, element_handle, &element);
185 DCHECK(result); 182 DCHECK(result);
186 element->NotificationReceived(frame, notification_name); 183 element->NotificationReceived(frame, notification_name);
187 184
188 if (notification_callback_.IsEmpty()) 185 if (notification_callback_.IsEmpty())
189 return; 186 return;
190 187
191 // Call global notification listeners. 188 // Call global notification listeners.
192 v8::Local<v8::Value> argv[] = { 189 v8::Local<v8::Value> argv[] = {
193 element_handle, 190 element_handle, v8::String::NewFromUtf8(isolate, notification_name.data(),
194 v8::String::NewFromUtf8(isolate, notification_name.data(), 191 v8::String::kNormalString,
195 v8::String::kNormalString, 192 notification_name.size()),
196 notification_name.size()),
197 }; 193 };
198 frame->callFunctionEvenIfScriptDisabled( 194 frame->callFunctionEvenIfScriptDisabled(
199 v8::Local<v8::Function>::New(isolate, notification_callback_), 195 v8::Local<v8::Function>::New(isolate, notification_callback_),
200 context->Global(), 196 context->Global(), arraysize(argv), argv);
201 arraysize(argv),
202 argv);
203 } 197 }
204 198
205 void AccessibilityController::LogAccessibilityEvents() { 199 void AccessibilityController::LogAccessibilityEvents() {
206 log_accessibility_events_ = true; 200 log_accessibility_events_ = true;
207 } 201 }
208 202
209 void AccessibilityController::SetNotificationListener( 203 void AccessibilityController::SetNotificationListener(
210 v8::Local<v8::Function> callback) { 204 v8::Local<v8::Function> callback) {
211 v8::Isolate* isolate = blink::mainThreadIsolate(); 205 v8::Isolate* isolate = blink::mainThreadIsolate();
212 notification_callback_.Reset(isolate, callback); 206 notification_callback_.Reset(isolate, callback);
(...skipping 13 matching lines...) Expand all
226 if (focused_element.isNull()) 220 if (focused_element.isNull())
227 focused_element = web_view()->accessibilityObject(); 221 focused_element = web_view()->accessibilityObject();
228 return elements_.GetOrCreate(focused_element); 222 return elements_.GetOrCreate(focused_element);
229 } 223 }
230 224
231 v8::Local<v8::Object> AccessibilityController::RootElement() { 225 v8::Local<v8::Object> AccessibilityController::RootElement() {
232 blink::WebAXObject root_element = web_view()->accessibilityObject(); 226 blink::WebAXObject root_element = web_view()->accessibilityObject();
233 return elements_.GetOrCreate(root_element); 227 return elements_.GetOrCreate(root_element);
234 } 228 }
235 229
236 v8::Local<v8::Object> 230 v8::Local<v8::Object> AccessibilityController::AccessibleElementById(
237 AccessibilityController::AccessibleElementById(const std::string& id) { 231 const std::string& id) {
238 blink::WebAXObject root_element = web_view()->accessibilityObject(); 232 blink::WebAXObject root_element = web_view()->accessibilityObject();
239 233
240 if (!root_element.updateLayoutAndCheckValidity()) 234 if (!root_element.updateLayoutAndCheckValidity())
241 return v8::Local<v8::Object>(); 235 return v8::Local<v8::Object>();
242 236
243 return FindAccessibleElementByIdRecursive( 237 return FindAccessibleElementByIdRecursive(
244 root_element, blink::WebString::fromUTF8(id.c_str())); 238 root_element, blink::WebString::fromUTF8(id.c_str()));
245 } 239 }
246 240
247 v8::Local<v8::Object> 241 v8::Local<v8::Object>
248 AccessibilityController::FindAccessibleElementByIdRecursive( 242 AccessibilityController::FindAccessibleElementByIdRecursive(
249 const blink::WebAXObject& obj, const blink::WebString& id) { 243 const blink::WebAXObject& obj,
244 const blink::WebString& id) {
250 if (obj.isNull() || obj.isDetached()) 245 if (obj.isNull() || obj.isDetached())
251 return v8::Local<v8::Object>(); 246 return v8::Local<v8::Object>();
252 247
253 blink::WebNode node = obj.node(); 248 blink::WebNode node = obj.node();
254 if (!node.isNull() && node.isElementNode()) { 249 if (!node.isNull() && node.isElementNode()) {
255 blink::WebElement element = node.to<blink::WebElement>(); 250 blink::WebElement element = node.to<blink::WebElement>();
256 element.getAttribute("id"); 251 element.getAttribute("id");
257 if (element.getAttribute("id") == id) 252 if (element.getAttribute("id") == id)
258 return elements_.GetOrCreate(obj); 253 return elements_.GetOrCreate(obj);
259 } 254 }
260 255
261 unsigned childCount = obj.childCount(); 256 unsigned childCount = obj.childCount();
262 for (unsigned i = 0; i < childCount; i++) { 257 for (unsigned i = 0; i < childCount; i++) {
263 v8::Local<v8::Object> result = 258 v8::Local<v8::Object> result =
264 FindAccessibleElementByIdRecursive(obj.childAt(i), id); 259 FindAccessibleElementByIdRecursive(obj.childAt(i), id);
265 if (*result) 260 if (*result)
266 return result; 261 return result;
267 } 262 }
268 263
269 return v8::Local<v8::Object>(); 264 return v8::Local<v8::Object>();
270 } 265 }
271 266
272 blink::WebView* AccessibilityController::web_view() { 267 blink::WebView* AccessibilityController::web_view() {
273 return web_view_test_proxy_base_->web_view(); 268 return web_view_test_proxy_base_->web_view();
274 } 269 }
275 270
276 } // namespace test_runner 271 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698