/prebuilt/extension/components/PluginInstall.js

1/*
2 * Copyright (c) 2009 Samuel Gross.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */ 22 23constCc=Components.classes; 24constCi=Components.interfaces; 25 26constPREF_DISABLED_PLUGIN_TYPES="plugin.disable_full_page_plugin_for_types"; 27constPDF_MIME_TYPE="application/pdf"; 28constPROFILE_AFTER_CHANGE="profile-after-change"; 29 30 31// This file is executed when the user first installs the PDF plugin extenion.
32//
33// We remove preferences for handling PDF files that would interfere with the
34// plugin. For example, the user may have set PDF files to save without asking.
35//
36// NOTE: This does not overwrite preferences set after the plugin is installed.
37// The user can still disable or uninstall the plugin through the add-ons
38// window, or change the file handling preferences through the "Applications"
39// preferences tab.
40 41 42functionNSGetModule(){ 43return{ 44log:function(s){ 45varlogger=Cc["@mozilla.org/consoleservice;1"]. 46getService(Ci.nsIConsoleService); 47 48logger.logStringMessage(''+s); 49}, 50 51registerSelf:function(compMgr,location,loaderStr,type){ 52this.log('NSGetModule'); 53 54this.observerSvc=Cc["@mozilla.org/observer-service;1"]. 55getService(Ci.nsIObserverService); 56 57// We need to wait until the profile is loaded in order to modify
58// user and mime-type preferences.
59this.observerSvc.addObserver(this,PROFILE_AFTER_CHANGE,false); 60}, 61 62observe:function(subject,topic,data){ 63this.observerSvc.removeObserver(this,PROFILE_AFTER_CHANGE); 64 65try{ 66this.enablePdfType(); 67}catch(e){ 68this.log("Error enabling PDF type: "+e); 69} 70 71try{ 72this.removePdfHandler(); 73}catch(e){ 74this.log("Error enabling PDF type: "+e); 75} 76}, 77 78/** Enables the PDF plugin. */ 79enablePdfType:function(){ 80varprefSvc=Cc["@mozilla.org/preferences-service;1"]. 81getService(Ci.nsIPrefBranch); 82 83if(prefSvc.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES)){ 84vartypes=prefSvc.getCharPref(PREF_DISABLED_PLUGIN_TYPES); 85 86if(types){ 87varfiltered=types.split(",").filter(function(v)v!=PDF_MIME_TYPE); 88 89prefSvc.setCharPref(PREF_DISABLED_PLUGIN_TYPES,filtered.join(",")); 90} 91} 92}, 93 94/** Removes any existing handler for the application/pdf mime-type. */ 95removePdfHandler:function(){ 96varhandlerSvc=Cc["@mozilla.org/uriloader/handler-service;1"]. 97getService(Ci.nsIHandlerService); 98 99varmimeSvc=Cc["@mozilla.org/mime;1"].100getService(Ci.nsIMIMEService);101102letmimeInfo=mimeSvc.getFromTypeAndExtension(PDF_MIME_TYPE,null);103104if(mimeInfo&&handlerSvc.exists(mimeInfo)){105handlerSvc.remove(mimeInfo);106}107}108}109}110