background preloader

Observers

Facebook Twitter

Plugins - MDC. Plugins are shared libraries that users can install to display content that the application itself can't display natively. For example, the Adobe Reader plugin lets the user open PDF files directly inside the browser, and the QuickTime and RealPlayer plugins are used to play special format videos in a web page. Plugins are now a legacy technology. They are not available on most mobile devices. Mozilla encourages website developers to avoid using plugins wherever possible. If there are plugin features which are not available in the web platform, we encourage developers to post their use cases to mozilla.dev.platform project list, so that Mozilla can prioritize web platform work to make those use cases possible. Plugins are written using NPAPI, the cross-browser API for plugins. Plugins can be written completely from scratch using C APIs (usually in C or C++) or they may be built on a plugin framework such as Firebreath, JUCE, or QtBrowserPlugin.

Writing a plugin for Mac OS X. NsIObserverService - MDC. This interface provides methods to add, remove, notify, and enumerate observers of various notifications. The XPCOM nsObserverService implements this interface to provide global notifications for a variety of subsystems. Implemented by @mozilla.org/observer-service;1 as a service: var observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); Method overview Methods addObserver() Registers a given listener for a notifications regarding the specified topic. Void addObserver( in nsIObserver anObserver, in string aTopic, in boolean ownsWeak ); Parameters anObserver The nsIObserver object which will receive notifications. aTopic The notification topic or subject. ownsWeak If set to false, the nsIObserverService will hold a strong reference to anObserver.

EnumerateObservers() Called to enumerate all observers registered for a particular topic. nsISimpleEnumerator enumerateObservers( in string aTopic ); Return value notifyObservers() aSubject. Monitoring plugins - MDC. Summary A new component of the plugin system is now available to measure how long it takes plugins (e.g., Adobe Flash) to execute their calls. This component then reports the plugin runtime using the observer service to anyone registered to receive the notifications. This article discusses how developers can make use of this new feature. Runtime Data The runtime information reported is always in fractions of a second. Because the component measures the wall clock time it takes for blocking plugin calls to execute, the value includes both CPU time, the wait time between allocation of CPU time to the process as well as any disk I/O time. It is therefore technically incorrect to say that the runtime is a measure of CPU use, however, it is a good representation of overall resources being consumed by the plugin.

Usage To make use of the new component you must register to receive its runtime notifications using the observer service. Registration Observing Clean Up Skeleton Observer Class. NsIObserver - MDC. This interface is implemented by an object that wishes to observe notifications. These notifications are often, though not always, broadcast via the nsIObserverService. Method overview Methods observe() This method will be called when there is a notification for the topic that the observer has been registered for.

If you expect multiple topics/subjects, the implementor is responsible for filtering. You should not modify, add, remove, or enumerate notifications in the implementation of this method. void observe( in nsISupports aSubject, in string aTopic, in wstring aData ); Parameters aSubject In general reflects the object whose change or action is being observed. aTopic Indicates the specific change or action. aData An optional parameter or other auxiliary data further describing the change or action. Remarks The specific values and meanings of the parameters provided varies widely, though, according to where the observer was registered, and what topic is being observed.

Example observer.unregister(); Observer Notifications - MDC. Sometimes you need your code to send a message to other parts of your code. For example, you might want to notify that a task is completed, and then several different actions must be performed. You could do that by calling all those functions directly, but XPCOM offers you a better and cleaner way to achieve that using observers and the observer service. An observer is an object that is responsible to observe (wait for) notifications and then to carry out subsequent actions.

To create an observer, you need to implement the nsIObserver interface. The interface has only one method observe() which takes three parameters. The first parameter (subject) can be any XPCOM object, the second parameter is a notification topic, and the final parameter is a string that further describes the notification. This example code shows you what an implementation of the nsIObserver interface looks like: To remove an observer for a specific topic, you use the removeObserver method. Useful Firefox notifications. Getting Source Tab When Listening to http-on-modify-request • mo. . I dont want to bash the firefox developers and i think firefox is actually pretty good and potentially ver powerfull for writing extensions, but the documentation is a big obstacle (for me atleast). There isn't hardly any real detailed documentation, its always scraps and peaces and some examples.

If it doesn't work, you NEED the forums. Although this is my first real powerful extension i am making, its also my last because development is slow and cumbersome if you want something which hasn't been done in an example before. On topic: I know how to use the functions, but are they permanent? I REALLY like it i can make seperate sandboxed http-connections for every tab, but i dont want to trade stability for functionallity . NsIHttpChannel - MDC. This interface allows for the modification of HTTP request parameters and the inspection of the resulting HTTP response status and headers when they become available. Inherits from: nsIChannelLast changed in Gecko 1.3 To create an HTTP channel, use nsIIOService with a HTTP URI, for example: var ios = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var ch = ios.newChannel(" null, null); Method overview Attributes Methods Get the value of a particular request header.

ACString getRequestHeader( in ACString aHeader ); Parameters aHeader The case-insensitive name of the request header to query (For example "Cache-Control"). Return value The value of the request header. Exceptions thrown If the header is not set. Get the value of a particular response header. ACString getResponseHeader( in ACString header ); header The case-insensitive name of the response header to query (For example "Set-Cookie"). isNoCacheResponse() None. aNewURI. NsIObserverService - MDC. This interface provides methods to add, remove, notify, and enumerate observers of various notifications. The XPCOM nsObserverService implements this interface to provide global notifications for a variety of subsystems. Implemented by @mozilla.org/observer-service;1 as a service: var observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); Method overview Methods addObserver() Registers a given listener for a notifications regarding the specified topic.

