Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function MultiplexHandler(aEvent) |
michael@0 | 6 | { |
michael@0 | 7 | MultiplexHandlerEx( |
michael@0 | 8 | aEvent, |
michael@0 | 9 | function Browser_SelectDetector(event) { |
michael@0 | 10 | BrowserCharsetReload(); |
michael@0 | 11 | /* window.content.location.reload() will re-download everything */ |
michael@0 | 12 | SelectDetector(event, null); |
michael@0 | 13 | }, |
michael@0 | 14 | function Browser_SetForcedCharset(charset, isPredefined) { |
michael@0 | 15 | BrowserSetForcedCharacterSet(charset); |
michael@0 | 16 | } |
michael@0 | 17 | ); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function MailMultiplexHandler(aEvent) |
michael@0 | 21 | { |
michael@0 | 22 | MultiplexHandlerEx( |
michael@0 | 23 | aEvent, |
michael@0 | 24 | function Mail_SelectDetector(event) { |
michael@0 | 25 | SelectDetector( |
michael@0 | 26 | event, |
michael@0 | 27 | function Mail_Reload() { |
michael@0 | 28 | messenger.setDocumentCharset(msgWindow.mailCharacterSet); |
michael@0 | 29 | } |
michael@0 | 30 | ); |
michael@0 | 31 | }, |
michael@0 | 32 | function Mail_SetForcedCharset(charset, isPredefined) { |
michael@0 | 33 | MessengerSetForcedCharacterSet(charset); |
michael@0 | 34 | } |
michael@0 | 35 | ); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function ComposerMultiplexHandler(aEvent) |
michael@0 | 39 | { |
michael@0 | 40 | MultiplexHandlerEx( |
michael@0 | 41 | aEvent, |
michael@0 | 42 | function Composer_SelectDetector(event) { |
michael@0 | 43 | SelectDetector( |
michael@0 | 44 | event, |
michael@0 | 45 | function Composer_Reload() { |
michael@0 | 46 | EditorLoadUrl(GetDocumentUrl()); |
michael@0 | 47 | } |
michael@0 | 48 | ); |
michael@0 | 49 | }, |
michael@0 | 50 | function Composer_SetForcedCharset(charset, isPredefined) { |
michael@0 | 51 | if ((!isPredefined) && charset.length > 0) { |
michael@0 | 52 | gCharsetMenu.SetCurrentComposerCharset(charset); |
michael@0 | 53 | } |
michael@0 | 54 | EditorSetDocumentCharacterSet(charset); |
michael@0 | 55 | } |
michael@0 | 56 | ); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function MultiplexHandlerEx(aEvent, aSelectDetector, aSetForcedCharset) |
michael@0 | 60 | { |
michael@0 | 61 | try { |
michael@0 | 62 | var node = aEvent.target; |
michael@0 | 63 | var name = node.getAttribute('name'); |
michael@0 | 64 | |
michael@0 | 65 | if (name == 'detectorGroup') { |
michael@0 | 66 | aSelectDetector(aEvent); |
michael@0 | 67 | } else if (name == 'charsetGroup') { |
michael@0 | 68 | var charset = node.getAttribute('id'); |
michael@0 | 69 | charset = charset.substring('charset.'.length, charset.length) |
michael@0 | 70 | aSetForcedCharset(charset, true); |
michael@0 | 71 | } else if (name == 'charsetCustomize') { |
michael@0 | 72 | //do nothing - please remove this else statement, once the charset prefs moves to the pref window |
michael@0 | 73 | } else { |
michael@0 | 74 | aSetForcedCharset(node.getAttribute('id'), false); |
michael@0 | 75 | } |
michael@0 | 76 | } catch(ex) { |
michael@0 | 77 | alert(ex); |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function SelectDetector(event, doReload) |
michael@0 | 82 | { |
michael@0 | 83 | dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n"); |
michael@0 | 84 | |
michael@0 | 85 | var uri = event.target.getAttribute("id"); |
michael@0 | 86 | var prefvalue = uri.substring('chardet.'.length, uri.length); |
michael@0 | 87 | if ("off" == prefvalue) { // "off" is special value to turn off the detectors |
michael@0 | 88 | prefvalue = ""; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | try { |
michael@0 | 92 | var pref = Components.classes["@mozilla.org/preferences-service;1"] |
michael@0 | 93 | .getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 94 | var str = Components.classes["@mozilla.org/supports-string;1"] |
michael@0 | 95 | .createInstance(Components.interfaces.nsISupportsString); |
michael@0 | 96 | |
michael@0 | 97 | str.data = prefvalue; |
michael@0 | 98 | pref.setComplexValue("intl.charset.detector", |
michael@0 | 99 | Components.interfaces.nsISupportsString, str); |
michael@0 | 100 | if (typeof doReload == "function") doReload(); |
michael@0 | 101 | } |
michael@0 | 102 | catch (ex) { |
michael@0 | 103 | dump("Failed to set the intl.charset.detector preference.\n"); |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | var gPrevCharset = null; |
michael@0 | 108 | function UpdateCurrentCharset() |
michael@0 | 109 | { |
michael@0 | 110 | // extract the charset from DOM |
michael@0 | 111 | var wnd = document.commandDispatcher.focusedWindow; |
michael@0 | 112 | if ((window == wnd) || (wnd == null)) wnd = window.content; |
michael@0 | 113 | |
michael@0 | 114 | // Uncheck previous item |
michael@0 | 115 | if (gPrevCharset) { |
michael@0 | 116 | var pref_item = document.getElementById('charset.' + gPrevCharset); |
michael@0 | 117 | if (pref_item) |
michael@0 | 118 | pref_item.setAttribute('checked', 'false'); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | var menuitem = document.getElementById('charset.' + wnd.document.characterSet); |
michael@0 | 122 | if (menuitem) { |
michael@0 | 123 | menuitem.setAttribute('checked', 'true'); |
michael@0 | 124 | } |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | function UpdateCurrentMailCharset() |
michael@0 | 128 | { |
michael@0 | 129 | var charset = msgWindow.mailCharacterSet; |
michael@0 | 130 | var menuitem = document.getElementById('charset.' + charset); |
michael@0 | 131 | |
michael@0 | 132 | if (menuitem) { |
michael@0 | 133 | menuitem.setAttribute('checked', 'true'); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | function UpdateCharsetDetector() |
michael@0 | 138 | { |
michael@0 | 139 | var prefvalue; |
michael@0 | 140 | |
michael@0 | 141 | try { |
michael@0 | 142 | var pref = Components.classes["@mozilla.org/preferences-service;1"] |
michael@0 | 143 | .getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 144 | prefvalue = pref.getComplexValue("intl.charset.detector", |
michael@0 | 145 | Components.interfaces.nsIPrefLocalizedString).data; |
michael@0 | 146 | } |
michael@0 | 147 | catch (ex) { |
michael@0 | 148 | prefvalue = ""; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | if (prefvalue == "") prefvalue = "off"; |
michael@0 | 152 | dump("intl.charset.detector = "+ prefvalue + "\n"); |
michael@0 | 153 | |
michael@0 | 154 | prefvalue = 'chardet.' + prefvalue; |
michael@0 | 155 | var menuitem = document.getElementById(prefvalue); |
michael@0 | 156 | |
michael@0 | 157 | if (menuitem) { |
michael@0 | 158 | menuitem.setAttribute('checked', 'true'); |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | function UpdateMenus(event) |
michael@0 | 163 | { |
michael@0 | 164 | // use setTimeout workaround to delay checkmark the menu |
michael@0 | 165 | // when onmenucomplete is ready then use it instead of oncreate |
michael@0 | 166 | // see bug 78290 for the detail |
michael@0 | 167 | UpdateCurrentCharset(); |
michael@0 | 168 | setTimeout(UpdateCurrentCharset, 0); |
michael@0 | 169 | UpdateCharsetDetector(); |
michael@0 | 170 | setTimeout(UpdateCharsetDetector, 0); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | function CreateMenu(node) |
michael@0 | 174 | { |
michael@0 | 175 | var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); |
michael@0 | 176 | observerService.notifyObservers(null, "charsetmenu-selected", node); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | function UpdateMailMenus(event) |
michael@0 | 180 | { |
michael@0 | 181 | // use setTimeout workaround to delay checkmark the menu |
michael@0 | 182 | // when onmenucomplete is ready then use it instead of oncreate |
michael@0 | 183 | // see bug 78290 for the detail |
michael@0 | 184 | UpdateCurrentMailCharset(); |
michael@0 | 185 | setTimeout(UpdateCurrentMailCharset, 0); |
michael@0 | 186 | UpdateCharsetDetector(); |
michael@0 | 187 | setTimeout(UpdateCharsetDetector, 0); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | var gCharsetMenu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components.interfaces.nsICurrentCharsetListener); |
michael@0 | 191 | var gLastBrowserCharset = null; |
michael@0 | 192 | |
michael@0 | 193 | function charsetLoadListener (event) |
michael@0 | 194 | { |
michael@0 | 195 | var charset = window.content.document.characterSet; |
michael@0 | 196 | |
michael@0 | 197 | if (charset.length > 0 && (charset != gLastBrowserCharset)) { |
michael@0 | 198 | gCharsetMenu.SetCurrentCharset(charset); |
michael@0 | 199 | gPrevCharset = gLastBrowserCharset; |
michael@0 | 200 | gLastBrowserCharset = charset; |
michael@0 | 201 | } |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | |
michael@0 | 205 | function composercharsetLoadListener (event) |
michael@0 | 206 | { |
michael@0 | 207 | var charset = window.content.document.characterSet; |
michael@0 | 208 | |
michael@0 | 209 | |
michael@0 | 210 | if (charset.length > 0 ) { |
michael@0 | 211 | gCharsetMenu.SetCurrentComposerCharset(charset); |
michael@0 | 212 | } |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | function SetForcedEditorCharset(charset) |
michael@0 | 216 | { |
michael@0 | 217 | if (charset.length > 0 ) { |
michael@0 | 218 | gCharsetMenu.SetCurrentComposerCharset(charset); |
michael@0 | 219 | } |
michael@0 | 220 | EditorSetDocumentCharacterSet(charset); |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | |
michael@0 | 224 | var gLastMailCharset = null; |
michael@0 | 225 | |
michael@0 | 226 | function mailCharsetLoadListener (event) |
michael@0 | 227 | { |
michael@0 | 228 | if (msgWindow) { |
michael@0 | 229 | var charset = msgWindow.mailCharacterSet; |
michael@0 | 230 | if (charset.length > 0 && (charset != gLastMailCharset)) { |
michael@0 | 231 | gCharsetMenu.SetCurrentMailCharset(charset); |
michael@0 | 232 | gLastMailCharset = charset; |
michael@0 | 233 | } |
michael@0 | 234 | } |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | function InitCharsetMenu() |
michael@0 | 238 | { |
michael@0 | 239 | removeEventListener("load", InitCharsetMenu, true); |
michael@0 | 240 | |
michael@0 | 241 | var wintype = document.documentElement.getAttribute('windowtype'); |
michael@0 | 242 | if (window && (wintype == "navigator:browser")) |
michael@0 | 243 | { |
michael@0 | 244 | var contentArea = window.document.getElementById("appcontent"); |
michael@0 | 245 | if (contentArea) |
michael@0 | 246 | contentArea.addEventListener("pageshow", charsetLoadListener, true); |
michael@0 | 247 | } |
michael@0 | 248 | else |
michael@0 | 249 | { |
michael@0 | 250 | var arrayOfStrings = wintype.split(":"); |
michael@0 | 251 | if (window && arrayOfStrings[0] == "mail") |
michael@0 | 252 | { |
michael@0 | 253 | var messageContent = window.document.getElementById("messagepane"); |
michael@0 | 254 | if (messageContent) |
michael@0 | 255 | messageContent.addEventListener("pageshow", mailCharsetLoadListener, true); |
michael@0 | 256 | } |
michael@0 | 257 | else |
michael@0 | 258 | if (window && arrayOfStrings[0] == "composer") |
michael@0 | 259 | { |
michael@0 | 260 | contentArea = window.document.getElementById("appcontent"); |
michael@0 | 261 | if (contentArea) |
michael@0 | 262 | contentArea.addEventListener("pageshow", composercharsetLoadListener, true); |
michael@0 | 263 | } |
michael@0 | 264 | } |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | addEventListener("load", InitCharsetMenu, true); |