Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / extensions / browser / api / system_display / system_display_api.cc
blob4bfc8832bed0b43fe5d38f2db88b483d07990a76
1 // Copyright 2013 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 "extensions/browser/api/system_display/system_display_api.h"
7 #include <string>
9 #include "extensions/browser/api/system_display/display_info_provider.h"
10 #include "extensions/common/api/system_display.h"
12 #if defined(OS_CHROMEOS)
13 #include "base/memory/scoped_ptr.h"
14 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
15 #include "ui/gfx/screen.h"
16 #endif
18 namespace extensions {
20 using api::system_display::DisplayUnitInfo;
22 namespace SetDisplayProperties = api::system_display::SetDisplayProperties;
24 typedef std::vector<linked_ptr<api::system_display::DisplayUnitInfo>>
25 DisplayInfo;
27 bool SystemDisplayGetInfoFunction::RunSync() {
28 DisplayInfo all_displays_info =
29 DisplayInfoProvider::Get()->GetAllDisplaysInfo();
30 results_ = api::system_display::GetInfo::Results::Create(all_displays_info);
31 return true;
34 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() {
35 #if !defined(OS_CHROMEOS)
36 SetError("Function available only on ChromeOS.");
37 return false;
38 #else
39 if (!KioskModeInfo::IsKioskEnabled(extension())) {
40 SetError("The extension needs to be kiosk enabled to use the function.");
41 return false;
43 std::string error;
44 scoped_ptr<SetDisplayProperties::Params> params(
45 SetDisplayProperties::Params::Create(*args_));
46 bool success =
47 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error);
48 if (!success)
49 SetError(error);
50 return true;
51 #endif
54 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() {
55 #if !defined(OS_CHROMEOS)
56 SetError("Function available only on ChromeOS.");
57 return false;
58 #else
59 scoped_ptr<api::system_display::EnableUnifiedDesktop::Params> params(
60 api::system_display::EnableUnifiedDesktop::Params::Create(*args_));
61 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled);
62 return true;
63 #endif
66 } // namespace extensions