safeMode.js
Go to the documentation of this file.
1 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 #
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
9 #
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
14 #
15 # The Original Code is mozilla.org code.
16 #
17 # The Initial Developer of the Original Code is
18 # Mike Connor.
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
21 #
22 # Contributor(s):
23 # Mike Connor <mconnor@steelgryphon.com>
24 # Asaf Romano <mozilla.mano@sent.com>
25 #
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
37 #
38 # ***** END LICENSE BLOCK *****
39 
40 function restartApp() {
41  var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
42  .getService(Components.interfaces.nsIAppStartup);
43  appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
44 }
45 
46 function clearAllPrefs() {
47  var prefService = Components.classes["@mozilla.org/preferences-service;1"]
48  .getService(Components.interfaces.nsIPrefService);
49  prefService.resetUserPrefs();
50 
51  // Remove the pref-overrides dir, if it exists
52  try {
53  var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
54  .getService(Components.interfaces.nsIProperties);
55  const NS_APP_PREFS_OVERRIDE_DIR = "PrefDOverride";
56  var prefOverridesDir = fileLocator.get(NS_APP_PREFS_OVERRIDE_DIR,
57  Components.interfaces.nsIFile);
58  prefOverridesDir.remove(true);
59  } catch (ex) {
60  Components.utils.reportError(ex);
61  }
62 }
63 
65  var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
66  .getService(Components.interfaces.nsIPrefBranch);
67  prefBranch.setBoolPref("browser.bookmarks.restore_default_bookmarks", true);
68 }
69 
70 function deleteLocalstore() {
71  const nsIDirectoryServiceContractID = "@mozilla.org/file/directory_service;1";
72  const nsIProperties = Components.interfaces.nsIProperties;
73  var directoryService = Components.classes[nsIDirectoryServiceContractID]
74  .getService(nsIProperties);
75  var localstoreFile = directoryService.get("LStoreS", Components.interfaces.nsIFile);
76  if (localstoreFile.exists())
77  localstoreFile.remove(false);
78 }
79 
80 function disableAddons() {
81  // Disable addons
82  const nsIUpdateItem = Components.interfaces.nsIUpdateItem;
83  var em = Components.classes["@mozilla.org/extensions/manager;1"]
84  .getService(Components.interfaces.nsIExtensionManager);
85  var type = nsIUpdateItem.TYPE_EXTENSION + nsIUpdateItem.TYPE_LOCALE;
86  var items = em.getItemList(type, { });
87  for (var i = 0; i < items.length; ++i)
88  em.disableItem(items[i].id);
89 
90  // Select the default theme
91  var prefB = Components.classes["@mozilla.org/preferences-service;1"]
92  .getService(Components.interfaces.nsIPrefBranch);
93  if (prefB.prefHasUserValue("general.skins.selectedSkin"))
94  prefB.clearUserPref("general.skins.selectedSkin");
95 
96  // Disable plugins
97  var phs = Components.classes["@mozilla.org/plugin/host;1"]
98  .getService(Components.interfaces.nsIPluginHost);
99  var plugins = phs.getPluginTags({ });
100  for (i = 0; i < plugins.length; ++i)
101  plugins[i].disabled = true;
102 }
103 
105  var searchService = Components.classes["@mozilla.org/browser/search-service;1"]
106  .getService(Components.interfaces.nsIBrowserSearchService);
107 
108  searchService.restoreDefaultEngines();
109 }
110 
111 function onOK() {
112  try {
113  if (document.getElementById("resetUserPrefs").checked)
114  clearAllPrefs();
115  if (document.getElementById("deleteBookmarks").checked)
117  if (document.getElementById("resetToolbars").checked)
119  if (document.getElementById("disableAddons").checked)
120  disableAddons();
121  if (document.getElementById("restoreSearch").checked)
123  } catch(e) {
124  }
125 
126  restartApp();
127 }
128 
129 function onCancel() {
130  var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
131  .getService(Components.interfaces.nsIAppStartup);
132  appStartup.quit(appStartup.eForceQuit);
133 }
134 
135 function onLoad() {
136  document.getElementById("tasks")
137  .addEventListener("CheckboxStateChange", UpdateOKButtonState, false);
138 }
139 
141  document.documentElement.getButton("accept").disabled =
142  !document.getElementById("resetUserPrefs").checked &&
143  !document.getElementById("deleteBookmarks").checked &&
144  !document.getElementById("resetToolbars").checked &&
145  !document.getElementById("disableAddons").checked &&
146  !document.getElementById("restoreSearch").checked;
147 }
function deleteLocalstore()
Definition: safeMode.js:70
function disableAddons()
Definition: safeMode.js:80
function restoreDefaultSearchEngines()
Definition: safeMode.js:104
function restartApp()
Definition: safeMode.js:40
function clearAllPrefs()
Definition: safeMode.js:46
function UpdateOKButtonState()
Definition: safeMode.js:140
function onCancel()
Definition: safeMode.js:129
function onOK()
Definition: safeMode.js:111
function restoreDefaultBookmarks()
Definition: safeMode.js:64
_getSelectedPageStyle s i
function onLoad()
Definition: safeMode.js:135