summaryrefslogtreecommitdiffstats
path: root/extensions/browser/api/system_display/system_display_api.cc
blob: 059f8dffd99a8564f253c79b06edf80a33e119e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/browser/api/system_display/system_display_api.h"

#include <string>

#include "build/build_config.h"
#include "extensions/browser/api/system_display/display_info_provider.h"
#include "extensions/common/api/system_display.h"

#if defined(OS_CHROMEOS)
#include "base/memory/scoped_ptr.h"
#include "extensions/common/manifest_handlers/kiosk_mode_info.h"
#include "ui/gfx/screen.h"
#endif

namespace extensions {

using api::system_display::DisplayUnitInfo;

namespace SetDisplayProperties = api::system_display::SetDisplayProperties;

typedef std::vector<linked_ptr<api::system_display::DisplayUnitInfo>>
    DisplayInfo;

bool SystemDisplayGetInfoFunction::RunSync() {
  DisplayInfo all_displays_info =
      DisplayInfoProvider::Get()->GetAllDisplaysInfo();
  results_ = api::system_display::GetInfo::Results::Create(all_displays_info);
  return true;
}

bool SystemDisplaySetDisplayPropertiesFunction::RunSync() {
#if !defined(OS_CHROMEOS)
  SetError("Function available only on ChromeOS.");
  return false;
#else
  if (!KioskModeInfo::IsKioskEnabled(extension())) {
    SetError("The extension needs to be kiosk enabled to use the function.");
    return false;
  }
  std::string error;
  scoped_ptr<SetDisplayProperties::Params> params(
      SetDisplayProperties::Params::Create(*args_));
  bool success =
      DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error);
  if (!success)
    SetError(error);
  return true;
#endif
}

bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() {
#if !defined(OS_CHROMEOS)
  SetError("Function available only on ChromeOS.");
  return false;
#else
  scoped_ptr<api::system_display::EnableUnifiedDesktop::Params> params(
      api::system_display::EnableUnifiedDesktop::Params::Create(*args_));
  DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled);
  return true;
#endif
}

}  // namespace extensions