diff options
24 files changed, 376 insertions, 32 deletions
diff --git a/chrome/browser/apps/guest_view/app_view_browsertest.cc b/chrome/browser/apps/guest_view/app_view_browsertest.cc index de71620..08a596f 100644 --- a/chrome/browser/apps/guest_view/app_view_browsertest.cc +++ b/chrome/browser/apps/guest_view/app_view_browsertest.cc @@ -12,6 +12,7 @@ #include "content/public/browser/render_process_host_observer.h" #include "content/public/test/browser_test_utils.h" #include "content/public/test/test_utils.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/app_window/app_window_registry.h" #include "extensions/browser/guest_view/app_view/app_view_guest.h" #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" @@ -22,6 +23,7 @@ #include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_response.h" +using extensions::ExtensionsAPIClient; using guest_view::GuestViewManager; using guest_view::TestGuestViewManagerFactory; @@ -130,7 +132,7 @@ class AppViewTest : public extensions::PlatformAppBrowserTest { guest_view::GuestViewManager::CreateWithDelegate( browser()->profile(), scoped_ptr<guest_view::GuestViewManagerDelegate>( - new extensions::ExtensionsGuestViewManagerDelegate( + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( browser()->profile())))); } diff --git a/chrome/browser/apps/guest_view/extension_view/extension_view_browsertest.cc b/chrome/browser/apps/guest_view/extension_view/extension_view_browsertest.cc index 6482965..27f2286 100644 --- a/chrome/browser/apps/guest_view/extension_view/extension_view_browsertest.cc +++ b/chrome/browser/apps/guest_view/extension_view/extension_view_browsertest.cc @@ -6,13 +6,14 @@ #include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/test/base/ui_test_utils.h" #include "components/guest_view/browser/guest_view_manager.h" +#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "components/guest_view/browser/guest_view_manager_factory.h" #include "components/guest_view/browser/test_guest_view_manager.h" #include "content/public/test/browser_test_utils.h" -#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/test/extension_test_message_listener.h" -using extensions::ExtensionsGuestViewManagerDelegate; +using extensions::ExtensionsAPIClient; using guest_view::GuestViewManager; using guest_view::TestGuestViewManager; using guest_view::TestGuestViewManagerFactory; @@ -32,9 +33,8 @@ class ExtensionViewTest : public extensions::PlatformAppBrowserTest { manager = static_cast<TestGuestViewManager*>( GuestViewManager::CreateWithDelegate( browser()->profile(), - scoped_ptr<guest_view::GuestViewManagerDelegate>( - new ExtensionsGuestViewManagerDelegate( - browser()->profile())))); + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( + browser()->profile()))); } return manager; } diff --git a/chrome/browser/apps/guest_view/web_view_browsertest.cc b/chrome/browser/apps/guest_view/web_view_browsertest.cc index 1f58684..c3e1c28 100644 --- a/chrome/browser/apps/guest_view/web_view_browsertest.cc +++ b/chrome/browser/apps/guest_view/web_view_browsertest.cc @@ -21,6 +21,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h" +#include "chrome/browser/task_management/task_management_browsertest_util.h" #include "chrome/browser/task_manager/task_manager_browsertest_util.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_dialogs.h" @@ -28,6 +29,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/guest_view/browser/guest_view_manager.h" +#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "components/guest_view/browser/guest_view_manager_factory.h" #include "components/guest_view/browser/test_guest_view_manager.h" #include "content/public/browser/gpu_data_manager.h" @@ -45,8 +47,8 @@ #include "extensions/browser/api/declarative/rules_registry_service.h" #include "extensions/browser/api/declarative/test_rules_registry.h" #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/app_window/native_app_window.h" -#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" #include "extensions/browser/guest_view/web_view/web_view_guest.h" #include "extensions/common/extension.h" #include "extensions/common/extensions_client.h" @@ -56,6 +58,7 @@ #include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_response.h" #include "ui/aura/window.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/compositor/compositor.h" #include "ui/compositor/compositor_observer.h" #include "ui/events/event_switches.h" @@ -81,7 +84,7 @@ #endif using extensions::ContextMenuMatcher; -using extensions::ExtensionsGuestViewManagerDelegate; +using extensions::ExtensionsAPIClient; using extensions::MenuItem; using guest_view::GuestViewManager; using guest_view::TestGuestViewManager; @@ -684,9 +687,8 @@ class WebViewTest : public extensions::PlatformAppBrowserTest { manager = static_cast<TestGuestViewManager*>( GuestViewManager::CreateWithDelegate( browser()->profile(), - scoped_ptr<guest_view::GuestViewManagerDelegate>( - new ExtensionsGuestViewManagerDelegate( - browser()->profile())))); + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( + browser()->profile()))); } return manager; } @@ -2642,3 +2644,84 @@ IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) { waiter.Wait(); } #endif + +#if defined(ENABLE_TASK_MANAGER) + +namespace { + +base::string16 GetExpectedPrefix(content::WebContents* web_contents) { + DCHECK(web_contents); + guest_view::GuestViewBase* guest = + guest_view::GuestViewBase::FromWebContents(web_contents); + DCHECK(guest); + + return l10n_util::GetStringFUTF16(guest->GetTaskPrefix(), base::string16()); +} + +const std::vector<task_management::WebContentsTag*>& GetTrackedTags() { + return task_management::WebContentsTagsManager::GetInstance()-> + tracked_tags(); +} + +} // namespace + +// Tests that the pre-existing WebViews are provided to the task manager. +IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagementPreExistingWebViews) { + ASSERT_TRUE(StartEmbeddedTestServer()); + + // Browser tests start with a single tab. + EXPECT_EQ(1U, GetTrackedTags().size()); + + content::WebContents* guest_contents = + LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", + "web_view/task_manager"); + + task_management::MockWebContentsTaskManager task_manager; + task_manager.StartObserving(); + + // The pre-existing tab and guest tasks are provided. + // TODO(afakhry): This will have to change once we start tracking extensions. + EXPECT_EQ(2U, task_manager.tasks().size()); + + const task_management::Task* task = task_manager.tasks().back(); + EXPECT_EQ(task_management::Task::GUEST, task->GetType()); + const base::string16 title = task->title(); + const base::string16 expected_prefix = GetExpectedPrefix(guest_contents); + EXPECT_TRUE(base::StartsWith(title, + expected_prefix, + base::CompareCase::INSENSITIVE_ASCII)); +} + +// Tests that the post-existing WebViews are provided to the task manager. +IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagementPostExistingWebViews) { + ASSERT_TRUE(StartEmbeddedTestServer()); + + // Browser tests start with a single tab. + EXPECT_EQ(1U, GetTrackedTags().size()); + + task_management::MockWebContentsTaskManager task_manager; + task_manager.StartObserving(); + + // Only the "about:blank" tab shows at the moment. + EXPECT_EQ(1U, task_manager.tasks().size()); + const task_management::Task* about_blank_task = task_manager.tasks().back(); + EXPECT_EQ(task_management::Task::RENDERER, about_blank_task->GetType()); + EXPECT_EQ(base::UTF8ToUTF16("Tab: about:blank"), about_blank_task->title()); + + // Now load a guest web view. + content::WebContents* guest_contents = + LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html", + "web_view/task_manager"); + // TODO(afakhry): This will have to change once we start tracking extensions. + EXPECT_EQ(2U, task_manager.tasks().size()); + + const task_management::Task* task = task_manager.tasks().back(); + EXPECT_EQ(task_management::Task::GUEST, task->GetType()); + const base::string16 title = task->title(); + const base::string16 expected_prefix = GetExpectedPrefix(guest_contents); + EXPECT_TRUE(base::StartsWith(title, + expected_prefix, + base::CompareCase::INSENSITIVE_ASCII)); +} + +#endif // defined(ENABLE_TASK_MANAGER) diff --git a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc index 734fb35..f4820ed 100644 --- a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc +++ b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc @@ -18,6 +18,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "components/guest_view/browser/guest_view_base.h" #include "components/guest_view/browser/guest_view_manager.h" +#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "components/guest_view/browser/guest_view_manager_factory.h" #include "components/guest_view/browser/test_guest_view_manager.h" #include "content/public/browser/notification_service.h" @@ -28,9 +29,9 @@ #include "content/public/browser/web_contents.h" #include "content/public/common/content_switches.h" #include "content/public/test/browser_test_utils.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/app_window/app_window.h" #include "extensions/browser/app_window/app_window_registry.h" -#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" #include "extensions/test/extension_test_message_listener.h" #include "net/test/embedded_test_server/embedded_test_server.h" #include "ui/base/ime/composition_text.h" @@ -39,7 +40,7 @@ #include "ui/events/keycodes/keyboard_codes.h" using extensions::AppWindow; -using extensions::ExtensionsGuestViewManagerDelegate; +using extensions::ExtensionsAPIClient; using guest_view::GuestViewBase; using guest_view::GuestViewManager; using guest_view::TestGuestViewManager; @@ -66,9 +67,8 @@ class WebViewInteractiveTest manager = static_cast<TestGuestViewManager*>( GuestViewManager::CreateWithDelegate( browser()->profile(), - scoped_ptr<guest_view::GuestViewManagerDelegate>( - new ExtensionsGuestViewManagerDelegate( - browser()->profile())))); + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( + browser()->profile()))); } return manager; } diff --git a/chrome/browser/extensions/api/chrome_extensions_api_client.cc b/chrome/browser/extensions/api/chrome_extensions_api_client.cc index d8cabfb..ab655ed 100644 --- a/chrome/browser/extensions/api/chrome_extensions_api_client.cc +++ b/chrome/browser/extensions/api/chrome_extensions_api_client.cc @@ -13,6 +13,7 @@ #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" #include "chrome/browser/favicon/favicon_utils.h" #include "chrome/browser/guest_view/app_view/chrome_app_view_guest_delegate.h" +#include "chrome/browser/guest_view/chrome_guest_view_manager_delegate.h" #include "chrome/browser/guest_view/extension_options/chrome_extension_options_guest_delegate.h" #include "chrome/browser/guest_view/mime_handler_view/chrome_mime_handler_view_guest_delegate.h" #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h" @@ -96,6 +97,12 @@ ChromeExtensionsAPIClient::CreateExtensionOptionsGuestDelegate( return new ChromeExtensionOptionsGuestDelegate(guest); } +scoped_ptr<guest_view::GuestViewManagerDelegate> +ChromeExtensionsAPIClient::CreateGuestViewManagerDelegate( + content::BrowserContext* context) const { + return make_scoped_ptr(new ChromeGuestViewManagerDelegate(context)); +} + scoped_ptr<MimeHandlerViewGuestDelegate> ChromeExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate( MimeHandlerViewGuest* guest) const { diff --git a/chrome/browser/extensions/api/chrome_extensions_api_client.h b/chrome/browser/extensions/api/chrome_extensions_api_client.h index 7f590b3..92bb450 100644 --- a/chrome/browser/extensions/api/chrome_extensions_api_client.h +++ b/chrome/browser/extensions/api/chrome_extensions_api_client.h @@ -29,6 +29,9 @@ class ChromeExtensionsAPIClient : public ExtensionsAPIClient { AppViewGuestDelegate* CreateAppViewGuestDelegate() const override; ExtensionOptionsGuestDelegate* CreateExtensionOptionsGuestDelegate( ExtensionOptionsGuest* guest) const override; + scoped_ptr<guest_view::GuestViewManagerDelegate> + CreateGuestViewManagerDelegate( + content::BrowserContext* context) const override; scoped_ptr<MimeHandlerViewGuestDelegate> CreateMimeHandlerViewGuestDelegate( MimeHandlerViewGuest* guest) const override; WebViewGuestDelegate* CreateWebViewGuestDelegate( diff --git a/chrome/browser/guest_view/chrome_guest_view_manager_delegate.cc b/chrome/browser/guest_view/chrome_guest_view_manager_delegate.cc new file mode 100644 index 0000000..2612276 --- /dev/null +++ b/chrome/browser/guest_view/chrome_guest_view_manager_delegate.cc @@ -0,0 +1,24 @@ +// Copyright 2015 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 "chrome/browser/guest_view/chrome_guest_view_manager_delegate.h" + +#include "chrome/browser/task_management/web_contents_tags.h" + +namespace extensions { + +ChromeGuestViewManagerDelegate::ChromeGuestViewManagerDelegate( + content::BrowserContext* context) + : ExtensionsGuestViewManagerDelegate(context) { +} + +ChromeGuestViewManagerDelegate::~ChromeGuestViewManagerDelegate() { +} + +void ChromeGuestViewManagerDelegate::AttachTaskManagerGuestTag( + content::WebContents* guest_web_contents) const { + task_management::WebContentsTags::CreateForGuestContents(guest_web_contents); +} + +} // namespace extensions diff --git a/chrome/browser/guest_view/chrome_guest_view_manager_delegate.h b/chrome/browser/guest_view/chrome_guest_view_manager_delegate.h new file mode 100644 index 0000000..b2f345f --- /dev/null +++ b/chrome/browser/guest_view/chrome_guest_view_manager_delegate.h @@ -0,0 +1,32 @@ +// Copyright 2015 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. + +#ifndef CHROME_BROWSER_GUEST_VIEW_CHROME_GUEST_VIEW_MANAGER_DELEGATE_H_ +#define CHROME_BROWSER_GUEST_VIEW_CHROME_GUEST_VIEW_MANAGER_DELEGATE_H_ + +#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" + +namespace extensions { + +// Defines a chrome-specific implementation of +// ExtensionsGuestViewManagerDelegate that knows about the concept of a task +// manager and the need for tagging the guest view WebContents by their +// appropriate task manager tag. +class ChromeGuestViewManagerDelegate + : public ExtensionsGuestViewManagerDelegate { + public: + explicit ChromeGuestViewManagerDelegate(content::BrowserContext* context); + ~ChromeGuestViewManagerDelegate() override; + + // GuestViewManagerDelegate: + void AttachTaskManagerGuestTag( + content::WebContents* guest_web_contents) const override; + + private: + DISALLOW_COPY_AND_ASSIGN(ChromeGuestViewManagerDelegate); +}; + +} // namespace extensions + +#endif // CHROME_BROWSER_GUEST_VIEW_CHROME_GUEST_VIEW_MANAGER_DELEGATE_H_ diff --git a/chrome/browser/task_management/providers/web_contents/guest_tag.cc b/chrome/browser/task_management/providers/web_contents/guest_tag.cc new file mode 100644 index 0000000..75b73ce --- /dev/null +++ b/chrome/browser/task_management/providers/web_contents/guest_tag.cc @@ -0,0 +1,20 @@ +// Copyright 2015 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 "chrome/browser/task_management/providers/web_contents/guest_tag.h" + +namespace task_management { + +GuestTask* GuestTag::CreateTask() const { + return new GuestTask(web_contents()); +} + +GuestTag::GuestTag(content::WebContents* web_contents) + : WebContentsTag(web_contents) { +} + +GuestTag::~GuestTag() { +} + +} // namespace task_management diff --git a/chrome/browser/task_management/providers/web_contents/guest_tag.h b/chrome/browser/task_management/providers/web_contents/guest_tag.h new file mode 100644 index 0000000..fed0fe0 --- /dev/null +++ b/chrome/browser/task_management/providers/web_contents/guest_tag.h @@ -0,0 +1,31 @@ +// Copyright 2015 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. + +#ifndef CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_GUEST_TAG_H_ +#define CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_GUEST_TAG_H_ + +#include "chrome/browser/task_management/providers/web_contents/guest_task.h" +#include "chrome/browser/task_management/providers/web_contents/web_contents_tag.h" + +namespace task_management { + +// Defines a concrete UserData type for WebContents owned by the GuestViewBase, +// which represents browser <*view> tag plugin guests. +class GuestTag : public WebContentsTag { + public: + // task_management::WebContentsTag: + GuestTask* CreateTask() const override; + + private: + friend class WebContentsTags; + + explicit GuestTag(content::WebContents* web_contents); + ~GuestTag() override; + + DISALLOW_COPY_AND_ASSIGN(GuestTag); +}; + +} // namespace task_management + +#endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_GUEST_TAG_H_ diff --git a/chrome/browser/task_management/providers/web_contents/guest_task.cc b/chrome/browser/task_management/providers/web_contents/guest_task.cc new file mode 100644 index 0000000..db34777 --- /dev/null +++ b/chrome/browser/task_management/providers/web_contents/guest_task.cc @@ -0,0 +1,52 @@ +// Copyright 2015 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 "chrome/browser/task_management/providers/web_contents/guest_task.h" + +#include "components/guest_view/browser/guest_view_base.h" +#include "ui/base/l10n/l10n_util.h" + +namespace task_management { + +GuestTask::GuestTask(content::WebContents* web_contents) + : RendererTask(GetCurrentTitle(web_contents), + GetFaviconFromWebContents(web_contents), + web_contents) { +} + +GuestTask::~GuestTask() { +} + +void GuestTask::OnTitleChanged(content::NavigationEntry* entry) { + set_title(GetCurrentTitle(web_contents())); +} + +void GuestTask::OnFaviconChanged() { + const gfx::ImageSkia* icon = GetFaviconFromWebContents(web_contents()); + set_icon(icon ? *icon : gfx::ImageSkia()); +} + +Task::Type GuestTask::GetType() const { + return Task::GUEST; +} + +base::string16 GuestTask::GetCurrentTitle( + content::WebContents* web_contents) const { + DCHECK(web_contents); + + guest_view::GuestViewBase* guest = + guest_view::GuestViewBase::FromWebContents(web_contents); + + DCHECK(guest); + + base::string16 title = + l10n_util::GetStringFUTF16(guest->GetTaskPrefix(), + RendererTask::GetTitleFromWebContents( + web_contents)); + + return title; +} + +} // namespace task_management + diff --git a/chrome/browser/task_management/providers/web_contents/guest_task.h b/chrome/browser/task_management/providers/web_contents/guest_task.h new file mode 100644 index 0000000..94756a2 --- /dev/null +++ b/chrome/browser/task_management/providers/web_contents/guest_task.h @@ -0,0 +1,32 @@ +// Copyright 2015 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. + +#ifndef CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_GUEST_TASK_H_ +#define CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_GUEST_TASK_H_ + +#include "chrome/browser/task_management/providers/web_contents/renderer_task.h" + +namespace task_management { + +// Defines a concrete RendererTask that represents WebContents owned by the +// GuestViewBase which represents a <*view> tag that is a browser plugin guest. +class GuestTask : public RendererTask { + public: + explicit GuestTask(content::WebContents* web_contents); + ~GuestTask() override; + + // task_management::RendererTask: + void OnTitleChanged(content::NavigationEntry* entry) override; + void OnFaviconChanged() override; + Type GetType() const override; + + private: + base::string16 GetCurrentTitle(content::WebContents* web_contents) const; + + DISALLOW_COPY_AND_ASSIGN(GuestTask); +}; + +} // namespace task_management + +#endif // CHROME_BROWSER_TASK_MANAGEMENT_PROVIDERS_WEB_CONTENTS_GUEST_TASK_H_ diff --git a/chrome/browser/task_management/web_contents_tags.cc b/chrome/browser/task_management/web_contents_tags.cc index bb4d1fe..3fed68a 100644 --- a/chrome/browser/task_management/web_contents_tags.cc +++ b/chrome/browser/task_management/web_contents_tags.cc @@ -6,11 +6,13 @@ #include "chrome/browser/task_management/providers/web_contents/background_contents_tag.h" #include "chrome/browser/task_management/providers/web_contents/devtools_tag.h" +#include "chrome/browser/task_management/providers/web_contents/guest_tag.h" #include "chrome/browser/task_management/providers/web_contents/panel_tag.h" #include "chrome/browser/task_management/providers/web_contents/prerender_tag.h" #include "chrome/browser/task_management/providers/web_contents/printing_tag.h" #include "chrome/browser/task_management/providers/web_contents/tab_contents_tag.h" #include "chrome/browser/task_management/providers/web_contents/web_contents_tags_manager.h" +#include "components/guest_view/browser/guest_view_base.h" #include "content/public/browser/web_contents.h" #if defined(ENABLE_EXTENSIONS) @@ -115,6 +117,19 @@ void WebContentsTags::CreateForPrintingContents( } // static +void WebContentsTags::CreateForGuestContents( + content::WebContents* web_contents) { +#if defined(ENABLE_TASK_MANAGER) + DCHECK(guest_view::GuestViewBase::IsGuest(web_contents)); + if (!WebContentsTag::FromWebContents(web_contents)) { + TagWebContents(web_contents, + new GuestTag(web_contents), + WebContentsTag::kTagKey); + } +#endif // defined(ENABLE_TASK_MANAGER) +} + +// static void WebContentsTags::ClearTag(content::WebContents* web_contents) { #if defined(ENABLE_TASK_MANAGER) const WebContentsTag* tag = WebContentsTag::FromWebContents(web_contents); diff --git a/chrome/browser/task_management/web_contents_tags.h b/chrome/browser/task_management/web_contents_tags.h index 15e7b3c..92d58f1 100644 --- a/chrome/browser/task_management/web_contents_tags.h +++ b/chrome/browser/task_management/web_contents_tags.h @@ -69,6 +69,13 @@ class WebContentsTags { // up by the caller, as it is owned by |web_contents|. static void CreateForPrintingContents(content::WebContents* web_contents); + // Tag a WebContents owned by a GuestViewBase so that it shows up in the + // task manager. Calling this function creates a GuestTag, and attaches it to + // |web_contents|. If an instance is already attached, this does nothing. The + // resulting tag does not have to be cleaned up by the caller, as it is owned + // by |web_contents|. + static void CreateForGuestContents(content::WebContents* web_contents); + // Clears the task-manager tag, created by any of the above functions, from // the given |web_contents| if any. // Clearing the tag is necessary only when you need to re-tag an existing diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 68d568a..1a7bdea 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1433,6 +1433,8 @@ 'browser/drive/drive_notification_manager_factory.h', 'browser/guest_view/app_view/chrome_app_view_guest_delegate.cc', 'browser/guest_view/app_view/chrome_app_view_guest_delegate.h', + 'browser/guest_view/chrome_guest_view_manager_delegate.cc', + 'browser/guest_view/chrome_guest_view_manager_delegate.h', 'browser/guest_view/extension_options/chrome_extension_options_guest_delegate.cc', 'browser/guest_view/extension_options/chrome_extension_options_guest_delegate.h', 'browser/guest_view/mime_handler_view/chrome_mime_handler_view_guest_delegate.cc', @@ -2997,6 +2999,10 @@ 'browser/task_management/providers/web_contents/devtools_tag.h', 'browser/task_management/providers/web_contents/devtools_task.cc', 'browser/task_management/providers/web_contents/devtools_task.h', + 'browser/task_management/providers/web_contents/guest_tag.cc', + 'browser/task_management/providers/web_contents/guest_tag.h', + 'browser/task_management/providers/web_contents/guest_task.cc', + 'browser/task_management/providers/web_contents/guest_task.h', 'browser/task_management/providers/web_contents/panel_tag.cc', 'browser/task_management/providers/web_contents/panel_tag.h', 'browser/task_management/providers/web_contents/panel_task.cc', diff --git a/components/guest_view/browser/guest_view_manager.cc b/components/guest_view/browser/guest_view_manager.cc index fa40a76..8fdc082 100644 --- a/components/guest_view/browser/guest_view_manager.cc +++ b/components/guest_view/browser/guest_view_manager.cc @@ -239,6 +239,9 @@ void GuestViewManager::AddGuest(int guest_instance_id, CHECK(!ContainsKey(guest_web_contents_by_instance_id_, guest_instance_id)); CHECK(CanUseGuestInstanceID(guest_instance_id)); guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; + + // Make |guest_web_contents| show up in the task manager. + delegate_->AttachTaskManagerGuestTag(guest_web_contents); } void GuestViewManager::RemoveGuest(int guest_instance_id) { diff --git a/components/guest_view/browser/guest_view_manager_delegate.h b/components/guest_view/browser/guest_view_manager_delegate.h index a46c278d..9a56633 100644 --- a/components/guest_view/browser/guest_view_manager_delegate.h +++ b/components/guest_view/browser/guest_view_manager_delegate.h @@ -14,6 +14,10 @@ namespace base { class DictionaryValue; } // namespace base +namespace content { +class WebContents; +} // namespace content + namespace guest_view { class GuestViewBase; @@ -29,6 +33,12 @@ class GuestViewManagerDelegate { GuestViewManagerDelegate(); virtual ~GuestViewManagerDelegate(); + // Attaches the task-manager-specific tag for the GuestViews to its + // |guest_web_contents| so that their corresponding tasks show up in the task + // manager. + virtual void AttachTaskManagerGuestTag( + content::WebContents* guest_web_contents) const {} + // Dispatches the event with |name| with the provided |args| to the embedder // of the given |guest| with |instance_id| for routing. virtual void DispatchEvent(const std::string& event_name, diff --git a/extensions/browser/api/extensions_api_client.cc b/extensions/browser/api/extensions_api_client.cc index 5fc571c..8426436 100644 --- a/extensions/browser/api/extensions_api_client.cc +++ b/extensions/browser/api/extensions_api_client.cc @@ -8,6 +8,7 @@ #include "extensions/browser/api/device_permissions_prompt.h" #include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h" #include "extensions/browser/api/web_request/web_request_event_router_delegate.h" +#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h" #include "extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.h" @@ -47,6 +48,12 @@ ExtensionsAPIClient::CreateExtensionOptionsGuestDelegate( return NULL; } +scoped_ptr<guest_view::GuestViewManagerDelegate> +ExtensionsAPIClient::CreateGuestViewManagerDelegate( + content::BrowserContext* context) const { + return make_scoped_ptr(new ExtensionsGuestViewManagerDelegate(context)); +} + scoped_ptr<MimeHandlerViewGuestDelegate> ExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate( MimeHandlerViewGuest* guest) const { diff --git a/extensions/browser/api/extensions_api_client.h b/extensions/browser/api/extensions_api_client.h index 35f0114..c367906 100644 --- a/extensions/browser/api/extensions_api_client.h +++ b/extensions/browser/api/extensions_api_client.h @@ -24,6 +24,10 @@ class BrowserContext; class WebContents; } +namespace guest_view { +class GuestViewManagerDelegate; +} // namespace guest_view + namespace extensions { class AppViewGuestDelegate; @@ -83,6 +87,10 @@ class ExtensionsAPIClient { virtual ExtensionOptionsGuestDelegate* CreateExtensionOptionsGuestDelegate( ExtensionOptionsGuest* guest) const; + // Returns a delegate for GuestViewManagerDelegate. + virtual scoped_ptr<guest_view::GuestViewManagerDelegate> + CreateGuestViewManagerDelegate(content::BrowserContext* context) const; + // Creates a delegate for MimeHandlerViewGuest. virtual scoped_ptr<MimeHandlerViewGuestDelegate> CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest* guest) const; diff --git a/extensions/browser/api/guest_view/guest_view_internal_api.cc b/extensions/browser/api/guest_view/guest_view_internal_api.cc index 405f8fa..6a60f56 100644 --- a/extensions/browser/api/guest_view/guest_view_internal_api.cc +++ b/extensions/browser/api/guest_view/guest_view_internal_api.cc @@ -6,10 +6,11 @@ #include "components/guest_view/browser/guest_view_base.h" #include "components/guest_view/browser/guest_view_manager.h" +#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "components/guest_view/common/guest_view_constants.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" -#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/common/api/guest_view_internal.h" #include "extensions/common/permissions/permissions_data.h" @@ -39,8 +40,7 @@ bool GuestViewInternalCreateGuestFunction::RunAsync() { if (!guest_view_manager) { guest_view_manager = GuestViewManager::CreateWithDelegate( browser_context(), - scoped_ptr<GuestViewManagerDelegate>( - new ExtensionsGuestViewManagerDelegate(context_))); + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate(context_)); } GuestViewManager::WebContentsCreatedCallback callback = diff --git a/extensions/browser/guest_view/extensions_guest_view_manager_delegate.cc b/extensions/browser/guest_view/extensions_guest_view_manager_delegate.cc index 854c6b2..c76988f 100644 --- a/extensions/browser/guest_view/extensions_guest_view_manager_delegate.cc +++ b/extensions/browser/guest_view/extensions_guest_view_manager_delegate.cc @@ -8,6 +8,7 @@ #include "components/guest_view/browser/guest_view_manager.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/render_process_host.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/event_router.h" #include "extensions/browser/guest_view/app_view/app_view_guest.h" #include "extensions/browser/guest_view/extension_options/extension_options_guest.h" diff --git a/extensions/browser/guest_view/extensions_guest_view_message_filter.cc b/extensions/browser/guest_view/extensions_guest_view_message_filter.cc index 016fffe..838ae95 100644 --- a/extensions/browser/guest_view/extensions_guest_view_message_filter.cc +++ b/extensions/browser/guest_view/extensions_guest_view_message_filter.cc @@ -6,11 +6,12 @@ #include "components/guest_view/browser/guest_view_base.h" #include "components/guest_view/browser/guest_view_manager.h" +#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "content/public/browser/browser_thread.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 "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_constants.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" #include "extensions/browser/guest_view/web_view/web_view_content_script_manager.h" @@ -78,8 +79,8 @@ GuestViewManager* ExtensionsGuestViewMessageFilter:: if (!manager) { manager = GuestViewManager::CreateWithDelegate( browser_context_, - scoped_ptr<GuestViewManagerDelegate>( - new ExtensionsGuestViewManagerDelegate(browser_context_))); + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( + browser_context_)); } return manager; } diff --git a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc index bce24bb..ec1c0ca 100644 --- a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc +++ b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc @@ -9,6 +9,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "components/guest_view/browser/test_guest_view_manager.h" #include "content/public/test/browser_test_utils.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" @@ -16,7 +17,7 @@ #include "extensions/test/result_catcher.h" #include "net/test/embedded_test_server/embedded_test_server.h" -using extensions::ExtensionsGuestViewManagerDelegate; +using extensions::ExtensionsAPIClient; using extensions::MimeHandlerViewGuest; using extensions::TestMimeHandlerViewGuest; using guest_view::GuestViewManager; @@ -50,9 +51,8 @@ class MimeHandlerViewTest : public ExtensionApiTest { manager = static_cast<TestGuestViewManager*>( GuestViewManager::CreateWithDelegate( browser()->profile(), - scoped_ptr<GuestViewManagerDelegate>( - new ExtensionsGuestViewManagerDelegate( - browser()->profile())))); + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( + browser()->profile()))); } return manager; } diff --git a/extensions/browser/guest_view/web_view/web_view_apitest.cc b/extensions/browser/guest_view/web_view/web_view_apitest.cc index 0e1b24e..5857b73 100644 --- a/extensions/browser/guest_view/web_view/web_view_apitest.cc +++ b/extensions/browser/guest_view/web_view/web_view_apitest.cc @@ -9,6 +9,7 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "components/guest_view/browser/guest_view_manager.h" +#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "components/guest_view/browser/guest_view_manager_factory.h" #include "components/guest_view/browser/test_guest_view_manager.h" #include "content/public/browser/render_process_host.h" @@ -16,11 +17,10 @@ #include "content/public/test/browser_test_utils.h" #include "content/public/test/test_renderer_host.h" #include "content/public/test/test_utils.h" +#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/api/test/test_api.h" #include "extensions/browser/app_window/app_window.h" #include "extensions/browser/app_window/app_window_registry.h" -#include "extensions/browser/extension_host.h" -#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" #include "extensions/browser/process_manager.h" #include "extensions/common/extension.h" #include "extensions/common/extension_paths.h" @@ -255,11 +255,11 @@ TestGuestViewManager* WebViewAPITest::GetGuestViewManager() { // TestGuestViewManager::WaitForSingleGuestCreated may and will get called // before a guest is created. if (!manager) { - manager = static_cast<TestGuestViewManager*>( - GuestViewManager::CreateWithDelegate( + manager = + static_cast<TestGuestViewManager*>(GuestViewManager::CreateWithDelegate( context, - scoped_ptr<guest_view::GuestViewManagerDelegate>( - new ExtensionsGuestViewManagerDelegate(context)))); + ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( + context))); } return manager; } |