michael@0: // -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: // This Source Code Form is subject to the terms of the Mozilla Public michael@0: // License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: // file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: this.EXPORTED_SYMBOLS = ["RemoteWebNavigation"]; michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: function makeURI(url) michael@0: { michael@0: return Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService). michael@0: newURI(url, null, null); michael@0: } michael@0: michael@0: function RemoteWebNavigation(browser) michael@0: { michael@0: this._browser = browser; michael@0: this._browser.messageManager.addMessageListener("WebNavigation:setHistory", this); michael@0: } michael@0: michael@0: RemoteWebNavigation.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebNavigation, Ci.nsISupports]), michael@0: michael@0: LOAD_FLAGS_MASK: 65535, michael@0: LOAD_FLAGS_NONE: 0, michael@0: LOAD_FLAGS_IS_REFRESH: 16, michael@0: LOAD_FLAGS_IS_LINK: 32, michael@0: LOAD_FLAGS_BYPASS_HISTORY: 64, michael@0: LOAD_FLAGS_REPLACE_HISTORY: 128, michael@0: LOAD_FLAGS_BYPASS_CACHE: 256, michael@0: LOAD_FLAGS_BYPASS_PROXY: 512, michael@0: LOAD_FLAGS_CHARSET_CHANGE: 1024, michael@0: LOAD_FLAGS_STOP_CONTENT: 2048, michael@0: LOAD_FLAGS_FROM_EXTERNAL: 4096, michael@0: LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP: 8192, michael@0: LOAD_FLAGS_FIRST_LOAD: 16384, michael@0: LOAD_FLAGS_ALLOW_POPUPS: 32768, michael@0: LOAD_FLAGS_BYPASS_CLASSIFIER: 65536, michael@0: LOAD_FLAGS_FORCE_ALLOW_COOKIES: 131072, michael@0: michael@0: STOP_NETWORK: 1, michael@0: STOP_CONTENT: 2, michael@0: STOP_ALL: 3, michael@0: michael@0: canGoBack: false, michael@0: canGoForward: false, michael@0: goBack: function() { michael@0: this._sendMessage("WebNavigation:GoBack", {}); michael@0: }, michael@0: goForward: function() { michael@0: this._sendMessage("WebNavigation:GoForward", {}); michael@0: }, michael@0: gotoIndex: function(aIndex) { michael@0: this._sendMessage("WebNavigation:GotoIndex", {index: aIndex}); michael@0: }, michael@0: loadURI: function(aURI, aLoadFlags, aReferrer, aPostData, aHeaders) { michael@0: this._browser._contentTitle = ""; michael@0: this._sendMessage("WebNavigation:LoadURI", {uri: aURI, flags: aLoadFlags}); michael@0: }, michael@0: reload: function(aReloadFlags) { michael@0: this._sendMessage("WebNavigation:Reload", {flags: aReloadFlags}); michael@0: }, michael@0: stop: function(aStopFlags) { michael@0: this._sendMessage("WebNavigation:Stop", {flags: aStopFlags}); michael@0: }, michael@0: michael@0: get document() { michael@0: return this._browser.contentDocument; michael@0: }, michael@0: michael@0: _currentURI: null, michael@0: get currentURI() { michael@0: if (!this._currentURI) { michael@0: this._currentURI = makeURI("about:blank"); michael@0: } michael@0: michael@0: return this._currentURI; michael@0: }, michael@0: set currentURI(aURI) { michael@0: this.loadURI(aURI.spec, null, null, null); michael@0: }, michael@0: michael@0: referringURI: null, michael@0: michael@0: _sessionHistory: null, michael@0: get sessionHistory() { return this._sessionHistory; }, michael@0: set sessionHistory(aValue) { }, michael@0: michael@0: _sendMessage: function(aMessage, aData) { michael@0: try { michael@0: this._browser.messageManager.sendAsyncMessage(aMessage, aData); michael@0: } michael@0: catch (e) { michael@0: Cu.reportError(e); michael@0: } michael@0: }, michael@0: michael@0: receiveMessage: function(aMessage) { michael@0: switch (aMessage.name) { michael@0: case "WebNavigation:setHistory": michael@0: this._sessionHistory = aMessage.objects.history; michael@0: break; michael@0: } michael@0: } michael@0: };