Changes

Jump to: navigation, search

PWCore

2,319 bytes added, 18:21, 24 April 2008
PW Core
PW Core is part of Mozilla 1.9 and will be released along with Firefox 3. If you are interested in seeing the code please visit [https://bugzilla.mozilla.org/show_bug.cgi?id=412770 this bug].
 
==Runtime Data==
 
The runtime information that PW Core reports is always in fractions of a second. For example a reported runtime of 0.500 would mean 500 milliseconds. Because PW Core 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 a call 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 taken up by the plugin.
==Usage==
As discussed above, to specify what you want done when a notification arrives your class must have an 'observe' method, receiving 3 parameters (subject, topic and data) that gets called with each notification. The topic contains PW's notification topic - 'experimental-notify-plugin-call', the data is the runtime in milliseconds and the subject is always 'null' and should not be used.
Here is an example that shows the runtime in an alert box to the userif the runtime exceeds half a second in length:
observe: function(subject, topic, data) {
if (topic == "experimental-notify-plugin-call" ) {
if (data > 0.500) { alert("Runtime is:" + data); }
}
}
- NOTE: This is just a simplified example and should never be used the use of alert() is discouraged as PW sends can send hundreds of notifications each second and will could potentially cause your browser to crash with the if an excessive number of alert boxesare displayed.
In Also note that in the example above an if statement first checks to see that the arriving notification's topic is the correct one. This is useful in cases where your class is registered to receive notifications for more than one topic with the Observer service.
===Clean Up===
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, "experimental-notify-plugin-call");
 
 
===Skeleton PW Observer Class===
 
Below is a skeleton class that you may use to listen to PW runtime notifications:
 
function PluginWatcherObserver()
{
this.register(); //takes care of registering this class with observer services as an observer for plugin runtime notifications
this.registered = false;
}
 
PluginWatcherObserver.prototype = {
observe: function(subject, topic, data) {
 
if (topic == "experimental-notify-plugin-call") //In case your class is registered to listen to other topics
//This gets executed each time a PW runtime notification arrives
// --YOUR CODE GOES HERE--
}
 
 
},
//Takes care of registering the observer services for the "experimental-notify-plugin-call" topic
register: function() {
if (this.registered == false) { //This check prevents double registration -- something you want to avoid!!
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "experimental-notify-plugin-call", false);
this.registered = true;
}
},
//Unregisters from the observer services
unregister: function() {
if (this.registered == true) {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, "experimental-notify-plugin-call");
this.registered = false;
}
}
}
1
edit

Navigation menu