| 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 "chrome/browser/extensions/api/system_display/system_display_api.h" | 5 #include "chrome/browser/extensions/api/system_display/system_display_api.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "chrome/browser/extensions/api/system_display/display_info_provider.h" |
| 12 #include "chrome/common/extensions/api/system_display.h" |
| 8 #include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h" | 13 #include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h" |
| 14 #include "ui/gfx/display.h" |
| 15 #include "ui/gfx/screen.h" |
| 9 | 16 |
| 10 namespace extensions { | 17 namespace extensions { |
| 11 | 18 |
| 12 using api::system_display::DisplayUnitInfo; | 19 using api::system_display::DisplayUnitInfo; |
| 13 | 20 |
| 14 namespace SetDisplayProperties = api::system_display::SetDisplayProperties; | 21 namespace SetDisplayProperties = api::system_display::SetDisplayProperties; |
| 15 | 22 |
| 23 typedef std::vector<linked_ptr< |
| 24 api::system_display::DisplayUnitInfo> > DisplayInfo; |
| 25 |
| 16 bool SystemDisplayGetInfoFunction::RunImpl() { | 26 bool SystemDisplayGetInfoFunction::RunImpl() { |
| 17 DisplayInfoProvider::Get()->RequestInfo( | 27 DisplayInfo all_displays_info = |
| 18 base::Bind( | 28 DisplayInfoProvider::Get()->GetAllDisplaysInfo(); |
| 19 &SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted, | 29 results_ = api::system_display::GetInfo::Results::Create(all_displays_info); |
| 20 this)); | |
| 21 return true; | 30 return true; |
| 22 } | 31 } |
| 23 | 32 |
| 24 void SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted( | |
| 25 bool success) { | |
| 26 if (success) { | |
| 27 results_ = api::system_display::GetInfo::Results::Create( | |
| 28 DisplayInfoProvider::Get()->display_info()); | |
| 29 } else { | |
| 30 SetError("Error occurred when querying display information."); | |
| 31 } | |
| 32 SendResponse(success); | |
| 33 } | |
| 34 | |
| 35 bool SystemDisplaySetDisplayPropertiesFunction::RunImpl() { | 33 bool SystemDisplaySetDisplayPropertiesFunction::RunImpl() { |
| 36 #if !defined(OS_CHROMEOS) | 34 #if !defined(OS_CHROMEOS) |
| 37 SetError("Function available only on ChromeOS."); | 35 SetError("Function available only on ChromeOS."); |
| 38 return false; | 36 return false; |
| 39 #else | 37 #else |
| 40 if (!KioskEnabledInfo::IsKioskEnabled(GetExtension())) { | 38 if (!KioskEnabledInfo::IsKioskEnabled(GetExtension())) { |
| 41 SetError("The extension needs to be kiosk enabled to use the function."); | 39 SetError("The extension needs to be kiosk enabled to use the function."); |
| 42 return false; | 40 return false; |
| 43 } | 41 } |
| 44 | 42 std::string error; |
| 45 scoped_ptr<SetDisplayProperties::Params> params( | 43 scoped_ptr<SetDisplayProperties::Params> params( |
| 46 SetDisplayProperties::Params::Create(*args_)); | 44 SetDisplayProperties::Params::Create(*args_)); |
| 47 DisplayInfoProvider::Get()->SetInfo(params->id, params->info, | 45 bool success = DisplayInfoProvider::Get()->SetInfo(params->id, |
| 48 base::Bind( | 46 params->info, |
| 49 &SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet, | 47 &error); |
| 50 this)); | 48 if (!success) |
| 49 SetError(error); |
| 50 SendResponse(success); |
| 51 return true; | 51 return true; |
| 52 #endif | 52 #endif |
| 53 } | 53 } |
| 54 | 54 |
| 55 void SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet( | |
| 56 bool success, const std::string& error) { | |
| 57 if (!success) | |
| 58 SetError(error); | |
| 59 SendResponse(success); | |
| 60 } | |
| 61 | |
| 62 } // namespace extensions | 55 } // namespace extensions |
| OLD | NEW |