Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Some of the changes and proposals from Lloyd, simplification of the m…
Browse files Browse the repository at this point in the history
…ain.js to not work with Firefox, only xulrunner. Also, a new content-window-nobrowser.js implementation which does not use a toplevel browser -- this enabled the ui/browser-session example to work. Notice the browser-session <browser /> tag uses an under implementation xul:tabbrowser but thing that this is a one browser app. It's the developer interface here that matters, we may revisit the under implementation later -- perhaps even an enhanced modified iframe -- another discussion.
  • Loading branch information
taboca committed Nov 3, 2010
1 parent a9edf4c commit e98696a
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 19 deletions.
20 changes: 8 additions & 12 deletions impl/packages/chromeless/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ function injectLabVars(window) {

/* This may go away - we expose a bunch of things in the developers HTML browser so far and we will revisit this, possibly keep the HTML browser safe and ask que HTML browser developer to message the upper app through a whitelisted require API */

window.require = require;
window.packaging = packaging;
window.Ci = Ci;
window.Cc = Cc;

/*
window.wrappedJSObject.packaging = packaging;
window.wrappedJSObject.require = require;
window.wrappedJSObject.Ci = Ci;
window.wrappedJSObject.Cc = Cc;
*/
}

function requireForBrowser( safe_module ) {
Expand All @@ -81,17 +88,6 @@ exports.main = function main(options) {

var openLab;

if (require("xul-app").is("Firefox")) {
tabBrowser.whenContentLoaded(function(window) {
if (window.location == LAB_URL) {
injectLabVars(window);
require("window-utils").closeOnUnload(window);
}
});
openLab = function openLabInTab() {
tabBrowser.addTab(LAB_URL);
};
} else
openLab = function openLabInWindow() {

var call = options.staticArgs;
Expand All @@ -100,7 +96,7 @@ exports.main = function main(options) {
/* We have some experimentation trying to launch the main window
with a transparent background */
//var contentWindow = require("chromeless-window");
var contentWindow = require("content-window");
var contentWindow = require("content-window-nobrowser");

/* Page window height and width is fixed, it won't be
and it also shoudl be smart, so HTML browser developer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
let {Cc, Ci} = require("chrome");

var xpcom = require("xpcom");

var xulNs = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

var blankXul = ('<?xml version="1.0"?>' +
'<?xml-stylesheet href="chrome://global/skin/" ' +
' type="text/css"?>' +
'<window xmlns="' + xulNs + '">' +
'</window>');

function Injector(browser, onStartLoad) {
memory.track(this);

browser.addProgressListener(this,
Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
this._onStartLoad = onStartLoad;
}

Injector.prototype = {
QueryInterface : xpcom.utils.generateQI([Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference]),

// Taken from Firebug' content/firebug/tabWatcher.js.
_safeGetName: function(request) {
try {
return request.name;
} catch (exc) {
return null;
}
},

// Much of this is taken from Firebug's content/firebug/tabWatcher.js,
// specifically the FrameProgressListener object.
onStateChange : function (aWebProgress, aRequest,
aStateFlags, aStatus) {
if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_REQUEST) {
// We need to get the hook in as soon as the new DOMWindow is
// created, but before it starts executing any scripts in the
// page. After lengthy analysis, it seems that the start of
// these "dummy" requests is the only state that works.

// TODO: Firebug's code mentions that XHTML doesn't dispatch
// any of these dummy requests, so we should probably use the
// Firebug's XHTML workaround here.
var safeName = this._safeGetName(aRequest);
var window = aWebProgress.DOMWindow;
if (window && window.wrappedJSObject &&
(safeName == "about:layout-dummy-request" ||
safeName == "about:document-onload-blocker")) {
// TODO: Firebug's code mentions that about:blank causes strange
// behavior here; I don't think it should apply to our use case,
// though.

try {
this._onStartLoad.call(undefined, window);
} catch (e) {
console.exception(e);
}
}
}
},

// Stubs for the nsIWebProgressListener interfaces which we don't use.
onProgressChange : function() { },
onLocationChange : function() { },
onStatusChange : function() { },
onSecurityChange : function() { }
};

var windows = [];

function Window(options) {
memory.track(this);

var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Ci.nsIWindowWatcher);
var url = "data:application/vnd.mozilla.xul+xml," + escape(blankXul);

var features = ["",
"width=" + options.width,
"height=" + options.height,
"centerscreen"];

if (options.titleBar == false)
features.push("titlebar=no");

/* We now pass the options.url, which is the user app directly
inserting it in the window, instead using the xul browser element
that was here. This helped to make the session history work.
*/

var window = ww.openWindow(null, options.url, null, features.join(","), null);

this._id = windows.push(this) - 1;
this._window = window;
this._browser = null;
this._injector = null;
this.options = options;

window.addEventListener("close", this, false);
window.addEventListener("DOMContentLoaded", this, false);
}

Window.prototype = {
handleEvent: function handleEvent(event) {
switch (event.type) {
case "close":
if (event.target == this._window) {
if (windows[this._id])
delete windows[this._id];
this._window.removeEventListener("close", this, false);
}
break;
case "DOMContentLoaded":
console.log("!");
if (event.target == this._window.document) {
this._window.removeEventListener("DOMContentLoaded", this, false);
this.options.onStartLoad(this._window);
}
break;
}
},
close: function() {
this._window.close();
}
};

require("errors").catchAndLogProps(Window.prototype, "handleEvent");

exports.Window = Window;

require("unload").when(
function() {
windows.slice().forEach(function(window) { window.close(); });
});
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,27 @@ let gSession = {
}
return jsonString;
},
initSessionHistory: function _initSessionHistory(gBrowser) {
_initSessionHistory: function _initSessionHistory() {

// We will change this eventually. We so far have a whole
// session history service associated with each browser
// due to fact we using tabbrowser
// gBrowser.selectedBrowser.webNavigation.sessionHistory;

try {
var gBrowser = this.windows[0];

gBrowser.webNavigation.sessionHistory =
Cc["@mozilla.org/browser/shistory;1"].
createInstance(Ci.nsISHistory);
gBrowser.browsers[0].removeAttribute("disablehistory");
// enable global history
try {
gBrowser.docShell.QueryInterface(Ci.nsIDocShellHistory).useGlobalHistory = true;
}
catch(ex) {
console.log("Places database may be locked: " + ex);
}
} catch (i) { console.log(i) }
},
}

Expand All @@ -139,6 +148,7 @@ exports.init = function init(aBrowser) {
gSession.initSessionFile();
console.log("Called setBroser");
gSession.addWindow(aBrowser);
gSession._initSessionHistory();
}

exports.save = function save() {
Expand Down
18 changes: 13 additions & 5 deletions ui/browser-session/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
<form><input id="awesomeBox" type="text" value="http://www.google.com" /><input type="button" onclick="launch();return false" value="go"/></form>

<button onclick="init();return false">Init</button>
<button onclick="back();return false">Back</button>
<button onclick="forward();return false">Forward</button>
<button onclick="save();return false">Save</button>

<div style='width:100%;height:550px;'>
<browser id="content" src="http://www.google.com" flex="1" />
<browser id="content" type="content-primary" />
</div>

<!-- hacks to make xul:tabbrowser work -->
Expand Down Expand Up @@ -65,19 +67,25 @@

<script type="text/javascript">

var sessionStore = null ;
var sessionStore = null;
var historyControls = null;

function init() {

historyControls = require("history");
sessionStore = require("session-store");
var browser = document.getElementById("content");
sessionStore.init(browser);
historyControls.init(browser);
}
function back() {
historyControls.back();
}
function forward() {
historyControls.forward();
}

function save() {
sessionStore.save();
}

function launch() {
try {
var uri = document.getElementById("awesomeBox").value;
Expand Down
11 changes: 11 additions & 0 deletions ui/browser-session/notes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Example in this folder is not complete - caution.

This is also from the components/nsSessionStore.js, it's here to give us
a hint on things we may need to address. One important use case is private
Expand All @@ -13,3 +14,13 @@ const OBSERVING = [
"private-browsing-change-granted"
];

Manipulating the browser history
===
https://developer.mozilla.org/en/Firefox_4_for_developers

The existing document history object, available through the window.history object, now supports the new HTML5 pushState() and replaceState() methods.

https://developer.mozilla.org/en/Security/CSP

The X-FRAME-OPTIONS response header The X-FRAME-OPTIONS HTTP response header introduced in Internet Explorer 8 is now supported by Firefox. This allows sites to indicate whether or not their pages can be used in frames, and if so, whether or not to restrict that to the sa
me origin.

0 comments on commit e98696a

Please sign in to comment.