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