From 70c7d0c9cb59142354ec790b6cb78f6746917d3c Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Thu, 2 Feb 2012 01:46:49 +0100 Subject: [PATCH] Bug 721777 - B2G should open new windows as new frames in Gaia r=bz,fabrice --- b2g/app/b2g.js | 10 ++++++++++ b2g/chrome/content/shell.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index b24ba90d1e24..6b9e24273f22 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -394,6 +394,15 @@ pref("layers.acceleration.force-enabled", true); pref("dom.screenEnabledProperty.enabled", true); pref("dom.screenBrightnessProperty.enabled", true); +// handle links targeting new windows +// 1=current window/tab, 2=new window, 3=new tab in most recent window +pref("browser.link.open_newwindow", 3); + +// 0: no restrictions - divert everything +// 1: don't divert window.open at all +// 2: don't divert window.open with features +pref("browser.link.open_newwindow.restriction", 0); + // Enable browser frame pref("dom.mozBrowserFramesEnabled", true); pref("dom.mozBrowserFramesWhitelist", "http://localhost:6666"); @@ -401,6 +410,7 @@ pref("dom.mozBrowserFramesWhitelist", "http://localhost:6666"); // Temporary permission hack for WebSMS pref("dom.sms.enabled", true); pref("dom.sms.whitelist", "file://,http://localhost:6666"); + // Ignore X-Frame-Options headers. pref("b2g.ignoreXFrameOptions", true); diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index bc015af91700..94bed7b9ae6d 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -225,6 +225,10 @@ var shell = { case 'load': this.home.removeEventListener('load', this, true); this.turnScreenOn(); + + let chromeWindow = window.QueryInterface(Ci.nsIDOMChromeWindow); + chromeWindow.browserDOMWindow = new nsBrowserAccess(); + this.sendEvent(window, 'ContentStart'); break; case 'MozApplicationManifest': @@ -356,3 +360,34 @@ MozKeyboard.prototype = { } }; + +function nsBrowserAccess() { +} + +nsBrowserAccess.prototype = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserDOMWindow]), + + openURI: function openURI(uri, opener, where, context) { + // TODO This should be replaced by an 'open-browser-window' intent + let contentWindow = content.wrappedJSObject; + if (!('getApplicationManager' in contentWindow)) + return null; + + let applicationManager = contentWindow.getApplicationManager(); + if (!applicationManager) + return null; + + let url = uri ? uri.spec : 'about:blank'; + let window = applicationManager.launch(url, where); + return window.contentWindow; + }, + + openURIInFrame: function openURIInFrame(uri, opener, where, context) { + throw new Error('Not Implemented'); + }, + + isTabContentWindow: function isTabContentWindow(contentWindow) { + return contentWindow == window; + } +}; +