diff options
author | stuartmorgan@google.com <stuartmorgan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 19:12:37 +0000 |
---|---|---|
committer | stuartmorgan@google.com <stuartmorgan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 19:12:37 +0000 |
commit | 996fd703fb7229e931203edc77df436aea9bc9a5 (patch) | |
tree | e52458f9e43ec4762ce58c3b15a235ad31e3d667 | |
parent | f62a8906648ddfcee0ffa9604939d4c7f66891aa (diff) | |
download | chromium_src-996fd703fb7229e931203edc77df436aea9bc9a5.zip chromium_src-996fd703fb7229e931203edc77df436aea9bc9a5.tar.gz chromium_src-996fd703fb7229e931203edc77df436aea9bc9a5.tar.bz2 |
Strip .plugin off of Mac plugin names when showing the crash info bar.
BUG=21029
TEST=Kill a plugin process; the plugin crash info bar shouldn't have ".plugin" in the plugin name.
Review URL: http://codereview.chromium.org/197018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25487 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/string_util.cc | 16 | ||||
-rw-r--r-- | base/string_util.h | 6 | ||||
-rw-r--r-- | base/string_util_unittest.cc | 19 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 11 |
4 files changed, 51 insertions, 1 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index 1edc0d9..82b6c0b 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -773,6 +773,22 @@ bool StartsWith(const std::wstring& str, } } +bool EndsWith(const std::wstring& str, + const std::wstring& search, + bool case_sensitive) { + std::wstring::size_type str_length = str.length(); + std::wstring::size_type search_length = search.length(); + if (search_length > str_length) + return false; + if (case_sensitive) { + return str.compare(str_length - search_length, search_length, search) == 0; + } else { + return std::equal(search.begin(), search.end(), + str.begin() + (str_length - search_length), + CaseInsensitiveCompare<wchar_t>()); + } +} + DataUnits GetByteDisplayUnits(int64 bytes) { // The byte thresholds at which we display amounts. A byte count is displayed // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1]. diff --git a/base/string_util.h b/base/string_util.h index c7f3115..0ae0185 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -363,6 +363,12 @@ bool StartsWith(const std::wstring& str, const std::wstring& search, bool case_sensitive); +// Returns true if str ends with search, or false otherwise. +bool EndsWith(const std::wstring& str, + const std::wstring& search, + bool case_sensitive); + + // Determines the type of ASCII character, independent of locale (the C // library versions will change based on locale). template <typename Char> diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 35c58d6..b11a999 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -1576,6 +1576,25 @@ TEST(StringUtilTest, StartsWith) { EXPECT_TRUE(StartsWith(L"java", L"", true)); } +TEST(StringUtilTest, EndsWith) { + EXPECT_TRUE(EndsWith(L"Foo.plugin", L".plugin", true)); + EXPECT_FALSE(EndsWith(L"Foo.Plugin", L".plugin", true)); + EXPECT_TRUE(EndsWith(L"Foo.plugin", L".plugin", false)); + EXPECT_TRUE(EndsWith(L"Foo.Plugin", L".plugin", false)); + EXPECT_FALSE(EndsWith(L".plug", L".plugin", true)); + EXPECT_FALSE(EndsWith(L".plug", L".plugin", false)); + EXPECT_FALSE(EndsWith(L"Foo.plugin Bar", L".plugin", true)); + EXPECT_FALSE(EndsWith(L"Foo.plugin Bar", L".plugin", false)); + EXPECT_FALSE(EndsWith(L"", L".plugin", false)); + EXPECT_FALSE(EndsWith(L"", L".plugin", true)); + EXPECT_TRUE(EndsWith(L"Foo.plugin", L"", false)); + EXPECT_TRUE(EndsWith(L"Foo.plugin", L"", true)); + EXPECT_TRUE(EndsWith(L".plugin", L".plugin", false)); + EXPECT_TRUE(EndsWith(L".plugin", L".plugin", true)); + EXPECT_TRUE(EndsWith(L"", L"", false)); + EXPECT_TRUE(EndsWith(L"", L"", true)); +} + TEST(StringUtilTest, GetStringFWithOffsets) { std::vector<string16> subst; subst.push_back(ASCIIToUTF16("1")); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 083296c..c76b733 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -9,6 +9,7 @@ #include "base/file_version_info.h" #include "base/process_util.h" #include "base/string16.h" +#include "base/string_util.h" #include "base/time.h" #include "chrome/browser/autofill_manager.h" #include "chrome/browser/blocked_popup_container.h" @@ -1657,8 +1658,16 @@ void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { FileVersionInfo::CreateFileVersionInfo(plugin_path)); if (version_info.get()) { const std::wstring& product_name = version_info->product_name(); - if (!product_name.empty()) + if (!product_name.empty()) { plugin_name = product_name; +#if defined(OS_MACOSX) + // Many plugins on the Mac have .plugin in the actual name, which looks + // terrible, so look for that and strip it off if present. + const std::wstring plugin_extension(L".plugin"); + if (EndsWith(plugin_name, plugin_extension, true)) + plugin_name.erase(plugin_name.length() - plugin_extension.length()); +#endif // OS_MACOSX + } } #else NOTIMPLEMENTED() << " convert plugin path to plugin name"; |