diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-06 02:47:51 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-06 02:47:51 +0000 |
commit | dd290d3f062e30567a3068ab1793998152c14297 (patch) | |
tree | 22d2eeab01f6b0763b31352b85c4e9de7e8cc90c /chrome/browser | |
parent | f47f3bb594b063d5539373c656b0b2fb39780ea1 (diff) | |
download | chromium_src-dd290d3f062e30567a3068ab1793998152c14297.zip chromium_src-dd290d3f062e30567a3068ab1793998152c14297.tar.gz chromium_src-dd290d3f062e30567a3068ab1793998152c14297.tar.bz2 |
Launch panels as popup windows in Aura, and add separate launcher icon logic for panels.
BUG=115901
TEST=Scratchpad and GTalk apps should open popup windows with a launcher icon (currently the blown up favicon, that will change in a follow up CL).
Review URL: http://codereview.chromium.org/9590001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125080 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
10 files changed, 119 insertions, 44 deletions
diff --git a/chrome/browser/extensions/extension_tab_helper.cc b/chrome/browser/extensions/extension_tab_helper.cc index e7f1fe9..1b8d3cb 100644 --- a/chrome/browser/extensions/extension_tab_helper.cc +++ b/chrome/browser/extensions/extension_tab_helper.cc @@ -67,21 +67,18 @@ void ExtensionTabHelper::SetExtensionApp(const Extension* extension) { void ExtensionTabHelper::SetExtensionAppById( const std::string& extension_app_id) { - if (extension_app_id.empty()) - return; - - Profile* profile = - Profile::FromBrowserContext(web_contents()->GetBrowserContext()); - ExtensionService* extension_service = profile->GetExtensionService(); - if (!extension_service || !extension_service->is_ready()) - return; - - const Extension* extension = - extension_service->GetExtensionById(extension_app_id, false); + const Extension* extension = GetExtension(extension_app_id); if (extension) SetExtensionApp(extension); } +void ExtensionTabHelper::SetExtensionAppIconById( + const std::string& extension_app_id) { + const Extension* extension = GetExtension(extension_app_id); + if (extension) + UpdateExtensionAppIcon(extension); +} + SkBitmap* ExtensionTabHelper::GetExtensionAppIcon() { if (extension_app_icon_.empty()) return NULL; @@ -235,6 +232,22 @@ void ExtensionTabHelper::OnRequest( web_contents()->GetRenderViewHost()); } +const Extension* ExtensionTabHelper::GetExtension( + const std::string& extension_app_id) { + if (extension_app_id.empty()) + return NULL; + + Profile* profile = + Profile::FromBrowserContext(web_contents()->GetBrowserContext()); + ExtensionService* extension_service = profile->GetExtensionService(); + if (!extension_service || !extension_service->is_ready()) + return NULL; + + const Extension* extension = + extension_service->GetExtensionById(extension_app_id, false); + return extension; +} + void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { extension_app_icon_.reset(); diff --git a/chrome/browser/extensions/extension_tab_helper.h b/chrome/browser/extensions/extension_tab_helper.h index dd1edc8..4d2f47e 100644 --- a/chrome/browser/extensions/extension_tab_helper.h +++ b/chrome/browser/extensions/extension_tab_helper.h @@ -66,6 +66,9 @@ class ExtensionTabHelper // specified id. void SetExtensionAppById(const std::string& extension_app_id); + // Set just the app icon, used by panels created by an extension. + void SetExtensionAppIconById(const std::string& extension_app_id); + const Extension* extension_app() const { return extension_app_; } bool is_app() const { return extension_app_ != NULL; } const WebApplicationInfo& web_app_info() const { @@ -121,6 +124,8 @@ class ExtensionTabHelper // ImageLoadingTracker to load the extension's image. void UpdateExtensionAppIcon(const Extension* extension); + const Extension* GetExtension(const std::string& extension_app_id); + // ImageLoadingTracker::Observer. virtual void OnImageLoaded(const gfx::Image& image, const std::string& extension_id, diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index 832e6ef..018de67 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -21,6 +21,7 @@ #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_tab_helper.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/extension_tabs_module_constants.h" #include "chrome/browser/extensions/extension_window_controller.h" @@ -615,8 +616,12 @@ bool CreateWindowFunction::RunImpl() { (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds), window_profile); } - for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) - new_window->AddSelectedTabWithURL(*i, content::PAGE_TRANSITION_LINK); + for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) { + TabContentsWrapper* tab = new_window->AddSelectedTabWithURL( + *i, content::PAGE_TRANSITION_LINK); + if (window_type == Browser::TYPE_PANEL) + tab->extension_tab_helper()->SetExtensionAppIconById(extension_id); + } if (contents) { TabStripModel* target_tab_strip = new_window->tabstrip_model(); target_tab_strip->InsertTabContentsAt(urls.size(), contents, diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 22fcb5a..89138e9 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -4603,10 +4603,18 @@ void Browser::ShowFirstRunBubble() { BrowserWindow* Browser::CreateBrowserWindow() { // TODO(yfriedman): remove OS_ANDROID clause when browser is excluded from // Android build. -#if (!defined(OS_CHROMEOS) || defined(USE_AURA)) && !defined(OS_ANDROID) - if (is_type_panel()) - return PanelManager::GetInstance()->CreatePanel(this); +#if !defined(OS_ANDROID) + bool create_panel = false; +#if defined(USE_AURA) + if (CommandLine::ForCurrentProcess()->HasSwitch( + ash::switches::kAuraPanelManager)) + create_panel = is_type_panel(); +#elif !defined(OS_CHROMEOS) + create_panel = is_type_panel(); #endif + if (create_panel) + return PanelManager::GetInstance()->CreatePanel(this); +#endif // OS_ANDROID return BrowserWindow::CreateBrowserWindow(this); } diff --git a/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc b/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc index a528729..703c5a8 100644 --- a/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc +++ b/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.cc @@ -39,6 +39,7 @@ namespace { // See description in PersistPinnedState(). const char kAppIDPath[] = "id"; +const char kAppTypePanel[] = "panel"; const char kAppTypePath[] = "type"; const char kAppTypeTab[] = "tab"; const char kAppTypeWindow[] = "window"; @@ -99,8 +100,13 @@ void ChromeLauncherDelegate::Init() { if (app->GetString(kAppIDPath, &app_id) && app->GetString(kAppTypePath, &type_string) && app_icon_loader_->IsValidID(app_id)) { - AppType app_type = (type_string == kAppTypeWindow) ? - APP_TYPE_WINDOW : APP_TYPE_TAB; + AppType app_type; + if (type_string == kAppTypeWindow) + app_type = APP_TYPE_WINDOW; + else if (type_string == kAppTypePanel) + app_type = APP_TYPE_PANEL; + else + app_type = APP_TYPE_TAB; CreateAppLauncherItem(NULL, app_id, app_type); } } @@ -175,6 +181,7 @@ ash::LauncherID ChromeLauncherDelegate::CreateAppLauncherItem( min_app_index : std::min(item_count, min_tab_index + 1); ash::LauncherID id = model_->next_id(); ash::LauncherItem item(ash::TYPE_APP); + item.image = Extension::GetDefaultIcon(true); model_->Add(insert_index, item); DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); id_to_item_map_[id].item_type = TYPE_APP; @@ -183,7 +190,8 @@ ash::LauncherID ChromeLauncherDelegate::CreateAppLauncherItem( id_to_item_map_[id].updater = updater; id_to_item_map_[id].pinned = updater == NULL; - app_icon_loader_->FetchImage(app_id); + if (app_type != APP_TYPE_PANEL) + app_icon_loader_->FetchImage(app_id); return id; } @@ -292,7 +300,8 @@ void ChromeLauncherDelegate::Open(ash::LauncherID id) { } } else { DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); - if (id_to_item_map_[id].app_type == APP_TYPE_TAB) { + AppType app_type = id_to_item_map_[id].app_type; + if (app_type == APP_TYPE_TAB) { const Extension* extension = profile_->GetExtensionService()->GetInstalledExtension( id_to_item_map_[id].app_id); @@ -304,9 +313,10 @@ void ChromeLauncherDelegate::Open(ash::LauncherID id) { } else { std::string app_name = web_app::GenerateApplicationNameFromExtensionId( id_to_item_map_[id].app_id); + Browser::Type browser_type = (app_type == APP_TYPE_PANEL) ? + Browser::TYPE_PANEL : Browser::TYPE_POPUP; Browser* browser = Browser::CreateForApp( - Browser::TYPE_POPUP, app_name, gfx::Rect(), - GetProfileForNewWindows()); + browser_type, app_name, gfx::Rect(), GetProfileForNewWindows()); browser->window()->Show(); } } @@ -354,13 +364,18 @@ void ChromeLauncherDelegate::SetAppImage(const std::string& id, const SkBitmap* image) { for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); i != id_to_item_map_.end(); ++i) { - if (i->second.app_id == id) { - int index = model_->ItemIndexByID(i->first); - ash::LauncherItem item = model_->items()[index]; + if (i->second.app_id != id) + continue; + // Panel items may share the same app_id as the app that created them, + // but they set their icon image in LauncherUpdater::UpdateLauncher(), + // so do not set panel images here. + if (i->second.app_type == APP_TYPE_PANEL) + continue; + int index = model_->ItemIndexByID(i->first); + ash::LauncherItem item = model_->items()[index]; item.image = image ? *image : Extension::GetDefaultIcon(true); - model_->Set(index, item); - // It's possible we're waiting on more than one item, so don't break. - } + model_->Set(index, item); + // It's possible we're waiting on more than one item, so don't break. } } @@ -443,9 +458,13 @@ void ChromeLauncherDelegate::PersistPinnedState() { id_to_item_map_[id].pinned) { base::DictionaryValue* app_value = new base::DictionaryValue; app_value->SetString(kAppIDPath, id_to_item_map_[id].app_id); - const char* app_type_string = - id_to_item_map_[id].app_type == APP_TYPE_WINDOW ? - kAppTypeWindow : kAppTypeTab; + const char* app_type_string; + if (id_to_item_map_[id].app_type == APP_TYPE_WINDOW) + app_type_string = kAppTypeWindow; + else if (id_to_item_map_[id].app_type == APP_TYPE_PANEL) + app_type_string = kAppTypePanel; + else + app_type_string = kAppTypeTab; app_value->SetString(kAppTypePath, app_type_string); updater.Get()->Append(app_value); } diff --git a/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h b/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h index 160cb16..350bf87 100644 --- a/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h +++ b/chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h @@ -39,6 +39,7 @@ class ChromeLauncherDelegate : public ash::LauncherDelegate, // Indicates what should happen when the app is launched. enum AppType { APP_TYPE_WINDOW, + APP_TYPE_PANEL, APP_TYPE_TAB }; diff --git a/chrome/browser/ui/views/ash/launcher/launcher_updater.cc b/chrome/browser/ui/views/ash/launcher/launcher_updater.cc index ec58176..5b1fe22 100644 --- a/chrome/browser/ui/views/ash/launcher/launcher_updater.cc +++ b/chrome/browser/ui/views/ash/launcher/launcher_updater.cc @@ -51,10 +51,13 @@ LauncherUpdater::~LauncherUpdater() { void LauncherUpdater::Init() { tab_model_->AddObserver(this); - if (type_ == TYPE_APP) { + if (type_ == TYPE_APP || type_ == TYPE_PANEL) { // App type never changes, create the launcher item immediately. + ChromeLauncherDelegate::AppType app_type = + type_ == TYPE_PANEL ? ChromeLauncherDelegate::APP_TYPE_PANEL + : ChromeLauncherDelegate::APP_TYPE_WINDOW; item_id_ = launcher_delegate_->CreateAppLauncherItem( - this, app_id_, ChromeLauncherDelegate::APP_TYPE_WINDOW); + this, app_id_, app_type); } else { // Determine if we have any tabs that should get launcher items. std::vector<TabContentsWrapper*> app_tabs; @@ -81,7 +84,7 @@ LauncherUpdater* LauncherUpdater::Create(Browser* browser) { if (browser->type() == Browser::TYPE_TABBED) { type = TYPE_TABBED; } else if (browser->is_app()) { - type = TYPE_APP; + type = browser->is_type_panel() ? TYPE_PANEL : TYPE_APP; app_id = web_app::GetExtensionIdFromApplicationName(browser->app_name()); } else { return NULL; @@ -142,7 +145,7 @@ void LauncherUpdater::TabChangedAt( void LauncherUpdater::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { - if (type_ == TYPE_APP) + if (type_ != TYPE_TABBED) return; UpdateAppTabState(contents, UPDATE_TAB_INSERTED); @@ -163,7 +166,7 @@ void LauncherUpdater::TabReplacedAt(TabStripModel* tab_strip_model, } void LauncherUpdater::TabDetachedAt(TabContentsWrapper* contents, int index) { - if (type_ == TYPE_APP) + if (type_ != TYPE_TABBED) return; UpdateAppTabState(contents, UPDATE_TAB_REMOVED); @@ -193,8 +196,17 @@ void LauncherUpdater::UpdateLauncher(TabContentsWrapper* tab) { if (item_index == -1) return; - ash::LauncherItem item; - if (launcher_model()->items()[item_index].type == ash::TYPE_APP) { + ash::LauncherItem item = launcher_model()->items()[item_index]; + if (type_ == TYPE_PANEL) { + // Update the icon for app panels. + // TODO(stevenjb): Get a large favicon for the launcher. + if (!tab->favicon_tab_helper()->GetFavicon().empty()) + item.image = tab->favicon_tab_helper()->GetFavicon(); + else if (tab->extension_tab_helper()->GetExtensionAppIcon()) + item.image = *tab->extension_tab_helper()->GetExtensionAppIcon(); + else + item.image = Extension::GetDefaultIcon(true); + } else if (launcher_model()->items()[item_index].type == ash::TYPE_APP) { // Use the app icon if we can. if (tab->extension_tab_helper()->GetExtensionAppIcon()) item.image = *tab->extension_tab_helper()->GetExtensionAppIcon(); diff --git a/chrome/browser/ui/views/ash/launcher/launcher_updater.h b/chrome/browser/ui/views/ash/launcher/launcher_updater.h index b38c985..2e0d4c2 100644 --- a/chrome/browser/ui/views/ash/launcher/launcher_updater.h +++ b/chrome/browser/ui/views/ash/launcher/launcher_updater.h @@ -34,6 +34,7 @@ class LauncherUpdater : public TabStripModelObserver { public: enum Type { TYPE_APP, + TYPE_PANEL, TYPE_TABBED }; @@ -55,6 +56,8 @@ class LauncherUpdater : public TabStripModelObserver { TabStripModel* tab_model() { return tab_model_; } + Type type() const { return type_; } + TabContentsWrapper* GetTab(ash::LauncherID id); // TabStripModel overrides: diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 4b03764..a92e62d 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -591,10 +591,7 @@ void BrowserView::Show() { return; } -#if defined(USE_AURA) - if (!icon_updater_.get()) - icon_updater_.reset(LauncherUpdater::Create(browser_.get())); -#endif // defined(USE_AURA) + CreateLauncherIcon(); // Showing the window doesn't make the browser window active right away. // This can cause SetFocusToLocationBar() to skip setting focus to the @@ -622,8 +619,10 @@ void BrowserView::Show() { } void BrowserView::ShowInactive() { - if (!frame_->IsVisible()) - frame_->ShowInactive(); + if (frame_->IsVisible()) + return; + CreateLauncherIcon(); + frame_->ShowInactive(); } void BrowserView::SetBounds(const gfx::Rect& bounds) { @@ -2536,6 +2535,13 @@ void BrowserView::SetToolbar(ToolbarView* toolbar) { } } +void BrowserView::CreateLauncherIcon() { +#if defined(USE_AURA) + if (!icon_updater_.get()) + icon_updater_.reset(LauncherUpdater::Create(browser_.get())); +#endif // defined(USE_AURA) +} + #if !defined(OS_CHROMEOS) || defined(USE_AURA) // static BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 54d95de..60a3455 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -552,6 +552,9 @@ class BrowserView : public BrowserWindow, // Set the value of |toolbar_| and hook it into the views hierarchy void SetToolbar(ToolbarView* toolbar); + // Create an icon for this window in the launcher (currently only for Ash). + void CreateLauncherIcon(); + // Last focused view that issued a tab traversal. int last_focused_view_storage_id_; |