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/background_contents_task.h"
7 #include "base/i18n/rtl.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/background/background_contents_service.h"
10 #include "chrome/browser/background/background_contents_service_factory.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/view_type_utils.h"
18 #include "extensions/common/extension_set.h"
19 #include "grit/theme_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/image/image_skia.h"
24 namespace task_management
{
28 // The default icon for the background webcontents task.
29 gfx::ImageSkia
* g_default_icon
= nullptr;
31 gfx::ImageSkia
* GetDefaultIcon() {
32 if (!g_default_icon
&& ResourceBundle::HasSharedInstance()) {
33 g_default_icon
= ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
37 return g_default_icon
;
40 base::string16
AdjustAndLocalizeTitle(const base::string16
& title
,
41 const std::string
& url_spec
) {
42 base::string16
localized_title(title
);
43 if (localized_title
.empty()) {
44 // No title (can't locate the parent app for some reason) so just display
45 // the URL (properly forced to be LTR).
46 localized_title
= base::i18n::GetDisplayStringInLTRDirectionality(
47 base::UTF8ToUTF16(url_spec
));
50 // Ensure that the string has the appropriate direction markers.
51 base::i18n::AdjustStringForLocaleDirection(&localized_title
);
52 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_BACKGROUND_APP_PREFIX
,
58 BackgroundContentsTask::BackgroundContentsTask(
59 const base::string16
& title
,
60 BackgroundContents
* background_contents
)
62 AdjustAndLocalizeTitle(title
, background_contents
->GetURL().spec()),
64 background_contents
->web_contents(),
65 background_contents
->web_contents()->GetRenderProcessHost()) {
68 BackgroundContentsTask::~BackgroundContentsTask() {
71 void BackgroundContentsTask::UpdateTitle() {
72 // TODO(afakhry): At the time of integration testing figure out whether we
73 // need to change the title of the task here.
76 void BackgroundContentsTask::UpdateFavicon() {
77 // We don't do anything here. For background contents we always use the
81 } // namespace task_management