Bug 660669 - Remove nsHTMLDocument::OpenCommon; r=bz

This commit is contained in:
Ms2ger 2011-06-04 08:57:23 +02:00
parent e1b3356b00
commit 338feb1384
2 changed files with 50 additions and 73 deletions

View File

@ -991,7 +991,7 @@ nsHTMLDocument::StopDocumentLoad()
mWriteState = eDocumentClosed;
// Remove the wyciwyg channel request from the document load group
// that we added in OpenCommon().
// that we added in Open().
NS_ASSERTION(mWyciwygChannel, "nsHTMLDocument::StopDocumentLoad(): "
"Trying to remove nonexistent wyciwyg channel!");
RemoveWyciwygChannel();
@ -1516,33 +1516,50 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie)
return NS_OK;
}
nsresult
nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
PRBool aReplace)
NS_IMETHODIMP
nsHTMLDocument::Open(const nsAString& aContentTypeOrUrl,
const nsAString& aReplaceOrName,
const nsAString& aFeatures,
JSContext* cx, PRUint8 aOptionalArgCount,
nsISupports** aReturn)
{
if (!IsHTML() || mDisableDocWrite) {
// No calling document.open() on XHTML
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
PRBool loadAsHtml5 = nsHtml5Module::sEnabled;
nsresult rv = NS_OK;
// If we already have a parser we ignore the document.open call.
if (mParser) {
return NS_OK;
}
NS_ASSERTION(nsContentUtils::CanCallerAccess(static_cast<nsIDOMHTMLDocument*>(this)),
"XOW should have caught this!");
if (!aContentType.EqualsLiteral("text/html") &&
!aContentType.EqualsLiteral("text/plain")) {
NS_WARNING("Unsupported type; fix the caller");
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
// When called with 3 or more arguments, document.open() calls window.open().
if (aOptionalArgCount > 2) {
nsCOMPtr<nsIDOMWindowInternal> window = GetWindowInternal();
if (!window) {
return NS_OK;
}
nsCOMPtr<nsIDOMWindow> newWindow;
nsresult rv = window->Open(aContentTypeOrUrl, aReplaceOrName, aFeatures,
getter_AddRefs(newWindow));
*aReturn = newWindow.forget().get();
return rv;
}
if (!IsHTML() || mDisableDocWrite) {
// No calling document.open() on XHTML
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
nsCAutoString contentType;
contentType.AssignLiteral("text/html");
if (aOptionalArgCount > 0) {
nsAutoString type;
ToLowerCase(aContentTypeOrUrl, type);
nsCAutoString actualType, dummy;
NS_ParseContentType(NS_ConvertUTF16toUTF8(type), actualType, dummy);
if (!actualType.EqualsLiteral("text/html") &&
!type.EqualsLiteral("replace")) {
contentType.AssignLiteral("text/plain");
}
}
// If we already have a parser we ignore the document.open call.
if (mParser) {
return NS_OK;
}
// check whether we're in the middle of unload. If so, ignore this call.
@ -1602,7 +1619,7 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
if (thisURI) {
thisURI->GetSpec(thisSpec);
}
printf("nsHTMLDocument::OpenCommon callerDoc %s this %s\n", callerSpec.get(), thisSpec.get());
printf("nsHTMLDocument::Open callerDoc %s this %s\n", callerSpec.get(), thisSpec.get());
#endif
return NS_ERROR_DOM_SECURITY_ERR;
@ -1615,9 +1632,7 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
if (cv) {
PRBool okToUnload;
rv = cv->PermitUnload(PR_FALSE, &okToUnload);
if (NS_SUCCEEDED(rv) && !okToUnload) {
if (NS_SUCCEEDED(cv->PermitUnload(PR_FALSE, &okToUnload)) && !okToUnload) {
// We don't want to unload, so stop here, but don't throw an
// exception.
return NS_OK;
@ -1639,7 +1654,7 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
nsCOMPtr<nsIChannel> channel;
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull, group);
nsresult rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull, group);
if (NS_FAILED(rv)) {
return rv;
@ -1700,6 +1715,7 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
// resetting the document.
mSecurityInfo = securityInfo;
PRBool loadAsHtml5 = nsHtml5Module::sEnabled;
if (loadAsHtml5) {
mParser = nsHtml5Module::NewHtml5Parser();
rv = NS_OK;
@ -1708,7 +1724,7 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
}
// This will be propagated to the parser when someone actually calls write()
SetContentTypeInternal(NS_ConvertUTF16toUTF8(aContentType));
SetContentTypeInternal(contentType);
mWriteState = eDocumentOpened;
@ -1739,7 +1755,9 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
// so, we need to tell the docshell to not create a new history
// entry for this load. Otherwise, make sure that we're doing a normal load,
// not whatever type of load was previously done on this docshell.
shell->SetLoadType(aReplace ? LOAD_NORMAL_REPLACE : LOAD_NORMAL);
shell->SetLoadType(
(aOptionalArgCount > 1 && aReplaceOrName.EqualsLiteral("replace"))
? LOAD_NORMAL_REPLACE : LOAD_NORMAL);
nsCOMPtr<nsIContentViewer> cv;
shell->GetContentViewer(getter_AddRefs(cv));
@ -1749,7 +1767,7 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
}
// Add a wyciwyg channel request into the document load group
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::OpenCommon(): wyciwyg "
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::Open(): wyciwyg "
"channel already exists!");
// In case the editor is listening and will see the new channel
@ -1762,46 +1780,7 @@ nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
--mWriteLevel;
return rv;
}
NS_IMETHODIMP
nsHTMLDocument::Open(const nsAString& aContentTypeOrUrl,
const nsAString& aReplaceOrName,
const nsAString& aFeatures,
JSContext* cx, PRUint8 aOptionalArgCount,
nsISupports** aReturn)
{
// When called with 3 or more arguments, document.open() calls window.open().
if (aOptionalArgCount > 2) {
nsCOMPtr<nsIDOMWindowInternal> window = GetWindowInternal();
if (!window) {
return NS_OK;
}
nsCOMPtr<nsIDOMWindow> newWindow;
nsresult rv = window->Open(aContentTypeOrUrl, aReplaceOrName, aFeatures,
getter_AddRefs(newWindow));
*aReturn = newWindow.forget().get();
return rv;
}
nsAutoString contentType;
contentType.AssignLiteral("text/html");
if (aOptionalArgCount > 0) {
nsAutoString type;
ToLowerCase(aContentTypeOrUrl, type);
nsCAutoString actualType, dummy;
NS_ParseContentType(NS_ConvertUTF16toUTF8(type), actualType, dummy);
if (!actualType.EqualsLiteral("text/html") &&
!type.EqualsLiteral("replace")) {
contentType.AssignLiteral("text/plain");
}
}
nsresult rv = OpenCommon(cx, contentType,
aOptionalArgCount > 1 && aReplaceOrName.EqualsLiteral("replace"));
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(this, aReturn);
}

View File

@ -233,8 +233,6 @@ protected:
nsresult WriteCommon(JSContext *cx, const nsAString& aText,
PRBool aNewlineTerminate);
nsresult OpenCommon(JSContext *cx, const nsAString& aContentType,
PRBool aReplace);
nsresult CreateAndAddWyciwygChannel(void);
nsresult RemoveWyciwygChannel(void);