OLD | NEW |
---|---|
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 namespace system_display = api::system_display; | 20 namespace display = api::system_display; |
21 | 21 |
22 const char SystemDisplayFunction::kCrosOnlyError[] = | 22 const char SystemDisplayFunction::kCrosOnlyError[] = |
23 "Function available only on ChromeOS."; | 23 "Function available only on ChromeOS."; |
24 const char SystemDisplayFunction::kKioskOnlyError[] = | 24 const char SystemDisplayFunction::kKioskOnlyError[] = |
25 "Only kiosk enabled extensions are allowed to use this function."; | 25 "Only kiosk enabled extensions are allowed to use this function."; |
26 | 26 |
27 bool SystemDisplayFunction::CheckValidExtension() { | 27 bool SystemDisplayFunction::PreRunValidation(std::string* error) { |
28 if (!extension()) | 28 if (!UIThreadExtensionFunction::PreRunValidation(error)) |
29 return false; | |
30 | |
31 #if !defined(OS_CHROMEOS) | |
32 *error = kCrosOnlyError; | |
33 return false; | |
34 #else | |
lazyboy
2016/08/29 18:03:05
nit: no need for #else block, just #endif is fine.
Devlin
2016/08/29 20:22:25
KioskModeInfo is currently only included on CrOS (
lazyboy
2016/08/29 21:31:46
Ah, just noticed those runs.
Acknowledged.
| |
35 if (!ShouldRestrictToKioskAndWebUI()) | |
29 return true; | 36 return true; |
30 #if defined(OS_CHROMEOS) | 37 |
38 if (source_context_type() == Feature::WEBUI_CONTEXT) | |
lazyboy
2016/08/29 18:03:05
Got it, thanks!
| |
39 return true; | |
31 if (KioskModeInfo::IsKioskEnabled(extension())) | 40 if (KioskModeInfo::IsKioskEnabled(extension())) |
32 return true; | 41 return true; |
42 *error = kKioskOnlyError; | |
43 return false; | |
33 #endif | 44 #endif |
34 SetError(kKioskOnlyError); | 45 } |
46 | |
47 bool SystemDisplayFunction::ShouldRestrictToKioskAndWebUI() { | |
48 return true; | |
49 } | |
50 | |
51 ExtensionFunction::ResponseAction SystemDisplayGetInfoFunction::Run() { | |
52 DisplayInfoProvider::DisplayUnitInfoList all_displays_info = | |
53 DisplayInfoProvider::Get()->GetAllDisplaysInfo(); | |
54 return RespondNow( | |
55 ArgumentList(display::GetInfo::Results::Create(all_displays_info))); | |
56 } | |
57 | |
58 ExtensionFunction::ResponseAction SystemDisplayGetDisplayLayoutFunction::Run() { | |
59 DisplayInfoProvider::DisplayLayoutList display_layout = | |
60 DisplayInfoProvider::Get()->GetDisplayLayout(); | |
61 return RespondNow( | |
62 ArgumentList(display::GetDisplayLayout::Results::Create(display_layout))); | |
63 } | |
64 | |
65 bool SystemDisplayGetDisplayLayoutFunction::ShouldRestrictToKioskAndWebUI() { | |
35 return false; | 66 return false; |
36 } | 67 } |
37 | 68 |
38 bool SystemDisplayGetInfoFunction::RunSync() { | 69 ExtensionFunction::ResponseAction |
39 DisplayInfoProvider::DisplayUnitInfoList all_displays_info = | 70 SystemDisplaySetDisplayPropertiesFunction::Run() { |
40 DisplayInfoProvider::Get()->GetAllDisplaysInfo(); | |
41 results_ = system_display::GetInfo::Results::Create(all_displays_info); | |
42 return true; | |
43 } | |
44 | |
45 bool SystemDisplayGetDisplayLayoutFunction::RunSync() { | |
46 #if !defined(OS_CHROMEOS) | |
47 SetError(kCrosOnlyError); | |
48 return false; | |
49 #else | |
50 DisplayInfoProvider::DisplayLayoutList display_layout = | |
51 DisplayInfoProvider::Get()->GetDisplayLayout(); | |
52 results_ = system_display::GetDisplayLayout::Results::Create(display_layout); | |
53 return true; | |
54 #endif | |
55 } | |
56 | |
57 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() { | |
58 #if !defined(OS_CHROMEOS) | |
59 SetError(kCrosOnlyError); | |
60 return false; | |
61 #else | |
62 if (!CheckValidExtension()) | |
63 return false; | |
64 std::string error; | 71 std::string error; |
65 std::unique_ptr<system_display::SetDisplayProperties::Params> params( | 72 std::unique_ptr<display::SetDisplayProperties::Params> params( |
66 system_display::SetDisplayProperties::Params::Create(*args_)); | 73 display::SetDisplayProperties::Params::Create(*args_)); |
67 bool result = | 74 bool result = |
68 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error); | 75 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error); |
69 if (!result) | 76 if (!result) |
70 SetError(error); | 77 return RespondNow(Error(error)); |
71 return result; | 78 return RespondNow(NoArguments()); |
72 #endif | |
73 } | 79 } |
74 | 80 |
75 bool SystemDisplaySetDisplayLayoutFunction::RunSync() { | 81 ExtensionFunction::ResponseAction SystemDisplaySetDisplayLayoutFunction::Run() { |
76 #if !defined(OS_CHROMEOS) | 82 std::unique_ptr<display::SetDisplayLayout::Params> params( |
77 SetError(kCrosOnlyError); | 83 display::SetDisplayLayout::Params::Create(*args_)); |
78 return false; | 84 if (!DisplayInfoProvider::Get()->SetDisplayLayout(params->layouts)) |
79 #else | 85 return RespondNow(Error("Unable to set display layout")); |
80 if (!CheckValidExtension()) | 86 return RespondNow(NoArguments()); |
81 return false; | |
82 std::unique_ptr<system_display::SetDisplayLayout::Params> params( | |
83 system_display::SetDisplayLayout::Params::Create(*args_)); | |
84 if (!DisplayInfoProvider::Get()->SetDisplayLayout(params->layouts)) { | |
85 SetError("Unable to set display layout"); | |
86 return false; | |
87 } | |
88 return true; | |
89 #endif | |
90 } | 87 } |
91 | 88 |
92 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() { | 89 ExtensionFunction::ResponseAction |
93 #if !defined(OS_CHROMEOS) | 90 SystemDisplayEnableUnifiedDesktopFunction::Run() { |
94 SetError(kCrosOnlyError); | 91 std::unique_ptr<display::EnableUnifiedDesktop::Params> params( |
95 return false; | 92 display::EnableUnifiedDesktop::Params::Create(*args_)); |
96 #else | |
97 if (!CheckValidExtension()) | |
98 return false; | |
99 std::unique_ptr<system_display::EnableUnifiedDesktop::Params> params( | |
100 system_display::EnableUnifiedDesktop::Params::Create(*args_)); | |
101 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled); | 93 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled); |
102 return true; | 94 return RespondNow(NoArguments()); |
103 #endif | |
104 } | 95 } |
105 | 96 |
106 bool SystemDisplayOverscanCalibrationStartFunction::RunSync() { | 97 ExtensionFunction::ResponseAction |
107 #if !defined(OS_CHROMEOS) | 98 SystemDisplayOverscanCalibrationStartFunction::Run() { |
108 SetError(kCrosOnlyError); | 99 std::unique_ptr<display::OverscanCalibrationStart::Params> params( |
109 return false; | 100 display::OverscanCalibrationStart::Params::Create(*args_)); |
110 #else | 101 if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id)) |
111 if (!CheckValidExtension()) | 102 return RespondNow(Error("Invalid display ID: " + params->id)); |
112 return false; | 103 return RespondNow(NoArguments()); |
113 std::unique_ptr<system_display::OverscanCalibrationStart::Params> params( | |
114 system_display::OverscanCalibrationStart::Params::Create(*args_)); | |
115 if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id)) { | |
116 SetError("Invalid display ID: " + params->id); | |
117 return false; | |
118 } | |
119 return true; | |
120 #endif | |
121 } | 104 } |
122 | 105 |
123 bool SystemDisplayOverscanCalibrationAdjustFunction::RunSync() { | 106 ExtensionFunction::ResponseAction |
124 #if !defined(OS_CHROMEOS) | 107 SystemDisplayOverscanCalibrationAdjustFunction::Run() { |
125 SetError(kCrosOnlyError); | 108 std::unique_ptr<display::OverscanCalibrationAdjust::Params> params( |
126 return false; | 109 display::OverscanCalibrationAdjust::Params::Create(*args_)); |
127 #else | 110 if (!params) |
128 if (!CheckValidExtension()) | 111 return RespondNow(Error("Invalid parameters")); |
129 return false; | |
130 std::unique_ptr<system_display::OverscanCalibrationAdjust::Params> params( | |
131 system_display::OverscanCalibrationAdjust::Params::Create(*args_)); | |
132 if (!params) { | |
133 SetError("Invalid parameters"); | |
134 return false; | |
135 } | |
136 if (!DisplayInfoProvider::Get()->OverscanCalibrationAdjust(params->id, | 112 if (!DisplayInfoProvider::Get()->OverscanCalibrationAdjust(params->id, |
137 params->delta)) { | 113 params->delta)) { |
138 SetError("Calibration not started for display ID: " + params->id); | 114 return RespondNow( |
139 return false; | 115 Error("Calibration not started for display ID: " + params->id)); |
140 } | 116 } |
141 return true; | 117 return RespondNow(NoArguments()); |
142 #endif | |
143 } | 118 } |
144 | 119 |
145 bool SystemDisplayOverscanCalibrationResetFunction::RunSync() { | 120 ExtensionFunction::ResponseAction |
146 #if !defined(OS_CHROMEOS) | 121 SystemDisplayOverscanCalibrationResetFunction::Run() { |
147 SetError(kCrosOnlyError); | 122 std::unique_ptr<display::OverscanCalibrationReset::Params> params( |
148 return false; | 123 display::OverscanCalibrationReset::Params::Create(*args_)); |
149 #else | 124 if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id)) |
150 if (!CheckValidExtension()) | 125 return RespondNow( |
151 return false; | 126 Error("Calibration not started for display ID: " + params->id)); |
152 std::unique_ptr<system_display::OverscanCalibrationReset::Params> params( | 127 return RespondNow(NoArguments()); |
153 system_display::OverscanCalibrationReset::Params::Create(*args_)); | |
154 if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id)) { | |
155 SetError("Calibration not started for display ID: " + params->id); | |
156 return false; | |
157 } | |
158 return true; | |
159 #endif | |
160 } | 128 } |
161 | 129 |
162 bool SystemDisplayOverscanCalibrationCompleteFunction::RunSync() { | 130 ExtensionFunction::ResponseAction |
163 #if !defined(OS_CHROMEOS) | 131 SystemDisplayOverscanCalibrationCompleteFunction::Run() { |
164 SetError(kCrosOnlyError); | 132 std::unique_ptr<display::OverscanCalibrationComplete::Params> params( |
165 return false; | 133 display::OverscanCalibrationComplete::Params::Create(*args_)); |
166 #else | |
167 if (!CheckValidExtension()) | |
168 return false; | |
169 std::unique_ptr<system_display::OverscanCalibrationComplete::Params> params( | |
170 system_display::OverscanCalibrationComplete::Params::Create(*args_)); | |
171 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) { | 134 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) { |
172 SetError("Calibration not started for display ID: " + params->id); | 135 return RespondNow( |
173 return false; | 136 Error("Calibration not started for display ID: " + params->id)); |
174 } | 137 } |
175 return true; | 138 return RespondNow(NoArguments()); |
176 #endif | |
177 } | 139 } |
178 | 140 |
179 } // namespace extensions | 141 } // namespace extensions |
OLD | NEW |