diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 18:47:30 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 18:47:30 +0000 |
commit | 0d177c0b2386a1dea6249157df81fce6c71758ac (patch) | |
tree | 91ff6fa288391d478ba7256f47794a2e5b24d5c7 /chrome/browser | |
parent | 3eb7c16a5e8699ea75a449ef98f19b87f0d716de (diff) | |
download | chromium_src-0d177c0b2386a1dea6249157df81fce6c71758ac.zip chromium_src-0d177c0b2386a1dea6249157df81fce6c71758ac.tar.gz chromium_src-0d177c0b2386a1dea6249157df81fce6c71758ac.tar.bz2 |
Tell the app launcher about any newly installed apps. This is intended to be used for a nice animation.
Review URL: http://codereview.chromium.org/1906004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46472 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_install_ui.cc | 30 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.css | 2 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.html | 23 | ||||
-rw-r--r-- | chrome/browser/views/app_launcher.cc | 23 | ||||
-rw-r--r-- | chrome/browser/views/app_launcher.h | 22 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.cc | 4 |
7 files changed, 88 insertions, 18 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index b80083f..1ae5786 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1242,7 +1242,7 @@ void Browser::NewTab() { #if defined(OS_WIN) if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kAppLauncherForNewTab)) { - AppLauncher::ShowForNewTab(this); + AppLauncher::ShowForNewTab(this, std::string()); return; } #endif diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index fa43635..80648c6 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/command_line.h" #include "base/file_util.h" #include "base/rand_util.h" #include "base/string_util.h" @@ -18,11 +19,13 @@ #include "chrome/browser/platform_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" -#if defined(TOOLKIT_VIEWS) // TODO(port) +#if defined(TOOLKIT_VIEWS) +#include "chrome/browser/views/app_launcher.h" #include "chrome/browser/views/extensions/extension_installed_bubble.h" #elif defined(TOOLKIT_GTK) #include "chrome/browser/gtk/extension_installed_bubble_gtk.h" #endif +#include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "chrome/common/url_constants.h" @@ -186,14 +189,33 @@ void ExtensionInstallUI::OnInstallSuccess(Extension* extension) { return; } - if (extension->GetFullLaunchURL().is_valid()) - Browser::OpenApplicationTab(profile_, extension); - // GetLastActiveWithProfile will fail on the build bots. This needs to be // implemented differently if any test is created which depends on // ExtensionInstalledBubble showing. Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); + if (extension->GetFullLaunchURL().is_valid()) { + std::string hash_params = "app-id="; + hash_params += extension->id(); + + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kAppLauncherForNewTab)) { +#if defined(TOOLKIT_VIEWS) + AppLauncher::ShowForNewTab(browser, hash_params); +#else + NOTREACHED(); +#endif + } else { + std::string url(chrome::kChromeUINewTabURL); + url += "/#"; + url += hash_params; + browser->AddTabWithURL(GURL(url), GURL(), PageTransition::TYPED, -1, + Browser::ADD_SELECTED, NULL, std::string()); + } + + return; + } + #if defined(TOOLKIT_VIEWS) if (!browser) return; diff --git a/chrome/browser/resources/new_new_tab.css b/chrome/browser/resources/new_new_tab.css index 43099a13..69409f2 100644 --- a/chrome/browser/resources/new_new_tab.css +++ b/chrome/browser/resources/new_new_tab.css @@ -16,7 +16,7 @@ body { min-height: 100%; } -html[hash=app-launcher] #container { +html[mode=app-launcher] #container { min-height: 0; } diff --git a/chrome/browser/resources/new_new_tab.html b/chrome/browser/resources/new_new_tab.html index a10b238..47bc25b 100644 --- a/chrome/browser/resources/new_new_tab.html +++ b/chrome/browser/resources/new_new_tab.html @@ -96,8 +96,27 @@ function updateSimpleSection(id, section) { document.getElementById(id).className += ' hidden'; } -// Reflect the hash as an attribute so we can use CSS attribute selectors on it. -document.documentElement.setAttribute('hash', location.hash.slice(1)); +// Parse any name value pairs passed through the URL hash. +var hashParams = (function() { + var result = {}; + if (location.hash.length) { + location.hash.substr(1).split('&').forEach(function(pair) { + pair = pair.split('='); + if (pair.length != 2) { + throw new Error('Unexpected hash value: ' + location.hash); + } + + result[pair[0]] = pair[1]; + }); + } + return result; +})(); + +// Reflect the mode param as an attribute so we can use CSS attribute selectors +// on it. +if ('mode' in hashParams) { + document.documentElement.setAttribute('mode', hashParams['mode']); +} </script> </head> diff --git a/chrome/browser/views/app_launcher.cc b/chrome/browser/views/app_launcher.cc index 7bd9ddb..20379f5 100644 --- a/chrome/browser/views/app_launcher.cc +++ b/chrome/browser/views/app_launcher.cc @@ -138,7 +138,19 @@ void InfoBubbleContentsView::ViewHierarchyChanged( // We make the AppLauncher the TabContents delegate so we get notifications // from the page to open links. dom_view_->tab_contents()->set_delegate(app_launcher_); - dom_view_->LoadURL(GetMenuURL()); + + GURL url = GetMenuURL(); + std::string ref = url.ref(); + if (!app_launcher_->hash_params().empty()) { + if (!ref.empty()) + ref += "&"; + ref += app_launcher_->hash_params(); + + url_canon::Replacements<char> replacements; + replacements.SetRef(ref.c_str(), url_parse::Component(0, ref.size())); + url = url.ReplaceComponents(replacements); + } + dom_view_->LoadURL(url); Browser* browser = app_launcher_->browser(); location_bar_ = new LocationBarView(browser->profile(), @@ -201,9 +213,11 @@ AppLauncher::~AppLauncher() { // static AppLauncher* AppLauncher::Show(Browser* browser, const gfx::Rect& bounds, - const gfx::Point& bubble_anchor) { + const gfx::Point& bubble_anchor, + const std::string& hash_params) { AppLauncher* app_launcher = new AppLauncher(browser); BrowserView* browser_view = static_cast<BrowserView*>(browser->window()); + app_launcher->hash_params_ = hash_params; app_launcher->info_bubble_ = PinnedContentsInfoBubble::Show(browser_view->frame()->GetWindow(), bounds, bubble_anchor, app_launcher->info_bubble_content_, @@ -213,7 +227,8 @@ AppLauncher* AppLauncher::Show(Browser* browser, } // static -AppLauncher* AppLauncher::ShowForNewTab(Browser* browser) { +AppLauncher* AppLauncher::ShowForNewTab(Browser* browser, + const std::string& hash_params) { BrowserView* browser_view = static_cast<BrowserView*>(browser->window()); TabStrip* tabstrip = browser_view->tabstrip()->AsTabStrip(); if (!tabstrip) @@ -232,7 +247,7 @@ AppLauncher* AppLauncher::ShowForNewTab(Browser* browser) { views::RootView::ConvertPointToScreen(location_bar->GetParent(), &location_bar_origin); - return Show(browser, bounds, location_bar_origin); + return Show(browser, bounds, location_bar_origin, hash_params); } void AppLauncher::Hide() { diff --git a/chrome/browser/views/app_launcher.h b/chrome/browser/views/app_launcher.h index 1472f06..2b5f429 100644 --- a/chrome/browser/views/app_launcher.h +++ b/chrome/browser/views/app_launcher.h @@ -44,21 +44,31 @@ class AppLauncher : public InfoBubbleDelegate, // Shows an application launcher bubble pointing to the |bounds| (which should // be in screen coordinates). |bubble_anchor| specifies at which coordinates // the bubble contents should appear (in screen coordinates). The bubble will - // be moved accordingly. + // be moved accordingly. Any |hash_params| are appended to the hash of the URL + // that is opened in the launcher. + // // The caller DOES NOT OWN the AppLauncher returned. It is deleted // automatically when the AppLauncher is closed. static AppLauncher* Show(Browser* browser, const gfx::Rect& bounds, - const gfx::Point& bubble_anchor); + const gfx::Point& bubble_anchor, + const std::string& hash_params); // Shows an application launcher bubble pointing to the new tab button. - // The caller DOES NOT OWN the AppLauncher returned. It is deleted + // Any |hash_params| are appened to the hash of the URL that is opened in the + // launcher. + // + // The caller DOES NOT OWN the AppLauncher returned. It is deleted // automatically when the AppLauncher is closed. - static AppLauncher* ShowForNewTab(Browser* browser); + static AppLauncher* ShowForNewTab(Browser* browser, + const std::string& hash_params); // Returns the browser this AppLauncher is associated with. Browser* browser() const { return browser_; } + // Returns any hash params for the page to open. + const std::string& hash_params() const { return hash_params_; } + // Hides the app launcher. void Hide(); @@ -107,6 +117,10 @@ class AppLauncher : public InfoBubbleDelegate, // The view with the navigation bar and render view, shown in the info-bubble. InfoBubbleContentsView* info_bubble_content_; + // An optional string containing querystring-encoded name/value pairs to be + // sent into the launcher's HTML page via its hash. + std::string hash_params_; + DISALLOW_COPY_AND_ASSIGN(AppLauncher); }; diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index ced65ab..c58f15a 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -974,8 +974,8 @@ void TabStrip::ButtonPressed(views::Button* sender, const views::Event& event) { switches::kAppLauncherForNewTab)) { NavigationController& controller = model_->GetSelectedTabContents()->controller(); - AppLauncher::ShowForNewTab(Browser::GetBrowserForController(&controller, - NULL)); + AppLauncher::ShowForNewTab( + Browser::GetBrowserForController(&controller, NULL), std::string()); return; } UserMetrics::RecordAction(UserMetricsAction("NewTab_Button"), |