Commit f6816c0c authored by tfarina@chromium.org's avatar tfarina@chromium.org

launcher: Remove old files and update DEPS whitelist.

BUG=125846
TBR=ben@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10855094

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150982 0039d316-1c4b-4281-b951-d872f2087c98
parent 5dd19912
...@@ -3,9 +3,6 @@ include_rules = [ ...@@ -3,9 +3,6 @@ include_rules = [
# TODO(tfarina): Remove all these. crbug.com/125846. # TODO(tfarina): Remove all these. crbug.com/125846.
# DO NOT ADD ANY MORE ITEMS TO THE LIST BELOW! # DO NOT ADD ANY MORE ITEMS TO THE LIST BELOW!
"!chrome/browser/ui/views/ash/chrome_shell_delegate.h", "!chrome/browser/ui/views/ash/chrome_shell_delegate.h",
"!chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller.h",
"!chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h",
"!chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h",
"!chrome/browser/ui/views/ash/panel_view_aura.h", "!chrome/browser/ui/views/ash/panel_view_aura.h",
"!chrome/browser/ui/views/find_bar_host.h", "!chrome/browser/ui/views/find_bar_host.h",
"!chrome/browser/ui/views/frame/browser_frame.h", "!chrome/browser/ui/views/frame/browser_frame.h",
......
// Copyright (c) 2012 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/ash/launcher/browser_launcher_item_controller.h"
#include "ash/launcher/launcher.h"
#include "ash/launcher/launcher_model.h"
#include "ash/shell.h"
#include "ash/wm/window_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/web_applications/web_app.h"
#include "content/public/browser/web_contents.h"
#include "grit/ui_resources.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/resource/resource_bundle.h"
using extensions::Extension;
BrowserLauncherItemController::BrowserLauncherItemController(
aura::Window* window,
TabStripModel* tab_model,
ChromeLauncherController* launcher_controller,
Type type,
const std::string& app_id)
: window_(window),
tab_model_(tab_model),
launcher_controller_(launcher_controller),
type_(type),
app_id_(app_id),
is_incognito_(tab_model->profile()->GetOriginalProfile() !=
tab_model->profile() && !Profile::IsGuestSession()),
item_id_(-1) {
window_->AddObserver(this);
}
BrowserLauncherItemController::~BrowserLauncherItemController() {
tab_model_->RemoveObserver(this);
window_->RemoveObserver(this);
if (item_id_ != -1)
launcher_controller_->LauncherItemClosed(item_id_);
}
void BrowserLauncherItemController::Init() {
tab_model_->AddObserver(this);
ash::LauncherItemStatus app_status =
ash::wm::IsActiveWindow(window_) ?
ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
if (type_ != TYPE_TABBED) {
item_id_ = launcher_controller_->CreateAppLauncherItem(
this, app_id_, app_status);
} else {
item_id_ = launcher_controller_->CreateTabbedLauncherItem(
this,
is_incognito_ ? ChromeLauncherController::STATE_INCOGNITO :
ChromeLauncherController::STATE_NOT_INCOGNITO,
app_status);
}
// In testing scenarios we can get tab strips with no active contents.
if (tab_model_->GetActiveTabContents())
UpdateLauncher(tab_model_->GetActiveTabContents());
}
// static
BrowserLauncherItemController* BrowserLauncherItemController::Create(
Browser* browser) {
// Under testing this can be called before the controller is created.
if (!ChromeLauncherController::instance())
return NULL;
Type type;
std::string app_id;
if (browser->type() == Browser::TYPE_TABBED ||
browser->type() == Browser::TYPE_POPUP) {
type = TYPE_TABBED;
} else if (browser->is_app()) {
if (browser->is_type_panel()) {
if (browser->app_type() == Browser::APP_TYPE_CHILD)
type = TYPE_EXTENSION_PANEL;
else
type = TYPE_APP_PANEL;
} else {
type = TYPE_TABBED;
}
app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name());
} else {
return NULL;
}
BrowserLauncherItemController* icon_updater =
new BrowserLauncherItemController(
browser->window()->GetNativeWindow(), browser->tab_strip_model(),
ChromeLauncherController::instance(), type, app_id);
icon_updater->Init();
return icon_updater;
}
void BrowserLauncherItemController::BrowserActivationStateChanged() {
if (tab_model_->GetActiveTabContents())
UpdateAppState(tab_model_->GetActiveTabContents());
UpdateItemStatus();
}
void BrowserLauncherItemController::ActiveTabChanged(
TabContents* old_contents,
TabContents* new_contents,
int index,
bool user_gesture) {
// Update immediately on a tab change.
if (old_contents)
UpdateAppState(old_contents);
UpdateAppState(new_contents);
UpdateLauncher(new_contents);
}
void BrowserLauncherItemController::TabInsertedAt(TabContents* contents,
int index,
bool foreground) {
UpdateAppState(contents);
}
void BrowserLauncherItemController::TabDetachedAt(TabContents* contents,
int index) {
launcher_controller_->UpdateAppState(
contents, ChromeLauncherController::APP_STATE_REMOVED);
}
void BrowserLauncherItemController::TabChangedAt(
TabContents* tab,
int index,
TabStripModelObserver::TabChangeType change_type) {
UpdateAppState(tab);
if (index != tab_model_->active_index() ||
!(change_type != TabStripModelObserver::LOADING_ONLY &&
change_type != TabStripModelObserver::TITLE_NOT_LOADING)) {
return;
}
if (tab->favicon_tab_helper()->FaviconIsValid() ||
!tab->favicon_tab_helper()->ShouldDisplayFavicon()) {
// We have the favicon, update immediately.
UpdateLauncher(tab);
} else {
int item_index = launcher_model()->ItemIndexByID(item_id_);
if (item_index == -1)
return;
ash::LauncherItem item = launcher_model()->items()[item_index];
item.image = SkBitmap();
launcher_model()->Set(item_index, item);
}
}
void BrowserLauncherItemController::TabReplacedAt(
TabStripModel* tab_strip_model,
TabContents* old_contents,
TabContents* new_contents,
int index) {
launcher_controller_->UpdateAppState(
old_contents, ChromeLauncherController::APP_STATE_REMOVED);
UpdateAppState(new_contents);
}
void BrowserLauncherItemController::FaviconUpdated() {
UpdateLauncher(tab_model_->GetActiveTabContents());
}
void BrowserLauncherItemController::OnWindowPropertyChanged(
aura::Window* window,
const void* key,
intptr_t old) {
if (key == aura::client::kDrawAttentionKey)
UpdateItemStatus();
}
void BrowserLauncherItemController::UpdateItemStatus() {
ash::LauncherItemStatus status;
if (ash::wm::IsActiveWindow(window_)) {
// Clear attention state if active.
if (window_->GetProperty(aura::client::kDrawAttentionKey))
window_->SetProperty(aura::client::kDrawAttentionKey, false);
status = ash::STATUS_ACTIVE;
} else if (window_->GetProperty(aura::client::kDrawAttentionKey)) {
status = ash::STATUS_ATTENTION;
} else {
status = ash::STATUS_RUNNING;
}
launcher_controller_->SetItemStatus(item_id_, status);
}
void BrowserLauncherItemController::UpdateLauncher(TabContents* tab) {
if (type_ == TYPE_APP_PANEL)
return; // Maintained entirely by ChromeLauncherController.
if (!tab)
return; // Assume the window is going to be closed if there are no tabs.
int item_index = launcher_model()->ItemIndexByID(item_id_);
if (item_index == -1)
return;
ash::LauncherItem item = launcher_model()->items()[item_index];
if (type_ == TYPE_EXTENSION_PANEL) {
if (!favicon_loader_.get() ||
favicon_loader_->web_contents() != tab->web_contents()) {
favicon_loader_.reset(
new LauncherFaviconLoader(this, tab->web_contents()));
}
// Update the icon for extension panels.
SkBitmap new_image = favicon_loader_->GetFavicon();
if (new_image.empty() && tab->extension_tab_helper()->GetExtensionAppIcon())
new_image = *tab->extension_tab_helper()->GetExtensionAppIcon();
// Only update the icon if we have a new image, or none has been set yet.
// This avoids flickering to an empty image when a pinned app is opened.
if (!new_image.empty())
item.image = new_image;
else if (item.image.empty())
item.image = extensions::Extension::GetDefaultIcon(true);
} else {
DCHECK_EQ(TYPE_TABBED, type_);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (tab->favicon_tab_helper()->ShouldDisplayFavicon()) {
item.image = tab->favicon_tab_helper()->GetFavicon().AsBitmap();
if (item.image.empty()) {
item.image = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
}
} else {
item.image = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
}
}
launcher_model()->Set(item_index, item);
}
void BrowserLauncherItemController::UpdateAppState(TabContents* tab) {
ChromeLauncherController::AppState app_state;
if (tab_model_->GetIndexOfTabContents(tab) == TabStripModel::kNoTab) {
app_state = ChromeLauncherController::APP_STATE_REMOVED;
} else if (tab_model_->GetActiveTabContents() == tab) {
if (ash::wm::IsActiveWindow(window_))
app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE;
else
app_state = ChromeLauncherController::APP_STATE_ACTIVE;
} else {
app_state = ChromeLauncherController::APP_STATE_INACTIVE;
}
launcher_controller_->UpdateAppState(tab, app_state);
}
ash::LauncherModel* BrowserLauncherItemController::launcher_model() {
return launcher_controller_->model();
}
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_
#include <string>
#include "ash/launcher/launcher_types.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h"
#include "ui/aura/window_observer.h"
class Browser;
class ChromeLauncherController;
class LauncherFaviconLoader;
class TabContents;
namespace ash {
class LauncherModel;
}
namespace aura {
class Window;
}
// BrowserLauncherItemController is responsible for keeping the launcher
// representation of a window up to date as the active tab changes.
class BrowserLauncherItemController : public TabStripModelObserver,
public LauncherFaviconLoader::Delegate,
public aura::WindowObserver {
public:
// This API is to be used as part of testing only.
class TestApi {
public:
explicit TestApi(BrowserLauncherItemController* controller)
: controller_(controller) {}
~TestApi() {}
// Returns the launcher id for the browser window.
ash::LauncherID item_id() const { return controller_->item_id_; }
private:
BrowserLauncherItemController* controller_;
};
enum Type {
TYPE_APP_PANEL,
TYPE_EXTENSION_PANEL,
TYPE_TABBED
};
BrowserLauncherItemController(aura::Window* window,
TabStripModel* tab_model,
ChromeLauncherController* launcher_controller,
Type type,
const std::string& app_id);
virtual ~BrowserLauncherItemController();
// Sets up this BrowserLauncherItemController.
void Init();
// Creates and returns a new BrowserLauncherItemController for |browser|. This
// returns NULL if a BrowserLauncherItemController is not needed for the
// specified browser.
static BrowserLauncherItemController* Create(Browser* browser);
aura::Window* window() { return window_; }
TabStripModel* tab_model() { return tab_model_; }
Type type() const { return type_; }
LauncherFaviconLoader* favicon_loader() const {
return favicon_loader_.get();
}
// Call to indicate that the window the tabcontents are in has changed its
// activation state.
void BrowserActivationStateChanged();
// TabStripModel overrides:
virtual void ActiveTabChanged(TabContents* old_contents,
TabContents* new_contents,
int index,
bool user_gesture) OVERRIDE;
virtual void TabInsertedAt(TabContents* contents,
int index,
bool foreground) OVERRIDE;
virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE;
virtual void TabChangedAt(
TabContents* tab,
int index,
TabStripModelObserver::TabChangeType change_type) OVERRIDE;
virtual void TabReplacedAt(TabStripModel* tab_strip_model,
TabContents* old_contents,
TabContents* new_contents,
int index) OVERRIDE;
// LauncherFaviconLoader::Delegate overrides:
virtual void FaviconUpdated() OVERRIDE;
// aura::WindowObserver overrides:
virtual void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) OVERRIDE;
private:
FRIEND_TEST_ALL_PREFIXES(BrowserLauncherItemControllerTest, PanelItem);
// Used to identify what an update corresponds to.
enum UpdateType {
UPDATE_TAB_REMOVED,
UPDATE_TAB_CHANGED,
UPDATE_TAB_INSERTED,
};
// Updates the launcher item status base on the activation and attention
// state of the window.
void UpdateItemStatus();
// Updates the launcher from |tab|.
void UpdateLauncher(TabContents* tab);
void UpdateAppState(TabContents* tab);
ash::LauncherModel* launcher_model();
// Browser window we're in.
aura::Window* window_;
TabStripModel* tab_model_;
ChromeLauncherController* launcher_controller_;
// Whether this corresponds to an app or tabbed browser.
const Type type_;
const std::string app_id_;
// Whether this is associated with an incognito profile.
const bool is_incognito_;
// ID of the item.
ash::LauncherID item_id_;
// Loads launcher sized favicons for panels.
scoped_ptr<LauncherFaviconLoader> favicon_loader_;
DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemController);
};
#endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_
// Copyright (c) 2012 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/ash/launcher/launcher_app_icon_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/extensions/extension.h"
namespace {
const extensions::Extension* GetExtensionByID(Profile* profile,
const std::string& id) {
ExtensionService* service = profile->GetExtensionService();
if (!service)
return NULL;
return service->extensions()->GetByID(id);
}
} // namespace
LauncherAppIconLoader::LauncherAppIconLoader(
Profile* profile,
ChromeLauncherController* controller)
: profile_(profile),
host_(controller) {
}
LauncherAppIconLoader::~LauncherAppIconLoader() {
}
void LauncherAppIconLoader::FetchImage(const std::string& id) {
for (ImageLoaderIDToExtensionIDMap::const_iterator i = map_.begin();
i != map_.end(); ++i) {
if (i->second == id)
return; // Already loading the image.
}
const extensions::Extension* extension = GetExtensionByID(profile_, id);
if (!extension)
return;
if (!image_loader_.get())
image_loader_.reset(new ImageLoadingTracker(this));
map_[image_loader_->next_id()] = id;
image_loader_->LoadImage(
extension,
extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALL,
ExtensionIconSet::MATCH_BIGGER),
gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALL,
ExtensionIconSet::EXTENSION_ICON_SMALL),
ImageLoadingTracker::CACHE);
}
void LauncherAppIconLoader::OnImageLoaded(const gfx::Image& image,
const std::string& extension_id,
int index) {
ImageLoaderIDToExtensionIDMap::iterator i = map_.find(index);
if (i == map_.end())
return; // The tab has since been removed, do nothing.
std::string id = i->second;
map_.erase(i);
if (image.IsEmpty())
host_->SetAppImage(id, extensions::Extension::GetDefaultIcon(true));
else
host_->SetAppImage(id, *image.ToImageSkia());
}
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_APP_ICON_LOADER_H_
#define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_APP_ICON_LOADER_H_
#include <map>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
#include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
class Profile;
namespace extensions {
class Extension;
}
// Default implementation of LauncherUpdater::AppIconLoader that interacts
// with the ExtensionService and ImageLoadingTracker to load images.
class LauncherAppIconLoader : public ChromeLauncherController::AppIconLoader,
public ImageLoadingTracker::Observer {
public:
LauncherAppIconLoader(Profile* profile, ChromeLauncherController* host);
virtual ~LauncherAppIconLoader();
// AppIconLoader:
virtual void FetchImage(const std::string& id) OVERRIDE;
// ImageLoadingTracker::Observer:
virtual void OnImageLoaded(const gfx::Image& image,
const std::string& extension_id,
int index) OVERRIDE;
private:
typedef std::map<int, std::string> ImageLoaderIDToExtensionIDMap;
Profile* profile_;
// ChromeLauncherController we're associated with (and owned by).
ChromeLauncherController* host_;
// Used to load images.
scoped_ptr<ImageLoadingTracker> image_loader_;
// Maps from id from the ImageLoadingTracker to the extension id.
ImageLoaderIDToExtensionIDMap map_;
DISALLOW_COPY_AND_ASSIGN(LauncherAppIconLoader);
};
#endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_APP_ICON_LOADER_H_
// Copyright (c) 2012 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/ash/launcher/launcher_app_tab_helper.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/web_contents.h"
namespace {
const extensions::Extension* GetExtensionForTab(Profile* profile,
TabContents* tab) {
ExtensionService* extension_service = profile->GetExtensionService();
if (!extension_service)
return NULL;
return extension_service->GetInstalledApp(tab->web_contents()->GetURL());
}
const extensions::Extension* GetExtensionByID(Profile* profile,
const std::string& id) {
ExtensionService* service = profile->GetExtensionService();
if (!service)
return NULL;
return service->extensions()->GetByID(id);
}
} // namespace
LauncherAppTabHelper::LauncherAppTabHelper(Profile* profile)
: profile_(profile) {
}
LauncherAppTabHelper::~LauncherAppTabHelper() {
}
std::string LauncherAppTabHelper::GetAppID(TabContents* tab) {
const extensions::Extension* extension = GetExtensionForTab(profile_, tab);
return extension ? extension->id() : std::string();
}
bool LauncherAppTabHelper::IsValidID(const std::string& id) {
return GetExtensionByID(profile_, id) != NULL;
}
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_APP_TAB_HELPER_H_
#define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_APP_TAB_HELPER_H_
#include <map>
#include <string>
#include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
class Profile;
class TabContents;
// Default implementation of LauncherUpdater::AppTabHelper that interacts
// with ExtensionService.
class LauncherAppTabHelper : public ChromeLauncherController::AppTabHelper {
public:
explicit LauncherAppTabHelper(Profile* profile);
virtual ~LauncherAppTabHelper();
// AppTabHelper:
virtual std::string GetAppID(TabContents* tab) OVERRIDE;
virtual bool IsValidID(const std::string& id) OVERRIDE;
private:
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(LauncherAppTabHelper);
};
#endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_APP_TAB_HELPER_H_
// Copyright (c) 2012 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/ash/launcher/launcher_context_menu.h"
#include "ash/launcher/launcher_context_menu.h"
#include "ash/shell.h"
#include "base/command_line.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
#include "chrome/common/chrome_switches.h"
#include "grit/ash_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
const ash::LauncherItem* item)
: ui::SimpleMenuModel(NULL),
controller_(controller),
item_(item ? *item : ash::LauncherItem()) {
set_delegate(this);
if (is_valid_item()) {
if (item_.type == ash::TYPE_APP_SHORTCUT) {
DCHECK(controller->IsPinned(item_.id));
AddItem(
MENU_PIN,
l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_UNPIN));
// No open actions for pending app shortcut.
if (item->status != ash::STATUS_IS_PENDING) {
AddSeparator();
AddCheckItemWithStringId(
LAUNCH_TYPE_REGULAR_TAB,
IDS_APP_CONTEXT_MENU_OPEN_REGULAR);
AddCheckItemWithStringId(
LAUNCH_TYPE_PINNED_TAB,
IDS_APP_CONTEXT_MENU_OPEN_PINNED);
AddCheckItemWithStringId(
LAUNCH_TYPE_WINDOW,
IDS_APP_CONTEXT_MENU_OPEN_WINDOW);
// Even though the launch type is Full Screen it is more accurately
// described as Maximized in Ash.
AddCheckItemWithStringId(
LAUNCH_TYPE_FULLSCREEN,
IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED);
}
} else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) {
AddItem(MENU_NEW_WINDOW,
l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_WINDOW));
if (!controller_->IsLoggedInAsGuest()) {
AddItem(MENU_NEW_INCOGNITO_WINDOW,
l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW));
}
} else {
AddItem(MENU_OPEN, controller->GetTitle(item_));
if (item_.type == ash::TYPE_PLATFORM_APP) {
AddItem(
MENU_PIN,
l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN));
}
if (controller->IsOpen(item_.id)) {
AddItem(MENU_CLOSE,
l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
}
}
AddSeparator();
}
AddCheckItemWithStringId(
MENU_AUTO_HIDE, ash::LauncherContextMenu::GetAutoHideResourceStringId());
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kShowLauncherAlignmentMenu)) {
AddSubMenuWithStringId(MENU_ALIGNMENT_MENU,
IDS_AURA_LAUNCHER_CONTEXT_MENU_POSITION,
&alignment_menu_);
}
}
LauncherContextMenu::~LauncherContextMenu() {
}
bool LauncherContextMenu::IsCommandIdChecked(int command_id) const {
switch (command_id) {
case LAUNCH_TYPE_PINNED_TAB:
return controller_->GetLaunchType(item_.id) ==
extensions::ExtensionPrefs::LAUNCH_PINNED;
case LAUNCH_TYPE_REGULAR_TAB:
return controller_->GetLaunchType(item_.id) ==
extensions::ExtensionPrefs::LAUNCH_REGULAR;
case LAUNCH_TYPE_WINDOW:
return controller_->GetLaunchType(item_.id) ==
extensions::ExtensionPrefs::LAUNCH_WINDOW;
case LAUNCH_TYPE_FULLSCREEN:
return controller_->GetLaunchType(item_.id) ==
extensions::ExtensionPrefs::LAUNCH_FULLSCREEN;
case MENU_AUTO_HIDE:
return ash::LauncherContextMenu::IsAutoHideMenuHideChecked();
default:
return false;
}
}
bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const {
switch (command_id) {
case MENU_PIN:
return item_.type == ash::TYPE_PLATFORM_APP ||
controller_->IsPinnable(item_.id);
default:
return true;
}
}
bool LauncherContextMenu::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) {
return false;
}
void LauncherContextMenu::ExecuteCommand(int command_id) {
switch (static_cast<MenuItem>(command_id)) {
case MENU_OPEN:
controller_->Open(item_.id, ui::EF_NONE);
break;
case MENU_CLOSE:
controller_->Close(item_.id);
break;
case MENU_PIN:
controller_->TogglePinned(item_.id);
break;
case LAUNCH_TYPE_PINNED_TAB:
controller_->SetLaunchType(item_.id,
extensions::ExtensionPrefs::LAUNCH_PINNED);
break;
case LAUNCH_TYPE_REGULAR_TAB:
controller_->SetLaunchType(item_.id,
extensions::ExtensionPrefs::LAUNCH_REGULAR);
break;
case LAUNCH_TYPE_WINDOW:
controller_->SetLaunchType(item_.id,
extensions::ExtensionPrefs::LAUNCH_WINDOW);
break;
case LAUNCH_TYPE_FULLSCREEN:
controller_->SetLaunchType(item_.id,
extensions::ExtensionPrefs::LAUNCH_FULLSCREEN);
break;
case MENU_AUTO_HIDE:
controller_->SetAutoHideBehavior(
ash::LauncherContextMenu::GetToggledAutoHideBehavior());
break;
case MENU_NEW_WINDOW:
controller_->CreateNewWindow();
break;
case MENU_NEW_INCOGNITO_WINDOW:
controller_->CreateNewIncognitoWindow();
break;
case MENU_ALIGNMENT_MENU:
break;
}
}
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_
#define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_
#include "ash/launcher/launcher_alignment_menu.h"
#include "ash/launcher/launcher_types.h"
#include "base/basictypes.h"
#include "ui/base/models/simple_menu_model.h"
class ChromeLauncherController;
// Context menu shown for a launcher item.
class LauncherContextMenu : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
// |item| is NULL if the context menu is for the launcher (the user right
// |clicked on an area with no icons).
LauncherContextMenu(ChromeLauncherController* controller,
const ash::LauncherItem* item);
virtual ~LauncherContextMenu();
// ID of the item we're showing the context menu for.
ash::LauncherID id() const { return item_.id; }
// ui::SimpleMenuModel::Delegate overrides:
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE;
virtual void ExecuteCommand(int command_id) OVERRIDE;
private:
enum MenuItem {
MENU_OPEN,
MENU_CLOSE,
MENU_PIN,
LAUNCH_TYPE_PINNED_TAB,
LAUNCH_TYPE_REGULAR_TAB,
LAUNCH_TYPE_FULLSCREEN,
LAUNCH_TYPE_WINDOW,
MENU_AUTO_HIDE,
MENU_NEW_WINDOW,
MENU_NEW_INCOGNITO_WINDOW,
MENU_ALIGNMENT_MENU,
};
// Does |item_| represent a valid item? See description of constructor for
// details on why it may not be valid.
bool is_valid_item() const { return item_.id != 0; }
ChromeLauncherController* controller_;
ash::LauncherItem item_;
ash::LauncherAlignmentMenu alignment_menu_;
DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu);
};
#endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_
// Copyright (c) 2012 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/ash/launcher/launcher_favicon_loader.h"
#include "base/logging.h"
#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller.h"
#include "chrome/common/favicon_url.h"
#include "chrome/common/icon_messages.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace internal {
const int kMaxBitmapSize = 256;
////////////////////////////////////////////////////////////////////////////////
// FaviconBitmapHandler fetchs all bitmaps with the 'icon' (or 'shortcut icon')
// link tag, storing the one that best matches ash::kLauncherPreferredSize.
// These icon bitmaps are not resized and are not cached beyond the lifetime
// of the class. Bitmaps larger than kMaxBitmapSize are ignored.
class FaviconBitmapHandler {
public:
FaviconBitmapHandler(content::WebContents* web_contents,
LauncherFaviconLoader::Delegate* delegate)
: web_contents_(web_contents),
delegate_(delegate) {
}
~FaviconBitmapHandler() {}
const SkBitmap& bitmap() const { return bitmap_; }
void OnUpdateFaviconURL(int32 page_id,
const std::vector<FaviconURL>& candidates);
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
int requested_size,
const std::vector<SkBitmap>& bitmaps);
private:
void DownloadFavicon(const GURL& image_url);
void AddFavicon(const GURL& image_url, const SkBitmap& new_bitmap);
content::WebContents* web_contents_;
LauncherFaviconLoader::Delegate* delegate_;
typedef std::set<GURL> UrlSet;
// Map of pending download urls.
UrlSet pending_requests_;
// Map of processed urls.
UrlSet processed_requests_;
// Current bitmap and source url.
SkBitmap bitmap_;
GURL bitmap_url_;
DISALLOW_COPY_AND_ASSIGN(FaviconBitmapHandler);
};
void FaviconBitmapHandler::OnUpdateFaviconURL(
int32 page_id,
const std::vector<FaviconURL>& candidates) {
// This function receives a complete list of faviocn urls for the page.
// It may get called multiple times with the same list, and will also get
// called any time an item is added or removed. As such, we track processed
// and pending urls, but only until they are removed from the list.
UrlSet new_pending, new_processed;
// Create a map of valid favicon urls.
std::set<GURL> urls;
for (std::vector<FaviconURL>::const_iterator iter = candidates.begin();
iter != candidates.end(); ++iter) {
if (iter->icon_type != FaviconURL::FAVICON)
continue;
const GURL& url = iter->icon_url;
if (url.is_valid())
urls.insert(url);
// Preserve matching pending requests amd processed requests.
if (pending_requests_.find(url) != pending_requests_.end())
new_pending.insert(url);
if (processed_requests_.find(url) != processed_requests_.end())
new_processed.insert(url);
}
pending_requests_ = new_pending;
processed_requests_ = new_processed;
// Reset bitmap_ if no longer valid (i.e. not in the list of urls).
if (urls.find(bitmap_url_) == urls.end()) {
bitmap_url_ = GURL();
bitmap_.reset();
}
// Request any new urls.
for (std::set<GURL>::iterator iter = urls.begin();
iter != urls.end(); ++iter) {
if (processed_requests_.find(*iter) != processed_requests_.end())
continue; // Skip already processed downloads.
if (pending_requests_.find(*iter) != pending_requests_.end())
continue; // Skip already pending downloads.
DownloadFavicon(*iter);
}
}
void FaviconBitmapHandler::DownloadFavicon(const GURL& image_url) {
int image_size = 0; // Request the full sized image.
pending_requests_.insert(image_url);
content::RenderViewHost* host = web_contents_->GetRenderViewHost();
FaviconUtil::DownloadFavicon(host, image_url, image_size);
}
void FaviconBitmapHandler::OnDidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
int requested_size,
const std::vector<SkBitmap>& bitmaps) {
UrlSet::iterator iter = pending_requests_.find(image_url);
if (iter == pending_requests_.end()) {
// Updates are received for all downloads; ignore unrequested urls.
return;
}
pending_requests_.erase(iter);
// Favicon bitmaps are ordered by decreasing width.
if (!errored && !bitmaps.empty())
AddFavicon(image_url, bitmaps[0]);
}
void FaviconBitmapHandler::AddFavicon(const GURL& image_url,
const SkBitmap& new_bitmap) {
processed_requests_.insert(image_url);
if (new_bitmap.height() > kMaxBitmapSize ||
new_bitmap.width() > kMaxBitmapSize)
return;
if (new_bitmap.height() < ash::kLauncherPreferredSize)
return;
if (!bitmap_.isNull()) {
// We want the smallest icon that is large enough.
if (new_bitmap.height() > bitmap_.height())
return;
}
bitmap_url_ = image_url;
bitmap_ = new_bitmap;
delegate_->FaviconUpdated();
}
} // namespace internal
////////////////////////////////////////////////////////////////////////////////
LauncherFaviconLoader::LauncherFaviconLoader(Delegate* delegate,
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {
favicon_handler_.reset(
new internal::FaviconBitmapHandler(web_contents, delegate));
}
LauncherFaviconLoader::~LauncherFaviconLoader() {
}
bool LauncherFaviconLoader::OnMessageReceived(const IPC::Message& message) {
bool message_handled = false; // Allow other handlers to receive these.
IPC_BEGIN_MESSAGE_MAP(LauncherFaviconLoader, message)
IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
IPC_MESSAGE_UNHANDLED(message_handled = false)
IPC_END_MESSAGE_MAP()
return message_handled;
}
SkBitmap LauncherFaviconLoader::GetFavicon() const {
return favicon_handler_->bitmap();
}
void LauncherFaviconLoader::OnUpdateFaviconURL(
int32 page_id,
const std::vector<FaviconURL>& candidates) {
favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
}
void LauncherFaviconLoader::OnDidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
int requested_size,
const std::vector<SkBitmap>& bitmaps) {
favicon_handler_->OnDidDownloadFavicon(
id, image_url, errored, requested_size, bitmaps);
}
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_FAVICON_LOADER_H_
#define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_FAVICON_LOADER_H_
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "chrome/common/favicon_url.h"
#include "content/public/browser/web_contents_observer.h"
class GURL;
class SkBitmap;
namespace internal {
class FaviconBitmapHandler;
}
// LauncherFaviconLoader handles updates to the list of favicon urls and
// retrieves the appropriately sized favicon for panels in the Launcher.
class LauncherFaviconLoader : public content::WebContentsObserver {
public:
class Delegate {
public:
virtual void FaviconUpdated() = 0;
protected:
virtual ~Delegate() {}
};
LauncherFaviconLoader(Delegate* delegate,
content::WebContents* web_contents);
virtual ~LauncherFaviconLoader();
// content::WebContentsObserver overrides.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
content::WebContents* web_contents() {
return content::WebContentsObserver::web_contents();
}
// Returns an appropriately sized favicon for the Launcher. If none are
// available will return an isNull bitmap.
SkBitmap GetFavicon() const;
private:
// Message Handlers.
void OnUpdateFaviconURL(int32 page_id,
const std::vector<FaviconURL>& candidates);
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
int requested_size,
const std::vector<SkBitmap>& bitmaps);
scoped_ptr<internal::FaviconBitmapHandler> favicon_handler_;
DISALLOW_COPY_AND_ASSIGN(LauncherFaviconLoader);
};
#endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_LAUNCHER_FAVICON_LOADER_H_
// Copyright (c) 2012 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 <vector>
#include "base/file_path.h"
#include "base/time.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller.h"
#include "chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/favicon_url.h"
#include "chrome/common/icon_messages.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "net/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
// Observer class to determine when favicons have completed loading.
class ContentsObserver : public content::WebContentsObserver {
public:
explicit ContentsObserver(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
got_favicons_(false),
downloads_received_(0) {
}
virtual ~ContentsObserver() {}
bool got_favicons() const { return got_favicons_; }
int downloads_received() const { return downloads_received_; }
void Reset() {
got_favicons_ = false;
downloads_received_ = 0;
}
// content::WebContentsObserver overrides.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
bool message_handled = false; // Allow other handlers to receive these.
IPC_BEGIN_MESSAGE_MAP(ContentsObserver, message)
IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
IPC_MESSAGE_UNHANDLED(message_handled = false)
IPC_END_MESSAGE_MAP()
return message_handled;
}
private:
void OnUpdateFaviconURL(int32 page_id,
const std::vector<FaviconURL>& candidates) {
got_favicons_ = true;
}
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
int requested_size,
const std::vector<SkBitmap>& bitmaps) {
++downloads_received_;
}
bool got_favicons_;
int downloads_received_;
};
} // namespace
class LauncherFaviconLoaderBrowsertest : public InProcessBrowserTest {
protected:
void NavigateTo(Browser* browser, const char* url) {
std::string url_path = base::StringPrintf("files/ash/launcher/%s", url);
ui_test_utils::NavigateToURL(browser, test_server()->GetURL(url_path));
}
void CreatePanelBrowser(const char* url, Browser** result) {
Browser* panel_browser = new Browser(
Browser::CreateParams::CreateForApp(
Browser::TYPE_PANEL, "Test Panel", gfx::Rect(),
browser()->profile()));
EXPECT_TRUE(panel_browser->is_type_panel());
ASSERT_EQ(static_cast<void*>(NULL), contents_observer_.get());
// Load initial tab contents before setting the observer.
ui_test_utils::NavigateToURL(panel_browser, GURL());
contents_observer_.reset(
new ContentsObserver(chrome::GetWebContentsAt(panel_browser, 0)));
NavigateTo(panel_browser, url);
*result = panel_browser;
}
LauncherFaviconLoader* GetFaviconLoader(Browser* browser) {
BrowserView* browser_view = static_cast<BrowserView*>(browser->window());
BrowserLauncherItemController* launcher_item_controller =
browser_view->launcher_item_controller();
if (!launcher_item_controller)
return NULL;
EXPECT_EQ(BrowserLauncherItemController::TYPE_EXTENSION_PANEL,
launcher_item_controller->type());
LauncherFaviconLoader* loader = launcher_item_controller->favicon_loader();
return loader;
}
void ResetDownloads() {
ASSERT_NE(static_cast<void*>(NULL), contents_observer_.get());
contents_observer_->Reset();
}
bool WaitForFaviconDownlads(int expected) {
const int64 max_seconds = 2;
base::Time start_time = base::Time::Now();
while (!contents_observer_->got_favicons() ||
contents_observer_->downloads_received() < expected) {
content::RunAllPendingInMessageLoop();
base::TimeDelta delta = base::Time::Now() - start_time;
if (delta.InSeconds() >= max_seconds) {
LOG(ERROR) << " WaitForFaviconDownlads timed out:"
<< " Got Favicons:" << contents_observer_->got_favicons()
<< " Received: " << contents_observer_->downloads_received()
<< " / " << expected;
return false;
}
}
return true;
}
private:
scoped_ptr<ContentsObserver> contents_observer_;
scoped_ptr<net::TestServer> test_server_;
};
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, SmallLauncherIcon) {
ASSERT_TRUE(test_server()->Start());
Browser* panel_browser;
ASSERT_NO_FATAL_FAILURE(
CreatePanelBrowser("launcher-smallfavicon.html", &panel_browser));
LauncherFaviconLoader* favicon_loader = GetFaviconLoader(panel_browser);
ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
EXPECT_TRUE(WaitForFaviconDownlads(1));
// No large favicons specified, bitmap should be empty.
EXPECT_TRUE(favicon_loader->GetFavicon().empty());
}
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, LargeLauncherIcon) {
ASSERT_TRUE(test_server()->Start());
Browser* panel_browser;
ASSERT_NO_FATAL_FAILURE(
CreatePanelBrowser("launcher-largefavicon.html", &panel_browser));
LauncherFaviconLoader* favicon_loader = GetFaviconLoader(panel_browser);
ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
EXPECT_TRUE(WaitForFaviconDownlads(1));
EXPECT_FALSE(favicon_loader->GetFavicon().empty());
EXPECT_EQ(128, favicon_loader->GetFavicon().height());
}
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ManyLauncherIcons) {
ASSERT_TRUE(test_server()->Start());
Browser* panel_browser;
ASSERT_NO_FATAL_FAILURE(
CreatePanelBrowser("launcher-manyfavicon.html", &panel_browser));
LauncherFaviconLoader* favicon_loader = GetFaviconLoader(panel_browser);
ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
EXPECT_TRUE(WaitForFaviconDownlads(3));
EXPECT_FALSE(favicon_loader->GetFavicon().empty());
// When multiple favicons are present, the correctly sized icon should be
// chosen. The icons are sized assuming ash::kLauncherPreferredSize < 128.
EXPECT_GT(128, ash::kLauncherPreferredSize);
EXPECT_EQ(48, favicon_loader->GetFavicon().height());
}
IN_PROC_BROWSER_TEST_F(LauncherFaviconLoaderBrowsertest, ChangeLauncherIcons) {
ASSERT_TRUE(test_server()->Start());
Browser* panel_browser;
ASSERT_NO_FATAL_FAILURE(
CreatePanelBrowser("launcher-manyfavicon.html", &panel_browser));
LauncherFaviconLoader* favicon_loader = GetFaviconLoader(panel_browser);
ASSERT_NE(static_cast<LauncherFaviconLoader*>(NULL), favicon_loader);
EXPECT_TRUE(WaitForFaviconDownlads(3));
EXPECT_FALSE(favicon_loader->GetFavicon().empty());
EXPECT_EQ(48, favicon_loader->GetFavicon().height());
ASSERT_NO_FATAL_FAILURE(ResetDownloads());
NavigateTo(panel_browser, "launcher-smallfavicon.html");
EXPECT_TRUE(WaitForFaviconDownlads(1));
EXPECT_TRUE(favicon_loader->GetFavicon().empty());
ASSERT_NO_FATAL_FAILURE(ResetDownloads());
NavigateTo(panel_browser, "launcher-largefavicon.html");
EXPECT_TRUE(WaitForFaviconDownlads(1));
EXPECT_FALSE(favicon_loader->GetFavicon().empty());
EXPECT_EQ(128, favicon_loader->GetFavicon().height());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment