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