| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/win/settings_app_monitor.h" | 5 #include "chrome/browser/win/settings_app_monitor.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 <stdint.h> | 10 #include <stdint.h> |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 // Helper function to get the parent element with class name "Flyout". Used to | 216 // Helper function to get the parent element with class name "Flyout". Used to |
| 217 // determine the |element|'s type. | 217 // determine the |element|'s type. |
| 218 base::string16 GetFlyoutParentAutomationId(IUIAutomation* automation, | 218 base::string16 GetFlyoutParentAutomationId(IUIAutomation* automation, |
| 219 IUIAutomationElement* element) { | 219 IUIAutomationElement* element) { |
| 220 // Create a condition that will include only elements with the right class | 220 // Create a condition that will include only elements with the right class |
| 221 // name in the tree view. | 221 // name in the tree view. |
| 222 base::win::ScopedVariant class_name(L"Flyout"); | 222 base::win::ScopedVariant class_name(L"Flyout"); |
| 223 base::win::ScopedComPtr<IUIAutomationCondition> condition; | 223 base::win::ScopedComPtr<IUIAutomationCondition> condition; |
| 224 HRESULT result = automation->CreatePropertyCondition( | 224 HRESULT result = automation->CreatePropertyCondition( |
| 225 UIA_ClassNamePropertyId, class_name, condition.Receive()); | 225 UIA_ClassNamePropertyId, class_name, condition.GetAddressOf()); |
| 226 if (FAILED(result)) | 226 if (FAILED(result)) |
| 227 return base::string16(); | 227 return base::string16(); |
| 228 | 228 |
| 229 base::win::ScopedComPtr<IUIAutomationTreeWalker> tree_walker; | 229 base::win::ScopedComPtr<IUIAutomationTreeWalker> tree_walker; |
| 230 result = automation->CreateTreeWalker(condition.Get(), tree_walker.Receive()); | 230 result = |
| 231 automation->CreateTreeWalker(condition.Get(), tree_walker.GetAddressOf()); |
| 231 if (FAILED(result)) | 232 if (FAILED(result)) |
| 232 return base::string16(); | 233 return base::string16(); |
| 233 | 234 |
| 234 base::win::ScopedComPtr<IUIAutomationCacheRequest> cache_request; | 235 base::win::ScopedComPtr<IUIAutomationCacheRequest> cache_request; |
| 235 result = automation->CreateCacheRequest(cache_request.Receive()); | 236 result = automation->CreateCacheRequest(cache_request.GetAddressOf()); |
| 236 if (FAILED(result)) | 237 if (FAILED(result)) |
| 237 return base::string16(); | 238 return base::string16(); |
| 238 ConfigureCacheRequest(cache_request.Get()); | 239 ConfigureCacheRequest(cache_request.Get()); |
| 239 | 240 |
| 240 // From MSDN, NormalizeElementBuildCache() "Retrieves the ancestor element | 241 // From MSDN, NormalizeElementBuildCache() "Retrieves the ancestor element |
| 241 // nearest to the specified Microsoft UI Automation element in the tree view". | 242 // nearest to the specified Microsoft UI Automation element in the tree view". |
| 242 IUIAutomationElement* flyout_element = nullptr; | 243 IUIAutomationElement* flyout_element = nullptr; |
| 243 result = tree_walker->NormalizeElementBuildCache(element, cache_request.Get(), | 244 result = tree_walker->NormalizeElementBuildCache(element, cache_request.Get(), |
| 244 &flyout_element); | 245 &flyout_element); |
| 245 if (FAILED(result) || !flyout_element) | 246 if (FAILED(result) || !flyout_element) |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 | 717 |
| 717 base::win::ScopedComPtr<IUnknown> | 718 base::win::ScopedComPtr<IUnknown> |
| 718 SettingsAppMonitor::Context::GetEventHandler() { | 719 SettingsAppMonitor::Context::GetEventHandler() { |
| 719 DCHECK(task_runner_->BelongsToCurrentThread()); | 720 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 720 if (!event_handler_) { | 721 if (!event_handler_) { |
| 721 ATL::CComObject<EventHandler>* obj = nullptr; | 722 ATL::CComObject<EventHandler>* obj = nullptr; |
| 722 HRESULT result = ATL::CComObject<EventHandler>::CreateInstance(&obj); | 723 HRESULT result = ATL::CComObject<EventHandler>::CreateInstance(&obj); |
| 723 if (SUCCEEDED(result)) { | 724 if (SUCCEEDED(result)) { |
| 724 obj->Initialize(task_runner_, weak_ptr_factory_.GetWeakPtr(), | 725 obj->Initialize(task_runner_, weak_ptr_factory_.GetWeakPtr(), |
| 725 automation_); | 726 automation_); |
| 726 obj->QueryInterface(event_handler_.Receive()); | 727 obj->QueryInterface(event_handler_.GetAddressOf()); |
| 727 } | 728 } |
| 728 } | 729 } |
| 729 return event_handler_; | 730 return event_handler_; |
| 730 } | 731 } |
| 731 | 732 |
| 732 base::win::ScopedComPtr<IUIAutomationEventHandler> | 733 base::win::ScopedComPtr<IUIAutomationEventHandler> |
| 733 SettingsAppMonitor::Context::GetAutomationEventHandler() { | 734 SettingsAppMonitor::Context::GetAutomationEventHandler() { |
| 734 DCHECK(task_runner_->BelongsToCurrentThread()); | 735 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 735 base::win::ScopedComPtr<IUIAutomationEventHandler> handler; | 736 base::win::ScopedComPtr<IUIAutomationEventHandler> handler; |
| 736 handler.QueryFrom(GetEventHandler().Get()); | 737 handler.QueryFrom(GetEventHandler().Get()); |
| 737 return handler; | 738 return handler; |
| 738 } | 739 } |
| 739 | 740 |
| 740 base::win::ScopedComPtr<IUIAutomationFocusChangedEventHandler> | 741 base::win::ScopedComPtr<IUIAutomationFocusChangedEventHandler> |
| 741 SettingsAppMonitor::Context::GetFocusChangedEventHandler() { | 742 SettingsAppMonitor::Context::GetFocusChangedEventHandler() { |
| 742 DCHECK(task_runner_->BelongsToCurrentThread()); | 743 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 743 base::win::ScopedComPtr<IUIAutomationFocusChangedEventHandler> handler; | 744 base::win::ScopedComPtr<IUIAutomationFocusChangedEventHandler> handler; |
| 744 handler.QueryFrom(GetEventHandler().Get()); | 745 handler.QueryFrom(GetEventHandler().Get()); |
| 745 return handler; | 746 return handler; |
| 746 } | 747 } |
| 747 | 748 |
| 748 HRESULT SettingsAppMonitor::Context::InstallObservers() { | 749 HRESULT SettingsAppMonitor::Context::InstallObservers() { |
| 749 DCHECK(task_runner_->BelongsToCurrentThread()); | 750 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 750 DCHECK(automation_); | 751 DCHECK(automation_); |
| 751 | 752 |
| 752 // Create a cache request so that elements received by way of events contain | 753 // Create a cache request so that elements received by way of events contain |
| 753 // all data needed for procesing. | 754 // all data needed for procesing. |
| 754 base::win::ScopedComPtr<IUIAutomationCacheRequest> cache_request; | 755 base::win::ScopedComPtr<IUIAutomationCacheRequest> cache_request; |
| 755 HRESULT result = automation_->CreateCacheRequest(cache_request.Receive()); | 756 HRESULT result = |
| 757 automation_->CreateCacheRequest(cache_request.GetAddressOf()); |
| 756 if (FAILED(result)) | 758 if (FAILED(result)) |
| 757 return result; | 759 return result; |
| 758 ConfigureCacheRequest(cache_request.Get()); | 760 ConfigureCacheRequest(cache_request.Get()); |
| 759 | 761 |
| 760 // Observe changes in focus. | 762 // Observe changes in focus. |
| 761 result = automation_->AddFocusChangedEventHandler( | 763 result = automation_->AddFocusChangedEventHandler( |
| 762 cache_request.Get(), GetFocusChangedEventHandler().Get()); | 764 cache_request.Get(), GetFocusChangedEventHandler().Get()); |
| 763 if (FAILED(result)) | 765 if (FAILED(result)) |
| 764 return result; | 766 return result; |
| 765 | 767 |
| 766 // Observe invocations. | 768 // Observe invocations. |
| 767 base::win::ScopedComPtr<IUIAutomationElement> desktop; | 769 base::win::ScopedComPtr<IUIAutomationElement> desktop; |
| 768 result = automation_->GetRootElement(desktop.Receive()); | 770 result = automation_->GetRootElement(desktop.GetAddressOf()); |
| 769 if (desktop) { | 771 if (desktop) { |
| 770 result = automation_->AddAutomationEventHandler( | 772 result = automation_->AddAutomationEventHandler( |
| 771 UIA_Invoke_InvokedEventId, desktop.Get(), TreeScope_Subtree, | 773 UIA_Invoke_InvokedEventId, desktop.Get(), TreeScope_Subtree, |
| 772 cache_request.Get(), GetAutomationEventHandler().Get()); | 774 cache_request.Get(), GetAutomationEventHandler().Get()); |
| 773 } | 775 } |
| 774 | 776 |
| 775 return result; | 777 return result; |
| 776 } | 778 } |
| 777 | 779 |
| 778 | 780 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 delegate_->OnPromoFocused(); | 835 delegate_->OnPromoFocused(); |
| 834 } | 836 } |
| 835 | 837 |
| 836 void SettingsAppMonitor::OnPromoChoiceMade(bool accept_promo) { | 838 void SettingsAppMonitor::OnPromoChoiceMade(bool accept_promo) { |
| 837 DCHECK(thread_checker_.CalledOnValidThread()); | 839 DCHECK(thread_checker_.CalledOnValidThread()); |
| 838 delegate_->OnPromoChoiceMade(accept_promo); | 840 delegate_->OnPromoChoiceMade(accept_promo); |
| 839 } | 841 } |
| 840 | 842 |
| 841 } // namespace win | 843 } // namespace win |
| 842 } // namespace shell_integration | 844 } // namespace shell_integration |
| OLD | NEW |