| Index: chrome/browser/ui/views/aura/app_list/extension_item_model.cc
|
| diff --git a/chrome/browser/ui/views/aura/app_list/extension_item_model.cc b/chrome/browser/ui/views/aura/app_list/extension_item_model.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d7bdb84ad8d605c96917427e874160bfbd70dfae
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/aura/app_list/extension_item_model.cc
|
| @@ -0,0 +1,123 @@
|
| +// Copyright (c) 2011 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.
|
| +
|
| +#include "chrome/browser/ui/views/aura/app_list/extension_item_model.h"
|
| +
|
| +#include "chrome/browser/event_disposition.h"
|
| +#include "chrome/browser/extensions/extension_prefs.h"
|
| +#include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/common/extensions/extension.h"
|
| +#include "chrome/common/extensions/extension_icon_set.h"
|
| +#include "chrome/common/extensions/extension_resource.h"
|
| +#include "grit/component_extension_resources_map.h"
|
| +#include "grit/theme_resources.h"
|
| +#include "ui/aura_shell/app_list/tile_view.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +#include "ui/gfx/codec/png_codec.h"
|
| +#include "ui/gfx/image/image.h"
|
| +#include "third_party/skia/include/core/SkBitmap.h"
|
| +
|
| +ExtensionItemModel::ExtensionItemModel(ExtensionService* service,
|
| + const Extension* extension)
|
| + : aura_shell::AppListItemModel(SkBitmap(), extension->name()),
|
| + service_(service),
|
| + extension_(extension) {
|
| + LoadImage();
|
| +}
|
| +
|
| +void ExtensionItemModel::LoadImage() {
|
| + ExtensionResource icon = extension_->GetIconResource(
|
| + aura_shell::TileView::kIconSize,
|
| + ExtensionIconSet::MATCH_BIGGER);
|
| + if (icon.relative_path().empty()) {
|
| + LoadDefaultImage();
|
| + return;
|
| + }
|
| +
|
| + if (extension_->location() == Extension::COMPONENT) {
|
| + FilePath directory_path = extension_->path();
|
| + FilePath relative_path = directory_path.BaseName().Append(
|
| + icon.relative_path());
|
| + for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) {
|
| + FilePath bm_resource_path =
|
| + FilePath().AppendASCII(kComponentExtensionResources[i].name);
|
| +#if defined(OS_WIN)
|
| + bm_resource_path = bm_resource_path.NormalizeWindowsPathSeparators();
|
| +#endif
|
| + if (relative_path == bm_resource_path) {
|
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + int resource = kComponentExtensionResources[i].value;
|
| +
|
| + base::StringPiece contents = rb.GetRawDataResource(resource);
|
| + SkBitmap icon;
|
| + if (gfx::PNGCodec::Decode(
|
| + reinterpret_cast<const unsigned char*>(contents.data()),
|
| + contents.size(), &icon)) {
|
| + SetIcon(icon);
|
| + return;
|
| + } else {
|
| + NOTREACHED() << "Unable to decode image resource " << resource;
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + tracker_.reset(new ImageLoadingTracker(this));
|
| + tracker_->LoadImage(extension_,
|
| + icon,
|
| + gfx::Size(aura_shell::TileView::kIconSize,
|
| + aura_shell::TileView::kIconSize),
|
| + ImageLoadingTracker::DONT_CACHE);
|
| +}
|
| +
|
| +void ExtensionItemModel::LoadDefaultImage() {
|
| + int resource = extension_->id() == extension_misc::kWebStoreAppId ?
|
| + IDR_WEBSTORE_ICON : IDR_APP_DEFAULT_ICON;
|
| +
|
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + SetIcon(*rb.GetImageNamed(resource).ToSkBitmap());
|
| +}
|
| +
|
| +void ExtensionItemModel::OnImageLoaded(SkBitmap* image,
|
| + const ExtensionResource& resource,
|
| + int tracker_index) {
|
| + if (image && !image->empty())
|
| + SetIcon(*image);
|
| + else
|
| + LoadDefaultImage();
|
| +}
|
| +
|
| +void ExtensionItemModel::Activate(int event_flags) {
|
| + Profile* profile = service_->profile();
|
| +
|
| + WindowOpenDisposition disposition =
|
| + browser::DispositionFromEventFlags(event_flags);
|
| +
|
| + GURL url;
|
| + if (extension_->id() == extension_misc::kWebStoreAppId)
|
| + url = extension_->GetFullLaunchURL();
|
| +
|
| + if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) {
|
| + // Opens in a tab.
|
| + Browser::OpenApplication(
|
| + profile, extension_, extension_misc::LAUNCH_TAB, url, disposition);
|
| + } else if (disposition == NEW_WINDOW) {
|
| + // Force a new window open.
|
| + Browser::OpenApplication(
|
| + profile, extension_, extension_misc::LAUNCH_WINDOW, url,
|
| + disposition);
|
| + } else {
|
| + // Look at preference to find the right launch container. If no preference
|
| + // is set, launch as a regular tab.
|
| + extension_misc::LaunchContainer launch_container =
|
| + service_->extension_prefs()->GetLaunchContainer(
|
| + extension_, ExtensionPrefs::LAUNCH_REGULAR);
|
| +
|
| + Browser::OpenApplication(
|
| + profile, extension_, launch_container, GURL(url),
|
| + NEW_FOREGROUND_TAB);
|
| + }
|
| +}
|
|
|