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 "chrome/browser/extensions/api/automation_internal/automation_internal_ api.h" | 5 #include "chrome/browser/extensions/api/automation_internal/automation_internal_ api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | |
9 #include "chrome/browser/extensions/api/automation_internal/automation_action_ad apter.h" | 10 #include "chrome/browser/extensions/api/automation_internal/automation_action_ad apter.h" |
10 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" | 11 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" |
12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | |
13 #include "chrome/browser/extensions/extension_tab_util.h" | |
11 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/common/extensions/api/automation_internal.h" | 16 #include "chrome/common/extensions/api/automation_internal.h" |
14 #include "chrome/common/extensions/manifest_handlers/automation.h" | 17 #include "chrome/common/extensions/manifest_handlers/automation.h" |
15 #include "content/public/browser/ax_event_notification_details.h" | 18 #include "content/public/browser/ax_event_notification_details.h" |
16 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/render_widget_host.h" | 21 #include "content/public/browser/render_widget_host.h" |
19 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "extensions/common/error_utils.h" | |
21 | 25 |
22 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
23 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h" | 27 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h" |
24 #endif | 28 #endif |
25 | 29 |
26 namespace extensions { | 30 namespace extensions { |
27 class AutomationWebContentsObserver; | 31 class AutomationWebContentsObserver; |
28 } // namespace extensions | 32 } // namespace extensions |
29 | 33 |
30 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::AutomationWebContentsObserver); | 34 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::AutomationWebContentsObserver); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 virtual void SetSelection(int32 id, int32 start, int32 end) OVERRIDE { | 92 virtual void SetSelection(int32 id, int32 start, int32 end) OVERRIDE { |
89 rwh_->AccessibilitySetTextSelection(id, start, end); | 93 rwh_->AccessibilitySetTextSelection(id, start, end); |
90 } | 94 } |
91 | 95 |
92 private: | 96 private: |
93 content::RenderWidgetHost* rwh_; | 97 content::RenderWidgetHost* rwh_; |
94 | 98 |
95 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostActionAdapter); | 99 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostActionAdapter); |
96 }; | 100 }; |
97 | 101 |
98 // TODO(aboxhall/dtseng): ensure that the initial data is sent down for the tab | |
99 // if this doesn't turn accessibility on for the first time (e.g. if a | |
100 // RendererAccessibility object existed already because a screenreader has been | |
101 // run at some point). | |
102 ExtensionFunction::ResponseAction | 102 ExtensionFunction::ResponseAction |
103 AutomationInternalEnableCurrentTabFunction::Run() { | 103 AutomationInternalEnableTabFunction::Run() { |
104 Browser* current_browser = GetCurrentBrowser(); | 104 using api::automation_internal::EnableTab::Params; |
105 TabStripModel* tab_strip = current_browser->tab_strip_model(); | 105 scoped_ptr<Params> params(Params::Create(*args_)); |
106 content::WebContents* contents = | 106 EXTENSION_FUNCTION_VALIDATE(params.get()); |
107 tab_strip->GetWebContentsAt(tab_strip->active_index()); | 107 content::WebContents* contents = NULL; |
108 if (!contents) | 108 if (params->tab_id.get()) { |
109 return RespondNow(Error("No active tab")); | 109 TabStripModel* tab_strip = NULL; |
110 int tab_index = -1; | |
111 int tab_id = *params->tab_id; | |
112 if (!ExtensionTabUtil::GetTabById(tab_id, | |
113 GetProfile(), | |
114 include_incognito(), | |
115 NULL, | |
David Tseng
2014/05/29 22:41:31
What is this (in-line comments would help out)?
aboxhall
2014/05/30 15:37:11
Added inline comments.
| |
116 &tab_strip, | |
117 &contents, | |
118 &tab_index)) { | |
119 return RespondNow(Error( | |
120 ErrorUtils::FormatErrorMessage(tabs_constants::kTabNotFoundError, | |
121 base::IntToString(tab_id)))); | |
122 } | |
123 } else { | |
124 contents = GetCurrentBrowser()->tab_strip_model()->GetActiveWebContents(); | |
125 if (!contents) | |
126 return RespondNow(Error("No active tab")); | |
127 } | |
110 content::RenderWidgetHost* rwh = | 128 content::RenderWidgetHost* rwh = |
111 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); | 129 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); |
112 if (!rwh) | 130 if (!rwh) |
113 return RespondNow(Error("Could not enable accessibility for active tab")); | 131 return RespondNow(Error("Could not enable accessibility for active tab")); |
114 AutomationWebContentsObserver::CreateForWebContents(contents); | 132 AutomationWebContentsObserver::CreateForWebContents(contents); |
115 rwh->EnableTreeOnlyAccessibilityMode(); | 133 rwh->EnableTreeOnlyAccessibilityMode(); |
116 return RespondNow( | 134 return RespondNow( |
117 ArgumentList(api::automation_internal::EnableCurrentTab::Results::Create( | 135 ArgumentList(api::automation_internal::EnableTab::Results::Create( |
118 rwh->GetProcess()->GetID(), rwh->GetRoutingID()))); | 136 rwh->GetProcess()->GetID(), rwh->GetRoutingID()))); |
119 } | 137 } |
David Tseng
2014/05/29 22:41:31
While we're here and I don't forget to ask, are yo
aboxhall
2014/05/30 15:37:11
Yes, sorry - that is next on my list :)
| |
120 | 138 |
121 ExtensionFunction::ResponseAction | 139 ExtensionFunction::ResponseAction |
122 AutomationInternalPerformActionFunction::Run() { | 140 AutomationInternalPerformActionFunction::Run() { |
123 const AutomationInfo* automation_info = AutomationInfo::Get(GetExtension()); | 141 const AutomationInfo* automation_info = AutomationInfo::Get(GetExtension()); |
124 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact); | 142 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact); |
125 | 143 |
126 using api::automation_internal::PerformAction::Params; | 144 using api::automation_internal::PerformAction::Params; |
127 scoped_ptr<Params> params(Params::Create(*args_)); | 145 scoped_ptr<Params> params(Params::Create(*args_)); |
128 EXTENSION_FUNCTION_VALIDATE(params.get()); | 146 EXTENSION_FUNCTION_VALIDATE(params.get()); |
129 | 147 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 return RespondNow(Error("desktop permission must be requested")); | 205 return RespondNow(Error("desktop permission must be requested")); |
188 | 206 |
189 AutomationManagerAsh::GetInstance()->Enable(browser_context()); | 207 AutomationManagerAsh::GetInstance()->Enable(browser_context()); |
190 return RespondNow(NoArguments()); | 208 return RespondNow(NoArguments()); |
191 #else | 209 #else |
192 return RespondNow(Error("getDesktop is unsupported by this platform")); | 210 return RespondNow(Error("getDesktop is unsupported by this platform")); |
193 #endif // defined(OS_CHROMEOS) | 211 #endif // defined(OS_CHROMEOS) |
194 } | 212 } |
195 | 213 |
196 } // namespace extensions | 214 } // namespace extensions |
OLD | NEW |