Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / accessibility / accessibility_extension_api.cc
blob67bdb8fba7b61b88f7783a5a3e4db86ce1f08098
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
3 // found in the LICENSE file.
5 #include "chrome/browser/accessibility/accessibility_extension_api.h"
7 #include "base/json/json_writer.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/extensions/api/accessibility_private.h"
16 #include "chrome/common/extensions/extension_constants.h"
17 #include "components/infobars/core/confirm_infobar_delegate.h"
18 #include "components/infobars/core/infobar.h"
19 #include "content/public/browser/browser_accessibility_state.h"
20 #include "extensions/browser/event_router.h"
21 #include "extensions/browser/extension_system.h"
22 #include "extensions/browser/lazy_background_task_queue.h"
23 #include "extensions/common/error_utils.h"
24 #include "extensions/common/manifest_handlers/background_info.h"
26 #if defined(OS_CHROMEOS)
27 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h"
28 #endif
30 namespace accessibility_private = extensions::api::accessibility_private;
32 namespace {
33 #if defined(OS_CHROMEOS)
34 // ScreenRect fields.
35 const char kLeft[] = "left";
36 const char kTop[] = "top";
37 const char kWidth[] = "width";
38 const char kHeight[] = "height";
39 #endif // defined(OS_CHROMEOS)
41 const char kErrorNotSupported[] = "This API is not supported on this platform.";
42 } // namespace
44 bool AccessibilityPrivateSetNativeAccessibilityEnabledFunction::RunSync() {
45 bool enabled;
46 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enabled));
47 if (enabled) {
48 content::BrowserAccessibilityState::GetInstance()->
49 EnableAccessibility();
50 } else {
51 content::BrowserAccessibilityState::GetInstance()->
52 DisableAccessibility();
54 return true;
57 bool AccessibilityPrivateSetFocusRingFunction::RunSync() {
58 #if defined(OS_CHROMEOS)
59 base::ListValue* rect_values = NULL;
60 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &rect_values));
62 std::vector<gfx::Rect> rects;
63 for (size_t i = 0; i < rect_values->GetSize(); ++i) {
64 base::DictionaryValue* rect_value = NULL;
65 EXTENSION_FUNCTION_VALIDATE(rect_values->GetDictionary(i, &rect_value));
66 int left, top, width, height;
67 EXTENSION_FUNCTION_VALIDATE(rect_value->GetInteger(kLeft, &left));
68 EXTENSION_FUNCTION_VALIDATE(rect_value->GetInteger(kTop, &top));
69 EXTENSION_FUNCTION_VALIDATE(rect_value->GetInteger(kWidth, &width));
70 EXTENSION_FUNCTION_VALIDATE(rect_value->GetInteger(kHeight, &height));
71 rects.push_back(gfx::Rect(left, top, width, height));
74 chromeos::AccessibilityFocusRingController::GetInstance()->SetFocusRing(
75 rects);
76 return true;
77 #endif // defined(OS_CHROMEOS)
79 error_ = kErrorNotSupported;
80 return false;