Chromium Code Reviews| Index: chrome/browser/task_manager/task_manager_resource_providers.cc |
| diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc |
| index 9f0966d4d579fa396b154c3e3882e35e1d951e37..ee444b77f92b0952b2530c23d8ec71cad38bad50 100644 |
| --- a/chrome/browser/task_manager/task_manager_resource_providers.cc |
| +++ b/chrome/browser/task_manager/task_manager_resource_providers.cc |
| @@ -38,6 +38,8 @@ |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_instant_controller.h" |
| #include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/browser/ui/panels/panel.h" |
| +#include "chrome/browser/ui/panels/panel_manager.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| #include "chrome/browser/view_type_utils.h" |
| @@ -331,8 +333,8 @@ gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { |
| return tab_contents_->favicon_tab_helper()->GetFavicon(); |
| } |
| -TabContents* TaskManagerTabContentsResource::GetTabContents() const { |
| - return tab_contents_; |
| +WebContents* TaskManagerTabContentsResource::GetWebContents() const { |
| + return tab_contents_->web_contents(); |
| } |
| const Extension* TaskManagerTabContentsResource::GetExtension() const { |
| @@ -524,6 +526,193 @@ void TaskManagerTabContentsResourceProvider::Observe(int type, |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| +// TaskManagerPanelResource class |
| +//////////////////////////////////////////////////////////////////////////////// |
| + |
| +TaskManagerPanelResource::TaskManagerPanelResource(Panel* panel) |
| + : TaskManagerRendererResource( |
| + panel->GetWebContents()->GetRenderProcessHost()->GetHandle(), |
| + panel->GetWebContents()->GetRenderViewHost()), |
| + panel_(panel) { |
| + message_prefix_id_ = GetMessagePrefixID( |
| + GetExtension()->is_app(), true, panel->profile()->IsOffTheRecord(), |
| + false, false); |
| +} |
| + |
| +TaskManagerPanelResource::~TaskManagerPanelResource() { |
| +} |
| + |
| +TaskManager::Resource::Type TaskManagerPanelResource::GetType() const { |
| + return EXTENSION; |
| +} |
| + |
| +string16 TaskManagerPanelResource::GetTitle() const { |
| + string16 title = panel_->GetWindowTitle(); |
| + // Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix |
| + // we need to explicitly set the title to be LTR format if there is no |
| + // strong RTL charater in it. Otherwise, if the task manager prefix is an |
| + // RTL word, the concatenated result might be wrong. For example, |
| + // a page whose title is "Yahoo! Mail: The best web-based Email!", without |
| + // setting it explicitly as LTR format, the concatenated result will be |
| + // "!Yahoo! Mail: The best web-based Email :PPA", in which the capital |
| + // letters "PPA" stands for the Hebrew word for "app". |
| + base::i18n::AdjustStringForLocaleDirection(&title); |
| + |
| + return l10n_util::GetStringFUTF16(message_prefix_id_, title); |
| +} |
| + |
| +string16 TaskManagerPanelResource::GetProfileName() const { |
|
Dmitry Titov
2012/07/18 22:52:15
this seems mostly duplicate the TaskManagerTabCont
|
| + ProfileInfoCache& cache = |
| + g_browser_process->profile_manager()->GetProfileInfoCache(); |
| + Profile* profile = panel_->profile()->GetOriginalProfile(); |
| + size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| + if (index == std::string::npos) |
| + return string16(); |
| + else |
| + return cache.GetNameOfProfileAtIndex(index); |
| +} |
| + |
| +gfx::ImageSkia TaskManagerPanelResource::GetIcon() const { |
| + return panel_->GetCurrentPageIcon(); |
| +} |
| + |
| +WebContents* TaskManagerPanelResource::GetWebContents() const { |
| + return panel_->GetWebContents(); |
| +} |
| + |
| +const Extension* TaskManagerPanelResource::GetExtension() const { |
| + ExtensionService* extension_service = |
| + panel_->profile()->GetExtensionService(); |
| + return extension_service->extensions()->GetByID(panel_->extension_id()); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// TaskManagerPanelResourceProvider class |
| +//////////////////////////////////////////////////////////////////////////////// |
| + |
| +TaskManagerPanelResourceProvider::TaskManagerPanelResourceProvider( |
| + TaskManager* task_manager) |
| + : updating_(false), |
| + task_manager_(task_manager) { |
| +} |
| + |
| +TaskManagerPanelResourceProvider::~TaskManagerPanelResourceProvider() { |
| +} |
| + |
| +TaskManager::Resource* TaskManagerPanelResourceProvider::GetResource( |
| + int origin_pid, |
| + int render_process_host_id, |
| + int routing_id) { |
| + // If an origin PID was specified, the request is from a plugin, not the |
| + // render view host process |
| + if (origin_pid) |
| + return NULL; |
| + |
| + for (std::map<Panel*, TaskManagerPanelResource*>::iterator i = |
| + resources_.begin(); i != resources_.end(); ++i) { |
| + WebContents* contents = i->first->GetWebContents(); |
| + if (contents && |
| + contents->GetRenderProcessHost()->GetID() == render_process_host_id && |
| + contents->GetRenderViewHost()->GetRoutingID() == routing_id) { |
| + return i->second; |
| + } |
| + } |
| + |
| + // Can happen if the panel went away while a network request was being |
| + // performed. |
| + return NULL; |
| +} |
| + |
| +void TaskManagerPanelResourceProvider::StartUpdating() { |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kBrowserlessPanels)) |
| + return; |
| + |
| + DCHECK(!updating_); |
| + updating_ = true; |
| + |
| + // Add all the Panels. |
| + std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| + for (size_t i = 0; i < panels.size(); ++i) |
| + Add(panels[i]); |
| + |
| + // Then we register for notifications to get new and remove closed panels. |
| + registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| + content::NotificationService::AllSources()); |
| + registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| + content::NotificationService::AllSources()); |
| +} |
| + |
| +void TaskManagerPanelResourceProvider::StopUpdating() { |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kBrowserlessPanels)) |
| + return; |
| + |
| + DCHECK(updating_); |
| + updating_ = false; |
| + |
| + // Unregister for notifications about new/removed panels. |
| + registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| + content::NotificationService::AllSources()); |
| + registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| + content::NotificationService::AllSources()); |
| + |
| + // Delete all the resources. |
| + STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| + resources_.clear(); |
| +} |
| + |
| +void TaskManagerPanelResourceProvider::Add(Panel* panel) { |
| + if (!updating_) |
| + return; |
| + |
| + std::map<Panel*, TaskManagerPanelResource*>::const_iterator iter = |
| + resources_.find(panel); |
| + if (iter != resources_.end()) |
| + return; |
| + |
| + TaskManagerPanelResource* resource = new TaskManagerPanelResource(panel); |
| + resources_[panel] = resource; |
| + task_manager_->AddResource(resource); |
| +} |
| + |
| +void TaskManagerPanelResourceProvider::Remove(Panel* panel) { |
| + if (!updating_) |
| + return; |
| + |
| + std::map<Panel*, TaskManagerPanelResource*>::iterator iter = |
| + resources_.find(panel); |
| + if (iter == resources_.end()) |
| + return; |
| + |
| + TaskManagerPanelResource* resource = iter->second; |
| + task_manager_->RemoveResource(resource); |
| + resources_.erase(iter); |
| + delete resource; |
| +} |
| + |
| +void TaskManagerPanelResourceProvider::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + Panel* panel = Panel::FromWebContents( |
| + content::Source<WebContents>(source).ptr()); |
| + if (!panel) |
| + return; |
| + |
| + switch (type) { |
| + case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: |
| + Add(panel); |
| + break; |
| + case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
| + Remove(panel); |
| + break; |
| + default: |
| + NOTREACHED() << "Unexpected notificiation."; |
| + break; |
| + } |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // TaskManagerBackgroundContentsResource class |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -1317,8 +1506,14 @@ bool TaskManagerExtensionProcessResourceProvider:: |
| // by TaskManagerBackgroundResourceProvider). |
| WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
| chrome::ViewType view_type = chrome::GetViewType(web_contents); |
| +#if defined(USE_ASH) |
| return (view_type != chrome::VIEW_TYPE_TAB_CONTENTS && |
| view_type != chrome::VIEW_TYPE_BACKGROUND_CONTENTS); |
| +#else |
| + return (view_type != chrome::VIEW_TYPE_TAB_CONTENTS && |
| + view_type != chrome::VIEW_TYPE_BACKGROUND_CONTENTS && |
| + view_type != chrome::VIEW_TYPE_PANEL); |
| +#endif // USE_ASH |
| } |
| void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( |