diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in
index cdebd4d34d..7c419644c2 100644
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -96,6 +96,7 @@ tools repackage:: $(PROGRAM)
rsync -a --exclude '*.in' $(srcdir)/macbuild/Contents $(dist_dest) --exclude English.lproj
rsync -a --exclude '*.in' $(srcdir)/macbuild/Contents/Resources/English.lproj/ $(dist_dest)/$(LPROJ)
sed -e 's/%APP_VERSION%/$(MOZ_APP_VERSION)/' -e 's/%MAC_APP_NAME%/$(MAC_APP_NAME)/' -e 's/%MOZ_MACBUNDLE_ID%/$(MOZ_MACBUNDLE_ID)/' -e 's/%MAC_BUNDLE_VERSION%/$(MAC_BUNDLE_VERSION)/' -e 's/%APP_VERSION_DISPLAY%/$(MOZ_APP_VERSION_DISPLAY)/' $(srcdir)/macbuild/Contents/Info.plist.in > $(dist_dest)/Contents/Info.plist
+ sed -e "s/%MAC_APP_NAME%/$(MAC_APP_NAME)/g" $(srcdir)/macbuild/Contents/Resources/scripting.sdef.in | perl -0777 -pe 's{}{}gs' > $(dist_dest)/Contents/Resources/$(MAC_APP_NAME).sdef
sed -e 's/%MAC_APP_NAME%/$(MAC_APP_NAME)/' $(srcdir)/macbuild/Contents/Resources/English.lproj/InfoPlist.strings.in | iconv -f UTF-8 -t UTF-16 > $(dist_dest)/$(LPROJ)/InfoPlist.strings
rsync -a --exclude-from='$(srcdir)/macbuild/Contents/MacOS-files.in' $(DIST)/bin/ $(dist_dest)/Contents/Resources
rsync -a --include-from='$(srcdir)/macbuild/Contents/MacOS-files.in' --exclude '*' $(DIST)/bin/ $(dist_dest)/Contents/MacOS
diff --git a/browser/app/macbuild/Contents/Info.plist.in b/browser/app/macbuild/Contents/Info.plist.in
index ba93aff165..53077ab8cd 100644
--- a/browser/app/macbuild/Contents/Info.plist.in
+++ b/browser/app/macbuild/Contents/Info.plist.in
@@ -141,6 +141,22 @@
CFBundleTypeRole
Viewer
+
+ CFBundleTypeExtensions
+
+ webp
+
+ CFBundleTypeIconFile
+ document.icns
+ CFBundleTypeMIMETypes
+
+ image/webp
+
+ CFBundleTypeName
+ WebP Image
+ CFBundleTypeRole
+ Viewer
+
CFBundleExecutable
firefox
@@ -211,6 +227,8 @@
%MAC_BUNDLE_VERSION%
NSAppleScriptEnabled
+ OSAScriptingDefinition
+ %MAC_APP_NAME%.sdef
LSApplicationCategoryType
public.app-category.productivity
LSMinimumSystemVersion
diff --git a/browser/app/macbuild/Contents/Resources/scripting.sdef.in b/browser/app/macbuild/Contents/Resources/scripting.sdef.in
new file mode 100644
index 0000000000..77a5b95a8e
--- /dev/null
+++ b/browser/app/macbuild/Contents/Resources/scripting.sdef.in
@@ -0,0 +1,322 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js
index e4c64a348e..9f3f576b8d 100644
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -878,6 +878,85 @@ BrowserGlue.prototype = {
PluginCrashReporter.init();
#endif
+#ifdef XP_MACOSX
+ try {
+ var applescriptService = Cc["@mozilla.org/applescript-service;1"].getService(Ci.nsIApplescriptService);
+ var applescriptCallback = {
+ isFullBrowserWindow : function(win) {
+ try {
+ var domWindow = win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowInternal)
+ .QueryInterface(Ci.nsIDOMWindow);
+ return domWindow && !domWindow.closed && !domWindow.document.documentElement.getAttribute("chromehidden");
+ } catch(e) {}
+ return false;
+ },
+ getWindow : function(index) {
+ let windowList = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
+ while (windowList.hasMoreElements() && index >= 0) {
+ let nextWin = windowList.getNext();
+ if (this.isFullBrowserWindow(nextWin)) {
+ if (index == 0) {
+ return nextWin;
+ }
+ index--;
+ }
+ }
+ return null;
+ },
+ createWindowAtIndex : function(index) {
+ var handler = Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler);
+ var defaultArgs = handler.defaultArgs;
+ var topWindow = Services.wm.getMostRecentWindow('');
+ topWindow.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no,non-remote", defaultArgs);
+ },
+ getWindows : function() {
+ var array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
+ let windowList = Services.wm.getZOrderXULWindowEnumerator("navigator:browser", true);
+ while (windowList.hasMoreElements()) {
+ let nextWin = windowList.getNext();
+ if (this.isFullBrowserWindow(nextWin)) {
+ array.appendElement(nextWin, false);
+ }
+ }
+ return array;
+ },
+ getTabsInWindow : function(index) {
+ var array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
+ let win = this.getWindow(index);
+ Array.forEach(win.gBrowser.browsers, function (b) {
+ array.appendElement(b.contentWindow, false);
+ });
+ return array;
+ },
+ getCurrentTabInWindow : function(index, tab_index) {
+ let win = this.getWindow(index);
+ return win.content;
+ },
+ createTabAtIndexInWindow : function(index, window_index) {
+ let win = this.getWindow(window_index);
+ if (win != null) {
+ let tab = win.gBrowser.addTab();
+ win.gBrowser.moveTabTo(tab, index);
+ }
+ },
+ closeTabAtIndexInWindow : function(index, window_index) {
+ let win = this.getWindow(window_index);
+ if (win != null) {
+ var tab = win.gBrowser.tabs[index];
+ win.gBrowser.removeTab(tab);
+ }
+ }
+ }
+
+ applescriptService.registerWindowCallback(applescriptCallback);
+ applescriptService.registerTabCallback(applescriptCallback);
+ }
+ catch (e) {
+ dump("nsIApplescriptService could not be found\n");
+ }
+#endif
+
Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
#ifdef NIGHTLY_BUILD
diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in
index 57247f17e0..c9d79cf22c 100644
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -154,6 +154,9 @@
; [Components]
@RESPATH@/browser/components/components.manifest
@RESPATH@/components/alerts.xpt
+#ifdef XP_MACOSX
+@RESPATH@/components/applescript.xpt
+#endif
#ifdef ACCESSIBILITY
#ifdef XP_WIN32
@BINPATH@/AccessibleMarshal.dll
diff --git a/toolkit/components/applescript/moz.build b/toolkit/components/applescript/moz.build
new file mode 100644
index 0000000000..6912f929ed
--- /dev/null
+++ b/toolkit/components/applescript/moz.build
@@ -0,0 +1,5 @@
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+ DIRS += [
+ 'public',
+ 'src',
+ ]
diff --git a/toolkit/components/applescript/public/moz.build b/toolkit/components/applescript/public/moz.build
new file mode 100644
index 0000000000..5b7fa13e9a
--- /dev/null
+++ b/toolkit/components/applescript/public/moz.build
@@ -0,0 +1,6 @@
+XPIDL_SOURCES += [
+ 'nsIApplescriptService.idl',
+]
+
+XPIDL_MODULE = 'applescript'
+
diff --git a/toolkit/components/applescript/public/nsIApplescriptService.idl b/toolkit/components/applescript/public/nsIApplescriptService.idl
new file mode 100644
index 0000000000..2e07331563
--- /dev/null
+++ b/toolkit/components/applescript/public/nsIApplescriptService.idl
@@ -0,0 +1,161 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla XUL Toolkit.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Scott Greenlay
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsISupports.idl"
+#include "nsIArray.idl"
+#include "nsIDOMWindow.idl"
+
+interface nsIApplescriptWindowCallback;
+interface nsIApplescriptTabCallback;
+
+[scriptable, uuid(bc5f5505-86be-41a3-942d-36abda9a85f5)]
+interface nsIApplescriptService : nsISupports
+{
+ /**
+ * Registers callback for getWindows
+ *
+ * @param callback The nsIApplescriptWindowCallback callback.
+ */
+ void registerWindowCallback(in nsIApplescriptWindowCallback callback);
+
+ /**
+ * Registers callback for getTabsForWindow
+ *
+ * @param callback The nsIApplescriptTabCallback callback.
+ */
+ void registerTabCallback(in nsIApplescriptTabCallback callback);
+
+ /**
+ * Returns an array of nsIXULWindows representing the current
+ * windows
+ */
+ nsIArray getWindows();
+
+ /**
+ * Creates a window.
+ *
+ * @param index The tab's index.
+ */
+ void createWindowAtIndex(in unsigned long index);
+
+ /**
+ * Returns an array of nsIDOMWindows representing the tabs in
+ * the window at the given index.
+ *
+ * @param index The window's index.
+ */
+ nsIArray getTabsInWindow(in unsigned long index);
+
+ /**
+ * Returns a nsIDOMWindow representing the current tab in
+ * the window at the given index.
+ *
+ * @param index The window's index.
+ * @param tab_index Returns the tab's index.
+ */
+ nsIDOMWindow getCurrentTabInWindow(in unsigned long index, out unsigned long tab_index);
+
+ /**
+ * Creates a tab in the window at the given index.
+ *
+ * @param index The tab's index.
+ * @param window_index The window's index.
+ */
+ void createTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
+
+ /**
+ * Closes a tab in the window at the given index.
+ *
+ * @param index The tab's index.
+ * @param window_index The window's index.
+ */
+ void closeTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
+};
+
+[scriptable, uuid(45f087af-9c24-4fc6-9325-359382196a4e)]
+interface nsIApplescriptWindowCallback : nsISupports
+{
+ /**
+ * Returns an array of nsIXULWindows representing the current
+ * windows
+ */
+ nsIArray getWindows();
+
+ /**
+ * Creates a window.
+ *
+ * @param index The tab's index.
+ */
+ void createWindowAtIndex(in unsigned long index);
+};
+
+[scriptable, uuid(a433c084-ffc7-4264-90fa-82c1e0100b46)]
+interface nsIApplescriptTabCallback : nsISupports
+{
+ /**
+ * Returns an array of nsIDOMWindows representing the tabs in
+ * the window at the given index.
+ *
+ * @param index The window's index.
+ */
+ nsIArray getTabsInWindow(in unsigned long index);
+
+ /**
+ * Returns a nsIDOMWindow representing the current tab in
+ * the window at the given index.
+ *
+ * @param index The window's index.
+ * @param tab_index Returns the tab's index.
+ */
+ nsIDOMWindow getCurrentTabInWindow(in unsigned long index, out unsigned long tab_index);
+
+ /**
+ * Creates a tab in the window at the given index.
+ *
+ * @param index The tab's index.
+ * @param window_index The window's index.
+ */
+ void createTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
+
+ /**
+ * Closes a tab in the window at the given index.
+ *
+ * @param index The tab's index.
+ * @param window_index The window's index.
+ */
+ void closeTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
+};
diff --git a/toolkit/components/applescript/src/MacScripting.h b/toolkit/components/applescript/src/MacScripting.h
new file mode 100644
index 0000000000..a9f4af031c
--- /dev/null
+++ b/toolkit/components/applescript/src/MacScripting.h
@@ -0,0 +1,43 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla XUL Toolkit.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Scott Greenlay
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef MacScripting_h_
+#define MacScripting_h_
+
+void SetupMacScripting(void);
+
+#endif
diff --git a/toolkit/components/applescript/src/MacScripting.mm b/toolkit/components/applescript/src/MacScripting.mm
new file mode 100644
index 0000000000..11e73dfc86
--- /dev/null
+++ b/toolkit/components/applescript/src/MacScripting.mm
@@ -0,0 +1,691 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla XUL Toolkit.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010-2019
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Based on original works by Scott Greenlay (bug 608049).
+ * Ported to TenFourFox and 10.4 SDK by Cameron Kaiser
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#import
+#import
+extern "C" {
+ IMP class_lookupMethod(Class, SEL);
+};
+#define class_getMethodImplementation(x,y) class_lookupMethod(x,y)
+
+#import "MacScripting.h"
+
+#include "nsIApplescriptService.h"
+
+#include "nsCOMPtr.h"
+#include "nsComponentManagerUtils.h"
+#include "nsArrayUtils.h"
+#include "nsString.h"
+#include "nsContentCID.h"
+#include "nsIServiceManager.h"
+#include "nsServiceManagerUtils.h"
+#include "nsIAppStartup.h"
+#include "nsISelection.h"
+#include "nsIDOMNode.h"
+#include "nsIDOMDocument.h"
+#include "nsIDOMHTMLDocument.h"
+#include "nsIDOMSerializer.h"
+#include "nsIDocument.h"
+#include "nsIDocumentEncoder.h"
+#include "nsIWindowMediator.h"
+#include "nsISimpleEnumerator.h"
+#include "nsIBaseWindow.h"
+#include "nsIWidget.h"
+#include "nsIXULWindow.h"
+#include "nsIDOMWindow.h"
+#include "nsPIDOMWindow.h"
+#include "nsIDOMWindowUtils.h"
+#include "nsIInterfaceRequestor.h"
+#include "nsIDOMLocation.h"
+#include "nsIPresShell.h"
+#include "nsObjCExceptions.h"
+#include "nsToolkitCompsCID.h"
+
+// 10.4 no haz.
+typedef int NSInteger;
+typedef unsigned int NSUInteger;
+
+#define NSIntegerMax LONG_MAX
+#define NSIntegerMin LONG_MIN
+#define NSUIntegerMax ULONG_MAX
+
+@class GeckoObject;
+@class GeckoWindow;
+@class GeckoTab;
+
+#pragma mark -
+
+@interface GeckoScriptingRoot : NSObject
+{
+ @private
+ // These must persist for the life of the scripting application.
+ struct objc_method swinMeth;
+ struct objc_method insoMeth;
+ struct objc_method remoMeth;
+ struct objc_method_list methodList;
+ BOOL didInit;
+}
+
++ (GeckoScriptingRoot*)sharedScriptingRoot;
+- (id)init;
+- (void)makeApplicationScriptable:(NSApplication*)application;
+
+@end
+
+#pragma mark -
+
+@interface GeckoWindow : NSObject
+{
+ NSUInteger mIndex;
+ nsCOMPtr mXULWindow;
+}
+
+- (id)initWithIndex:(NSUInteger)index andXULWindow:(nsIXULWindow*)xulWindow;
++ (id)windowWithIndex:(NSUInteger)index andXULWindow:(nsIXULWindow*)xulWindow;
+
+// Default Scripting Dictionary
+- (NSString*)title;
+- (NSUInteger)orderedIndex;
+- (BOOL)isMiniaturizable;
+- (BOOL)isMiniaturized;
+- (void)setIsMiniaturized:(BOOL)miniaturized;
+- (BOOL)isResizable;
+- (BOOL)isVisible;
+- (void)setIsVisible:(BOOL)visible;
+- (BOOL)isZoomable;
+- (BOOL)isZoomed;
+- (void)setIsZoomed:(BOOL)zoomed;
+
+- (id)handleCloseScriptCommand:(NSCloseCommand*)command;
+
+// Gecko Scripting Dictionary
+- (NSArray*)scriptTabs;
+- (GeckoTab*)selectedScriptTab;
+
+// Helper Methods
+- (void)_setIndex:(NSUInteger)index;
+
+@end
+
+#pragma mark -
+
+@interface GeckoTab : NSObject
+{
+ NSUInteger mIndex;
+ GeckoWindow *mWindow;
+ nsCOMPtr mContentWindow;
+}
+
+- (id)initWithIndex:(NSUInteger)index andContentWindow:(nsIDOMWindow*)contentWindow andWindow:(GeckoWindow*)window;
++ (id)tabWithIndex:(NSUInteger)index andContentWindow:(nsIDOMWindow*)contentWindow andWindow:(GeckoWindow*)window;
+
+// Gecko Scripting Dictionary
+- (NSString*)title;
+- (NSUInteger)orderedIndex;
+- (NSString*)URL;
+- (NSString*)source;
+- (NSString*)text;
+- (NSString*)selectedText;
+
+- (void)setURL:(NSString*)newURL;
+
+- (id)handleCloseScriptCommand:(NSCloseCommand*)command;
+
+// Helper Methods
+- (void)_setWindow:(GeckoWindow*)window;
+- (void)_setIndex:(NSUInteger)index;
+
+@end
+
+#pragma mark -
+
+@interface GeckoQuit : NSScriptCommand
+{
+}
+
+@end
+
+#pragma mark -
+void SetupMacScripting(void) {
+ NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
+
+ [[GeckoScriptingRoot sharedScriptingRoot] makeApplicationScriptable:[NSApplication sharedApplication]];
+
+ NS_OBJC_END_TRY_ABORT_BLOCK;
+}
+
+#pragma mark -
+
+static GeckoScriptingRoot *sharedScriptingRoot = nil;
+
+@implementation GeckoScriptingRoot
+
++ (GeckoScriptingRoot*)sharedScriptingRoot {
+ @synchronized (sharedScriptingRoot) {
+ if (!sharedScriptingRoot) {
+ sharedScriptingRoot = [[GeckoScriptingRoot alloc] init];
+ }
+ }
+ return sharedScriptingRoot;
+}
+
+- (id)init {
+ self = [super init];
+ if (self)
+ didInit = NO;
+ return self;
+}
+
+- (void)makeApplicationScriptable:(NSApplication*)application {
+ if (didInit) return;
+
+ NS_WARNING("starting Script Host");
+ IMP scriptWindows = class_getMethodImplementation([self class], @selector(scriptWindows));
+// class_addMethod([application class], @selector(scriptWindows), scriptWindows, "@@:");
+
+ IMP insertScriptWindows = class_getMethodImplementation([self class], @selector(insertObject:inScriptWindowsAtIndex:));
+// class_addMethod([application class], @selector(insertObject:inScriptWindowsAtIndex:), insertScriptWindows, "v@:@I");
+
+ IMP removeScriptWindows = class_getMethodImplementation([self class], @selector(removeObjectFromScriptWindowsAtIndex:));
+// class_addMethod([application class], @selector(removeObjectFromScriptWindowsAtIndex:), removeScriptWindows, "v@:I");
+
+ // The 10.4 SDK doesn't have class_addMethod, but it does have class_addMethods.
+ swinMeth.method_name = @selector(scriptWindows);
+ swinMeth.method_imp = scriptWindows;
+ swinMeth.method_types = "@@:";
+
+ insoMeth.method_name = @selector(insertObject:inScriptWindowsAtIndex:);
+ insoMeth.method_imp = insertScriptWindows;
+ insoMeth.method_types = "v@:@l";
+
+ remoMeth.method_name = @selector(removeObjectFromScriptWindowsAtIndex:);
+ remoMeth.method_imp = removeScriptWindows;
+ remoMeth.method_types = "v@:l";
+
+ methodList.method_count = 3;
+ methodList.method_list[0] = swinMeth;
+ methodList.method_list[1] = insoMeth;
+ methodList.method_list[2] = remoMeth;
+
+ class_addMethods([application class], &methodList);
+ didInit = YES;
+}
+
+- (NSArray*)scriptWindows {
+ NS_WARNING("AppleScript: root scriptWindows");
+ nsCOMPtr applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
+ if (!applescriptService) {
+ return [NSArray arrayWithObjects:nil];
+ }
+
+ nsCOMPtr windows;
+ if (NS_FAILED(applescriptService->GetWindows(getter_AddRefs(windows))) || !windows) {
+ return [NSArray arrayWithObjects:nil];
+ }
+
+ NSUInteger index = 0;
+ NSMutableArray *windowArray = [NSMutableArray array];
+
+ PRUint32 length;
+ windows->GetLength(&length);
+ for (PRUint32 i = 0; i < length; ++i) {
+ nsCOMPtr xulWindow(do_QueryElementAt(windows, i));
+ if (xulWindow) {
+ GeckoWindow *window = [GeckoWindow windowWithIndex:index andXULWindow:xulWindow];
+ if (window) {
+ [windowArray addObject:window];
+ index++;
+ }
+ }
+ }
+ return windowArray;
+}
+
+- (void)insertObject:(NSObject*)object inScriptWindowsAtIndex:(NSUInteger)index {
+ if (![object isKindOfClass:[GeckoWindow class]]) {
+ return;
+ }
+
+ GeckoWindow *window = (GeckoWindow*)object;
+ [window _setIndex:index];
+
+ nsCOMPtr applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
+ if (applescriptService) {
+ (void*)applescriptService->CreateWindowAtIndex(index);
+ }
+}
+
+- (void)removeObjectFromScriptWindowsAtIndex:(NSUInteger)index {
+ NSArray *windows = [self scriptWindows];
+ if (windows && index < [windows count]) {
+ NSCloseCommand *closeCommend = [[[NSCloseCommand alloc] init] autorelease];
+ [(GeckoWindow*)[windows objectAtIndex:index] handleCloseScriptCommand:closeCommend];
+ }
+}
+
+@end
+
+#pragma mark -
+
+@implementation GeckoWindow
+
++ (id)windowWithIndex:(NSUInteger)index andXULWindow:(nsIXULWindow*)xulWindow {
+ return [[[self alloc] initWithIndex:index andXULWindow:xulWindow] autorelease];
+}
+
+- (id)initWithIndex:(NSUInteger)index andXULWindow:(nsIXULWindow*)xulWindow {
+ self = [super init];
+
+ if (self) {
+ mIndex = index;
+ mXULWindow = xulWindow;
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+- (void)_setIndex:(NSUInteger)index {
+ mIndex = index;
+}
+
+- (id)uniqueID {
+ return [NSNumber numberWithInt:mIndex];
+}
+
+- (NSScriptObjectSpecifier*)objectSpecifier
+{
+ NSScriptObjectSpecifier *objectSpecifier = [[NSUniqueIDSpecifier alloc] initWithContainerClassDescription:[NSScriptClassDescription classDescriptionForClass:[NSApp class]]
+ containerSpecifier:[NSApp objectSpecifier]
+ key:@"scriptWindows"
+ uniqueID:[self uniqueID]];
+
+ return [objectSpecifier autorelease];
+}
+
+- (NSWindow*)window
+{
+ nsresult rv;
+ nsCOMPtr baseWindow = do_QueryInterface(mXULWindow, &rv);
+ NS_ENSURE_SUCCESS(rv, nil);
+
+ nsCOMPtr widget;
+ rv = baseWindow->GetMainWidget(getter_AddRefs(widget));
+ NS_ENSURE_SUCCESS(rv, nil);
+
+ return (NSWindow*)widget->GetNativeData(NS_NATIVE_WINDOW);
+}
+
+- (NSString*)title
+{
+ NS_WARNING("AppleScript: window title");
+ NSWindow *window = [self window];
+ return window ? [window title] : @"";
+}
+
+- (NSUInteger)orderedIndex {
+ return mIndex;
+}
+
+- (BOOL)isMiniaturizable {
+ NSWindow *window = [self window];
+ return window ? [window isMiniaturizable] : false;
+}
+
+- (BOOL)isMiniaturized {
+ NSWindow *window = [self window];
+ return window ? [window isMiniaturizable] : false;
+}
+
+- (void)setIsMiniaturized:(BOOL)miniaturized {
+ NSWindow *window = [self window];
+ if (window) {
+ [window setIsMiniaturized:miniaturized];
+ }
+}
+
+- (BOOL)isResizable {
+ NSWindow *window = [self window];
+ return window ? [window isResizable] : false;
+}
+
+- (BOOL)isVisible {
+ NSWindow *window = [self window];
+ return window ? [window isVisible] : false;
+}
+
+- (void)setIsVisible:(BOOL)visible {
+ NSWindow *window = [self window];
+ if (window) {
+ [window setIsVisible:visible];
+ }
+}
+
+- (BOOL)isZoomable {
+ NSWindow *window = [self window];
+ return window ? [window isZoomable] : false;
+}
+
+- (BOOL)isZoomed {
+ NSWindow *window = [self window];
+ return window ? [window isZoomed] : false;
+}
+
+- (void)setIsZoomed:(BOOL)zoomed {
+ NSWindow *window = [self window];
+ if (window) {
+ [window setIsZoomed:zoomed];
+ }
+}
+
+- (id)handleCloseScriptCommand:(NSCloseCommand*)command {
+ NSWindow *window = [self window];
+ if (window) {
+ return [window handleCloseScriptCommand:command];
+ }
+ return nil;
+}
+
+- (NSArray*)scriptTabs {
+ NS_WARNING("AppleScript: window scriptTabs");
+ nsCOMPtr applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
+ if (!applescriptService) {
+ return [NSArray arrayWithObjects:nil];
+ }
+
+ nsCOMPtr tabs;
+ if (NS_FAILED(applescriptService->GetTabsInWindow(mIndex, getter_AddRefs(tabs))) || !tabs) {
+ return [NSArray arrayWithObjects:nil];
+ }
+
+ NSUInteger index = 0;
+ NSMutableArray *tabArray = [NSMutableArray array];
+
+ PRUint32 length;
+ tabs->GetLength(&length);
+ for (PRUint32 i = 0; i < length; ++i) {
+ nsCOMPtr contentWindow(do_QueryElementAt(tabs, i));
+ if (contentWindow) {
+ GeckoTab *tab = [GeckoTab tabWithIndex:index andContentWindow:contentWindow andWindow:self];
+ [tabArray addObject:tab];
+ index++;
+ }
+ }
+ return tabArray;
+}
+
+- (GeckoTab*)selectedScriptTab {
+ NS_WARNING("AppleScript: window selectedScriptTab");
+ nsCOMPtr applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
+ if (!applescriptService) {
+ return nil;
+ }
+
+ nsCOMPtr contentWindow;
+ PRUint32 tabIndex = 0;
+ if (NS_FAILED(applescriptService->GetCurrentTabInWindow(mIndex, &tabIndex, getter_AddRefs(contentWindow))) || !contentWindow) {
+ return nil;
+ }
+
+ return [GeckoTab tabWithIndex:tabIndex andContentWindow:contentWindow andWindow:self];
+}
+
+- (void)insertObject:(NSObject*)object inScriptTabsAtIndex:(NSUInteger)index {
+ if (![object isKindOfClass:[GeckoTab class]]) {
+ return;
+ }
+
+ [(GeckoTab*)object _setWindow:self];
+ [(GeckoTab*)object _setIndex:index];
+
+ nsCOMPtr applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
+ if (applescriptService) {
+ (void*)applescriptService->CreateTabAtIndexInWindow(index, mIndex);
+ }
+}
+
+- (void)removeObjectFromScriptTabsAtIndex:(NSUInteger)index {
+ NSArray *tabs = [self scriptTabs];
+ if (tabs && index < [tabs count]) {
+ NSCloseCommand *closeCommend = [[[NSCloseCommand alloc] init] autorelease];
+ [(GeckoTab*)[tabs objectAtIndex:index] handleCloseScriptCommand:closeCommend];
+ }
+}
+
+@end
+
+#pragma mark -
+
+@implementation GeckoTab
+
++ (id)tabWithIndex:(NSUInteger)index andContentWindow:(nsIDOMWindow*)contentWindow andWindow:(GeckoWindow*)window {
+ return [[[self alloc] initWithIndex:index andContentWindow:contentWindow andWindow:window] autorelease];
+}
+
+- (id)initWithIndex:(NSUInteger)index andContentWindow:(nsIDOMWindow*)contentWindow andWindow:(GeckoWindow*)window {
+ self = [super init];
+
+ if (self) {
+ mIndex = index;
+ mWindow = [window retain];
+ mContentWindow = contentWindow;
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+ [mWindow release];
+ [super dealloc];
+}
+
+- (void)_setWindow:(GeckoWindow*)window {
+ if (mWindow) {
+ [mWindow release];
+ }
+
+ mWindow = nil;
+
+ if (window) {
+ mWindow = [window retain];
+ }
+}
+
+- (void)_setIndex:(NSUInteger)index {
+ mIndex = index;
+}
+
+- (NSScriptObjectSpecifier*)objectSpecifier
+{
+ if (!mWindow) {
+ return nil;
+ }
+ NSScriptObjectSpecifier *objectSpecifier = [[NSIndexSpecifier alloc] initWithContainerClassDescription:[NSScriptClassDescription classDescriptionForClass:[mWindow class]]
+ containerSpecifier:[mWindow objectSpecifier]
+ key:@"scriptTabs"
+ index:[self orderedIndex]];
+ return [objectSpecifier autorelease];
+}
+
+- (NSString*)title
+{
+ NS_WARNING("AppleScript: tab title");
+ nsCOMPtr piWindow = do_QueryInterface(mContentWindow);
+ if (!piWindow)
+ return @"";
+ nsCOMPtr pdoc = piWindow->GetDoc();
+ if (!pdoc)
+ return @"";
+ nsCOMPtr p = pdoc->GetShell();
+ if (!p)
+ return @"";
+ nsIDocument* doc = p->GetDocument();
+ if (doc) {
+ nsCOMPtr htmlDocument(do_QueryInterface(doc));
+ if (htmlDocument) {
+ nsAutoString title;
+ if (NS_SUCCEEDED(htmlDocument->GetTitle(title))) {
+ return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(title).get()];
+ }
+ }
+ }
+ return @"";
+}
+
+- (NSString*)URL {
+#if(0)
+ nsCOMPtr contentWinInternal(do_QueryInterface(mContentWindow));
+ if (contentWinInternal) {
+ nsCOMPtr domLoc;
+ if (NS_SUCCEEDED(contentWinInternal->GetLocation(getter_AddRefs(domLoc))) && domLoc) {
+ nsAutoString url;
+ if (NS_SUCCEEDED(domLoc->ToString(url))) {
+ return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(url).get()];
+ }
+ }
+ }
+#endif
+ return @"";
+}
+
+- (void)setURL:(NSString*)newURL {
+#if(0)
+ nsCOMPtr contentWinInternal(do_QueryInterface(mContentWindow));
+ if (!contentWinInternal) {
+ return;
+ }
+ nsCOMPtr domLoc;
+ if (!NS_SUCCEEDED(contentWinInternal->GetLocation(getter_AddRefs(domLoc))) || !domLoc) {
+ return;
+ }
+ nsAutoString url;
+ if (NS_SUCCEEDED(domLoc->ToString(url))) {
+ nsCAutoString geckoURL;
+ geckoURL.Assign([newURL UTF8String]);
+ domLoc->Assign(NS_ConvertUTF8toUTF16(geckoURL));
+ }
+#endif
+}
+
+- (NSString*)source {
+#if(0)
+ nsCOMPtr document;
+ if (NS_SUCCEEDED(mContentWindow->GetDocument(getter_AddRefs(document))) && document) {
+ nsCOMPtr serializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID));
+ if (serializer) {
+ nsAutoString source;
+ if (NS_SUCCEEDED(serializer->SerializeToString(document, source))) {
+ return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(source).get()];
+ }
+ }
+ }
+#endif
+ return @"";
+}
+
+- (NSString*)text {
+#if(0)
+ nsCOMPtr document;
+ if (NS_SUCCEEDED(mContentWindow->GetDocument(getter_AddRefs(document))) && document) {
+ nsresult rv = NS_OK;
+
+ nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
+ formatType.Append("text/plain");
+
+ nsCOMPtr encoder(do_CreateInstance(formatType.get(), &rv));
+ if (NS_SUCCEEDED(rv) && encoder) {
+ PRUint32 flags = nsIDocumentEncoder::SkipInvisibleContent;
+ nsAutoString readstring;
+ readstring.AssignASCII("text/plain");
+
+ if (NS_SUCCEEDED(encoder->Init(document, readstring, flags))) {
+ nsAutoString text;
+ if (NS_SUCCEEDED(encoder->EncodeToString(text))) {
+ return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(text).get()];
+ }
+ }
+ }
+ }
+#endif
+ return @"";
+}
+
+- (NSString*)selectedText {
+#if(0)
+ nsCOMPtr selection;
+ if (NS_SUCCEEDED(mContentWindow->GetSelection(getter_AddRefs(selection))) && selection) {
+ nsXPIDLString selectedTextChars;
+ if (NS_SUCCEEDED(selection->ToString(getter_Copies(selectedTextChars)))) {
+ nsAutoString selectedText(selectedTextChars);
+ return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(selectedText).get()];
+ }
+ }
+#endif
+ return @"";
+}
+
+- (NSUInteger)orderedIndex {
+ return mIndex;
+}
+
+- (id)handleCloseScriptCommand:(NSCloseCommand*)command {
+ nsCOMPtr applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
+ if (applescriptService) {
+ (void*)applescriptService->CloseTabAtIndexInWindow(mIndex, [mWindow orderedIndex]);
+ }
+ return nil;
+}
+
+@end
+
+#pragma mark -
+
+@implementation GeckoQuit
+
+- (id)performDefaultImplementation {
+ NS_WARNING("AppleScript: quit");
+ nsCOMPtr appStartup = do_GetService(NS_APPSTARTUP_CONTRACTID);
+ if (appStartup) {
+ appStartup->Quit(nsIAppStartup::eAttemptQuit);
+ }
+ return nil;
+}
+
+@end
diff --git a/toolkit/components/applescript/src/moz.build b/toolkit/components/applescript/src/moz.build
new file mode 100644
index 0000000000..c4ac0a639b
--- /dev/null
+++ b/toolkit/components/applescript/src/moz.build
@@ -0,0 +1,12 @@
+
+SOURCES += [
+ 'MacScripting.mm',
+ 'nsApplescriptService.cpp',
+]
+
+EXPORTS += [
+ 'nsApplescriptService.h',
+]
+
+FINAL_LIBRARY = 'xul'
+
diff --git a/toolkit/components/applescript/src/nsApplescriptService.cpp b/toolkit/components/applescript/src/nsApplescriptService.cpp
new file mode 100644
index 0000000000..50994e1316
--- /dev/null
+++ b/toolkit/components/applescript/src/nsApplescriptService.cpp
@@ -0,0 +1,124 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla XUL Toolkit.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Scott Greenlay
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsXPCOM.h"
+#include "nsApplescriptService.h"
+
+#ifdef XP_MACOSX
+#include "MacScripting.h"
+#endif
+
+NS_IMPL_ISUPPORTS(nsApplescriptService, nsIApplescriptService)
+
+nsApplescriptService::nsApplescriptService()
+{
+#ifdef XP_MACOSX
+ SetupMacScripting();
+#endif
+}
+
+nsApplescriptService::~nsApplescriptService()
+{
+}
+
+NS_IMETHODIMP
+nsApplescriptService::GetWindows(nsIArray **windows)
+{
+ if (windowCallback) {
+ return windowCallback->GetWindows(windows);
+ }
+ *windows = NULL;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplescriptService::CreateWindowAtIndex(uint32_t index)
+{
+ if (windowCallback) {
+ return windowCallback->CreateWindowAtIndex(index);
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplescriptService::GetTabsInWindow(uint32_t index, nsIArray **tabs) {
+ if (tabCallback) {
+ return tabCallback->GetTabsInWindow(index, tabs);
+ }
+ *tabs = NULL;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplescriptService::GetCurrentTabInWindow(uint32_t index, uint32_t *tab_index, nsIDOMWindow **window) {
+ if (tabCallback) {
+ return tabCallback->GetCurrentTabInWindow(index, tab_index, window);
+ }
+ if (tab_index) {
+ tab_index = 0;
+ }
+ *window = NULL;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplescriptService::CreateTabAtIndexInWindow(uint32_t index, uint32_t window_index) {
+ if (tabCallback) {
+ return tabCallback->CreateTabAtIndexInWindow(index, window_index);
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplescriptService::CloseTabAtIndexInWindow(uint32_t index, uint32_t window_index) {
+ if (tabCallback) {
+ return tabCallback->CloseTabAtIndexInWindow(index, window_index);
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplescriptService::RegisterWindowCallback(nsIApplescriptWindowCallback *callback) {
+ windowCallback = callback;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplescriptService::RegisterTabCallback(nsIApplescriptTabCallback *callback) {
+ tabCallback = callback;
+ return NS_OK;
+}
diff --git a/toolkit/components/applescript/src/nsApplescriptService.h b/toolkit/components/applescript/src/nsApplescriptService.h
new file mode 100644
index 0000000000..5ce31f686b
--- /dev/null
+++ b/toolkit/components/applescript/src/nsApplescriptService.h
@@ -0,0 +1,60 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla XUL Toolkit.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Scott Greenlay
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef __nsApplescriptService__
+#define __nsApplescriptService__
+
+#include "nsCOMPtr.h"
+#include "nsIApplescriptService.h"
+
+class nsApplescriptService : public nsIApplescriptService
+{
+public:
+ NS_DECL_NSIAPPLESCRIPTSERVICE
+ NS_DECL_ISUPPORTS
+
+ nsApplescriptService();
+
+protected:
+ virtual ~nsApplescriptService();
+
+private:
+ nsCOMPtr windowCallback;
+ nsCOMPtr tabCallback;
+};
+
+#endif /* __nsApplescriptService__ */
diff --git a/toolkit/components/build/moz.build b/toolkit/components/build/moz.build
index f6786438c5..b233338574 100644
--- a/toolkit/components/build/moz.build
+++ b/toolkit/components/build/moz.build
@@ -28,6 +28,11 @@ LOCAL_INCLUDES += [
'../url-classifier',
]
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+ LOCAL_INCLUDES += [
+ '../applescript/src',
+ ]
+
if not CONFIG['MOZ_DISABLE_PARENTAL_CONTROLS']:
LOCAL_INCLUDES += [
'../parentalcontrols',
diff --git a/toolkit/components/build/nsToolkitCompsCID.h b/toolkit/components/build/nsToolkitCompsCID.h
index 0f6d20d2f3..42fe5d2a3d 100644
--- a/toolkit/components/build/nsToolkitCompsCID.h
+++ b/toolkit/components/build/nsToolkitCompsCID.h
@@ -12,6 +12,9 @@
#define NS_SYSTEMALERTSERVICE_CONTRACTID \
"@mozilla.org/system-alerts-service;1"
+#define NS_APPLESCRIPTSERVICE_CONTRACTID \
+ "@mozilla.org/applescript-service;1"
+
#define NS_AUTOCOMPLETECONTROLLER_CONTRACTID \
"@mozilla.org/autocomplete/controller;1"
@@ -101,6 +104,10 @@
#define NS_ALERTSSERVICE_CID \
{ 0xa0ccaaf8, 0x9da, 0x44d8, { 0xb2, 0x50, 0x9a, 0xc3, 0xe9, 0x3c, 0x81, 0x17 } }
+// {BC5F5505-86BE-41A3-942D-36ABDA9A85F5}
+#define NS_APPLESCRIPTSERVICE_CID \
+{ 0xbc5f5505, 0x86be, 0x41a3, { 0x94, 0x2d, 0x36, 0xab, 0xda, 0x9a, 0x85, 0xf5 } }
+
// {84E11F80-CA55-11DD-AD8B-0800200C9A66}
#define NS_SYSTEMALERTSSERVICE_CID \
{ 0x84e11f80, 0xca55, 0x11dd, { 0xad, 0x8b, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 } }
diff --git a/toolkit/components/build/nsToolkitCompsModule.cpp b/toolkit/components/build/nsToolkitCompsModule.cpp
index ecf2383ed9..7fc637976a 100644
--- a/toolkit/components/build/nsToolkitCompsModule.cpp
+++ b/toolkit/components/build/nsToolkitCompsModule.cpp
@@ -18,6 +18,10 @@
#include "nsAlertsService.h"
+#if defined(MOZ_WIDGET_COCOA)
+#include "nsApplescriptService.h"
+#endif
+
#include "nsDownloadManager.h"
#include "DownloadPlatform.h"
#include "nsDownloadProxy.h"
@@ -84,6 +88,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsParentalControlsService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAlertsService)
+#if defined(MOZ_WIDGET_COCOA)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsApplescriptService)
+#endif
+
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDownloadManager,
nsDownloadManager::GetSingleton)
NS_GENERIC_FACTORY_CONSTRUCTOR(DownloadPlatform)
@@ -139,6 +147,9 @@ NS_DEFINE_NAMED_CID(NS_TOOLKIT_TERMINATOR_CID);
#endif
NS_DEFINE_NAMED_CID(NS_USERINFO_CID);
NS_DEFINE_NAMED_CID(NS_ALERTSSERVICE_CID);
+#if defined(MOZ_WIDGET_COCOA)
+NS_DEFINE_NAMED_CID(NS_APPLESCRIPTSERVICE_CID);
+#endif
#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
NS_DEFINE_NAMED_CID(NS_PARENTALCONTROLSSERVICE_CID);
#endif
@@ -174,6 +185,9 @@ static const Module::CIDEntry kToolkitCIDs[] = {
#endif // defined (MOZ_HAS_PERFSTATS)
{ &kNS_USERINFO_CID, false, nullptr, nsUserInfoConstructor },
{ &kNS_ALERTSSERVICE_CID, false, nullptr, nsAlertsServiceConstructor },
+#if defined(MOZ_WIDGET_COCOA)
+ { &kNS_APPLESCRIPTSERVICE_CID, false, nullptr, nsApplescriptServiceConstructor },
+#endif
#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
{ &kNS_PARENTALCONTROLSSERVICE_CID, false, nullptr, nsParentalControlsServiceConstructor },
#endif
@@ -211,6 +225,9 @@ static const Module::ContractIDEntry kToolkitContracts[] = {
#endif // defined (MOZ_HAS_PERFSTATS)
{ NS_USERINFO_CONTRACTID, &kNS_USERINFO_CID },
{ NS_ALERTSERVICE_CONTRACTID, &kNS_ALERTSSERVICE_CID },
+#if defined(MOZ_WIDGET_COCOA)
+ { NS_APPLESCRIPTSERVICE_CONTRACTID, &kNS_APPLESCRIPTSERVICE_CID },
+#endif
#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
{ NS_PARENTALCONTROLSSERVICE_CONTRACTID, &kNS_PARENTALCONTROLSSERVICE_CID },
#endif
diff --git a/toolkit/components/moz.build b/toolkit/components/moz.build
index 800227e593..7fab1fc31c 100644
--- a/toolkit/components/moz.build
+++ b/toolkit/components/moz.build
@@ -61,6 +61,9 @@ DIRS += [
'xulstore'
]
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+ DIRS += ['applescript'];
+
if CONFIG['MOZ_BUILD_APP'] != 'mobile/android':
DIRS += ['viewsource'];