 Chromium Code Reviews
 Chromium Code Reviews Issue 2072633002:
  Add Get/SetDisplayLayout to chrome.system.display extension API  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2072633002:
  Add Get/SetDisplayLayout to chrome.system.display extension API  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 using api::system_display::DisplayUnitInfo; | 20 namespace system_display = api::system_display; | 
| 21 | |
| 22 namespace SetDisplayProperties = api::system_display::SetDisplayProperties; | |
| 23 | 21 | 
| 24 const char SystemDisplayFunction::kCrosOnlyError[] = | 22 const char SystemDisplayFunction::kCrosOnlyError[] = | 
| 25 "Function available only on ChromeOS."; | 23 "Function available only on ChromeOS."; | 
| 26 const char SystemDisplayFunction::kKioskOnlyError[] = | 24 const char SystemDisplayFunction::kKioskOnlyError[] = | 
| 27 "Only kiosk enabled extensions are allowed to use this function."; | 25 "Only kiosk enabled extensions are allowed to use this function."; | 
| 28 | 26 | 
| 29 bool SystemDisplayFunction::CheckValidExtension() { | 27 bool SystemDisplayFunction::CheckValidExtension() { | 
| 30 if (!extension()) | 28 if (!extension()) | 
| 31 return true; | 29 return true; | 
| 32 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) | 
| 33 if (KioskModeInfo::IsKioskEnabled(extension())) | 31 if (KioskModeInfo::IsKioskEnabled(extension())) | 
| 34 return true; | 32 return true; | 
| 35 #endif | 33 #endif | 
| 36 SetError(kKioskOnlyError); | 34 SetError(kKioskOnlyError); | 
| 37 return false; | 35 return false; | 
| 38 } | 36 } | 
| 39 | 37 | 
| 40 bool SystemDisplayGetInfoFunction::RunSync() { | 38 bool SystemDisplayGetInfoFunction::RunSync() { | 
| 41 DisplayUnitInfoList all_displays_info = | 39 DisplayInfoProvider::DisplayUnitInfoList all_displays_info = | 
| 42 DisplayInfoProvider::Get()->GetAllDisplaysInfo(); | 40 DisplayInfoProvider::Get()->GetAllDisplaysInfo(); | 
| 43 results_ = api::system_display::GetInfo::Results::Create(all_displays_info); | 41 results_ = system_display::GetInfo::Results::Create(all_displays_info); | 
| 44 return true; | 42 return true; | 
| 45 } | 43 } | 
| 46 | 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 | |
| 47 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() { | 57 bool SystemDisplaySetDisplayPropertiesFunction::RunSync() { | 
| 48 #if !defined(OS_CHROMEOS) | 58 #if !defined(OS_CHROMEOS) | 
| 49 SetError(kCrosOnlyError); | 59 SetError(kCrosOnlyError); | 
| 50 return false; | 60 return false; | 
| 51 #else | 61 #else | 
| 52 if (!CheckValidExtension()) | 62 if (!CheckValidExtension()) | 
| 53 return false; | 63 return false; | 
| 54 std::string error; | 64 std::string error; | 
| 55 std::unique_ptr<SetDisplayProperties::Params> params( | 65 std::unique_ptr<system_display::SetDisplayProperties::Params> params( | 
| 56 SetDisplayProperties::Params::Create(*args_)); | 66 system_display::SetDisplayProperties::Params::Create(*args_)); | 
| 57 bool result = | 67 bool result = | 
| 58 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error); | 68 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, &error); | 
| 59 if (!result) | 69 if (!result) | 
| 60 SetError(error); | 70 SetError(error); | 
| 61 return result; | 71 return result; | 
| 62 #endif | 72 #endif | 
| 63 } | 73 } | 
| 64 | 74 | 
| 75 bool SystemDisplaySetDisplayLayoutFunction::RunSync() { | |
| 76 #if !defined(OS_CHROMEOS) | |
| 77 SetError("Function available only on ChromeOS."); | |
| 
xiyuan
2016/06/16 20:11:52
SetError(kCrosOnlyError);
 
stevenjb
2016/06/17 01:34:59
Done.
 | |
| 78 return false; | |
| 79 #else | |
| 80 if (!CheckValidExtension()) | |
| 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 } | |
| 91 | |
| 65 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() { | 92 bool SystemDisplayEnableUnifiedDesktopFunction::RunSync() { | 
| 66 #if !defined(OS_CHROMEOS) | 93 #if !defined(OS_CHROMEOS) | 
| 67 SetError(kCrosOnlyError); | 94 SetError(kCrosOnlyError); | 
| 68 return false; | 95 return false; | 
| 69 #else | 96 #else | 
| 70 if (!CheckValidExtension()) | 97 if (!CheckValidExtension()) | 
| 71 return false; | 98 return false; | 
| 72 std::unique_ptr<api::system_display::EnableUnifiedDesktop::Params> params( | 99 std::unique_ptr<system_display::EnableUnifiedDesktop::Params> params( | 
| 73 api::system_display::EnableUnifiedDesktop::Params::Create(*args_)); | 100 system_display::EnableUnifiedDesktop::Params::Create(*args_)); | 
| 74 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled); | 101 DisplayInfoProvider::Get()->EnableUnifiedDesktop(params->enabled); | 
| 75 return true; | 102 return true; | 
| 76 #endif | 103 #endif | 
| 77 } | 104 } | 
| 78 | 105 | 
| 79 bool SystemDisplayOverscanCalibrationStartFunction::RunSync() { | 106 bool SystemDisplayOverscanCalibrationStartFunction::RunSync() { | 
| 80 #if !defined(OS_CHROMEOS) | 107 #if !defined(OS_CHROMEOS) | 
| 81 SetError(kCrosOnlyError); | 108 SetError(kCrosOnlyError); | 
| 82 return false; | 109 return false; | 
| 83 #else | 110 #else | 
| 84 if (!CheckValidExtension()) | 111 if (!CheckValidExtension()) | 
| 85 return false; | 112 return false; | 
| 86 std::unique_ptr<api::system_display::OverscanCalibrationStart::Params> params( | 113 std::unique_ptr<system_display::OverscanCalibrationStart::Params> params( | 
| 87 api::system_display::OverscanCalibrationStart::Params::Create(*args_)); | 114 system_display::OverscanCalibrationStart::Params::Create(*args_)); | 
| 88 if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id)) { | 115 if (!DisplayInfoProvider::Get()->OverscanCalibrationStart(params->id)) { | 
| 89 SetError("Invalid display ID: " + params->id); | 116 SetError("Invalid display ID: " + params->id); | 
| 90 return false; | 117 return false; | 
| 91 } | 118 } | 
| 92 return true; | 119 return true; | 
| 93 #endif | 120 #endif | 
| 94 } | 121 } | 
| 95 | 122 | 
| 96 bool SystemDisplayOverscanCalibrationAdjustFunction::RunSync() { | 123 bool SystemDisplayOverscanCalibrationAdjustFunction::RunSync() { | 
| 97 #if !defined(OS_CHROMEOS) | 124 #if !defined(OS_CHROMEOS) | 
| 98 SetError(kCrosOnlyError); | 125 SetError(kCrosOnlyError); | 
| 99 return false; | 126 return false; | 
| 100 #else | 127 #else | 
| 101 if (!CheckValidExtension()) | 128 if (!CheckValidExtension()) | 
| 102 return false; | 129 return false; | 
| 103 std::unique_ptr<api::system_display::OverscanCalibrationAdjust::Params> | 130 std::unique_ptr<system_display::OverscanCalibrationAdjust::Params> params( | 
| 104 params(api::system_display::OverscanCalibrationAdjust::Params::Create( | 131 system_display::OverscanCalibrationAdjust::Params::Create(*args_)); | 
| 105 *args_)); | |
| 106 if (!params) { | 132 if (!params) { | 
| 107 SetError("Invalid parameters"); | 133 SetError("Invalid parameters"); | 
| 108 return false; | 134 return false; | 
| 109 } | 135 } | 
| 110 if (!DisplayInfoProvider::Get()->OverscanCalibrationAdjust(params->id, | 136 if (!DisplayInfoProvider::Get()->OverscanCalibrationAdjust(params->id, | 
| 111 params->delta)) { | 137 params->delta)) { | 
| 112 SetError("Calibration not started for display ID: " + params->id); | 138 SetError("Calibration not started for display ID: " + params->id); | 
| 113 return false; | 139 return false; | 
| 114 } | 140 } | 
| 115 return true; | 141 return true; | 
| 116 #endif | 142 #endif | 
| 117 } | 143 } | 
| 118 | 144 | 
| 119 bool SystemDisplayOverscanCalibrationResetFunction::RunSync() { | 145 bool SystemDisplayOverscanCalibrationResetFunction::RunSync() { | 
| 120 #if !defined(OS_CHROMEOS) | 146 #if !defined(OS_CHROMEOS) | 
| 121 SetError(kCrosOnlyError); | 147 SetError(kCrosOnlyError); | 
| 122 return false; | 148 return false; | 
| 123 #else | 149 #else | 
| 124 if (!CheckValidExtension()) | 150 if (!CheckValidExtension()) | 
| 125 return false; | 151 return false; | 
| 126 std::unique_ptr<api::system_display::OverscanCalibrationReset::Params> params( | 152 std::unique_ptr<system_display::OverscanCalibrationReset::Params> params( | 
| 127 api::system_display::OverscanCalibrationReset::Params::Create(*args_)); | 153 system_display::OverscanCalibrationReset::Params::Create(*args_)); | 
| 128 if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id)) { | 154 if (!DisplayInfoProvider::Get()->OverscanCalibrationReset(params->id)) { | 
| 129 SetError("Calibration not started for display ID: " + params->id); | 155 SetError("Calibration not started for display ID: " + params->id); | 
| 130 return false; | 156 return false; | 
| 131 } | 157 } | 
| 132 return true; | 158 return true; | 
| 133 #endif | 159 #endif | 
| 134 } | 160 } | 
| 135 | 161 | 
| 136 bool SystemDisplayOverscanCalibrationCompleteFunction::RunSync() { | 162 bool SystemDisplayOverscanCalibrationCompleteFunction::RunSync() { | 
| 137 #if !defined(OS_CHROMEOS) | 163 #if !defined(OS_CHROMEOS) | 
| 138 SetError(kCrosOnlyError); | 164 SetError(kCrosOnlyError); | 
| 139 return false; | 165 return false; | 
| 140 #else | 166 #else | 
| 141 if (!CheckValidExtension()) | 167 if (!CheckValidExtension()) | 
| 142 return false; | 168 return false; | 
| 143 std::unique_ptr<api::system_display::OverscanCalibrationComplete::Params> | 169 std::unique_ptr<system_display::OverscanCalibrationComplete::Params> params( | 
| 144 params(api::system_display::OverscanCalibrationComplete::Params::Create( | 170 system_display::OverscanCalibrationComplete::Params::Create(*args_)); | 
| 145 *args_)); | |
| 146 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) { | 171 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) { | 
| 147 SetError("Calibration not started for display ID: " + params->id); | 172 SetError("Calibration not started for display ID: " + params->id); | 
| 148 return false; | 173 return false; | 
| 149 } | 174 } | 
| 150 return true; | 175 return true; | 
| 151 #endif | 176 #endif | 
| 152 } | 177 } | 
| 153 | 178 | 
| 154 } // namespace extensions | 179 } // namespace extensions | 
| OLD | NEW |