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_finder.h" | |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/browser_window.h" | |
27 #include "chrome/browser/ui/simple_message_box.h" | 25 #include "chrome/browser/ui/simple_message_box.h" |
28 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
29 #include "content/public/browser/page_navigator.h" | |
30 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
31 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
32 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
33 #include "grit/ui_strings.h" | 30 #include "grit/ui_strings.h" |
34 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
35 #include "ui/base/dragdrop/drag_drop_types.h" | 32 #include "ui/base/dragdrop/drag_drop_types.h" |
36 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
37 #include "ui/base/models/tree_node_iterator.h" | 34 #include "ui/base/models/tree_node_iterator.h" |
38 | 35 |
39 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
(...skipping 12 matching lines...) Expand all Loading... |
52 #include "chrome/browser/ui/gtk/custom_drag.h" | 49 #include "chrome/browser/ui/gtk/custom_drag.h" |
53 #endif | 50 #endif |
54 | 51 |
55 using base::Time; | 52 using base::Time; |
56 using content::OpenURLParams; | 53 using content::OpenURLParams; |
57 using content::PageNavigator; | 54 using content::PageNavigator; |
58 using content::WebContents; | 55 using content::WebContents; |
59 | 56 |
60 namespace { | 57 namespace { |
61 | 58 |
62 // A PageNavigator implementation that creates a new Browser. This is used when | |
63 // opening a url and there is no Browser open. The Browser is created the first | |
64 // time the PageNavigator method is invoked. | |
65 class NewBrowserPageNavigator : public PageNavigator { | |
66 public: | |
67 explicit NewBrowserPageNavigator(Profile* profile) | |
68 : profile_(profile), | |
69 browser_(NULL) {} | |
70 | |
71 virtual ~NewBrowserPageNavigator() { | |
72 if (browser_) | |
73 browser_->window()->Show(); | |
74 } | |
75 | |
76 Browser* browser() const { return browser_; } | |
77 | |
78 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE { | |
79 if (!browser_) { | |
80 Profile* profile = (params.disposition == OFF_THE_RECORD) ? | |
81 profile_->GetOffTheRecordProfile() : profile_; | |
82 browser_ = Browser::Create(profile); | |
83 } | |
84 | |
85 OpenURLParams forward_params = params; | |
86 forward_params.disposition = NEW_FOREGROUND_TAB; | |
87 return browser_->OpenURL(forward_params); | |
88 } | |
89 | |
90 private: | |
91 Profile* profile_; | |
92 Browser* browser_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(NewBrowserPageNavigator); | |
95 }; | |
96 | |
97 void CloneBookmarkNodeImpl(BookmarkModel* model, | 59 void CloneBookmarkNodeImpl(BookmarkModel* model, |
98 const BookmarkNodeData::Element& element, | 60 const BookmarkNodeData::Element& element, |
99 const BookmarkNode* parent, | 61 const BookmarkNode* parent, |
100 int index_to_add_at) { | 62 int index_to_add_at) { |
101 if (element.is_url) { | 63 if (element.is_url) { |
102 model->AddURL(parent, index_to_add_at, element.title, element.url); | 64 model->AddURL(parent, index_to_add_at, element.title, element.url); |
103 } else { | 65 } else { |
104 const BookmarkNode* new_folder = model->AddFolder(parent, | 66 const BookmarkNode* new_folder = model->AddFolder(parent, |
105 index_to_add_at, | 67 index_to_add_at, |
106 element.title); | 68 element.title); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 bool was_nested = MessageLoop::current()->IsNested(); | 332 bool was_nested = MessageLoop::current()->IsNested(); |
371 MessageLoop::current()->SetNestableTasksAllowed(true); | 333 MessageLoop::current()->SetNestableTasksAllowed(true); |
372 bookmark_pasteboard_helper_mac::StartDrag(profile, nodes, view); | 334 bookmark_pasteboard_helper_mac::StartDrag(profile, nodes, view); |
373 MessageLoop::current()->SetNestableTasksAllowed(was_nested); | 335 MessageLoop::current()->SetNestableTasksAllowed(was_nested); |
374 #elif defined(TOOLKIT_GTK) | 336 #elif defined(TOOLKIT_GTK) |
375 BookmarkDrag::BeginDrag(profile, nodes); | 337 BookmarkDrag::BeginDrag(profile, nodes); |
376 #endif | 338 #endif |
377 } | 339 } |
378 | 340 |
379 void OpenAll(gfx::NativeWindow parent, | 341 void OpenAll(gfx::NativeWindow parent, |
380 Profile* profile, | |
381 PageNavigator* navigator, | 342 PageNavigator* navigator, |
382 const std::vector<const BookmarkNode*>& nodes, | 343 const std::vector<const BookmarkNode*>& nodes, |
383 WindowOpenDisposition initial_disposition) { | 344 WindowOpenDisposition initial_disposition) { |
384 if (!ShouldOpenAll(parent, nodes)) | 345 if (!ShouldOpenAll(parent, nodes)) |
385 return; | 346 return; |
386 | 347 |
387 NewBrowserPageNavigator navigator_impl(profile); | |
388 if (!navigator) { | |
389 Browser* browser = browser::FindTabbedBrowser(profile, false); | |
390 if (!browser || !chrome::GetActiveWebContents(browser)) { | |
391 navigator = &navigator_impl; | |
392 } else { | |
393 if (initial_disposition != NEW_WINDOW && | |
394 initial_disposition != OFF_THE_RECORD) { | |
395 browser->window()->Activate(); | |
396 } | |
397 navigator = chrome::GetActiveWebContents(browser); | |
398 } | |
399 } | |
400 | |
401 bool opened_url = false; | 348 bool opened_url = false; |
402 for (size_t i = 0; i < nodes.size(); ++i) | 349 for (size_t i = 0; i < nodes.size(); ++i) |
403 OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url); | 350 OpenAllImpl(nodes[i], initial_disposition, &navigator, &opened_url); |
404 } | 351 } |
405 | 352 |
406 void OpenAll(gfx::NativeWindow parent, | 353 void OpenAll(gfx::NativeWindow parent, |
407 Profile* profile, | |
408 PageNavigator* navigator, | 354 PageNavigator* navigator, |
409 const BookmarkNode* node, | 355 const BookmarkNode* node, |
410 WindowOpenDisposition initial_disposition) { | 356 WindowOpenDisposition initial_disposition) { |
411 std::vector<const BookmarkNode*> nodes; | 357 std::vector<const BookmarkNode*> nodes; |
412 nodes.push_back(node); | 358 nodes.push_back(node); |
413 OpenAll(parent, profile, navigator, nodes, initial_disposition); | 359 OpenAll(parent, navigator, nodes, initial_disposition); |
414 } | 360 } |
415 | 361 |
416 void CopyToClipboard(BookmarkModel* model, | 362 void CopyToClipboard(BookmarkModel* model, |
417 const std::vector<const BookmarkNode*>& nodes, | 363 const std::vector<const BookmarkNode*>& nodes, |
418 bool remove_nodes) { | 364 bool remove_nodes) { |
419 if (nodes.empty()) | 365 if (nodes.empty()) |
420 return; | 366 return; |
421 | 367 |
422 BookmarkNodeData(nodes).WriteToClipboard(NULL); | 368 BookmarkNodeData(nodes).WriteToClipboard(NULL); |
423 | 369 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 void DisableBookmarkBarViewAnimationsForTesting(bool disabled) { | 716 void DisableBookmarkBarViewAnimationsForTesting(bool disabled) { |
771 g_bookmark_bar_view_animations_disabled = disabled; | 717 g_bookmark_bar_view_animations_disabled = disabled; |
772 } | 718 } |
773 | 719 |
774 bool IsBookmarkBarViewAnimationsDisabled() { | 720 bool IsBookmarkBarViewAnimationsDisabled() { |
775 return g_bookmark_bar_view_animations_disabled; | 721 return g_bookmark_bar_view_animations_disabled; |
776 } | 722 } |
777 #endif | 723 #endif |
778 | 724 |
779 } // namespace bookmark_utils | 725 } // namespace bookmark_utils |
OLD | NEW |