зеркало из https://github.com/mozilla/gecko-dev.git
Bug 659738 - Move document.open implementation from classinfo to nsHTMLDocument; r=bz
This commit is contained in:
Родитель
c047325b54
Коммит
df63bccfbe
|
@ -1516,9 +1516,8 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX TBI: accepting arguments to the open method.
|
||||
nsresult
|
||||
nsHTMLDocument::OpenCommon(JSContext *cx, const nsACString& aContentType,
|
||||
nsHTMLDocument::OpenCommon(JSContext* cx, const nsAString& aContentType,
|
||||
PRBool aReplace)
|
||||
{
|
||||
if (!IsHTML() || mDisableDocWrite) {
|
||||
|
@ -1709,7 +1708,7 @@ nsHTMLDocument::OpenCommon(JSContext *cx, const nsACString& aContentType,
|
|||
}
|
||||
|
||||
// This will be propagated to the parser when someone actually calls write()
|
||||
SetContentTypeInternal(aContentType);
|
||||
SetContentTypeInternal(NS_ConvertUTF16toUTF8(aContentType));
|
||||
|
||||
mWriteState = eDocumentOpened;
|
||||
|
||||
|
@ -1767,10 +1766,40 @@ nsHTMLDocument::OpenCommon(JSContext *cx, const nsACString& aContentType,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Open(const nsACString& aContentType, PRBool aReplace,
|
||||
JSContext *cx, nsIDOMDocument** aReturn)
|
||||
nsHTMLDocument::Open(const nsAString& aContentTypeOrUrl,
|
||||
const nsAString& aReplaceOrName,
|
||||
const nsAString& aFeatures,
|
||||
JSContext* cx, PRUint8 aOptionalArgCount,
|
||||
nsISupports** aReturn)
|
||||
{
|
||||
nsresult rv = OpenCommon(cx, aContentType, aReplace);
|
||||
// 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);
|
||||
|
@ -1893,9 +1922,9 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
|
|||
"DOM Events", this);
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDocument> ignored;
|
||||
rv = Open(NS_LITERAL_CSTRING("text/html"), PR_FALSE, cx,
|
||||
getter_AddRefs(ignored));
|
||||
nsCOMPtr<nsISupports> ignored;
|
||||
rv = Open(NS_LITERAL_STRING("text/html"), EmptyString(), EmptyString(), cx,
|
||||
1, getter_AddRefs(ignored));
|
||||
|
||||
// If Open() fails, or if it didn't create a parser (as it won't
|
||||
// if the user chose to not discard the current document through
|
||||
|
|
|
@ -235,7 +235,7 @@ protected:
|
|||
|
||||
nsresult WriteCommon(JSContext *cx, const nsAString& aText,
|
||||
PRBool aNewlineTerminate);
|
||||
nsresult OpenCommon(JSContext *cx, const nsACString& aContentType,
|
||||
nsresult OpenCommon(JSContext *cx, const nsAString& aContentType,
|
||||
PRBool aReplace);
|
||||
|
||||
nsresult CreateAndAddWyciwygChannel(void);
|
||||
|
|
|
@ -1652,7 +1652,6 @@ jsid nsDOMClassInfo::sScrollX_id = JSID_VOID;
|
|||
jsid nsDOMClassInfo::sScrollY_id = JSID_VOID;
|
||||
jsid nsDOMClassInfo::sScrollMaxX_id = JSID_VOID;
|
||||
jsid nsDOMClassInfo::sScrollMaxY_id = JSID_VOID;
|
||||
jsid nsDOMClassInfo::sOpen_id = JSID_VOID;
|
||||
jsid nsDOMClassInfo::sItem_id = JSID_VOID;
|
||||
jsid nsDOMClassInfo::sNamedItem_id = JSID_VOID;
|
||||
jsid nsDOMClassInfo::sEnumerate_id = JSID_VOID;
|
||||
|
@ -1988,7 +1987,6 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
|
|||
SET_JSID_TO_STRING(sScrollY_id, cx, "scrollY");
|
||||
SET_JSID_TO_STRING(sScrollMaxX_id, cx, "scrollMaxX");
|
||||
SET_JSID_TO_STRING(sScrollMaxY_id, cx, "scrollMaxY");
|
||||
SET_JSID_TO_STRING(sOpen_id, cx, "open");
|
||||
SET_JSID_TO_STRING(sItem_id, cx, "item");
|
||||
SET_JSID_TO_STRING(sNamedItem_id, cx, "namedItem");
|
||||
SET_JSID_TO_STRING(sEnumerate_id, cx, "enumerateProperties");
|
||||
|
@ -5115,7 +5113,6 @@ nsDOMClassInfo::ShutDown()
|
|||
sScrollY_id = JSID_VOID;
|
||||
sScrollMaxX_id = JSID_VOID;
|
||||
sScrollMaxY_id = JSID_VOID;
|
||||
sOpen_id = JSID_VOID;
|
||||
sItem_id = JSID_VOID;
|
||||
sEnumerate_id = JSID_VOID;
|
||||
sNavigator_id = JSID_VOID;
|
||||
|
@ -8917,86 +8914,6 @@ ResolveImpl(JSContext *cx, nsIXPConnectWrappedNative *wrapper, jsid id,
|
|||
return doc->ResolveName(depStr, nsnull, result, aCache);
|
||||
}
|
||||
|
||||
// static
|
||||
JSBool
|
||||
nsHTMLDocumentSH::DocumentOpen(JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JSObject *obj = JS_THIS_OBJECT(cx, vp);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
|
||||
jsval *argv = JS_ARGV(cx, vp);
|
||||
if (argc > 2) {
|
||||
JSObject *global = ::JS_GetGlobalForObject(cx, obj);
|
||||
|
||||
// DOM0 quirk that makes document.open() call window.open() if
|
||||
// called with 3 or more arguments.
|
||||
|
||||
return ::JS_CallFunctionName(cx, global, "open", argc, JS_ARGV(cx, vp), vp);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> native = do_QueryWrapper(cx, obj);
|
||||
if (!native) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_FAILURE);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLDocument> doc = do_QueryInterface(native);
|
||||
NS_ENSURE_TRUE(doc, JS_FALSE);
|
||||
|
||||
nsCAutoString contentType("text/html");
|
||||
if (argc > 0) {
|
||||
JSString* jsstr = JS_ValueToString(cx, argv[0]);
|
||||
if (!jsstr) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsDependentJSString depStr;
|
||||
if (!depStr.init(cx, jsstr)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString type;
|
||||
type.Assign(depStr);
|
||||
ToLowerCase(type);
|
||||
nsCAutoString actualType, dummy;
|
||||
NS_ParseContentType(NS_ConvertUTF16toUTF8(type), actualType, dummy);
|
||||
if (!actualType.EqualsLiteral("text/html") &&
|
||||
!type.EqualsLiteral("replace")) {
|
||||
contentType = "text/plain";
|
||||
}
|
||||
}
|
||||
|
||||
PRBool replace = PR_FALSE;
|
||||
if (argc > 1) {
|
||||
JSString* jsstr = JS_ValueToString(cx, argv[1]);
|
||||
if (!jsstr) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
const jschar *chars = ::JS_GetStringCharsZ(cx, jsstr);
|
||||
if (!chars) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
replace = NS_LITERAL_STRING("replace").Equals(chars);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> retval;
|
||||
nsresult rv = doc->Open(contentType, replace, cx, getter_AddRefs(retval));
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*vp = OBJECT_TO_JSVAL(obj);
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
|
||||
static JSClass sHTMLDocumentAllClass = {
|
||||
"HTML document.all class",
|
||||
|
@ -9496,14 +9413,6 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
}
|
||||
}
|
||||
|
||||
if (id == sOpen_id) {
|
||||
JSFunction *fnc =::JS_DefineFunctionById(cx, obj, id, DocumentOpen, 0,
|
||||
JSPROP_ENUMERATE);
|
||||
*objp = obj;
|
||||
|
||||
return fnc ? NS_OK : NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
if (id == sAll_id && !sDisableDocumentAllSupport &&
|
||||
!ObjectIsNativeWrapper(cx, obj)) {
|
||||
nsIDocument *doc = static_cast<nsIDocument*>(wrapper->Native());
|
||||
|
|
|
@ -310,7 +310,6 @@ public:
|
|||
static jsid sScrollY_id;
|
||||
static jsid sScrollMaxX_id;
|
||||
static jsid sScrollMaxY_id;
|
||||
static jsid sOpen_id;
|
||||
static jsid sItem_id;
|
||||
static jsid sNamedItem_id;
|
||||
static jsid sEnumerate_id;
|
||||
|
@ -979,7 +978,6 @@ protected:
|
|||
{
|
||||
}
|
||||
|
||||
static JSBool DocumentOpen(JSContext *cx, uintN argc, jsval *vp);
|
||||
static JSBool GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
|
||||
nsDocument *doc,
|
||||
nsContentList **nodeList);
|
||||
|
|
|
@ -71,16 +71,15 @@ interface nsIDOMHTMLDocument : nsIDOMDocument
|
|||
readonly attribute nsIDOMHTMLCollection forms;
|
||||
nsIDOMNodeList getElementsByName(in DOMString elementName);
|
||||
|
||||
// This is the internal version of open(); note that the version
|
||||
// scriptable with JS is defined entirely in classinfo.
|
||||
// If aContentType is not something supported by nsHTMLDocument and
|
||||
// the HTML content sink, trying to write to the document will
|
||||
// probably throw.
|
||||
// Pass aReplace = true to trigger a replacement of the previous
|
||||
// document in session history; pass false for normal history handling.
|
||||
[implicit_jscontext]
|
||||
nsIDOMDocument open(in ACString aContentType,
|
||||
in boolean aReplace);
|
||||
[implicit_jscontext, optional_argc]
|
||||
nsISupports open([optional] in DOMString aContentTypeOrUrl,
|
||||
[optional] in DOMString aReplaceOrName,
|
||||
[optional] in DOMString aFeatures);
|
||||
void close();
|
||||
|
||||
[implicit_jscontext]
|
||||
|
|
Загрузка…
Ссылка в новой задаче