Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2362)

Unified Diff: chrome/common/extensions/extension.cc

Issue 11786003: Move Icons out of Extension class (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: License year update Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index b50cc5395f49350207256008d2b5a445a25621cf..99b6269d76dcaa5bc549264153a17ad1c28aad3d 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,7 +10,6 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/file_path.h"
-#include "base/file_util.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
@@ -29,9 +28,9 @@
// TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and
// SystemIndicator have been moved out of Extension.
#include "chrome/common/extensions/api/extension_action/action_info.h"
+#include "chrome/common/extensions/api/icons/icons_handler.h"
#include "chrome/common/extensions/csp_validator.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
-#include "chrome/common/extensions/extension_resource.h"
#include "chrome/common/extensions/feature_switch.h"
#include "chrome/common/extensions/features/base_feature_provider.h"
#include "chrome/common/extensions/features/feature.h"
@@ -51,8 +50,6 @@
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "webkit/glue/image_decoder.h"
#include "webkit/glue/web_intent_service_data.h"
#if defined(OS_WIN)
@@ -297,9 +294,6 @@ const size_t Extension::kIdSize = 16;
const char Extension::kMimeType[] = "application/x-chrome-extension";
-const int Extension::kPageActionIconMaxSize = 19;
-const int Extension::kBrowserActionIconMaxSize = 19;
-
const int Extension::kValidWebExtentSchemes =
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS;
@@ -611,65 +605,6 @@ bool Extension::FormatPEMForFileOutput(const std::string& input,
}
// static
-void Extension::DecodeIcon(const Extension* extension,
- int preferred_icon_size,
- ExtensionIconSet::MatchType match_type,
- scoped_ptr<SkBitmap>* result) {
- std::string path = extension->icons().Get(preferred_icon_size, match_type);
- int size = extension->icons().GetIconSizeFromPath(path);
- ExtensionResource icon_resource = extension->GetResource(path);
- DecodeIconFromPath(icon_resource.GetFilePath(), size, result);
-}
-
-// static
-void Extension::DecodeIcon(const Extension* extension,
- int icon_size,
- scoped_ptr<SkBitmap>* result) {
- DecodeIcon(extension, icon_size, ExtensionIconSet::MATCH_EXACTLY, result);
-}
-
-// static
-void Extension::DecodeIconFromPath(const FilePath& icon_path,
- int icon_size,
- scoped_ptr<SkBitmap>* result) {
- if (icon_path.empty())
- return;
-
- std::string file_contents;
- if (!file_util::ReadFileToString(icon_path, &file_contents)) {
- DLOG(ERROR) << "Could not read icon file: " << icon_path.LossyDisplayName();
- return;
- }
-
- // Decode the image using WebKit's image decoder.
- const unsigned char* data =
- reinterpret_cast<const unsigned char*>(file_contents.data());
- webkit_glue::ImageDecoder decoder;
- scoped_ptr<SkBitmap> decoded(new SkBitmap());
- *decoded = decoder.Decode(data, file_contents.length());
- if (decoded->empty()) {
- DLOG(ERROR) << "Could not decode icon file: "
- << icon_path.LossyDisplayName();
- return;
- }
-
- if (decoded->width() != icon_size || decoded->height() != icon_size) {
- DLOG(ERROR) << "Icon file has unexpected size: "
- << base::IntToString(decoded->width()) << "x"
- << base::IntToString(decoded->height());
- return;
- }
-
- result->swap(decoded);
-}
-
-// static
-const gfx::ImageSkia& Extension::GetDefaultIcon(bool is_app) {
- int id = is_app ? IDR_APP_DEFAULT_ICON : IDR_EXTENSION_DEFAULT_ICON;
- return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id);
-}
-
-// static
GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) {
return GURL(std::string(extensions::kExtensionScheme) +
content::kStandardSchemeSeparator + extension_id + "/");
@@ -921,8 +856,9 @@ std::set<FilePath> Extension::GetBrowserImages() const {
// indicate that we're doing something wrong.
// Extension icons.
- for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin();
- iter != icons().map().end(); ++iter) {
+ for (ExtensionIconSet::IconMap::const_iterator iter =
+ IconsInfo::GetIcons(this).map().begin();
+ iter != IconsInfo::GetIcons(this).map().end(); ++iter) {
image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second)));
}
@@ -959,18 +895,6 @@ std::set<FilePath> Extension::GetBrowserImages() const {
return image_paths;
}
-ExtensionResource Extension::GetIconResource(
- int size, ExtensionIconSet::MatchType match_type) const {
- std::string path = icons().Get(size, match_type);
- return path.empty() ? ExtensionResource() : GetResource(path);
-}
-
-GURL Extension::GetIconURL(int size,
- ExtensionIconSet::MatchType match_type) const {
- std::string path = icons().Get(size, match_type);
- return path.empty() ? GURL() : GetResourceURL(path);
-}
-
GURL Extension::GetFullLaunchURL() const {
return launch_local_path().empty() ? GURL(launch_web_url()) :
url().Resolve(launch_local_path());
@@ -1899,7 +1823,6 @@ bool Extension::LoadSharedFeatures(
if (!LoadDescription(error) ||
!LoadHomepageURL(error) ||
!LoadUpdateURL(error) ||
- !LoadIcons(error) ||
!LoadCommands(error) ||
!LoadPlugins(error) ||
!LoadNaClModules(error) ||
@@ -1995,23 +1918,6 @@ bool Extension::LoadUpdateURL(string16* error) {
return true;
}
-bool Extension::LoadIcons(string16* error) {
- if (!manifest_->HasKey(keys::kIcons))
- return true;
- DictionaryValue* icons_value = NULL;
- if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) {
- *error = ASCIIToUTF16(errors::kInvalidIcons);
- return false;
- }
-
- return manifest_handler_helpers::LoadIconsFromDictionary(
- icons_value,
- extension_misc::kExtensionIconSizes,
- extension_misc::kNumExtensionIconSizes,
- &icons_,
- error);
-}
-
bool Extension::LoadCommands(string16* error) {
if (manifest_->HasKey(keys::kCommands)) {
DictionaryValue* commands = NULL;

Powered by Google App Engine
This is Rietveld 408576698