blob: c8dd3ec4a88983bfd6b7c7e5e2cd854ebfedf6f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/browser.h"
#import "chrome/browser/cocoa/bookmark_menu_bridge.h"
#import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h"
#include "chrome/browser/browser_process.h"
#include "webkit/glue/window_open_disposition.h" // CURRENT_TAB
@implementation BookmarkMenuCocoaController
- (id)initWithBridge:(BookmarkMenuBridge *)bridge {
if ((self = [super init])) {
bridge_ = bridge;
DCHECK(bridge_);
}
return self;
}
// Return the a BookmarkNode that has the given id (called
// "identifier" here to avoid conflict with objc's concept of "id").
- (BookmarkNode*)nodeForIdentifier:(int)identifier {
return bridge_->GetBookmarkModel()->GetNodeByID(identifier);
}
// Open the URL of the given BookmarkNode in the current tab.
- (void)openURLForNode:(BookmarkNode*)node {
Browser* browser = BrowserList::GetLastActive();
if (!browser) { // No windows open?
Browser::OpenEmptyWindow(bridge_->GetDefaultProfile());
browser = BrowserList::GetLastActive();
}
DCHECK(browser);
TabContents* tab_contents = browser->GetSelectedTabContents();
DCHECK(tab_contents);
// A TabContents is a PageNavigator, so we can OpenURL() on it.
tab_contents->OpenURL(node->GetURL(), GURL(), CURRENT_TAB,
PageTransition::AUTO_BOOKMARK);
}
- (IBAction)openBookmarkMenuItem:(id)sender {
NSInteger tag = [sender tag];
int identifier = tag;
BookmarkNode* node = [self nodeForIdentifier:identifier];
DCHECK(node);
if (!node)
return; // shouldn't be reached
[self openURLForNode:node];
}
@end // BookmarkMenuCocoaController
|