Search completed in 1.29 seconds.
116 results for "xpconnect":
Your results are loading. Please wait...
nsIXPConnect
js/src/xpconnect/idl/nsIXPConnect.idlNot scriptable Provides the XPConnect service. ...
... js/src/xpconnect/idl/nsIXPConnect.idlNot scriptable Provides the XPConnect service. ...
... js/src/xpconnect/idl/nsIXPConnect.idlNot scriptable Provides the XPConnect service. ...
...And 31 more matches
XPConnect wrappers
This document is a high-level overview of XPConnect wrapper objects (for the more technical description see XPConnect security membranes). For practical advice on dealing with wrappers, see Safely accessing content DOM from chrome. Developers in the know understand that wrappers play a large role in XPConnect, and that we have a lot of them. Less informed developers understand that wrappers exist and are somehow important, but they don't know when they should use what wrappers, or if they should be seeing a wrapper. Note: Wrappers can appear in the console log; for example "[object XrayWrapper [object blah]]". Because these are wrapped, you won't be able to peek down inside them from the console. ...
...d that we have a lot of them. Less informed developers understand that wrappers exist and are somehow important, but they don't know when they should use what wrappers, or if they should be seeing a wrapper. Note: Wrappers can appear in the console log; for example "[object XrayWrapper [object blah]]". Because these are wrapped, you won't be able to peek down inside them from the console. Basic XPConnect objects XPCWrappedNative These objects are created when any natively implemented XPCOM object (that is, any object implemented in C++) needs to be reflected into JavaScript. This includes all DOM objects (including Window) and chrome elements that are reflected into JavaScript. This wrapper is responsible for mapping calls from JavaScript into C++. This means that when you say window.focus(), ...
...nted XPCOM object (that is, any object implemented in C++) needs to be reflected into JavaScript. This includes all DOM objects (including Window) and chrome elements that are reflected into JavaScript. This wrapper is responsible for mapping calls from JavaScript into C++. This means that when you say window.focus(), you're calling into XPCWrappedNative code. If you call 'toString()' and get "[xpconnect wrapped nsIFoo]" then the reference is to a XPCWrappedNative object with interface nsIFoo. They are implicitly created by XPConnect and you should not have to worry about how that happens. There are several types of wrapped natives, but I won't cover those here. XPCWrappedJS These objects are the exact opposite of XPCWrappedNative. They exist to reflect an object from JavaScript into C++. This...
...er you pass your JavaScript object into a C++ function, we create one of these wrappers. For example, if you've implemented some component with an interface nsIFoo and you pass your JavaScript object into a C++ function taking an nsIFoo, an XPCWrappedJS is created around your object. C++ calls are routed through XPCWrappedJS code into your JavaScript implementation. These wrappers are created by XPConnect, so you should not have to worry about how to construct them or whether to construct them. Double wrapping. There is one case where an XPCWrappedNative wraps another wrapper object. This case is where a JS object was passed in via some IDL-declared interface, creating an XPCWrappedJS, and is now being returned to JavaScript via some other interface. In order to preserve API compatibility, an XPC...
XPConnect
XPConnect is a bridge between JavaScript and XPCOM. With XPConnect, you can use XPCOM components from JavaScript code, and interact with JavaScript objects from within XPCOM components. XPConnect is part of Firefox and is actively used in XUL applications. Documentation Architecture basics XPConnect, JavaScript, XPCOM, XUL... Using components How to talk with XPCOM components. XPConnect and XPIDL FAQ A FAQ about using XPConnect and XPIDL. This page needs to migrate to MDN. ...
...OM components. XPConnect is part of Firefox and is actively used in XUL applications. Documentation Architecture basics XPConnect, JavaScript, XPCOM, XUL... Using components How to talk with XPCOM components. XPConnect and XPIDL FAQ A FAQ about using XPConnect and XPIDL. This page needs to migrate to MDN. ...
...efox and is actively used in XUL applications. Documentation Architecture basics XPConnect, JavaScript, XPCOM, XUL... Using components How to talk with XPCOM components. XPConnect and XPIDL FAQ A FAQ about using XPConnect and XPIDL. This page needs to migrate to MDN. ...
Fun With XBL and XPConnect
Once the regular XUL textfield widget is bound to this interface, it calls the auto complete function of the object using regular JavaScript. The basic model of interaction is as follows: Binding to the XPCOM Object The widget holds onto an XPCOM object that is the auto complete engine that will perform our auto complete lookups. ...
Index
Mozilla › Tech › XPCOM › Index
ersions (Firefox 2 and 3, for example). 6 Creating a Python XPCOM component Guide, NeedsHelp, PyXPCOM, XPCOM, XPCOM:Language Bindings Creating Applications with Mozilla already provides a tutorial for making a simple JavaScript or C++ component (implementing the nsISimple interface). Here is how to make the same component in Python using PyXPCOM. ...
... Creating a Python XPCOM component Guide, NeedsHelp, PyXPCOM, XPCOM, XPCOM:Language Bindings Creating Applications with Mozilla already provides a tutorial for making a simple JavaScript or C++ component (implementing the nsISimple interface). Here is how to make the same component in Python using PyXPCOM. 7 Fun With XBL and XPConnect XBL, XPCOM, XPCOM:Language Bindings, XPConnect No summary! 8 Generating GUIDs Add-ons, Developing Mozilla, Developing_Mozilla:Tools, Extensions, Tools, XPCOM GUIDs are used in Mozilla programming for identifying several types of entities, including XPCOM Interfaces (this type of GUIDs is callled IID), components (CID), and legacy add-ons--like extensions and themes--that were created prior to Firefox 1.5. Add-ons ca...
...Embedding, Landing, Mozilla, XPCOM, XPCOM:Language Bindings An XPCOM Language Binding is a bridge between a particular language and XPCOM to provide access to XPCOM objects from that language, and to let modules written in that language be used as XPCOM objects by all other languages for which there are XPCOM bindings. ...
...And 32 more matches
Mozilla DOM Hacking Guide
ledge of C++ and XPCOM is assumed. If you don't know XPCOM yet, and would like to be able to read this document quickly, you can read the Introduction to XPCOM for the DOM. Otherwise, for more detailed XPCOM documentation, please see the XPCOM project page. Class Info and Helper Classes Introduction to Class Info Class Info is what gives the DOM classes their correct behavior when used through XPConnect. It lies at the heart of the famous "XPCDOM landing" that happened in May. We will talk a lot about XPConnect in this document, since it is so important for the DOM. By "correct behavior", I mean "the intended behavior with respect to the specification or de facto standard". We will see that Class Info is mainly used to implement the DOM Level 0. The W3C DOM is mainly implemented in IDL. The goal...
...r the DOM. By "correct behavior", I mean "the intended behavior with respect to the specification or de facto standard". We will see that Class Info is mainly used to implement the DOM Level 0. The W3C DOM is mainly implemented in IDL. The goals of Class Info are twofold: Interface flattening, and implementing behaviors that are not possible with IDL alone. A brief introduction to JavaScript and XPConnect. Before we begin the explanation of Class Info, I'd like to introduce quickly the JavaScript engine and XPConnect. In JavaScript, there is no knowledge of types, like there is in C++. A function for example can be represented by a JSFunction, a JSObject, a jsval, ... This means that when we use the DOM from JavaScript, we pass arguments that have no type. However, since the DOM is coded in C++, ...
...ine and XPConnect. In JavaScript, there is no knowledge of types, like there is in C++. A function for example can be represented by a JSFunction, a JSObject, a jsval, ... This means that when we use the DOM from JavaScript, we pass arguments that have no type. However, since the DOM is coded in C++, we expect to receive an argument of the correct type for our function. This is one of the jobs of XPConnect. XPConnect will "wrap" the argument in a wrapper that will be of the type expected by our C++ function. Similarly, then return type of the C++ function will be wrapped by XPConnect so that JavaScript can use it safely. When, in JavaScript, a client tries to access a DOM object or a DOM method on a DOM object, the JS engine asks XPConnect to search for the relevant C++ method to call. For example...
...And 20 more matches
nsIDOMWindowUtils
d key inputting. This state is the same as ime-mode: password. IME_STATUS_PLUGIN 3 Plug-in has focus. At this time we should not attempt to set the IME state. COMPOSITION_ATTR_RAWINPUT 0x02 Synthesize a text event to the window. Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges. Currently, this method doesn't support 4 or more clauses composition string. Obsolete since Gecko 38.0 COMPOSITION_ATTR_SELECTEDRAWTEXT 0x03 Obsolete since Gecko 38.0 COMPOSITION_ATTR_CONVERTEDTEXT 0x04 Obsolete since Gecko 38.0 COMPOSITION_ATTR_SELECTEDCONVERTEDTEXT 0x05 Obsolete since Gecko 38.0 QUERY_CONTENT_FLAG_USE_NAT...
...See CSS2 specification for details. AUTHOR_SHEET 2 A possible type of a style sheet loaded/removed with loadSheet()/removeSheet(). See CSS2 specification for details. Methods activateNativeMenuItemAt() See nsIWidget.ActivateNativeMenuItemAt(). Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges. void activateNativeMenuItemAt( in AString indexString ); Parameters indexString clearMozAfterPaintEvents() void clearMozAfterPaintEvents(); Parameters None. compareCanvases() Compare the two canvases, returning the number of differing pixels and the maximum difference in a channel. This will throw an error if the dimensions of the two canvases are different. This m...
...ateNativeMenuItemAt( in AString indexString ); Parameters indexString clearMozAfterPaintEvents() void clearMozAfterPaintEvents(); Parameters None. compareCanvases() Compare the two canvases, returning the number of differing pixels and the maximum difference in a channel. This will throw an error if the dimensions of the two canvases are different. This method requires UniversalXPConnect privileges. PRUint32 compareCanvases( in nsIDOMHTMLCanvasElement aCanvas1, in nsIDOMHTMLCanvasElement aCanvas2, out unsigned long aMaxDifference ); Parameters aCanvas1 aCanvas2 aMaxDifference Return value computeAnimationDistance() Method for testing nsStyleAnimation::ComputeDistance. Returns the distance between the two values as reported by nsStyleAnimation::Comput...
...And 18 more matches
nsIXPCScriptable
Note: This is not really an XPCOM interface. For example, callers must guarantee that they set the *_retval of the various methods that return a boolean to PR_TRUE before making the call. Implementations may skip writing to *_retval unless they want to return PR_FALSE. js/src/xpconnect/idl/nsIXPCScriptable.idlNot scriptable Please add a summary to this article. Last changed in Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0) Inherits from: nsISupports Method overview void preCreate(in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); void create(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); void postCreate(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); ...
...3.0 / SeaMonkey 2.0) Inherits from: nsISupports Method overview void preCreate(in nsISupports nativeObj, in JSContextPtr cx, in JSObjectPtr globalObj, out JSObjectPtr parentObj); void create(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); void postCreate(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); PRBool addProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); PRBool delProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); PRBool getProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); PRBool setProperty(in nsIXPConnectWrappedNative...
...Property(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); PRBool getProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); PRBool setProperty(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in JSValPtr vp); PRBool enumerate(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj); PRBool newEnumerate(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 enum_op, in JSValPtr statep, out JSID idp); PRBool newResolve(in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); PRBool convert(in nsIXPCo...
...And 16 more matches
JavaScript-DOM Prototypes in Mozilla
In the case where the C++ object has class info (nsIClassInfo), the JSObject is a more or less empty JSObject which is not really that special. ...
...In the case where the C++ object has class info (nsIClassInfo), the JSObject is a more or less empty JSObject which is not really that special. ...
...In the case where the C++ object has class info (nsIClassInfo), the JSObject is a more or less empty JSObject which is not really that special. ...
...And 7 more matches
Using XPCOM Components
og to view, organize, or remove cookies that have been stored on the system, they are using the CookieManager component behind the scenes. The Cookie Manager Dialog shows user interface[cookie-manager-ui] that is presented to the user in Mozilla for working with the CookieManager component. The Cookie Manager Dialog This dialog is written in XUL and JavaScript, and uses a part of XPCOM called XPConnect to seamlessly connect to the CookieManager component (see Connecting to Components from the Interface below). XUL is just one way to expose the functionality of the CookieManager component-but it's a particularly useful one in the Mozilla world. The functionality of the CookieManager component is available through the nsICookieManager interface, which is comprised of the public methods in the ta...
...sICookieManager interface is called. The function is carried out by the CookieManager component, and the selected cookie is deleted from disk and removed from the displayed list. ...
...ions() { for (var c=0; c<deletedCookies.length; c++) { cmgr.remove(deletedCookies[c].host, deletedCookies[c].name, deletedCookies[c].path); } deletedCookies.length = 0; } Connecting to Components from the Interface The Mozilla user interface uses JavaScript that has been given access to XPCOM components in the application core with a technology called XPConnect. ...
...And 7 more matches
Chapter 4: Using XPCOM—Implementing advanced processes - Archive of obsolete content
trouble with any of the details of the interface, it is helpful to search on the source code for usage examples within Firefox. Note: To look at the Firefox 3 source code, choose "Firefox 3" in the Starting Points list. For Firefox 3.5 choose "Mozilla 1.9.1." For the current development trunk of Firefox, choose "Mozilla Central" and for Thunderbird, choose "Comm. Central". Calling XPCOM from XPConnect Use the XPConnect technology to use XPCOM in JavaScript. Listing 1 shows how you can use XPConnect to acquire references to XPCOM services and create new XPCOM objects. Each component is identified with a contract ID in the form @domain_name/module_name/component_name;version_number, and implements one or more interfaces that determine what functions can be called on these components. Interface...
...d be accessed with getService(). For other components, you can create as many instances as you need. For instance, this is the case for files (nsILocalFile). Those are created with createInstance(). It's important to know whether a component should be created with getService() or createInstance(), because using one instead of the other can cause problems. ...
...ing XPCOM functions using XPConnect <?xml version="1.0" encoding="UTF-8"?> <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script type="application/javascript"><![CDATA[ var ioService = Components.classes['@mozilla.org/network/io-service;1'] .getService(Components.interfaces.nsIIOService); alert(ioService); ]]></script> </page> Calling XPConnect using local files Try saving the contents of Listing 1 as the file test.xul, somewhere on your desktop, and drag and drop it into Firefox to open it. You'll note that even though the file includes an alert method, nothing happens. This is a by-product of the fact that test.xul currently doesn't have privileges. In order to use XPConnect, the file needs special UniversalXPConnect privileges. Bec...
...And 5 more matches
wrappedJSObject
wrappedJSObject is a property sometimes available on XPConnect wrappers. When available, it lets you access the JavaScript object hidden by the wrapper. There are two kinds of XPConnect wrappers that support the wrappedJSObject property: XPCNativeWrappers which are used to protect the chrome code working with content objects. See XPCNativeWrapper for detailed documentation. Regular XPConnect wrappers which you can encounter, for example, when using XPCOM components implemented in JS. This article focuses on the latter kind of wrappers, which hide any properties or methods on the component that are not part of the supported interfaces as declared in xpidl. The rest of this article demonstrates what XPConnect wrappers do and how wrappedJSObject can be used to bypass them. Example com...
...the @myself.com/my-component;1 contract. ...
...face: function(aIID) { if (!aIID.equals(Components.interfaces.nsISupports) && !aIID.equals(Components.interfaces.nsIHelloWorld)) throw Components.results.NS_ERROR_NO_INTERFACE; return this; } }; XPConnect wrapping Now let's get a reference to our component. ...
...And 4 more matches
The Joy of XUL - Archive of obsolete content
ish to keep proprietary. The Netscape Public License (NPL) and Mozilla Public License (MPL) require developers who alter original work (source code files that are provided with Mozilla) to release the source code for these changes to their customers. Overlays can be used to add features to Mozilla without contaminating the original open source code with proprietary alterations. ...
.... The Netscape Public License (NPL) and Mozilla Public License (MPL) require developers who alter original work (source code files that are provided with Mozilla) to release the source code for these changes to their customers. Overlays can be used to add features to Mozilla without contaminating the original open source code with proprietary alterations. ...
.../XPConnect XPCOM and XPConnect are complementary technologies that enable the integration of external libraries with XUL applications. XPCOM, which stands for Cross Platform Component Object Model, is a framework for writing cross-platform, modular software. XPCOM components can be written in C, C++, and JavaScript, and they can be used from C, C++, JavaScript, Python, Java, and Perl. XPConnect is a technology which enables simple interoperation between XPCOM and JavaScript. XPConnect allows JavaScript objects to transparently access and manipulate XPCOM objects. It also enables JavaScript objects to present XPCOM compliant interfaces to be called by XPCOM objects. ...
...And 3 more matches
Mozilla internal string guide
L String types The C++ signatures follow the abstract-type convention described above, such that all method parameters are based on the abstract classes. The following table describes the purpose of each string type in IDL. IDL type C++ Type Purpose string char* Raw character pointer to ASCII (7-bit) string, no string classes used. High bit is not guaranteed across XPConnect boundaries. wstring char16_t* Raw character pointer to UTF-16 string, no string classes used. AString nsAString UTF-16 string. ACString nsACString 8-bit string. All bits are preserved across XPConnect boundaries. AUTF8String nsACString UTF-8 string. Converted to UTF-16 as necessary when value is used across XPConnect boundaries. ...
...The special JavaScript value undefined becomes the string "undefined". ...
.... The implementation of GetUtf16String() will use aResult.Assign to "return" the value. In SetUtf16String() the value of the string can be used through a variety of methods including Iterators, PromiseFlatString, and assignment to other strings. In GetValue(), the first parameter, aKey, is treated as a raw sequence of 8-bit values. Any non-ASCII characters in aKey will be preserved when crossing XPConnect boundaries. The implementation of GetValue() will assign a UTF-8 encoded 8-bit string into aResult. If the this method is called across XPConnect boundaries, such as from a script, then the result will be decoded from UTF-8 into UTF-16 and used as a Unicode value. Choosing a string type It can be difficult to determine the correct string type to use for IDL. The following points should help det...
...And 3 more matches
Language bindings
ll other languages for which XPCOM bindings exist to access these modules. Since the XPCOM layer itself is written in C/C++, its API can be accessed out-of-the-box using C or C++. In order to allow any other language to use the XPCOM API, a bridging layer is required. ...
... other language to use the XPCOM API, a bridging layer is required. The following bridging layers are currently available: Components objectThe Components object is the object through which XPConnect functionality is reflected into JavaScript. ...
...true or false respectively.Components.lastResultComponents.managerComponents.manager is a convenience reflection of the global native component manager service. The scriptable methods on the nsIComponentManager interface can be called directly on this object.Components.resultsComponents.results is a read-only object whose properties are the names listed as the first parameters of the macros in js/xpconnect/src/xpc.msg (also at Table Of Errors), with the value of each corresponding to that constant's value.Components.returnCodeComponents.stackComponents.stack is a read only property of type nsIStackFrame (IDL definition) that represents a snapshot of the current JavaScript callstack. This can be used for various diagnostic purposes.Components.utilsComponents.utils is a collection of various useful X...
...And 2 more matches
Index - Archive of obsolete content
at the queries use syntax that is specific to XML. 1683 Textbox (XPFE autocomplete) XUL Elements, XUL Reference This element is created by setting the type attribute of a textbox to autocomplete. It is used to create a textbox with a popup containing a list of possible completions for what the user has started to type. 1684 The Joy of XUL Guide, Mozilla, XPCOM, XPConnect, XUL This guide is designed to introduce application developers and their managers to XUL so they can not only understand why Mozilla's platform is based on it, but how they might adopt it for their own use. XUL (pronounced "zool") is Mozilla's XML-based user interface language that lets you build feature rich cross-platform applications that can run connected to or disconnected from the In...
...BL, XUL, XUL_Tutorial This section will describe an example XBL element. 1809 XBL Inheritance Tutorials, XBL, XUL, XUL_Tutorial No summary! 1810 XPCOM Examples Tutorials, XUL, XUL_Tutorial This section provides some examples of using XPCOM along with some additional interfaces. 1811 XPCOM Interfaces Tutorials, XPCOM:Language Bindings, XPConnect, XUL, XUL_Tutorial No summary! 1812 XUL Structure Tutorials, XUL, XUL_Tutorial We'll begin by looking at how the XUL is handled in Mozilla. 1813 XUL accessibility guidelines Accessibility, XUL Welcome to the XUL Accessibility Guidelines. By following these principles and practices, you will be able to write your XUL applications in such a way that a...
...amonkey and for the record, old Netscape 4.x. Its original inspiration comes from http://www.alain.knaff.lu/howto/MozillaCustomization/ and http://mit.edu/~firefox/www/maintain...utoconfig.html. For history, I've kept Mozilla and Netscape chapters, as certain points are complementary to the web-based AutoConfig file. 3424 Monitoring WiFi access points WiFi Code with UniversalXPConnect privileges can monitor the list of available WiFi access points to obtain information about them including their SSID, MAC address, and signal strength. This capability was introduced primarily to allow WiFi-based location services to be used by geolocation services. 3425 No Proxy For configuration Administration, Configuration management, Guide, NeedsUpdate This document pro...
...pting for NPAPI plugins Plugins that used to take advantage of being scriptable via LiveConnect in 4.x Netscape browsers lost this possibility in the new world. The main reason for this is that there is no guarantee of Java compatibility on a binary level due to the jri/jni switch. The new Mozilla XPCOM architecture allows XPCOM components be scriptable via a different mechanism called XPConnect. We leverage some of these ideas to help you make your Netscape Communicator 4.x plugins exposed to JavaScript in Mozilla based browsers. 3613 Plugins Add-ons, NPAPI, Obsolete, Plugins For more information about plugin roadmap, see non-archived plugin information. 3614 Adobe Flash Add-ons, Addons, Adobe, Flash, Guide, NeedsUpdate, Plugins This article exp...
Monitoring WiFi access points - Archive of obsolete content
Code with UniversalXPConnect privileges can monitor the list of available WiFi access points to obtain information about them including their SSID, MAC address, and signal strength. This capability was introduced primarily to allow WiFi-based location services to be used by geolocation services. Example This example simply displays a list of the available access points. ...
...ity was introduced primarily to allow WiFi-based location services to be used by geolocation services. Example This example simply displays a list of the available access points. ...
...sPoints.length; i++) { var a = accessPoints[i]; d.innerHTML += "<p>" + a.mac + " " + a.ssid + " " + a.signal + "</p>"; } var c = document.getElementById("c"); c.innerHTML = "<p>" + count++ + "</p>"; }, onError: function (value) { alert("error: " +value); }, QueryInterface: function(iid) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); if (iid.equals(Components.interfaces.nsIWifiListener) || iid.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_ERROR_NO_INTERFACE; }, } netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var listener = new test(); var wifi_service = Components.classes["@mozilla.org/wifi/monitor;1"].getSe...
...t> </head> <body> <div id="d"><p></p></div> <div id="c"><p></p></div> </body> </html> The nsIWifiListener object The first thing the code above does is to prototype the listener object that will be receiving notifications of changes to the access point list. This object is described in lines 11 through 40 in the code above. The onChange() method (lines 13 through 27) begins by enabling UniversalXPConnect privileges, then clearing out the div (d) that will receive the updated list of access points. Then the loop in lines 19-22 iterates over the list of access points received in the accessPoints array and adds them to the HTML in the div. Then the c div is updated with the number of times the list has been refreshed. The onError() method simply opens an alert that displays the error code received. ...
XPJS Components Proposal - Archive of obsolete content
This is a proposal for a system that got implemented, but it may differ from the actual implementation. See the status document for more recent info on the status of this proposal. Draft 1.0 What are XPJS Components? XPJS Components is a (cheesy) name for a system to support xpcom components written in JavaScript. Now, you might ask: "Isn't that what XPConnect does?" And I would answer that XPConnect is necessary, but not sufficient to the task. XPConnect provides the mechanisms for communication between native and JS xpcom components, but it does not provide all of the infrastructure to register and instantiate JS components outside of the limitations of the browser window. XPJS will provide that infrastructure. So what does this mean? The XPJS Component system will support implemen...
...her. The XPJSManager is in charge of loading these .js files, helping them register themselves, and acting as an intermediary between the xpcom component manager and the JS code. XJS Components are not run in browser windows. Each .js file (let's call it a module) is started up and run in the context of a relatively 'raw' JS global object. The standard (non-DOM) JS classes will be available. The xpconnectComponents object will be available. And some additional yet to be defined objects may be available. The xpconnectComponents object allows access to the whole repository of native and JS xpcom components, so this is not as isolated an environment as it might at first sound. A 'load' or 'import' function will also be provided to let the JS code import other .js files where libraries of code might ...
... When a XPJS Component module is first installed - or at autoregistration time - the XPJSManager will load the .js file into a fresh JS environment, let its top level script run to do whatever initialization it wants to do, and then it will call the module's NSRegisterSelf function (passing the filespec of the .js file). ...
...tance for some clsid (or progid). The component manager will load up the XPJSManager's module and call the native NSGetFactory it finds there. That native NSGetFactory function will check the information it stored in the registry to see that the JS factory for the given clsid is in a given .js file. It will load that .js file (if not already loaded) and call the NSGetFactory function. Our friend XPConnect will convert the JS object returned from the JS module's NSGetFactory function into an xpcom object. The component manager (and anyone else with a reference to that factory) can then call the factory's CreateInstance method at will. The JS module is free to implement factories and components and services that the factories construct on command. Any code anywhere and implemented in any language c...
Leak-hunting strategies and tips
structors that should have been virtual: If you expect to override an object's destructor (which includes giving a derived class of it an nsCOMPtr member variable) and delete that object through a pointer to the base class using delete, its destructor better be virtual. ...
... override an object's destructor (which includes giving a derived class of it an nsCOMPtr member variable) and delete that object through a pointer to the base class using delete, its destructor better be virtual. (But we have many virtual destructors in the codebase that don't need to be -- don't do that.) Debugging leaks that go through XPConnect Many large object graphs that leak go through XPConnect. ...
... includes giving a derived class of it an nsCOMPtr member variable) and delete that object through a pointer to the base class using delete, its destructor better be virtual. (But we have many virtual destructors in the codebase that don't need to be -- don't do that.) Debugging leaks that go through XPConnect Many large object graphs that leak go through XPConnect. ...
...hrough a pointer to the base class using delete, its destructor better be virtual. (But we have many virtual destructors in the codebase that don't need to be -- don't do that.) Debugging leaks that go through XPConnect Many large object graphs that leak go through XPConnect. This can mean there will be XPConnect wrapper objects showing up as owning the leaked objects, but it doesn't mean it's XPConnect's fault (although that has been known to happen, it's rare). Debugging leaks that go through XPConnect requires a basic understanding of what XPConnect does. XPConnect allows an XPCOM object to be exposed to JavaScript, and it allows certain JavaScript objects to be exposed to C++ code as normal XPCOM objects. When a C++ object is exposed to JavaScript (the more common of the two), an XPCWrapped...
Avoiding leaks in JavaScript XPCOM components
in Firefox 3, a cycle collector was introduced and refined in later versions, and Mozilla is currently working on a generational garbage collector for JS. This article needs to be updated to reflect the changes and the cases where they help. Take every information on this site with a grain of salt, although most concepts and best practices still apply. Using XPCOM in JavaScript (also known as XPConnect) is an environment where memory management issues are not obvious. There are no calls to malloc and free and no reference counting. Despite this, it's easy to write JavaScript code that leaks. It's easy to write leaky code in any garbage-collected language. But it's even easier in this environment because some of the objects you're dealing with are reference-counted behind the scenes. Programmer...
...grammer can still create leaks by leaving objects reachable that are no longer needed. For example, if an object's constructor adds the object to a list that is reachable from a global variable and nothing ever removes it from the list, the object will never be destroyed since it is always reachable from the list. ...
...It allows JavaScript code to access XPCOM objects (i.e., it wraps native XPCOM objects for JavaScript) and it allows JavaScript code to implement XPCOM interfaces (i.e., it wraps JavaScript objects for XPCOM). ...
...It allows JavaScript code to access XPCOM objects (i.e., it wraps native XPCOM objects for JavaScript) and it allows JavaScript code to implement XPCOM interfaces (i.e., it wraps JavaScript objects for XPCOM). For JavaScript objects that implement XPCOM interfaces, the interface between reference counting and garbage collection is quite simple. ...
Chapter 3: Introduction to XUL—How to build a more intuitive UI - Archive of obsolete content
Please be aware that if you attempt to open this sample directly in Firefox, it will not run correctly. Menus Hierarchically structured dropdown menus are the part of the user interface used for frequently accessed functions in an application o...
...the autocompletesearch attribute. If you want to use the Location Bar history, set the value for this to history; if you want it to be the Search Bar history, use search-history; and if you want it to be another form's input history, use form-history; this attribute can take one value or multiple space-delimited values. Also, in order to actually read in a history for autocomplete, you will need XPConnect privileges, which we will cover in Chapter 4. Menu List Use the menulist element to create a control for making selections from a drop-down list. As shown in Listing 17, this is implemented in combination with the menupopup element; it produces output as shown in Figure 14. A click reveals the drop-down list; when an item is selected, the values of that item's label and value attributes are co...
...te backward and forward through pages and includes the ability to prevent scripts in embedded frames from accessing outside the frame. For building applications linked to external web pages, this is a more secure and more convenient approach. The tabbrowser element is even more capable than the browser element because it includes the basic tab-handling features from Firefox. To use this requires XPConnect privileges, the same as autocomplete does; this will be covered in Chapter 4. Opening a page If you specify a URI value for the src attribute in the browser element, that URI will be opened by default. If the src attribute's value changes, you can dynamically open a different web page or XUL document. Functions like Back, Forward, Reload can all be called using the goBack(), goForward(), and r...
Components.lastResult
Most interfaces only return one success code -- NS_OK -- so Components.lastResult is rarely necessary. ...
...Most interfaces only return one success code -- NS_OK -- so Components.lastResult is rarely necessary. ...
...only return one success code -- NS_OK -- so Components.lastResult is rarely necessary. In cases where Components.lastResult is used, it is best to get it right away after the target call is made and save it in a local variable to test its value rather than doing multiple tests against Components.lastResult. This is because many 'Components' properties and methods are themselves implemented using XPConnect and subsequent calls to Components.lastResult might reflect the result of 'implicit' XPConnect calls rather than the result of the target call. Example In the following example, the local variable i contains the actual result returned by bar() (assuming that bar() is called via XPConnect), and Components.lastResult contains the success code returned by bar(). // Given that foo.bar is a method ...
Components object
ture. Warning: This object is only intended for code running with chrome privileges. Exposing the object to regular web code was a mistake. If you use this object on your web page, your site might break at any time! In current versions of Firefox only a few interfaces required for compatibility are still accessible. Don't use Components! The Components object is the object through which XPConnect functionality is reflected into JavaScript. The Components object is actually a native instance of the nsIXPCComponents interface which is reflected into JavaScript as a top level object using XPConnect. Some properties of Components require advanced privileges and may not work in web pages. The Components object has the following members: classes array of classes by ContractID class...
...which is reflected into JavaScript as a top level object using XPConnect. Some properties of Components require advanced privileges and may not work in web pages. ...
... utils.cre...
xptcall FAQ
assembly language code. It is used to facilitate cross language and cross thread method calls. Porting this code is required in order to make Mozilla run on any given platform. Why does xptcall exist? xptcall exists for two reasons: To support invoking arbitrary methods on XPCOM interfaces. To support dynamically impersonating any XPCOM interface. Both of these facilities are required by XPConnect. These facilities are also used by xpcom/proxy. It may also be used by other subsystems in the future. The xptcall approach was chosen over an approach that would have required generating stub code for calling and implementing all interfaces. Though the chosen approach requires some core platform specific code, it has minimal footprint and is extendable to work with any valid XPCOM interface wit...
...rts* that, PRUint32 methodIndex, PRUint32 paramCount, nsXPTCVariant* params); nsXPTCVariant is a discriminated union of the types that can be passed as parameters to the target function (including void* to represent arbitrary pointer types). Given the correct set of parameters, this function can call any method on any XPCOM interface. XPConnect uses information from typelib files to reflect arbitrary XPCOM interfaces into JavaScript and to make calls from JavaScript to XPCOM using XPTC_InvokeByIndex. The information in the typelibs allows XPConnect to convert function parameters and build the nsXPTCVariant array required to make this call. The stubs (or impersonation) facility of xptcall allows for implementing a class which can, at ru...
...credible ideas about how to get the required functionality in a cross platform way and/or without resorting to assembly code I'd love to hear about it. Is xptcall a platform requirement for Mozilla? Yes. Mozilla will not run properly without a functioning port of xptcall. Non-functional stub code exists to allow building xptcall on non-supported platforms. But any browser feature that relies on XPConnect will fail. Any platform that does not do xptcall is in trouble. We need to get moving on getting xptcall working everywhere! What platforms are supported? The growing list: Porting status Where can I find other resources? The code is at: xpcom/reflect/xptcall A new porting guide is at: https://developer.mozilla.org/En/Xptcall_Porting_Guide Pre-implementation proposals are here and here...
xpidl
Mozilla › Tech › XPIDL › xpidl
pyxpidl has been used for some time now, but now this older tool has been fully retired. xpidl is based on the libIDL idl compiler from the Gnome project. ...
...pyxpidl has been used for some time now, but now this older tool has been fully retired. xpidl is based on the libIDL idl compiler from the Gnome project. ...
...(NYI) -t create a typelib of a specific version number -I add entry to start of include path for ``#include "nsIThing.idl" -o use basename (e.g. ...
WebIDL bindings
r you want here. return; } // For some reason we want to catch and rethrow exceptions from SetSomeNumber, say. aCallback.SetSomeNumber(2*number, rv, eRethrowExceptions); if (rv.Failed()) { // The exception is now stored on rv. This code MUST report // it usefully; otherwise it will assert. } } External interfaces External interfaces are represented in C++ as objects that XPConnect knows how to unwrap to. This can mean XPCOM interfaces (whether declared in XPIDL or not) or it can mean some type that there's a castable native unwrapping function for. The C++ type to be used should be the nativeType listed for the external interface in the Bindings.conf file. The exact representation depends on how the type is being used. Arguments become nsIFoo*. Return values can be alr...
...gument, defaulting to eReportExceptions, and calling it will invoke the callable with undefined as the this value. The second Call method allows passing in an explicit this value as the first argument. This second call method is a template on the type of the first argument, so the this value can be passed in in whatever form is most convenient, as long as it's either a type that can be wrapped by XPConnect or a WebIDL interface type. If aReportExceptions is set to eReportExceptions, the Call methods will report JS exceptions before returning. If aReportExceptions is set to eRethrowExceptions, JS exceptions will be stashed in the ErrorResult and will be reported when the stack unwinds to wherever the ErrorResult was set up. For example, this WebIDL: callback MyCallback = long (MyInterface arg1, ...
...riginCallable] Used to flag a method that, when called, will not have the same-origin constraint tested: it can be called from a context with a different origin. [SecureContext] We implement the standard extended attribute with a few details specific to Gecko: System principals are considered secure. An extension poking at non-secured DOM objects will see APIs marked with [SecureContext]. XPConnect sandboxes doesn't see [SecureContext] APIs, but this may change in bug 1273687. [NeedsSubjectPrincipal], [GetterNeedsSubjectPrincipal], [SetterNeedsSubjectPrincipal] Used to flag a method or an attribute that needs to know the subject principal. This principal will be passed as argument. If the interface is not exposed on any worker global, the argument will be a nsIPrincipal& because a subje...
A XUL Bestiary - Archive of obsolete content
tion Object Model in the hierarchy of XUL widgets: browser, menu, menuitem, and so on. The DOM and the AOM form a kind of continuum, the whole of which is manipulable from the standards upon which XUL is based. Near Synonyms for XUL There is much confusion about the words that begin with "X" in the Mozilla Open Source Project. The Mozilla XPArchitecture section below describes XPCOM, XPIDL, and XPConnect, three somewhat related technologies for getting access to application code from the interface. This section describes XUL, XPToolkit, and XPFE, which are in some respects synonymous and in others quite different. In briefest terms, XUL is the XML-based language used for creating interfaces, XPToolkit is the set of XUL widgets (menus, toolbar, etc.) actually assembed for this purpose -- the buil...
...ces rules for design and compilation that make it possible to use the services of an object without knowing anything about implementation. XPIDL, the Cross-Platform Interface Definition Language, is a language in which these interfaces insisted upon by XPCOM can be described. When XPIDL is used to describe the XPCOM interfaces, it makes those interfaces available in special header files. Finally, XPConnect is the technology that connects these XPCOM/XPIDL interfaces to JavaScript, the scripting language XUL uses. These three cross-platform glue technologies fit in the middle of an architecture that looks something like this: Author: Ian Oeschger Other Documents: Mozilla Jargon File and Introduction to XUL Original Document Information Author(s): Ian Oeschger Last Updated Date: April 16, 2...
Index - Archive of obsolete content
Archive › Mozilla › XUL › Index
that the queries use syntax that is specific to XML. 952 Textbox (XPFE autocomplete) XUL Elements, XUL Reference This element is created by setting the type attribute of a textbox to autocomplete. It is used to create a textbox with a popup containing a list of possible completions for what the user has started to type. 953 The Joy of XUL Guide, Mozilla, XPCOM, XPConnect, XUL This guide is designed to introduce application developers and their managers to XUL so they can not only understand why Mozilla's platform is based on it, but how they might adopt it for their own use. XUL (pronounced "zool") is Mozilla's XML-based user interface language that lets you build feature rich cross-platform applications that can run connected to or disconnected from the In...
...BL, XUL, XUL_Tutorial This section will describe an example XBL element. 1078 XBL Inheritance Tutorials, XBL, XUL, XUL_Tutorial No summary! 1079 XPCOM Examples Tutorials, XUL, XUL_Tutorial This section provides some examples of using XPCOM along with some additional interfaces. 1080 XPCOM Interfaces Tutorials, XPCOM:Language Bindings, XPConnect, XUL, XUL_Tutorial No summary! 1081 XUL Structure Tutorials, XUL, XUL_Tutorial We'll begin by looking at how the XUL is handled in Mozilla. 1082 XUL accessibility guidelines Accessibility, XUL Welcome to the XUL Accessibility Guidelines. By following these principles and practices, you will be able to write your XUL applications in such a way that a...
Extentsions FAQ - Archive of obsolete content
How to customizes toolbar button to coexist in a toolbar palette and status bar? Option #3 Install Status Buttons 1.0 <https://addons.mozilla.org/firefox/1272/> "Lets you put toolbar buttons at either end of the status-bar. ...
...rbird address book lacks. ...
RDF in Mozilla FAQ - Archive of obsolete content
datasource is a locally-installed component that implements nsIRDFDataSource. For example, the bookmarks service. First, check here to make sure you will be allowed to access a built-in datasource. There are several security restrictions on accessing built-in datasources from "untrusted" XUL and JS. Since a built-in datasource is just an XPCOM component, you can instantiate it directly using the XPConnect component manager. // Use the component manager to get the bookmarks service var bookmarks = Components. classes["@mozilla.org/rdf/datasource;1?name=bookmarks"]. getService(Components.interfaces.nsIRDFDataSource); // Now do something interesting with it... if (bookmarks.HasAssertion( RDF.GetResource("http://home.netscape.com/NC-rdf#BookmarksRoot"), RDF.GetResource("http://home.n...
...longside duplicates.xul. Note that for these to work, you have to relax Mozilla's security model. To do this, add the following line to your preferences file. (Shut down Mozilla first since it overwrites your preferences file when you quit.) user_pref("signed.applets.codebase_principal_support", true); Mozilla will ask you if you want to grant the scripts in duplicates.xul permission to access XPConnect; respond in the affirmative. Currently, Mozilla does not allow unprivileged access to the RDF interfaces and services; see bug 122846 for details. Please mail danbri, mozilla-rdf or waterson with URLs if you are aware of other examples to which we ought to link! Notes See also W3C RDF and Semantic Web pages for more information on RDF and related technologies. Contributors Examples sec...
A bird's-eye view of the Mozilla framework
an interface defined in XPIDL (Cross-Platform IDL), derived from the CORBA IDL. The XPIDL interface description is independent of the programming language used to implement the object itself. For example, a JavaScript object or C++ class could both implement the same XPIDL interface. Scripting languages such as JavaScript cannot directly access XPCOM components, but access them indirectly using XPConnect. XPConnect also provides a required layer for XPCOM components written in a scripting language. Let's consider a Resource Description Framework (RDF) example, where RDF is a framework for describing and interchangingmetadata, that is, information about information. In this example, we're interested in the RDF sub-graph underlying theContents Panel widget within theHelp Viewer window. Suppose the...
...f the XULElement as a single RDF graph. var tocDS = tocTree.database; NsIRDFCompositeDataSource inherits from nsIRDFDataSource. Help.js declares an nsIRDFService as a compile time constant at the beginning of the file. const RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); The Components object is made available to JavaScript via XPConnect; it serves as a bridge connecting JavaScript and XPCOM. getLink() uses the nsIRDFService to obtain an nsIRDFResource for the requested link. var resource = RDF.GetResource(rdfID); nsIRDFCompositeDataSource inherits from nsIRDFDataSource, which supports a GetTarget() method for obtaining the nsIRDFNode for a given resource and property. var link = tocDS.GetTarget(resource, NC_LINK, true); ...
JavaScript Tips
XUL Tips When inserting code with an XUL overlay, wrap functions and variables inside an object with a unique name to avoid conflicting with existing or future function and variable names. var UniqueName = { _privateMember: 3, publicMember: "A string", init: function() { this.doSomething(this.anotherMember); }, doSomething: function(aParam) { alert(aParam); } }; XPConnect Don't use object methods and properties more than you have to. It is often faster to store the result in a temporary variable. Don't call methods that you don't have to. For instance, windowManager.getEnumerator(aType).hasMoreElements() may be replaced with windowManager.getMostRecentWindow(aType) != null for a single window. Don't query interfaces unless you need to access methods and prope...
...terfaces in both cases). Don't call QueryInterface unless you expect to succeed. Instead, use instanceof, e,g,: if (target instanceof Components.interfaces.nsIRDFResource) return target.Value; if (target instanceof Components.interfaces.nsIRDFLiteral) return target.Value; return null; Don't test the return value of QueryInterface, it always returns the original variable if it succeeds. XPConnect knows all about tearoffs and modifies the object that you QueryInterface or instanceof to cache all its known interfaces. When passing an object to an XPCOM method it is helpful if the object you pass is an XPCOM object, so that the C++ method access a C++ object. However, this is not always necessary or desirable. For instance the offline observer declared above is a JavaScript object that is r...
about:memory
This "explicit" value at the root of the tree represents all the memory allocated via explicit calls to allocation functions. The "window-objects" sub-tree represents all JavaScript window objects, which includes the browser tabs and UI windows. For example, the "top(http://editio...
...resents heap-allocated memory that is not measured by any memory reporter. This is typically 10--20% of "explicit". If it gets higher, it indicates that additional memory reporters should be added. DMD can be used to determine where these memory reporters should be added. There are measurements for other content such as images and workers, and for browser subsystems such as the startup cache and XPConnect. Some add-on memory usage is identified, as the following example shows. +---40,214,384 B (04.17%) -- add-ons | +--21,184,320 B (02.20%) ++ {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}/js-non-window/zones/zone(0x100496800)/compartment([System Principal], jar:file:///Users/njn/Library/Application%20Support/Firefox/Profiles/puna0zr8.new/extensions/%7Bd10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d%7D.xpi!/boot...
GCIntegration - SpiderMonkey Redirect 1
in the first slice of the GC. Therefore, it's not possible for code to modify them between when the initial snapshot is taken and when the pointer is marked, so no write barrier is needed. Many pointers in Gecko are traced via NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS and its related macros. These pointers are always traced in the first slice, and so they don't need a write barrier. Many other XPConnect pointers are also traced in this way. See XPCJSRuntime::TraceBlackJS and XPCJSRuntime::TraceGrayJS. If a pointer doesn't fit one of these categories, then it probably requires a write barrier. Before the pointer is modified (except initializing writes, which don't need a barrier), you should call IncrementalReferenceBarrier() or IncrementalValueBarrier(), passing it the value the pointer held b...
...eBlackJS and XPCJSRuntime::TraceGrayJS. If a pointer doesn't fit one of these categories, then it probably requires a write barrier. Before the pointer is modified (except initializing writes, which don't need a barrier), you should call IncrementalReferenceBarrier() or IncrementalValueBarrier(), passing it the value the pointer held before the write. There are several examples of this usage in XPConnect. The js::ObjectPtr class is intended to serve as a drop-in replacement for JSObject *. It has an assignment operator that automatically invokes a write barrier. So far, though, there hasn't been much use for this class--there aren't many places outside of SpiderMonkey where a write barrier is required. Read barriers "Weak pointers" are a major complication to the scheme described above. For th...
Components.Constructor
ent is the contract ID of the XPCOM component to create. The component is then returned immediately, with only the base interface nsISupports available on it; you must call nsISupports.QueryInterface() on it to call methods on the object. ...
...The arguments used with the initialization method are the arguments passed to the Components.Constructor()-c...
Using components
Commonly, we start our scripts like so: var Cc = Components.classes; var Ci = Components.interfaces; If we want to get a hold of a component, we then do something like: var rc = Cc["@mozilla.org/registry;1"]; var rs = rc.getService(Ci.nsIRegistry); See also: xpcshell -- how to get a command line interface to JavaScript More Info As was already stated, it is common to start addon scripts like: var Cc = Components.classes; var Ci = Components.interfaces; There is also another way to start, which is exactly equivalent to the above. var {Cc: classes, Ci: interfaces} = Components; There are many more than just classes and interfaces. ...
...bject nsXPCComponents_Classes] results=[object nsXPCComponents_Results] isSuccessCode=function isSuccessCode() { [native code] } Constructor=[object nsXPCComponents_Constructor] QueryInterface=function QueryInterface() { [native code] } interfacesByID=[object nsXPCComponents_InterfacesByID] classesByID=[object nsXPCComponents_ClassesByID] stack=JS frame :: Scratchpad/4 :: cDump :: line 8 manager=[xpconnect wrapped nsIComponentManager] ID=[object nsXPCComponents_ID] Exception=[object nsXPCComponents_Exception] reportError=function reportError() { [native code] } canCreateWrapper=function canCreateWrapper() { [native code] } canCallMethod=function canCallMethod() { [native code] } canGetProperty=function canGetProperty() { [native code] } canSetProperty=function canSetProperty() { [native code] } ...
HOWTO
Async network requests Problem You want to make network requests or do other asynchronous work in xpcshell. However, when you start your script, it exits immediately, before the network request returns. Solution 1. Put the following at the end of your script: // Do async processing // From <https://developer.mozilla.org/en/XPConnect/xpcshell/HOWTO> print("Doing async work"); gScriptDone = false; var gThreadManager = Cc["@mozilla.org/thread-manager;1"] .getService(Ci.nsIThreadManager); var mainThread = gThreadManager.currentThread; while (!gScriptDone) mainThread.processNextEvent(true); while (mainThread.hasPendingEvents()) mainThread.processNextEvent(true); 2. In all callbacks where your script is finished, i.e. both success and error callbacks, put: gScriptDone = true; If you for...
...] Solution 1 var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] .getService(Components.interfaces.mozIJSSubScriptLoader); loader.loadSubScript("chrome://myall/content/file.jsm"); See: http://mxr.mozilla.org/comm-central/...figUtils.js#54 Solution 2 Append the following at the top of your JS file which you want to run in xpcshell { // <https://developer.mozilla.org/en/XPConnect/xpcshell/HOWTO> // <https://bugzilla.mozilla.org/show_bug.cgi?id=546628> let Cc = Components.classes; let Ci = Components.interfaces; // Register resource://app/ URI let ios = Cc["@mozilla.org/network/io-service;1"] .getService(Ci.nsIIOService); let resHandler = ios.getProtocolHandler("resource") .QueryInterface(Ci.nsIResProtocolHandler); let mozDir = Cc["@mozilla.org/fil...
xpcshell
It is a console application that lets you run JavaScript code. Unlike the ordinary JS shell (js), xpcshell lets the scripts running in it access XPCOM functionality. Prerequisites You need your own build of Mozilla to use xpcshell. Running xpcshell ./run-mozilla.sh ./xpcshell xpcshell is almost always in the same directory as run-mozilla.sh. $ locate run-mozilla.sh /usr/lib/firefox-0.10.1/run-mozilla.sh /usr/lib/thunderbird-0.9/run-mozilla.sh /usr/local/mozilla/run-mozilla.sh /opt/mozilla/run-mozilla.sh /root/.Trash/mozilla/run-mozilla.sh Just pick one, cd over there, and run-mozilla.sh xpcshell, if it's present. ...
...tify this, run xpcshell with the -v 180 command-line option, which tells xpcshell to use JavaScript 1.8. Example You can input JavaScript, straight to Mozilla. js> 5+7 12 js> print("Hello, world!") Hello, world! js> See also HOWTO for common problems in writing xpcshell scripts, e.g., doing async network calls or using JS modules. Pretty much all Mozilla programs use XPCOM components via XPConnect. Read XPConnect:Using components to get started with that. See the XPCShell Reference for information on command line arguments and extension functions. Learn how to write xpcshell-based unit tests. Read XPCShell:Profiling for information on how to profile scripts. ...
nsIFile
specific path string or by using cross-platform locations retrieved from the directory service. All methods with string parameters have two forms. The preferred form operates on UTF-16 encoded characters strings. An alternate form operates on characters strings encoded in the "native" charset. A string containing characters encoded in the native charset cannot be safely passed to javascript via xpconnect. Therefore, the UTF-16 forms are scriptable, but the "native methods" are not. In addition, the native form cannot deal with files whose name contains characters outside the default system code page on Windows. Using the native form limits the ability of your code to deal with the full Unicode support on Windows 2000 or later where the OS itself does not have such a limitation. Therefore, you mus...
...ironment variables (with the precedence the same as the order they're enumerated). On Win32 platforms, it is the currently selected ANSI codepage (specified by CP_ACP). The word "Native" appears in the name of methods that operate on or return strings encoded in the native character set. A string containing characters encoded in the native character set cannot be safely passed to JavaScript via XPConnect. Therefore, the "native" methods and attributes are not scriptable. XPCOM provides the string conversion functions NS_CStringToUTF16 and NS_UTF16ToCString, which can be used to convert a string between UTF-16 and the native character encoding. This interface was frozen for Gecko 1.0. See bug 129279 for details. From Gecko 2.0 interfaces are no longer frozen. See also nsILocalFile NS_CStrin...
nsIScriptError
66 Introduced Gecko 1.0 Inherits from: nsIConsoleMessage Last changed in Gecko 1.9 (Firefox 3) Implemented by: @mozilla.org/scripterror;1. To create an instance, use: var scriptError = Components.classes["@mozilla.org/scripterror;1"] .createInstance(Components.interfaces.nsIScriptError); Note: The nsIScriptError2 interface was merged into this interface in Gecko 12.0. Prior to that release, if you wanted to associate an outer window with a script error, you had to use nsIScriptError2 instead. ...
...ere in the code. This is an attempt to group them together for reference. Note that these are strings. If you want to log an error at chrome level you should set a Category from the first section (leaving it empty might log it as content error). As Addon author I would recommend using "chrome javascript" for logging exceptions caused by addon code. ...
nsISecurityCheckedComponent
caps/idl/nsISecurityCheckedComponent.idlScriptable Provides methods that let an XPCOM component define custom rules for accessing it from potentially unprivileged code. Inherits from: nsISupports Last changed in Gecko 1.7 Capability strings In Gecko, a "capability" is a string identifying a set of actions that code is allowed to perform. Two examples: Code that has the "UniversalXPConnect" capability is allowed to access all of XPCOM. This includes creating instances of arbitrary XPCOM objects and calling methods and setting properties on them. Code that has the "UniversalBrowserRead" capability is allowed to perform certain actions that allow it to read information from the local system. For example, this capability allows code to set the value of <input type="file"> and access...
...ges have no special capabilities. Extensions can define their own capabilities and use this interface to only allow access to code trusted with that capability. The two special return values of '"allAccess" or "noAccess" unconditionally allow or deny access to the operation. All code has the "allAccess" capability, and no code has the "noAccess" capability. This interface is used in Mozilla by XPConnect and a handful of things that need special handing (XUL controllers, the UI for the <video> tag, etc.). Method overview string canCallMethod(in nsIIDPtr iid, in wstring methodName); string canCreateWrapper(in nsIIDPtr iid); string canGetProperty(in nsIIDPtr iid, in wstring propertyName); string canSetProperty(in nsIIDPtr iid, in wstring propertyName); Methods canCallMethod() Returns a ...
nsIVariant
We mark the interface [scriptable] so that JS can use methods that refer to this interface. But we mark all the methods and attributes [noscript] since any nsIVariant object will be automatically converted to a JS type anyway. ...
...e pointer. (The reference count of the object is incremented.) Native code only!getAsISupports nsISupports getAsISupports(); Parameters None. Return value The interface pointer. (The reference count of the object is incremented.) Native code only!getAsJSVal jsval getAsJSVal(); Parameters None. Return value Returns the underlying JS value, if the variant was created by passing a JS object into XPConnect. Native code only!getAsString string getAsString(); Parameters None. Return value The value is converted to an 8-bit string in the ISO-8859-1 character set. If the value was UTF16 then the high bits are lost. If the value was UTF8 then it is converted to UTF16 and the high bits are discarded. Arrays and interface pointers cannot be converted to a string. Native code only!getAsStringWithSize void...
Xptcall Porting Guide
Porters of this functionality implement the platform specific code for the stub methods that fill the vtbl for ...
...c/md/test as a place to evolve the basic functionality as a port is coming together. Not all of the functionality is exercised, but it is a place to get started. xptcall/tests has an api level test for NS_InvokeByIndex, but no tests for the stubs functionality. Such a test ought to be written, but this has not yet been done. A full 'test' at this point requires building the client and running the XPConnect test called TestXPC in mozilla/js/src/xpconnect/tests. Getting these ports done is very important. Please let me know if you are interested in doing one. I'll answer any questions as I get them. Porting Status Original Author: John Bandhauer, 31 May 1999. ...
XPCOM
This can create a difficult situation for extension developers trying to support multiple Gecko versions (Firefox 2 and 3, for example).Creating a Python XPCOM componentCreating Applications with Mozilla already provides a tutorial for making a simple JavaScript or C++ component (implementing the nsISimple interface). Here is how to make the same component in Python using PyXPCOM.Fun With XBL and XPConnectGenerating GUIDsGUIDs are used in Mozilla programming for identifying several types of entities, including XPCOM Interfaces (this type of GUIDs is callled IID), components (CID), and legacy add-ons--like extensions and themes--that were created prior to Firefox 1.5. Add-ons can (and should) be identified with IDs of the form extensionname@organization.tld since Firefox 1.5.Generic factoryMost XPCO...
...When available, it lets you access the JavaScript object hidden by the wrapper.XPCOM ABIXPCOM ABI is the binary interface of XPCOM components. While XPCOM components written in a scripting language (such as JavaScript) can be moved across platforms (such as Windows and OS X) without adaptation, those written in a compiled language (such as C++) require recompilation when moving to a dif...
Chapter 5: Let's build a Firefox extension - Archive of obsolete content
path to the file. Chrome URLs are structured as: chrome://%package name%/%package type%/%relative path to source file% For example, the Chrome URL for the Firefox browser window is as follows: chrome://browser/content/browser.xul Here, the package name is "browser", the file "browser.xul", and the type of the package is "content". Source files represented through chrome URLs run with UniversalXPConnect privileges; even if they haven't been granted "use XPConnect as local file" privileges, as discussed in Chapter 4, they will be able to use XPCOM functions (Figure 1). Extension/ chrome manifest Chrome/ #registered in the chrome content package #Run with privileges locale package skin package Figure 1: Chrome packages and chrome registration (FIXME: Not really explicit and not a...
Exception logging in JavaScript - Archive of obsolete content
eporting in Firefox 3 Firefox 3 improves reporting of unhandled exceptions by establishing a set of rules that determines whether or not an exception is worth reporting: Any methods on interfaces annotated with the [function] attribute in IDL (see, for example, nsIDomEventListener) that throw exceptions always report those exceptions into the Error Console. Any exceptions that are generated by XPConnect -- that is, those exceptions whose result codes are defined in nsIXPConnect.idl -- are always logged into the Error Console. The NS_NOINTERFACE error is never reported when returned by a JavaScript object's QueryInterface() method on the nsISupports interface. The NS_NOINTERFACE error is never reported when returned by a JavaScript object's GetInterface() method on the nsIInterfaceRequestor int...
Mozilla Application Framework in Detail - Archive of obsolete content
passing memory management This component object model makes virtually all of the functionality of Gecko available as a series of components, or reusable cross-platform libraries, that can be accessed from the browser or scripted from any Mozilla application. Applications that want to access the various Mozilla XPCOM libraries (networking, security, DOM, etc.) use a special layer of XPCOM called XPConnect, which reflects the library interfaces into JavaScript (or other languages). XPConnect glues the front end to the C++-based components in XPCOM, and it can be extended to include scripting support for other languages: PyXPCOM already offers support for Python, Java is supported by JavaXPCOM, and there are efforts underway to add Perl and Ruby language support for XPConnect. On the developer side,...
RDF Datasource How-To - Archive of obsolete content
corresponds to the tree element, http://foo.bar.com/, the graph will be traversed and content will be constructed using the pattern specified within the template tags. For a complete description of how content is built from RDF, see the XUL:Template Guide. 1 As of this writing, it is not currently possible to implement JavaScript XPCOM components; however, it may soon be possible to do so via XPConnect. Update: JavaScript XPCOM should now be possible. Contact: Chris Waterson (waterson@netscape.com) Original Document Information Author(s): Chris Waterson Last Updated Date: June 19, 2000 Copyright Information: Copyright (C) Chris Waterson ...
Standalone XPCOM - Archive of obsolete content
e-standalone-modules=xpcom. What's the difference between Standalone and non-Standalone XPCOM? There is no binary difference between standalone XPCOM and the XPCOM that ships with the Mozilla browser. The one functional difference is that XPT files cannot be read from .zip files in standalone XPCOM. TODO for v 1.0 Optional exclusion of specific features into standalone XPCOM like registry, xpconnect. Tweeking these options will cause reduction in memory requirements and size. Get xpcom/tests directory upto date and documented. Update this document for Mac. API freeze and documentation Original Document Information Author: Suresh Duddi Last Updated Date: 15 May 2000 Copyright Information: Portions of this content are (C) 1998-2007 by individual mozilla.org contributors; content ava...
XPCOM Interfaces - Archive of obsolete content
things that JavaScript cannot do itself. However, there is a way in which you can call them, which we will see shortly. We can call any of the functions provided by the component as described by the interfaces it implements. For example, once we have a component, we can check if it implements nsISound, and, if so, we can play sound through it. The process of calling XPCOM from a script is called XPConnect, which is a layer which translates script objects into native objects. Creating XPCOM Objects There are three steps to calling an XPCOM component. Get a component Get the part of the component that implements the interface that we want to use. Call the function we need Once you've done the first two steps, you can repeat the last step as often as necessary. Let's say we want to rename a ...
2006-12-01 - Archive of obsolete content
Summary: mozilla.dev.security - November 25, 2006 to December 1, 2006 Return to mozilla-dev-security Announcements None during this week. Discussions Protocol Security Daniele Rizzo posted a question as to whether or not it is possible to enable/disable the privilege of UniversalXpConnect in a 'entire' protocol (http://, file://). Problem with downloading signed script components in a Firefox extension Andrew Groom is having problems getting an extension to download a signed script and would appreciates some help with his problem. Meetings None during this week. ...
JS-Engine FAQ - Archive of obsolete content
An alternative would be to use built-in E4X. ...
Obsolete: XPCOM-based scripting for NPAPI plugins - Archive of obsolete content
Netscape 6 and 6.01 Introduction Plugins that used to take advantage of being scriptable via LiveConnect in 4.x Netscape browsers lost this possibility in the new world. The main reason for this is that there is no guarantee of Java compatibility on a binary level due to the jri/jni switch. The new Mozilla XPCOM architecture allows XPCOM components be scriptable via a different mechanism called XPConnect. We leverage some of these ideas to help you make your Netscape Communicator 4.x plugins exposed to JavaScript in Mozilla based browsers. In order to make it still possible to script plugins, some changes have been made to the Mozilla code. The changes allow to make existing 4.x plugins scriptable with only minor modifications in their code. The present document describes the steps of what should...
Archive of obsolete content
Plugins that used to take advantage of being scriptable via LiveConnect in 4.x Netscape browsers lost this possibility in the new world. The main reason for this is that there is no guarantee of Java compatibility on a binary level due to the jri/jni switch. The new Mozilla XPCOM architecture allows XPCOM components be scriptable via a different mechanism called XPConnect. We leverage some of these ideas to help you make your Netscape Communicator 4.x plugins exposed to JavaScript in Mozilla based browsers. Plugins For more information about plugin roadmap, see non-archived plugin information. RSS Really Simple Syndication (RSS) is a popular HTML-like XML-based data format used for syndication. RSS has a sordid hi...
Plug-in Development Overview - Gecko Plugin API Reference
See the Wikipedia article for historical information. Both technologies are now obsolete for the purposes of plug-in scriptability, and the cross-browser npruntime API should be used instead. See the Scripting plugins section of this reference for the details. Building Plug-ins Once you have added the special code and additional files to make your plug-in...
XInclude - MDN Web Docs Glossary: Definitions of Web-related terms
} } else if (href.match(/#$/, '') || href.match(/^#/, '')) { alert('Fragment identifiers are disallowed in an XInclude "href" attribute'); return false; } var j; var xincludeParent = xinclude.parentNode; try { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserRead'); // Necessary with file:///-located files trying to reach external sites if (href !== null) { var response, responseType; var request = new XMLHttpRequest(); request.open('GET', href, false); request.setRequestHeader('If-Modified-Since', 'Thu, 1 Jan 1970 00:00:00 GMT'); ...
About Scriptable Interfaces - Interfaces
outside world while hiding the inner details of the component implementation. Interfaces are written in an Interface Description Language. When we label an interface as scriptable, we're saying that components exporting this interface can be referenced (through this interface) from scripts (e.g JavaScript), and that we can write new components implementing the interface using script languages. XPConnect XPConnect is a technology that allows scriptable interfaces to be used/implemented from/in JavaScript scripts. No other scripts languages are supported by XPConnect. Python There's an extension extensions/python that bridges the gap between XPCOM and Python, allowing scriptable interfaces to be used/implemented from/in Python scripts. ...
Creating JavaScript callbacks in components
tation: function doLoad(event) { // do something here } window.addEventListener("load", doLoad, false); Revealing the magic How is this possible? Is nsIDOMEventListener magical? Well, it actually is a little magical. But you can use the same magic in your own IDL callbacks. The nsIDOMEventListener interface is "marked" with the function attribute. See it here. The function attribute tells the XPConnect machinery to treat the JavaScript function as if it was an implementation of the callback interface. Note, that since the JavaScript function is a single method, this magic only works for callback interfaces with a single method, like nsIDOMEventListener. The JavaScript function is passed the same arguments as defined by the callback method. So we could convert the example above to accept JavaScr...
Debugging on Windows
variable MOZ_NO_REMOTE: set MOZ_NO_REMOTE=1 Or, starting with Firefox 2 and other Gecko 1.8.1-based applications, you can use the -no-remote command-line switch instead (implemented in bug 325509). You can also specify the profile to use with the -P profile_name command-line argument. Debugging JavaScript Use Venkman, the JavaScript Debugger for Mozilla. You can use helper functions from nsXPConnect.cpp to inspect and modify the state of JavaScript code from the MSVS debugger. For example, to print curent JavaScript stack to stdout, evaluate this in QuickWatch window: {,,xul}DumpJSStack() Note: Visual C++ will show you something in the quick watch window, but not the stack, you have to look in the OS console for the output. Also this magical command only works when the VC++ stack is in...
Error codes returned by Mozilla APIs
NS_ERROR_DOM_FILE_NOT_FOUND_ERR (0x80650000) File was not found. NS_ERROR_DOM_FILE_NOT_READABLE_ERR (...
PRUint64
This has been fixed. ...
SpiderMonkey compartments
t garbage collection we shortcut having to walk unrelated heap areas of a window or tab that triggered a garbage collection. See also JS_NewCompartmentAndGlobalObject() JS_EnterCrossCompartmentCall() JS_LeaveCrossCompartmentCall() JSAutoCompartment Invariants SpiderMonkey Internals: Thread Safety Andreas Gal blog post Bobby Holley blog post Sfink/Contexts_and_Compartments XPConnect security membranes ...
Invariants
be in the same compartment. So it is utterly crucially important that this invariant always be true if objects are being created. The public API for compartment-hopping, JSAutoEnterCompartment, and the internal API, js::AutoCompartment, both make sure the invariant is maintained. However, there is another internal API, js::SwitchToCompartment, that lets you break this invariant, and of course in XPConnect we use that from time to time when we know we aren't going to be creating any new objects (other than global objects, which have no parent or prototype) or doing anything that might call back into native code that could create objects. We do this in order to save some CPU cycles (in other words, for no good reason whatsoever). If !JS_IsRunning(cx) && cx->globalObject == NULL, then cx->compartmen...
JSClass.flags
is set, each instance of the class has a field for private data. The field can be accessed using JS_GetPrivate and JS_SetPrivate. MXR ID Search for JSCLASS_HAS_PRIVATE JSCLASS_PRIVATE_IS_NSISUPPORTS Mozilla extension. The private field of each object of this class points to an XPCOM object (see nsISupports). This is only meaningful if SpiderMonkey is built with XPConnect and the JSCLASS_HAS_PRIVATE flag is also set. MXR ID Search for JSCLASS_PRIVATE_IS_NSISUPPORTS JSCLASS_IS_DOMJSCLASS Added in SpiderMonkey 17 Objects are DOM. MXR ID Search for JSCLASS_IS_DOMJSCLASS JSCLASS_EMULATES_UNDEFINED Added in SpiderMonkey 24 Causes objects which have this class to emulate undefined in certain circumstances. An...
JS_SetOptions
ent things. The former creates a property on the global object. The latter creates a property on obj. With this flag, both create a global property. MXR ID Search for JSOPTION_VAROBJFIX JSOPTION_PRIVATE_IS_NSISUPPORTS Mozilla extension. The context's private data points to an XPCOM object (see nsISupports). This is only meaningful if SpiderMonkey is built with XPConnect. MXR ID Search for JSOPTION_PRIVATE_IS_NSISUPPORTS JSOPTION_COMPILE_N_GO Caller of JS_CompileScript et al promises to execute the compiled script once only, in the same scope object used for compilation. The caller may not modify objects on the scope chain between compilation and execution. This enables compile-time scope chain resolution of consts (a performan...
How to build an XPCOM component in JavaScript
onent slightly. The imported library contains functions for generating the module, factory, and the NSGetModule and QueryInterface functions for you. Note: it doesn't do the work of creating your interface definition file or the type library for you, so you still have to go through those steps above if they haven't been done. The library provides a simple example of its use in the source code (js/xpconnect/loader/XPCOMUtils.jsm), but here's another using this example. To begin, include a line at the top of your interface to import the XPCOMUtils library: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); then implement your interface the same way you did above, except with a few modifications so that XPCOMUtils can set it up properly: /********************************************...
An Overview of XPCOM
is a binary representation of an interface or interfaces. It provides programmatic control and access of the interface, which is crucial for interfaces used in the non C++ world. When components are accessed from other languages, as they can be in XPCOM, they use the binary type library to access the interface, learn what methods it supports, and call those methods. This aspect of XPCOM is called XPConnect. XPConnect is the layer of XPCOM that provides access to XPCOM components from languages such as JavaScript. See Connecting to Components from the Interface for more information about XPConnect. When a component is accessible from a language other than C++, such as JavaScript, its interface is said to be "reflected" into that language. Every reflected interface must have a corresponding type lib...
Component Internals
rted symbol from the components shared library. "Native" here includes any language that can generate a platform native dynamically loaded library. Scripting languages and other "non-native" languages usually have no way to build native libraries. In order to have "non-native" XPCOM components work, XPCOM must have a special component loader which knows how to deal with these type of components. XPConnect, for example, provides a component loader that makes the various types, including the interfaces and their parameters, available to JavaScript. Each language supported by XPCOM must have a component loader. Three parts of a XPCOM Component Library XPCOM is like an onionor a parfait! Everybody likes parfaits. XPCOM components have at least three layers. From the innermost and moving outward thes...
Finishing the Component
al = PR_TRUE; return NS_OK; } node = node->next; } return NS_OK; } At this point, all of the backend work is complete. You can of course improve this backend in many ways, but this example presents the basic creation of what is commonly referred to as a "browser helper object" like WebLock. The next chapter looks at how to tie this into the front end - specifically, how to use XPConnect to access and control this component from JavaScript in the user interface. << PreviousNext >> Copyright (c) 2003 by Doug Turner and Ian Oeschger. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.02 or later. Distribution of substantively modified versions of this document is prohibited without the explicit permission...
Resources
This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.02 or later. Distr...
Creating XPCOM components
Factories XPIDL and Type Libraries XPCOM Services XPCOM Types Method Types Reference Counting Status Codes Variable Mappings Common XPCOM Error Codes Using XPCOM Components Component Examples Cookie Manager The WebBrowserFind Component The WebLock Component Component Use in Mozilla Finding Mozilla Components Using XPCOM Components in Your Cpp XPConnect: Using XPCOM Components From Script Component Internals Creating Components in Cpp XPCOM Initialization XPCOM Registry Manifests Registration Methods in XPCOM Autoregistration The Shutdown Process Three Parts of a XPCOM Component Library XPCOM Glue The Glue Library XPCOM String Classes Creating the Component Code What We'll Be Working On Component Regist...
How To Pass an XPCOM Object to a New Window
...
Components.classes
To access a service (a singleton component, only single instance of which exists at any time), you should use getService instead of createInstance: var os = Components.classes["@mozilla.org/observer-service;1"] .getS...
Components.interfaces
ties are interfaces indexed by their names. Introduction Components.interfaces is a read-only object whose properties implement the nsIJSIID interface. Each object represents one of the XPCOM interfaces -- that some component or another might or might not implement. It reflects only those interfaces which have been designated in their .idl description as scriptable, that is the interfaces which XPConnect is capable of reflecting into JavaScript. Properties of the Components.interfaces object are used where XPCOM methods expect a parameter of type nsID. This includes nsISupports.QueryInterface(), the optional parameter accepted by nsIJSCID.getService(), nsIJSCID.createInstance() when called from JavaScript, and nsIClassInfo.getInterfaces(). The properties of the Components.interfaces object can ...
Components.interfacesByID
read-only array of classes indexed by IID. Introduction Components.interfacesByID is a read-only array of objects which implement the nsIJSIID interface. Each object represents one of the XPCOM interfaces -- that some component or another might or might not implement. It reflects only those interfaces which have been designated in their .idl description as [scriptable], i.e. the interfaces which XPConnect is capable of reflecting into JavaScript. Components.interfacesByID is exactly like Components.interfaces except that the elements are indexed by the canonical form of their IID. Usage You can retrieve an interface object using: var iface = Components.interfacesByID["{aa610f20-a889-11d3-8c81-000064657374}"]; ...
Components.results
Introduction Components.results is an object whose properties are the names of well-known XPCOM result codes, with each value being that of the corresponding result code. Elements in this array can be used to test against unknown nsresult variables or they can be 'thrown' to indicate failure... ...
Components.returnCode
can hold an XPCOM return code additionally to the value returned by the return statement. Note that Components.returnCode is currently non-functional due to bug 287107. This problem was introduced in Mozilla 1.4. Usage Components.returnCode is a property that can be used to indicate to an XPCOM caller of the JavaScript method that the method is returning a specific nsresult code. Generally, XPConnect does a fine job of making it unnecessary for JavaScript code to worry about nsresult codes. By default the successful completion of the JavaScript method will cause XPConnect to return a result code of NS_OK to the caller. If the JavaScript code needs to signal failure then that is done by throwing an exception. However, there are a very few XPCOM interfaces that specify success code return value...
Components.utils.forceGC
utely necessary. Note: nsIDOMWindowUtils.garbageCollect() offers similar functionality but will trigger the cycle collector in addition to the garbage collector in the JavaScript engine. This will make sure that XPCOM components that build cycles with JavaScript objects also get collected which might be important, for example for testcases that depend on the garbage collector. Requires UniversalXPConnect privileges. If you want to schedule garbage collection to occur in the future, at a time when no JavaScript code is running, you can use Components.utils.schedulePreciseGC() instead. ...
Components.utils.import
faces.mozIJSSubScriptLoader); loader.loadSubScript(someURL, obj1); loader.loadSubScript(someURL, obj2); assert(obj2 === obj1); ...returns false. This means Components.utils.import is better suited for efficient sharing of code (and data?) between JS scripts running in different scope. Additional Resources Components.utils bug 238324 The documentation in xpccomponents.idl The tests in js/xpconnect/tests/unit/ Importing SDK/CommonJS modules into other code ...
Components.utils
Its interface is defined at js/xpconnect/idl/xpccomponents.idl. The object currently has the following members: EDITORS! please keep this list in sync with the Components object page Methods Method Description cloneInto() Create a structured clone of an object in a different JavaScript context. createArrayIn() Removed in Gecko 31 Returns an array created in specified compartment. createObjectIn() Creates a new object, created in the scope of the specified object's compartment. dispatch() Dispatches a runnable to the current/main thread. ...
Components.utils.unload
le called MyModule.jsm using the following line of code: Components.utils.unload("resource://myaddon/modules/MyModule.jsm"); Note: Currently Components.utils.unload clears the global object of an unloaded module. This may cause modules to misbehave after unloading even if you have a reference to them. See bug 769253 See also bug 481603 The documentation in xpccomponents.idl The tests in js/xpconnect/tests/unit/ ...
Other Resources
Other Resources Embedding Mozilla XPConnect - Javascript-XPCOM bridge BlackConnect - Java-XPCOM bridge (no longer supported) XPIDL to Java types - from Blackconnect ...
JavaXPCOM
JavaXPCOM allows for communication between Java and XPCOM, such that a Java application can access XPCOM objects, and XPCOM can access any Java class that implements an XPCOM interface. JavaXPCOM is not actively maintained. With JavaXPCOM, a developer can talk to XPCOM or embed Gecko from a Java application. JavaXPCOM is very similar to XPConnect (JavaScript-XPCOM bridge), and uses XPIDL. Note: JavaXPCOM was included in XULRunner up through version 1.9.2. It has been removed in XULRunner 2, and is not actively maintained. Documentation JavaXPCOM Development How to get and build the source, as well as how to view and report bugs. Sample code There are several Java test applications checked in to the tree that give examples ...
PyXPCOM
yXPCOM allows for communication between Python and XPCOM, such that a Python application can access XPCOM objects, and XPCOM can access any Python class that implements an XPCOM interface. PyXPCOM is actively used in ActiveState Komodo products, for example. With PyXPCOM, a developer can talk to XPCOM or embed Gecko from a Python application. PyXPCOM is similar to JavaXPCOM (Java-XPCOM bridge) or XPConnect (JavaScript-XPCOM bridge). Mozilla defines many external interfaces available to embeddors and component developers. PyXPCOM provides access to these interfaces as Python interfaces. PyXPCOM also contains several classes that provide access to functions for initializing and shutting down XPCOM and Gecko from Python, as well as some XPCOM helper functions. Documentation ...
Architecture basics
XPCOM is like COM, for Windows. It lets you get pointers to components inside Mozilla, and it lets you talk about their interfaces as well. XPConnect is what lets JavaScript talk with Mozilla guts, the XPCOM system. You can imagine it like a bridge between JavaScript code, and Mozilla guts. xpcshell is a command line interface to Mozilla JavaScript. It's an interactive interpreter -- it gives you a shell that talks straight to Mozilla, via JavaScript's XPConnect bridge into it. ...
nsIRegistry
...
XPCShell Reference
print(obj1, obj2, ...) print() is useful to print something to the screen. It dumps whatever is passed to the screen, putting spaces between arguments and appending a newline at the end. An example print(1, 2, 3) Will print 1 2 3<newline>. dump(object) dump() is almost like print. It only handles one parameter and it doesn't append a newline. dumpXPC(depth) This function dumps the XPConnect object. See the documentation on debugDump() for the nsIXPConnect interface for more information. version(newVersion) version() returns the JavaScript engine version number. If you pass a number to it, it will set the version number (and return the old version number). See the above documentation on the -v command-line argument for more information. quit(exitCode) quit() exits the shell...
IDispatch
js/src/xpconnect/idl/XPCIDispatch.idlScriptable This interface is not to be used directly, it is to be used internally for XPConnect's IDispatch support. Inherits from: nsISupports Last changed in Gecko 1.7 ...
mozIJSSubScriptLoader
66 Introduced Gecko 1.0 Inherits from: nsISupports Last changed in Gecko 28 (Firefox 28 / Thunderbird 28 / SeaMonkey 2.25 / Firefox OS 1.3) Implemented by: @mozilla.org/moz/jssubscript-loader;1. To get this service, use: var mozIJSSubScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] .getService(Components.interfaces.mozIJSSubScriptLoader); Note: See Components.utils.import for another way to import JavaScript code. ...
nsIClassInfo
ssInfo implementation. Obsolete since Gecko 2.0 Methods getHelperForLanguage() Get a language mapping specific helper object that may assist in using objects of this class in a specific lanaguage. For example, if asked for the helper for nsIProgrammingLanguage::JAVASCRIPT this might return an object that can be nsISupports.QueryInterface()'d into the nsIXPCScriptable interface to assist XPConnect in supplying JavaScript specific behavior to callers of the instance object. nsISupports getHelperForLanguage( in PRUint32 language ); Parameters language This parameter selects the language mapping specific helper object to be returned. nsIProgrammingLanguage defines language identifiers that may be passed for this parameter. Return value Should return null if no helper available for...
nsIDOMParser
n these matter, feel free to ask questions in mozilla.dev.tech.dom and update this documentation to mention these cases. When a DOMParser is instantiated by calling new DOMParser(), it inherits the calling code's principal (except that for chrome callers the principal is set to the null principal) and the documentURI and baseURI of the window the constructor came from. If the caller has UniversalXPConnect privileges, it can pass parameters to new DOMParser(). If fewer than three parameters are passed, the remaining parameters will default to null. The first parameter is the principal to use; this overrides the default principal normally inherited. The second parameter is the documentURI to use. The third parameter is the baseURI to use. If you instantiate a DOMParser by calling createInstance()...
nsIDispatchSupport
Inherits from: nsISupports Last changed in Gecko 1.7 Method overview void COMVariant2JSVal(in COMVARIANTPtr comvar, out jsval val); unsigned long getHostingFlags(in string aContext); boolean isClassMarkedSafeForScripting(in nsCIDRef cid, out boolean classExists); boolean isClassSafeToHost(in JSContextPtr cx, in nsCIDRef cid, in boolean capsCheck, out boolean classExists); boolean isObjectSafeForScripting(in voidPtr theObject, in nsIIDRef id); void JSVal2COMVariant(in jsval var, out COMVARIANT comvar); Methods COMVariant2JSVal() Converts a COM Variant to a jsval. ...
nsIEventListenerService
Introduced Gecko 1.9.2 Inherits from: nsISupports Last changed in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4) Implemented by: @mozilla.org/eventlistenerservice;1. To create an instance, use: var eventListenerService = Components.classes["@mozilla.org/eventlistenerservice;1"] .getService(Components.interfaces.nsIEventListenerService); UniversalXPConnect privileges are required to use this service. Method overview void getEventTargetChainFor(in nsIDOMEventTarget aEventTarget, [optional] out unsigned long aCount, [retval, array, size_is(aCount)] out nsIDOMEventTarget aOutArray); void getListenerInfoFor(in nsIDOMEventTarget aEventTarget, [optional] out unsigned long aCount, [retval, array, size_is(aCount)] out nsIEven...
nsIJSCID
Inherits from: nsIJSID Last changed in Gecko 1.7 Method overview nsISupports createInstance(); nsISupports getService(); Methods createInstance() nsISupports createInstance(); Parameters None. Return value getService() nsISupports getService(); Parameters None. Return value See also See Components.classes for usage patterns of the createInstance() and getService() methods. ...
nsIJSID
Inherits from: nsISupports Last changed in Gecko 1.9 (Firefox 3) The following methods return objects that implement this interface: Components.interfaces.name Components.classes[contract] Components.interfacesById[uuid] Components.classesById[cid] The first two cases create a named JSID while the last two cases create an unnamed JSID. An unnamed JSID also results when you implement a function that is passed an nsIIDRef parameter, such as QueryInterface(). Note that for these cases of JSID the specified class or interface must exist and be scriptable. ...
nsIMimeConverter
eConverterOutputCallback output_fn, in void *closure); void EncoderDestroy(in MimeEncoderData *data, in boolean abort_p); long EncoderWrite(in MimeEncoderData *data, in string buffer, in long size); Methods encodeMimePartIIStr() An variant of encodeMimePartIIStr_UTF8() which treats the header as written in the given charset. This should only be used by native code, as xpconnect translation causes it to not work properly. string encodeMimePartIIStr(in string header, in boolean structured, in string mailCharset, in long fieldnamelen, in long encodedWordSize); Parameters propertyName The name of the property to retrieve. Return Value The value of th...
nsIMsgWindow
not the existing message pane and header should be cleared before the HTML is displayed. StopUrls() This is equivalent to calling Stop(nsIWebNavigation::STOP_NETWORK) on the nsIWebNavigation object. void StopUrls(); closeWindow() When the msg window is being unloaded from the content window, this notification can be used to force a flush on anything the message window hangs on. For some reason XPConnect is still hanging onto the message window even though all of our objects have let go of it. This forces a release. It clears out the content listener, the windowCommands, the statusFeedback and the docShell objects. void closeWindow(); Remarks See also ...
nsIScriptError2
1.0 66 Introduced Gecko 2.0 Obsolete Gecko 12.0 Inherits from: nsIScriptError Last changed in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6) In Gecko 12.0 this Interface was merged into the nsIScriptError interface. ...
nsIWinTaskbar
reateTaskbarTabPreview( in nsIDocShell shell, in nsITaskbarPreviewController controller ); Parameters shell An nsIDocShell object representing the top-level window from which to create the preview. controller An nsITaskbarPreviewController you implement. Return value An nsITaskbarTabPreview object for the new tab preview. ...
nsIXPCException
js/src/xpconnect/idl/xpcexception.idlScriptable These exception objects are the preferred types of exceptions when implementing xpcom interfaces in JavaScript. Inherits from: nsIException Last changed in Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0) Method overview void initialize(in string aMessage, in nsresult aResult, in string aName, in nsIStackFrame aLocation, in nsISupports aData, in nsIException aInner); xpcexJSVal stealJSVal(); Native code only! void stowJSVal(in xpcexJSContextPtr cx, in xpcexJSVal val); Native code only! Methods initialize() void initialize( in string aMessage, in nsresult aResult, in string aName, in nsIStackFrame aLocation, in nsISupports aData, in nsIException aInner ); Parameters aMessage aResult aName aLocation a...
nsIXmlRpcClient
ictionary can only hold any of the supported input types. Return value will be converted as follows: i4 or int: nsISupportsPRInt32 boolean: nsISupportsPRBool string: nsISupportsCString double: nsISupportsDouble dateTime.iso8601: nsISupportsPRTime base64: nsISupportsCString array: nsISupportsArray struct: nsIDictionary Faults (server side errors) are indicated by returning NS_ERROR_FAILURE. Via nsIXPConnect::GetPendingException()->data a nsIXmlRpcFault object can be retreieved with more information on the fault. Parameters listener A nsIXmlRpcClientListener that will get notified of XML-RPC events ctxt A context to be passed on to the listener methodName Remote method to call arguments Array of arguments to pass to the remote method count void asyncCall ( in nsIXmlRpcClientListener lis...
nsIXmlRpcFault
Obsolete since Gecko 1.9 (Firefox 3)This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. extensions/xml-rpc/idl/nsIXmlRpcClient.idlScriptable An XML-RPC exception. XML-RPC server fault codes are returned wrapped in this; access it using nsIXPConnect.GetPendingException->data. Inherits from: nsISupports Last changed in Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0) Method overview void init(in PRInt32 faultCode, in string faultSring); string toString(); Attributes Attribute Type Description faultCode PRInt32 Read only. faultString string Read only. Methods init() void getData( in PRInt32 faultCo...
XPCOM Interface Reference
indowCreatornsIWindowMediatornsIWindowWatchernsIWindowsRegKeynsIWindowsShellServicensIWorkernsIWorkerFactorynsIWorkerGlobalScopensIWorkerMessageEventnsIWorkerMessagePortnsIWorkerScopensIWritablePropertyBagnsIWritablePropertyBag2nsIXFormsModelElementnsIXFormsNSInstanceElementnsIXFormsNSModelElementnsIXMLHttpRequestnsIXMLHttpRequestEventTargetnsIXMLHttpRequestUploadnsIXPCExceptionnsIXPCScriptablensIXPConnectnsIXSLTExceptionnsIXSLTProcessornsIXSLTProcessorObsoletensIXULAppInfonsIXULBrowserWindownsIXULBuilderListenernsIXULRuntimensIXULSortServicensIXULTemplateBuildernsIXULTemplateQueryProcessornsIXULTemplateResultnsIXULWindownsIXmlRpcClientnsIXmlRpcFaultnsIZipEntrynsIZipReadernsIZipReaderCachensIZipWriternsMsgFilterFileAttribValuensMsgFolderFlagTypensMsgJunkStatusnsMsgKeynsMsgLabelValuensMsgPriorityVal...
nsIAbCard/Thunderbird3
constraints for certain properties. However, such constraints might not be checked by this method. These functions convert values in the same manner as the default implementation of nsIVariant. A value MUST be convertible to a string; if this convention is not followed, consumers of cards may fail unpredictably or return incorrect results. The non-variant functions are marked [noscript] since XPConnect uses magic with nsIVariant such that the other functions are not needed, although C++ does need them. void setProperty(in AUTF8String name, in nsIVariant value); [noscript] void setPropertyAsAString(in string name, in AString value); [noscript] void setPropertyAsAUTF8String(in string name, in AUTF8String value); [noscript] void setPropertyAsUint32(in string name, in PRUint32 value); [noscri...
Weak reference
erence; and nsIWeakReference::QueryReferent gives you the same functionality as QueryInterface for getting back. Additionally, nsCOMPtr now supports the new key do_QueryReferent to simplify life even further. How do I make a class support weak references? In JavaScript, just make sure that your QueryInterface method returns your object for the nsISupportsWeakReference interface, and you're set; XPConnect does all the work for you. Just roll in nsSupportsWeakReference, a mix-in class that does all the work, and adjust your QueryInterface accordingly, e.g., //... #include "nsWeakReference.h" class nsFoo : public nsIFoo, ..., public nsSupportsWeakReference { ... }; // ...if you used the table macros to implement |QueryInterface|, add an entry NS_INTERFACE_MAP_BEGIN(nsFoo) // ... NS_INTERFA...
Working with out parameters
lavor, out nsISupports aData, out unsigned long aDataLen ) ; ... } The getTransferData method takes three parameters, aFlavor, aData, and aDataLen, and returns nothing. aData and aDataLen are marked as out, meaning that they act as "return values" for this method, and are changed during the method call. These are so-called out parameters. Usage In order to use such a method from JavaScript via XPConnect, you have to follow a specific rule. To get at the out parameters, you have to pass in an object. After the call, this object will have a new property called value, which contains the out values. Assuming you have an object called transferable, you would invoke getTransferData() as follows: var aData = {}; var aDataLen = {}; transferable.getTransferData("text/unicode", aData, aDataLen); var ...
XPIDL
if it chooses to replace it. Buffers must be deallocated with NS_Free, and interface pointers must be Release'd. Afterwards, the above rules for out apply. Shared out-parameters should not be freed, as they are intended to refer to constant string literals. Resources (mostly outdated) Some unsorted notes including a keyword list xpidl is a tool for generating C++ headers, Java interfaces, XPConnect typelibs, and HTML documentation from XPIDL files Generating xpt files on Windows A Google groups post with instructions on how to use variable-length argument lists using XPIDL. ...
Working with windows in chrome code
ram2: 42 }; args.wrappedJSObject = args; var watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] .getService(Components.interfaces.nsIWindowWatcher); watcher.openWindow(null, url, windowName, features, args); // In the window code var args = window.arguments[0].wrappedJSObject; This uses the wrappedJSObject trick. By passing args to openWindow xpconnect will automatically wrap it as a generic nsISupports. The opened window can then just get at the underlying JavaScript object using wrappedJSObject. Advanced data sharing The above code is useful when you need to pass data from one window to another or to a set of windows, but sometimes you just want to share a JavaScript variable in common between different windows. You could declare a local va...
Mozilla
irefox and other applications, Mozilla developers have created a number of useful JavaScript libraries you can use in your projects. Documentation for these libraries can be found here. JavaScript Tips JavaScript-DOM Prototypes in Mozilla When a DOM node is accessed from JavaScript in Mozilla, the native C++ DOM node is wrapped using XPConnect and the wrapper is exposed to JavaScript as the JavaScript representation of the DOM node. When XPConnect wraps a C++ object it will create a JSObject that is unique to this C++ object. In the case where the C++ object has class info (nsIClassInfo), the JSObject is a more or less empty JSObject which is not really that special. All the methods that are supposed to show up on...
Constants - Plugins
scription NPVERS_HAS_STREAMOUTPUT 8 Streaming data. NPVERS_HAS_NOTIFICATION 9 Notification of completion. NPVERS_HAS_LIVECONNECT 9 LiveConnect. NPVERS_WIN16_HAS_LIVECONNECT 9 LiveConnect (Win16). NPVERS_68K_HAS_LIVECONNECT 11 LiveConnect (68K). NPVERS_HAS_WINDOWLESS 11 Windowless plug-in. NPVERS_HAS_XPCONNECT_SCRIPTING 13 Plug-in is scriptable using XPConnect. NPVERS_HAS_NPRUNTIME_SCRIPTING 14 Plug-in is scriptable using NPRuntime. NPVERS_HAS_FORM_VALUES 15 NPPVformValue NPPVariables are supported. NPVERS_HAS_POPUPS_ENABLED_STATE 16 The NPN_PushPopupsEnabledState() and NPN_PopPopupsEnabledState() functions are supported. NPVERS_HAS_RESPONSE_H...
Plug-in Development Overview - Plugins
See the Wikipedia article for historical information. Both technologies are now obsolete for the purposes of plug-in scriptability, and the cross-browser npruntime API should be used instead. See the Scripting plugins section of this reference for the details. Building Plug-ins Once you have added the special code and additional files to make your plug-in...
Document.documentURIObject - Web APIs
For web content this property doesn't have any special meaning and can be used just like any other custom property. Privileged code must be careful not to try getting or setting this property on a non-wrapped content object (e.g., on a wrappedJSObject of an XPCNativeWrapper). See bug 324464's comments for details. ...
Document - Web APIs
Web › API › Document
ard extensions Firefox notes Mozilla defines a set of non-standard properties made only for XUL content: Document.currentScript Returns the <script> element that is currently executing. Document.documentURIObject (Mozilla add-ons only!) Returns the nsIURI object representing the URI of the document. This property only has special meaning in privileged JavaScript code (with UniversalXPConnect privileges). Document.popupNode Returns the node upon which a popup was invoked. Document.tooltipNode Returns the node which is the target of the current tooltip. Mozilla also define some non-standard methods: Document.execCommandShowHelp()Obsolete since Gecko 14 This method never did anything and always threw an exception, so it was removed in Gecko 14.0 (Firefox 14.0 / Thunderbird 14.
Node.baseURIObject - Web APIs
The Node.baseURIObject property returns the nsIURI representing the node's (typically a document or an element) base URL. It's similar to Node.baseURI, except it returns an nsIURI instead of a string. This property exists on all nodes (HTML, XUL, SVG, MathML, etc.), but only if the script trying to use it has UniversalXPConnect privileges. See Node.baseURI for details on what the base URL is. Syntax uriObj = node.baseURIObject Value An nsIURI. This property is read-only; attempting to write to it will throw an exception. In addition, this property may only be accessed from privileged code. Specification Not in any specification. ...
Window.controllers - Web APIs
ault, a window's controller contains the code that supports the global window commands. ...
JavaScript shells - JavaScript
, GTK2 for GUI apps, POSIX for system programming, etc. The best of CPAN now for JavaScript programmers. ShellJS - Portable Unix shell commands for Node.js List of JavaScript shells The following JavaScript shells work with Mozilla. Firefox has a built-in JavaScript console, which support multi-line editing. JavaScript Shell (js) - A command line interpreter for JavaScript xpcshell is an XPConnect - enabled shell, sometimes useful for Mozilla development. Babel REPL - A browser-based REPL for experimenting with future JavaScript. ES6Console.com - An open-source JavaScript console to test ECMAScript 2015 code inside the browser. jsconsole.com -- An open-source JavaScript console with the ability to easily link to particular expressions JavaScript Shell (web page) - also available as par...