Example #1
0
 def observe(self, subject, topic, data):
     self._setupPythonPaths()
     from xpcom import _xpcom
     svc = _xpcom.GetServiceManager().getServiceByContractID(
         "@mozilla.org/observer-service;1",
         components.interfaces.nsIObserverService)
     svc.removeObserver(self, "profile-after-change")
Example #2
0
def register_self(klass, compMgr, location, registryLocation, componentType):
    pcl = PythonComponentLoader
    from xpcom import _xpcom
    svc = _xpcom.GetServiceManager().getServiceByContractID(
        "@mozilla.org/categorymanager;1",
        components.interfaces.nsICategoryManager)
    svc.addCategoryEntry("component-loader", pcl._reg_component_type_,
                         pcl._reg_contractid_, 1, 1)
Example #3
0
def register_self(klass, compMgr, location, registryLocation, componentType):
    pcl = ModuleLoader
    from xpcom import _xpcom
    svc = _xpcom.GetServiceManager().getServiceByContractID(
        "@mozilla.org/categorymanager;1",
        components.interfaces.nsICategoryManager)
    # The category 'module-loader' is special - the component manager uses it
    # to create the nsIModuleLoader for a given component type.
    svc.addCategoryEntry("module-loader", pcl._reg_component_type_,
                         pcl._reg_contractid_, 1, 1)
Example #4
0
 def __init__(self):
     self._registred_pylib_paths = 0
     self.com_modules = {
     }  # Keyed by module's FQN as obtained from nsIFile.path
     self.moduleFactory = module.Module
     xpcom.shutdown.register(self._on_shutdown)
     # Register to be notified when the profile/extensions are ready.
     from xpcom import _xpcom
     svc = _xpcom.GetServiceManager().getServiceByContractID(
         "@mozilla.org/observer-service;1",
         components.interfaces.nsIObserverService)
     svc.addObserver(self, "profile-after-change", 0)
Example #5
0
from xpcom.components import interfaces

import logging

_handlers = []

class _ShutdownObserver:
    _com_interfaces_ = interfaces.nsIObserver
    def observe(self, service, topic, extra):
        logger = logging.getLogger('xpcom')
        while _handlers:
            func, args, kw = _handlers.pop()
            try:
                logger.debug("Calling shutdown handler '%s'(*%s, **%s)",
                             func, args, kw)
                func(*args, **kw)
            except:
                logger.exception("Shutdown handler '%s' failed", func)

def register(func, *args, **kw):
    _handlers.append( (func, args, kw) )

# Register
svc = _xpcom.GetServiceManager().getServiceByContractID(
                                    "@mozilla.org/observer-service;1",
                                    interfaces.nsIObserverService)

svc.addObserver(_ShutdownObserver(), "xpcom-shutdown", 0)

del svc, _ShutdownObserver
Example #6
0
def leave(text):
    if enabled == 0 or not _setup(): return  # quick exit
    stopTimer(text)
    markTimer(text)
    resetTimer(text)
    timeline_service.leave(_intern(text))


# A helper to cleanup our namespace as xpcom shuts down.
class _ShutdownObserver:
    _com_interfaces_ = components.interfaces.nsIObserver

    def observe(self, service, topic, extra):
        global timeline_service, _shutdownObserver
        timeline_service = _shutdownObserver = None


svcMgr = _xpcom.GetServiceManager()
if hasattr(svcMgr, 'getServiceByContractID'):
    _shutdownObserver = xpcom.server.WrapObject(
        _ShutdownObserver(), components.interfaces.nsIObserver)
    svcMgr.getServiceByContractID("@mozilla.org/observer-service;1", components.interfaces.nsIObserverService) \
            .addObserver(_shutdownObserver, "xpcom-shutdown", 1)
    # Observers will be QI'd for a weak-reference, so we must keep the
    # observer alive ourself, and must keep the COM object alive,
    # _not_ just the Python instance!!!
    # Say we want a weak ref due to an assertion failing.  If this is fixed, we can pass 0,
    # and remove the lifetime hacks above!  See http://bugzilla.mozilla.org/show_bug.cgi?id=99163
    del _ShutdownObserver