Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / extension_file_util.cc
1 // Copyright (c) 2013 The Chromium Authors. 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 "chrome/common/extensions/extension_file_util.h"
6
7 #include "base/files/file_path.h"
8 #include "base/values.h"
9 #include "chrome/common/extensions/api/extension_action/action_info.h"
10 #include "chrome/common/extensions/manifest_handlers/theme_handler.h"
11 #include "extensions/common/constants.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_icon_set.h"
14 #include "extensions/common/manifest_handlers/icons_handler.h"
15
16 using extensions::Extension;
17 using extensions::ExtensionResource;
18 using extensions::Manifest;
19
20 namespace {
21
22 // Add the image paths contained in the |icon_set| to |image_paths|.
23 void AddPathsFromIconSet(const ExtensionIconSet& icon_set,
24                          std::set<base::FilePath>* image_paths) {
25   // TODO(viettrungluu): These |FilePath::FromUTF8Unsafe()| indicate that we're
26   // doing something wrong.
27   for (ExtensionIconSet::IconMap::const_iterator iter = icon_set.map().begin();
28        iter != icon_set.map().end(); ++iter) {
29     image_paths->insert(base::FilePath::FromUTF8Unsafe(iter->second));
30   }
31 }
32
33 }  // namespace
34
35 namespace extension_file_util {
36
37 std::set<base::FilePath> GetBrowserImagePaths(const Extension* extension) {
38   std::set<base::FilePath> image_paths;
39
40   AddPathsFromIconSet(extensions::IconsInfo::GetIcons(extension), &image_paths);
41
42   // Theme images
43   const base::DictionaryValue* theme_images =
44       extensions::ThemeInfo::GetImages(extension);
45   if (theme_images) {
46     for (base::DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd();
47          it.Advance()) {
48       base::FilePath::StringType path;
49       if (it.value().GetAsString(&path))
50         image_paths.insert(base::FilePath(path));
51     }
52   }
53
54   const extensions::ActionInfo* page_action =
55       extensions::ActionInfo::GetPageActionInfo(extension);
56   if (page_action && !page_action->default_icon.empty())
57     AddPathsFromIconSet(page_action->default_icon, &image_paths);
58
59   const extensions::ActionInfo* browser_action =
60       extensions::ActionInfo::GetBrowserActionInfo(extension);
61   if (browser_action && !browser_action->default_icon.empty())
62     AddPathsFromIconSet(browser_action->default_icon, &image_paths);
63
64   return image_paths;
65 }
66
67 }  // namespace extension_file_util