OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
12 #include "base/i18n/string_search.h" | 12 #include "base/i18n/string_search.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/bookmarks/bookmark_model.h" | 18 #include "chrome/browser/bookmarks/bookmark_model.h" |
19 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 19 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
20 #include "chrome/browser/history/query_parser.h" | 20 #include "chrome/browser/history/query_parser.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
26 #include "chrome/browser/ui/simple_message_box.h" | 26 #include "chrome/browser/ui/simple_message_box.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "content/public/browser/page_navigator.h" | 28 #include "content/public/browser/page_navigator.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
32 #include "grit/ui_strings.h" | 32 #include "grit/ui_strings.h" |
33 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
34 #include "ui/base/dragdrop/drag_drop_types.h" | 34 #include "ui/base/dragdrop/drag_drop_types.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 disposition = NEW_BACKGROUND_TAB; | 148 disposition = NEW_BACKGROUND_TAB; |
149 else | 149 else |
150 disposition = initial_disposition; | 150 disposition = initial_disposition; |
151 (*navigator)->OpenURL(OpenURLParams(node->url(), content::Referrer(), | 151 (*navigator)->OpenURL(OpenURLParams(node->url(), content::Referrer(), |
152 disposition, content::PAGE_TRANSITION_AUTO_BOOKMARK, | 152 disposition, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
153 false)); | 153 false)); |
154 if (!*opened_url) { | 154 if (!*opened_url) { |
155 *opened_url = true; | 155 *opened_url = true; |
156 // We opened the first URL which may have opened a new window or clobbered | 156 // We opened the first URL which may have opened a new window or clobbered |
157 // the current page, reset the navigator just to be sure. | 157 // the current page, reset the navigator just to be sure. |
158 Browser* new_browser = BrowserList::GetLastActiveWithProfile(profile); | 158 Browser* new_browser = browser::FindLastActiveWithProfile(profile); |
159 if (new_browser) { | 159 if (new_browser) { |
160 WebContents* current_tab = new_browser->GetSelectedWebContents(); | 160 WebContents* current_tab = new_browser->GetSelectedWebContents(); |
161 if (current_tab) | 161 if (current_tab) |
162 *navigator = current_tab; | 162 *navigator = current_tab; |
163 } // else, new_browser == NULL, which happens during testing. | 163 } // else, new_browser == NULL, which happens during testing. |
164 } | 164 } |
165 } else { | 165 } else { |
166 // For folders only open direct children. | 166 // For folders only open direct children. |
167 for (int i = 0; i < node->child_count(); ++i) { | 167 for (int i = 0; i < node->child_count(); ++i) { |
168 const BookmarkNode* child_node = node->GetChild(i); | 168 const BookmarkNode* child_node = node->GetChild(i); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 void OpenAll(gfx::NativeWindow parent, | 381 void OpenAll(gfx::NativeWindow parent, |
382 Profile* profile, | 382 Profile* profile, |
383 PageNavigator* navigator, | 383 PageNavigator* navigator, |
384 const std::vector<const BookmarkNode*>& nodes, | 384 const std::vector<const BookmarkNode*>& nodes, |
385 WindowOpenDisposition initial_disposition) { | 385 WindowOpenDisposition initial_disposition) { |
386 if (!ShouldOpenAll(parent, nodes)) | 386 if (!ShouldOpenAll(parent, nodes)) |
387 return; | 387 return; |
388 | 388 |
389 NewBrowserPageNavigator navigator_impl(profile); | 389 NewBrowserPageNavigator navigator_impl(profile); |
390 if (!navigator) { | 390 if (!navigator) { |
391 Browser* browser = BrowserList::FindTabbedBrowser(profile, false); | 391 Browser* browser = browser::FindTabbedBrowser(profile, false); |
392 if (!browser || !browser->GetSelectedWebContents()) { | 392 if (!browser || !browser->GetSelectedWebContents()) { |
393 navigator = &navigator_impl; | 393 navigator = &navigator_impl; |
394 } else { | 394 } else { |
395 if (initial_disposition != NEW_WINDOW && | 395 if (initial_disposition != NEW_WINDOW && |
396 initial_disposition != OFF_THE_RECORD) { | 396 initial_disposition != OFF_THE_RECORD) { |
397 browser->window()->Activate(); | 397 browser->window()->Activate(); |
398 } | 398 } |
399 navigator = browser->GetSelectedWebContents(); | 399 navigator = browser->GetSelectedWebContents(); |
400 } | 400 } |
401 } | 401 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 void GetURLAndTitleToBookmark(WebContents* web_contents, | 659 void GetURLAndTitleToBookmark(WebContents* web_contents, |
660 GURL* url, | 660 GURL* url, |
661 string16* title) { | 661 string16* title) { |
662 *url = web_contents->GetURL(); | 662 *url = web_contents->GetURL(); |
663 *title = web_contents->GetTitle(); | 663 *title = web_contents->GetTitle(); |
664 } | 664 } |
665 | 665 |
666 void GetURLAndTitleToBookmarkFromCurrentTab(Profile* profile, | 666 void GetURLAndTitleToBookmarkFromCurrentTab(Profile* profile, |
667 GURL* url, | 667 GURL* url, |
668 string16* title) { | 668 string16* title) { |
669 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 669 Browser* browser = browser::FindLastActiveWithProfile(profile); |
670 WebContents* web_contents = browser ? browser->GetSelectedWebContents() | 670 WebContents* web_contents = browser ? browser->GetSelectedWebContents() |
671 : NULL; | 671 : NULL; |
672 if (web_contents) | 672 if (web_contents) |
673 GetURLAndTitleToBookmark(web_contents, url, title); | 673 GetURLAndTitleToBookmark(web_contents, url, title); |
674 } | 674 } |
675 | 675 |
676 void GetURLsForOpenTabs( | 676 void GetURLsForOpenTabs( |
677 Browser* browser, | 677 Browser* browser, |
678 std::vector<std::pair<GURL, string16> >* urls) { | 678 std::vector<std::pair<GURL, string16> >* urls) { |
679 for (int i = 0; i < browser->tab_count(); ++i) { | 679 for (int i = 0; i < browser->tab_count(); ++i) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 void RecordBookmarkLaunch(BookmarkLaunchLocation location) { | 774 void RecordBookmarkLaunch(BookmarkLaunchLocation location) { |
775 #if defined(OS_WIN) | 775 #if defined(OS_WIN) |
776 // TODO(estade): do this on other platforms too. For now it's compiled out | 776 // TODO(estade): do this on other platforms too. For now it's compiled out |
777 // so that stats from platforms for which this is incompletely implemented | 777 // so that stats from platforms for which this is incompletely implemented |
778 // don't mix in with Windows, where it should be implemented exhaustively. | 778 // don't mix in with Windows, where it should be implemented exhaustively. |
779 UMA_HISTOGRAM_ENUMERATION("Bookmarks.LaunchLocation", location, LAUNCH_LIMIT); | 779 UMA_HISTOGRAM_ENUMERATION("Bookmarks.LaunchLocation", location, LAUNCH_LIMIT); |
780 #endif | 780 #endif |
781 } | 781 } |
782 | 782 |
783 } // namespace bookmark_utils | 783 } // namespace bookmark_utils |
OLD | NEW |