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