1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/application/common/manifest_handlers/tizen_setting_handler.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "xwalk/application/common/application_manifest_constants.h"
16 namespace keys = application_widget_keys;
18 namespace application {
20 TizenSettingInfo::TizenSettingInfo()
21 : hwkey_enabled_(true),
22 screen_orientation_(PORTRAIT) {}
24 TizenSettingInfo::~TizenSettingInfo() {}
26 TizenSettingHandler::TizenSettingHandler() {}
28 TizenSettingHandler::~TizenSettingHandler() {}
30 bool TizenSettingHandler::Parse(scoped_refptr<ApplicationData> application,
31 base::string16* error) {
32 scoped_ptr<TizenSettingInfo> app_info(new TizenSettingInfo);
33 const Manifest* manifest = application->GetManifest();
37 manifest->GetString(keys::kTizenHardwareKey, &hwkey);
38 app_info->set_hwkey_enabled(hwkey != "disable");
40 std::string screen_orientation;
41 manifest->GetString(keys::kTizenScreenOrientationKey, &screen_orientation);
42 if (base::strcasecmp("portrait", screen_orientation.c_str()) == 0)
43 app_info->set_screen_orientation(TizenSettingInfo::PORTRAIT);
44 else if (base::strcasecmp("landscape", screen_orientation.c_str()) == 0)
45 app_info->set_screen_orientation(TizenSettingInfo::LANDSCAPE);
47 app_info->set_screen_orientation(TizenSettingInfo::AUTO);
48 std::string encryption;
49 manifest->GetString(keys::kTizenEncryptionKey, &encryption);
50 app_info->set_encryption_enabled(encryption == "enable");
52 application->SetManifestData(keys::kTizenSettingKey,
57 bool TizenSettingHandler::Validate(
58 scoped_refptr<const ApplicationData> application,
59 std::string* error) const {
60 const Manifest* manifest = application->GetManifest();
63 manifest->GetString(keys::kTizenHardwareKey, &hwkey);
64 if (!hwkey.empty() && hwkey != "enable" && hwkey != "disable") {
65 *error = std::string("The hwkey value must be 'enable'/'disable',"
66 " or not specified in configuration file.");
70 std::string screen_orientation;
71 manifest->GetString(keys::kTizenScreenOrientationKey, &screen_orientation);
72 if (!screen_orientation.empty() &&
73 base::strcasecmp("portrait", screen_orientation.c_str()) != 0 &&
74 base::strcasecmp("landscape", screen_orientation.c_str()) != 0 &&
75 base::strcasecmp("auto-rotation", screen_orientation.c_str()) != 0) {
76 *error = std::string("The screen-orientation must be 'portrait'/"
77 "'landscape'/'auto-rotation' or not specified.");
80 std::string encryption;
81 manifest->GetString(keys::kTizenEncryptionKey, &encryption);
82 if (!encryption.empty() && encryption != "enable" &&
83 encryption != "disable") {
84 *error = std::string("The encryption value must be 'enable'/'disable', "
85 "or not specified in configuration file.");
91 std::vector<std::string> TizenSettingHandler::Keys() const {
92 return std::vector<std::string>(1, keys::kTizenSettingKey);
95 } // namespace application