Bug 132105, XLinks must pay attention to the popup prefs. r=harishd, sr=jst.

This commit is contained in:
heikki%netscape.com 2002-06-04 20:24:37 +00:00
Родитель da9d6579c8
Коммит eed0243d70
5 изменённых файлов: 104 добавлений и 6 удалений

Просмотреть файл

@ -42,6 +42,7 @@ REQUIRES = xpcom \
htmlparser \
xpconnect \
unicharutil \
pref \
$(NULL)
CPPSRCS = \

Просмотреть файл

@ -37,6 +37,7 @@ REQUIRES = xpcom \
layout \
gfx \
unicharutil \
pref \
$(NULL)
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN

Просмотреть файл

@ -59,13 +59,14 @@
#include "nsIPresShell.h"
#include "nsGUIEvent.h"
#include "nsIPresContext.h"
#include "nsIPref.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMViewCSS.h"
#include "nsIXBLService.h"
#include "nsIXBLBinding.h"
#include "nsIBindingManager.h"
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
nsresult
NS_NewXMLElement(nsIContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
@ -357,6 +358,21 @@ static inline nsresult SpecialAutoLoadReturn(nsresult aRv, nsLinkVerb aVerb)
return aRv;
}
inline PRBool BlockNewWindow(nsIPref *aPref)
{
PRBool blockNewWindow = PR_FALSE;
nsCOMPtr<nsIPref> prefs;
if (aPref) {
prefs = dont_QueryInterface(aPref);
} else {
prefs = do_GetService(kPrefServiceCID);
}
if (prefs) {
prefs->GetBoolPref("browser.block.target_new_window", &blockNewWindow);
}
return blockNewWindow;
}
NS_IMETHODIMP
nsXMLElement::MaybeTriggerAutoLink(nsIWebShell *aShell)
{
@ -381,15 +397,22 @@ nsXMLElement::MaybeTriggerAutoLink(nsIWebShell *aShell)
value.Equals(onloadString)) {
// show= ?
nsLinkVerb verb = eLinkVerb_Undefined;
nsLinkVerb verb = eLinkVerb_Undefined; // basically means same as replace
rv = nsGenericContainerElement::GetAttr(kNameSpaceID_XLink,
kShowAtom, value);
if (NS_FAILED(rv))
break;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
PRBool disableNewDuringLoad = PR_FALSE;
if (prefs) {
prefs->GetBoolPref("dom.disable_open_during_load", &disableNewDuringLoad);
}
// XXX Should probably do this using atoms
if (value.Equals(NS_LITERAL_STRING("new"))) {
verb = eLinkVerb_New;
if (!disableNewDuringLoad && value.Equals(NS_LITERAL_STRING("new"))) {
if (!BlockNewWindow(prefs)) {
verb = eLinkVerb_New;
}
} else if (value.Equals(NS_LITERAL_STRING("replace"))) {
// We want to actually stop processing the current document now.
// We do this by returning the correct value so that the one
@ -469,7 +492,7 @@ nsXMLElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
nsAutoString show, href, target;
nsIURI* baseURL = nsnull;
nsLinkVerb verb = eLinkVerb_Undefined;
nsLinkVerb verb = eLinkVerb_Undefined; // basically means same as replace
nsGenericContainerElement::GetAttr(kNameSpaceID_XLink,
kHrefAtom,
href);
@ -484,7 +507,9 @@ nsXMLElement::HandleDOMEvent(nsIPresContext* aPresContext,
// XXX Should probably do this using atoms
if (show.Equals(NS_LITERAL_STRING("new"))) {
verb = eLinkVerb_New;
if (!BlockNewWindow(nsnull)) {
verb = eLinkVerb_New;
}
} else if (show.Equals(NS_LITERAL_STRING("replace"))) {
verb = eLinkVerb_Replace;
} else if (show.Equals(NS_LITERAL_STRING("embed"))) {

Просмотреть файл

@ -0,0 +1,57 @@
<html>
<head>
<title>Synchronized document.load() test</title>
<style type="text/css">
.box {
display: box;
border: 1px solid black;
margin-bottom: 0.5em;
}
.boxheader {
font-weight: bold;
color: maroon;
}
pre {
margin-left: 2em;
}
</style>
<script type="text/javascript">
var xmlDoc = document.implementation.createDocument("", "test", null);
function documentLoaded(e) {
var s = new XMLSerializer();
var str = s.serializeToString(xmlDoc);
document.getElementById("id1").firstChild.nodeValue = str;
var eventProperties = "";
for (prop in e) {
eventProperties += prop + " : '" + e[prop] + "'\n";
}
document.getElementById("id2").firstChild.nodeValue =
"Event object: " + e + "\n" +
"Event properties:\n" +
eventProperties;
}
xmlDoc.addEventListener("load", documentLoaded, false);
function execute()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
xmlDoc.load("http://green/heikki/login/data.xml");
}
</script>
</head>
<body onload="execute();">
<h1>Synchronized document.load() test</h1>
<div class="box"><span class="boxheader">XML document serialized</span>
<pre id="id1">@@No result@@</pre>
</div>
<div class="box"><span class="boxheader">Event information</span>
<pre id="id2">@@No result@@</pre>
</div>
</body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<?xml-stylesheet href="link.css" type="text/css"?>
<root xmlns:xlink="http://www.w3.org/1999/xlink">
<p>Testing manual simple XLinks.</p>
<mylink xlink:type="simple" xlink:show="new" xlink:href="resource:/res/samples/test0.html">
Must not open, illegal</mylink>
<mylink xlink:type="simple" xlink:show="new" xlink:href="http://www.mozilla.org">
Must open in new window (www.mozilla.org)</mylink>
<mylink xlink:type="simple" xlink:show="replace" xlink:href="http://www.mozillazine.org">
Must open in same window (www.mozillazine.org)</mylink>
<mylink xlink:type="simple" xlink:show="foo" xlink:href="http://www.mozilla.org/">
Foo</mylink>
</root>