| OLD | NEW |
| 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 "components/test_runner/accessibility_controller.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "components/test_runner/web_test_proxy.h" |
| 8 #include "gin/handle.h" | 9 #include "gin/handle.h" |
| 9 #include "gin/object_template_builder.h" | 10 #include "gin/object_template_builder.h" |
| 10 #include "gin/wrappable.h" | 11 #include "gin/wrappable.h" |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" | 12 #include "third_party/WebKit/public/web/WebDocument.h" |
| 12 #include "third_party/WebKit/public/web/WebElement.h" | 13 #include "third_party/WebKit/public/web/WebElement.h" |
| 13 #include "third_party/WebKit/public/web/WebFrame.h" | 14 #include "third_party/WebKit/public/web/WebFrame.h" |
| 14 #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" |
| 15 #include "third_party/WebKit/public/web/WebSettings.h" | 17 #include "third_party/WebKit/public/web/WebSettings.h" |
| 16 #include "third_party/WebKit/public/web/WebView.h" | 18 #include "third_party/WebKit/public/web/WebView.h" |
| 17 | 19 |
| 18 namespace test_runner { | 20 namespace test_runner { |
| 19 | 21 |
| 20 class AccessibilityControllerBindings | 22 class AccessibilityControllerBindings |
| 21 : public gin::Wrappable<AccessibilityControllerBindings> { | 23 : public gin::Wrappable<AccessibilityControllerBindings> { |
| 22 public: | 24 public: |
| 23 static gin::WrapperInfo kWrapperInfo; | 25 static gin::WrapperInfo kWrapperInfo; |
| 24 | 26 |
| 25 static void Install(base::WeakPtr<AccessibilityController> controller, | 27 static void Install(base::WeakPtr<AccessibilityController> controller, |
| 26 blink::WebFrame* frame); | 28 blink::WebLocalFrame* frame); |
| 27 | 29 |
| 28 private: | 30 private: |
| 29 explicit AccessibilityControllerBindings( | 31 explicit AccessibilityControllerBindings( |
| 30 base::WeakPtr<AccessibilityController> controller); | 32 base::WeakPtr<AccessibilityController> controller); |
| 31 ~AccessibilityControllerBindings() override; | 33 ~AccessibilityControllerBindings() override; |
| 32 | 34 |
| 33 // gin::Wrappable: | 35 // gin::Wrappable: |
| 34 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 36 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 35 v8::Isolate* isolate) override; | 37 v8::Isolate* isolate) override; |
| 36 | 38 |
| 37 void LogAccessibilityEvents(); | 39 void LogAccessibilityEvents(); |
| 38 void SetNotificationListener(v8::Local<v8::Function> callback); | 40 void SetNotificationListener(v8::Local<v8::Function> callback); |
| 39 void UnsetNotificationListener(); | 41 void UnsetNotificationListener(); |
| 40 v8::Local<v8::Object> FocusedElement(); | 42 v8::Local<v8::Object> FocusedElement(); |
| 41 v8::Local<v8::Object> RootElement(); | 43 v8::Local<v8::Object> RootElement(); |
| 42 v8::Local<v8::Object> AccessibleElementById(const std::string& id); | 44 v8::Local<v8::Object> AccessibleElementById(const std::string& id); |
| 43 | 45 |
| 44 base::WeakPtr<AccessibilityController> controller_; | 46 base::WeakPtr<AccessibilityController> controller_; |
| 45 | 47 |
| 46 DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerBindings); | 48 DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerBindings); |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 gin::WrapperInfo AccessibilityControllerBindings::kWrapperInfo = { | 51 gin::WrapperInfo AccessibilityControllerBindings::kWrapperInfo = { |
| 50 gin::kEmbedderNativeGin}; | 52 gin::kEmbedderNativeGin}; |
| 51 | 53 |
| 52 // static | 54 // static |
| 53 void AccessibilityControllerBindings::Install( | 55 void AccessibilityControllerBindings::Install( |
| 54 base::WeakPtr<AccessibilityController> controller, | 56 base::WeakPtr<AccessibilityController> controller, |
| 55 blink::WebFrame* frame) { | 57 blink::WebLocalFrame* frame) { |
| 56 v8::Isolate* isolate = blink::mainThreadIsolate(); | 58 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 57 v8::HandleScope handle_scope(isolate); | 59 v8::HandleScope handle_scope(isolate); |
| 58 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 60 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 59 if (context.IsEmpty()) | 61 if (context.IsEmpty()) |
| 60 return; | 62 return; |
| 61 | 63 |
| 62 v8::Context::Scope context_scope(context); | 64 v8::Context::Scope context_scope(context); |
| 63 | 65 |
| 64 gin::Handle<AccessibilityControllerBindings> bindings = | 66 gin::Handle<AccessibilityControllerBindings> bindings = |
| 65 gin::CreateHandle(isolate, | 67 gin::CreateHandle(isolate, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 v8::Local<v8::Object> AccessibilityControllerBindings::RootElement() { | 128 v8::Local<v8::Object> AccessibilityControllerBindings::RootElement() { |
| 127 return controller_ ? controller_->RootElement() : v8::Local<v8::Object>(); | 129 return controller_ ? controller_->RootElement() : v8::Local<v8::Object>(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 v8::Local<v8::Object> AccessibilityControllerBindings::AccessibleElementById( | 132 v8::Local<v8::Object> AccessibilityControllerBindings::AccessibleElementById( |
| 131 const std::string& id) { | 133 const std::string& id) { |
| 132 return controller_ ? controller_->AccessibleElementById(id) | 134 return controller_ ? controller_->AccessibleElementById(id) |
| 133 : v8::Local<v8::Object>(); | 135 : v8::Local<v8::Object>(); |
| 134 } | 136 } |
| 135 | 137 |
| 136 AccessibilityController::AccessibilityController() | 138 AccessibilityController::AccessibilityController( |
| 139 WebTestProxyBase* web_test_proxy_base) |
| 137 : log_accessibility_events_(false), | 140 : log_accessibility_events_(false), |
| 138 weak_factory_(this) { | 141 web_test_proxy_base_(web_test_proxy_base), |
| 139 } | 142 weak_factory_(this) {} |
| 140 | 143 |
| 141 AccessibilityController::~AccessibilityController() {} | 144 AccessibilityController::~AccessibilityController() {} |
| 142 | 145 |
| 143 void AccessibilityController::Reset() { | 146 void AccessibilityController::Reset() { |
| 144 elements_.Clear(); | 147 elements_.Clear(); |
| 145 notification_callback_.Reset(); | 148 notification_callback_.Reset(); |
| 146 log_accessibility_events_ = false; | 149 log_accessibility_events_ = false; |
| 147 } | 150 } |
| 148 | 151 |
| 149 void AccessibilityController::Install(blink::WebFrame* frame) { | 152 void AccessibilityController::Install(blink::WebLocalFrame* frame) { |
| 150 frame->view()->settings()->setAccessibilityEnabled(true); | 153 frame->view()->settings()->setAccessibilityEnabled(true); |
| 151 frame->view()->settings()->setInlineTextBoxAccessibilityEnabled(true); | 154 frame->view()->settings()->setInlineTextBoxAccessibilityEnabled(true); |
| 152 | 155 |
| 153 AccessibilityControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); | 156 AccessibilityControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); |
| 154 } | 157 } |
| 155 | 158 |
| 156 bool AccessibilityController::ShouldLogAccessibilityEvents() { | 159 bool AccessibilityController::ShouldLogAccessibilityEvents() { |
| 157 return log_accessibility_events_; | 160 return log_accessibility_events_; |
| 158 } | 161 } |
| 159 | 162 |
| 160 void AccessibilityController::NotificationReceived( | 163 void AccessibilityController::NotificationReceived( |
| 161 const blink::WebAXObject& target, const std::string& notification_name) { | 164 const blink::WebAXObject& target, const std::string& notification_name) { |
| 162 v8::Isolate* isolate = blink::mainThreadIsolate(); | 165 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 163 v8::HandleScope handle_scope(isolate); | 166 v8::HandleScope handle_scope(isolate); |
| 164 | 167 |
| 165 blink::WebFrame* frame = web_view_->mainFrame(); | 168 blink::WebFrame* frame = web_view()->mainFrame(); |
| 166 if (!frame || frame->isWebRemoteFrame()) | 169 if (!frame || frame->isWebRemoteFrame()) |
| 167 return; | 170 return; |
| 168 | 171 |
| 169 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 172 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 170 if (context.IsEmpty()) | 173 if (context.IsEmpty()) |
| 171 return; | 174 return; |
| 172 | 175 |
| 173 v8::Context::Scope context_scope(context); | 176 v8::Context::Scope context_scope(context); |
| 174 | 177 |
| 175 // Call notification listeners on the element. | 178 // Call notification listeners on the element. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 192 v8::String::kNormalString, | 195 v8::String::kNormalString, |
| 193 notification_name.size()), | 196 notification_name.size()), |
| 194 }; | 197 }; |
| 195 frame->callFunctionEvenIfScriptDisabled( | 198 frame->callFunctionEvenIfScriptDisabled( |
| 196 v8::Local<v8::Function>::New(isolate, notification_callback_), | 199 v8::Local<v8::Function>::New(isolate, notification_callback_), |
| 197 context->Global(), | 200 context->Global(), |
| 198 arraysize(argv), | 201 arraysize(argv), |
| 199 argv); | 202 argv); |
| 200 } | 203 } |
| 201 | 204 |
| 202 void AccessibilityController::SetDelegate(WebTestDelegate* delegate) { | |
| 203 delegate_ = delegate; | |
| 204 } | |
| 205 | |
| 206 void AccessibilityController::SetWebView(blink::WebView* web_view) { | |
| 207 web_view_ = web_view; | |
| 208 } | |
| 209 | |
| 210 void AccessibilityController::LogAccessibilityEvents() { | 205 void AccessibilityController::LogAccessibilityEvents() { |
| 211 log_accessibility_events_ = true; | 206 log_accessibility_events_ = true; |
| 212 } | 207 } |
| 213 | 208 |
| 214 void AccessibilityController::SetNotificationListener( | 209 void AccessibilityController::SetNotificationListener( |
| 215 v8::Local<v8::Function> callback) { | 210 v8::Local<v8::Function> callback) { |
| 216 v8::Isolate* isolate = blink::mainThreadIsolate(); | 211 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 217 notification_callback_.Reset(isolate, callback); | 212 notification_callback_.Reset(isolate, callback); |
| 218 } | 213 } |
| 219 | 214 |
| 220 void AccessibilityController::UnsetNotificationListener() { | 215 void AccessibilityController::UnsetNotificationListener() { |
| 221 notification_callback_.Reset(); | 216 notification_callback_.Reset(); |
| 222 } | 217 } |
| 223 | 218 |
| 224 v8::Local<v8::Object> AccessibilityController::FocusedElement() { | 219 v8::Local<v8::Object> AccessibilityController::FocusedElement() { |
| 225 blink::WebFrame* frame = web_view_->mainFrame(); | 220 blink::WebFrame* frame = web_view()->mainFrame(); |
| 226 if (!frame) | 221 if (!frame) |
| 227 return v8::Local<v8::Object>(); | 222 return v8::Local<v8::Object>(); |
| 228 | 223 |
| 229 blink::WebAXObject focused_element = | 224 blink::WebAXObject focused_element = |
| 230 frame->document().focusedAccessibilityObject(); | 225 frame->document().focusedAccessibilityObject(); |
| 231 if (focused_element.isNull()) | 226 if (focused_element.isNull()) |
| 232 focused_element = web_view_->accessibilityObject(); | 227 focused_element = web_view()->accessibilityObject(); |
| 233 return elements_.GetOrCreate(focused_element); | 228 return elements_.GetOrCreate(focused_element); |
| 234 } | 229 } |
| 235 | 230 |
| 236 v8::Local<v8::Object> AccessibilityController::RootElement() { | 231 v8::Local<v8::Object> AccessibilityController::RootElement() { |
| 237 blink::WebAXObject root_element = web_view_->accessibilityObject(); | 232 blink::WebAXObject root_element = web_view()->accessibilityObject(); |
| 238 return elements_.GetOrCreate(root_element); | 233 return elements_.GetOrCreate(root_element); |
| 239 } | 234 } |
| 240 | 235 |
| 241 v8::Local<v8::Object> | 236 v8::Local<v8::Object> |
| 242 AccessibilityController::AccessibleElementById(const std::string& id) { | 237 AccessibilityController::AccessibleElementById(const std::string& id) { |
| 243 blink::WebAXObject root_element = web_view_->accessibilityObject(); | 238 blink::WebAXObject root_element = web_view()->accessibilityObject(); |
| 244 | 239 |
| 245 if (!root_element.updateLayoutAndCheckValidity()) | 240 if (!root_element.updateLayoutAndCheckValidity()) |
| 246 return v8::Local<v8::Object>(); | 241 return v8::Local<v8::Object>(); |
| 247 | 242 |
| 248 return FindAccessibleElementByIdRecursive( | 243 return FindAccessibleElementByIdRecursive( |
| 249 root_element, blink::WebString::fromUTF8(id.c_str())); | 244 root_element, blink::WebString::fromUTF8(id.c_str())); |
| 250 } | 245 } |
| 251 | 246 |
| 252 v8::Local<v8::Object> | 247 v8::Local<v8::Object> |
| 253 AccessibilityController::FindAccessibleElementByIdRecursive( | 248 AccessibilityController::FindAccessibleElementByIdRecursive( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 267 for (unsigned i = 0; i < childCount; i++) { | 262 for (unsigned i = 0; i < childCount; i++) { |
| 268 v8::Local<v8::Object> result = | 263 v8::Local<v8::Object> result = |
| 269 FindAccessibleElementByIdRecursive(obj.childAt(i), id); | 264 FindAccessibleElementByIdRecursive(obj.childAt(i), id); |
| 270 if (*result) | 265 if (*result) |
| 271 return result; | 266 return result; |
| 272 } | 267 } |
| 273 | 268 |
| 274 return v8::Local<v8::Object>(); | 269 return v8::Local<v8::Object>(); |
| 275 } | 270 } |
| 276 | 271 |
| 272 blink::WebView* AccessibilityController::web_view() { |
| 273 return web_test_proxy_base_->web_view(); |
| 274 } |
| 275 |
| 277 } // namespace test_runner | 276 } // namespace test_runner |
| OLD | NEW |