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