summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/system_display/system_display_api.cc
blob: 36dd2f26e73fc2a75e368ff3af643be94b34c923 (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
// 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 "chrome/browser/extensions/api/system_display/system_display_api.h"

#include "base/memory/scoped_ptr.h"
#include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h"

namespace extensions {

using api::system_display::DisplayUnitInfo;

namespace SetDisplayProperties = api::system_display::SetDisplayProperties;

bool SystemDisplayGetInfoFunction::RunImpl() {
  DisplayInfoProvider::Get()->RequestInfo(
      base::Bind(
          &SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted,
          this));
  return true;
}

void SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted(
    bool success) {
  if (success) {
    results_ = api::system_display::GetInfo::Results::Create(
                   DisplayInfoProvider::Get()->display_info());
  } else {
    SetError("Error occurred when querying display information.");
  }
  SendResponse(success);
}

bool SystemDisplaySetDisplayPropertiesFunction::RunImpl() {
#if !defined(OS_CHROMEOS)
  SetError("Function available only on ChromeOS.");
  return false;
#else
  if (!KioskEnabledInfo::IsKioskEnabled(GetExtension())) {
    SetError("The extension needs to be kiosk enabled to use the function.");
    return false;
  }

  scoped_ptr<SetDisplayProperties::Params> params(
      SetDisplayProperties::Params::Create(*args_));
  DisplayInfoProvider::Get()->SetInfo(params->id, params->info,
      base::Bind(
          &SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet,
          this));
  return true;
#endif
}

void SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet(
    bool success, const std::string& error) {
  if (!success)
    SetError(error);
  SendResponse(success);
}

}  // namespace extensions