diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-21 16:47:44 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-21 16:47:44 +0000 |
commit | 4926e54ada598ecce30237b2e4d0ad5580709536 (patch) | |
tree | f7c2defd33c6e6fe2d461f3092b9f47e7f959178 | |
parent | d7828c27c67a11e316b6ba8679ac91300715d97e (diff) | |
download | chromium_src-4926e54ada598ecce30237b2e4d0ad5580709536.zip chromium_src-4926e54ada598ecce30237b2e4d0ad5580709536.tar.gz chromium_src-4926e54ada598ecce30237b2e4d0ad5580709536.tar.bz2 |
Remove wstrings from bookmarks, part 8.
Convert lots of uses of the wstring BookmarkNode::GetTitle() in browser/cocoa.
BUG=23581
TEST=builds and passes
Review URL: http://codereview.chromium.org/3113028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56996 0039d316-1c4b-4281-b951-d872f2087c98
14 files changed, 41 insertions, 35 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index 3214a67..14fdecb 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -984,7 +984,7 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; // Add a tooltip std::string url_string = child->GetURL().possibly_invalid_spec(); NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", - base::SysWideToNSString(child->GetTitle()), + base::SysUTF16ToNSString(child->GetTitleAsString16()), url_string.c_str()]; [item setToolTip:tooltip]; } @@ -1013,7 +1013,7 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node { if (!node->is_folder()) return nil; - NSString* title = base::SysWideToNSString(node->GetTitle()); + NSString* title = base::SysUTF16ToNSString(node->GetTitleAsString16()); NSMenu* menu = [[[NSMenu alloc] initWithTitle:title] autorelease]; [self addFolderNode:node toMenu:menu]; @@ -1105,7 +1105,7 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; [button setTarget:self]; [button setAction:@selector(openBookmark:)]; // Add a tooltip. - NSString* title = base::SysWideToNSString(node->GetTitle()); + NSString* title = base::SysUTF16ToNSString(node->GetTitleAsString16()); std::string url_string = node->GetURL().possibly_invalid_spec(); NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title, url_string.c_str()]; diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm index 494b58d..b04455e 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm @@ -1014,11 +1014,11 @@ TEST_F(BookmarkBarControllerTest, DropBookmarks) { "javascript:alert('lolwut')", "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. }; - std::wstring titles[] = { - std::wstring(L"Philosophoraptor"), - std::wstring(L"Can't draw"), - std::wstring(L"Inspiration"), - std::wstring(L"Frum stuf") + const char* titles[] = { + "Philosophoraptor", + "Can't draw", + "Inspiration", + "Frum stuf" }; EXPECT_EQ(arraysize(urls), arraysize(titles)); @@ -1026,7 +1026,7 @@ TEST_F(BookmarkBarControllerTest, DropBookmarks) { NSMutableArray* nstitles = [NSMutableArray array]; for (size_t i = 0; i < arraysize(urls); ++i) { [nsurls addObject:base::SysUTF8ToNSString(urls[i])]; - [nstitles addObject:base::SysWideToNSString(titles[i])]; + [nstitles addObject:base::SysUTF8ToNSString(titles[i])]; } BookmarkModel* model = helper_.profile()->GetBookmarkModel(); @@ -1044,7 +1044,8 @@ TEST_F(BookmarkBarControllerTest, DropBookmarks) { std::string my_string = parent->GetChild(i)->GetURL().spec(); EXPECT_NE(gurl_string.find(my_string), std::string::npos); } - EXPECT_EQ(parent->GetChild(i)->GetTitle(), titles[i]); + EXPECT_EQ(parent->GetChild(i)->GetTitleAsString16(), + ASCIIToUTF16(titles[i])); } } @@ -1166,8 +1167,8 @@ TEST_F(BookmarkBarControllerTest, TestDragButton) { EXPECT_EQ(1, folder->GetChildCount()); x = NSMidX([[[bar_ buttons] objectAtIndex:0] frame]); x += [[bar_ view] frame].origin.x; - std::wstring title = [[[bar_ buttons] objectAtIndex:2] - bookmarkNode]->GetTitle(); + string16 title = + [[[bar_ buttons] objectAtIndex:2] bookmarkNode]->GetTitleAsString16(); [bar_ dragButton:[[bar_ buttons] objectAtIndex:2] to:NSMakePoint(x, 0) copy:NO]; @@ -1176,7 +1177,7 @@ TEST_F(BookmarkBarControllerTest, TestDragButton) { // In the folder EXPECT_EQ(2, folder->GetChildCount()); // At the end - EXPECT_EQ(title, folder->GetChild(1)->GetTitle()); + EXPECT_EQ(title, folder->GetChild(1)->GetTitleAsString16()); } TEST_F(BookmarkBarControllerTest, TestCopyButton) { @@ -1947,7 +1948,7 @@ TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkData) { ASSERT_TRUE(targetButton); NSPoint targetPoint = [targetButton center]; newNode = other->GetChild(2); // Should be O4f. - EXPECT_EQ(newNode->GetTitle(), L"O4f"); + EXPECT_EQ(newNode->GetTitleAsString16(), ASCIIToUTF16("O4f")); [bar_ setDragDataNode:newNode]; [dragInfo setDropLocation:targetPoint]; [bar_ dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; diff --git a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm index 0e3771a..477804b 100644 --- a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm @@ -250,7 +250,7 @@ const CGFloat kScrollWindowVerticalMargin = 0.0; [button setTarget:self]; [button setAction:@selector(openBookmark:)]; // Add a tooltip. - NSString* title = base::SysWideToNSString(node->GetTitle()); + NSString* title = base::SysUTF16ToNSString(node->GetTitleAsString16()); std::string urlString = node->GetURL().possibly_invalid_spec(); NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title, urlString.c_str()]; diff --git a/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm index fc7e80b..a636259 100644 --- a/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm @@ -1311,7 +1311,7 @@ TEST_F(BookmarkBarFolderControllerMenuTest, DragBookmarkData) { targetButton = [folderController buttonWithTitleEqualTo:@"2f2f"]; ASSERT_TRUE(targetButton); newNode = other->GetChild(2); // Should be O4f. - EXPECT_EQ(newNode->GetTitle(), L"O4f"); + EXPECT_EQ(newNode->GetTitleAsString16(), ASCIIToUTF16("O4f")); [folderController setDragDataNode:newNode]; [dragInfo setDropLocation:[targetButton center]]; [folderController dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; diff --git a/chrome/browser/cocoa/bookmark_bubble_controller.mm b/chrome/browser/cocoa/bookmark_bubble_controller.mm index b7fd366..4b8d154 100644 --- a/chrome/browser/cocoa/bookmark_bubble_controller.mm +++ b/chrome/browser/cocoa/bookmark_bubble_controller.mm @@ -278,8 +278,7 @@ void BookmarkBubbleNotificationBridge::Observe( - (IBAction)remove:(id)sender { [self stopPulsingBookmarkButton]; // TODO(viettrungluu): get rid of conversion and utf_string_conversions.h. - model_->SetURLStarred(node_->GetURL(), WideToUTF16Hack(node_->GetTitle()), - false); + model_->SetURLStarred(node_->GetURL(), node_->GetTitleAsString16(), false); UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"), model_->profile()); node_ = NULL; // no longer valid @@ -324,7 +323,7 @@ void BookmarkBubbleNotificationBridge::Observe( if (!node_) return; // First the title... - NSString* oldTitle = base::SysWideToNSString(node_->GetTitle()); + NSString* oldTitle = base::SysUTF16ToNSString(node_->GetTitleAsString16()); NSString* newTitle = [nameTextField_ stringValue]; if (![oldTitle isEqual:newTitle]) { model_->SetTitle(node_, base::SysNSStringToUTF16(newTitle)); @@ -353,7 +352,8 @@ void BookmarkBubbleNotificationBridge::Observe( // Fill in all information related to the folder pop up button. - (void)fillInFolderList { - [nameTextField_ setStringValue:base::SysWideToNSString(node_->GetTitle())]; + [nameTextField_ + setStringValue:base::SysUTF16ToNSString(node_->GetTitleAsString16())]; DCHECK([folderPopUpButton_ numberOfItems] == 0); [self addFolderNodes:model_->root_node() toPopUpButton:folderPopUpButton_ @@ -387,7 +387,7 @@ void BookmarkBubbleNotificationBridge::Observe( toPopUpButton:(NSPopUpButton*)button indentation:(int)indentation { if (!model_->is_root(parent)) { - NSString* title = base::SysWideToNSString(parent->GetTitle()); + NSString* title = base::SysUTF16ToNSString(parent->GetTitleAsString16()); NSMenu* menu = [button menu]; NSMenuItem* item = [menu addItemWithTitle:title action:NULL diff --git a/chrome/browser/cocoa/bookmark_button_cell.mm b/chrome/browser/cocoa/bookmark_button_cell.mm index f8d0ffc..48b7a7d 100644 --- a/chrome/browser/cocoa/bookmark_button_cell.mm +++ b/chrome/browser/cocoa/bookmark_button_cell.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -48,7 +48,7 @@ [self setBookmarkNode:node]; if (node) { - NSString* title = base::SysWideToNSString(node->GetTitle()); + NSString* title = base::SysUTF16ToNSString(node->GetTitleAsString16()); [self setBookmarkCellText:title image:cellImage]; [self setMenu:contextMenu]; } else { diff --git a/chrome/browser/cocoa/bookmark_editor_base_controller.mm b/chrome/browser/cocoa/bookmark_editor_base_controller.mm index a431c20..044233e 100644 --- a/chrome/browser/cocoa/bookmark_editor_base_controller.mm +++ b/chrome/browser/cocoa/bookmark_editor_base_controller.mm @@ -395,7 +395,8 @@ class BookmarkEditorBaseControllerBridge : public BookmarkModelObserver { for (int i = 0; i < childCount; ++i) { const BookmarkNode* childNode = node->GetChild(i); if (childNode->type() != BookmarkNode::URL) { - NSString* childName = base::SysWideToNSString(childNode->GetTitle()); + NSString* childName = + base::SysUTF16ToNSString(childNode->GetTitleAsString16()); NSMutableArray* children = [self addChildFoldersFromNode:childNode]; BookmarkFolderInfo* folderInfo = [BookmarkFolderInfo bookmarkFolderInfoWithFolderName:childName diff --git a/chrome/browser/cocoa/bookmark_editor_controller.mm b/chrome/browser/cocoa/bookmark_editor_controller.mm index 0de44ae..5461640 100644 --- a/chrome/browser/cocoa/bookmark_editor_controller.mm +++ b/chrome/browser/cocoa/bookmark_editor_controller.mm @@ -48,7 +48,7 @@ // Set text fields to match our bookmark. If the node is NULL we // arrived here from an "Add Page..." item in a context menu. if (node_) { - [self setInitialName:base::SysWideToNSString(node_->GetTitle())]; + [self setInitialName:base::SysUTF16ToNSString(node_->GetTitleAsString16())]; std::string url_string = node_->GetURL().possibly_invalid_spec(); initialUrl_.reset([[NSString stringWithUTF8String:url_string.c_str()] retain]); diff --git a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm index 87f8210..385adae 100644 --- a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm @@ -61,7 +61,7 @@ TEST_F(BookmarkEditorControllerTest, EditTitle) { [controller_ ok:nil]; ASSERT_EQ(default_parent_->GetChildCount(), 1); const BookmarkNode* child = default_parent_->GetChild(0); - EXPECT_EQ(child->GetTitle(), L"whamma jamma bamma"); + EXPECT_EQ(child->GetTitleAsString16(), ASCIIToUTF16("whamma jamma bamma")); EXPECT_EQ(child->GetURL(), GURL(default_name_)); } @@ -388,7 +388,7 @@ TEST_F(BookmarkEditorControllerTreeTest, ChangeNameAndBookmarkGroup) { ASSERT_EQ(parent, group_c_); int childIndex = parent->IndexOfChild(bookmark_bb_3_); ASSERT_EQ(4, childIndex); - EXPECT_EQ(bookmark_bb_3_->GetTitle(), L"NEW NAME"); + EXPECT_EQ(bookmark_bb_3_->GetTitleAsString16(), ASCIIToUTF16("NEW NAME")); } TEST_F(BookmarkEditorControllerTreeTest, AddFolderWithGroupSelected) { @@ -418,6 +418,6 @@ TEST_F(BookmarkEditorControllerTreeNoNodeTest, NewBookmarkNoNode) { [controller_ ok:nil]; const BookmarkNode* new_node = group_bb_->GetChild(5); ASSERT_EQ(0, new_node->GetChildCount()); - EXPECT_EQ(new_node->GetTitle(), L"NEW BOOKMARK"); + EXPECT_EQ(new_node->GetTitleAsString16(), ASCIIToUTF16("NEW BOOKMARK")); EXPECT_EQ(new_node->GetURL(), GURL("http://NEWURL.com")); } diff --git a/chrome/browser/cocoa/bookmark_folder_target.mm b/chrome/browser/cocoa/bookmark_folder_target.mm index b47e5a77..7e957d2 100644 --- a/chrome/browser/cocoa/bookmark_folder_target.mm +++ b/chrome/browser/cocoa/bookmark_folder_target.mm @@ -79,7 +79,7 @@ NSString* kBookmarkButtonDragType = @"ChromiumBookmarkButtonDragType"; } else { const std::string spec = node->GetURL().spec(); NSString* url = base::SysUTF8ToNSString(spec); - NSString* title = base::SysWideToNSString(node->GetTitle()); + NSString* title = base::SysUTF16ToNSString(node->GetTitleAsString16()); [pboard declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:nil]; [pboard setDataForURL:url title:title]; diff --git a/chrome/browser/cocoa/bookmark_menu_bridge.mm b/chrome/browser/cocoa/bookmark_menu_bridge.mm index e635548..cc11a47 100644 --- a/chrome/browser/cocoa/bookmark_menu_bridge.mm +++ b/chrome/browser/cocoa/bookmark_menu_bridge.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -222,8 +222,8 @@ void BookmarkMenuBridge::ConfigureMenuItem(const BookmarkNode* node, // Add a tooltip std::string url_string = node->GetURL().possibly_invalid_spec(); NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", - base::SysWideToNSString(node->GetTitle()), - url_string.c_str()]; + base::SysUTF16ToNSString(node->GetTitleAsString16()), + url_string.c_str()]; [item setToolTip:tooltip]; // Check to see if we have a favicon. diff --git a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm index adae210..0acbc4b 100644 --- a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm +++ b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm @@ -6,6 +6,7 @@ #include "app/text_elider.h" #include "base/sys_string_conversions.h" +#include "base/utf_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" // IDC_BOOKMARK_MENU #import "chrome/browser/app_controller_mac.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -30,7 +31,8 @@ const NSUInteger kMaximumMenuPixelsWide = 300; NSFont* nsfont = [NSFont menuBarFontOfSize:0]; // 0 means "default" gfx::Font font(base::SysNSStringToWide([nsfont fontName]), static_cast<int>([nsfont pointSize])); - std::wstring title = gfx::ElideText(node->GetTitle(), + std::wstring title = gfx::ElideText(UTF16ToWideHack( + node->GetTitleAsString16()), font, kMaximumMenuPixelsWide, false); diff --git a/chrome/browser/cocoa/bookmark_name_folder_controller.mm b/chrome/browser/cocoa/bookmark_name_folder_controller.mm index e6f05a6..c2c0f54 100644 --- a/chrome/browser/cocoa/bookmark_name_folder_controller.mm +++ b/chrome/browser/cocoa/bookmark_name_folder_controller.mm @@ -32,7 +32,8 @@ DCHECK_LE(newIndex, parent->GetChildCount()); } if (node_) { - initialName_.reset([base::SysWideToNSString(node_->GetTitle()) retain]); + initialName_.reset( + [base::SysUTF16ToNSString(node_->GetTitleAsString16()) retain]); } else { NSString* newString = l10n_util::GetNSStringWithFixup(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME); diff --git a/chrome/browser/cocoa/cookie_tree_node.mm b/chrome/browser/cocoa/cookie_tree_node.mm index 553a7bb..114f739 100644 --- a/chrome/browser/cocoa/cookie_tree_node.mm +++ b/chrome/browser/cocoa/cookie_tree_node.mm @@ -18,7 +18,8 @@ } - (void)rebuild { - title_.reset([base::SysWideToNSString(treeNode_->GetTitle()) retain]); + title_.reset( + [base::SysUTF16ToNSString(treeNode_->GetTitleAsString16()) retain]); children_.reset(); // The tree node assumes ownership of the cookie details object details_.reset([[CocoaCookieDetails createFromCookieTreeNode:(treeNode_)] |