Highlight background pages in task manager if user clicks View Background Pages.
Added "highlight_background_resources" param to BrowserWindow::ShowTaskManager() and added support in Cocoa for drawing highlights. BUG=71490 TEST=Click View Background Pages, see background pages are highlighted in yellow. Review URL: http://codereview.chromium.org/6312178 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73993 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
chrome
@ -942,7 +942,7 @@ void RecordLastRunAppBundlePath() {
|
||||
case IDC_TASK_MANAGER:
|
||||
UserMetrics::RecordAction(UserMetricsAction("TaskManager"),
|
||||
defaultProfile);
|
||||
TaskManagerMac::Show();
|
||||
TaskManagerMac::Show(false);
|
||||
break;
|
||||
case IDC_OPTIONS:
|
||||
[self showPreferences:sender];
|
||||
|
@ -340,7 +340,7 @@ void BackgroundModeManager::ExecuteCommand(int item) {
|
||||
GetBrowserWindow()->OpenOptionsDialog();
|
||||
break;
|
||||
case IDC_TASK_MANAGER:
|
||||
GetBrowserWindow()->OpenTaskManager();
|
||||
GetBrowserWindow()->OpenTaskManager(true);
|
||||
break;
|
||||
default:
|
||||
ExecuteApplication(item);
|
||||
|
@ -1768,9 +1768,12 @@ void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) {
|
||||
GetSelectedTabContentsWrapper()->render_view_host(), action);
|
||||
}
|
||||
|
||||
void Browser::OpenTaskManager() {
|
||||
void Browser::OpenTaskManager(bool highlight_background_resources) {
|
||||
UserMetrics::RecordAction(UserMetricsAction("TaskManager"), profile_);
|
||||
window_->ShowTaskManager();
|
||||
if (highlight_background_resources)
|
||||
window_->ShowBackgroundPages();
|
||||
else
|
||||
window_->ShowTaskManager();
|
||||
}
|
||||
|
||||
void Browser::OpenBugReportDialog() {
|
||||
@ -2262,8 +2265,8 @@ void Browser::ExecuteCommandWithDisposition(
|
||||
case IDC_DEV_TOOLS_INSPECT: ToggleDevToolsWindow(
|
||||
DEVTOOLS_TOGGLE_ACTION_INSPECT);
|
||||
break;
|
||||
case IDC_TASK_MANAGER: // fall through to OpenTaskManager().
|
||||
case IDC_VIEW_BACKGROUND_PAGES: OpenTaskManager(); break;
|
||||
case IDC_TASK_MANAGER: OpenTaskManager(false); break;
|
||||
case IDC_VIEW_BACKGROUND_PAGES: OpenTaskManager(true); break;
|
||||
case IDC_FEEDBACK: OpenBugReportDialog(); break;
|
||||
|
||||
case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break;
|
||||
|
@ -530,7 +530,7 @@ class Browser : public TabHandlerDelegate,
|
||||
void OpenFile();
|
||||
void OpenCreateShortcutsDialog();
|
||||
void ToggleDevToolsWindow(DevToolsToggleAction action);
|
||||
void OpenTaskManager();
|
||||
void OpenTaskManager(bool highlight_background_resources);
|
||||
void OpenBugReportDialog();
|
||||
|
||||
void ToggleBookmarkBar();
|
||||
|
@ -206,6 +206,9 @@ class BrowserWindow {
|
||||
// Shows the Task manager.
|
||||
virtual void ShowTaskManager() = 0;
|
||||
|
||||
// Shows task information related to background pages.
|
||||
virtual void ShowBackgroundPages() = 0;
|
||||
|
||||
// Shows the Bookmark bubble. |url| is the URL being bookmarked,
|
||||
// |already_bookmarked| is true if the url is already bookmarked.
|
||||
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
|
||||
|
@ -73,6 +73,7 @@ class BrowserWindowCocoa : public BrowserWindow,
|
||||
virtual views::Window* ShowAboutChromeDialog();
|
||||
virtual void ShowUpdateChromeDialog();
|
||||
virtual void ShowTaskManager();
|
||||
virtual void ShowBackgroundPages();
|
||||
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
|
||||
virtual bool IsDownloadShelfVisible() const;
|
||||
virtual DownloadShelf* GetDownloadShelf();
|
||||
|
@ -309,7 +309,11 @@ void BrowserWindowCocoa::ShowUpdateChromeDialog() {
|
||||
}
|
||||
|
||||
void BrowserWindowCocoa::ShowTaskManager() {
|
||||
TaskManagerMac::Show();
|
||||
TaskManagerMac::Show(false);
|
||||
}
|
||||
|
||||
void BrowserWindowCocoa::ShowBackgroundPages() {
|
||||
TaskManagerMac::Show(true);
|
||||
}
|
||||
|
||||
void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
|
||||
|
@ -29,6 +29,7 @@ class TaskManagerMac;
|
||||
TaskManagerMac* taskManagerObserver_; // weak
|
||||
TaskManager* taskManager_; // weak
|
||||
TaskManagerModel* model_; // weak
|
||||
bool highlightBackgroundResources_;
|
||||
|
||||
scoped_nsobject<WindowSizeAutosaver> size_saver_;
|
||||
|
||||
@ -39,10 +40,14 @@ class TaskManagerMac;
|
||||
|
||||
// Descriptor of the current sort column.
|
||||
scoped_nsobject<NSSortDescriptor> currentSortDescriptor_;
|
||||
|
||||
// Color we use for background resources.
|
||||
scoped_nsobject<NSColor> backgroundResourceColor_;
|
||||
}
|
||||
|
||||
// Creates and shows the task manager's window.
|
||||
- (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver;
|
||||
- (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver
|
||||
highlightBackgroundResources:(bool)highlightBackgroundResources;
|
||||
|
||||
// Refreshes all data in the task manager table.
|
||||
- (void)reloadData;
|
||||
@ -65,7 +70,7 @@ class TaskManagerMac;
|
||||
class TaskManagerMac : public TaskManagerModelObserver,
|
||||
public TableRowNSImageCache::Table {
|
||||
public:
|
||||
TaskManagerMac(TaskManager* task_manager);
|
||||
TaskManagerMac(TaskManager* task_manager, bool highlight_background);
|
||||
virtual ~TaskManagerMac();
|
||||
|
||||
// TaskManagerModelObserver
|
||||
@ -83,8 +88,9 @@ class TaskManagerMac : public TaskManagerModelObserver,
|
||||
virtual SkBitmap GetIcon(int r) const;
|
||||
|
||||
// Creates the task manager if it doesn't exist; otherwise, it activates the
|
||||
// existing task manager window.
|
||||
static void Show();
|
||||
// existing task manager window. Highlights background resources if
|
||||
// |highlight_background_resources| is true.
|
||||
static void Show(bool highlight_background_resources);
|
||||
|
||||
// Returns the TaskManager observed by |this|.
|
||||
TaskManager* task_manager() { return task_manager_; }
|
||||
@ -94,6 +100,9 @@ class TaskManagerMac : public TaskManagerModelObserver,
|
||||
|
||||
// Returns the cocoa object. Used for testing.
|
||||
TaskManagerWindowController* cocoa_controller() { return window_controller_; }
|
||||
|
||||
// Returns true if the resource at this location is a background resource.
|
||||
bool IsBackgroundRow(int row) const;
|
||||
private:
|
||||
// The task manager.
|
||||
TaskManager* const task_manager_; // weak
|
||||
@ -108,6 +117,9 @@ class TaskManagerMac : public TaskManagerModelObserver,
|
||||
// Caches favicons for all rows. Needs to be initalized after |model_|.
|
||||
TableRowNSImageCache icon_cache_;
|
||||
|
||||
// If true, highlight background resources.
|
||||
bool highlight_background_resources_;
|
||||
|
||||
// An open task manager window. There can only be one open at a time. This
|
||||
// is reset to NULL when the window is closed.
|
||||
static TaskManagerMac* instance_;
|
||||
|
@ -102,7 +102,8 @@ class SortHelper {
|
||||
|
||||
@implementation TaskManagerWindowController
|
||||
|
||||
- (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver {
|
||||
- (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver
|
||||
highlightBackgroundResources:(bool)highlightBackgroundResources {
|
||||
NSString* nibpath = [base::mac::MainAppBundle()
|
||||
pathForResource:@"TaskManager"
|
||||
ofType:@"nib"];
|
||||
@ -110,6 +111,15 @@ class SortHelper {
|
||||
taskManagerObserver_ = taskManagerObserver;
|
||||
taskManager_ = taskManagerObserver_->task_manager();
|
||||
model_ = taskManager_->model();
|
||||
highlightBackgroundResources_ = highlightBackgroundResources;
|
||||
if (highlightBackgroundResources_) {
|
||||
// Highlight background resources with a yellow background.
|
||||
backgroundResourceColor_.reset(
|
||||
[[NSColor colorWithDeviceRed:0xff/255.0
|
||||
green:0xfa/255.0
|
||||
blue:0xcd/255.0
|
||||
alpha:1.0] retain]);
|
||||
}
|
||||
|
||||
if (g_browser_process && g_browser_process->local_state()) {
|
||||
size_saver_.reset([[WindowSizeAutosaver alloc]
|
||||
@ -192,6 +202,7 @@ class SortHelper {
|
||||
[self adjustSelectionAndEndProcessButton];
|
||||
|
||||
[tableView_ setDoubleAction:@selector(selectDoubleClickedTab:)];
|
||||
[tableView_ setIntercellSpacing:NSMakeSize(0.0, 0.0)];
|
||||
[tableView_ sizeToFit];
|
||||
}
|
||||
|
||||
@ -370,6 +381,29 @@ class SortHelper {
|
||||
[self autorelease];
|
||||
}
|
||||
|
||||
// Delegate method invoked before each cell in the table is displayed. We
|
||||
// override this to provide highlighting of background resources.
|
||||
- (void) tableView:(NSTableView*)tableView
|
||||
willDisplayCell:(id)cell
|
||||
forTableColumn:(NSTableColumn*)tableColumn
|
||||
row:(NSInteger)row {
|
||||
if (!highlightBackgroundResources_)
|
||||
return;
|
||||
|
||||
bool isBackground =
|
||||
taskManagerObserver_->IsBackgroundRow(viewToModelMap_[row]);
|
||||
DCHECK([cell respondsToSelector:@selector(setBackgroundColor:)]);
|
||||
if ([cell respondsToSelector:@selector(setBackgroundColor:)]) {
|
||||
if (isBackground && ![tableView isRowSelected:row]) {
|
||||
[cell setDrawsBackground:YES];
|
||||
[cell setBackgroundColor:backgroundResourceColor_];
|
||||
} else {
|
||||
[cell setBackgroundColor:nil];
|
||||
[cell setDrawsBackground:NO];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TaskManagerWindowController (NSTableDataSource)
|
||||
@ -502,12 +536,16 @@ class SortHelper {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TaskManagerMac implementation:
|
||||
|
||||
TaskManagerMac::TaskManagerMac(TaskManager* task_manager)
|
||||
TaskManagerMac::TaskManagerMac(TaskManager* task_manager,
|
||||
bool highlight_background_resources)
|
||||
: task_manager_(task_manager),
|
||||
model_(task_manager->model()),
|
||||
icon_cache_(this) {
|
||||
icon_cache_(this),
|
||||
highlight_background_resources_(highlight_background_resources) {
|
||||
window_controller_ =
|
||||
[[TaskManagerWindowController alloc] initWithTaskManagerObserver:this];
|
||||
[[TaskManagerWindowController alloc]
|
||||
initWithTaskManagerObserver:this
|
||||
highlightBackgroundResources:highlight_background_resources];
|
||||
model_->AddObserver(this);
|
||||
}
|
||||
|
||||
@ -569,14 +607,28 @@ SkBitmap TaskManagerMac::GetIcon(int r) const {
|
||||
return model_->GetResourceIcon(r);
|
||||
}
|
||||
|
||||
// static
|
||||
void TaskManagerMac::Show() {
|
||||
if (instance_) {
|
||||
// If there's a Task manager window open already, just activate it.
|
||||
[[instance_->window_controller_ window]
|
||||
makeKeyAndOrderFront:instance_->window_controller_];
|
||||
} else {
|
||||
instance_ = new TaskManagerMac(TaskManager::GetInstance());
|
||||
instance_->model_->StartUpdating();
|
||||
}
|
||||
bool TaskManagerMac::IsBackgroundRow(int row) const {
|
||||
return model_->IsBackgroundResource(row);
|
||||
}
|
||||
|
||||
// static
|
||||
void TaskManagerMac::Show(bool highlight_background_resources) {
|
||||
if (instance_) {
|
||||
if (instance_->highlight_background_resources_ ==
|
||||
highlight_background_resources) {
|
||||
// There's a Task manager window open already, so just activate it.
|
||||
[[instance_->window_controller_ window]
|
||||
makeKeyAndOrderFront:instance_->window_controller_];
|
||||
return;
|
||||
} else {
|
||||
// The user is switching between "View Background Pages" and
|
||||
// "Task Manager" so close the existing window and fall through to
|
||||
// open a new one.
|
||||
[[instance_->window_controller_ window] close];
|
||||
}
|
||||
}
|
||||
// Create a new instance.
|
||||
instance_ = new TaskManagerMac(TaskManager::GetInstance(),
|
||||
highlight_background_resources);
|
||||
instance_->model_->StartUpdating();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class TaskManagerWindowControllerTest : public CocoaTest {
|
||||
// Test creation, to ensure nothing leaks or crashes.
|
||||
TEST_F(TaskManagerWindowControllerTest, Init) {
|
||||
TaskManager task_manager;
|
||||
TaskManagerMac* bridge(new TaskManagerMac(&task_manager));
|
||||
TaskManagerMac* bridge(new TaskManagerMac(&task_manager, false));
|
||||
TaskManagerWindowController* controller = bridge->cocoa_controller();
|
||||
|
||||
// Releases the controller, which in turn deletes |bridge|.
|
||||
@ -57,7 +57,7 @@ TEST_F(TaskManagerWindowControllerTest, Sort) {
|
||||
task_manager.AddResource(&resource2);
|
||||
task_manager.AddResource(&resource3); // Will be in the same group as 2.
|
||||
|
||||
TaskManagerMac* bridge(new TaskManagerMac(&task_manager));
|
||||
TaskManagerMac* bridge(new TaskManagerMac(&task_manager, false));
|
||||
TaskManagerWindowController* controller = bridge->cocoa_controller();
|
||||
NSTableView* table = [controller tableView];
|
||||
ASSERT_EQ(3, [controller numberOfRowsInTableView:table]);
|
||||
@ -90,7 +90,7 @@ TEST_F(TaskManagerWindowControllerTest, SelectionAdaptsToSorting) {
|
||||
task_manager.AddResource(&resource1);
|
||||
task_manager.AddResource(&resource2);
|
||||
|
||||
TaskManagerMac* bridge(new TaskManagerMac(&task_manager));
|
||||
TaskManagerMac* bridge(new TaskManagerMac(&task_manager, false));
|
||||
TaskManagerWindowController* controller = bridge->cocoa_controller();
|
||||
NSTableView* table = [controller tableView];
|
||||
ASSERT_EQ(2, [controller numberOfRowsInTableView:table]);
|
||||
|
@ -845,6 +845,12 @@ void BrowserWindowGtk::ShowTaskManager() {
|
||||
TaskManagerGtk::Show();
|
||||
}
|
||||
|
||||
void BrowserWindowGtk::ShowBackgroundPages() {
|
||||
// TODO(atwilson): Support highlighting background resources.
|
||||
// (http://crbug.com/71490)
|
||||
TaskManagerGtk::Show();
|
||||
}
|
||||
|
||||
void BrowserWindowGtk::ShowBookmarkBubble(const GURL& url,
|
||||
bool already_bookmarked) {
|
||||
toolbar_->GetLocationBarView()->ShowStarBubble(url, !already_bookmarked);
|
||||
|
@ -92,6 +92,7 @@ class BrowserWindowGtk : public BrowserWindow,
|
||||
virtual views::Window* ShowAboutChromeDialog();
|
||||
virtual void ShowUpdateChromeDialog();
|
||||
virtual void ShowTaskManager();
|
||||
virtual void ShowBackgroundPages();
|
||||
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
|
||||
virtual bool IsDownloadShelfVisible() const;
|
||||
virtual DownloadShelf* GetDownloadShelf();
|
||||
|
@ -1074,6 +1074,12 @@ void BrowserView::ShowTaskManager() {
|
||||
browser::ShowTaskManager();
|
||||
}
|
||||
|
||||
void BrowserView::ShowBackgroundPages() {
|
||||
// TODO(atwilson): Support highlighting background resources.
|
||||
// (http://crbug.com/71490)
|
||||
browser::ShowTaskManager();
|
||||
}
|
||||
|
||||
void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
|
||||
toolbar_->location_bar()->ShowStarBubble(url, !already_bookmarked);
|
||||
}
|
||||
|
@ -289,6 +289,7 @@ class BrowserView : public BrowserBubbleHost,
|
||||
virtual views::Window* ShowAboutChromeDialog();
|
||||
virtual void ShowUpdateChromeDialog();
|
||||
virtual void ShowTaskManager();
|
||||
virtual void ShowBackgroundPages();
|
||||
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
|
||||
virtual void SetDownloadShelfVisible(bool visible);
|
||||
virtual bool IsDownloadShelfVisible() const;
|
||||
|
@ -74,6 +74,7 @@ class TestBrowserWindow : public BrowserWindow {
|
||||
virtual views::Window* ShowAboutChromeDialog() { return NULL; }
|
||||
virtual void ShowUpdateChromeDialog() {}
|
||||
virtual void ShowTaskManager() {}
|
||||
virtual void ShowBackgroundPages() {}
|
||||
virtual void ShowBookmarkManager() {}
|
||||
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {}
|
||||
virtual bool IsDownloadShelfVisible() const { return false; }
|
||||
|
Reference in New Issue
Block a user