Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / manifest_handlers / warp_handler.cc
1 // Copyright (c) 2013 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/warp_handler.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "xwalk/application/common/application_manifest_constants.h"
9
10 namespace xwalk {
11
12 namespace keys = application_widget_keys;
13
14 namespace application {
15
16 WARPInfo::WARPInfo() {
17 }
18
19 WARPInfo::~WARPInfo() {
20 }
21
22 WARPHandler::WARPHandler() {
23 }
24
25 WARPHandler::~WARPHandler() {
26 }
27
28 bool WARPHandler::Parse(scoped_refptr<ApplicationData> application,
29                        base::string16* error) {
30   base::Value* value;
31   if (!application->GetManifest()->HasPath(keys::kAccessKey))
32     return true;
33   if (!application->GetManifest()->Get(keys::kAccessKey, &value)) {
34     *error = base::ASCIIToUTF16(
35         "Invalid value of Widget Access Request Policy(WARP).");
36     return false;
37   }
38
39   scoped_ptr<base::ListValue> warp_list;
40   if (value->IsType(base::Value::TYPE_DICTIONARY)) {
41     warp_list.reset(new base::ListValue);
42     warp_list->Append(value->DeepCopy());
43   } else {
44     base::ListValue* list;
45     value->GetAsList(&list);
46     if (list)
47       warp_list.reset(list->DeepCopy());
48   }
49
50   if (!warp_list) {
51     *error = base::ASCIIToUTF16(
52         "Invalid Widget Access Request Policy(WARP) list.");
53     return false;
54   }
55
56   scoped_ptr<WARPInfo> warp_info(new WARPInfo);
57   warp_info->SetWARP(warp_list.release());
58   application->SetManifestData(keys::kAccessKey, warp_info.release());
59
60   return true;
61 }
62
63 std::vector<std::string> WARPHandler::Keys() const {
64   return std::vector<std::string>(1, keys::kAccessKey);
65 }
66
67 }  // namespace application
68 }  // namespace xwalk