Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / task_management / providers / web_contents / tab_contents_task.cc
blob20ebbe79e2377a6e94fb43158c78d6c0359fec75
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 set_icon(*RendererTask::GetFaviconFromWebContents(web_contents()));
45 Task::Type TabContentsTask::GetType() const {
46 // A tab that loads an extension URL is considered to be an extension even
47 // though it's tracked as a TabContentsTask.
48 return HostsExtension(web_contents()) ? Task::EXTENSION : Task::RENDERER;
51 base::string16 TabContentsTask::GetCurrentTitle() const {
52 // Check if the URL is an app and if the tab is hoisting an extension.
53 Profile* profile =
54 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
55 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
56 extensions::ExtensionRegistry* extension_registry =
57 extensions::ExtensionRegistry::Get(profile);
58 GURL url = web_contents()->GetURL();
59 base::string16 url_spec = base::UTF8ToUTF16(url.spec());
61 bool is_app = process_map->Contains(process_id()) &&
62 extension_registry->enabled_extensions().GetAppByURL(url) != nullptr;
63 bool is_extension = HostsExtension(web_contents());
64 bool is_incognito = profile->IsOffTheRecord();
66 base::string16 tab_title =
67 RendererTask::GetTitleFromWebContents(web_contents());
69 // Fall back to the URL if the title is empty.
70 return PrefixRendererTitle(tab_title.empty() ? url_spec : tab_title,
71 is_app,
72 is_extension,
73 is_incognito,
74 false); // is_background.
77 } // namespace task_management