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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" |
6 | 6 |
7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" // IDC_BOOKMARK_MENU | 9 #include "chrome/app/chrome_command_ids.h" // IDC_BOOKMARK_MENU |
10 #import "chrome/browser/app_controller_mac.h" | 10 #import "chrome/browser/app_controller_mac.h" |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
12 #include "chrome/browser/bookmarks/bookmark_utils.h" | 12 #include "chrome/browser/bookmarks/bookmark_utils.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" |
14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
15 #include "chrome/browser/ui/cocoa/event_utils.h" | 16 #include "chrome/browser/ui/cocoa/event_utils.h" |
16 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
17 #include "ui/base/text/text_elider.h" | 18 #include "ui/base/text/text_elider.h" |
18 | 19 |
19 using content::OpenURLParams; | 20 using content::OpenURLParams; |
20 using content::Referrer; | 21 using content::Referrer; |
21 using content::UserMetricsAction; | 22 using content::UserMetricsAction; |
22 | 23 |
23 namespace { | 24 namespace { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 86 } |
86 | 87 |
87 // Return the a BookmarkNode that has the given id (called | 88 // Return the a BookmarkNode that has the given id (called |
88 // "identifier" here to avoid conflict with objc's concept of "id"). | 89 // "identifier" here to avoid conflict with objc's concept of "id"). |
89 - (const BookmarkNode*)nodeForIdentifier:(int)identifier { | 90 - (const BookmarkNode*)nodeForIdentifier:(int)identifier { |
90 return bridge_->GetBookmarkModel()->GetNodeByID(identifier); | 91 return bridge_->GetBookmarkModel()->GetNodeByID(identifier); |
91 } | 92 } |
92 | 93 |
93 // Open the URL of the given BookmarkNode in the current tab. | 94 // Open the URL of the given BookmarkNode in the current tab. |
94 - (void)openURLForNode:(const BookmarkNode*)node { | 95 - (void)openURLForNode:(const BookmarkNode*)node { |
95 Browser* browser = Browser::GetTabbedBrowser(bridge_->GetProfile(), true); | 96 Browser* browser = browser::FindTabbedBrowser(bridge_->GetProfile(), true); |
96 if (!browser) | 97 if (!browser) |
97 browser = Browser::Create(bridge_->GetProfile()); | 98 browser = Browser::Create(bridge_->GetProfile()); |
98 WindowOpenDisposition disposition = | 99 WindowOpenDisposition disposition = |
99 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 100 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
100 OpenURLParams params( | 101 OpenURLParams params( |
101 node->url(), Referrer(), disposition, | 102 node->url(), Referrer(), disposition, |
102 content::PAGE_TRANSITION_AUTO_BOOKMARK, false); | 103 content::PAGE_TRANSITION_AUTO_BOOKMARK, false); |
103 browser->OpenURL(params); | 104 browser->OpenURL(params); |
104 } | 105 } |
105 | 106 |
106 // Open sites under BookmarkNode with the specified disposition. | 107 // Open sites under BookmarkNode with the specified disposition. |
107 - (void)openAll:(NSInteger)tag | 108 - (void)openAll:(NSInteger)tag |
108 withDisposition:(WindowOpenDisposition)disposition { | 109 withDisposition:(WindowOpenDisposition)disposition { |
109 int identifier = tag; | 110 int identifier = tag; |
110 | 111 |
111 const BookmarkNode* node = [self nodeForIdentifier:identifier]; | 112 const BookmarkNode* node = [self nodeForIdentifier:identifier]; |
112 DCHECK(node); | 113 DCHECK(node); |
113 | 114 |
114 Browser* browser = Browser::GetTabbedBrowser(bridge_->GetProfile(), true); | 115 Browser* browser = browser::FindTabbedBrowser(bridge_->GetProfile(), true); |
115 if (!browser) | 116 if (!browser) |
116 browser = Browser::Create(bridge_->GetProfile()); | 117 browser = Browser::Create(bridge_->GetProfile()); |
117 DCHECK(browser); | 118 DCHECK(browser); |
118 | 119 |
119 if (!node || !browser) | 120 if (!node || !browser) |
120 return; // shouldn't be reached | 121 return; // shouldn't be reached |
121 | 122 |
122 bookmark_utils::OpenAll(NULL, browser->profile(), browser, node, | 123 bookmark_utils::OpenAll(NULL, browser->profile(), browser, node, |
123 disposition); | 124 disposition); |
124 | 125 |
(...skipping 24 matching lines...) Expand all Loading... |
149 | 150 |
150 - (IBAction)openAllBookmarksNewWindow:(id)sender { | 151 - (IBAction)openAllBookmarksNewWindow:(id)sender { |
151 [self openAll:[sender tag] withDisposition:NEW_WINDOW]; | 152 [self openAll:[sender tag] withDisposition:NEW_WINDOW]; |
152 } | 153 } |
153 | 154 |
154 - (IBAction)openAllBookmarksIncognitoWindow:(id)sender { | 155 - (IBAction)openAllBookmarksIncognitoWindow:(id)sender { |
155 [self openAll:[sender tag] withDisposition:OFF_THE_RECORD]; | 156 [self openAll:[sender tag] withDisposition:OFF_THE_RECORD]; |
156 } | 157 } |
157 | 158 |
158 @end // BookmarkMenuCocoaController | 159 @end // BookmarkMenuCocoaController |
OLD | NEW |