Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / task_management / providers / web_contents / tab_contents_task.cc
blob55271f9245546e3dee721490520b4ab7e979d9f5
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/task_management/providers/web_contents/tab_contents_task.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/web_contents.h"
10 #include "extensions/browser/extension_registry.h"
11 #include "extensions/browser/process_map.h"
12 #include "extensions/common/constants.h"
14 namespace task_management {
16 namespace {
18 bool HostsExtension(content::WebContents* web_contents) {
19 DCHECK(web_contents);
20 return web_contents->GetURL().SchemeIs(extensions::kExtensionScheme);
23 } // namespace
26 TabContentsTask::TabContentsTask(content::WebContents* web_contents)
27 : RendererTask(base::string16(),
28 RendererTask::GetFaviconFromWebContents(web_contents),
29 web_contents,
30 web_contents->GetRenderProcessHost()) {
31 set_title(GetCurrentTitle());
34 TabContentsTask::~TabContentsTask() {
37 void TabContentsTask::UpdateTitle() {
38 set_title(GetCurrentTitle());
41 void TabContentsTask::UpdateFavicon() {
42 const gfx::ImageSkia* icon =
43 RendererTask::GetFaviconFromWebContents(web_contents());
44 set_icon(icon ? *icon : gfx::ImageSkia());
47 Task::Type TabContentsTask::GetType() const {
48 // A tab that loads an extension URL is considered to be an extension even
49 // though it's tracked as a TabContentsTask.
50 return HostsExtension(web_contents()) ? Task::EXTENSION : Task::RENDERER;
53 base::string16 TabContentsTask::GetCurrentTitle() const {
54 // Check if the URL is an app and if the tab is hoisting an extension.
55 Profile* profile =
56 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
57 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
58 extensions::ExtensionRegistry* extension_registry =
59 extensions::ExtensionRegistry::Get(profile);
60 GURL url = web_contents()->GetURL();
62 bool is_app = process_map->Contains(process_id()) &&
63 extension_registry->enabled_extensions().GetAppByURL(url) != nullptr;
64 bool is_extension = HostsExtension(web_contents());
65 bool is_incognito = profile->IsOffTheRecord();
67 base::string16 tab_title =
68 RendererTask::GetTitleFromWebContents(web_contents());
70 // Fall back to the URL if the title is empty.
71 return PrefixRendererTitle(tab_title,
72 is_app,
73 is_extension,
74 is_incognito,
75 false); // is_background.
78 } // namespace task_management