| 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 <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace extensions { | 24 namespace extensions { |
| 25 | 25 |
| 26 namespace display = api::system_display; | 26 namespace display = api::system_display; |
| 27 | 27 |
| 28 const char SystemDisplayFunction::kCrosOnlyError[] = | 28 const char SystemDisplayFunction::kCrosOnlyError[] = |
| 29 "Function available only on ChromeOS."; | 29 "Function available only on ChromeOS."; |
| 30 const char SystemDisplayFunction::kKioskOnlyError[] = | 30 const char SystemDisplayFunction::kKioskOnlyError[] = |
| 31 "Only kiosk enabled extensions are allowed to use this function."; | 31 "Only kiosk enabled extensions are allowed to use this function."; |
| 32 | 32 |
| 33 const char |
| 34 SystemDisplayShowNativeTouchCalibrationFunction::kTouchCalibrationError[] = |
| 35 "Touch calibration failed"; |
| 36 |
| 33 namespace { | 37 namespace { |
| 34 | 38 |
| 35 class OverscanTracker; | 39 class OverscanTracker; |
| 36 | 40 |
| 37 // Singleton class to track overscan calibration overlays. An observer is | 41 // Singleton class to track overscan calibration overlays. An observer is |
| 38 // created per WebContents which tracks any calbiration overlays by id. | 42 // created per WebContents which tracks any calbiration overlays by id. |
| 39 // If the render frame is deleted (e.g. the tab is closed) before the overlay | 43 // If the render frame is deleted (e.g. the tab is closed) before the overlay |
| 40 // calibraiton is completed, the observer will call the overscan complete | 44 // calibraiton is completed, the observer will call the overscan complete |
| 41 // method to remove the overlay. When all observers are removed, the singleton | 45 // method to remove the overlay. When all observers are removed, the singleton |
| 42 // tracker will delete itself. | 46 // tracker will delete itself. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 display::OverscanCalibrationComplete::Params::Create(*args_)); | 264 display::OverscanCalibrationComplete::Params::Create(*args_)); |
| 261 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) { | 265 if (!DisplayInfoProvider::Get()->OverscanCalibrationComplete(params->id)) { |
| 262 return RespondNow( | 266 return RespondNow( |
| 263 Error("Calibration not started for display ID: " + params->id)); | 267 Error("Calibration not started for display ID: " + params->id)); |
| 264 } | 268 } |
| 265 OverscanTracker::RemoveDisplay(GetSenderWebContents(), params->id); | 269 OverscanTracker::RemoveDisplay(GetSenderWebContents(), params->id); |
| 266 return RespondNow(NoArguments()); | 270 return RespondNow(NoArguments()); |
| 267 } | 271 } |
| 268 | 272 |
| 269 ExtensionFunction::ResponseAction | 273 ExtensionFunction::ResponseAction |
| 270 SystemDisplayTouchCalibrationStartFunction::Run() { | 274 SystemDisplayShowNativeTouchCalibrationFunction::Run() { |
| 271 std::unique_ptr<display::TouchCalibrationStart::Params> params( | 275 std::unique_ptr<display::ShowNativeTouchCalibration::Params> params( |
| 272 display::TouchCalibrationStart::Params::Create(*args_)); | 276 display::ShowNativeTouchCalibration::Params::Create(*args_)); |
| 273 | 277 |
| 274 std::string error; | 278 std::string error; |
| 275 if (DisplayInfoProvider::Get()->IsTouchCalibrationActive(&error)) | 279 if (DisplayInfoProvider::Get()->IsNativeTouchCalibrationActive(&error)) |
| 276 return RespondNow(Error(error)); | 280 return RespondNow(Error(error)); |
| 277 | 281 |
| 278 if (!DisplayInfoProvider::Get()->TouchCalibrationStart(params->id)) | 282 if (!DisplayInfoProvider::Get()->ShowNativeTouchCalibration( |
| 279 return RespondNow(Error("Invalid display ID: " + params->id)); | 283 params->id, &error, |
| 284 base::Bind(&SystemDisplayShowNativeTouchCalibrationFunction:: |
| 285 OnCalibrationComplete, |
| 286 this))) { |
| 287 return RespondNow(Error(error)); |
| 288 } |
| 289 return RespondLater(); |
| 290 } |
| 291 |
| 292 void SystemDisplayShowNativeTouchCalibrationFunction::OnCalibrationComplete( |
| 293 bool success) { |
| 294 if (success) |
| 295 Respond(OneArgument(base::MakeUnique<base::FundamentalValue>(true))); |
| 296 else |
| 297 Respond(Error(kTouchCalibrationError)); |
| 298 } |
| 299 |
| 300 ExtensionFunction::ResponseAction |
| 301 SystemDisplayStartCustomTouchCalibrationFunction::Run() { |
| 302 std::unique_ptr<display::StartCustomTouchCalibration::Params> params( |
| 303 display::StartCustomTouchCalibration::Params::Create(*args_)); |
| 304 |
| 305 std::string error; |
| 306 if (DisplayInfoProvider::Get()->IsNativeTouchCalibrationActive(&error)) |
| 307 return RespondNow(Error(error)); |
| 308 |
| 309 if (!DisplayInfoProvider::Get()->StartCustomTouchCalibration(params->id, |
| 310 &error)) |
| 311 return RespondNow(Error(error)); |
| 280 return RespondNow(NoArguments()); | 312 return RespondNow(NoArguments()); |
| 281 } | 313 } |
| 282 | 314 |
| 283 ExtensionFunction::ResponseAction | 315 ExtensionFunction::ResponseAction |
| 284 SystemDisplayTouchCalibrationSetFunction::Run() { | 316 SystemDisplayCompleteCustomTouchCalibrationFunction::Run() { |
| 285 std::unique_ptr<display::TouchCalibrationSet::Params> params( | 317 std::unique_ptr<display::CompleteCustomTouchCalibration::Params> params( |
| 286 display::TouchCalibrationSet::Params::Create(*args_)); | 318 display::CompleteCustomTouchCalibration::Params::Create(*args_)); |
| 287 | 319 |
| 288 std::string error; | 320 std::string error; |
| 289 if (DisplayInfoProvider::Get()->IsTouchCalibrationActive(&error)) | 321 if (DisplayInfoProvider::Get()->IsNativeTouchCalibrationActive(&error)) |
| 290 return RespondNow(Error(error)); | 322 return RespondNow(Error(error)); |
| 291 | 323 |
| 292 if (!DisplayInfoProvider::Get()->TouchCalibrationSet( | 324 if (!DisplayInfoProvider::Get()->CompleteCustomTouchCalibration( |
| 293 params->id, params->pairs, params->bounds, &error)) { | 325 params->pairs, params->bounds, &error)) { |
| 294 return RespondNow(Error(error)); | 326 return RespondNow(Error(error)); |
| 295 } | 327 } |
| 296 return RespondNow(NoArguments()); | 328 return RespondNow(NoArguments()); |
| 297 } | 329 } |
| 298 | 330 |
| 299 ExtensionFunction::ResponseAction | 331 ExtensionFunction::ResponseAction |
| 300 SystemDisplayTouchCalibrationResetFunction::Run() { | 332 SystemDisplayClearTouchCalibrationFunction::Run() { |
| 301 std::unique_ptr<display::TouchCalibrationReset::Params> params( | 333 std::unique_ptr<display::ClearTouchCalibration::Params> params( |
| 302 display::TouchCalibrationReset::Params::Create(*args_)); | 334 display::ClearTouchCalibration::Params::Create(*args_)); |
| 303 | 335 |
| 304 std::string error; | 336 std::string error; |
| 305 if (DisplayInfoProvider::Get()->IsTouchCalibrationActive(&error)) | 337 if (DisplayInfoProvider::Get()->IsNativeTouchCalibrationActive(&error)) |
| 306 return RespondNow(Error(error)); | 338 return RespondNow(Error(error)); |
| 307 | 339 |
| 308 if (!DisplayInfoProvider::Get()->TouchCalibrationReset(params->id, &error)) | 340 if (!DisplayInfoProvider::Get()->ClearTouchCalibration(params->id, &error)) |
| 309 return RespondNow(Error(error)); | 341 return RespondNow(Error(error)); |
| 310 return RespondNow(NoArguments()); | 342 return RespondNow(NoArguments()); |
| 311 } | 343 } |
| 312 | 344 |
| 313 } // namespace extensions | 345 } // namespace extensions |
| OLD | NEW |