diff options
author | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 21:43:09 +0000 |
---|---|---|
committer | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 21:43:09 +0000 |
commit | 57750f829d2a0f7850a6f2100d8db84624993bb3 (patch) | |
tree | 0647b428c50e7edac77722729f62331003e96dd3 /chrome/browser/app_controller_mac.mm | |
parent | 7867dfea46fbb8a030b02290d779ad58ce7632d7 (diff) | |
download | chromium_src-57750f829d2a0f7850a6f2100d8db84624993bb3.zip chromium_src-57750f829d2a0f7850a6f2100d8db84624993bb3.tar.gz chromium_src-57750f829d2a0f7850a6f2100d8db84624993bb3.tar.bz2 |
Handle file drops and URL open requests. Along with declaring that we handle the http scheme, this allows Chromium to be set as a default browser for the Mac.
Review URL: http://codereview.chromium.org/87043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14134 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 71eb508..6b2bf48 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -4,9 +4,12 @@ #import "chrome/browser/app_controller_mac.h" +#include "base/command_line.h" #include "base/message_loop.h" +#include "base/sys_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" +#include "chrome/browser/browser_init.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_shutdown.h" #import "chrome/browser/cocoa/bookmark_menu_bridge.h" @@ -16,6 +19,8 @@ @interface AppController(PRIVATE) - (void)initMenuState; +- (void)getUrl:(NSAppleEventDescriptor*)event + withReply:(NSAppleEventDescriptor*)reply; @end @implementation AppController @@ -32,6 +37,16 @@ // will be the signal to exit. DCHECK(g_browser_process); g_browser_process->AddRefModule(); + + NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; + [em setEventHandler:self + andSelector:@selector(getUrl:withReply:) + forEventClass:kInternetEventClass + andEventID:kAEGetURL]; + [em setEventHandler:self + andSelector:@selector(getUrl:withReply:) + forEventClass:'WWW!' // A particularly ancient AppleEvent that dates + andEventID:'OURL']; // back to the Spyglass days. } - (void)dealloc { @@ -52,6 +67,12 @@ // handle it. If it says to continue, post the quit message, otherwise // go back to normal. + NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; + [em removeEventHandlerForEventClass:kInternetEventClass + andEventID:kAEGetURL]; + [em removeEventHandlerForEventClass:'WWW!' + andEventID:'OURL']; + // TODO(pinkerton): Not sure where this should live, including it here // causes all sorts of asserts from the open renderers. On Windows, it // lives in Browser::OnWindowClosing, but that's not appropriate on Mac @@ -134,10 +155,49 @@ // TODO(jrg): DCHECK() to confirm that. // TODO(jrg): Find a better way to get the "default" profile. if (g_browser_process->profile_manager()) - return *g_browser_process->profile_manager()->begin(); + return* g_browser_process->profile_manager()->begin(); return NULL; } +// Various methods to open URLs that we get in a native fashion. We use +// BrowserInit here because on the other platforms, URLs to open come through +// the ProcessSingleton, and it calls BrowserInit. It's best to bottleneck the +// openings through that for uniform handling. + +namespace { + +void OpenURLs(const std::vector<GURL>& urls) { + CommandLine dummy((std::wstring())); + BrowserInit::LaunchWithProfile launch(std::wstring(), dummy); + launch.OpenURLsInBrowser(BrowserList::GetLastActive(), false, urls); +} + +} + +- (void)getUrl:(NSAppleEventDescriptor*)event + withReply:(NSAppleEventDescriptor*)reply { + NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] + stringValue]; + + GURL gurl(base::SysNSStringToUTF8(urlStr)); + std::vector<GURL> gurlVector; + gurlVector.push_back(gurl); + + OpenURLs(gurlVector); +} + +- (void)application:(NSApplication*)sender + openFiles:(NSArray*)filenames { + std::vector<GURL> gurlVector; + + for (NSString* filename in filenames) { + NSURL* fileURL = [NSURL fileURLWithPath:filename]; + GURL gurl(base::SysNSStringToUTF8([fileURL absoluteString])); + gurlVector.push_back(gurl); + } + + OpenURLs(gurlVector); +} @end |