*prevent_default = Emit("open-file", &args);
}
+void App::OnOpenURL(const std::string& url) {
+ base::ListValue args;
+ args.AppendString(url);
+ Emit("open-url", &args);
+}
+
void App::OnWillFinishLaunching() {
Emit("will-finish-launching");
}
virtual void OnWindowAllClosed() OVERRIDE;
virtual void OnOpenFile(bool* prevent_default,
const std::string& file_path) OVERRIDE;
+ virtual void OnOpenURL(const std::string& url) OVERRIDE;
virtual void OnWillFinishLaunching() OVERRIDE;
virtual void OnFinishLaunching() OVERRIDE;
#import "browser/atom_application_mac.h"
#include "base/auto_reset.h"
+#include "base/strings/sys_string_conversions.h"
#include "browser/browser.h"
@implementation AtomApplication
handlingSendEvent_ = handlingSendEvent;
}
+- (void)awakeFromNib {
+ [[NSAppleEventManager sharedAppleEventManager]
+ setEventHandler:self
+ andSelector:@selector(handleURLEvent:withReplyEvent:)
+ forEventClass:kInternetEventClass
+ andEventID:kAEGetURL];
+}
+
- (IBAction)closeAllWindows:(id)sender {
atom::Browser::Get()->Quit();
}
+- (void)handleURLEvent:(NSAppleEventDescriptor*)event
+ withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
+ NSString* url = [
+ [event paramDescriptorForKeyword:keyDirectObject] stringValue];
+ atom::Browser::Get()->OpenURL(base::SysNSStringToUTF8(url));
+}
+
@end
return prevent_default;
}
+void Browser::OpenURL(const std::string& url) {
+ FOR_EACH_OBSERVER(BrowserObserver, observers_, OnOpenURL(url));
+}
+
void Browser::WillFinishLaunching() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching());
}
// Tell the application to open a file.
bool OpenFile(const std::string& file_path);
+ // Tell the application to open a url.
+ void OpenURL(const std::string& url);
+
// Tell the application the loading has been done.
void WillFinishLaunching();
void DidFinishLaunching();
virtual void OnOpenFile(bool* prevent_default,
const std::string& file_path) {}
+ // Browser is used to open a url.
+ virtual void OnOpenURL(const std::string& url) {}
+
// The browser has finished loading.
virtual void OnWillFinishLaunching() {}
virtual void OnFinishLaunching() {}
var app = require('app');
+var dialog = require('dialog');
var delegate = require('atom-delegate');
var ipc = require('ipc');
var Menu = require('menu');
app.terminate();
});
+app.on('open-url', function(event, url) {
+ dialog.showMessageBox({message: url, buttons: ['OK']});
+});
+
delegate.browserMainParts.preMainMessageLoopRun = function() {
app.commandLine.appendSwitch('js-flags', '--harmony_collections');