OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/accessibility/accessibility_extension_api.h" | 5 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/accessibility/accessibility_extension_api_constants.h" | 10 #include "chrome/browser/accessibility/accessibility_extension_api_constants.h" |
11 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 11 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
12 #include "chrome/browser/api/infobars/infobar_delegate.h" | 12 #include "chrome/browser/api/infobars/infobar_delegate.h" |
13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
14 #include "chrome/browser/extensions/event_router.h" | 14 #include "chrome/browser/extensions/event_router.h" |
15 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
16 #include "chrome/browser/infobars/infobar_tab_helper.h" | 16 #include "chrome/browser/infobars/infobar_tab_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
19 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/extensions/extension_error_utils.h" | 19 #include "chrome/common/extensions/extension_error_utils.h" |
21 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
22 | 21 |
23 namespace keys = extension_accessibility_api_constants; | 22 namespace keys = extension_accessibility_api_constants; |
24 | 23 |
25 // Returns the AccessibilityControlInfo serialized into a JSON string, | 24 // Returns the AccessibilityControlInfo serialized into a JSON string, |
26 // consisting of an array of a single object of type AccessibilityObject, | 25 // consisting of an array of a single object of type AccessibilityObject, |
27 // as defined in the accessibility extension api's json schema. | 26 // as defined in the accessibility extension api's json schema. |
28 scoped_ptr<ListValue> ControlInfoToEventArguments( | 27 scoped_ptr<ListValue> ControlInfoToEventArguments( |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 SetResult(Value::CreateNullValue()); | 189 SetResult(Value::CreateNullValue()); |
191 } | 190 } |
192 return true; | 191 return true; |
193 } | 192 } |
194 | 193 |
195 bool GetAlertsForTabFunction::RunImpl() { | 194 bool GetAlertsForTabFunction::RunImpl() { |
196 int tab_id; | 195 int tab_id; |
197 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 196 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
198 | 197 |
199 TabStripModel* tab_strip = NULL; | 198 TabStripModel* tab_strip = NULL; |
200 TabContents* contents = NULL; | 199 content::WebContents* contents = NULL; |
201 int tab_index = -1; | 200 int tab_index = -1; |
202 if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(), | 201 if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(), |
203 NULL, &tab_strip, &contents, &tab_index)) { | 202 NULL, &tab_strip, &contents, &tab_index)) { |
204 error_ = ExtensionErrorUtils::FormatErrorMessage( | 203 error_ = ExtensionErrorUtils::FormatErrorMessage( |
205 extensions::tabs_constants::kTabNotFoundError, | 204 extensions::tabs_constants::kTabNotFoundError, |
206 base::IntToString(tab_id)); | 205 base::IntToString(tab_id)); |
207 return false; | 206 return false; |
208 } | 207 } |
209 | 208 |
210 ListValue* alerts_value = new ListValue; | 209 ListValue* alerts_value = new ListValue; |
211 | 210 |
212 InfoBarTabHelper* infobar_helper = | 211 InfoBarTabHelper* infobar_helper = |
213 InfoBarTabHelper::FromWebContents(contents->web_contents()); | 212 InfoBarTabHelper::FromWebContents(contents); |
214 for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); ++i) { | 213 for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); ++i) { |
215 // TODO(hashimoto): Make other kind of alerts available. crosbug.com/24281 | 214 // TODO(hashimoto): Make other kind of alerts available. crosbug.com/24281 |
216 InfoBarDelegate* infobar_delegate = infobar_helper->GetInfoBarDelegateAt(i); | 215 InfoBarDelegate* infobar_delegate = infobar_helper->GetInfoBarDelegateAt(i); |
217 ConfirmInfoBarDelegate* confirm_infobar_delegate = | 216 ConfirmInfoBarDelegate* confirm_infobar_delegate = |
218 infobar_delegate->AsConfirmInfoBarDelegate(); | 217 infobar_delegate->AsConfirmInfoBarDelegate(); |
219 if (confirm_infobar_delegate) { | 218 if (confirm_infobar_delegate) { |
220 DictionaryValue* alert_value = new DictionaryValue; | 219 DictionaryValue* alert_value = new DictionaryValue; |
221 const string16 message_text = confirm_infobar_delegate->GetMessageText(); | 220 const string16 message_text = confirm_infobar_delegate->GetMessageText(); |
222 alert_value->SetString(keys::kMessageKey, message_text); | 221 alert_value->SetString(keys::kMessageKey, message_text); |
223 alerts_value->Append(alert_value); | 222 alerts_value->Append(alert_value); |
224 } | 223 } |
225 } | 224 } |
226 | 225 |
227 SetResult(alerts_value); | 226 SetResult(alerts_value); |
228 return true; | 227 return true; |
229 } | 228 } |
OLD | NEW |