toolkit/modules/RemoteWebNavigation.jsm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/modules/RemoteWebNavigation.jsm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +// -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 +// This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +// License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +// file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +this.EXPORTED_SYMBOLS = ["RemoteWebNavigation"];
    1.10 +
    1.11 +const Ci = Components.interfaces;
    1.12 +const Cc = Components.classes;
    1.13 +const Cu = Components.utils;
    1.14 +
    1.15 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.16 +
    1.17 +function makeURI(url)
    1.18 +{
    1.19 +  return Cc["@mozilla.org/network/io-service;1"].
    1.20 +         getService(Ci.nsIIOService).
    1.21 +         newURI(url, null, null);
    1.22 +}
    1.23 +
    1.24 +function RemoteWebNavigation(browser)
    1.25 +{
    1.26 +  this._browser = browser;
    1.27 +  this._browser.messageManager.addMessageListener("WebNavigation:setHistory", this);
    1.28 +}
    1.29 +
    1.30 +RemoteWebNavigation.prototype = {
    1.31 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebNavigation, Ci.nsISupports]),
    1.32 +
    1.33 +  LOAD_FLAGS_MASK: 65535,
    1.34 +  LOAD_FLAGS_NONE: 0,
    1.35 +  LOAD_FLAGS_IS_REFRESH: 16,
    1.36 +  LOAD_FLAGS_IS_LINK: 32,
    1.37 +  LOAD_FLAGS_BYPASS_HISTORY: 64,
    1.38 +  LOAD_FLAGS_REPLACE_HISTORY: 128,
    1.39 +  LOAD_FLAGS_BYPASS_CACHE: 256,
    1.40 +  LOAD_FLAGS_BYPASS_PROXY: 512,
    1.41 +  LOAD_FLAGS_CHARSET_CHANGE: 1024,
    1.42 +  LOAD_FLAGS_STOP_CONTENT: 2048,
    1.43 +  LOAD_FLAGS_FROM_EXTERNAL: 4096,
    1.44 +  LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP: 8192,
    1.45 +  LOAD_FLAGS_FIRST_LOAD: 16384,
    1.46 +  LOAD_FLAGS_ALLOW_POPUPS: 32768,
    1.47 +  LOAD_FLAGS_BYPASS_CLASSIFIER: 65536,
    1.48 +  LOAD_FLAGS_FORCE_ALLOW_COOKIES: 131072,
    1.49 +
    1.50 +  STOP_NETWORK: 1,
    1.51 +  STOP_CONTENT: 2,
    1.52 +  STOP_ALL: 3,
    1.53 +
    1.54 +  canGoBack: false,
    1.55 +  canGoForward: false,
    1.56 +  goBack: function() {
    1.57 +    this._sendMessage("WebNavigation:GoBack", {});
    1.58 +  },
    1.59 +  goForward: function() {
    1.60 +    this._sendMessage("WebNavigation:GoForward", {});
    1.61 +  },
    1.62 +  gotoIndex: function(aIndex) {
    1.63 +    this._sendMessage("WebNavigation:GotoIndex", {index: aIndex});
    1.64 +  },
    1.65 +  loadURI: function(aURI, aLoadFlags, aReferrer, aPostData, aHeaders) {
    1.66 +    this._browser._contentTitle = "";
    1.67 +    this._sendMessage("WebNavigation:LoadURI", {uri: aURI, flags: aLoadFlags});
    1.68 +  },
    1.69 +  reload: function(aReloadFlags) {
    1.70 +    this._sendMessage("WebNavigation:Reload", {flags: aReloadFlags});
    1.71 +  },
    1.72 +  stop: function(aStopFlags) {
    1.73 +    this._sendMessage("WebNavigation:Stop", {flags: aStopFlags});
    1.74 +  },
    1.75 +
    1.76 +  get document() {
    1.77 +    return this._browser.contentDocument;
    1.78 +  },
    1.79 +
    1.80 +  _currentURI: null,
    1.81 +  get currentURI() {
    1.82 +    if (!this._currentURI) {
    1.83 +      this._currentURI = makeURI("about:blank");
    1.84 +    }
    1.85 +
    1.86 +    return this._currentURI;
    1.87 +  },
    1.88 +  set currentURI(aURI) {
    1.89 +    this.loadURI(aURI.spec, null, null, null);
    1.90 +  },
    1.91 +
    1.92 +  referringURI: null,
    1.93 +
    1.94 +  _sessionHistory: null,
    1.95 +  get sessionHistory() { return this._sessionHistory; },
    1.96 +  set sessionHistory(aValue) { },
    1.97 +
    1.98 +  _sendMessage: function(aMessage, aData) {
    1.99 +    try {
   1.100 +      this._browser.messageManager.sendAsyncMessage(aMessage, aData);
   1.101 +    }
   1.102 +    catch (e) {
   1.103 +      Cu.reportError(e);
   1.104 +    }
   1.105 +  },
   1.106 +
   1.107 +  receiveMessage: function(aMessage) {
   1.108 +    switch (aMessage.name) {
   1.109 +      case "WebNavigation:setHistory":
   1.110 +        this._sessionHistory = aMessage.objects.history;
   1.111 +        break;
   1.112 +    }
   1.113 +  }
   1.114 +};

mercurial