Void addObserver( in nsIObserver anObserver, in string aTopic, in boolean ownsWeak ); Parameters anObserver The nsIObserver object which will receive notifications. aTopic The notification topic or subject. ownsWeak If set to false, the nsIObserverService will hold a strong reference to anObserver. EnumerateObservers() Called to enumerate all observers registered for a particular topic. nsISimpleEnumerator enumerateObservers( in string aTopic ); Return value notifyObservers() aSubject. NsIHttpHeaderVisitor - MDC. This interface is used to view HTTP request and response headers. Method overview Methods Called by the nsIHttpChannel implementation when visiting request and response headers. This method can throw an exception to terminate enumeration of the channel's headers. void visitHeader( in ACString aHeader, in ACString aValue ); Parameters aHeader A string containing the key for a header such as "Content-Type" aValue The header's value field such as "text/html".

Example This example shows how to detect Flash content. MyNsIHttpHeaderVisitor = function ( ) { this. See also nsIHttpChannel Document Tags and Contributors. Creating Sandboxed HTTP Connections - MDC. Introduction Starting with Gecko 1.8.1 (Firefox 2), it is possible to create sandboxed HTTP connections which don't affect the user's cookies. This article will cover the basics of doing HTTP connections from XPCOM JavaScript, and should easily translate to C++ XPCOM. Setting up an HTTP connection The first step in setting up an HTTP connection from an URL (stored in a string) is to create an nsIURI out of it. nsIURI is an XPCOM representation of an URI, with useful methods to query and manipulate the URI. To create an nsIURI from an string, we use the newURI method of nsIIOService: var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService);var uri = ioService.newURI(myURLString, null, null); Once the nsIURI has been created, a nsIChannel can be generated from it using nsIIOService's newChannelFromURI method: var channel = ioService.newChannelFromURI(uri); To initiate the connection, the asyncOpen method is called.

Handling cookies. Observer Notifications - MDC. Listening to events on all tabs - MDC. Firefox 3.5 adds support for listening to progress events on all tabs. Adding a listener To listen to progress events on all tabs, call the browser's addTabsProgressListener() method: gBrowser.addTabsProgressListener(myProgressListener); myProgressListener is an object that implements the callbacks used to provide notifications of progress events.

Removing a listener To remove a previously installed progress listener, call removeTabsProgressListener(): gBrowser.removeTabsProgressListener(myProgressListener); Implementing a listener The listener object itself has five methods it can implement to handle various events: onLocationChange Called when the URI of the document displayed in the tab changes. void onLocationChange( nsIDOMXULElement aBrowser, nsIWebProgress aWebProgress, nsIRequest aRequest, nsIURI aLocation [optional] in unsigned long aFlags ); Parameters aBrowser The browser representing the tab whose location changed. aWebProgress The progress instance responsible for handling the events. aFlags. XUL Questions and Answers - MDC.

Return to mozilla-dev-tech-xul summaries The frequently asked questions should be moved to XUL FAQ (make sure they have a clear answer.) Daniel Glazman has been working on this for his projects. He said the code will be open-source, but it is not released yet (as of Oct 2006). Some teasers are on his blog . Overlaying elements without IDs The original developers only tend to put IDs where they need them. As an extension author, you have at least two options: use DOM methods to dynamically create or rearrange elements file an enhancement request in Bugzilla to have extra IDs added. hidechrome="true" doesn’t work on a Mac? Unfortunately, no simple solution to this was posted. Is it possible to have checkbox support for multi column lists? The current issue is a person exploring if it is possible to have checkbox support for multi column lists.

<window id="test-window" title="Check List Test" xmlns:html=" " <listcell type="checkbox" value="3" label="hukfzgjcfj" } else { Intercepting Page Loads - MDC. There are several ways to detect and intercept loading of web pages and their content, be it only to realize when it happens, modify their contents, or to block them and do something else instead. Some of the techniques presented here apply only to content loaded in the main browser area, while others detect content being loaded in other XUL windows, or even detect XUL content being loaded.

Also, the different techniques tap into different steps of the load process. Which one you should use solely depends on your needs. We will start with the simplest one, which is also the most common to use. Note: Performance is very important when it comes to add-ons and page loads. Read the recommendations in Appendix A regarding performance if you're planning on implementing any of these. The Easy Way: Load Events This comes from the tabbrowser code snippets page. This. gBrowser is a global object that corresponds to the tabbrowser element in the main browser window. HTTP Observers Notes on usage: Adding preferences to an extension - MDC. This article takes the Creating a dynamic status bar extension sample to the next level, adding a popup menu that lets you quickly switch between multiple stocks to watch.

It also adds a preference dialog that lets you switch to a stock other than one of the ones included in the popup menu. As before, concepts covered in the previous articles in this series won't be rehashed here, so if you haven't already seen them: Also, for reference, you may want to take a look at Preferences System and the Preferences API.

Download the sample You can download a copy of this sample to look over, or to use as the basis for your own extension. Update the manifests The install manifest and chrome manifest need to be updated. <em:optionsURL> This line establishes the URL of the XUL file that describes the options dialog. Establish the defaults pref("extensions.stockwatcher2.symbol", "GOOG"); The JavaScript code startup() shutdown() observe() watchStock()