Upstream version 9.38.198.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/utf_string_conversions.h"
11 #include "xwalk/application/common/application_manifest_constants.h"
12
13 namespace xwalk {
14
15 namespace keys = application_widget_keys;
16
17 namespace application {
18
19 TizenSettingInfo::TizenSettingInfo()
20     : hwkey_enabled_(true) {}
21
22 TizenSettingInfo::~TizenSettingInfo() {}
23
24 TizenSettingHandler::TizenSettingHandler() {}
25
26 TizenSettingHandler::~TizenSettingHandler() {}
27
28 bool TizenSettingHandler::Parse(scoped_refptr<ApplicationData> application,
29                                 base::string16* error) {
30   scoped_ptr<TizenSettingInfo> app_info(new TizenSettingInfo);
31   const Manifest* manifest = application->GetManifest();
32   DCHECK(manifest);
33
34   std::string hwkey;
35   manifest->GetString(keys::kTizenHardwareKey, &hwkey);
36   app_info->set_hwkey_enabled(hwkey != "disable");
37
38   application->SetManifestData(keys::kTizenSettingKey,
39                                app_info.release());
40   return true;
41 }
42
43 bool TizenSettingHandler::Validate(
44     scoped_refptr<const ApplicationData> application,
45     std::string* error) const {
46   const Manifest* manifest = application->GetManifest();
47   DCHECK(manifest);
48   std::string hwkey;
49   manifest->GetString(keys::kTizenHardwareKey, &hwkey);
50   if (!hwkey.empty() && hwkey != "enable" && hwkey != "disable") {
51     *error = std::string("The hwkey value must be 'enable'/'disable',"
52                          " or not specified in configuration file.");
53     return false;
54   }
55   return true;
56 }
57
58 std::vector<std::string> TizenSettingHandler::Keys() const {
59   return std::vector<std::string>(1, keys::kTizenSettingKey);
60 }
61
62 }  // namespace application
63 }  // namespace xwalk