diff options
author | asargent <asargent@chromium.org> | 2015-01-08 10:10:55 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-08 18:11:55 +0000 |
commit | f7f7e3b6b2be0ccc4c0db1dbcd9b85a546716c75 (patch) | |
tree | 2a306306eb779c5683590ab850d3ef9b4ff3e1a5 /extensions | |
parent | b473df2a2b68d52ec3e0b041042d9e54ff86560b (diff) | |
download | chromium_src-f7f7e3b6b2be0ccc4c0db1dbcd9b85a546716c75.zip chromium_src-f7f7e3b6b2be0ccc4c0db1dbcd9b85a546716c75.tar.gz chromium_src-f7f7e3b6b2be0ccc4c0db1dbcd9b85a546716c75.tar.bz2 |
Provide default implementation of ExtensionsClient::GetBrowserImagePaths
Right now ChromeExtensionsClient has the only real implementation of
this function, and it returns the icons for:
1) the extension itself (the top-level icons key in the manifest)
2) page/browser actions
3) theme images
This patch moves to having a default implementation in ExtensionsClient
of GetBrowserImagePaths which returns the paths for (1), leaving
(2) and (3) speficic to ChromeExtensionsClient.
We need to do this to enable the Unpacker class to move from chrome/ to
extensions/, because the unpacker does some validation checks on the
paths returned by GetBrowserImagePaths and has tests for that
validation we want to move out of chrome/ also.
BUG=447014
Review URL: https://codereview.chromium.org/840813005
Cr-Commit-Position: refs/heads/master@{#310537}
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/common/extension_icon_set.cc | 7 | ||||
-rw-r--r-- | extensions/common/extension_icon_set.h | 11 | ||||
-rw-r--r-- | extensions/common/extensions_client.cc | 12 | ||||
-rw-r--r-- | extensions/common/extensions_client.h | 7 | ||||
-rw-r--r-- | extensions/shell/common/shell_extensions_client.cc | 5 | ||||
-rw-r--r-- | extensions/shell/common/shell_extensions_client.h | 2 | ||||
-rw-r--r-- | extensions/test/test_extensions_client.cc | 5 | ||||
-rw-r--r-- | extensions/test/test_extensions_client.h | 2 |
8 files changed, 35 insertions, 16 deletions
diff --git a/extensions/common/extension_icon_set.cc b/extensions/common/extension_icon_set.cc index 65ccff0..221f32f 100644 --- a/extensions/common/extension_icon_set.cc +++ b/extensions/common/extension_icon_set.cc @@ -4,6 +4,7 @@ #include "extensions/common/extension_icon_set.h" +#include "base/files/file_path.h" #include "base/logging.h" #include "base/strings/string_util.h" @@ -69,3 +70,9 @@ int ExtensionIconSet::GetIconSizeFromPath(const std::string& path) const { return 0; } + +void ExtensionIconSet::GetPaths(std::set<base::FilePath>* paths) const { + CHECK(paths); + for (auto iter : map()) + paths->insert(base::FilePath::FromUTF8Unsafe(iter.second)); +} diff --git a/extensions/common/extension_icon_set.h b/extensions/common/extension_icon_set.h index 2791db2..e491b72 100644 --- a/extensions/common/extension_icon_set.h +++ b/extensions/common/extension_icon_set.h @@ -6,8 +6,13 @@ #define EXTENSIONS_COMMON_EXTENSION_ICON_SET_H_ #include <map> +#include <set> #include <string> +namespace base { +class FilePath; +} + // Represents the set of icons for an extension. class ExtensionIconSet { public: @@ -45,6 +50,12 @@ class ExtensionIconSet { // Returns icon size if the set contains the specified path or 0 if not found. int GetIconSizeFromPath(const std::string& path) const; + // Add the paths of all icons in this set into |paths|, handling the + // conversion of (string) -> (base::FilePath). Note that these paths are not + // validated in any way, so they may be invalid paths or reference + // nonexistent files. + void GetPaths(std::set<base::FilePath>* paths) const; + private: IconMap map_; }; diff --git a/extensions/common/extensions_client.cc b/extensions/common/extensions_client.cc index 89795b8..89d420b 100644 --- a/extensions/common/extensions_client.cc +++ b/extensions/common/extensions_client.cc @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "extensions/common/extensions_client.h" + #include "base/basictypes.h" #include "base/logging.h" -#include "extensions/common/extensions_client.h" +#include "extensions/common/extension_icon_set.h" +#include "extensions/common/manifest_handlers/icons_handler.h" namespace extensions { @@ -19,6 +22,13 @@ ExtensionsClient* ExtensionsClient::Get() { return g_client; } +std::set<base::FilePath> ExtensionsClient::GetBrowserImagePaths( + const Extension* extension) { + std::set<base::FilePath> paths; + extensions::IconsInfo::GetIcons(extension).GetPaths(&paths); + return paths; +} + void ExtensionsClient::Set(ExtensionsClient* client) { // This can happen in unit tests, where the utility thread runs in-process. if (g_client) diff --git a/extensions/common/extensions_client.h b/extensions/common/extensions_client.h index bfe67ca..9a9bedf 100644 --- a/extensions/common/extensions_client.h +++ b/extensions/common/extensions_client.h @@ -127,8 +127,13 @@ class ExtensionsClient { // or WebUI, such as icons or theme images. This set of paths is used by the // extension unpacker to determine which assets should be transcoded safely // within the utility sandbox. + // + // The default implementation returns the images used as icons for the + // extension itself, so implementors of ExtensionsClient overriding this may + // want to call the base class version and then add additional paths to that + // result. virtual std::set<base::FilePath> GetBrowserImagePaths( - const Extension* extension) = 0; + const Extension* extension); // Return the extensions client. static ExtensionsClient* Get(); diff --git a/extensions/shell/common/shell_extensions_client.cc b/extensions/shell/common/shell_extensions_client.cc index d20a608cd..611ff99 100644 --- a/extensions/shell/common/shell_extensions_client.cc +++ b/extensions/shell/common/shell_extensions_client.cc @@ -222,9 +222,4 @@ bool ShellExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const { return true; } -std::set<base::FilePath> ShellExtensionsClient::GetBrowserImagePaths( - const Extension* extension) { - return std::set<base::FilePath>(); -} - } // namespace extensions diff --git a/extensions/shell/common/shell_extensions_client.h b/extensions/shell/common/shell_extensions_client.h index 3e5e9bb..0e8e519 100644 --- a/extensions/shell/common/shell_extensions_client.h +++ b/extensions/shell/common/shell_extensions_client.h @@ -47,8 +47,6 @@ class ShellExtensionsClient : public ExtensionsClient { std::string GetWebstoreBaseURL() const override; std::string GetWebstoreUpdateURL() const override; bool IsBlacklistUpdateURL(const GURL& url) const override; - std::set<base::FilePath> GetBrowserImagePaths( - const Extension* extension) override; private: const ExtensionsAPIPermissions extensions_api_permissions_; diff --git a/extensions/test/test_extensions_client.cc b/extensions/test/test_extensions_client.cc index 77f8442..bc3fd49 100644 --- a/extensions/test/test_extensions_client.cc +++ b/extensions/test/test_extensions_client.cc @@ -167,9 +167,4 @@ bool TestExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const { return true; } -std::set<base::FilePath> TestExtensionsClient::GetBrowserImagePaths( - const Extension* extension) { - return std::set<base::FilePath>(); -} - } // namespace extensions diff --git a/extensions/test/test_extensions_client.h b/extensions/test/test_extensions_client.h index 05ebb7f..bc8fe7c 100644 --- a/extensions/test/test_extensions_client.h +++ b/extensions/test/test_extensions_client.h @@ -44,8 +44,6 @@ class TestExtensionsClient : public ExtensionsClient { std::string GetWebstoreBaseURL() const override; std::string GetWebstoreUpdateURL() const override; bool IsBlacklistUpdateURL(const GURL& url) const override; - std::set<base::FilePath> GetBrowserImagePaths( - const Extension* extension) override; // A whitelist of extensions that can script anywhere. Do not add to this // list (except in tests) without consulting the Extensions team first. |