| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/bookmarks/bookmark_utils.h" | 5 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // Implementation of OpenAll. Opens all nodes of type URL and any children of | 120 // Implementation of OpenAll. Opens all nodes of type URL and any children of |
| 121 // |node| that are of type URL. |navigator| is the PageNavigator used to open | 121 // |node| that are of type URL. |navigator| is the PageNavigator used to open |
| 122 // URLs. After the first url is opened |opened_url| is set to true and | 122 // URLs. After the first url is opened |opened_url| is set to true and |
| 123 // |navigator| is set to the PageNavigator of the last active tab. This is done | 123 // |navigator| is set to the PageNavigator of the last active tab. This is done |
| 124 // to handle a window disposition of new window, in which case we want | 124 // to handle a window disposition of new window, in which case we want |
| 125 // subsequent tabs to open in that window. | 125 // subsequent tabs to open in that window. |
| 126 void OpenAllImpl(const BookmarkNode* node, | 126 void OpenAllImpl(const BookmarkNode* node, |
| 127 WindowOpenDisposition initial_disposition, | 127 WindowOpenDisposition initial_disposition, |
| 128 PageNavigator** navigator, | 128 PageNavigator** navigator, |
| 129 Profile* profile, |
| 129 bool* opened_url) { | 130 bool* opened_url) { |
| 130 if (node->is_url()) { | 131 if (node->is_url()) { |
| 131 WindowOpenDisposition disposition; | 132 WindowOpenDisposition disposition; |
| 132 if (*opened_url) | 133 if (*opened_url) |
| 133 disposition = NEW_BACKGROUND_TAB; | 134 disposition = NEW_BACKGROUND_TAB; |
| 134 else | 135 else |
| 135 disposition = initial_disposition; | 136 disposition = initial_disposition; |
| 136 (*navigator)->OpenURL(node->GetURL(), GURL(), disposition, | 137 (*navigator)->OpenURL(node->GetURL(), GURL(), disposition, |
| 137 PageTransition::AUTO_BOOKMARK); | 138 PageTransition::AUTO_BOOKMARK); |
| 138 if (!*opened_url) { | 139 if (!*opened_url) { |
| 139 *opened_url = true; | 140 *opened_url = true; |
| 140 // We opened the first URL which may have opened a new window or clobbered | 141 // We opened the first URL which may have opened a new window or clobbered |
| 141 // the current page, reset the navigator just to be sure. | 142 // the current page, reset the navigator just to be sure. |
| 142 Browser* new_browser = BrowserList::GetLastActive(); | 143 Browser* new_browser = BrowserList::GetLastActiveWithProfile(profile); |
| 143 if (new_browser) { | 144 if (new_browser) { |
| 144 TabContents* current_tab = new_browser->GetSelectedTabContents(); | 145 TabContents* current_tab = new_browser->GetSelectedTabContents(); |
| 145 DCHECK(new_browser && current_tab); | 146 DCHECK(new_browser && current_tab); |
| 146 if (new_browser && current_tab) | 147 if (new_browser && current_tab) |
| 147 *navigator = current_tab; | 148 *navigator = current_tab; |
| 148 } // else, new_browser == NULL, which happens during testing. | 149 } // else, new_browser == NULL, which happens during testing. |
| 149 } | 150 } |
| 150 } else { | 151 } else { |
| 151 // For folders only open direct children. | 152 // For folders only open direct children. |
| 152 for (int i = 0; i < node->child_count(); ++i) { | 153 for (int i = 0; i < node->child_count(); ++i) { |
| 153 const BookmarkNode* child_node = node->GetChild(i); | 154 const BookmarkNode* child_node = node->GetChild(i); |
| 154 if (child_node->is_url()) | 155 if (child_node->is_url()) |
| 155 OpenAllImpl(child_node, initial_disposition, navigator, opened_url); | 156 OpenAllImpl(child_node, initial_disposition, navigator, profile, |
| 157 opened_url); |
| 156 } | 158 } |
| 157 } | 159 } |
| 158 } | 160 } |
| 159 | 161 |
| 160 bool ShouldOpenAll(gfx::NativeWindow parent, | 162 bool ShouldOpenAll(gfx::NativeWindow parent, |
| 161 const std::vector<const BookmarkNode*>& nodes) { | 163 const std::vector<const BookmarkNode*>& nodes) { |
| 162 int child_count = 0; | 164 int child_count = 0; |
| 163 for (size_t i = 0; i < nodes.size(); ++i) | 165 for (size_t i = 0; i < nodes.size(); ++i) |
| 164 child_count += ChildURLCount(nodes[i]); | 166 child_count += ChildURLCount(nodes[i]); |
| 165 if (child_count < bookmark_utils::num_urls_before_prompting) | 167 if (child_count < bookmark_utils::num_urls_before_prompting) |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 if (initial_disposition != NEW_WINDOW && | 378 if (initial_disposition != NEW_WINDOW && |
| 377 initial_disposition != OFF_THE_RECORD) { | 379 initial_disposition != OFF_THE_RECORD) { |
| 378 browser->window()->Activate(); | 380 browser->window()->Activate(); |
| 379 } | 381 } |
| 380 navigator = browser->GetSelectedTabContents(); | 382 navigator = browser->GetSelectedTabContents(); |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 384 bool opened_url = false; | 386 bool opened_url = false; |
| 385 for (size_t i = 0; i < nodes.size(); ++i) | 387 for (size_t i = 0; i < nodes.size(); ++i) |
| 386 OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url); | 388 OpenAllImpl(nodes[i], initial_disposition, &navigator, profile, |
| 389 &opened_url); |
| 387 } | 390 } |
| 388 | 391 |
| 389 void OpenAll(gfx::NativeWindow parent, | 392 void OpenAll(gfx::NativeWindow parent, |
| 390 Profile* profile, | 393 Profile* profile, |
| 391 PageNavigator* navigator, | 394 PageNavigator* navigator, |
| 392 const BookmarkNode* node, | 395 const BookmarkNode* node, |
| 393 WindowOpenDisposition initial_disposition) { | 396 WindowOpenDisposition initial_disposition) { |
| 394 std::vector<const BookmarkNode*> nodes; | 397 std::vector<const BookmarkNode*> nodes; |
| 395 nodes.push_back(node); | 398 nodes.push_back(node); |
| 396 OpenAll(parent, profile, navigator, nodes, initial_disposition); | 399 OpenAll(parent, profile, navigator, nodes, initial_disposition); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 return true; | 688 return true; |
| 686 | 689 |
| 687 for (int i = 0; i < node->child_count(); ++i) { | 690 for (int i = 0; i < node->child_count(); ++i) { |
| 688 if (NodeHasURLs(node->GetChild(i))) | 691 if (NodeHasURLs(node->GetChild(i))) |
| 689 return true; | 692 return true; |
| 690 } | 693 } |
| 691 return false; | 694 return false; |
| 692 } | 695 } |
| 693 | 696 |
| 694 } // namespace bookmark_utils | 697 } // namespace bookmark_utils |
| OLD | NEW |