mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1204983 - Allow about: pages to load remote content (r=bholley,bz,florian,dragana)
This commit is contained in:
parent
bc4d77476e
commit
53eca9873d
@ -46,3 +46,5 @@ component {d8903bf6-68d5-4e97-bcd1-e4d3012f721a} nsBrowserGlue.js
|
||||
#ifndef MOZ_MULET
|
||||
contract @mozilla.org/content-permission/prompt;1 {d8903bf6-68d5-4e97-bcd1-e4d3012f721a}
|
||||
#endif
|
||||
component {97eea4bb-db50-4ae0-9147-1e5ed55b4ed5} nsBrowserGlue.js
|
||||
contract @mozilla.org/browser/aboutnewtab-service;1 {97eea4bb-db50-4ae0-9147-1e5ed55b4ed5}
|
||||
|
@ -7,11 +7,14 @@
|
||||
|
||||
#include "AboutRedirector.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIAboutNewTabService.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "nsDOMString.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace browser {
|
||||
@ -176,14 +179,50 @@ AboutRedirector::NewChannel(nsIURI* aURI,
|
||||
|
||||
for (int i = 0; i < kRedirTotal; i++) {
|
||||
if (!strcmp(path.get(), kRedirMap[i].id)) {
|
||||
nsAutoCString url;
|
||||
|
||||
// check if about:newtab got overridden
|
||||
if (path.EqualsLiteral("newtab")) {
|
||||
nsCOMPtr<nsIAboutNewTabService> aboutNewTabService =
|
||||
do_GetService("@mozilla.org/browser/aboutnewtab-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
bool overridden = false;
|
||||
rv = aboutNewTabService->GetOverridden(&overridden);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (overridden) {
|
||||
rv = aboutNewTabService->GetNewTabURL(url);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
// fall back to the specified url in the map
|
||||
if (url.IsEmpty()) {
|
||||
url.AssignASCII(kRedirMap[i].url);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIChannel> tempChannel;
|
||||
nsCOMPtr<nsIURI> tempURI;
|
||||
rv = NS_NewURI(getter_AddRefs(tempURI),
|
||||
nsDependentCString(kRedirMap[i].url));
|
||||
rv = NS_NewURI(getter_AddRefs(tempURI), url);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// If tempURI links to an external URI (i.e. something other than
|
||||
// chrome:// or resource://) then set the LOAD_REPLACE flag on the
|
||||
// channel which forces the channel owner to reflect the displayed
|
||||
// URL rather then being the systemPrincipal.
|
||||
bool isUIResource = false;
|
||||
rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,
|
||||
&isUIResource);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsLoadFlags loadFlags =
|
||||
isUIResource ? static_cast<nsLoadFlags>(nsIChannel::LOAD_NORMAL)
|
||||
: static_cast<nsLoadFlags>(nsIChannel::LOAD_REPLACE);
|
||||
|
||||
rv = NS_NewChannelInternal(getter_AddRefs(tempChannel),
|
||||
tempURI,
|
||||
aLoadInfo);
|
||||
aLoadInfo,
|
||||
nullptr, // aLoadGroup
|
||||
nullptr, // aCallbacks
|
||||
loadFlags);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
tempChannel->SetOriginalURI(aURI);
|
||||
|
@ -30,6 +30,7 @@ DIRS += [
|
||||
DIRS += ['build']
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIAboutNewTabService.idl',
|
||||
'nsIBrowserGlue.idl',
|
||||
'nsIBrowserHandler.idl',
|
||||
]
|
||||
|
@ -187,6 +187,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils",
|
||||
"@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
|
||||
|
||||
const ABOUT_NEWTAB = "about:newtab";
|
||||
|
||||
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
||||
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
||||
|
||||
@ -2474,6 +2476,45 @@ BrowserGlue.prototype = {
|
||||
_xpcom_factory: BrowserGlueServiceFactory,
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// nsIAboutNewTabService implementation
|
||||
//-------------------------------------
|
||||
|
||||
function AboutNewTabService()
|
||||
{
|
||||
this._newTabURL = ABOUT_NEWTAB;
|
||||
this._overridden = false;
|
||||
}
|
||||
|
||||
AboutNewTabService.prototype = {
|
||||
classID: Components.ID("{97eea4bb-db50-4ae0-9147-1e5ed55b4ed5}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutNewTabService]),
|
||||
|
||||
get newTabURL() {
|
||||
return this._newTabURL;
|
||||
},
|
||||
|
||||
set newTabURL(aNewTabURL) {
|
||||
if (aNewTabURL === ABOUT_NEWTAB) {
|
||||
this.resetNewTabURL();
|
||||
return;
|
||||
}
|
||||
this._newTabURL = aNewTabURL;
|
||||
this._overridden = true;
|
||||
Services.obs.notifyObservers(null, "newtab-url-changed", this._newTabURL);
|
||||
},
|
||||
|
||||
get overridden() {
|
||||
return this._overridden;
|
||||
},
|
||||
|
||||
resetNewTabURL: function() {
|
||||
this._newTabURL = ABOUT_NEWTAB;
|
||||
this._overridden = false;
|
||||
Services.obs.notifyObservers(null, "newtab-url-changed", this._newTabURL);
|
||||
}
|
||||
};
|
||||
|
||||
function ContentPermissionPrompt() {}
|
||||
|
||||
ContentPermissionPrompt.prototype = {
|
||||
@ -3218,7 +3259,7 @@ var E10SUINotification = {
|
||||
};
|
||||
#endif
|
||||
|
||||
var components = [BrowserGlue, ContentPermissionPrompt];
|
||||
var components = [BrowserGlue, ContentPermissionPrompt, AboutNewTabService];
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|
||||
|
||||
|
||||
|
32
browser/components/nsIAboutNewTabService.idl
Normal file
32
browser/components/nsIAboutNewTabService.idl
Normal file
@ -0,0 +1,32 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* Allows to override about:newtab to point to a different location
|
||||
* than the one specified within AboutRedirector.cpp
|
||||
*/
|
||||
|
||||
[scriptable, uuid(6c66f022-beb1-46ea-8af6-c6c6dd937ea9)]
|
||||
interface nsIAboutNewTabService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Returns "about:newtab" if not overridden, otherwise
|
||||
* a string represenation of the new URL.
|
||||
*/
|
||||
attribute ACString newTabURL;
|
||||
|
||||
/**
|
||||
* Returns true if the default of "about:newtab" got
|
||||
* overridden.
|
||||
*/
|
||||
readonly attribute bool overridden;
|
||||
|
||||
/**
|
||||
* Resets "about:newtab" to the default and also resets the
|
||||
* overridden attribute to false.
|
||||
*/
|
||||
void resetNewTabURL();
|
||||
};
|
@ -9,6 +9,7 @@
|
||||
#include "nsAboutProtocolUtils.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "nsDOMString.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule)
|
||||
|
||||
@ -48,7 +49,7 @@ static RedirEntry kRedirMap[] = {
|
||||
{ "crashes", "chrome://global/content/crashes.xhtml", 0 },
|
||||
#endif
|
||||
{
|
||||
"credits", "http://www.mozilla.org/credits/",
|
||||
"credits", "https://www.mozilla.org/credits/",
|
||||
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT
|
||||
},
|
||||
{
|
||||
@ -143,12 +144,27 @@ nsAboutRedirector::NewChannel(nsIURI* aURI,
|
||||
nsCOMPtr<nsIURI> tempURI;
|
||||
rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// If tempURI links to an external URI (i.e. something other than
|
||||
// chrome:// or resource://) then set the LOAD_REPLACE flag on the
|
||||
// channel which forces the channel owner to reflect the displayed
|
||||
// URL rather then being the systemPrincipal.
|
||||
bool isUIResource = false;
|
||||
rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,
|
||||
&isUIResource);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsLoadFlags loadFlags =
|
||||
isUIResource ? static_cast<nsLoadFlags>(nsIChannel::LOAD_NORMAL)
|
||||
: static_cast<nsLoadFlags>(nsIChannel::LOAD_REPLACE);
|
||||
|
||||
rv = NS_NewChannelInternal(getter_AddRefs(tempChannel),
|
||||
tempURI,
|
||||
aLoadInfo);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
aLoadInfo,
|
||||
nullptr, // aLoadGroup
|
||||
nullptr, // aCallbacks
|
||||
loadFlags);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
tempChannel->SetOriginalURI(aURI);
|
||||
|
||||
|
@ -1533,18 +1533,6 @@ NS_TryToMakeImmutable(nsIURI *uri,
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_URIChainHasFlags(nsIURI *uri,
|
||||
uint32_t flags,
|
||||
bool *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsINetUtil> util = do_GetNetUtil(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return util->URIChainHasFlags(uri, flags, result);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIURI>
|
||||
NS_GetInnermostURI(nsIURI *aURI)
|
||||
{
|
||||
|
@ -88,6 +88,18 @@ net_EnsureIOService(nsIIOService **ios, nsCOMPtr<nsIIOService> &grip)
|
||||
return rv;
|
||||
}
|
||||
|
||||
INLINE_IF_EXTERN nsresult
|
||||
NS_URIChainHasFlags(nsIURI *uri,
|
||||
uint32_t flags,
|
||||
bool *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsINetUtil> util = do_GetNetUtil(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return util->URIChainHasFlags(uri, flags, result);
|
||||
}
|
||||
|
||||
INLINE_IF_EXTERN nsresult
|
||||
NS_NewURI(nsIURI **result,
|
||||
const nsACString &spec,
|
||||
|
Loading…
Reference in New Issue
Block a user