Skip to content

Commit

Permalink
#164: basic AppleScript support
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Feb 12, 2019
1 parent ceed596 commit a3765ca
Show file tree
Hide file tree
Showing 17 changed files with 1,557 additions and 0 deletions.
1 change: 1 addition & 0 deletions browser/app/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions browser/app/macbuild/Contents/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>webp</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>document.icns</string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>image/webp</string>
</array>
<key>CFBundleTypeName</key>
<string>WebP Image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>firefox</string>
Expand Down Expand Up @@ -211,6 +227,8 @@
<string>%MAC_BUNDLE_VERSION%</string>
<key>NSAppleScriptEnabled</key>
<true/>
<key>OSAScriptingDefinition</key>
<string>%MAC_APP_NAME%.sdef</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down
322 changes: 322 additions & 0 deletions browser/app/macbuild/Contents/Resources/scripting.sdef.in

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions browser/components/nsBrowserGlue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions browser/installer/package-manifest.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions toolkit/components/applescript/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
DIRS += [
'public',
'src',
]
6 changes: 6 additions & 0 deletions toolkit/components/applescript/public/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
XPIDL_SOURCES += [
'nsIApplescriptService.idl',
]

XPIDL_MODULE = 'applescript'

161 changes: 161 additions & 0 deletions toolkit/components/applescript/public/nsIApplescriptService.idl
Original file line number Diff line number Diff line change
@@ -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 <scott@greenlay.net>
*
* 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);
};
43 changes: 43 additions & 0 deletions toolkit/components/applescript/src/MacScripting.h
Original file line number Diff line number Diff line change
@@ -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 <scott@greenlay.net>
*
* 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
Loading

0 comments on commit a3765ca

Please sign in to comment.