[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 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/bookmarks/bookmark_utils.h" |
| 6 | |
[email protected] | 90f3990 | 2009-10-03 04:25:37 | [diff] [blame] | 7 | #include "app/clipboard/clipboard.h" |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 8 | #include "app/drag_drop_types.h" |
[email protected] | a92b864 | 2009-05-05 23:38:56 | [diff] [blame] | 9 | #include "app/l10n_util.h" |
[email protected] | 992c625 | 2009-05-13 18:54:20 | [diff] [blame] | 10 | #include "app/tree_node_iterator.h" |
[email protected] | a036896 | 2009-02-24 21:47:16 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 630947c | 2009-11-04 18:37:31 | [diff] [blame] | 12 | #include "base/file_path.h" |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 13 | #include "base/string_util.h" |
[email protected] | 9c6a85d | 2010-01-21 22:53:46 | [diff] [blame^] | 14 | #include "base/string16.h" |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 15 | #include "base/time.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 16 | #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 17 | #include "chrome/browser/bookmarks/bookmark_model.h" |
| 18 | #include "chrome/browser/browser.h" |
| 19 | #include "chrome/browser/browser_list.h" |
[email protected] | b08cadb9 | 2009-08-04 21:52:29 | [diff] [blame] | 20 | #include "chrome/browser/browser_process.h" |
[email protected] | ce560f8 | 2009-06-03 09:39:44 | [diff] [blame] | 21 | #include "chrome/browser/browser_window.h" |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 22 | #include "chrome/browser/history/query_parser.h" |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 23 | #include "chrome/browser/profile.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 24 | #include "chrome/browser/tab_contents/page_navigator.h" |
[email protected] | 1132436e | 2009-04-08 20:06:33 | [diff] [blame] | 25 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 26 | #include "chrome/common/notification_service.h" |
| 27 | #include "chrome/common/pref_names.h" |
| 28 | #include "chrome/common/pref_service.h" |
[email protected] | 903e7a8 | 2009-07-28 00:45:35 | [diff] [blame] | 29 | #include "grit/app_strings.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 30 | #include "grit/chromium_strings.h" |
| 31 | #include "grit/generated_resources.h" |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 32 | #include "net/base/net_util.h" |
[email protected] | 2362e4f | 2009-05-08 00:34:05 | [diff] [blame] | 33 | #include "views/event.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 34 | |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 35 | using base::Time; |
| 36 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 37 | namespace { |
| 38 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 39 | // A PageNavigator implementation that creates a new Browser. This is used when |
| 40 | // opening a url and there is no Browser open. The Browser is created the first |
| 41 | // time the PageNavigator method is invoked. |
| 42 | class NewBrowserPageNavigator : public PageNavigator { |
| 43 | public: |
| 44 | explicit NewBrowserPageNavigator(Profile* profile) |
| 45 | : profile_(profile), |
| 46 | browser_(NULL) {} |
| 47 | |
| 48 | virtual ~NewBrowserPageNavigator() { |
| 49 | if (browser_) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 50 | browser_->window()->Show(); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | Browser* browser() const { return browser_; } |
| 54 | |
| 55 | virtual void OpenURL(const GURL& url, |
| 56 | const GURL& referrer, |
| 57 | WindowOpenDisposition disposition, |
| 58 | PageTransition::Type transition) { |
| 59 | if (!browser_) { |
| 60 | Profile* profile = (disposition == OFF_THE_RECORD) ? |
| 61 | profile_->GetOffTheRecordProfile() : profile_; |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 62 | browser_ = Browser::Create(profile); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 63 | // Always open the first tab in the foreground. |
| 64 | disposition = NEW_FOREGROUND_TAB; |
| 65 | } |
[email protected] | e0c7c26 | 2009-04-23 23:09:43 | [diff] [blame] | 66 | browser_->OpenURL(url, referrer, NEW_FOREGROUND_TAB, transition); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | private: |
| 70 | Profile* profile_; |
| 71 | Browser* browser_; |
| 72 | |
| 73 | DISALLOW_COPY_AND_ASSIGN(NewBrowserPageNavigator); |
| 74 | }; |
| 75 | |
| 76 | void CloneDragDataImpl(BookmarkModel* model, |
| 77 | const BookmarkDragData::Element& element, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 78 | const BookmarkNode* parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 79 | int index_to_add_at) { |
| 80 | if (element.is_url) { |
| 81 | model->AddURL(parent, index_to_add_at, element.title, element.url); |
| 82 | } else { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 83 | const BookmarkNode* new_folder = model->AddGroup(parent, |
| 84 | index_to_add_at, |
| 85 | element.title); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 86 | for (int i = 0; i < static_cast<int>(element.children.size()); ++i) |
| 87 | CloneDragDataImpl(model, element.children[i], new_folder, i); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Returns the number of descendants of node that are of type url. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 92 | int DescendantURLCount(const BookmarkNode* node) { |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 93 | int result = 0; |
| 94 | for (int i = 0; i < node->GetChildCount(); ++i) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 95 | const BookmarkNode* child = node->GetChild(i); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 96 | if (child->is_url()) |
| 97 | result++; |
| 98 | else |
| 99 | result += DescendantURLCount(child); |
| 100 | } |
| 101 | return result; |
| 102 | } |
| 103 | |
| 104 | // Implementation of OpenAll. Opens all nodes of type URL and recurses for |
| 105 | // groups. |navigator| is the PageNavigator used to open URLs. After the first |
| 106 | // url is opened |opened_url| is set to true and |navigator| is set to the |
| 107 | // PageNavigator of the last active tab. This is done to handle a window |
| 108 | // disposition of new window, in which case we want subsequent tabs to open in |
| 109 | // that window. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 110 | void OpenAllImpl(const BookmarkNode* node, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 111 | WindowOpenDisposition initial_disposition, |
| 112 | PageNavigator** navigator, |
| 113 | bool* opened_url) { |
| 114 | if (node->is_url()) { |
| 115 | WindowOpenDisposition disposition; |
| 116 | if (*opened_url) |
| 117 | disposition = NEW_BACKGROUND_TAB; |
| 118 | else |
| 119 | disposition = initial_disposition; |
| 120 | (*navigator)->OpenURL(node->GetURL(), GURL(), disposition, |
| 121 | PageTransition::AUTO_BOOKMARK); |
| 122 | if (!*opened_url) { |
| 123 | *opened_url = true; |
| 124 | // We opened the first URL which may have opened a new window or clobbered |
| 125 | // the current page, reset the navigator just to be sure. |
| 126 | Browser* new_browser = BrowserList::GetLastActive(); |
| 127 | if (new_browser) { |
| 128 | TabContents* current_tab = new_browser->GetSelectedTabContents(); |
| 129 | DCHECK(new_browser && current_tab); |
| 130 | if (new_browser && current_tab) |
| 131 | *navigator = current_tab; |
| 132 | } // else, new_browser == NULL, which happens during testing. |
| 133 | } |
| 134 | } else { |
| 135 | // Group, recurse through children. |
| 136 | for (int i = 0; i < node->GetChildCount(); ++i) { |
| 137 | OpenAllImpl(node->GetChild(i), initial_disposition, navigator, |
| 138 | opened_url); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
[email protected] | d6d6d58 | 2009-10-12 19:22:26 | [diff] [blame] | 143 | bool ShouldOpenAll(gfx::NativeWindow parent, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 144 | const std::vector<const BookmarkNode*>& nodes) { |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 145 | int descendant_count = 0; |
| 146 | for (size_t i = 0; i < nodes.size(); ++i) |
| 147 | descendant_count += DescendantURLCount(nodes[i]); |
[email protected] | f785ad1 | 2008-11-19 23:01:28 | [diff] [blame] | 148 | if (descendant_count < bookmark_utils::num_urls_before_prompting) |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 149 | return true; |
| 150 | |
| 151 | std::wstring message = |
| 152 | l10n_util::GetStringF(IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL, |
| 153 | IntToWString(descendant_count)); |
[email protected] | a036896 | 2009-02-24 21:47:16 | [diff] [blame] | 154 | #if defined(OS_WIN) |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 155 | return MessageBox(parent, message.c_str(), |
| 156 | l10n_util::GetString(IDS_PRODUCT_NAME).c_str(), |
| 157 | MB_YESNO | MB_ICONWARNING | MB_TOPMOST) == IDYES; |
[email protected] | a036896 | 2009-02-24 21:47:16 | [diff] [blame] | 158 | #else |
| 159 | // TODO(port): Display a dialog prompt. |
| 160 | NOTIMPLEMENTED(); |
| 161 | return true; |
| 162 | #endif |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 165 | // Comparison function that compares based on date modified of the two nodes. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 166 | bool MoreRecentlyModified(const BookmarkNode* n1, const BookmarkNode* n2) { |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 167 | return n1->date_group_modified() > n2->date_group_modified(); |
| 168 | } |
| 169 | |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 170 | // Returns true if |text| contains each string in |words|. This is used when |
| 171 | // searching for bookmarks. |
| 172 | bool DoesBookmarkTextContainWords(const std::wstring& text, |
| 173 | const std::vector<std::wstring>& words) { |
| 174 | for (size_t i = 0; i < words.size(); ++i) { |
| 175 | if (text.find(words[i]) == std::wstring::npos) |
| 176 | return false; |
| 177 | } |
| 178 | return true; |
| 179 | } |
| 180 | |
| 181 | // Returns true if |node|s title or url contains the strings in |words|. |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 182 | // |languages| argument is user's accept-language setting to decode IDN. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 183 | bool DoesBookmarkContainWords(const BookmarkNode* node, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 184 | const std::vector<std::wstring>& words, |
| 185 | const std::wstring& languages) { |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 186 | return |
| 187 | DoesBookmarkTextContainWords( |
| 188 | l10n_util::ToLower(node->GetTitle()), words) || |
[email protected] | 1f31bb7 | 2009-12-16 03:18:25 | [diff] [blame] | 189 | DoesBookmarkTextContainWords( |
| 190 | l10n_util::ToLower(UTF8ToWide(node->GetURL().spec())), words) || |
| 191 | DoesBookmarkTextContainWords(l10n_util::ToLower(net::FormatUrl( |
| 192 | node->GetURL(), languages, false, true, NULL, NULL, NULL)), words); |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 193 | } |
| 194 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 195 | } // namespace |
| 196 | |
| 197 | namespace bookmark_utils { |
| 198 | |
[email protected] | f785ad1 | 2008-11-19 23:01:28 | [diff] [blame] | 199 | int num_urls_before_prompting = 15; |
| 200 | |
[email protected] | f28cbb7 | 2008-11-04 19:29:08 | [diff] [blame] | 201 | int PreferredDropOperation(int source_operations, int operations) { |
| 202 | int common_ops = (source_operations & operations); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 203 | if (!common_ops) |
| 204 | return 0; |
| 205 | if (DragDropTypes::DRAG_COPY & common_ops) |
| 206 | return DragDropTypes::DRAG_COPY; |
| 207 | if (DragDropTypes::DRAG_LINK & common_ops) |
| 208 | return DragDropTypes::DRAG_LINK; |
| 209 | if (DragDropTypes::DRAG_MOVE & common_ops) |
| 210 | return DragDropTypes::DRAG_MOVE; |
| 211 | return DragDropTypes::DRAG_NONE; |
| 212 | } |
| 213 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 214 | int BookmarkDragOperation(const BookmarkNode* node) { |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 215 | if (node->is_url()) { |
| 216 | return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE | |
| 217 | DragDropTypes::DRAG_LINK; |
| 218 | } |
| 219 | return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE; |
| 220 | } |
| 221 | |
| 222 | int BookmarkDropOperation(Profile* profile, |
| 223 | const views::DropTargetEvent& event, |
| 224 | const BookmarkDragData& data, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 225 | const BookmarkNode* parent, |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 226 | int index) { |
| 227 | if (data.IsFromProfile(profile) && data.size() > 1) |
| 228 | // Currently only accept one dragged node at a time. |
| 229 | return DragDropTypes::DRAG_NONE; |
| 230 | |
| 231 | if (!bookmark_utils::IsValidDropLocation(profile, data, parent, index)) |
| 232 | return DragDropTypes::DRAG_NONE; |
| 233 | |
| 234 | if (data.GetFirstNode(profile)) { |
| 235 | // User is dragging from this profile: move. |
| 236 | return DragDropTypes::DRAG_MOVE; |
| 237 | } |
| 238 | // User is dragging from another app, copy. |
| 239 | return PreferredDropOperation(event.GetSourceOperations(), |
| 240 | DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK); |
| 241 | } |
| 242 | |
| 243 | int PerformBookmarkDrop(Profile* profile, |
| 244 | const BookmarkDragData& data, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 245 | const BookmarkNode* parent_node, |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 246 | int index) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 247 | const BookmarkNode* dragged_node = data.GetFirstNode(profile); |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 248 | BookmarkModel* model = profile->GetBookmarkModel(); |
| 249 | if (dragged_node) { |
| 250 | // Drag from same profile, do a move. |
| 251 | model->Move(dragged_node, parent_node, index); |
| 252 | return DragDropTypes::DRAG_MOVE; |
| 253 | } else if (data.has_single_url()) { |
| 254 | // New URL, add it at the specified location. |
[email protected] | 9c6a85d | 2010-01-21 22:53:46 | [diff] [blame^] | 255 | string16 title = data.elements[0].title; |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 256 | if (title.empty()) { |
| 257 | // No title, use the host. |
[email protected] | 9c6a85d | 2010-01-21 22:53:46 | [diff] [blame^] | 258 | title = UTF8ToUTF16(data.elements[0].url.host()); |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 259 | if (title.empty()) |
[email protected] | 9c6a85d | 2010-01-21 22:53:46 | [diff] [blame^] | 260 | title = l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_UNKNOWN_DRAG_TITLE); |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 261 | } |
| 262 | model->AddURL(parent_node, index, title, data.elements[0].url); |
| 263 | return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK; |
| 264 | } else { |
| 265 | // Dropping a group from different profile. Always accept. |
| 266 | bookmark_utils::CloneDragData(model, data.elements, parent_node, index); |
| 267 | return DragDropTypes::DRAG_COPY; |
| 268 | } |
| 269 | } |
| 270 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 271 | bool IsValidDropLocation(Profile* profile, |
| 272 | const BookmarkDragData& data, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 273 | const BookmarkNode* drop_parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 274 | int index) { |
| 275 | if (!drop_parent->is_folder()) { |
| 276 | NOTREACHED(); |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | if (!data.is_valid()) |
| 281 | return false; |
| 282 | |
| 283 | if (data.IsFromProfile(profile)) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 284 | std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 285 | for (size_t i = 0; i < nodes.size(); ++i) { |
| 286 | // Don't allow the drop if the user is attempting to drop on one of the |
| 287 | // nodes being dragged. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 288 | const BookmarkNode* node = nodes[i]; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 289 | int node_index = (drop_parent == node->GetParent()) ? |
| 290 | drop_parent->IndexOfChild(nodes[i]) : -1; |
| 291 | if (node_index != -1 && (index == node_index || index == node_index + 1)) |
| 292 | return false; |
| 293 | |
| 294 | // drop_parent can't accept a child that is an ancestor. |
| 295 | if (drop_parent->HasAncestor(node)) |
| 296 | return false; |
| 297 | } |
| 298 | return true; |
| 299 | } |
| 300 | // From the same profile, always accept. |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | void CloneDragData(BookmarkModel* model, |
| 305 | const std::vector<BookmarkDragData::Element>& elements, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 306 | const BookmarkNode* parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 307 | int index_to_add_at) { |
| 308 | if (!parent->is_folder() || !model) { |
| 309 | NOTREACHED(); |
| 310 | return; |
| 311 | } |
| 312 | for (size_t i = 0; i < elements.size(); ++i) |
| 313 | CloneDragDataImpl(model, elements[i], parent, index_to_add_at + i); |
| 314 | } |
| 315 | |
[email protected] | d6d6d58 | 2009-10-12 19:22:26 | [diff] [blame] | 316 | void OpenAll(gfx::NativeWindow parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 317 | Profile* profile, |
| 318 | PageNavigator* navigator, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 319 | const std::vector<const BookmarkNode*>& nodes, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 320 | WindowOpenDisposition initial_disposition) { |
| 321 | if (!ShouldOpenAll(parent, nodes)) |
| 322 | return; |
| 323 | |
| 324 | NewBrowserPageNavigator navigator_impl(profile); |
| 325 | if (!navigator) { |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 326 | Browser* browser = |
[email protected] | 299dabd | 2008-11-19 02:27:16 | [diff] [blame] | 327 | BrowserList::FindBrowserWithType(profile, Browser::TYPE_NORMAL); |
[email protected] | b6f2b913 | 2008-11-17 16:27:51 | [diff] [blame] | 328 | if (!browser || !browser->GetSelectedTabContents()) { |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 329 | navigator = &navigator_impl; |
[email protected] | b6f2b913 | 2008-11-17 16:27:51 | [diff] [blame] | 330 | } else { |
[email protected] | c9938e6d | 2009-03-13 19:54:11 | [diff] [blame] | 331 | if (initial_disposition != NEW_WINDOW && |
| 332 | initial_disposition != OFF_THE_RECORD) { |
| 333 | browser->window()->Activate(); |
| 334 | } |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 335 | navigator = browser->GetSelectedTabContents(); |
[email protected] | b6f2b913 | 2008-11-17 16:27:51 | [diff] [blame] | 336 | } |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | bool opened_url = false; |
| 340 | for (size_t i = 0; i < nodes.size(); ++i) |
| 341 | OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url); |
| 342 | } |
| 343 | |
[email protected] | d6d6d58 | 2009-10-12 19:22:26 | [diff] [blame] | 344 | void OpenAll(gfx::NativeWindow parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 345 | Profile* profile, |
| 346 | PageNavigator* navigator, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 347 | const BookmarkNode* node, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 348 | WindowOpenDisposition initial_disposition) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 349 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 350 | nodes.push_back(node); |
| 351 | OpenAll(parent, profile, navigator, nodes, initial_disposition); |
| 352 | } |
| 353 | |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 354 | void CopyToClipboard(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 355 | const std::vector<const BookmarkNode*>& nodes, |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 356 | bool remove_nodes) { |
[email protected] | b08cadb9 | 2009-08-04 21:52:29 | [diff] [blame] | 357 | #if defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 358 | if (nodes.empty()) |
| 359 | return; |
| 360 | |
[email protected] | b08cadb9 | 2009-08-04 21:52:29 | [diff] [blame] | 361 | BookmarkDragData(nodes).WriteToClipboard(NULL); |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 362 | |
| 363 | if (remove_nodes) { |
| 364 | for (size_t i = 0; i < nodes.size(); ++i) { |
| 365 | model->Remove(nodes[i]->GetParent(), |
| 366 | nodes[i]->GetParent()->IndexOfChild(nodes[i])); |
| 367 | } |
| 368 | } |
[email protected] | b08cadb9 | 2009-08-04 21:52:29 | [diff] [blame] | 369 | #else |
| 370 | // Not implemented on mac yet. |
[email protected] | 7018c5f3 | 2009-07-31 23:37:57 | [diff] [blame] | 371 | #endif |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void PasteFromClipboard(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 375 | const BookmarkNode* parent, |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 376 | int index) { |
[email protected] | b08cadb9 | 2009-08-04 21:52:29 | [diff] [blame] | 377 | #if defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 378 | if (!parent) |
| 379 | return; |
| 380 | |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 381 | BookmarkDragData bookmark_data; |
[email protected] | b08cadb9 | 2009-08-04 21:52:29 | [diff] [blame] | 382 | if (!bookmark_data.ReadFromClipboard()) |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 383 | return; |
| 384 | |
| 385 | if (index == -1) |
| 386 | index = parent->GetChildCount(); |
| 387 | bookmark_utils::CloneDragData(model, bookmark_data.elements, parent, index); |
[email protected] | a036896 | 2009-02-24 21:47:16 | [diff] [blame] | 388 | #else |
[email protected] | b08cadb9 | 2009-08-04 21:52:29 | [diff] [blame] | 389 | // Not implemented on mac yet. |
[email protected] | a036896 | 2009-02-24 21:47:16 | [diff] [blame] | 390 | #endif |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 391 | } |
| 392 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 393 | bool CanPasteFromClipboard(const BookmarkNode* node) { |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 394 | if (!node) |
| 395 | return false; |
| 396 | |
[email protected] | eda5713 | 2009-10-01 14:55:28 | [diff] [blame] | 397 | #if defined(OS_MACOSX) |
| 398 | NOTIMPLEMENTED(); |
| 399 | return false; |
| 400 | #else |
| 401 | return g_browser_process->clipboard()->IsFormatAvailableByString( |
[email protected] | 65a6150d | 2009-09-08 22:16:05 | [diff] [blame] | 402 | BookmarkDragData::kClipboardFormatString, Clipboard::BUFFER_STANDARD); |
[email protected] | eda5713 | 2009-10-01 14:55:28 | [diff] [blame] | 403 | #endif |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | 903e7a8 | 2009-07-28 00:45:35 | [diff] [blame] | 406 | std::string GetNameForURL(const GURL& url) { |
| 407 | if (url.is_valid()) { |
| 408 | return WideToUTF8(net::GetSuggestedFilename( |
[email protected] | 630947c | 2009-11-04 18:37:31 | [diff] [blame] | 409 | url, std::string(), std::string(), FilePath()).ToWStringHack()); |
[email protected] | 903e7a8 | 2009-07-28 00:45:35 | [diff] [blame] | 410 | } else { |
| 411 | return l10n_util::GetStringUTF8(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); |
| 412 | } |
| 413 | } |
| 414 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 415 | std::vector<const BookmarkNode*> GetMostRecentlyModifiedGroups( |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 416 | BookmarkModel* model, |
| 417 | size_t max_count) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 418 | std::vector<const BookmarkNode*> nodes; |
| 419 | TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 420 | while (iterator.has_next()) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 421 | const BookmarkNode* parent = iterator.Next(); |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 422 | if (parent->is_folder() && parent->date_group_modified() > base::Time()) { |
| 423 | if (max_count == 0) { |
| 424 | nodes.push_back(parent); |
| 425 | } else { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 426 | std::vector<const BookmarkNode*>::iterator i = |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 427 | std::upper_bound(nodes.begin(), nodes.end(), parent, |
| 428 | &MoreRecentlyModified); |
| 429 | if (nodes.size() < max_count || i != nodes.end()) { |
| 430 | nodes.insert(i, parent); |
| 431 | while (nodes.size() > max_count) |
| 432 | nodes.pop_back(); |
| 433 | } |
| 434 | } |
| 435 | } // else case, the root node, which we don't care about or imported nodes |
| 436 | // (which have a time of 0). |
| 437 | } |
| 438 | |
| 439 | if (nodes.size() < max_count) { |
| 440 | // Add the bookmark bar and other nodes if there is space. |
| 441 | if (find(nodes.begin(), nodes.end(), model->GetBookmarkBarNode()) == |
| 442 | nodes.end()) { |
| 443 | nodes.push_back(model->GetBookmarkBarNode()); |
| 444 | } |
| 445 | |
| 446 | if (nodes.size() < max_count && |
| 447 | find(nodes.begin(), nodes.end(), model->other_node()) == nodes.end()) { |
| 448 | nodes.push_back(model->other_node()); |
| 449 | } |
| 450 | } |
| 451 | return nodes; |
| 452 | } |
| 453 | |
| 454 | void GetMostRecentlyAddedEntries(BookmarkModel* model, |
| 455 | size_t count, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 456 | std::vector<const BookmarkNode*>* nodes) { |
| 457 | TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 458 | while (iterator.has_next()) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 459 | const BookmarkNode* node = iterator.Next(); |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 460 | if (node->is_url()) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 461 | std::vector<const BookmarkNode*>::iterator insert_position = |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 462 | std::upper_bound(nodes->begin(), nodes->end(), node, |
| 463 | &MoreRecentlyAdded); |
| 464 | if (nodes->size() < count || insert_position != nodes->end()) { |
| 465 | nodes->insert(insert_position, node); |
| 466 | while (nodes->size() > count) |
| 467 | nodes->pop_back(); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 473 | bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2) { |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 474 | return n1->date_added() > n2->date_added(); |
| 475 | } |
| 476 | |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 477 | void GetBookmarksContainingText(BookmarkModel* model, |
| 478 | const std::wstring& text, |
| 479 | size_t max_count, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 480 | const std::wstring& languages, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 481 | std::vector<const BookmarkNode*>* nodes) { |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 482 | std::vector<std::wstring> words; |
| 483 | QueryParser parser; |
| 484 | parser.ExtractQueryWords(l10n_util::ToLower(text), &words); |
| 485 | if (words.empty()) |
| 486 | return; |
| 487 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 488 | TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 489 | while (iterator.has_next()) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 490 | const BookmarkNode* node = iterator.Next(); |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 491 | if (node->is_url() && DoesBookmarkContainWords(node, words, languages)) { |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 492 | nodes->push_back(node); |
| 493 | if (nodes->size() == max_count) |
| 494 | return; |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 499 | bool DoesBookmarkContainText(const BookmarkNode* node, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 500 | const std::wstring& text, |
| 501 | const std::wstring& languages) { |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 502 | std::vector<std::wstring> words; |
| 503 | QueryParser parser; |
| 504 | parser.ExtractQueryWords(l10n_util::ToLower(text), &words); |
| 505 | if (words.empty()) |
| 506 | return false; |
| 507 | |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 508 | return (node->is_url() && DoesBookmarkContainWords(node, words, languages)); |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 509 | } |
| 510 | |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 511 | static const BookmarkNode* CreateNewNode(BookmarkModel* model, |
| 512 | const BookmarkNode* parent, const BookmarkEditor::EditDetails& details, |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 513 | const std::wstring& new_title, const GURL& new_url, |
| 514 | BookmarkEditor::Handler* handler) { |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 515 | const BookmarkNode* node; |
| 516 | if (details.type == BookmarkEditor::EditDetails::NEW_URL) { |
| 517 | node = model->AddURL(parent, parent->GetChildCount(), new_title, new_url); |
| 518 | } else if (details.type == BookmarkEditor::EditDetails::NEW_FOLDER) { |
| 519 | node = model->AddGroup(parent, parent->GetChildCount(), new_title); |
| 520 | for (size_t i = 0; i < details.urls.size(); ++i) { |
| 521 | model->AddURL(node, node->GetChildCount(), details.urls[i].second, |
| 522 | details.urls[i].first); |
| 523 | } |
[email protected] | eea8fd553 | 2009-12-16 00:08:10 | [diff] [blame] | 524 | model->SetDateGroupModified(parent, Time::Now()); |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 525 | } else { |
| 526 | NOTREACHED(); |
| 527 | return NULL; |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 528 | } |
| 529 | |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 530 | if (handler) |
| 531 | handler->NodeCreated(node); |
| 532 | return node; |
| 533 | } |
| 534 | |
| 535 | const BookmarkNode* ApplyEditsWithNoGroupChange(BookmarkModel* model, |
| 536 | const BookmarkNode* parent, const BookmarkEditor::EditDetails& details, |
| 537 | const std::wstring& new_title, const GURL& new_url, |
| 538 | BookmarkEditor::Handler* handler) { |
| 539 | if (details.type == BookmarkEditor::EditDetails::NEW_URL || |
| 540 | details.type == BookmarkEditor::EditDetails::NEW_FOLDER) { |
| 541 | return CreateNewNode(model, parent, details, new_title, new_url, handler); |
| 542 | } |
| 543 | |
| 544 | const BookmarkNode* node = details.existing_node; |
| 545 | DCHECK(node); |
| 546 | const BookmarkNode* old_parent = node->GetParent(); |
| 547 | int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; |
| 548 | |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 549 | // If we're not showing the tree we only need to modify the node. |
| 550 | if (old_index == -1) { |
| 551 | NOTREACHED(); |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 552 | return node; |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | if (new_url != node->GetURL()) { |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 556 | // TODO(sky): need SetURL on the model. |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 557 | const BookmarkNode* new_node = model->AddURLWithCreationTime(old_parent, |
| 558 | old_index, new_title, new_url, node->date_added()); |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 559 | model->Remove(old_parent, old_index + 1); |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 560 | return new_node; |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 561 | } else { |
| 562 | model->SetTitle(node, new_title); |
| 563 | } |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 564 | return node; |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 565 | } |
| 566 | |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 567 | const BookmarkNode* ApplyEditsWithPossibleGroupChange(BookmarkModel* model, |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 568 | const BookmarkNode* new_parent, const BookmarkEditor::EditDetails& details, |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 569 | const std::wstring& new_title, const GURL& new_url, |
| 570 | BookmarkEditor::Handler* handler) { |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 571 | if (details.type == BookmarkEditor::EditDetails::NEW_URL || |
| 572 | details.type == BookmarkEditor::EditDetails::NEW_FOLDER) { |
| 573 | return CreateNewNode(model, new_parent, details, new_title, new_url, |
| 574 | handler); |
| 575 | } |
| 576 | |
| 577 | const BookmarkNode* node = details.existing_node; |
| 578 | DCHECK(node); |
| 579 | const BookmarkNode* old_parent = node->GetParent(); |
| 580 | int old_index = old_parent->IndexOfChild(node); |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 581 | const BookmarkNode* return_node = node; |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 582 | |
| 583 | Time date_added = node->date_added(); |
| 584 | if (new_parent == node->GetParent()) { |
| 585 | // The parent is the same. |
| 586 | if (node->is_url() && new_url != node->GetURL()) { |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 587 | model->Remove(old_parent, old_index); |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 588 | return_node = model->AddURLWithCreationTime(old_parent, old_index, |
| 589 | new_title, new_url, date_added); |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 590 | } else { |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 591 | model->SetTitle(node, new_title); |
| 592 | } |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 593 | } else if (node->is_url() && new_url != node->GetURL()) { |
| 594 | // The parent and URL changed. |
| 595 | model->Remove(old_parent, old_index); |
| 596 | return_node = model->AddURLWithCreationTime(new_parent, |
| 597 | new_parent->GetChildCount(), new_title, new_url, date_added); |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 598 | } else { |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 599 | // The parent and title changed. Move the node and change the title. |
| 600 | model->Move(node, new_parent, new_parent->GetChildCount()); |
| 601 | model->SetTitle(node, new_title); |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 602 | } |
[email protected] | a8d71b0 | 2009-07-07 00:36:34 | [diff] [blame] | 603 | return return_node; |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 604 | } |
| 605 | |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 606 | // Formerly in BookmarkBarView |
| 607 | void ToggleWhenVisible(Profile* profile) { |
| 608 | PrefService* prefs = profile->GetPrefs(); |
| 609 | const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar); |
| 610 | |
| 611 | // The user changed when the bookmark bar is shown, update the preferences. |
| 612 | prefs->SetBoolean(prefs::kShowBookmarkBar, always_show); |
[email protected] | 6faa0e0d | 2009-04-28 06:50:36 | [diff] [blame] | 613 | prefs->ScheduleSavePersistentPrefs(); |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 614 | |
| 615 | // And notify the notification service. |
| 616 | Source<Profile> source(profile); |
| 617 | NotificationService::current()->Notify( |
| 618 | NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 619 | source, |
| 620 | NotificationService::NoDetails()); |
| 621 | } |
| 622 | |
[email protected] | 1e7bab7 | 2009-06-03 17:23:36 | [diff] [blame] | 623 | void RegisterPrefs(PrefService* prefs) { |
| 624 | prefs->RegisterDictionaryPref(prefs::kBookmarkManagerPlacement); |
| 625 | prefs->RegisterIntegerPref(prefs::kBookmarkManagerSplitLocation, -1); |
| 626 | } |
| 627 | |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 628 | void RegisterUserPrefs(PrefService* prefs) { |
| 629 | // Formerly in BookmarkBarView |
| 630 | prefs->RegisterBooleanPref(prefs::kShowBookmarkBar, false); |
| 631 | |
| 632 | // Formerly in BookmarkTableView |
| 633 | prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth1, -1); |
| 634 | prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth1, -1); |
| 635 | prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth2, -1); |
| 636 | prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth2, -1); |
| 637 | prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1); |
| 638 | } |
| 639 | |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 640 | void GetURLAndTitleToBookmark(TabContents* tab_contents, |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 641 | GURL* url, |
| 642 | std::wstring* title) { |
[email protected] | 76624fde | 2009-10-09 18:13:23 | [diff] [blame] | 643 | *url = tab_contents->GetURL(); |
| 644 | *title = UTF16ToWideHack(tab_contents->GetTitle()); |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 645 | } |
| 646 | |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 647 | void GetURLsForOpenTabs(Browser* browser, |
| 648 | std::vector<std::pair<GURL, std::wstring> >* urls) { |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 649 | for (int i = 0; i < browser->tab_count(); ++i) { |
[email protected] | ec12ffe | 2009-10-16 22:28:44 | [diff] [blame] | 650 | std::pair<GURL, std::wstring> entry; |
| 651 | GetURLAndTitleToBookmark(browser->GetTabContentsAt(i), &(entry.first), |
| 652 | &(entry.second)); |
| 653 | urls->push_back(entry); |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 654 | } |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 655 | } |
| 656 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 657 | } // namespace bookmark_utils |