Upstream version 10.38.220.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
24 TizenSettingInfo::~TizenSettingInfo() {}
25
26 TizenSettingHandler::TizenSettingHandler() {}
27
28 TizenSettingHandler::~TizenSettingHandler() {}
29
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();
34   DCHECK(manifest);
35
36   std::string hwkey;
37   manifest->GetString(keys::kTizenHardwareKey, &hwkey);
38   app_info->set_hwkey_enabled(hwkey != "disable");
39
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);
46   else
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");
51
52   application->SetManifestData(keys::kTizenSettingKey,
53                                app_info.release());
54   return true;
55 }
56
57 bool TizenSettingHandler::Validate(
58     scoped_refptr<const ApplicationData> application,
59     std::string* error) const {
60   const Manifest* manifest = application->GetManifest();
61   DCHECK(manifest);
62   std::string hwkey;
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.");
67     return false;
68   }
69
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.");
78     return false;
79   }
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.");
86     return false;
87   }
88   return true;
89 }
90
91 std::vector<std::string> TizenSettingHandler::Keys() const {
92   return std::vector<std::string>(1, keys::kTizenSettingKey);
93 }
94
95 }  // namespace application
96 }  // namespace xwalk