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