0c8abc5f42e96ec0637c6f79f2decbf6b63a9ead
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / manifest_handlers / tizen_splash_screen_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_splash_screen_handler.h"
6
7 #include <map>
8 #include <utility>
9
10 #include "base/file_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 TizenSplashScreenInfo::TizenSplashScreenInfo() {}
21 TizenSplashScreenInfo::~TizenSplashScreenInfo() {}
22
23 TizenSplashScreenHandler::TizenSplashScreenHandler() {}
24
25 TizenSplashScreenHandler::~TizenSplashScreenHandler() {}
26
27 bool TizenSplashScreenHandler::Parse(scoped_refptr<ApplicationData> application,
28                                      base::string16* error) {
29   scoped_ptr<TizenSplashScreenInfo> ss_info(new TizenSplashScreenInfo);
30   const Manifest* manifest = application->GetManifest();
31   DCHECK(manifest);
32
33   base::Value* splash_screen = NULL;
34   manifest->Get(keys::kTizenSplashScreenKey, &splash_screen);
35   if (splash_screen && splash_screen->IsType(base::Value::TYPE_DICTIONARY)) {
36     base::DictionaryValue* ss_dict = NULL;
37     splash_screen->GetAsDictionary(&ss_dict);
38     std::string src;
39     ss_dict->GetString(keys::kTizenSplashScreenSrcKey, &src);
40     ss_info->set_src(src);
41   }
42   application->SetManifestData(keys::kTizenSplashScreenKey, ss_info.release());
43   return true;
44 }
45
46 bool TizenSplashScreenHandler::Validate(
47     scoped_refptr<const ApplicationData> application,
48     std::string* error) const {
49   const Manifest* manifest = application->GetManifest();
50   DCHECK(manifest);
51   base::Value* splash_screen = NULL;
52   manifest->Get(keys::kTizenSplashScreenKey, &splash_screen);
53   if (!splash_screen || !splash_screen->IsType(base::Value::TYPE_DICTIONARY)) {
54     *error = std::string("The splash-screen attribute is not set correctly.");
55     return false;
56   }
57   base::DictionaryValue* ss_dict = NULL;
58   splash_screen->GetAsDictionary(&ss_dict);
59   std::string ss_src;
60   ss_dict->GetString(keys::kTizenSplashScreenSrcKey, &ss_src);
61   base::FilePath path = application->Path().Append(FILE_PATH_LITERAL(ss_src));
62   if (!base::PathExists(path)) {
63     *error = std::string("The splash screen image does not exist");
64     return false;
65   }
66   return true;
67 }
68
69 std::vector<std::string> TizenSplashScreenHandler::Keys() const {
70   return std::vector<std::string>(1, keys::kTizenSplashScreenKey);
71 }
72
73 }  // namespace application
74 }  // namespace xwalk