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 | // -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | // This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | // License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 5 | |
michael@0 | 6 | this.EXPORTED_SYMBOLS = ["RemoteWebNavigation"]; |
michael@0 | 7 | |
michael@0 | 8 | const Ci = Components.interfaces; |
michael@0 | 9 | const Cc = Components.classes; |
michael@0 | 10 | const Cu = Components.utils; |
michael@0 | 11 | |
michael@0 | 12 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | function makeURI(url) |
michael@0 | 15 | { |
michael@0 | 16 | return Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 17 | getService(Ci.nsIIOService). |
michael@0 | 18 | newURI(url, null, null); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function RemoteWebNavigation(browser) |
michael@0 | 22 | { |
michael@0 | 23 | this._browser = browser; |
michael@0 | 24 | this._browser.messageManager.addMessageListener("WebNavigation:setHistory", this); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | RemoteWebNavigation.prototype = { |
michael@0 | 28 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebNavigation, Ci.nsISupports]), |
michael@0 | 29 | |
michael@0 | 30 | LOAD_FLAGS_MASK: 65535, |
michael@0 | 31 | LOAD_FLAGS_NONE: 0, |
michael@0 | 32 | LOAD_FLAGS_IS_REFRESH: 16, |
michael@0 | 33 | LOAD_FLAGS_IS_LINK: 32, |
michael@0 | 34 | LOAD_FLAGS_BYPASS_HISTORY: 64, |
michael@0 | 35 | LOAD_FLAGS_REPLACE_HISTORY: 128, |
michael@0 | 36 | LOAD_FLAGS_BYPASS_CACHE: 256, |
michael@0 | 37 | LOAD_FLAGS_BYPASS_PROXY: 512, |
michael@0 | 38 | LOAD_FLAGS_CHARSET_CHANGE: 1024, |
michael@0 | 39 | LOAD_FLAGS_STOP_CONTENT: 2048, |
michael@0 | 40 | LOAD_FLAGS_FROM_EXTERNAL: 4096, |
michael@0 | 41 | LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP: 8192, |
michael@0 | 42 | LOAD_FLAGS_FIRST_LOAD: 16384, |
michael@0 | 43 | LOAD_FLAGS_ALLOW_POPUPS: 32768, |
michael@0 | 44 | LOAD_FLAGS_BYPASS_CLASSIFIER: 65536, |
michael@0 | 45 | LOAD_FLAGS_FORCE_ALLOW_COOKIES: 131072, |
michael@0 | 46 | |
michael@0 | 47 | STOP_NETWORK: 1, |
michael@0 | 48 | STOP_CONTENT: 2, |
michael@0 | 49 | STOP_ALL: 3, |
michael@0 | 50 | |
michael@0 | 51 | canGoBack: false, |
michael@0 | 52 | canGoForward: false, |
michael@0 | 53 | goBack: function() { |
michael@0 | 54 | this._sendMessage("WebNavigation:GoBack", {}); |
michael@0 | 55 | }, |
michael@0 | 56 | goForward: function() { |
michael@0 | 57 | this._sendMessage("WebNavigation:GoForward", {}); |
michael@0 | 58 | }, |
michael@0 | 59 | gotoIndex: function(aIndex) { |
michael@0 | 60 | this._sendMessage("WebNavigation:GotoIndex", {index: aIndex}); |
michael@0 | 61 | }, |
michael@0 | 62 | loadURI: function(aURI, aLoadFlags, aReferrer, aPostData, aHeaders) { |
michael@0 | 63 | this._browser._contentTitle = ""; |
michael@0 | 64 | this._sendMessage("WebNavigation:LoadURI", {uri: aURI, flags: aLoadFlags}); |
michael@0 | 65 | }, |
michael@0 | 66 | reload: function(aReloadFlags) { |
michael@0 | 67 | this._sendMessage("WebNavigation:Reload", {flags: aReloadFlags}); |
michael@0 | 68 | }, |
michael@0 | 69 | stop: function(aStopFlags) { |
michael@0 | 70 | this._sendMessage("WebNavigation:Stop", {flags: aStopFlags}); |
michael@0 | 71 | }, |
michael@0 | 72 | |
michael@0 | 73 | get document() { |
michael@0 | 74 | return this._browser.contentDocument; |
michael@0 | 75 | }, |
michael@0 | 76 | |
michael@0 | 77 | _currentURI: null, |
michael@0 | 78 | get currentURI() { |
michael@0 | 79 | if (!this._currentURI) { |
michael@0 | 80 | this._currentURI = makeURI("about:blank"); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | return this._currentURI; |
michael@0 | 84 | }, |
michael@0 | 85 | set currentURI(aURI) { |
michael@0 | 86 | this.loadURI(aURI.spec, null, null, null); |
michael@0 | 87 | }, |
michael@0 | 88 | |
michael@0 | 89 | referringURI: null, |
michael@0 | 90 | |
michael@0 | 91 | _sessionHistory: null, |
michael@0 | 92 | get sessionHistory() { return this._sessionHistory; }, |
michael@0 | 93 | set sessionHistory(aValue) { }, |
michael@0 | 94 | |
michael@0 | 95 | _sendMessage: function(aMessage, aData) { |
michael@0 | 96 | try { |
michael@0 | 97 | this._browser.messageManager.sendAsyncMessage(aMessage, aData); |
michael@0 | 98 | } |
michael@0 | 99 | catch (e) { |
michael@0 | 100 | Cu.reportError(e); |
michael@0 | 101 | } |
michael@0 | 102 | }, |
michael@0 | 103 | |
michael@0 | 104 | receiveMessage: function(aMessage) { |
michael@0 | 105 | switch (aMessage.name) { |
michael@0 | 106 | case "WebNavigation:setHistory": |
michael@0 | 107 | this._sessionHistory = aMessage.objects.history; |
michael@0 | 108 | break; |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | }; |