3a75474d457081484dcf7ba2981566e3698550f2
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / manifest_handlers / navigation_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/navigation_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 namespace {
16 const char navigation_separator = ' ';
17 }
18
19 NavigationInfo::NavigationInfo(const std::string& allowed_domains) {
20   base::SplitString(allowed_domains, navigation_separator, &allowed_domains_);
21 }
22
23 NavigationInfo::~NavigationInfo() {
24 }
25
26 NavigationHandler::NavigationHandler() {
27 }
28
29 NavigationHandler::~NavigationHandler() {
30 }
31
32 bool NavigationHandler::Parse(scoped_refptr<ApplicationData> application_data,
33                               base::string16* error) {
34   if (!application_data->GetManifest()->HasPath(keys::kAllowNavigationKey))
35     return true;
36   std::string allowed_domains;
37   if (!application_data->GetManifest()->GetString(keys::kAllowNavigationKey,
38                                                   &allowed_domains)) {
39     *error = base::ASCIIToUTF16("Invalid value of allow-navigation.");
40     return false;
41   }
42   if (allowed_domains.empty())
43     return true;
44
45   application_data->SetManifestData(keys::kAllowNavigationKey,
46                                     new NavigationInfo(allowed_domains));
47
48   return true;
49 }
50
51 std::vector<std::string> NavigationHandler::Keys() const {
52   return std::vector<std::string>(1, keys::kAllowNavigationKey);
53 }
54
55 }  // namespace application
56 }  // namespace xwalk