Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / manifest_handlers / tizen_setting_handler.cc
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.
4
5 #include "xwalk/application/common/manifest_handlers/tizen_setting_handler.h"
6
7 #include <map>
8 #include <utility>
9
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "xwalk/application/common/application_manifest_constants.h"
13
14 namespace xwalk {
15
16 namespace keys = application_widget_keys;
17
18 namespace application {
19
20 TizenSettingInfo::TizenSettingInfo()
21     : hwkey_enabled_(true),
22       screen_orientation_(PORTRAIT),
23       background_support_enabled_(false) {}
24
25 TizenSettingInfo::~TizenSettingInfo() {}
26
27 TizenSettingHandler::TizenSettingHandler() {}
28
29 TizenSettingHandler::~TizenSettingHandler() {}
30
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();
35   DCHECK(manifest);
36
37   std::string hwkey;
38   manifest->GetString(keys::kTizenHardwareKey, &hwkey);
39   app_info->set_hwkey_enabled(hwkey != "disable");
40
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);
47   else
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");
52
53   std::string context_menu;
54   manifest->GetString(keys::kTizenContextMenuKey, &context_menu);
55   app_info->set_context_menu_enabled(context_menu != "disable");
56
57   std::string background_support;
58   manifest->GetString(keys::kTizenBackgroundSupportKey, &background_support);
59   app_info->set_background_support_enabled(background_support == "enable");
60
61   application->SetManifestData(keys::kTizenSettingKey,
62                                app_info.release());
63   return true;
64 }
65
66 bool TizenSettingHandler::Validate(
67     scoped_refptr<const ApplicationData> application,
68     std::string* error) const {
69   const Manifest* manifest = application->GetManifest();
70   DCHECK(manifest);
71   std::string hwkey;
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.");
76     return false;
77   }
78
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.");
87     return false;
88   }
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.");
95     return false;
96   }
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.");
104     return false;
105   }
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"
113                          "file.");
114   }
115   return true;
116 }
117
118 std::vector<std::string> TizenSettingHandler::Keys() const {
119   return std::vector<std::string>(1, keys::kTizenSettingKey);
120 }
121
122 }  // namespace application
123 }  // namespace xwalk