Commit a15905af authored by sreeram@chromium.org's avatar sreeram@chromium.org

Add "Instant:" prefix to Instant preview tabs in the Task manager.

BUG=105130
TEST=Open Task Manager. Enable Instant. Type a query into the omnibox. Observe that the Instant preview is listed as "Instant: ..." instead of "Tab: ...".


Review URL: http://codereview.chromium.org/8759009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112745 0039d316-1c4b-4281-b951-d872f2087c98
parent 26f71307
...@@ -3783,6 +3783,9 @@ Public Exponent (<ph name="PUBLIC_EXPONENT_NUM_BITS">$3<ex>24</ex></ph> bits): ...@@ -3783,6 +3783,9 @@ Public Exponent (<ph name="PUBLIC_EXPONENT_NUM_BITS">$3<ex>24</ex></ph> bits):
<message name="IDS_TASK_MANAGER_NOTIFICATION_PREFIX" desc="The prefix for a Desktop Notification in the Task Manager"> <message name="IDS_TASK_MANAGER_NOTIFICATION_PREFIX" desc="The prefix for a Desktop Notification in the Task Manager">
Notification: <ph name="NOTIFICATION_NAME">$1<ex>http://www.domain.com</ex></ph> Notification: <ph name="NOTIFICATION_NAME">$1<ex>http://www.domain.com</ex></ph>
</message> </message>
<message name="IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX" desc="The prefix for an Instant preview in the Task Manager">
Instant: <ph name="INSTANT_PREVIEW_NAME">$1<ex>http://www.google.com/</ex></ph>
</message>
<!-- Theme preview info bar --> <!-- Theme preview info bar -->
<message name="IDS_THEME_INSTALL_INFOBAR_LABEL" desc="Text displayed on an infobar when a theme has been installed."> <message name="IDS_THEME_INSTALL_INFOBAR_LABEL" desc="Text displayed on an infobar when a theme has been installed.">
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/command_line.h" #include "base/command_line.h"
#include "base/string_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/autocomplete/autocomplete_edit.h"
...@@ -14,6 +15,8 @@ ...@@ -14,6 +15,8 @@
#include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/omnibox/location_bar.h"
...@@ -29,6 +32,8 @@ ...@@ -29,6 +32,8 @@
#include "content/browser/renderer_host/render_widget_host_view.h" #include "content/browser/renderer_host/render_widget_host_view.h"
#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
// Tests are flaky on Linux because of http://crbug.com/80118. // Tests are flaky on Linux because of http://crbug.com/80118.
#if defined(OS_LINUX) #if defined(OS_LINUX)
...@@ -802,6 +807,28 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { ...@@ -802,6 +807,28 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) {
ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
} }
// Tests that the task manager identifies instant's preview tab correctly.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) {
// The browser starts with one new tab, so the task manager should have two
// rows initially, one for the browser process and one for tab's renderer.
TaskManagerModel* task_manager = TaskManager::GetInstance()->model();
task_manager->StartUpdating();
TaskManagerBrowserTestUtil::WaitForResourceChange(2);
ASSERT_TRUE(test_server()->Start());
EnableInstant();
SetupInstantProvider("instant.html");
DetermineInstantSupport();
SearchAndWaitForPreviewToShow();
// Now there should be three rows, the third being the instant preview.
TaskManagerBrowserTestUtil::WaitForResourceChange(3);
string16 prefix = l10n_util::GetStringFUTF16(
IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16());
string16 title = task_manager->GetResourceTitle(2);
EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix;
}
// Tests the INSTANT experiment of the field trial. // Tests the INSTANT experiment of the field trial.
class InstantFieldTrialInstantTest : public InstantTest { class InstantFieldTrialInstantTest : public InstantTest {
public: public:
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h" #include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -70,8 +71,11 @@ namespace { ...@@ -70,8 +71,11 @@ namespace {
// Returns the appropriate message prefix ID for tabs and extensions, // Returns the appropriate message prefix ID for tabs and extensions,
// reflecting whether they are apps or in incognito mode. // reflecting whether they are apps or in incognito mode.
int GetMessagePrefixID(bool is_app, bool is_extension, int GetMessagePrefixID(bool is_app,
bool is_incognito, bool is_prerender) { bool is_extension,
bool is_incognito,
bool is_prerender,
bool is_instant_preview) {
if (is_app) { if (is_app) {
if (is_incognito) if (is_incognito)
return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX; return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX;
...@@ -84,6 +88,8 @@ int GetMessagePrefixID(bool is_app, bool is_extension, ...@@ -84,6 +88,8 @@ int GetMessagePrefixID(bool is_app, bool is_extension,
return IDS_TASK_MANAGER_EXTENSION_PREFIX; return IDS_TASK_MANAGER_EXTENSION_PREFIX;
} else if (is_prerender) { } else if (is_prerender) {
return IDS_TASK_MANAGER_PRERENDER_PREFIX; return IDS_TASK_MANAGER_PRERENDER_PREFIX;
} else if (is_instant_preview) {
return IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX;
} else { } else {
return IDS_TASK_MANAGER_TAB_PREFIX; return IDS_TASK_MANAGER_TAB_PREFIX;
} }
...@@ -216,16 +222,30 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource( ...@@ -216,16 +222,30 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource(
: TaskManagerRendererResource( : TaskManagerRendererResource(
tab_contents->tab_contents()->GetRenderProcessHost()->GetHandle(), tab_contents->tab_contents()->GetRenderProcessHost()->GetHandle(),
tab_contents->render_view_host()), tab_contents->render_view_host()),
tab_contents_(tab_contents) { tab_contents_(tab_contents),
is_instant_preview_(false) {
if (!prerender_icon_) { if (!prerender_icon_) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); ResourceBundle& rb = ResourceBundle::GetSharedInstance();
prerender_icon_ = rb.GetBitmapNamed(IDR_PRERENDER); prerender_icon_ = rb.GetBitmapNamed(IDR_PRERENDER);
} }
for (BrowserList::const_iterator i = BrowserList::begin();
i != BrowserList::end(); ++i) {
if ((*i)->instant() &&
(*i)->instant()->GetPreviewContents() == tab_contents_) {
is_instant_preview_ = true;
break;
}
}
} }
TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { TaskManagerTabContentsResource::~TaskManagerTabContentsResource() {
} }
void TaskManagerTabContentsResource::InstantCommitted() {
DCHECK(is_instant_preview_);
is_instant_preview_ = false;
}
bool TaskManagerTabContentsResource::IsPrerendering() const { bool TaskManagerTabContentsResource::IsPrerendering() const {
prerender::PrerenderManager* prerender_manager = prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForProfile( prerender::PrerenderManagerFactory::GetForProfile(
...@@ -279,7 +299,8 @@ string16 TaskManagerTabContentsResource::GetTitle() const { ...@@ -279,7 +299,8 @@ string16 TaskManagerTabContentsResource::GetTitle() const {
is_app, is_app,
HostsExtension(), HostsExtension(),
tab_contents_->profile()->IsOffTheRecord(), tab_contents_->profile()->IsOffTheRecord(),
IsPrerendering()); IsPrerendering(),
is_instant_preview_);
return l10n_util::GetStringFUTF16(message_id, tab_title); return l10n_util::GetStringFUTF16(message_id, tab_title);
} }
...@@ -376,6 +397,8 @@ void TaskManagerTabContentsResourceProvider::StartUpdating() { ...@@ -376,6 +397,8 @@ void TaskManagerTabContentsResourceProvider::StartUpdating() {
// (http://crbug.com/7321). // (http://crbug.com/7321).
registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
content::NotificationService::AllBrowserContextsAndSources()); content::NotificationService::AllBrowserContextsAndSources());
registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
content::NotificationService::AllBrowserContextsAndSources());
} }
void TaskManagerTabContentsResourceProvider::StopUpdating() { void TaskManagerTabContentsResourceProvider::StopUpdating() {
...@@ -395,6 +418,9 @@ void TaskManagerTabContentsResourceProvider::StopUpdating() { ...@@ -395,6 +418,9 @@ void TaskManagerTabContentsResourceProvider::StopUpdating() {
registrar_.Remove( registrar_.Remove(
this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
content::NotificationService::AllBrowserContextsAndSources()); content::NotificationService::AllBrowserContextsAndSources());
registrar_.Remove(
this, chrome::NOTIFICATION_INSTANT_COMMITTED,
content::NotificationService::AllBrowserContextsAndSources());
// Delete all the resources. // Delete all the resources.
STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
...@@ -456,12 +482,27 @@ void TaskManagerTabContentsResourceProvider::Remove( ...@@ -456,12 +482,27 @@ void TaskManagerTabContentsResourceProvider::Remove(
delete resource; delete resource;
} }
void TaskManagerTabContentsResourceProvider::Update(
TabContentsWrapper* tab_contents) {
if (!updating_)
return;
std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator
iter = resources_.find(tab_contents);
DCHECK(iter != resources_.end());
if (iter != resources_.end())
iter->second->InstantCommitted();
}
void TaskManagerTabContentsResourceProvider::Observe(int type, void TaskManagerTabContentsResourceProvider::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
TabContentsWrapper* tab_contents = TabContentsWrapper* tab_contents;
TabContentsWrapper::GetCurrentWrapperForContents( if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) {
content::Source<TabContents>(source).ptr()); tab_contents = content::Source<TabContentsWrapper>(source).ptr();
} else {
tab_contents = TabContentsWrapper::GetCurrentWrapperForContents(
content::Source<TabContents>(source).ptr());
}
// A background page does not have a TabContentsWrapper. // A background page does not have a TabContentsWrapper.
if (!tab_contents) if (!tab_contents)
return; return;
...@@ -482,6 +523,9 @@ void TaskManagerTabContentsResourceProvider::Observe(int type, ...@@ -482,6 +523,9 @@ void TaskManagerTabContentsResourceProvider::Observe(int type,
case content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED: case content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED:
Remove(tab_contents); Remove(tab_contents);
break; break;
case chrome::NOTIFICATION_INSTANT_COMMITTED:
Update(tab_contents);
break;
default: default:
NOTREACHED() << "Unexpected notification."; NOTREACHED() << "Unexpected notification.";
return; return;
...@@ -1073,7 +1117,7 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( ...@@ -1073,7 +1117,7 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource(
DCHECK(!extension_name.empty()); DCHECK(!extension_name.empty());
int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, int message_id = GetMessagePrefixID(GetExtension()->is_app(), true,
extension_host_->profile()->IsOffTheRecord(), false); extension_host_->profile()->IsOffTheRecord(), false, false);
title_ = l10n_util::GetStringFUTF16(message_id, extension_name); title_ = l10n_util::GetStringFUTF16(message_id, extension_name);
} }
......
...@@ -98,6 +98,10 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource { ...@@ -98,6 +98,10 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource {
explicit TaskManagerTabContentsResource(TabContentsWrapper* tab_contents); explicit TaskManagerTabContentsResource(TabContentsWrapper* tab_contents);
virtual ~TaskManagerTabContentsResource(); virtual ~TaskManagerTabContentsResource();
// Called when the underlying tab_contents has been committed, and is thus no
// longer an Instant preview.
void InstantCommitted();
// TaskManager::Resource methods: // TaskManager::Resource methods:
virtual Type GetType() const OVERRIDE; virtual Type GetType() const OVERRIDE;
virtual string16 GetTitle() const OVERRIDE; virtual string16 GetTitle() const OVERRIDE;
...@@ -114,6 +118,7 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource { ...@@ -114,6 +118,7 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource {
static SkBitmap* prerender_icon_; static SkBitmap* prerender_icon_;
TabContentsWrapper* tab_contents_; TabContentsWrapper* tab_contents_;
bool is_instant_preview_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource); DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource);
}; };
...@@ -140,6 +145,7 @@ class TaskManagerTabContentsResourceProvider ...@@ -140,6 +145,7 @@ class TaskManagerTabContentsResourceProvider
void Add(TabContentsWrapper* tab_contents); void Add(TabContentsWrapper* tab_contents);
void Remove(TabContentsWrapper* tab_contents); void Remove(TabContentsWrapper* tab_contents);
void Update(TabContentsWrapper* tab_contents);
void AddToTaskManager(TabContentsWrapper* tab_contents); void AddToTaskManager(TabContentsWrapper* tab_contents);
......
...@@ -542,6 +542,7 @@ ...@@ -542,6 +542,7 @@
'browser/mouseleave_interactive_uitest.cc', 'browser/mouseleave_interactive_uitest.cc',
'browser/notifications/notifications_interactive_uitest.cc', 'browser/notifications/notifications_interactive_uitest.cc',
'browser/npapi_interactive_test.cc', 'browser/npapi_interactive_test.cc',
'browser/task_manager/task_manager_browsertest_util.cc',
'browser/ui/gtk/bookmarks/bookmark_bar_gtk_interactive_uitest.cc', 'browser/ui/gtk/bookmarks/bookmark_bar_gtk_interactive_uitest.cc',
'browser/ui/omnibox/omnibox_view_browsertest.cc', 'browser/ui/omnibox/omnibox_view_browsertest.cc',
'browser/ui/panels/panel_browsertest.cc', 'browser/ui/panels/panel_browsertest.cc',
......
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