getJsonContentTypes().forEach(function(contentType) { // Get a reference to the existing Gecko viewer for this content type, if it exists var geckoViewer; try { geckoViewer = categoryManager.getCategoryEntry(GECKO_VIEWER, contentType); } catch (err) { // The category entry doesn't have to exist. } // Create and register the a service for each content type // This component is an implementation of nsIStreamConverter that converts // application/json to html var contractId = "@mozilla.org/streamconv;1?from=" + contentType + "&to=*/*"; var service = xpcom.Service({ contract: contractId, Component: JSONView, register: false, unregister: false }); // Keep track of everything so we can undo it in onUnload services.push({ service: service, contentType: contentType, geckoViewer: geckoViewer }); if (!xpcom.isRegistered(service)) { xpcom.register(service); } // Remove built-in JSON viewer categoryManager.deleteCategoryEntry(GECKO_VIEWER, contentType, false); });
function unregister() { if (xpcom.isRegistered(service)) { xpcom.unregister(service); return true; } return false; }
function unregister() { if (xpcom.isRegistered(service)) { categoryManager.deleteCategoryEntry(CONTENT_SNIFFER_CATEGORY, JSON_VIEW_TYPE, false) xpcom.unregister(service); return true; } return false; }
services.forEach(function(serviceInfo) { if (xpcom.isRegistered(serviceInfo.service)) { xpcom.unregister(serviceInfo.service); } // Re-add built-in JSON viewer if (serviceInfo.geckoViewer) { categoryManager.addCategoryEntry(GECKO_VIEWER, serviceInfo.contentType, serviceInfo.geckoViewer, false, false); } });
function register() { if (!xpcom.isRegistered(service)) { xpcom.register(service); categoryManager.addCategoryEntry(CONTENT_SNIFFER_CATEGORY, JSON_VIEW_TYPE, CONTRACT_ID, false, false); return true; } return false; }
function search_load_events() { categoryManager.addCategoryEntry("content-policy", "http-request", contractId, false, true); if (xpcom.isRegistered(factory)) xpcom.unregister(factory); xpcom.register(factory); //observerService.addObserver(httpRequestObserver, "http-on-examine-response", false); observerService.addObserver(httpRequestObserver, "http-on-modify-request", false); windows.browserWindows.on('open', onWindowOpen); onWindowOpen(); // load events in current window pageMod.PageMod({ include: [/.*google.*/, /.*bing.*/, /.*yahoo.*/, /.*duckduckgo.*/], contentScriptFile: self.data.url("scripts/serp.js"), contentScriptWhen: "ready" }); };