[Easy Unlock] Fix a DCHECK: Load localized string correctly.
[chromium-blink-merge.git] / chrome / common / extensions / extension_file_util.cc
blobefac29ecfe4ae865e894f7501ae21d6fc7770abf
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.
5 #include "chrome/common/extensions/extension_file_util.h"
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"
16 using extensions::Extension;
17 using extensions::ExtensionResource;
18 using extensions::Manifest;
20 namespace {
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));
33 } // namespace
35 namespace extension_file_util {
37 std::set<base::FilePath> GetBrowserImagePaths(const Extension* extension) {
38 std::set<base::FilePath> image_paths;
40 AddPathsFromIconSet(extensions::IconsInfo::GetIcons(extension), &image_paths);
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));
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);
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);
64 return image_paths;
67 } // namespace extension_file_util