-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/devtools/devtools_window.h"
-#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/task_manager/renderer_resource.h"
#include "chrome/browser/task_manager/resource_provider.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/browser/task_manager/task_manager_util.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
+#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/view_type_utils.h"
namespace task_manager {
-class ExtensionProcessResource : public Resource {
+class ExtensionProcessResource : public RendererResource {
public:
- explicit ExtensionProcessResource(
- content::RenderViewHost* render_view_host);
+ explicit ExtensionProcessResource(content::RenderViewHost* render_view_host);
virtual ~ExtensionProcessResource();
// Resource methods:
virtual base::string16 GetTitle() const OVERRIDE;
- virtual base::string16 GetProfileName() const OVERRIDE;
virtual gfx::ImageSkia GetIcon() const OVERRIDE;
- virtual base::ProcessHandle GetProcess() const OVERRIDE;
- virtual int GetUniqueChildProcessId() const OVERRIDE;
virtual Type GetType() const OVERRIDE;
- virtual bool CanInspect() const OVERRIDE;
- virtual void Inspect() const OVERRIDE;
- virtual bool SupportNetworkUsage() const OVERRIDE;
- virtual void SetSupportNetworkUsage() OVERRIDE;
- virtual const extensions::Extension* GetExtension() const OVERRIDE;
- // Returns the pid of the extension process.
- int process_id() const { return pid_; }
+ private:
+ const extensions::Extension* GetExtension() const;
// Returns true if the associated extension has a background page.
- virtual bool IsBackground() const OVERRIDE;
+ bool IsBackground() const;
- private:
// The icon painted for the extension process.
static gfx::ImageSkia* default_icon_;
- content::RenderViewHost* render_view_host_;
-
// Cached data about the extension.
- base::ProcessHandle process_handle_;
- int pid_;
- int unique_process_id_;
base::string16 title_;
DISALLOW_COPY_AND_ASSIGN(ExtensionProcessResource);
ExtensionProcessResource::ExtensionProcessResource(
content::RenderViewHost* render_view_host)
- : render_view_host_(render_view_host) {
+ : RendererResource(render_view_host->GetProcess()->GetHandle(),
+ render_view_host) {
if (!default_icon_) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON);
}
- process_handle_ = render_view_host_->GetProcess()->GetHandle();
- unique_process_id_ = render_view_host->GetProcess()->GetID();
- pid_ = base::GetProcId(process_handle_);
base::string16 extension_name = base::UTF8ToUTF16(GetExtension()->name());
DCHECK(!extension_name.empty());
Profile* profile = Profile::FromBrowserContext(
render_view_host->GetProcess()->GetBrowserContext());
- int message_id = util::GetMessagePrefixID(
- GetExtension()->is_app(),
- true, // is_extension
- profile->IsOffTheRecord(),
- false, // is_prerender
- IsBackground());
+ int message_id = util::GetMessagePrefixID(GetExtension()->is_app(),
+ true, // is_extension
+ profile->IsOffTheRecord(),
+ false, // is_prerender
+ IsBackground());
title_ = l10n_util::GetStringFUTF16(message_id, extension_name);
}
return title_;
}
-base::string16 ExtensionProcessResource::GetProfileName() const {
- return util::GetProfileNameFromInfoCache(
- Profile::FromBrowserContext(
- render_view_host_->GetProcess()->GetBrowserContext()));
-}
-
gfx::ImageSkia ExtensionProcessResource::GetIcon() const {
return *default_icon_;
}
-base::ProcessHandle ExtensionProcessResource::GetProcess() const {
- return process_handle_;
-}
-
-int ExtensionProcessResource::GetUniqueChildProcessId() const {
- return unique_process_id_;
-}
-
Resource::Type ExtensionProcessResource::GetType() const {
return EXTENSION;
}
-bool ExtensionProcessResource::CanInspect() const {
- return true;
-}
-
-void ExtensionProcessResource::Inspect() const {
- DevToolsWindow::OpenDevToolsWindow(render_view_host_);
-}
-
-bool ExtensionProcessResource::SupportNetworkUsage() const {
- return true;
-}
-
-void ExtensionProcessResource::SetSupportNetworkUsage() {
- NOTREACHED();
-}
-
const Extension* ExtensionProcessResource::GetExtension() const {
Profile* profile = Profile::FromBrowserContext(
- render_view_host_->GetProcess()->GetBrowserContext());
+ render_view_host()->GetProcess()->GetBrowserContext());
extensions::ProcessManager* process_manager =
extensions::ExtensionSystem::Get(profile)->process_manager();
- return process_manager->GetExtensionForRenderViewHost(render_view_host_);
+ return process_manager->GetExtensionForRenderViewHost(render_view_host());
}
bool ExtensionProcessResource::IsBackground() const {
WebContents* web_contents =
- WebContents::FromRenderViewHost(render_view_host_);
+ WebContents::FromRenderViewHost(render_view_host());
extensions::ViewType view_type = extensions::GetViewType(web_contents);
return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
}
IsHandledByThisProvider(content::RenderViewHost* render_view_host) {
WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host);
// Don't add WebContents that belong to a guest (those are handled by
- // GuestResourceProvider). Otherwise they will be added twice, and
- // in this case they will have the app's name as a title (due to the
- // ExtensionProcessResource constructor).
+ // GuestInformation). Otherwise they will be added twice.
if (web_contents->GetRenderProcessHost()->IsGuest())
return false;
extensions::ViewType view_type = extensions::GetViewType(web_contents);
- // Don't add WebContents (those are handled by
- // TabContentsResourceProvider) or background contents (handled
- // by BackgroundResourceProvider).
-#if defined(USE_ASH)
- return (view_type != extensions::VIEW_TYPE_TAB_CONTENTS &&
- view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS);
-#else
+ // Don't add tab contents (those are handled by TabContentsResourceProvider)
+ // or background contents (handled by BackgroundInformation) or panels
+ // (handled by PanelInformation)
return (view_type != extensions::VIEW_TYPE_TAB_CONTENTS &&
view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS &&
view_type != extensions::VIEW_TYPE_PANEL);
-#endif // USE_ASH
}
void ExtensionProcessResourceProvider::AddToTaskManager(
if (!IsHandledByThisProvider(render_view_host))
return;
+ if (resources_.count(render_view_host))
+ return;
ExtensionProcessResource* resource =
new ExtensionProcessResource(render_view_host);
- if (resources_.find(render_view_host) != resources_.end())
- return;
resources_[render_view_host] = resource;
task_manager_->AddResource(resource);
}