OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "win8/test/ui_automation_client.h" | 5 #include "win8/test/ui_automation_client.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 #include <oleauto.h> | 9 #include <oleauto.h> |
10 #include <uiautomation.h> | 10 #include <uiautomation.h> |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (FAILED(result)) { | 242 if (FAILED(result)) { |
243 LOG(ERROR) << std::hex << result; | 243 LOG(ERROR) << std::hex << result; |
244 return result; | 244 return result; |
245 } | 245 } |
246 event_handler_obj->Initialize(base::ThreadTaskRunnerHandle::Get(), | 246 event_handler_obj->Initialize(base::ThreadTaskRunnerHandle::Get(), |
247 weak_ptr_factory_.GetWeakPtr()); | 247 weak_ptr_factory_.GetWeakPtr()); |
248 base::win::ScopedComPtr<IUIAutomationEventHandler> event_handler( | 248 base::win::ScopedComPtr<IUIAutomationEventHandler> event_handler( |
249 event_handler_obj); | 249 event_handler_obj); |
250 | 250 |
251 result = automation_->AddAutomationEventHandler( | 251 result = automation_->AddAutomationEventHandler( |
252 UIA_Window_WindowOpenedEventId, | 252 UIA_Window_WindowOpenedEventId, root_element.get(), TreeScope_Descendants, |
253 root_element, | 253 cache_request.get(), event_handler.get()); |
254 TreeScope_Descendants, | |
255 cache_request, | |
256 event_handler); | |
257 | 254 |
258 if (FAILED(result)) { | 255 if (FAILED(result)) { |
259 LOG(ERROR) << std::hex << result; | 256 LOG(ERROR) << std::hex << result; |
260 return result; | 257 return result; |
261 } | 258 } |
262 | 259 |
263 event_handler_ = event_handler; | 260 event_handler_ = event_handler; |
264 return S_OK; | 261 return S_OK; |
265 } | 262 } |
266 | 263 |
267 // Removes this instance's window observer. | 264 // Removes this instance's window observer. |
268 HRESULT UIAutomationClient::Context::RemoveWindowObserver() { | 265 HRESULT UIAutomationClient::Context::RemoveWindowObserver() { |
269 DCHECK(thread_checker_.CalledOnValidThread()); | 266 DCHECK(thread_checker_.CalledOnValidThread()); |
270 DCHECK(automation_.get()); | 267 DCHECK(automation_.get()); |
271 DCHECK(event_handler_.get()); | 268 DCHECK(event_handler_.get()); |
272 | 269 |
273 HRESULT result = S_OK; | 270 HRESULT result = S_OK; |
274 base::win::ScopedComPtr<IUIAutomationElement> root_element; | 271 base::win::ScopedComPtr<IUIAutomationElement> root_element; |
275 | 272 |
276 // The opening of all windows are observed. | 273 // The opening of all windows are observed. |
277 result = automation_->GetRootElement(root_element.Receive()); | 274 result = automation_->GetRootElement(root_element.Receive()); |
278 if (FAILED(result)) { | 275 if (FAILED(result)) { |
279 LOG(ERROR) << std::hex << result; | 276 LOG(ERROR) << std::hex << result; |
280 return result; | 277 return result; |
281 } | 278 } |
282 | 279 |
283 result = automation_->RemoveAutomationEventHandler( | 280 result = automation_->RemoveAutomationEventHandler( |
284 UIA_Window_WindowOpenedEventId, | 281 UIA_Window_WindowOpenedEventId, root_element.get(), event_handler_.get()); |
285 root_element, | |
286 event_handler_); | |
287 if (FAILED(result)) { | 282 if (FAILED(result)) { |
288 LOG(ERROR) << std::hex << result; | 283 LOG(ERROR) << std::hex << result; |
289 return result; | 284 return result; |
290 } | 285 } |
291 | 286 |
292 event_handler_ = NULL; | 287 event_handler_ = NULL; |
293 return S_OK; | 288 return S_OK; |
294 } | 289 } |
295 | 290 |
296 // Handles an automation event. If the event results in the processing for which | 291 // Handles an automation event. If the event results in the processing for which |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 // Cache invokable pattern for the item. | 411 // Cache invokable pattern for the item. |
417 result = automation_->CreateCacheRequest(cache_request.Receive()); | 412 result = automation_->CreateCacheRequest(cache_request.Receive()); |
418 if (FAILED(result)) { | 413 if (FAILED(result)) { |
419 LOG(ERROR) << std::hex << result; | 414 LOG(ERROR) << std::hex << result; |
420 return result; | 415 return result; |
421 } | 416 } |
422 cache_request->AddPattern(UIA_InvokePatternId); | 417 cache_request->AddPattern(UIA_InvokePatternId); |
423 | 418 |
424 result = element->FindFirstBuildCache( | 419 result = element->FindFirstBuildCache( |
425 static_cast<TreeScope>(TreeScope_Children | TreeScope_Descendants), | 420 static_cast<TreeScope>(TreeScope_Children | TreeScope_Descendants), |
426 condition, | 421 condition.get(), cache_request.get(), target.Receive()); |
427 cache_request, | |
428 target.Receive()); | |
429 if (FAILED(result)) { | 422 if (FAILED(result)) { |
430 LOG(ERROR) << std::hex << result; | 423 LOG(ERROR) << std::hex << result; |
431 return result; | 424 return result; |
432 } | 425 } |
433 | 426 |
434 // If the item was found, invoke it. | 427 // If the item was found, invoke it. |
435 if (!target.get()) { | 428 if (!target.get()) { |
436 LOG(WARNING) << "Failed to find desired item to invoke."; | 429 LOG(WARNING) << "Failed to find desired item to invoke."; |
437 return E_FAIL; | 430 return E_FAIL; |
438 } | 431 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 return result; | 475 return result; |
483 } | 476 } |
484 | 477 |
485 result = automation_->get_ControlViewCondition( | 478 result = automation_->get_ControlViewCondition( |
486 control_view_condition.Receive()); | 479 control_view_condition.Receive()); |
487 if (FAILED(result)) { | 480 if (FAILED(result)) { |
488 LOG(ERROR) << std::hex << result; | 481 LOG(ERROR) << std::hex << result; |
489 return result; | 482 return result; |
490 } | 483 } |
491 | 484 |
492 result = automation_->CreateAndCondition( | 485 result = automation_->CreateAndCondition(invokable_condition.get(), |
493 invokable_condition, control_view_condition, condition.Receive()); | 486 control_view_condition.get(), |
| 487 condition.Receive()); |
494 if (FAILED(result)) { | 488 if (FAILED(result)) { |
495 LOG(ERROR) << std::hex << result; | 489 LOG(ERROR) << std::hex << result; |
496 return result; | 490 return result; |
497 } | 491 } |
498 | 492 |
499 // Cache item names. | 493 // Cache item names. |
500 result = automation_->CreateCacheRequest(cache_request.Receive()); | 494 result = automation_->CreateCacheRequest(cache_request.Receive()); |
501 if (FAILED(result)) { | 495 if (FAILED(result)) { |
502 LOG(ERROR) << std::hex << result; | 496 LOG(ERROR) << std::hex << result; |
503 return result; | 497 return result; |
504 } | 498 } |
505 cache_request->AddProperty(UIA_NamePropertyId); | 499 cache_request->AddProperty(UIA_NamePropertyId); |
506 | 500 |
507 result = element->FindAllBuildCache( | 501 result = element->FindAllBuildCache( |
508 static_cast<TreeScope>(TreeScope_Children | TreeScope_Descendants), | 502 static_cast<TreeScope>(TreeScope_Children | TreeScope_Descendants), |
509 condition, | 503 condition.get(), cache_request.get(), element_array.Receive()); |
510 cache_request, | |
511 element_array.Receive()); | |
512 if (FAILED(result)) { | 504 if (FAILED(result)) { |
513 LOG(ERROR) << std::hex << result; | 505 LOG(ERROR) << std::hex << result; |
514 return result; | 506 return result; |
515 } | 507 } |
516 | 508 |
517 if (!element_array.get()) { | 509 if (!element_array.get()) { |
518 LOG(ERROR) << "The window may have vanished."; | 510 LOG(ERROR) << "The window may have vanished."; |
519 return S_OK; | 511 return S_OK; |
520 } | 512 } |
521 | 513 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 context_, | 611 context_, |
620 base::ThreadTaskRunnerHandle::Get(), | 612 base::ThreadTaskRunnerHandle::Get(), |
621 base::string16(class_name), | 613 base::string16(class_name), |
622 item_name, | 614 item_name, |
623 init_callback, | 615 init_callback, |
624 result_callback)); | 616 result_callback)); |
625 } | 617 } |
626 | 618 |
627 } // namespace internal | 619 } // namespace internal |
628 } // namespace win8 | 620 } // namespace win8 |
OLD | NEW |