1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/task_manager/providers/web_contents/tab_contents_task.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_contents.h"
#if !BUILDFLAG(IS_ANDROID)
#include "extensions/browser/extension_registry.h" // nogncheck
#include "extensions/browser/process_map.h" // nogncheck
#include "extensions/common/constants.h" // nogncheck
#endif // !BUILDFLAG(IS_ANDROID)
namespace task_manager {
namespace {
bool HostsExtension(content::WebContents* web_contents) {
DCHECK(web_contents);
#if BUILDFLAG(IS_ANDROID)
return false;
#else // BUILDFLAG(IS_ANDROID)
return web_contents->GetLastCommittedURL().SchemeIs(
extensions::kExtensionScheme);
#endif // BUILDFLAG(IS_ANDROID)
}
} // namespace
TabContentsTask::TabContentsTask(content::WebContents* web_contents)
: RendererTask(std::u16string(),
RendererTask::GetFaviconFromWebContents(web_contents),
web_contents) {
set_title(GetCurrentTitle());
}
TabContentsTask::~TabContentsTask() = default;
void TabContentsTask::UpdateTitle() {
set_title(GetCurrentTitle());
}
void TabContentsTask::UpdateFavicon() {
DefaultUpdateFaviconImpl();
}
Task::Type TabContentsTask::GetType() const {
// A tab that loads an extension URL is considered to be an extension even
// though it's tracked as a TabContentsTask.
return HostsExtension(web_contents()) ? Task::EXTENSION : Task::RENDERER;
}
std::u16string TabContentsTask::GetCurrentTitle() const {
// Check if the URL is an app and if the tab is hoisting an extension.
Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
#if BUILDFLAG(IS_ANDROID)
bool is_app = false;
#else // BUILDFLAG(IS_ANDROID)
extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
extensions::ExtensionRegistry* extension_registry =
extensions::ExtensionRegistry::Get(profile);
GURL url = web_contents()->GetLastCommittedURL();
bool is_app = process_map->Contains(GetChildProcessUniqueID()) &&
extension_registry->enabled_extensions().GetAppByURL(url) != nullptr;
#endif // BUILDFLAG(IS_ANDROID)
bool is_extension = HostsExtension(web_contents());
bool is_incognito = profile->IsOffTheRecord();
std::u16string tab_title =
RendererTask::GetTitleFromWebContents(web_contents());
// Fall back to the URL if the title is empty.
return PrefixRendererTitle(tab_title,
is_app,
is_extension,
is_incognito,
false); // is_background.
}
} // namespace task_manager
|