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" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/extensions/api/automation_internal.h" | 16 #include "chrome/common/extensions/api/automation_internal.h" |
15 #include "chrome/common/extensions/manifest_handlers/automation.h" | 17 #include "chrome/common/extensions/manifest_handlers/automation.h" |
16 #include "content/public/browser/ax_event_notification_details.h" | 18 #include "content/public/browser/ax_event_notification_details.h" |
17 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/render_widget_host.h" | 21 #include "content/public/browser/render_widget_host.h" |
20 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 virtual void SetSelection(int32 id, int32 start, int32 end) OVERRIDE { | 115 virtual void SetSelection(int32 id, int32 start, int32 end) OVERRIDE { |
114 rwh_->AccessibilitySetTextSelection(id, start, end); | 116 rwh_->AccessibilitySetTextSelection(id, start, end); |
115 } | 117 } |
116 | 118 |
117 private: | 119 private: |
118 content::RenderWidgetHost* rwh_; | 120 content::RenderWidgetHost* rwh_; |
119 | 121 |
120 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostActionAdapter); | 122 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostActionAdapter); |
121 }; | 123 }; |
122 | 124 |
123 // TODO(aboxhall/dtseng): ensure that the initial data is sent down for the tab | |
124 // if this doesn't turn accessibility on for the first time (e.g. if a | |
125 // RendererAccessibility object existed already because a screenreader has been | |
126 // run at some point). | |
127 ExtensionFunction::ResponseAction | 125 ExtensionFunction::ResponseAction |
128 AutomationInternalEnableCurrentTabFunction::Run() { | 126 AutomationInternalEnableTabFunction::Run() { |
129 const AutomationInfo* automation_info = AutomationInfo::Get(GetExtension()); | 127 const AutomationInfo* automation_info = AutomationInfo::Get(GetExtension()); |
130 EXTENSION_FUNCTION_VALIDATE(automation_info); | 128 EXTENSION_FUNCTION_VALIDATE(automation_info); |
131 | 129 |
132 Browser* current_browser = GetCurrentBrowser(); | 130 using api::automation_internal::EnableTab::Params; |
133 TabStripModel* tab_strip = current_browser->tab_strip_model(); | 131 scoped_ptr<Params> params(Params::Create(*args_)); |
134 content::WebContents* contents = | 132 EXTENSION_FUNCTION_VALIDATE(params.get()); |
135 tab_strip->GetWebContentsAt(tab_strip->active_index()); | 133 content::WebContents* contents = NULL; |
136 if (!contents) | 134 if (params->tab_id.get()) { |
137 return RespondNow(Error("No active tab")); | 135 int tab_id = *params->tab_id; |
| 136 if (!ExtensionTabUtil::GetTabById(tab_id, |
| 137 GetProfile(), |
| 138 include_incognito(), |
| 139 NULL, /* browser out param*/ |
| 140 NULL, /* tab_strip out param */ |
| 141 &contents, |
| 142 NULL /* tab_index out param */)) { |
| 143 return RespondNow( |
| 144 Error(tabs_constants::kTabNotFoundError, base::IntToString(tab_id))); |
| 145 } |
| 146 } else { |
| 147 contents = GetCurrentBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 148 if (!contents) |
| 149 return RespondNow(Error("No active tab")); |
| 150 } |
138 content::RenderWidgetHost* rwh = | 151 content::RenderWidgetHost* rwh = |
139 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); | 152 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); |
140 if (!rwh) | 153 if (!rwh) |
141 return RespondNow(Error("Could not enable accessibility for active tab")); | 154 return RespondNow(Error("Could not enable accessibility for active tab")); |
142 | 155 |
143 if (!CanRequestAutomation(GetExtension(), automation_info, contents)) { | 156 if (!CanRequestAutomation(GetExtension(), automation_info, contents)) { |
144 return RespondNow( | 157 return RespondNow( |
145 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec())); | 158 Error(kCannotRequestAutomationOnPage, contents->GetURL().spec())); |
146 } | 159 } |
147 AutomationWebContentsObserver::CreateForWebContents(contents); | 160 AutomationWebContentsObserver::CreateForWebContents(contents); |
148 rwh->EnableTreeOnlyAccessibilityMode(); | 161 rwh->EnableTreeOnlyAccessibilityMode(); |
149 return RespondNow( | 162 return RespondNow( |
150 ArgumentList(api::automation_internal::EnableCurrentTab::Results::Create( | 163 ArgumentList(api::automation_internal::EnableTab::Results::Create( |
151 rwh->GetProcess()->GetID(), rwh->GetRoutingID()))); | 164 rwh->GetProcess()->GetID(), rwh->GetRoutingID()))); |
152 } | 165 } |
153 | 166 |
154 ExtensionFunction::ResponseAction | 167 ExtensionFunction::ResponseAction |
155 AutomationInternalPerformActionFunction::Run() { | 168 AutomationInternalPerformActionFunction::Run() { |
156 const AutomationInfo* automation_info = AutomationInfo::Get(GetExtension()); | 169 const AutomationInfo* automation_info = AutomationInfo::Get(GetExtension()); |
157 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact); | 170 EXTENSION_FUNCTION_VALIDATE(automation_info && automation_info->interact); |
158 | 171 |
159 using api::automation_internal::PerformAction::Params; | 172 using api::automation_internal::PerformAction::Params; |
160 scoped_ptr<Params> params(Params::Create(*args_)); | 173 scoped_ptr<Params> params(Params::Create(*args_)); |
161 EXTENSION_FUNCTION_VALIDATE(params.get()); | 174 EXTENSION_FUNCTION_VALIDATE(params.get()); |
162 | 175 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return RespondNow(Error("desktop permission must be requested")); | 241 return RespondNow(Error("desktop permission must be requested")); |
229 | 242 |
230 AutomationManagerAsh::GetInstance()->Enable(browser_context()); | 243 AutomationManagerAsh::GetInstance()->Enable(browser_context()); |
231 return RespondNow(NoArguments()); | 244 return RespondNow(NoArguments()); |
232 #else | 245 #else |
233 return RespondNow(Error("getDesktop is unsupported by this platform")); | 246 return RespondNow(Error("getDesktop is unsupported by this platform")); |
234 #endif // defined(OS_CHROMEOS) | 247 #endif // defined(OS_CHROMEOS) |
235 } | 248 } |
236 | 249 |
237 } // namespace extensions | 250 } // namespace extensions |
OLD | NEW |