diff options
author | afakhry <afakhry@chromium.org> | 2015-08-20 22:43:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-21 05:44:47 +0000 |
commit | 16eec42f36533d656bd9f1be39a71238a6f06e6d (patch) | |
tree | 4d4e8d373c118b4555d940e761175d306299bf3b | |
parent | 1c170958398caa74605603eb6c12948d00072385 (diff) | |
download | chromium_src-16eec42f36533d656bd9f1be39a71238a6f06e6d.zip chromium_src-16eec42f36533d656bd9f1be39a71238a6f06e6d.tar.gz chromium_src-16eec42f36533d656bd9f1be39a71238a6f06e6d.tar.bz2 |
OOPIF: Fix the new task manager to show the correct proc IDs of subframe procs
We used to get the RenderProcessHost from the WebContents. This doesn't
work for out-of-process RenderFrameHosts.
BUG=522293
TEST=browser_tests --gtest_filter=SubframeTaskBrowserTest.*
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_site_isolation
Review URL: https://codereview.chromium.org/1296883007
Cr-Commit-Position: refs/heads/master@{#344690}
13 files changed, 165 insertions, 16 deletions
diff --git a/chrome/browser/task_management/providers/web_contents/background_contents_task.cc b/chrome/browser/task_management/providers/web_contents/background_contents_task.cc index 439c144..85f37f2 100644 --- a/chrome/browser/task_management/providers/web_contents/background_contents_task.cc +++ b/chrome/browser/task_management/providers/web_contents/background_contents_task.cc @@ -58,10 +58,11 @@ base::string16 AdjustAndLocalizeTitle(const base::string16& title, BackgroundContentsTask::BackgroundContentsTask( const base::string16& title, BackgroundContents* background_contents) - : RendererTask(AdjustAndLocalizeTitle(title, - background_contents->GetURL().spec()), - GetDefaultIcon(), - background_contents->web_contents()) { + : RendererTask( + AdjustAndLocalizeTitle(title, background_contents->GetURL().spec()), + GetDefaultIcon(), + background_contents->web_contents(), + background_contents->web_contents()->GetRenderProcessHost()) { } BackgroundContentsTask::~BackgroundContentsTask() { diff --git a/chrome/browser/task_management/providers/web_contents/devtools_task.cc b/chrome/browser/task_management/providers/web_contents/devtools_task.cc index 76148e2..f0da9f4 100644 --- a/chrome/browser/task_management/providers/web_contents/devtools_task.cc +++ b/chrome/browser/task_management/providers/web_contents/devtools_task.cc @@ -4,12 +4,15 @@ #include "chrome/browser/task_management/providers/web_contents/devtools_task.h" +#include "content/public/browser/web_contents.h" + namespace task_management { DevToolsTask::DevToolsTask(content::WebContents* web_contents) : RendererTask(RendererTask::GetTitleFromWebContents(web_contents), RendererTask::GetFaviconFromWebContents(web_contents), - web_contents) { + web_contents, + web_contents->GetRenderProcessHost()) { } DevToolsTask::~DevToolsTask() { diff --git a/chrome/browser/task_management/providers/web_contents/extension_task.cc b/chrome/browser/task_management/providers/web_contents/extension_task.cc index acbfde1..a63781a 100644 --- a/chrome/browser/task_management/providers/web_contents/extension_task.cc +++ b/chrome/browser/task_management/providers/web_contents/extension_task.cc @@ -38,7 +38,8 @@ ExtensionTask::ExtensionTask(content::WebContents* web_contents, extensions::ViewType view_type) : RendererTask(GetExtensionTitle(web_contents, extension, view_type), GetDefaultIcon(), - web_contents) { + web_contents, + web_contents->GetRenderProcessHost()) { } ExtensionTask::~ExtensionTask() { diff --git a/chrome/browser/task_management/providers/web_contents/guest_task.cc b/chrome/browser/task_management/providers/web_contents/guest_task.cc index db34777..6c959b4 100644 --- a/chrome/browser/task_management/providers/web_contents/guest_task.cc +++ b/chrome/browser/task_management/providers/web_contents/guest_task.cc @@ -5,6 +5,7 @@ #include "chrome/browser/task_management/providers/web_contents/guest_task.h" #include "components/guest_view/browser/guest_view_base.h" +#include "content/public/browser/web_contents.h" #include "ui/base/l10n/l10n_util.h" namespace task_management { @@ -12,7 +13,8 @@ namespace task_management { GuestTask::GuestTask(content::WebContents* web_contents) : RendererTask(GetCurrentTitle(web_contents), GetFaviconFromWebContents(web_contents), - web_contents) { + web_contents, + web_contents->GetRenderProcessHost()) { } GuestTask::~GuestTask() { diff --git a/chrome/browser/task_management/providers/web_contents/panel_task.cc b/chrome/browser/task_management/providers/web_contents/panel_task.cc index 5198adc..ce07140 100644 --- a/chrome/browser/task_management/providers/web_contents/panel_task.cc +++ b/chrome/browser/task_management/providers/web_contents/panel_task.cc @@ -7,6 +7,7 @@ #include "base/i18n/rtl.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/panels/panel.h" +#include "content/public/browser/web_contents.h" #include "extensions/browser/extension_registry.h" #include "ui/gfx/image/image_skia.h" @@ -24,7 +25,8 @@ const gfx::ImageSkia* GetPanelIcon(Panel* panel) { PanelTask::PanelTask(Panel* panel, content::WebContents* web_contents) : RendererTask(GetCurrentPanelTitle(panel), GetPanelIcon(panel), - web_contents), + web_contents, + web_contents->GetRenderProcessHost()), panel_(panel) { } diff --git a/chrome/browser/task_management/providers/web_contents/prerender_task.cc b/chrome/browser/task_management/providers/web_contents/prerender_task.cc index dc039b4..616edad 100644 --- a/chrome/browser/task_management/providers/web_contents/prerender_task.cc +++ b/chrome/browser/task_management/providers/web_contents/prerender_task.cc @@ -5,6 +5,7 @@ #include "chrome/browser/task_management/providers/web_contents/prerender_task.h" #include "chrome/grit/generated_resources.h" +#include "content/public/browser/web_contents.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" @@ -40,7 +41,8 @@ PrerenderTask::PrerenderTask(content::WebContents* web_contents) : RendererTask( PrefixTitle(RendererTask::GetTitleFromWebContents(web_contents)), GetPrerenderIcon(), - web_contents) { + web_contents, + web_contents->GetRenderProcessHost()) { } PrerenderTask::~PrerenderTask() { diff --git a/chrome/browser/task_management/providers/web_contents/printing_task.cc b/chrome/browser/task_management/providers/web_contents/printing_task.cc index 2fe02b2..fef4efc 100644 --- a/chrome/browser/task_management/providers/web_contents/printing_task.cc +++ b/chrome/browser/task_management/providers/web_contents/printing_task.cc @@ -5,6 +5,7 @@ #include "chrome/browser/task_management/providers/web_contents/printing_task.h" #include "chrome/grit/generated_resources.h" +#include "content/public/browser/web_contents.h" #include "ui/base/l10n/l10n_util.h" namespace task_management { @@ -21,7 +22,8 @@ PrintingTask::PrintingTask(content::WebContents* web_contents) : RendererTask( PrefixTitle(RendererTask::GetTitleFromWebContents(web_contents)), RendererTask::GetFaviconFromWebContents(web_contents), - web_contents) { + web_contents, + web_contents->GetRenderProcessHost()) { } PrintingTask::~PrintingTask() { diff --git a/chrome/browser/task_management/providers/web_contents/renderer_task.cc b/chrome/browser/task_management/providers/web_contents/renderer_task.cc index 86021b4..6b5acad 100644 --- a/chrome/browser/task_management/providers/web_contents/renderer_task.cc +++ b/chrome/browser/task_management/providers/web_contents/renderer_task.cc @@ -63,10 +63,11 @@ inline bool IsRendererResourceSamplingDisabled(int64 flags) { RendererTask::RendererTask(const base::string16& title, const gfx::ImageSkia* icon, - content::WebContents* web_contents) - : Task(title, icon, web_contents->GetRenderProcessHost()->GetHandle()), + content::WebContents* web_contents, + content::RenderProcessHost* render_process_host) + : Task(title, icon, render_process_host->GetHandle()), web_contents_(web_contents), - render_process_host_(web_contents->GetRenderProcessHost()), + render_process_host_(render_process_host), renderer_resources_sampler_( CreateRendererResourcesSampler(render_process_host_)), render_process_id_(render_process_host_->GetID()), diff --git a/chrome/browser/task_management/providers/web_contents/renderer_task.h b/chrome/browser/task_management/providers/web_contents/renderer_task.h index 74d3553..45434c3 100644 --- a/chrome/browser/task_management/providers/web_contents/renderer_task.h +++ b/chrome/browser/task_management/providers/web_contents/renderer_task.h @@ -23,7 +23,8 @@ class RendererTask : public Task { public: RendererTask(const base::string16& title, const gfx::ImageSkia* icon, - content::WebContents* web_contents); + content::WebContents* web_contents, + content::RenderProcessHost* render_process_host); ~RendererTask() override; // An abstract method that will be called when the event diff --git a/chrome/browser/task_management/providers/web_contents/subframe_task.cc b/chrome/browser/task_management/providers/web_contents/subframe_task.cc index 34df977..ee9c715 100644 --- a/chrome/browser/task_management/providers/web_contents/subframe_task.cc +++ b/chrome/browser/task_management/providers/web_contents/subframe_task.cc @@ -33,7 +33,11 @@ SubframeTask::SubframeTask(content::RenderFrameHost* render_frame_host, content::WebContents* web_contents) : RendererTask(AdjustTitle(render_frame_host->GetSiteInstance()), nullptr, - web_contents) { + web_contents, + render_frame_host->GetProcess()) { + // Note that we didn't get the RenderProcessHost from the WebContents, but + // rather from the RenderFrameHost. Out-of-process iframes reside on + // different processes than that of their main frame. } SubframeTask::~SubframeTask() { diff --git a/chrome/browser/task_management/providers/web_contents/subframe_task_browsertest.cc b/chrome/browser/task_management/providers/web_contents/subframe_task_browsertest.cc new file mode 100644 index 0000000..53df079 --- /dev/null +++ b/chrome/browser/task_management/providers/web_contents/subframe_task_browsertest.cc @@ -0,0 +1,128 @@ +// 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 "base/strings/utf_string_conversions.h" +#include "chrome/browser/task_management/task_management_browsertest_util.h" +#include "chrome/grit/generated_resources.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/public/test/browser_test_utils.h" +#include "content/public/test/test_utils.h" +#include "net/dns/mock_host_resolver.h" +#include "net/test/embedded_test_server/embedded_test_server.h" +#include "ui/base/l10n/l10n_util.h" + +namespace task_management { + +namespace { + +// URL of a test page on a.com that has two cross-site iframes to b.com and +// c.com. +const char kCrossSitePageUrl[] = "/cross-site/a.com/iframe_cross_site.html"; + +// URL of a test page on a.com that has no cross-site iframes. +const char kSimplePageUrl[] = "/cross-site/a.com/title2.html"; + +base::string16 GetExpectedSubframeTitlePrefix() { + return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_SUBFRAME_PREFIX, + base::string16()); +} + +base::string16 PrefixExpectedTabTitle(const char* title) { + return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, + base::UTF8ToUTF16(title)); +} + +} // namespace + +// A test for OOPIFs and how they show up in the task manager as +// SubframeTasks. +class SubframeTaskBrowserTest : public InProcessBrowserTest { + public: + SubframeTaskBrowserTest() {} + ~SubframeTaskBrowserTest() override {} + + void SetUpCommandLine(base::CommandLine* command_line) override { + InProcessBrowserTest::SetUpCommandLine(command_line); + content::IsolateAllSitesForTesting(command_line); + } + + void SetUpOnMainThread() override { + host_resolver()->AddRule("*", "127.0.0.1"); + ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); + content::SetupCrossSiteRedirector(embedded_test_server()); + } + + void NavigateTo(const char* page_url) const { + ui_test_utils::NavigateToURL(browser(), + embedded_test_server()->GetURL(page_url)); + } + + private: + DISALLOW_COPY_AND_ASSIGN(SubframeTaskBrowserTest); +}; + +// Makes sure that, if sites are isolated, the task manager will show the +// expected SubframeTasks, and they will be shown as running on different +// processes as expected. +IN_PROC_BROWSER_TEST_F(SubframeTaskBrowserTest, TaskManagerShowsSubframeTasks) { + MockWebContentsTaskManager task_manager; + EXPECT_TRUE(task_manager.tasks().empty()); + task_manager.StartObserving(); + + // Currently only the about:blank page. + ASSERT_EQ(1U, task_manager.tasks().size()); + const Task* about_blank_task = task_manager.tasks().front(); + EXPECT_EQ(Task::RENDERER, about_blank_task->GetType()); + EXPECT_EQ(PrefixExpectedTabTitle("about:blank"), about_blank_task->title()); + + NavigateTo(kCrossSitePageUrl); + + // Whether sites are isolated or not, we expect to have at least one tab + // contents task. + ASSERT_GE(task_manager.tasks().size(), 1U); + const Task* cross_site_task = task_manager.tasks().front(); + EXPECT_EQ(Task::RENDERER, cross_site_task->GetType()); + EXPECT_EQ(PrefixExpectedTabTitle("cross-site iframe test"), + cross_site_task->title()); + + if (!content::AreAllSitesIsolatedForTesting()) { + // Sites are not isolated. No SubframeTasks are expected, just the above + // task. + ASSERT_EQ(1U, task_manager.tasks().size()); + } else { + // Sites are isolated. We expect, in addition to the above task, two more + // SubframeTasks, one for b.com and another for c.com. + ASSERT_EQ(3U, task_manager.tasks().size()); + const Task* subframe_task_1 = task_manager.tasks()[1]; + const Task* subframe_task_2 = task_manager.tasks()[2]; + + EXPECT_EQ(Task::RENDERER, subframe_task_1->GetType()); + EXPECT_EQ(Task::RENDERER, subframe_task_2->GetType()); + + EXPECT_TRUE(base::StartsWith(subframe_task_1->title(), + GetExpectedSubframeTitlePrefix(), + base::CompareCase::INSENSITIVE_ASCII)); + EXPECT_TRUE(base::StartsWith(subframe_task_2->title(), + GetExpectedSubframeTitlePrefix(), + base::CompareCase::INSENSITIVE_ASCII)); + + // All tasks must be running on different processes. + EXPECT_NE(subframe_task_1->process_id(), subframe_task_2->process_id()); + EXPECT_NE(subframe_task_1->process_id(), cross_site_task->process_id()); + EXPECT_NE(subframe_task_2->process_id(), cross_site_task->process_id()); + } + + // If we navigate to the simple page on a.com which doesn't have cross-site + // iframes, we expect not to have any SubframeTasks. + NavigateTo(kSimplePageUrl); + + ASSERT_EQ(1U, task_manager.tasks().size()); + const Task* simple_page_task = task_manager.tasks().front(); + EXPECT_EQ(Task::RENDERER, simple_page_task->GetType()); + EXPECT_EQ(PrefixExpectedTabTitle("Title Of Awesomeness"), + simple_page_task->title()); +} + +} // namespace task_management diff --git a/chrome/browser/task_management/providers/web_contents/tab_contents_task.cc b/chrome/browser/task_management/providers/web_contents/tab_contents_task.cc index ac8a59b..20ebbe7 100644 --- a/chrome/browser/task_management/providers/web_contents/tab_contents_task.cc +++ b/chrome/browser/task_management/providers/web_contents/tab_contents_task.cc @@ -26,7 +26,8 @@ bool HostsExtension(content::WebContents* web_contents) { TabContentsTask::TabContentsTask(content::WebContents* web_contents) : RendererTask(base::string16(), RendererTask::GetFaviconFromWebContents(web_contents), - web_contents) { + web_contents, + web_contents->GetRenderProcessHost()) { set_title(GetCurrentTitle()); } diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 9831847..e6133d3 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -420,6 +420,7 @@ 'browser/task_management/providers/web_contents/background_contents_tag_browsertest.cc', 'browser/task_management/providers/web_contents/devtools_tag_browsertest.cc', 'browser/task_management/providers/web_contents/extension_tag_browsertest.cc', + 'browser/task_management/providers/web_contents/subframe_task_browsertest.cc', 'browser/task_management/providers/web_contents/tab_contents_tag_browsertest.cc', 'browser/task_manager/task_manager_browsertest.cc', 'browser/task_manager/task_manager_browsertest_util.cc', |