OLD | NEW |
| (Empty) |
1 // Copyright 2013 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. | |
4 | |
5 #include "chrome/browser/task_manager/task_manager_resource_util.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/i18n/rtl.h" | |
9 #include "base/string16.h" | |
10 #include "base/utf_string_conversions.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/browser/profiles/profile_info_cache.h" | |
14 #include "chrome/browser/profiles/profile_manager.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "grit/generated_resources.h" | |
17 | |
18 int TaskManagerResourceUtil::GetMessagePrefixID(bool is_app, | |
19 bool is_extension, | |
20 bool is_incognito, | |
21 bool is_prerender, | |
22 bool is_instant_overlay, | |
23 bool is_background) { | |
24 if (is_app) { | |
25 if (is_background) | |
26 return IDS_TASK_MANAGER_BACKGROUND_PREFIX; | |
27 if (is_incognito) | |
28 return IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX; | |
29 return IDS_TASK_MANAGER_APP_PREFIX; | |
30 } | |
31 if (is_extension) { | |
32 if (is_incognito) | |
33 return IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX; | |
34 return IDS_TASK_MANAGER_EXTENSION_PREFIX; | |
35 } | |
36 if (is_prerender) | |
37 return IDS_TASK_MANAGER_PRERENDER_PREFIX; | |
38 if (is_instant_overlay) | |
39 return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX; | |
40 | |
41 return IDS_TASK_MANAGER_TAB_PREFIX; | |
42 } | |
43 | |
44 string16 TaskManagerResourceUtil::GetProfileNameFromInfoCache( | |
45 Profile* profile) { | |
46 DCHECK(profile); | |
47 | |
48 ProfileInfoCache& cache = | |
49 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
50 size_t index = cache.GetIndexOfProfileWithPath( | |
51 profile->GetOriginalProfile()->GetPath()); | |
52 if (index == std::string::npos) | |
53 return string16(); | |
54 else | |
55 return cache.GetNameOfProfileAtIndex(index); | |
56 } | |
57 | |
58 string16 TaskManagerResourceUtil::GetTitleFromWebContents( | |
59 content::WebContents* web_contents) { | |
60 DCHECK(web_contents); | |
61 | |
62 string16 title = web_contents->GetTitle(); | |
63 if (title.empty()) { | |
64 GURL url = web_contents->GetURL(); | |
65 title = UTF8ToUTF16(url.spec()); | |
66 // Force URL to be LTR. | |
67 title = base::i18n::GetDisplayStringInLTRDirectionality(title); | |
68 } else { | |
69 // Since the tab_title will be concatenated with | |
70 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to | |
71 // be LTR format if there is no strong RTL charater in it. Otherwise, if | |
72 // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result | |
73 // might be wrong. For example, http://mail.yahoo.com, whose title is | |
74 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly | |
75 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best | |
76 // web-based Email :BAT", in which the capital letters "BAT" stands for | |
77 // the Hebrew word for "tab". | |
78 base::i18n::AdjustStringForLocaleDirection(&title); | |
79 } | |
80 return title; | |
81 } | |
OLD | NEW |