#164: basic AppleScript support

This commit is contained in:
Cameron Kaiser 2019-02-11 16:54:38 -08:00
parent ceed596553
commit a3765caeed
17 changed files with 1557 additions and 0 deletions

View File

@ -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

View File

@ -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>
@ -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>

View File

@ -0,0 +1,322 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary>
<suite name="Standard Suite" code="core" description="Common classes and commands for most applications.">
<cocoa name="NSCoreSuite"/>
<!--
<class name="item" code="cobj" description="A scriptable object." plural="items">
<cocoa class="GeckoObject"/>
<property name="class" code="pcls" type="type" access="r" description="The class of the object.">
<cocoa key="class"/>
</property>
<property name="properties" code="pALL" type="record" description="All of the object&apos;s properties.">
<cocoa key="properties"/>
</property>
<responds-to name="count">
<cocoa method=""/>
</responds-to>
<responds-to name="delete">
<cocoa method=""/>
</responds-to>
<responds-to name="duplicate">
<cocoa method=""/>
</responds-to>
<responds-to name="exists">
<cocoa method=""/>
</responds-to>
<responds-to name="get">
<cocoa method=""/>
</responds-to>
<responds-to name="move">
<cocoa method=""/>
</responds-to>
<responds-to name="set">
<cocoa method=""/>
</responds-to>
</class>
-->
<class name="window" code="cwin" description="A window.">
<cocoa class="NSWindow"/>
<property name="name" code="pnam" description="The full title of the window." type="text">
<cocoa key="title"/>
</property>
<property name="id" code="ID " description="The unique identifier of the window." type="integer" access="r">
<cocoa key="uniqueID"/>
</property>
<property name="bounds" code="pbnd" description="The bounding rectangle of the window." type="rectangle">
<cocoa key="boundsAsQDRect"/>
</property>
<property name="closeable" code="hclb" description="Whether the window has a close box." type="boolean" access="r">
<cocoa key="hasCloseBox"/>
</property>
<property name="titled" code="ptit" description="Whether the window has a title bar." type="boolean" access="r">
<cocoa key="hasTitleBar"/>
</property>
<property name="index" code="pidx" description="The index of the window in the back-to-front window ordering." type="integer">
<cocoa key="orderedIndex"/>
</property>
<property name="floating" code="isfl" description="Whether the window floats." type="boolean" access="r">
<cocoa key="isFloatingPanel"/>
</property>
<property name="miniaturizable" code="ismn" description="Whether the window can be miniaturized." type="boolean" access="r">
<cocoa key="isMiniaturizable"/>
</property>
<property name="miniaturized" code="pmnd" description="Whether the window is currently miniaturized." type="boolean">
<cocoa key="isMiniaturized"/>
</property>
<property name="modal" code="pmod" description="Whether the window is the application&apos;s current modal window." type="boolean" access="r">
<cocoa key="isModalPanel"/>
</property>
<property name="resizable" code="prsz" description="Whether the window can be resized." type="boolean" access="r">
<cocoa key="isResizable"/>
</property>
<property name="visible" code="pvis" description="Whether the window is currently visible." type="boolean">
<cocoa key="isVisible"/>
</property>
<property name="zoomable" code="iszm" description="Whether the window can be zoomed." type="boolean" access="r">
<cocoa key="isZoomable"/>
</property>
<property name="zoomed" code="pzum" description="Whether the window is currently zoomed." type="boolean">
<cocoa key="isZoomed"/>
</property>
<responds-to name="close">
<cocoa method="handleCloseScriptCommand:"/>
</responds-to>
<responds-to name="print">
<cocoa method="handlePrintScriptCommand:"/>
</responds-to>
<responds-to name="save">
<cocoa method="handleSaveScriptCommand:"/>
</responds-to>
</class>
<enumeration name="savo" code="savo">
<enumerator name="ask" code="ask " description="Ask the user whether or not to save the file."/>
<enumerator name="no" code="no " description="Do not save the file."/>
<enumerator name="yes" code="yes " description="Save the file."/>
</enumeration>
<command name="open" code="aevtodoc" description="Open an object.">
<direct-parameter description="The file(s) to be opened.">
<type type="file" list="yes"/>
</direct-parameter>
</command>
<command name="save" code="coresave" description="Save an object.">
<direct-parameter type="specifier" description="the object to save, usually a document or window"/>
<parameter name="as" code="fltp" type="text" optional="yes" description="The file type in which to save the data.">
<cocoa key="FileType"/>
</parameter>
<parameter name="in" code="kfil" type="file" optional="yes" description="The file in which to save the object.">
<cocoa key="File"/>
</parameter>
</command>
<enumeration name="printing error handling" code="enum">
<enumerator name="standard" code="lwst" description="Standard PostScript error handling">
<cocoa boolean-value="NO"/>
</enumerator>
<enumerator name="detailed" code="lwdt" description="print a detailed report of PostScript errors">
<cocoa boolean-value="YES"/>
</enumerator>
</enumeration>
<record-type name="print settings" code="pset">
<property name="copies" code="lwcp" type="integer" description="the number of copies of a document to be printed">
<cocoa key="NSCopies"/>
</property>
<property name="collating" code="lwcl" type="boolean" description="Should printed copies be collated?">
<cocoa key="NSMustCollate"/>
</property>
<property name="starting page" code="lwfp" type="integer" description="the first page of the document to be printed">
<cocoa key="NSFirstPage"/>
</property>
<property name="ending page" code="lwlp" type="integer" description="the last page of the document to be printed">
<cocoa key="NSLastPage"/>
</property>
<property name="pages across" code="lwla" type="integer" description="number of logical pages laid across a physical page">
<cocoa key="NSPagesAcross"/>
</property>
<property name="pages down" code="lwld" type="integer" description="number of logical pages laid out down a physical page">
<cocoa key="NSPagesDown"/>
</property>
<property name="requested print time" code="lwqt" type="date" description="the time at which the desktop printer should print the document">
<cocoa key="NSPrintTime"/>
</property>
<property name="error handling" code="lweh" type="printing error handling" description="how errors are handled">
<cocoa key="NSDetailedErrorReporting"/>
</property>
<property name="fax number" code="faxn" type="text" description="for fax number">
<cocoa key="NSFaxNumber"/>
</property>
<property name="target printer" code="trpr" type="text" description="for target printer">
<cocoa key="NSPrinterName"/>
</property>
</record-type>
<command name="print" code="aevtpdoc" description="Print an object.">
<direct-parameter type="file" description="The file(s) or document(s) to be printed."/>
<parameter name="print dialog" code="pdlg" type="boolean" optional="yes" description="Should the application show the Print dialog?">
<cocoa key="ShowPrintDialog"/>
</parameter>
<parameter name="with properties" code="prdt" type="print settings" optional="yes" description="the print settings">
<cocoa key="PrintSettings"/>
</parameter>
</command>
<command name="close" code="coreclos" description="Close an object.">
<cocoa class="NSCloseCommand"/>
<direct-parameter type="specifier" description="the object to close"/>
<!--
<parameter name="saving" code="savo" type="savo" optional="yes" description="Specifies whether changes should be saved before closing.">
<cocoa key="SaveOptions"/>
</parameter>
<parameter name="saving in" code="kfil" type="file" optional="yes" description="The file in which to save the object.">
<cocoa key="File"/>
</parameter>
-->
</command>
<command name="quit" code="aevtquit" description="Quit an application.">
<cocoa class="GeckoQuit"/>
<!--
<cocoa class="NSQuitCommand"/>
<parameter name="saving" code="savo" type="savo" optional="yes" description="Specifies whether changes should be saved before quitting.">
<cocoa key="SaveOptions"/>
</parameter>
-->
</command>
<command name="count" code="corecnte" description="Return the number of elements of a particular class within an object.">
<cocoa class="NSCountCommand"/>
<direct-parameter type="specifier" description="the object whose elements are to be counted"/>
<parameter name="each" code="kocl" type="type" optional="yes" description="The class of objects to be counted.">
<cocoa key="ObjectClass"/>
</parameter>
<result description="the number of elements" type="integer"/>
</command>
<command name="delete" code="coredelo" description="Delete an object.">
<cocoa class="NSDeleteCommand"/>
<direct-parameter type="specifier" description="the object to delete"/>
</command>
<command name="duplicate" code="coreclon" description="Copy object(s) and put the copies at a new location.">
<cocoa name="Copy" class="NSCloneCommand"/>
<direct-parameter type="specifier" description="the object(s) to duplicate"/>
<parameter name="to" code="insh" type="location specifier" optional="yes" description="The location for the new object(s).">
<cocoa key="ToLocation"/>
</parameter>
<parameter name="with properties" code="prdt" type="record" optional="yes" description="Properties to be set in the new duplicated object(s).">
<cocoa key="WithProperties"/>
</parameter>
<!-- ?? Duplicate is supposed to return the new objects, but it doesn't, at least in 10.4. -->
</command>
<command name="exists" code="coredoex" description="Verify if an object exists.">
<cocoa class="NSExistsCommand"/>
<direct-parameter type="specifier" description="the object in question"/>
<result description="true if it exists, false if not" type="boolean"/>
</command>
<command name="get" code="coregetd" description="Get the data for an object.">
<cocoa class="NSGetCommand"/>
<direct-parameter type="specifier" description="the object for the command"/>
<result type="any"/>
</command>
<command name="make" code="corecrel" description="Make a new object.">
<cocoa class="NSCreateCommand"/>
<parameter name="new" code="kocl" type="type" description="The class of the new object.">
<cocoa key="ObjectClass"/>
</parameter>
<parameter name="at" code="insh" type="location specifier" optional="yes" description="The location at which to insert the object.">
<cocoa key="Location"/>
</parameter>
<parameter name="with data" code="data" type="any" optional="yes" description="The initial data for the object.">
<cocoa key="ObjectData"/>
</parameter>
<parameter name="with properties" code="prdt" type="record" optional="yes" description="The initial values for properties of the object.">
<cocoa key="KeyDictionary"/>
</parameter>
<result description="to the new object" type="specifier"/>
</command>
<command name="move" code="coremove" description="Move object(s) to a new location.">
<cocoa class="NSMoveCommand"/>
<direct-parameter type="specifier" description="the object for the command"/>
<parameter name="to" code="insh" type="location specifier" description="The new location for the object(s).">
<cocoa key="ToLocation"/>
</parameter>
</command>
<command name="set" code="coresetd" description="Set an object&apos;s data.">
<cocoa class="NSSetCommand"/>
<direct-parameter type="specifier" description="the object for the command"/>
<parameter name="to" code="data" type="any" description="The new value.">
<cocoa key="Value"/>
</parameter>
</command>
</suite>
<suite name="%MAC_APP_NAME% suite" code="MOZB" description="%MAC_APP_NAME% specific classes">
<!-- 10.4 doesn't support class-extension. -->
<class name="application" code="capp" description="An application&apos;s top level scripting object." inherits="item" plural="applications">
<cocoa class="NSApplication"/>
<element type="window" access="r">
<cocoa key="orderedWindows"/>
</element>
<element type="browser window" access="r">
<cocoa key="scriptWindows"/>
</element>
<property name="frontmost" code="pisf" type="boolean" access="r" description="Is this the frontmost (active) application?">
<cocoa key="isActive"/>
</property>
<property name="name" code="pnam" type="text" access="r" description="The name of the application.">
<cocoa key="name"/>
</property>
<property name="version" code="vers" type="text" access="r" description="The version of the application.">
<cocoa key="version"/>
</property>
<!--
<responds-to name="open">
<cocoa method="handleOpenScriptCommand:"/>
</responds-to>
<responds-to name="quit">
<cocoa method="handleQuitScriptCommand:"/>
</responds-to>
-->
</class>
<class name="browser window" code="BWin" description="A %MAC_APP_NAME% browser window." inherits="window" plural="browser windows">
<contents name="current tab" code="pCTb" type="tab" access="r" description="The currently selected tab in the browser window.">
<cocoa key="selectedScriptTab"/>
</contents>
<cocoa class="GeckoWindow"/>
<element description="Tabs open in the browser window." type="tab" access="r">
<cocoa key="scriptTabs"/>
</element>
<property name="name" code="pnam" type="text" access="r" description="The full title of the browser window.">
<cocoa key="title"/>
</property>
<property name="index" code="pidx" type="integer" access="r" description="The index of the browser window, ordered front to back.">
<cocoa key="orderedIndex"/>
</property>
</class>
<class name="tab" code="BTab" description="A %MAC_APP_NAME% browser window tab." inherits="item" plural="tabs">
<cocoa class="GeckoTab"/>
<property name="name" code="pnam" type="text" access="r" description="The name of the tab.">
<cocoa key="title"/>
</property>
<property name="index" code="pidx" type="integer" access="r" description="The index of the tab, ordered left to right.">
<cocoa key="orderedIndex"/>
</property>
<property name="URL" code="pURL" type="text" access="rw" description="The current URL of the tab.">
<cocoa key="URL"/>
</property>
<property name="source" code="pSrc" type="text" access="r" description="The HTML source of the web page currently loaded in the tab.">
<cocoa key="source"/>
</property>
<property name="text" code="pTxt" type="text" access="r" description="The text of the web page currently loaded in the tab. Modifications to text aren&apos;t reflected on the web page.">
<cocoa key="text"/>
</property>
<property name="selected" code="pSTx" type="text" access="r" description="The selected text on the web page currently loaded in the tab.">
<cocoa key="selectedText"/>
</property>
<responds-to name="close">
<cocoa method="handleCloseScriptCommand:"/>
</responds-to>
<!--
<responds-to name="print">
<cocoa method="handlePrintScriptCommand:"/>
</responds-to>
<responds-to name="save">
<cocoa method="handleSaveScriptCommand:"/>
</responds-to>
-->
</class>
</suite>
</dictionary>

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,5 @@
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
DIRS += [
'public',
'src',
]

