Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: extensions/browser/api/system_display/system_display_api.cc

Issue 2002773002: Add overscanCalibration methods to system_display.idl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "extensions/browser/api/system_display/system_display_api.h" 5 #include "extensions/browser/api/system_display/system_display_api.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "extensions/browser/api/system_display/display_info_provider.h" 11 #include "extensions/browser/api/system_display/display_info_provider.h"
12 #include "extensions/common/api/system_display.h" 12 #include "extensions/common/api/system_display.h"
13 13
14 #if defined(OS_CHROMEOS) 14 #if defined(OS_CHROMEOS)
15 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" 15 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
16 #endif 16 #endif
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 using api::system_display::DisplayUnitInfo; 20 using api::system_display::DisplayUnitInfo;
21 21
22 namespace SetDisplayProperties = api::system_display::SetDisplayProperties; 22 namespace SetDisplayProperties = api::system_display::SetDisplayProperties;
23 23
24 bool SystemDisplayFunction::CheckValidExtension() {
25 if (extension() && !KioskModeInfo::IsKioskEnabled(extension())) {
26 SetError("The extension needs to be kiosk enabled to use the function.");
27 return false;
28 }
29 return true;
30 }
31
24 bool SystemDisplayGetInfoFunction::RunSync() { 32 bool SystemDisplayGetInfoFunction::RunSync() {
25 DisplayUnitInfoList all_displays_info = 33 DisplayUnitInfoList all_displays_info =
26 DisplayInfoProvider::Get()->GetAllDisplaysInfo(); 34 DisplayInfoProvider::Get()->GetAllDisplaysInfo();
27 results_ = api::system_display::GetInfo::Results::Create(all_displays_info); 35 results_ = api::system_display::GetInfo::Results::Create(all_displays_info);
28 return true; 36 return true;
29 } 37 }
30 38
31 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() { 39 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() {
32 #if !defined(OS_CHROMEOS) 40 #if !defined(OS_CHROMEOS)
33 SetError("Function available only on ChromeOS."); 41 SetError("Function available only on ChromeOS.");
34 return false; 42 return false;
35 #else 43 #else
36 if (extension() && !KioskModeInfo::IsKioskEnabled(extension())) { 44 if (!CheckValidExtension())
37 SetError("The extension needs to be kiosk enabled to use the function.");
38 return false; 45 return false;
39 }
40 std::string error; 46 std::string error;
41 std::unique_ptr<SetDisplayProperties::Params> params( 47 std::unique_ptr<SetDisplayProperties::Params> params(
42 SetDisplayProperties::Params::Create(*args_)); 48 SetDisplayProperties::Params::Create(*args_));
43 bool result = 49 bool result =
44 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error); 50 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error);
45 if (!result) 51 if (!result)
46 SetError(error); 52 SetError(error);
47 return result; 53 return result;
48 #endif 54 #endif
49 } 55 }
50 56
51 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() { 57 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() {
52 #if !defined(OS_CHROMEOS) 58 #if !defined(OS_CHROMEOS)
53 SetError("Function available only on ChromeOS."); 59 SetError("Function available only on ChromeOS.");
54 return false; 60 return false;
55 #else 61 #else
62 if (!CheckValidExtension())
63 return false;
56 std::unique_ptr<api::system_display::EnableUnifiedDesktop::Params> params( 64 std::unique_ptr<api::system_display::EnableUnifiedDesktop::Params> params(
57 api::system_display::EnableUnifiedDesktop::Params::Create(*args_)); 65 api::system_display::EnableUnifiedDesktop::Params::Create(*args_));
58 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled); 66 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled);
59 return true; 67 return true;
60 #endif 68 #endif
61 } 69 }
62 70
71 bool SystemDisplayOverscanCalibrationStartFunction::RunSync() {
72 #if !defined(OS_CHROMEOS)
73 SetError("Function available only on ChromeOS.");
74 return false;
75 #else
76 if (!CheckValidExtension())
77 return false;
78 std::unique_ptr<api::system_display::OverscanCalibrationStart::Params> params(
79 api::system_display::OverscanCalibrationStart::Params::Create(*args_));
80 if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id)) {
81 SetError("Invalid display ID: " + params->id);
82 return false;
83 }
84 return true;
85 #endif
86 }
87
88 bool SystemDisplayOverscanCalibrationAdjustFunction::RunSync() {
89 #if !defined(OS_CHROMEOS)
90 SetError("Function available only on ChromeOS.");
91 return false;
92 #else
93 if (!CheckValidExtension())
94 return false;
95 std::unique_ptr<api::system_display::OverscanCalibrationAdjust::Params>
96 params(api::system_display::OverscanCalibrationAdjust::Params::Create(
97 *args_));
98 if (!params) {
99 SetError("Invalid parameters");
100 return false;
101 }
102 if (!DisplayInfoProvider::Get()->OverscanCalibrationAdjust(params->id,
103 params->delta)) {
104 SetError("Calibration not started for display ID: " + params->id);
105 return false;
106 }
107 return true;
108 #endif
109 }
110
111 bool SystemDisplayOverscanCalibrationResetFunction::RunSync() {
112 #if !defined(OS_CHROMEOS)
113 SetError("Function available only on ChromeOS.");
114 return false;
115 #else
116 if (!CheckValidExtension())
117 return false;
118 std::unique_ptr<api::system_display::OverscanCalibrationReset::Params> params(
119 api::system_display::OverscanCalibrationReset::Params::Create(*args_));
120 if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id)) {
121 SetError("Calibration not started for display ID: " + params->id);
122 return false;
123 }
124 return true;
125 #endif
126 }
127
128 bool SystemDisplayOverscanCalibrationCompleteFunction::RunSync() {
129 #if !defined(OS_CHROMEOS)
130 SetError("Function available only on ChromeOS.");
131 return false;
132 #else
133 if (!CheckValidExtension())
134 return false;
135 std::unique_ptr<api::system_display::OverscanCalibrationComplete::Params>
136 params(api::system_display::OverscanCalibrationComplete::Params::Create(
137 *args_));
138 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) {
139 SetError("Calibration not started for display ID: " + params->id);
140 return false;
141 }
142 return true;
143 #endif
144 }
145
63 } // namespace extensions 146 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698