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

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: Fix non-chromeos + tests Created 4 years, 6 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 const char SystemDisplayFunction::kCrosOnlyError[] =
25 "Function available only on ChromeOS.";
26 const char SystemDisplayFunction::kKioskOnlyError[] =
27 "Only kiosk enabled extensions are allowed to use this function.";
28
29 bool SystemDisplayFunction::CheckValidExtension() {
30 if (!extension())
31 return true;
32 #if defined(OS_CHROMEOS)
33 if (KioskModeInfo::IsKioskEnabled(extension()))
34 return true;
35 #endif
36 SetError(kKioskOnlyError);
37 return false;
38 }
39
24 bool SystemDisplayGetInfoFunction::RunSync() { 40 bool SystemDisplayGetInfoFunction::RunSync() {
25 DisplayUnitInfoList all_displays_info = 41 DisplayUnitInfoList all_displays_info =
26 DisplayInfoProvider::Get()->GetAllDisplaysInfo(); 42 DisplayInfoProvider::Get()->GetAllDisplaysInfo();
27 results_ = api::system_display::GetInfo::Results::Create(all_displays_info); 43 results_ = api::system_display::GetInfo::Results::Create(all_displays_info);
28 return true; 44 return true;
29 } 45 }
30 46
31 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() { 47 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() {
32 #if !defined(OS_CHROMEOS) 48 #if !defined(OS_CHROMEOS)
33 SetError("Function available only on ChromeOS."); 49 SetError(kCrosOnlyError);
34 return false; 50 return false;
35 #else 51 #else
36 if (extension() && !KioskModeInfo::IsKioskEnabled(extension())) { 52 if (!CheckValidExtension())
37 SetError("The extension needs to be kiosk enabled to use the function.");
38 return false; 53 return false;
39 }
40 std::string error; 54 std::string error;
41 std::unique_ptr<SetDisplayProperties::Params> params( 55 std::unique_ptr<SetDisplayProperties::Params> params(
42 SetDisplayProperties::Params::Create(*args_)); 56 SetDisplayProperties::Params::Create(*args_));
43 bool result = 57 bool result =
44 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error); 58 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error);
45 if (!result) 59 if (!result)
46 SetError(error); 60 SetError(error);
47 return result; 61 return result;
48 #endif 62 #endif
49 } 63 }
50 64
51 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() { 65 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() {
52 #if !defined(OS_CHROMEOS) 66 #if !defined(OS_CHROMEOS)
53 SetError("Function available only on ChromeOS."); 67 SetError(kCrosOnlyError);
54 return false; 68 return false;
55 #else 69 #else
70 if (!CheckValidExtension())
71 return false;
56 std::unique_ptr<api::system_display::EnableUnifiedDesktop::Params> params( 72 std::unique_ptr<api::system_display::EnableUnifiedDesktop::Params> params(
57 api::system_display::EnableUnifiedDesktop::Params::Create(*args_)); 73 api::system_display::EnableUnifiedDesktop::Params::Create(*args_));
58 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled); 74 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled);
59 return true; 75 return true;
60 #endif 76 #endif
61 } 77 }
62 78
79 bool SystemDisplayOverscanCalibrationStartFunction::RunSync() {
80 #if !defined(OS_CHROMEOS)
81 SetError(kCrosOnlyError);
82 return false;
83 #else
84 if (!CheckValidExtension())
85 return false;
86 std::unique_ptr<api::system_display::OverscanCalibrationStart::Params> params(
87 api::system_display::OverscanCalibrationStart::Params::Create(*args_));
88 if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id)) {
89 SetError("Invalid display ID: " + params->id);
90 return false;
91 }
92 return true;
93 #endif
94 }
95
96 bool SystemDisplayOverscanCalibrationAdjustFunction::RunSync() {
97 #if !defined(OS_CHROMEOS)
98 SetError(kCrosOnlyError);
99 return false;
100 #else
101 if (!CheckValidExtension())
102 return false;
103 std::unique_ptr<api::system_display::OverscanCalibrationAdjust::Params>
104 params(api::system_display::OverscanCalibrationAdjust::Params::Create(
105 *args_));
106 if (!params) {
107 SetError("Invalid parameters");
108 return false;
109 }
110 if (!DisplayInfoProvider::Get()->OverscanCalibrationAdjust(params->id,
111 params->delta)) {
112 SetError("Calibration not started for display ID: " + params->id);
113 return false;
114 }
115 return true;
116 #endif
117 }
118
119 bool SystemDisplayOverscanCalibrationResetFunction::RunSync() {
120 #if !defined(OS_CHROMEOS)
121 SetError(kCrosOnlyError);
122 return false;
123 #else
124 if (!CheckValidExtension())
125 return false;
126 std::unique_ptr<api::system_display::OverscanCalibrationReset::Params> params(
127 api::system_display::OverscanCalibrationReset::Params::Create(*args_));
128 if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id)) {
129 SetError("Calibration not started for display ID: " + params->id);
130 return false;
131 }
132 return true;
133 #endif
134 }
135
136 bool SystemDisplayOverscanCalibrationCompleteFunction::RunSync() {
137 #if !defined(OS_CHROMEOS)
138 SetError(kCrosOnlyError);
139 return false;
140 #else
141 if (!CheckValidExtension())
142 return false;
143 std::unique_ptr<api::system_display::OverscanCalibrationComplete::Params>
144 params(api::system_display::OverscanCalibrationComplete::Params::Create(
145 *args_));
146 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) {
147 SetError("Calibration not started for display ID: " + params->id);
148 return false;
149 }
150 return true;
151 #endif
152 }
153
63 } // namespace extensions 154 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698