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),
23 background_support_enabled_(false) {}
25 TizenSettingInfo::~TizenSettingInfo() {}
27 TizenSettingHandler::TizenSettingHandler() {}
29 TizenSettingHandler::~TizenSettingHandler() {}
31 bool TizenSettingHandler::Parse(scoped_refptr<ApplicationData> application,
32 base::string16* error) {
33 scoped_ptr<TizenSettingInfo> app_info(new TizenSettingInfo);
34 const Manifest* manifest = application->GetManifest();
38 manifest->GetString(keys::kTizenHardwareKey, &hwkey);
39 app_info->set_hwkey_enabled(hwkey != "disable");
41 std::string screen_orientation;
42 manifest->GetString(keys::kTizenScreenOrientationKey, &screen_orientation);
43 if (base::strcasecmp("portrait", screen_orientation.c_str()) == 0)
44 app_info->set_screen_orientation(TizenSettingInfo::PORTRAIT);
45 else if (base::strcasecmp("landscape", screen_orientation.c_str()) == 0)
46 app_info->set_screen_orientation(TizenSettingInfo::LANDSCAPE);
48 app_info->set_screen_orientation(TizenSettingInfo::AUTO);
49 std::string encryption;
50 manifest->GetString(keys::kTizenEncryptionKey, &encryption);
51 app_info->set_encryption_enabled(encryption == "enable");
53 std::string context_menu;
54 manifest->GetString(keys::kTizenContextMenuKey, &context_menu);
55 app_info->set_context_menu_enabled(context_menu != "disable");
57 std::string background_support;
58 manifest->GetString(keys::kTizenBackgroundSupportKey, &background_support);
59 app_info->set_background_support_enabled(background_support == "enable");
61 application->SetManifestData(keys::kTizenSettingKey,
66 bool TizenSettingHandler::Validate(
67 scoped_refptr<const ApplicationData> application,
68 std::string* error) const {
69 const Manifest* manifest = application->GetManifest();
72 manifest->GetString(keys::kTizenHardwareKey, &hwkey);
73 if (!hwkey.empty() && hwkey != "enable" && hwkey != "disable") {
74 *error = std::string("The hwkey value must be 'enable'/'disable',"
75 " or not specified in configuration file.");
79 std::string screen_orientation;
80 manifest->GetString(keys::kTizenScreenOrientationKey, &screen_orientation);
81 if (!screen_orientation.empty() &&
82 base::strcasecmp("portrait", screen_orientation.c_str()) != 0 &&
83 base::strcasecmp("landscape", screen_orientation.c_str()) != 0 &&
84 base::strcasecmp("auto-rotation", screen_orientation.c_str()) != 0) {
85 *error = std::string("The screen-orientation must be 'portrait'/"
86 "'landscape'/'auto-rotation' or not specified.");
89 std::string encryption;
90 manifest->GetString(keys::kTizenEncryptionKey, &encryption);
91 if (!encryption.empty() && encryption != "enable" &&
92 encryption != "disable") {
93 *error = std::string("The encryption value must be 'enable'/'disable', "
94 "or not specified in configuration file.");
97 std::string context_menu;
98 manifest->GetString(keys::kTizenContextMenuKey, &context_menu);
99 if (!context_menu.empty() &&
100 context_menu != "enable" &&
101 context_menu != "disable") {
102 *error = std::string("The context-menu value must be 'enable'/'disable', "
103 "or not specified in configuration file.");
106 std::string background_support;
107 manifest->GetString(keys::kTizenBackgroundSupportKey, &background_support);
108 if (!background_support.empty() &&
109 background_support != "enable" &&
110 background_support != "disable") {
111 *error = std::string("The background-support value must be"
112 "'enable'/'disable', or not specified in configuration"
118 std::vector<std::string> TizenSettingHandler::Keys() const {
119 return std::vector<std::string>(1, keys::kTizenSettingKey);
122 } // namespace application