| 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..3f455a9020b227df762cc1e4a4b4344596e77276 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"
|
| @@ -103,6 +105,17 @@ int GetMessagePrefixID(bool is_app,
|
| }
|
| }
|
|
|
| +string16 GetProfileNameFromInfoCache(Profile* profile) {
|
| + ProfileInfoCache& cache =
|
| + g_browser_process->profile_manager()->GetProfileInfoCache();
|
| + size_t index = cache.GetIndexOfProfileWithPath(
|
| + profile->GetOriginalProfile()->GetPath());
|
| + if (index == std::string::npos)
|
| + return string16();
|
| + else
|
| + return cache.GetNameOfProfileAtIndex(index);
|
| +}
|
| +
|
| } // namespace
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -315,14 +328,7 @@ string16 TaskManagerTabContentsResource::GetTitle() const {
|
| }
|
|
|
| string16 TaskManagerTabContentsResource::GetProfileName() const {
|
| - ProfileInfoCache& cache =
|
| - g_browser_process->profile_manager()->GetProfileInfoCache();
|
| - Profile* profile = tab_contents_->profile()->GetOriginalProfile();
|
| - size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| - if (index == std::string::npos)
|
| - return string16();
|
| - else
|
| - return cache.GetNameOfProfileAtIndex(index);
|
| + return GetProfileNameFromInfoCache(tab_contents_->profile());
|
| }
|
|
|
| gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const {
|
| @@ -331,8 +337,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 +530,200 @@ 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 {
|
| + return GetProfileNameFromInfoCache(panel_->profile());
|
| +}
|
| +
|
| +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 (PanelResourceMap::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;
|
| +
|
| + PanelResourceMap::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;
|
| +
|
| + PanelResourceMap::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) {
|
| + WebContents* web_contents = content::Source<WebContents>(source).ptr();
|
| + if (chrome::GetViewType(web_contents) != chrome::VIEW_TYPE_PANEL)
|
| + return;
|
| +
|
| + switch (type) {
|
| + case content::NOTIFICATION_WEB_CONTENTS_CONNECTED:
|
| + {
|
| + std::vector<Panel*>panels = PanelManager::GetInstance()->panels();
|
| + for (size_t i = 0; i < panels.size(); ++i) {
|
| + if (panels[i]->GetWebContents() == web_contents) {
|
| + Add(panels[i]);
|
| + break;
|
| + }
|
| + }
|
| + break;
|
| + }
|
| + case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED:
|
| + {
|
| + for (PanelResourceMap::iterator iter = resources_.begin();
|
| + iter != resources_.end(); ++iter) {
|
| + Panel* panel = iter->first;
|
| + if (panel->GetWebContents() == web_contents) {
|
| + Remove(panel);
|
| + break;
|
| + }
|
| + }
|
| + break;
|
| + }
|
| + default:
|
| + NOTREACHED() << "Unexpected notificiation.";
|
| + break;
|
| + }
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| // TaskManagerBackgroundContentsResource class
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| @@ -1137,16 +1337,8 @@ string16 TaskManagerExtensionProcessResource::GetTitle() const {
|
| }
|
|
|
| string16 TaskManagerExtensionProcessResource::GetProfileName() const {
|
| - ProfileInfoCache& cache =
|
| - g_browser_process->profile_manager()->GetProfileInfoCache();
|
| - Profile* profile = Profile::FromBrowserContext(
|
| - render_view_host_->GetProcess()->GetBrowserContext());
|
| - profile = profile->GetOriginalProfile();
|
| - size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| - if (index == std::string::npos)
|
| - return string16();
|
| - else
|
| - return cache.GetNameOfProfileAtIndex(index);
|
| + return GetProfileNameFromInfoCache(Profile::FromBrowserContext(
|
| + render_view_host_->GetProcess()->GetBrowserContext()));
|
| }
|
|
|
| gfx::ImageSkia TaskManagerExtensionProcessResource::GetIcon() const {
|
| @@ -1317,8 +1509,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(
|
|
|