View File

@ -0,0 +1,6 @@
XPIDL_SOURCES += [
'nsIApplescriptService.idl',
]
XPIDL_MODULE = 'applescript'

View File

@ -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);
};

View File

@ -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

View File

@ -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 <scott@greenlay.net> (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 <Cocoa/Cocoa.h>
#import <objc/objc-runtime.h>
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<nsIXULWindow> 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<nsIDOMWindow> 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<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
if (!applescriptService) {
return [NSArray arrayWithObjects:nil];
}
nsCOMPtr<nsIArray> 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<nsIXULWindow> 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<nsIApplescriptService> 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<nsIBaseWindow> baseWindow = do_QueryInterface(mXULWindow, &rv);
NS_ENSURE_SUCCESS(rv, nil);
nsCOMPtr<nsIWidget> 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<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
if (!applescriptService) {
return [NSArray arrayWithObjects:nil];
}
nsCOMPtr<nsIArray> 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<nsIDOMWindow> 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<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
if (!applescriptService) {
return nil;
}
nsCOMPtr<nsIDOMWindow> 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<nsIApplescriptService> 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<nsPIDOMWindow> piWindow = do_QueryInterface(mContentWindow);
if (!piWindow)
return @"";
nsCOMPtr<nsIDocument> pdoc = piWindow->GetDoc();
if (!pdoc)
return @"";
nsCOMPtr<nsIPresShell> p = pdoc->GetShell();
if (!p)
return @"";
nsIDocument* doc = p->GetDocument();
if (doc) {
nsCOMPtr<nsIDOMHTMLDocument> 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<nsIDOMWindowInternal> contentWinInternal(do_QueryInterface(mContentWindow));
if (contentWinInternal) {
nsCOMPtr<nsIDOMLocation> 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<nsIDOMWindowInternal> contentWinInternal(do_QueryInterface(mContentWindow));
if (!contentWinInternal) {
return;
}
nsCOMPtr<nsIDOMLocation> 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<nsIDOMDocument> document;
if (NS_SUCCEEDED(mContentWindow->GetDocument(getter_AddRefs(document))) && document) {
nsCOMPtr<nsIDOMSerializer> 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<nsIDOMDocument> 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<nsIDocumentEncoder> 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<nsISelection> 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<nsIApplescriptService> 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<nsIAppStartup> appStartup = do_GetService(NS_APPSTARTUP_CONTRACTID);
if (appStartup) {
appStartup->Quit(nsIAppStartup::eAttemptQuit);
}
return nil;
}
@end

View File

@ -0,0 +1,12 @@
SOURCES += [
'MacScripting.mm',
'nsApplescriptService.cpp',
]
EXPORTS += [
'nsApplescriptService.h',
]
FINAL_LIBRARY = 'xul'

View File

@ -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 <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 "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;
}

View File

@ -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 <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 __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<nsIApplescriptWindowCallback> windowCallback;
nsCOMPtr<nsIApplescriptTabCallback> tabCallback;
};
#endif /* __nsApplescriptService__ */

View File

@ -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',

View File

@ -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 } }

View File

@ -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

View File

@ -61,6 +61,9 @@ DIRS += [
'xulstore'
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
DIRS += ['applescript'];
if CONFIG['MOZ_BUILD_APP'] != 'mobile/android':
DIRS += ['viewsource'];