OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 withReply:(NSAppleEventDescriptor*)reply; | 23 withReply:(NSAppleEventDescriptor*)reply; |
24 - (void)openFiles:(NSAppleEventDescriptor*)event | 24 - (void)openFiles:(NSAppleEventDescriptor*)event |
25 withReply:(NSAppleEventDescriptor*)reply; | 25 withReply:(NSAppleEventDescriptor*)reply; |
26 @end | 26 @end |
27 | 27 |
28 @implementation AppController | 28 @implementation AppController |
29 | 29 |
30 - (void)awakeFromNib { | 30 - (void)awakeFromNib { |
31 // Set up the command updater for when there are no windows open | 31 // Set up the command updater for when there are no windows open |
32 [self initMenuState]; | 32 [self initMenuState]; |
33 bookmarkMenuBridge_ = new BookmarkMenuBridge(); | 33 bookmarkMenuBridge_.reset(new BookmarkMenuBridge()); |
34 } | 34 } |
35 | 35 |
36 - (void)applicationDidFinishLaunching:(NSNotification*)notify { | 36 - (void)applicationDidFinishLaunching:(NSNotification*)notify { |
37 // Hold an extra ref to the BrowserProcess singleton so it doesn't go away | 37 // Hold an extra ref to the BrowserProcess singleton so it doesn't go away |
38 // when all the browser windows get closed. We'll release it on quit which | 38 // when all the browser windows get closed. We'll release it on quit which |
39 // will be the signal to exit. | 39 // will be the signal to exit. |
40 DCHECK(g_browser_process); | 40 DCHECK(g_browser_process); |
41 g_browser_process->AddRefModule(); | 41 g_browser_process->AddRefModule(); |
42 | 42 |
43 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 43 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
44 [em setEventHandler:self | 44 [em setEventHandler:self |
45 andSelector:@selector(getUrl:withReply:) | 45 andSelector:@selector(getUrl:withReply:) |
46 forEventClass:kInternetEventClass | 46 forEventClass:kInternetEventClass |
47 andEventID:kAEGetURL]; | 47 andEventID:kAEGetURL]; |
48 [em setEventHandler:self | 48 [em setEventHandler:self |
49 andSelector:@selector(getUrl:withReply:) | 49 andSelector:@selector(getUrl:withReply:) |
50 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates | 50 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates |
51 andEventID:'OURL']; // back to the Spyglass days. | 51 andEventID:'OURL']; // back to the Spyglass days. |
52 [em setEventHandler:self | 52 [em setEventHandler:self |
53 andSelector:@selector(openFiles:withReply:) | 53 andSelector:@selector(openFiles:withReply:) |
54 forEventClass:kCoreEventClass | 54 forEventClass:kCoreEventClass |
55 andEventID:kAEOpenDocuments]; | 55 andEventID:kAEOpenDocuments]; |
56 } | 56 } |
57 | 57 |
58 - (void)dealloc { | 58 - (void)dealloc { |
59 delete bookmarkMenuBridge_; | |
60 delete menuState_; | |
61 [super dealloc]; | 59 [super dealloc]; |
62 } | 60 } |
63 | 61 |
64 // We can't use the standard terminate: method because it will abruptly exit | 62 // We can't use the standard terminate: method because it will abruptly exit |
65 // the app and leave things on the stack in an unfinalized state. We need to | 63 // the app and leave things on the stack in an unfinalized state. We need to |
66 // post a quit message to our run loop so the stack can gracefully unwind. | 64 // post a quit message to our run loop so the stack can gracefully unwind. |
67 - (IBAction)quit:(id)sender { | 65 - (IBAction)quit:(id)sender { |
68 // TODO(pinkerton): | 66 // TODO(pinkerton): |
69 // since we have to roll it ourselves, ask the delegate (ourselves, really) | 67 // since we have to roll it ourselves, ask the delegate (ourselves, really) |
70 // if we should terminate. For example, we might not want to if the user | 68 // if we should terminate. For example, we might not want to if the user |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // various commands. | 101 // various commands. |
104 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 102 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
105 SEL action = [item action]; | 103 SEL action = [item action]; |
106 BOOL enable = NO; | 104 BOOL enable = NO; |
107 if (action == @selector(commandDispatch:)) { | 105 if (action == @selector(commandDispatch:)) { |
108 NSInteger tag = [item tag]; | 106 NSInteger tag = [item tag]; |
109 if (menuState_->SupportsCommand(tag)) | 107 if (menuState_->SupportsCommand(tag)) |
110 enable = menuState_->IsCommandEnabled(tag) ? YES : NO; | 108 enable = menuState_->IsCommandEnabled(tag) ? YES : NO; |
111 } else if (action == @selector(quit:)) { | 109 } else if (action == @selector(quit:)) { |
112 enable = YES; | 110 enable = YES; |
| 111 } else if (action == @selector(showPreferences:)) { |
| 112 enable = YES; |
113 } | 113 } |
114 return enable; | 114 return enable; |
115 } | 115 } |
116 | 116 |
117 // Called when the user picks a menu item when there are no key windows. Calls | 117 // Called when the user picks a menu item when there are no key windows. Calls |
118 // through to the browser object to execute the command. This assumes that the | 118 // through to the browser object to execute the command. This assumes that the |
119 // command is supported and doesn't check, otherwise it would have been disabled | 119 // command is supported and doesn't check, otherwise it would have been disabled |
120 // in the UI in validateUserInterfaceItem:. | 120 // in the UI in validateUserInterfaceItem:. |
121 - (void)commandDispatch:(id)sender { | 121 - (void)commandDispatch:(id)sender { |
122 Profile* default_profile = [self defaultProfile]; | 122 Profile* default_profile = [self defaultProfile]; |
(...skipping 26 matching lines...) Expand all Loading... |
149 | 149 |
150 // Otherwise open a new window. | 150 // Otherwise open a new window. |
151 Browser::OpenEmptyWindow([self defaultProfile]); | 151 Browser::OpenEmptyWindow([self defaultProfile]); |
152 | 152 |
153 // We've handled the reopen event, so return NO to tell AppKit not | 153 // We've handled the reopen event, so return NO to tell AppKit not |
154 // to do anything. | 154 // to do anything. |
155 return NO; | 155 return NO; |
156 } | 156 } |
157 | 157 |
158 - (void)initMenuState { | 158 - (void)initMenuState { |
159 menuState_ = new CommandUpdater(NULL); | 159 menuState_.reset(new CommandUpdater(NULL)); |
160 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); | 160 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); |
161 menuState_->UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); | 161 menuState_->UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); |
162 menuState_->UpdateCommandEnabled(IDC_OPEN_FILE, true); | 162 menuState_->UpdateCommandEnabled(IDC_OPEN_FILE, true); |
163 // TODO(pinkerton): ...more to come... | 163 // TODO(pinkerton): ...more to come... |
164 } | 164 } |
165 | 165 |
166 - (Profile*)defaultProfile { | 166 - (Profile*)defaultProfile { |
167 // TODO(jrg): Find a better way to get the "default" profile. | 167 // TODO(jrg): Find a better way to get the "default" profile. |
168 if (g_browser_process->profile_manager()) | 168 if (g_browser_process->profile_manager()) |
169 return* g_browser_process->profile_manager()->begin(); | 169 return* g_browser_process->profile_manager()->begin(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 NSData* fileURLData = [fileURLDesc data]; | 224 NSData* fileURLData = [fileURLDesc data]; |
225 if (!fileURLData) | 225 if (!fileURLData) |
226 continue; | 226 continue; |
227 GURL gurl(std::string((char*)[fileURLData bytes], [fileURLData length])); | 227 GURL gurl(std::string((char*)[fileURLData bytes], [fileURLData length])); |
228 gurlVector.push_back(gurl); | 228 gurlVector.push_back(gurl); |
229 } | 229 } |
230 | 230 |
231 OpenURLs(gurlVector); | 231 OpenURLs(gurlVector); |
232 } | 232 } |
233 | 233 |
| 234 // Show the preferences window, or bring it to the front if it's already |
| 235 // visible. |
| 236 - (IBAction)showPreferences:(id)sender { |
| 237 // TODO(pinkerton): more goes here... |
| 238 } |
| 239 |
234 @end | 240 @end |
OLD | NEW |