Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / task_management / providers / web_contents / tab_contents_task.cc
blob9e36039e5817a94e82e0b66790110f5d69cdf98a
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::OnTitleChanged(content::NavigationEntry* entry) {
38 set_title(GetCurrentTitle());
41 void TabContentsTask::OnFaviconChanged() {
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();
61 base::string16 url_spec = base::UTF8ToUTF16(url.spec());
63 bool is_app = process_map->Contains(process_id()) &&
64 extension_registry->enabled_extensions().GetAppByURL(url) != nullptr;
65 bool is_extension = HostsExtension(web_contents());
66 bool is_incognito = profile->IsOffTheRecord();
68 base::string16 tab_title =
69 RendererTask::GetTitleFromWebContents(web_contents());
71 // Fall back to the URL if the title is empty.
72 return PrefixRendererTitle(tab_title.empty() ? url_spec : tab_title,
73 is_app,
74 is_extension,
75 is_incognito,
76 false); // is_background.
79 } // namespace task_management