mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 21:18:35 +00:00
Checking in new files needed for layout split. Not part of the build yet.
This commit is contained in:
parent
ed992c159a
commit
de8d58f084
210
content/base/public/nsContentCID.h
Normal file
210
content/base/public/nsContentCID.h
Normal file
@ -0,0 +1,210 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsContentCID_h__
|
||||
#define nsContentCID_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
// {1691E1F7-EE41-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_STYLESET_CID \
|
||||
{ 0x1691e1f7, 0xee41, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {96882B70-8A27-11d2-8EAF-00805F29F370}
|
||||
#define NS_HTMLSTYLESHEET_CID \
|
||||
{ 0x96882b70, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {972D8D8F-F0DA-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_DOCUMENT_VIEWER_CID \
|
||||
{ 0x972d8d8f, 0xf0da, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {A5121627-EDB6-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_ANONYMOUSCONTENT_CID \
|
||||
{ 0xa5121627, 0xedb6, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {FC886801-E768-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID \
|
||||
{ 0xfc886801, 0xe768, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
/* a6cf90f9-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_LAYOUT_DEBUGGER_CID \
|
||||
{ 0xa6cf90f9, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
/* a6cf90fc-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_HTML_ELEMENT_FACTORY_CID \
|
||||
{ 0xa6cf90fc, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
#define NS_HTMLDOCUMENT_CID \
|
||||
{ /* 5d0fcdd0-4daa-11d2-b328-00805f8a3859 */ \
|
||||
0x5d0fcdd0, 0x4daa, 0x11d2, \
|
||||
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
|
||||
|
||||
#define NS_XMLDOCUMENT_CID \
|
||||
{ /* a6cf9063-15b3-11d2-932e-00805f8add32 */ \
|
||||
0xa6cf9063, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
#define NS_XML_ELEMENT_FACTORY_CID \
|
||||
{ /* CF170391-79CC-11d3-BE44-0020A6361667 */ \
|
||||
0xcf170391, 0x79cc, 0x11d3, \
|
||||
{0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67}}
|
||||
|
||||
#define NS_IMAGEDOCUMENT_CID \
|
||||
{ /* e11a6080-4daa-11d2-b328-00805f8a3859 */ \
|
||||
0xe11a6080, 0x4daa, 0x11d2, \
|
||||
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
|
||||
|
||||
// {A1FDE864-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_HTMLHRELEMENT_CID \
|
||||
{ 0xa1fde864, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {A1FDE865-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_HTMLINPUTELEMENT_CID \
|
||||
{ 0xa1fde865, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {A1FDE866-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_HTMLATTRIBUTES_CID \
|
||||
{ 0xa1fde866, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
#define NS_HTMLIMAGEELEMENT_CID \
|
||||
{ /* d6008c40-4dad-11d2-b328-00805f8a3859 */ \
|
||||
0xd6008c40, 0x4dad, 0x11d2, \
|
||||
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
|
||||
|
||||
#define NS_HTMLOPTIONELEMENT_CID \
|
||||
{ /* a6cf90f5-15b3-11d2-932e-00805f8add32 */ \
|
||||
0xa6cf90f5, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
#define NS_NAMESPACEMANAGER_CID \
|
||||
{ /* d9783472-8fe9-11d2-9d3c-0060088f9ff7 */ \
|
||||
0xd9783472, 0x8fe9, 0x11d2, \
|
||||
{0x9d, 0x3c, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
/* a6cf90d7-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_FRAME_UTIL_CID \
|
||||
{ 0xa6cf90d5, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
|
||||
// XXX This should really be factored into a style-specific DLL so
|
||||
// that all the HTML, generic layout, and style stuff isn't munged
|
||||
// together.
|
||||
|
||||
// {2E363D60-872E-11d2-B531-000000000000}
|
||||
#define NS_CSSPARSER_CID \
|
||||
{ 0x2e363d60, 0x872e, 0x11d2, { 0xb5, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
// {95F46161-D177-11d2-BF86-00105A1B0627}
|
||||
#define NS_HTML_CSS_STYLESHEET_CID \
|
||||
{ 0x95f46161, 0xd177, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
|
||||
|
||||
// {A1FDE867-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_CSS_STYLESHEET_CID \
|
||||
{ 0xa1fde867, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {eaca2576-0d4a-11d3-9d7e-0060088f9ff7}
|
||||
#define NS_CSS_LOADER_CID \
|
||||
{ 0xeaca2576, 0x0d4a, 0x11d3, { 0x9d, 0x7e, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7 } }
|
||||
|
||||
// {96882B71-8A27-11d2-8EAF-00805F29F370}
|
||||
#define NS_TEXTNODE_CID \
|
||||
{ 0x96882b71, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {96882B72-8A27-11d2-8EAF-00805F29F370}
|
||||
#define NS_SELECTION_CID \
|
||||
{ 0x96882b72, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
#define NS_FRAMESELECTION_CID \
|
||||
{/* {905F80F1-8A7B-11d2-918C-0080C8E44DB5}*/ \
|
||||
0x905f80f1, 0x8a7b, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
|
||||
|
||||
#define NS_DOMSELECTION_CID \
|
||||
{/* {C87A37FC-8109-4ce2-A322-8CDEC925379F}*/ \
|
||||
0xc87a37fc, 0x8109, 0x4ce2, { 0xa3, 0x22, 0x8c, 0xde, 0xc9, 0x25, 0x37, 0x9f } }
|
||||
|
||||
#define NS_RANGE_CID \
|
||||
{/* {56AD2981-8A87-11d2-918C-0080C8E44DB5}*/ \
|
||||
0x56ad2981, 0x8a87, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
|
||||
|
||||
// {A1FDE868-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_ATTRIBUTECONTENT_CID \
|
||||
{ 0xa1fde868, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
#define NS_CONTENTITERATOR_CID \
|
||||
{/* {a6cf90e3-15b3-11d2-932e-00805f8add32}*/ \
|
||||
0xa6cf90e3, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
|
||||
|
||||
#define NS_GENERATEDSUBTREEITERATOR_CID \
|
||||
{/* {9A45253B-EB8F-49f1-B925-E9EA90D3EB3A}*/ \
|
||||
0x9a45253b, 0xeb8f, 0x49f1, { 0xb9, 0x25, 0xe9, 0xea, 0x90, 0xd3, 0xeb, 0x3a } }
|
||||
|
||||
#define NS_GENERATEDCONTENTITERATOR_CID \
|
||||
{/* {A364930F-E353-49f1-AC69-91637EB8B757}*/ \
|
||||
0xa364930f, 0xe353, 0x49f1, { 0xac, 0x69, 0x91, 0x63, 0x7e, 0xb8, 0xb7, 0x57 } }
|
||||
|
||||
#define NS_SUBTREEITERATOR_CID \
|
||||
{/* {a6cf90e5-15b3-11d2-932e-00805f8add32}*/ \
|
||||
0xa6cf90e5, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
|
||||
|
||||
// {09F689E0-B4DA-11d2-A68B-00104BDE6048}
|
||||
#define NS_EVENTLISTENERMANAGER_CID \
|
||||
{ 0x9f689e0, 0xb4da, 0x11d2, { 0xa6, 0x8b, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
|
||||
|
||||
// {A1FDE862-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_EVENTSTATEMANAGER_CID \
|
||||
{ 0xa1fde862, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {64F300A1-C88C-11d3-97FB-00400553EEF0}
|
||||
#define NS_XBLSERVICE_CID \
|
||||
{ 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
|
||||
|
||||
// {15671AF5-39F9-4c70-8CE3-72C97111B52D}
|
||||
#define NS_BINDINGMANAGER_CID \
|
||||
{ 0x15671af5, 0x39f9, 0x4c70, { 0x8c, 0xe3, 0x72, 0xc9, 0x71, 0x11, 0xb5, 0x2d } }
|
||||
|
||||
// 3a9cd622-264d-11d4-ba06-0060b0fc76dd
|
||||
#define NS_DOM_IMPLEMENTATION_CID \
|
||||
{ 0x3a9cd622, 0x264d, 0x11d4, {0xba, 0x06, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xdd } }
|
||||
|
||||
// {AE52FE52-683A-437D-B661-DE55F4E0A873}
|
||||
#define NS_NODEINFOMANAGER_CID \
|
||||
{ 0xae52fe52, 0x683a, 0x437d, { 0xb6, 0x61, 0xde, 0x55, 0xf4, 0xe0, 0xa8, 0x73 } }
|
||||
|
||||
// {ECEA1B28-AE54-4047-8BBE-C624235106B4}
|
||||
#define NS_COMPUTEDDOMSTYLE_CID \
|
||||
{ 0xecea1b28, 0xae54, 0x4047, { 0x8b, 0xbe, 0xc6, 0x24, 0x23, 0x51, 0x06, 0xb4 } }
|
||||
|
||||
// {4aef38b7-6364-4e23-a5e7-12f837fbbd9c}
|
||||
#define NS_XMLCONTENTSERIALIZER_CID \
|
||||
{ 0x4aef38b7, 0x6364, 0x4e23, { 0xa5, 0xe7, 0x12, 0xf8, 0x37, 0xfb, 0xbd, 0x9c } }
|
||||
|
||||
// {9d3f70da-86e9-11d4-95ec-00b0d03e37b7}
|
||||
#define NS_HTMLCONTENTSERIALIZER_CID \
|
||||
{ 0x9d3f70da, 0x86e9, 0x11d4, { 0x95, 0xec, 0x00, 0xb0, 0xd0, 0x3e, 0x37, 0xb7 } }
|
||||
|
||||
// {6030f7ef-32ed-46a7-9a63-6a5d3f90445f}
|
||||
#define NS_PLAINTEXTSERIALIZER_CID \
|
||||
{ 0x6030f7ef, 0x32ed, 0x46a7, { 0x9a, 0x63, 0x6a, 0x5d, 0x3f, 0x90, 0x44, 0x5f } }
|
||||
|
||||
#endif /* nsContentCID_h__ */
|
75
content/base/public/nsContentUtils.h
Normal file
75
content/base/public/nsContentUtils.h
Normal file
@ -0,0 +1,75 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/* A namespace class for static layout utilities. */
|
||||
|
||||
#ifndef nsContentUtils_h___
|
||||
#define nsContentUtils_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "jspubtd.h"
|
||||
#include "nsAReadableString.h"
|
||||
|
||||
class nsIScriptContext;
|
||||
class nsIScriptGlobalObject;
|
||||
|
||||
class nsContentUtils
|
||||
{
|
||||
public:
|
||||
|
||||
// These are copied from nsJSUtils.h
|
||||
|
||||
static nsresult GetStaticScriptGlobal(JSContext* aContext,
|
||||
JSObject* aObj,
|
||||
nsIScriptGlobalObject** aNativeGlobal);
|
||||
|
||||
static nsresult GetStaticScriptContext(JSContext* aContext,
|
||||
JSObject* aObj,
|
||||
nsIScriptContext** aScriptContext);
|
||||
|
||||
static nsresult GetDynamicScriptGlobal(JSContext *aContext,
|
||||
nsIScriptGlobalObject** aNativeGlobal);
|
||||
|
||||
static nsresult GetDynamicScriptContext(JSContext *aContext,
|
||||
nsIScriptContext** aScriptContext);
|
||||
|
||||
static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAReadableString& aSource,
|
||||
PRUint32 aSrcOffset,
|
||||
PRUnichar* aDest,
|
||||
PRUint32 aLength);
|
||||
|
||||
static PRUint32 CopyNewlineNormalizedUnicodeTo(nsReadingIterator<PRUnichar>& aSrcStart, const nsReadingIterator<PRUnichar>& aSrcEnd, nsAWritableString& aDest);
|
||||
};
|
||||
|
||||
#endif /* nsContentUtils_h___ */
|
273
content/base/src/nsContentUtils.cpp
Normal file
273
content/base/src/nsContentUtils.cpp
Normal file
@ -0,0 +1,273 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
/* A namespace class for static layout utilities. */
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsContentUtils::GetStaticScriptGlobal(JSContext* aContext,
|
||||
JSObject* aObj,
|
||||
nsIScriptGlobalObject** aNativeGlobal)
|
||||
{
|
||||
nsISupports* supports;
|
||||
JSClass* clazz;
|
||||
JSObject* parent;
|
||||
JSObject* glob = aObj; // starting point for search
|
||||
|
||||
if (!glob)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
while (nsnull != (parent = JS_GetParent(aContext, glob)))
|
||||
glob = parent;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
clazz = JS_GetClass(aContext, glob);
|
||||
#else
|
||||
clazz = JS_GetClass(glob);
|
||||
#endif
|
||||
|
||||
if (!clazz ||
|
||||
!(clazz->flags & JSCLASS_HAS_PRIVATE) ||
|
||||
!(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) ||
|
||||
!(supports = (nsISupports*) JS_GetPrivate(aContext, glob))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return supports->QueryInterface(NS_GET_IID(nsIScriptGlobalObject),
|
||||
(void**) aNativeGlobal);
|
||||
}
|
||||
|
||||
//static
|
||||
nsresult
|
||||
nsContentUtils::GetStaticScriptContext(JSContext* aContext,
|
||||
JSObject* aObj,
|
||||
nsIScriptContext** aScriptContext)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> nativeGlobal;
|
||||
GetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal));
|
||||
if (!nativeGlobal)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsIScriptContext* scriptContext = nsnull;
|
||||
nativeGlobal->GetContext(&scriptContext);
|
||||
*aScriptContext = scriptContext;
|
||||
return scriptContext ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//static
|
||||
nsresult
|
||||
nsContentUtils::GetDynamicScriptGlobal(JSContext* aContext,
|
||||
nsIScriptGlobalObject** aNativeGlobal)
|
||||
{
|
||||
nsIScriptGlobalObject* nativeGlobal = nsnull;
|
||||
nsCOMPtr<nsIScriptContext> scriptCX;
|
||||
GetDynamicScriptContext(aContext, getter_AddRefs(scriptCX));
|
||||
if (scriptCX) {
|
||||
*aNativeGlobal = nativeGlobal = scriptCX->GetGlobalObject();
|
||||
}
|
||||
return nativeGlobal ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//static
|
||||
nsresult
|
||||
nsContentUtils::GetDynamicScriptContext(JSContext *aContext,
|
||||
nsIScriptContext** aScriptContext)
|
||||
{
|
||||
// XXX We rely on the rule that if any JSContext in our JSRuntime has a
|
||||
// private set then that private *must* be a pointer to an nsISupports.
|
||||
nsISupports *supports = (nsIScriptContext*) JS_GetContextPrivate(aContext);
|
||||
if (!supports)
|
||||
return nsnull;
|
||||
return supports->QueryInterface(NS_GET_IID(nsIScriptContext),
|
||||
(void**)aScriptContext);
|
||||
}
|
||||
|
||||
template <class OutputIterator>
|
||||
struct NormalizeNewlinesCharTraits {
|
||||
public:
|
||||
typedef typename OutputIterator::value_type value_type;
|
||||
|
||||
public:
|
||||
NormalizeNewlinesCharTraits(OutputIterator& aIterator) : mIterator(aIterator) { }
|
||||
void writechar(typename OutputIterator::value_type aChar) {
|
||||
*mIterator++ = aChar;
|
||||
}
|
||||
|
||||
private:
|
||||
OutputIterator mIterator;
|
||||
};
|
||||
|
||||
#ifdef HAVE_CPP_PARTIAL_SPECIALIZATION
|
||||
|
||||
template <class CharT>
|
||||
struct NormalizeNewlinesCharTraits<CharT*> {
|
||||
public:
|
||||
typedef CharT value_type;
|
||||
|
||||
public:
|
||||
NormalizeNewlinesCharTraits(CharT* aCharPtr) : mCharPtr(aCharPtr) { }
|
||||
void writechar(CharT aChar) {
|
||||
*mCharPtr++ = aChar;
|
||||
}
|
||||
|
||||
private:
|
||||
CharT* mCharPtr;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
struct NormalizeNewlinesCharTraits<char*> {
|
||||
public:
|
||||
typedef char value_type;
|
||||
|
||||
public:
|
||||
NormalizeNewlinesCharTraits(char* aCharPtr) : mCharPtr(aCharPtr) { }
|
||||
void writechar(char aChar) {
|
||||
*mCharPtr++ = aChar;
|
||||
}
|
||||
|
||||
private:
|
||||
char* mCharPtr;
|
||||
};
|
||||
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
struct NormalizeNewlinesCharTraits<PRUnichar*> {
|
||||
public:
|
||||
typedef PRUnichar value_type;
|
||||
|
||||
public:
|
||||
NormalizeNewlinesCharTraits(PRUnichar* aCharPtr) : mCharPtr(aCharPtr) { }
|
||||
void writechar(PRUnichar aChar) {
|
||||
*mCharPtr++ = aChar;
|
||||
}
|
||||
|
||||
private:
|
||||
PRUnichar* mCharPtr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template <class OutputIterator>
|
||||
class CopyNormalizeNewlines
|
||||
{
|
||||
public:
|
||||
typedef typename OutputIterator::value_type value_type;
|
||||
|
||||
public:
|
||||
CopyNormalizeNewlines(OutputIterator* aDestination) :
|
||||
mLastCharCR(PR_FALSE),
|
||||
mDestination(aDestination),
|
||||
mWritten(0)
|
||||
{ }
|
||||
|
||||
PRUint32 GetCharsWritten() {
|
||||
return mWritten;
|
||||
}
|
||||
|
||||
PRUint32 write(const typename OutputIterator::value_type* aSource, PRUint32 aSourceLength) {
|
||||
// If the last source buffer ended with a CR...
|
||||
if (mLastCharCR) {
|
||||
// ..and if the next one is a LF, then skip it since
|
||||
// we've already written out a newline
|
||||
if (aSourceLength && (*aSource == value_type('\n'))) {
|
||||
aSource++;
|
||||
}
|
||||
mLastCharCR = PR_FALSE;
|
||||
}
|
||||
|
||||
const typename OutputIterator::value_type* done_writing = aSource + aSourceLength;
|
||||
PRUint32 num_written = 0;
|
||||
while ( aSource < done_writing ) {
|
||||
if (*aSource == value_type('\r')) {
|
||||
mDestination->writechar('\n');
|
||||
aSource++;
|
||||
// If we've reached the end of the buffer, record
|
||||
// that we wrote out a CR
|
||||
if (aSource == done_writing) {
|
||||
mLastCharCR = PR_TRUE;
|
||||
}
|
||||
// If the next character is a LF, skip it
|
||||
else if (*aSource == value_type('\n')) {
|
||||
aSource++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
mDestination->writechar(*aSource++);
|
||||
}
|
||||
num_written++;
|
||||
}
|
||||
|
||||
mWritten += num_written;
|
||||
return aSourceLength;
|
||||
}
|
||||
|
||||
private:
|
||||
PRBool mLastCharCR;
|
||||
OutputIterator* mDestination;
|
||||
PRUint32 mWritten;
|
||||
};
|
||||
|
||||
// static
|
||||
PRUint32
|
||||
nsContentUtils::CopyNewlineNormalizedUnicodeTo(const nsAReadableString& aSource, PRUint32 aSrcOffset, PRUnichar* aDest, PRUint32 aLength)
|
||||
{
|
||||
typedef NormalizeNewlinesCharTraits<PRUnichar*> sink_traits;
|
||||
|
||||
sink_traits dest_traits(aDest);
|
||||
CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits);
|
||||
nsReadingIterator<PRUnichar> fromBegin, fromEnd;
|
||||
copy_string(aSource.BeginReading(fromBegin).advance( PRInt32(aSrcOffset) ), aSource.BeginReading(fromEnd).advance( PRInt32(aSrcOffset+aLength) ), normalizer);
|
||||
return normalizer.GetCharsWritten();
|
||||
}
|
||||
|
||||
// static
|
||||
PRUint32
|
||||
nsContentUtils::CopyNewlineNormalizedUnicodeTo(nsReadingIterator<PRUnichar>& aSrcStart, const nsReadingIterator<PRUnichar>& aSrcEnd, nsAWritableString& aDest)
|
||||
{
|
||||
typedef nsWritingIterator<PRUnichar> WritingIterator;
|
||||
typedef NormalizeNewlinesCharTraits<WritingIterator> sink_traits;
|
||||
|
||||
WritingIterator iter;
|
||||
aDest.BeginWriting(iter);
|
||||
sink_traits dest_traits(iter);
|
||||
CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits);
|
||||
copy_string(aSrcStart, aSrcEnd, normalizer);
|
||||
return normalizer.GetCharsWritten();
|
||||
}
|
210
content/build/nsContentCID.h
Normal file
210
content/build/nsContentCID.h
Normal file
@ -0,0 +1,210 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsContentCID_h__
|
||||
#define nsContentCID_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
// {1691E1F7-EE41-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_STYLESET_CID \
|
||||
{ 0x1691e1f7, 0xee41, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {96882B70-8A27-11d2-8EAF-00805F29F370}
|
||||
#define NS_HTMLSTYLESHEET_CID \
|
||||
{ 0x96882b70, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {972D8D8F-F0DA-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_DOCUMENT_VIEWER_CID \
|
||||
{ 0x972d8d8f, 0xf0da, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {A5121627-EDB6-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_ANONYMOUSCONTENT_CID \
|
||||
{ 0xa5121627, 0xedb6, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {FC886801-E768-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID \
|
||||
{ 0xfc886801, 0xe768, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
/* a6cf90f9-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_LAYOUT_DEBUGGER_CID \
|
||||
{ 0xa6cf90f9, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
/* a6cf90fc-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_HTML_ELEMENT_FACTORY_CID \
|
||||
{ 0xa6cf90fc, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
#define NS_HTMLDOCUMENT_CID \
|
||||
{ /* 5d0fcdd0-4daa-11d2-b328-00805f8a3859 */ \
|
||||
0x5d0fcdd0, 0x4daa, 0x11d2, \
|
||||
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
|
||||
|
||||
#define NS_XMLDOCUMENT_CID \
|
||||
{ /* a6cf9063-15b3-11d2-932e-00805f8add32 */ \
|
||||
0xa6cf9063, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
#define NS_XML_ELEMENT_FACTORY_CID \
|
||||
{ /* CF170391-79CC-11d3-BE44-0020A6361667 */ \
|
||||
0xcf170391, 0x79cc, 0x11d3, \
|
||||
{0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67}}
|
||||
|
||||
#define NS_IMAGEDOCUMENT_CID \
|
||||
{ /* e11a6080-4daa-11d2-b328-00805f8a3859 */ \
|
||||
0xe11a6080, 0x4daa, 0x11d2, \
|
||||
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
|
||||
|
||||
// {A1FDE864-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_HTMLHRELEMENT_CID \
|
||||
{ 0xa1fde864, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {A1FDE865-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_HTMLINPUTELEMENT_CID \
|
||||
{ 0xa1fde865, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {A1FDE866-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_HTMLATTRIBUTES_CID \
|
||||
{ 0xa1fde866, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
#define NS_HTMLIMAGEELEMENT_CID \
|
||||
{ /* d6008c40-4dad-11d2-b328-00805f8a3859 */ \
|
||||
0xd6008c40, 0x4dad, 0x11d2, \
|
||||
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
|
||||
|
||||
#define NS_HTMLOPTIONELEMENT_CID \
|
||||
{ /* a6cf90f5-15b3-11d2-932e-00805f8add32 */ \
|
||||
0xa6cf90f5, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
#define NS_NAMESPACEMANAGER_CID \
|
||||
{ /* d9783472-8fe9-11d2-9d3c-0060088f9ff7 */ \
|
||||
0xd9783472, 0x8fe9, 0x11d2, \
|
||||
{0x9d, 0x3c, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
/* a6cf90d7-15b3-11d2-932e-00805f8add32 */
|
||||
#define NS_FRAME_UTIL_CID \
|
||||
{ 0xa6cf90d5, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
|
||||
// XXX This should really be factored into a style-specific DLL so
|
||||
// that all the HTML, generic layout, and style stuff isn't munged
|
||||
// together.
|
||||
|
||||
// {2E363D60-872E-11d2-B531-000000000000}
|
||||
#define NS_CSSPARSER_CID \
|
||||
{ 0x2e363d60, 0x872e, 0x11d2, { 0xb5, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
// {95F46161-D177-11d2-BF86-00105A1B0627}
|
||||
#define NS_HTML_CSS_STYLESHEET_CID \
|
||||
{ 0x95f46161, 0xd177, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
|
||||
|
||||
// {A1FDE867-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_CSS_STYLESHEET_CID \
|
||||
{ 0xa1fde867, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {eaca2576-0d4a-11d3-9d7e-0060088f9ff7}
|
||||
#define NS_CSS_LOADER_CID \
|
||||
{ 0xeaca2576, 0x0d4a, 0x11d3, { 0x9d, 0x7e, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7 } }
|
||||
|
||||
// {96882B71-8A27-11d2-8EAF-00805F29F370}
|
||||
#define NS_TEXTNODE_CID \
|
||||
{ 0x96882b71, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {96882B72-8A27-11d2-8EAF-00805F29F370}
|
||||
#define NS_SELECTION_CID \
|
||||
{ 0x96882b72, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
#define NS_FRAMESELECTION_CID \
|
||||
{/* {905F80F1-8A7B-11d2-918C-0080C8E44DB5}*/ \
|
||||
0x905f80f1, 0x8a7b, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
|
||||
|
||||
#define NS_DOMSELECTION_CID \
|
||||
{/* {C87A37FC-8109-4ce2-A322-8CDEC925379F}*/ \
|
||||
0xc87a37fc, 0x8109, 0x4ce2, { 0xa3, 0x22, 0x8c, 0xde, 0xc9, 0x25, 0x37, 0x9f } }
|
||||
|
||||
#define NS_RANGE_CID \
|
||||
{/* {56AD2981-8A87-11d2-918C-0080C8E44DB5}*/ \
|
||||
0x56ad2981, 0x8a87, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
|
||||
|
||||
// {A1FDE868-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_ATTRIBUTECONTENT_CID \
|
||||
{ 0xa1fde868, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
#define NS_CONTENTITERATOR_CID \
|
||||
{/* {a6cf90e3-15b3-11d2-932e-00805f8add32}*/ \
|
||||
0xa6cf90e3, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
|
||||
|
||||
#define NS_GENERATEDSUBTREEITERATOR_CID \
|
||||
{/* {9A45253B-EB8F-49f1-B925-E9EA90D3EB3A}*/ \
|
||||
0x9a45253b, 0xeb8f, 0x49f1, { 0xb9, 0x25, 0xe9, 0xea, 0x90, 0xd3, 0xeb, 0x3a } }
|
||||
|
||||
#define NS_GENERATEDCONTENTITERATOR_CID \
|
||||
{/* {A364930F-E353-49f1-AC69-91637EB8B757}*/ \
|
||||
0xa364930f, 0xe353, 0x49f1, { 0xac, 0x69, 0x91, 0x63, 0x7e, 0xb8, 0xb7, 0x57 } }
|
||||
|
||||
#define NS_SUBTREEITERATOR_CID \
|
||||
{/* {a6cf90e5-15b3-11d2-932e-00805f8add32}*/ \
|
||||
0xa6cf90e5, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
|
||||
|
||||
// {09F689E0-B4DA-11d2-A68B-00104BDE6048}
|
||||
#define NS_EVENTLISTENERMANAGER_CID \
|
||||
{ 0x9f689e0, 0xb4da, 0x11d2, { 0xa6, 0x8b, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
|
||||
|
||||
// {A1FDE862-E802-11d4-9885-00C04FA0CF4B}
|
||||
#define NS_EVENTSTATEMANAGER_CID \
|
||||
{ 0xa1fde862, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
|
||||
|
||||
// {64F300A1-C88C-11d3-97FB-00400553EEF0}
|
||||
#define NS_XBLSERVICE_CID \
|
||||
{ 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
|
||||
|
||||
// {15671AF5-39F9-4c70-8CE3-72C97111B52D}
|
||||
#define NS_BINDINGMANAGER_CID \
|
||||
{ 0x15671af5, 0x39f9, 0x4c70, { 0x8c, 0xe3, 0x72, 0xc9, 0x71, 0x11, 0xb5, 0x2d } }
|
||||
|
||||
// 3a9cd622-264d-11d4-ba06-0060b0fc76dd
|
||||
#define NS_DOM_IMPLEMENTATION_CID \
|
||||
{ 0x3a9cd622, 0x264d, 0x11d4, {0xba, 0x06, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xdd } }
|
||||
|
||||
// {AE52FE52-683A-437D-B661-DE55F4E0A873}
|
||||
#define NS_NODEINFOMANAGER_CID \
|
||||
{ 0xae52fe52, 0x683a, 0x437d, { 0xb6, 0x61, 0xde, 0x55, 0xf4, 0xe0, 0xa8, 0x73 } }
|
||||
|
||||
// {ECEA1B28-AE54-4047-8BBE-C624235106B4}
|
||||
#define NS_COMPUTEDDOMSTYLE_CID \
|
||||
{ 0xecea1b28, 0xae54, 0x4047, { 0x8b, 0xbe, 0xc6, 0x24, 0x23, 0x51, 0x06, 0xb4 } }
|
||||
|
||||
// {4aef38b7-6364-4e23-a5e7-12f837fbbd9c}
|
||||
#define NS_XMLCONTENTSERIALIZER_CID \
|
||||
{ 0x4aef38b7, 0x6364, 0x4e23, { 0xa5, 0xe7, 0x12, 0xf8, 0x37, 0xfb, 0xbd, 0x9c } }
|
||||
|
||||
// {9d3f70da-86e9-11d4-95ec-00b0d03e37b7}
|
||||
#define NS_HTMLCONTENTSERIALIZER_CID \
|
||||
{ 0x9d3f70da, 0x86e9, 0x11d4, { 0x95, 0xec, 0x00, 0xb0, 0xd0, 0x3e, 0x37, 0xb7 } }
|
||||
|
||||
// {6030f7ef-32ed-46a7-9a63-6a5d3f90445f}
|
||||
#define NS_PLAINTEXTSERIALIZER_CID \
|
||||
{ 0x6030f7ef, 0x32ed, 0x46a7, { 0x9a, 0x63, 0x6a, 0x5d, 0x3f, 0x90, 0x44, 0x5f } }
|
||||
|
||||
#endif /* nsContentCID_h__ */
|
556
content/build/nsContentDLF.cpp
Normal file
556
content/build/nsContentDLF.cpp
Normal file
@ -0,0 +1,556 @@
|
||||
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsContentModule.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIDocumentLoaderFactory.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsString.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "prprf.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsICSSLoader.h"
|
||||
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIXULContentSink.h"
|
||||
#include "nsIStreamLoadableDocument.h"
|
||||
#include "nsIDocStreamLoaderFactory.h"
|
||||
|
||||
#define VIEW_SOURCE_HTML
|
||||
|
||||
// URL for the "user agent" style sheet
|
||||
#define UA_CSS_URL "resource:/res/ua.css"
|
||||
|
||||
// Factory code for creating variations on html documents
|
||||
|
||||
#undef NOISY_REGISTRY
|
||||
|
||||
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
|
||||
|
||||
extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult);
|
||||
|
||||
static char* gHTMLTypes[] = {
|
||||
"text/html",
|
||||
"text/plain",
|
||||
"text/rtf",
|
||||
"text/cpp",
|
||||
"text/css",
|
||||
0
|
||||
};
|
||||
|
||||
static char* gXMLTypes[] = {
|
||||
"text/xml",
|
||||
"application/xml",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
static char* gRDFTypes[] = {
|
||||
"text/rdf",
|
||||
"text/xul",
|
||||
"text/cached-xul",
|
||||
0
|
||||
};
|
||||
|
||||
static char* gImageTypes[] = {
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/x-png",
|
||||
"image/x-art",
|
||||
"image/x-jg",
|
||||
0
|
||||
};
|
||||
|
||||
class nsContentDLF : public nsIDocumentLoaderFactory,
|
||||
public nsIDocStreamLoaderFactory
|
||||
{
|
||||
public:
|
||||
nsContentDLF();
|
||||
virtual ~nsContentDLF();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// for nsIDocumentLoaderFactory
|
||||
NS_IMETHOD CreateInstance(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
|
||||
nsIDocument* aDocument,
|
||||
const char *aCommand,
|
||||
nsIContentViewer** aDocViewerResult);
|
||||
|
||||
// for nsIDocStreamLoaderFactory
|
||||
NS_METHOD CreateInstance(nsIInputStream& aInputStream,
|
||||
const char* aContentType,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult InitUAStyleSheet();
|
||||
|
||||
nsresult CreateDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsISupports* aContainer,
|
||||
const nsCID& aDocumentCID,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult CreateRDFDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult CreateXULDocumentFromStream(nsIInputStream& aXULStream,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult CreateRDFDocument(nsISupports*,
|
||||
nsCOMPtr<nsIDocument>*,
|
||||
nsCOMPtr<nsIDocumentViewer>*);
|
||||
|
||||
static nsICSSStyleSheet* GetUAStyleSheet() {
|
||||
return nsContentModule::gUAStyleSheet;
|
||||
}
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult, "null OUT ptr");
|
||||
if (!aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsContentDLF* it = new nsContentDLF();
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(NS_GET_IID(nsIDocumentLoaderFactory), (void**)aResult);
|
||||
}
|
||||
|
||||
nsContentDLF::nsContentDLF()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsContentDLF::~nsContentDLF()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsContentDLF)
|
||||
NS_IMPL_RELEASE(nsContentDLF)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(NS_GET_IID(nsIDocumentLoaderFactory))) {
|
||||
nsIDocumentLoaderFactory *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsIDocStreamLoaderFactory))) {
|
||||
nsIDocStreamLoaderFactory *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDocumentLoaderFactory *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::CreateInstance(const char *aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (!GetUAStyleSheet()) {
|
||||
// Load the UA style sheet
|
||||
nsCOMPtr<nsIURI> uaURL;
|
||||
rv = NS_NewURI(getter_AddRefs(uaURL), UA_CSS_URL);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsICSSLoader> cssLoader;
|
||||
rv = NS_NewCSSLoader(getter_AddRefs(cssLoader));
|
||||
if (cssLoader) {
|
||||
PRBool complete;
|
||||
rv = cssLoader->LoadAgentSheet(uaURL, nsContentModule::gUAStyleSheet, complete,
|
||||
nsnull);
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv);
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if(0==PL_strcmp(aCommand,"view-source")) {
|
||||
#ifdef VIEW_SOURCE_HTML
|
||||
aContentType=gHTMLTypes[0];
|
||||
#else
|
||||
if(0==PL_strcmp(aContentType,gHTMLTypes[1])) {
|
||||
aContentType=gHTMLTypes[0];
|
||||
}
|
||||
else if(0==PL_strcmp(aContentType,gHTMLTypes[2])) {
|
||||
aContentType=gHTMLTypes[0];
|
||||
}
|
||||
else
|
||||
aContentType=gXMLTypes[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
// Try html
|
||||
int typeIndex=0;
|
||||
while(gHTMLTypes[typeIndex]) {
|
||||
if (0== PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
|
||||
return CreateDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContainer, kHTMLDocumentCID,
|
||||
aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// Try XML
|
||||
typeIndex = 0;
|
||||
while(gXMLTypes[typeIndex]) {
|
||||
if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
|
||||
return CreateDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContainer, kXMLDocumentCID,
|
||||
aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// Try RDF
|
||||
typeIndex = 0;
|
||||
while (gRDFTypes[typeIndex]) {
|
||||
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
|
||||
return CreateRDFDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContentType, aContainer,
|
||||
aExtraInfo, aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// Try image types
|
||||
typeIndex = 0;
|
||||
while(gImageTypes[typeIndex]) {
|
||||
if (0== PL_strcmp(gImageTypes[typeIndex++], aContentType)) {
|
||||
return CreateDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContainer, kImageDocumentCID,
|
||||
aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, then we weren't able to create anything. Sorry!
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
|
||||
nsIDocument* aDocument,
|
||||
const char *aCommand,
|
||||
nsIContentViewer** aDocViewerResult)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
do {
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
// Create the document viewer
|
||||
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
docv->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
|
||||
|
||||
// Bind the document to the Content Viewer
|
||||
rv = docv->BindToDocument(aDocument, aCommand);
|
||||
*aDocViewerResult = docv;
|
||||
NS_IF_ADDREF(*aDocViewerResult);
|
||||
} while (PR_FALSE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsContentDLF::CreateDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsISupports* aContainer,
|
||||
const nsCID& aDocumentCID,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIURI> aURL;
|
||||
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#ifdef NOISY_CREATE_DOC
|
||||
if (nsnull != aURL) {
|
||||
nsAutoString tmp;
|
||||
aURL->ToString(tmp);
|
||||
fputs(tmp, stdout);
|
||||
printf(": creating document\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
do {
|
||||
// Create the document
|
||||
rv = nsComponentManager::CreateInstance(aDocumentCID, nsnull,
|
||||
NS_GET_IID(nsIDocument),
|
||||
getter_AddRefs(doc));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
// Create the document viewer XXX: could reuse document viewer here!
|
||||
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
docv->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
|
||||
|
||||
// Initialize the document to begin loading the data. An
|
||||
// nsIStreamListener connected to the parser is returned in
|
||||
// aDocListener.
|
||||
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
// Bind the document to the Content Viewer
|
||||
rv = docv->BindToDocument(doc, aCommand);
|
||||
*aDocViewer = docv;
|
||||
NS_IF_ADDREF(*aDocViewer);
|
||||
} while (PR_FALSE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::CreateInstance(nsIInputStream& aInputStream,
|
||||
const char* aContentType,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer)
|
||||
|
||||
{
|
||||
nsresult status = NS_ERROR_FAILURE;
|
||||
|
||||
// Try RDF
|
||||
int typeIndex = 0;
|
||||
while (gRDFTypes[typeIndex]) {
|
||||
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
|
||||
return CreateXULDocumentFromStream(aInputStream,
|
||||
aCommand,
|
||||
aContainer,
|
||||
aExtraInfo,
|
||||
aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// ...common work for |CreateRDFDocument| and |CreateXULDocumentFromStream|
|
||||
nsresult
|
||||
nsContentDLF::CreateRDFDocument(nsISupports* aExtraInfo,
|
||||
nsCOMPtr<nsIDocument>* doc,
|
||||
nsCOMPtr<nsIDocumentViewer>* docv)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// Create the XUL document
|
||||
rv = nsComponentManager::CreateInstance(kXULDocumentCID, nsnull,
|
||||
NS_GET_IID(nsIDocument),
|
||||
getter_AddRefs(*doc));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create the image content viewer...
|
||||
rv = NS_NewDocumentViewer(getter_AddRefs(*docv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Load the UA style sheet if we haven't already done that
|
||||
(*docv)->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// ...note, this RDF document _may_ be XUL :-)
|
||||
nsresult
|
||||
nsContentDLF::CreateRDFDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
nsresult rv = CreateRDFDocument(aExtraInfo, address_of(doc), address_of(docv));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> aURL;
|
||||
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
/*
|
||||
* Initialize the document to begin loading the data...
|
||||
*
|
||||
* An nsIStreamListener connected to the parser is returned in
|
||||
* aDocListener.
|
||||
*/
|
||||
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
/*
|
||||
* Bind the document to the Content Viewer...
|
||||
*/
|
||||
rv = docv->BindToDocument(doc, aCommand);
|
||||
*aDocViewer = docv;
|
||||
NS_IF_ADDREF(*aDocViewer);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsContentDLF::CreateXULDocumentFromStream(nsIInputStream& aXULStream,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
|
||||
do
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
if ( NS_FAILED(status = CreateRDFDocument(aExtraInfo, address_of(doc), address_of(docv))) )
|
||||
break;
|
||||
|
||||
if ( NS_FAILED(status = docv->BindToDocument(doc, aCommand)) )
|
||||
break;
|
||||
|
||||
*aDocViewer = docv;
|
||||
NS_IF_ADDREF(*aDocViewer);
|
||||
|
||||
nsCOMPtr<nsIStreamLoadableDocument> loader = do_QueryInterface(doc, &status);
|
||||
if ( NS_FAILED(status) )
|
||||
break;
|
||||
|
||||
status = loader->LoadFromStream(aXULStream, aContainer, aCommand);
|
||||
}
|
||||
while (0);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
|
||||
|
||||
static nsresult
|
||||
RegisterTypes(nsIComponentManager* aCompMgr,
|
||||
const char* aCommand,
|
||||
nsIFile* aPath,
|
||||
char** aTypes)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
while (*aTypes) {
|
||||
char contractid[500];
|
||||
char* contentType = *aTypes++;
|
||||
PR_snprintf(contractid, sizeof(contractid),
|
||||
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "%s;1?type=%s",
|
||||
aCommand, contentType);
|
||||
#ifdef NOISY_REGISTRY
|
||||
printf("Register %s => %s\n", contractid, aPath);
|
||||
#endif
|
||||
rv = aCompMgr->RegisterComponentSpec(kDocumentFactoryImplCID, "Content",
|
||||
contractid, aPath, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsContentModule::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath)
|
||||
{
|
||||
// We do not register view or view-source document factories because
|
||||
// that is for layout. Now load-as-data might be a different story...
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsContentModule::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath)
|
||||
{
|
||||
aCompMgr->UnregisterComponentSpec(kDocumentFactoryImplCID, aPath);
|
||||
}
|
528
content/build/nsContentFactory.cpp
Normal file
528
content/build/nsContentFactory.cpp
Normal file
@ -0,0 +1,528 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#include "nslayout.h"
|
||||
#include "nsContentModule.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsITextContent.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIFrameUtil.h"
|
||||
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsHTMLParts.h"
|
||||
#include "nsDOMCID.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICSSParser.h"
|
||||
#include "nsIHTMLStyleSheet.h"
|
||||
#include "nsIHTMLCSSStyleSheet.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsICSSLoader.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIContentIterator.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIScriptNameSetRegistry.h"
|
||||
#include "nsIScriptNameSpaceManager.h"
|
||||
#include "nsIScriptExternalNameSet.h"
|
||||
#include "nsIEventListenerManager.h"
|
||||
#include "nsILayoutDebugger.h"
|
||||
#include "nsIElementFactory.h"
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFrameSelection.h"
|
||||
#include "nsIDOMDOMImplementation.h"
|
||||
#include "nsIPrivateDOMImplementation.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIHTMLAttributes.h"
|
||||
|
||||
#include "nsIXBLService.h"
|
||||
#include "nsIBindingManager.h"
|
||||
|
||||
#include "nsContentPolicyUtils.h"
|
||||
|
||||
#include "nsXMLContentSerializer.h"
|
||||
#include "nsHTMLContentSerializer.h"
|
||||
#include "nsPlainTextSerializer.h"
|
||||
|
||||
#include "nsINodeInfo.h"
|
||||
#include "nsIComputedDOMStyle.h"
|
||||
|
||||
#include "nsEventStateManager.h"
|
||||
|
||||
class nsIDocumentLoaderFactory;
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
|
||||
static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID);
|
||||
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kCSSParserCID, NS_CSSPARSER_CID);
|
||||
static NS_DEFINE_CID(kHTMLCSSStyleSheetCID, NS_HTML_CSS_STYLESHEET_CID);
|
||||
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
|
||||
static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID);
|
||||
static NS_DEFINE_CID(kCSSStyleSheetCID, NS_CSS_STYLESHEET_CID);
|
||||
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
|
||||
static NS_DEFINE_IID(kHTMLImageElementCID, NS_HTMLIMAGEELEMENT_CID);
|
||||
static NS_DEFINE_IID(kHTMLHrElementCID, NS_HTMLHRELEMENT_CID);
|
||||
static NS_DEFINE_IID(kHTMLInputElementCID, NS_HTMLINPUTELEMENT_CID);
|
||||
static NS_DEFINE_IID(kHTMLOptionElementCID, NS_HTMLOPTIONELEMENT_CID);
|
||||
|
||||
static NS_DEFINE_IID(kAnonymousElementCID, NS_ANONYMOUSCONTENT_CID);
|
||||
|
||||
static NS_DEFINE_IID(kHTMLAttributesCID, NS_HTMLATTRIBUTES_CID);
|
||||
|
||||
static NS_DEFINE_CID(kSelectionCID, NS_SELECTION_CID);
|
||||
static NS_DEFINE_IID(kFrameSelectionCID, NS_FRAMESELECTION_CID);
|
||||
static NS_DEFINE_IID(kDOMSelectionCID, NS_DOMSELECTION_CID);
|
||||
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
static NS_DEFINE_IID(kAttributeContentCID, NS_ATTRIBUTECONTENT_CID);
|
||||
static NS_DEFINE_IID(kContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||
static NS_DEFINE_IID(kGeneratedContentIteratorCID, NS_GENERATEDCONTENTITERATOR_CID);
|
||||
static NS_DEFINE_IID(kGeneratedSubtreeIteratorCID, NS_GENERATEDSUBTREEITERATOR_CID);
|
||||
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
|
||||
|
||||
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kFrameUtilCID, NS_FRAME_UTIL_CID);
|
||||
static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
|
||||
static NS_DEFINE_CID(kEventStateManagerCID, NS_EVENTSTATEMANAGER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kDocumentViewerCID, NS_DOCUMENT_VIEWER_CID);
|
||||
static NS_DEFINE_CID(kContentDocumentLoaderFactoryCID, NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
|
||||
static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
|
||||
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
|
||||
static NS_DEFINE_CID(kTextEncoderCID, NS_TEXT_ENCODER_CID);
|
||||
static NS_DEFINE_CID(kHTMLCopyTextEncoderCID, NS_HTMLCOPY_TEXT_ENCODER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kXMLContentSerializerCID, NS_XMLCONTENTSERIALIZER_CID);
|
||||
static NS_DEFINE_CID(kHTMLContentSerializerCID, NS_HTMLCONTENTSERIALIZER_CID);
|
||||
static NS_DEFINE_CID(kPlainTextSerializerCID, NS_PLAINTEXTSERIALIZER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kXBLServiceCID, NS_XBLSERVICE_CID);
|
||||
static NS_DEFINE_CID(kBindingManagerCID, NS_BINDINGMANAGER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID);
|
||||
static NS_DEFINE_CID(kNodeInfoManagerCID, NS_NODEINFOMANAGER_CID);
|
||||
static NS_DEFINE_CID(kContentPolicyCID, NS_CONTENTPOLICY_CID);
|
||||
static NS_DEFINE_CID(kComputedDOMStyleCID, NS_COMPUTEDDOMSTYLE_CID);
|
||||
|
||||
extern nsresult NS_NewAnonymousContent2(nsIContent** aInstancePtrResult);
|
||||
|
||||
extern nsresult NS_NewSelection(nsIFrameSelection** aResult);
|
||||
extern nsresult NS_NewDomSelection(nsISelection** aResult);
|
||||
extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult);
|
||||
extern nsresult NS_NewRange(nsIDOMRange** aResult);
|
||||
extern nsresult NS_NewContentIterator(nsIContentIterator** aResult);
|
||||
extern nsresult NS_NewGenRegularIterator(nsIContentIterator** aResult);
|
||||
extern nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aResult);
|
||||
extern nsresult NS_NewGenSubtreeIterator(nsIContentIterator** aInstancePtrResult);
|
||||
|
||||
extern nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
|
||||
extern nsresult NS_NewHTMLElementFactory(nsIElementFactory** aResult);
|
||||
extern nsresult NS_NewXMLElementFactory(nsIElementFactory** aResult);
|
||||
|
||||
extern nsresult NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult);
|
||||
extern nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult);
|
||||
|
||||
extern nsresult NS_NewXBLService(nsIXBLService** aResult);
|
||||
|
||||
extern nsresult NS_NewBindingManager(nsIBindingManager** aResult);
|
||||
|
||||
extern nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult);
|
||||
|
||||
extern nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsContentFactory::nsContentFactory(const nsCID &aClass)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mClassID = aClass;
|
||||
#if 0
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ Creating Content factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
nsContentFactory::~nsContentFactory()
|
||||
{
|
||||
#if 0
|
||||
char* cs = mClassID.ToString();
|
||||
printf("+++ Destroying Content factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsContentFactory, NS_GET_IID(nsIFactory))
|
||||
|
||||
#ifdef DEBUG
|
||||
#define LOG_NEW_FAILURE(_msg,_ec) \
|
||||
printf("nsContentFactory::CreateInstance failed for %s: error=%d(0x%x)\n", \
|
||||
_msg, _ec, _ec)
|
||||
#else
|
||||
#define LOG_NEW_FAILURE(_msg,_ec)
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
nsContentFactory::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
if (aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
|
||||
// XXX ClassID check happens here
|
||||
if (mClassID.Equals(kHTMLDocumentCID)) {
|
||||
res = NS_NewHTMLDocument((nsIDocument **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLDocument", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kXMLDocumentCID)) {
|
||||
res = NS_NewXMLDocument((nsIDocument **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewXMLDocument", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kImageDocumentCID)) {
|
||||
res = NS_NewImageDocument((nsIDocument **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewImageDocument", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLAttributesCID)) {
|
||||
res = NS_NewHTMLAttributes((nsIHTMLAttributes**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLAttributes", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kAnonymousElementCID)) {
|
||||
res = NS_NewAnonymousContent2((nsIContent**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewAnonymousContent2", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
#if 1
|
||||
// XXX replace these with nsIElementFactory calls
|
||||
else if (mClassID.Equals(kHTMLImageElementCID)) {
|
||||
// Note! NS_NewHTMLImageElement is special cased to handle a null nodeinfo
|
||||
res = NS_NewHTMLImageElement((nsIHTMLContent**)&inst, nsnull);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLImageElement", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLOptionElementCID)) {
|
||||
// Note! NS_NewHTMLOptionElement is special cased to handle a null nodeinfo
|
||||
res = NS_NewHTMLOptionElement((nsIHTMLContent**)&inst, nsnull);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLOptionElement", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLInputElementCID)) {
|
||||
// Note! NS_NewHTMLOptionElement is special cased to handle a null nodeinfo
|
||||
res = NS_NewHTMLInputElement((nsIHTMLContent**)&inst, nsnull);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLInputElement", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (mClassID.Equals(kFrameSelectionCID)) {
|
||||
res = NS_NewSelection((nsIFrameSelection**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewSelection", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kDOMSelectionCID)) {
|
||||
res = NS_NewDomSelection((nsISelection**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewDomSelection", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kRangeCID)) {
|
||||
res = NS_NewRange((nsIDOMRange **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewRange", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kAttributeContentCID)) {
|
||||
res = NS_NewAttributeContent((nsIContent **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewAttributeContent", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kContentIteratorCID)) {
|
||||
res = NS_NewContentIterator((nsIContentIterator **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewContentIterator", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kGeneratedContentIteratorCID)) {
|
||||
res = NS_NewGenRegularIterator((nsIContentIterator **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewGenRegularIterator", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kSubtreeIteratorCID)) {
|
||||
res = NS_NewContentSubtreeIterator((nsIContentIterator **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewContentSubtreeIterator", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kGeneratedSubtreeIteratorCID)) {
|
||||
res = NS_NewGenSubtreeIterator((nsIContentIterator **)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewGenSubtreeIterator", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kCSSParserCID)) {
|
||||
res = NS_NewCSSParser((nsICSSParser**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewCSSParser", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLCSSStyleSheetCID)) {
|
||||
res = NS_NewHTMLCSSStyleSheet((nsIHTMLCSSStyleSheet**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLCSSStyleSheet", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kCSSStyleSheetCID)) {
|
||||
res = NS_NewCSSStyleSheet((nsICSSStyleSheet**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewCSSStyleSheet", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kStyleSetCID)) {
|
||||
res = NS_NewStyleSet((nsIStyleSet**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewStyleSet", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLStyleSheetCID)) {
|
||||
res = NS_NewHTMLStyleSheet((nsIHTMLStyleSheet**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLStyleSheet", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kCSSLoaderCID)) {
|
||||
res = NS_NewCSSLoader((nsICSSLoader**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewCSSLoader", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kTextNodeCID)) {
|
||||
res = NS_NewTextNode((nsIContent**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewTextNode", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kNameSpaceManagerCID)) {
|
||||
res = NS_NewNameSpaceManager((nsINameSpaceManager**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewNameSpaceManager", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kEventListenerManagerCID)) {
|
||||
res = NS_NewEventListenerManager((nsIEventListenerManager**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewEventListenerManager", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kEventStateManagerCID)) {
|
||||
res = NS_NewEventStateManager((nsIEventStateManager**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewEventStateManager", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kContentDocumentLoaderFactoryCID)) {
|
||||
res = NS_NewContentDocumentLoaderFactory((nsIDocumentLoaderFactory**)&inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewContentDocumentLoaderFactory", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLElementFactoryCID)) {
|
||||
res = NS_NewHTMLElementFactory((nsIElementFactory**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLElementFactory", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kXMLElementFactoryCID)) {
|
||||
res = NS_NewXMLElementFactory((nsIElementFactory**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewXMLElementFactory", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kTextEncoderCID)) {
|
||||
res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewTextEncoder", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLCopyTextEncoderCID)) {
|
||||
res = NS_NewHTMLCopyTextEncoder((nsIDocumentEncoder**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLCopyTextEncoder", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kXMLContentSerializerCID)) {
|
||||
res = NS_NewXMLContentSerializer((nsIContentSerializer**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewXMLContentSerializer", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kHTMLContentSerializerCID)) {
|
||||
res = NS_NewHTMLContentSerializer((nsIContentSerializer**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewHTMLContentSerializer", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kPlainTextSerializerCID)) {
|
||||
res = NS_NewPlainTextSerializer((nsIContentSerializer**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewPlainTextSerializer", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kXBLServiceCID)) {
|
||||
res = NS_NewXBLService((nsIXBLService**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewXBLService", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kBindingManagerCID)) {
|
||||
res = NS_NewBindingManager((nsIBindingManager**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewBindingManager", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kNodeInfoManagerCID)) {
|
||||
res = NS_NewNodeInfoManager((nsINodeInfoManager**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewNodeInfoManager", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kDOMImplementationCID)) {
|
||||
res = NS_NewDOMImplementation((nsIDOMDOMImplementation**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewDOMImplementation", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kDocumentViewerCID)) {
|
||||
res = NS_NewDocumentViewer((nsIDocumentViewer**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewDocumentViewer", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kContentPolicyCID)) {
|
||||
res = NS_NewContentPolicy((nsIContentPolicy**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewContentPolicy", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kComputedDOMStyleCID)) {
|
||||
res = NS_NewComputedDOMStyle((nsIComputedDOMStyle**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
LOG_NEW_FAILURE("NS_NewComputedDOMStyle", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
NS_RELEASE(inst);
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
// We didn't get the right interface, so clean up
|
||||
LOG_NEW_FAILURE("final QueryInterface", res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsContentFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
431
content/build/nsContentModule.cpp
Normal file
431
content/build/nsContentModule.cpp
Normal file
@ -0,0 +1,431 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
#include "nspr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsContentModule.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsICSSLoader.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsCSSKeywords.h" // to addref/release table
|
||||
#include "nsCSSProps.h" // to addref/release table
|
||||
#include "nsCSSAtoms.h" // to addref/release table
|
||||
#include "nsColorNames.h" // to addref/release table
|
||||
#include "nsLayoutAtoms.h"
|
||||
#include "nsDOMCID.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIScriptNameSetRegistry.h"
|
||||
#include "nsIScriptNameSpaceManager.h"
|
||||
#include "nsIScriptExternalNameSet.h"
|
||||
|
||||
#include "nsINodeInfo.h"
|
||||
|
||||
#include "nsIElementFactory.h"
|
||||
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsIContentSerializer.h"
|
||||
#include "nsIHTMLToTextSink.h"
|
||||
|
||||
// XXX
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsRange.h"
|
||||
#include "nsGenericElement.h"
|
||||
#include "nsIHTTPProtocolHandler.h"
|
||||
#include "gbdate.h"
|
||||
#include "nsContentPolicyUtils.h"
|
||||
#define PRODUCT_NAME "Gecko"
|
||||
|
||||
static NS_DEFINE_CID(kHTTPHandlerCID, NS_IHTTPHANDLER_CID);
|
||||
static nsContentModule *gModule = NULL;
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFile* location,
|
||||
nsIModule** return_cobj)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(return_cobj, "Null argument");
|
||||
NS_ASSERTION(gModule == NULL, "nsContentModule: Module already created.");
|
||||
|
||||
// Create an initialize the Content module instance
|
||||
nsContentModule *m = new nsContentModule();
|
||||
if (!m) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
||||
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete m;
|
||||
m = nsnull;
|
||||
}
|
||||
gModule = m; // WARNING: Weak Reference
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID);
|
||||
|
||||
class ContentScriptNameSet : public nsIScriptExternalNameSet {
|
||||
public:
|
||||
ContentScriptNameSet();
|
||||
virtual ~ContentScriptNameSet();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext);
|
||||
NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext);
|
||||
};
|
||||
|
||||
ContentScriptNameSet::ContentScriptNameSet()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
ContentScriptNameSet::~ContentScriptNameSet()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ContentScriptNameSet, NS_GET_IID(nsIScriptExternalNameSet));
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentScriptNameSet::InitializeClasses(nsIScriptContext* aScriptContext)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentScriptNameSet::AddNameSet(nsIScriptContext* aScriptContext)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsIScriptNameSpaceManager* manager;
|
||||
static NS_DEFINE_IID(kHTMLImageElementCID, NS_HTMLIMAGEELEMENT_CID);
|
||||
static NS_DEFINE_IID(kHTMLOptionElementCID, NS_HTMLOPTIONELEMENT_CID);
|
||||
|
||||
result = aScriptContext->GetNameSpaceManager(&manager);
|
||||
if (NS_OK == result) {
|
||||
result = manager->RegisterGlobalName(NS_ConvertToString("HTMLImageElement"),
|
||||
NS_GET_IID(nsIScriptObjectOwner),
|
||||
kHTMLImageElementCID,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(manager);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = manager->RegisterGlobalName(NS_ConvertToString("HTMLOptionElement"),
|
||||
NS_GET_IID(nsIScriptObjectOwner),
|
||||
kHTMLOptionElementCID,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(manager);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_RELEASE(manager);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
nsIScriptNameSetRegistry* nsContentModule::gRegistry;
|
||||
nsICSSStyleSheet* nsContentModule::gUAStyleSheet = nsnull;
|
||||
|
||||
nsContentModule::nsContentModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsContentModule::~nsContentModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsContentModule, NS_GET_IID(nsIModule))
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsContentModule::Initialize()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mInitialized = PR_TRUE;
|
||||
|
||||
// Register all of our atoms once
|
||||
nsCSSAtoms::AddRefAtoms();
|
||||
nsCSSKeywords::AddRefTable();
|
||||
nsCSSProps::AddRefTable();
|
||||
nsColorNames::AddRefTable();
|
||||
nsHTMLAtoms::AddRefAtoms();
|
||||
nsLayoutAtoms::AddRefAtoms();
|
||||
|
||||
// XXX Initialize the script name set thingy-ma-jigger
|
||||
if (!gRegistry) {
|
||||
rv = nsServiceManager::GetService(kCScriptNameSetRegistryCID,
|
||||
NS_GET_IID(nsIScriptNameSetRegistry),
|
||||
(nsISupports**) &gRegistry);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
ContentScriptNameSet* nameSet = new ContentScriptNameSet();
|
||||
gRegistry->AddExternalNameSet(nameSet);
|
||||
}
|
||||
}
|
||||
|
||||
SetUserAgent();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsContentModule::Shutdown()
|
||||
{
|
||||
if (!mInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsRange::Shutdown();
|
||||
nsGenericElement::Shutdown();
|
||||
|
||||
// Release all of our atoms
|
||||
nsColorNames::ReleaseTable();
|
||||
nsCSSProps::ReleaseTable();
|
||||
nsCSSKeywords::ReleaseTable();
|
||||
nsCSSAtoms::ReleaseAtoms();
|
||||
nsHTMLAtoms::ReleaseAtoms();
|
||||
nsLayoutAtoms::ReleaseAtoms();
|
||||
|
||||
NS_IF_RELEASE(gRegistry);
|
||||
NS_IF_RELEASE(gUAStyleSheet);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (!mInitialized) {
|
||||
rv = Initialize();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFactory> f = new nsContentFactory(aClass);
|
||||
if (!f) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return f->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
struct Components {
|
||||
const char* mDescription;
|
||||
nsID mCID;
|
||||
const char* mContractID;
|
||||
};
|
||||
|
||||
// The HTML namespace.
|
||||
|
||||
// The list of components we register
|
||||
static Components gComponents[] = {
|
||||
{ "Namespace manager", NS_NAMESPACEMANAGER_CID, nsnull, },
|
||||
{ "Event listener manager", NS_EVENTLISTENERMANAGER_CID, nsnull, },
|
||||
{ "Event state manager", NS_EVENTSTATEMANAGER_CID, nsnull, },
|
||||
|
||||
{ "Document Viewer", NS_DOCUMENT_VIEWER_CID, nsnull, },
|
||||
{ "HTML Style Sheet", NS_HTMLSTYLESHEET_CID, nsnull, },
|
||||
{ "Style Set", NS_STYLESET_CID, nsnull, },
|
||||
{ "Frame Selection", NS_FRAMESELECTION_CID, nsnull, },
|
||||
{ "CSS Style Sheet", NS_CSS_STYLESHEET_CID, nsnull, },
|
||||
|
||||
{ "HTML document", NS_HTMLDOCUMENT_CID, nsnull, },
|
||||
{ "HTML-CSS style sheet", NS_HTML_CSS_STYLESHEET_CID, nsnull, },
|
||||
|
||||
{ "DOM implementation", NS_DOM_IMPLEMENTATION_CID, nsnull, },
|
||||
|
||||
{ "XML document", NS_XMLDOCUMENT_CID, nsnull, },
|
||||
{ "Image document", NS_IMAGEDOCUMENT_CID, nsnull, },
|
||||
|
||||
{ "CSS parser", NS_CSSPARSER_CID, nsnull, },
|
||||
{ "CSS loader", NS_CSS_LOADER_CID, nsnull, },
|
||||
|
||||
{ "HTML element factory", NS_HTML_ELEMENT_FACTORY_CID, NS_HTML_ELEMENT_FACTORY_CONTRACTID, },
|
||||
{ "Text element", NS_TEXTNODE_CID, nsnull, },
|
||||
|
||||
{ "Anonymous Content", NS_ANONYMOUSCONTENT_CID, nsnull, },
|
||||
|
||||
{ "Attribute Content", NS_ATTRIBUTECONTENT_CID, nsnull, },
|
||||
|
||||
{ "HTML Attributes", NS_HTMLATTRIBUTES_CID, nsnull, },
|
||||
|
||||
{ "XML element factory", NS_XML_ELEMENT_FACTORY_CID, NS_XML_ELEMENT_FACTORY_CONTRACTID, },
|
||||
|
||||
{ "Selection", NS_SELECTION_CID, nsnull, },
|
||||
{ "Dom selection", NS_DOMSELECTION_CID, nsnull, },
|
||||
{ "Frame selection", NS_FRAMESELECTION_CID, nsnull, },
|
||||
{ "Range", NS_RANGE_CID, nsnull, },
|
||||
{ "Content iterator", NS_CONTENTITERATOR_CID, nsnull, },
|
||||
{ "Generated Content iterator", NS_GENERATEDCONTENTITERATOR_CID, nsnull, },
|
||||
{ "Generated Subtree iterator", NS_GENERATEDSUBTREEITERATOR_CID, nsnull, },
|
||||
{ "Subtree iterator", NS_SUBTREEITERATOR_CID, nsnull, },
|
||||
|
||||
// XXX ick
|
||||
{ "HTML image element", NS_HTMLIMAGEELEMENT_CID, nsnull, },
|
||||
{ "HTML option element", NS_HTMLOPTIONELEMENT_CID, nsnull, },
|
||||
// XXX end ick
|
||||
|
||||
{ "XML document encoder", NS_TEXT_ENCODER_CID,
|
||||
NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", },
|
||||
{ "HTML document encoder", NS_TEXT_ENCODER_CID,
|
||||
NS_DOC_ENCODER_CONTRACTID_BASE "text/html", },
|
||||
{ "Plaintext document encoder", NS_TEXT_ENCODER_CID,
|
||||
NS_DOC_ENCODER_CONTRACTID_BASE "text/plain", },
|
||||
{ "HTML copy encoder", NS_HTMLCOPY_TEXT_ENCODER_CID,
|
||||
NS_HTMLCOPY_ENCODER_CONTRACTID, },
|
||||
{ "XML content serializer", NS_XMLCONTENTSERIALIZER_CID,
|
||||
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/xml", },
|
||||
{ "HTML content serializer", NS_HTMLCONTENTSERIALIZER_CID,
|
||||
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/html", },
|
||||
{ "XUL content serializer", NS_XMLCONTENTSERIALIZER_CID,
|
||||
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/xul", },
|
||||
{ "plaintext content serializer", NS_PLAINTEXTSERIALIZER_CID,
|
||||
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/plain", },
|
||||
{ "plaintext sink", NS_PLAINTEXTSERIALIZER_CID,
|
||||
NS_PLAINTEXTSINK_CONTRACTID, },
|
||||
|
||||
{ "XBL Service", NS_XBLSERVICE_CID, "@mozilla.org/xbl;1" },
|
||||
{ "XBL Binding Manager", NS_BINDINGMANAGER_CID, "@mozilla.org/xbl/binding-manager;1" },
|
||||
|
||||
{ "Content policy service", NS_CONTENTPOLICY_CID, NS_CONTENTPOLICY_CONTRACTID },
|
||||
{ "NodeInfoManager", NS_NODEINFOMANAGER_CID, NS_NODEINFOMANAGER_CONTRACTID },
|
||||
{ "DOM CSS Computed Style Declaration", NS_COMPUTEDDOMSTYLE_CID,
|
||||
"@mozilla.org/DOM/Level2/CSS/computedStyleDeclaration;1" }
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFile* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering content components\n");
|
||||
#endif
|
||||
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
rv = aCompMgr->RegisterComponentSpec(cp->mCID, cp->mDescription,
|
||||
cp->mContractID, aPath, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsContentModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
rv = RegisterDocumentFactories(aCompMgr, aPath);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering content components\n");
|
||||
#endif
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end) {
|
||||
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsContentModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
UnregisterDocumentFactories(aCompMgr, aPath);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
void
|
||||
nsContentModule::SetUserAgent( void )
|
||||
{
|
||||
nsString productName; productName.AssignWithConversion(PRODUCT_NAME);
|
||||
nsString productVersion; productVersion.AssignWithConversion(PRODUCT_VERSION);
|
||||
nsresult rv = nsnull;
|
||||
|
||||
nsCOMPtr<nsIHTTPProtocolHandler> theService(do_GetService(kHTTPHandlerCID,
|
||||
&rv));
|
||||
|
||||
if( NS_SUCCEEDED(rv) && (nsnull != theService) )
|
||||
{
|
||||
rv = theService->SetProduct(productName.GetUnicode());
|
||||
|
||||
rv = theService->SetProductSub(productVersion.GetUnicode());
|
||||
}
|
||||
}
|
80
content/build/nsContentModule.h
Normal file
80
content/build/nsContentModule.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#ifndef nsContentModule_h___
|
||||
#define nsContentModule_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
class nsICSSStyleSheet;
|
||||
class nsIScriptNameSetRegistry;
|
||||
|
||||
// Module implementation for the content library
|
||||
class nsContentModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
nsContentModule();
|
||||
virtual ~nsContentModule();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
nsresult Initialize();
|
||||
|
||||
protected:
|
||||
void Shutdown();
|
||||
|
||||
nsresult RegisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath);
|
||||
|
||||
void UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath);
|
||||
|
||||
void SetUserAgent();
|
||||
|
||||
PRBool mInitialized;
|
||||
// static nsIFactory* gFactory;
|
||||
static nsIScriptNameSetRegistry* gRegistry;
|
||||
|
||||
public:
|
||||
static nsICSSStyleSheet* gUAStyleSheet;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsContentFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
nsContentFactory(const nsCID &aClass);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIFACTORY
|
||||
|
||||
protected:
|
||||
virtual ~nsContentFactory();
|
||||
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
#endif /* nsContentModule_h___ */
|
172
content/xul/content/src/nsAnonymousElement.cpp
Normal file
172
content/xul/content/src/nsAnonymousElement.cpp
Normal file
@ -0,0 +1,172 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
//
|
||||
// Eric Vaughan
|
||||
// Netscape Communications
|
||||
//
|
||||
// See documentation in associated header file
|
||||
//
|
||||
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsXMLElement.h"
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsIAnonymousContent.h"
|
||||
#include "nsINodeInfo.h"
|
||||
|
||||
class AnonymousElement : public nsXMLElement, public nsIAnonymousContent
|
||||
{
|
||||
public:
|
||||
AnonymousElement() {}
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus* aEventStatus);
|
||||
|
||||
NS_IMETHOD Init(nsINodeInfo *aInfo);
|
||||
};
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP
|
||||
AnonymousElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const {
|
||||
return this->nsXMLElement::SizeOf(aSizer, aResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
AnonymousElement::Init(nsINodeInfo *aInfo)
|
||||
{
|
||||
return nsXMLElement::Init(aInfo);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AnonymousElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus* aEventStatus)
|
||||
{
|
||||
/*
|
||||
// if our parent is not anonymous then we don't want to bubble the event
|
||||
// so lets set our parent in nsnull to prevent it. Then we will set it
|
||||
// back.
|
||||
nsIContent* parent = nsnull;
|
||||
GetParent(parent);
|
||||
|
||||
nsCOMPtr<nsIAnonymousContent> anonymousParent(do_QueryInterface(parent));
|
||||
|
||||
|
||||
if (!anonymousParent)
|
||||
SetParent(nsnull);
|
||||
*/
|
||||
|
||||
nsresult rv = nsXMLElement::HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
||||
aFlags, aEventStatus);
|
||||
|
||||
/*
|
||||
if (!anonymousParent)
|
||||
SetParent(parent);
|
||||
*/
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(AnonymousElement, nsXMLElement)
|
||||
NS_IMPL_RELEASE_INHERITED(AnonymousElement, nsXMLElement)
|
||||
|
||||
//
|
||||
// QueryInterface
|
||||
//
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(AnonymousElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIAnonymousContent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsXMLElement)
|
||||
|
||||
|
||||
nsresult NS_CreateAnonymousNode(nsIContent* aParent, nsIAtom* aTag, PRInt32 aNameSpaceId, nsCOMPtr<nsIContent>& aNewNode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aParent);
|
||||
|
||||
// create the xml element
|
||||
//NS_NewXMLElement(getter_AddRefs(content), aTag);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
aParent->GetDocument(*getter_AddRefs(doc));
|
||||
|
||||
nsCOMPtr<nsINodeInfoManager> nodeInfoManager;
|
||||
doc->GetNodeInfoManager(*getter_AddRefs(nodeInfoManager));
|
||||
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo;
|
||||
nodeInfoManager->GetNodeInfo(aTag, nsnull, aNameSpaceId,
|
||||
*getter_AddRefs(nodeInfo));
|
||||
|
||||
nsXMLElement *content = new AnonymousElement();
|
||||
|
||||
if (!content)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = content->Init(nodeInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
delete content;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
aNewNode = content;
|
||||
|
||||
/*
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
aParent->GetDocument(*getter_AddRefs(document));
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(document));
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
nsString name;
|
||||
aTag->ToString(name);
|
||||
domDocument->CreateElement(name, getter_AddRefs(element));
|
||||
aNewNode = do_QueryInterface(element);
|
||||
*/
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult NS_NewAnonymousContent2(nsIContent **aNewNode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aNewNode);
|
||||
*aNewNode = nsnull;
|
||||
|
||||
nsIContent *content = new AnonymousElement();
|
||||
|
||||
if (!content)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(content);
|
||||
nsresult rv = content->QueryInterface(NS_GET_IID(nsIContent),(void**)aNewNode);
|
||||
NS_RELEASE(content);
|
||||
|
||||
return rv;
|
||||
}
|
556
layout/build/nsContentDLF.cpp
Normal file
556
layout/build/nsContentDLF.cpp
Normal file
@ -0,0 +1,556 @@
|
||||
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsContentModule.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIDocumentLoaderFactory.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsString.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "prprf.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsICSSLoader.h"
|
||||
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIXULContentSink.h"
|
||||
#include "nsIStreamLoadableDocument.h"
|
||||
#include "nsIDocStreamLoaderFactory.h"
|
||||
|
||||
#define VIEW_SOURCE_HTML
|
||||
|
||||
// URL for the "user agent" style sheet
|
||||
#define UA_CSS_URL "resource:/res/ua.css"
|
||||
|
||||
// Factory code for creating variations on html documents
|
||||
|
||||
#undef NOISY_REGISTRY
|
||||
|
||||
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
||||
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
|
||||
|
||||
extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult);
|
||||
|
||||
static char* gHTMLTypes[] = {
|
||||
"text/html",
|
||||
"text/plain",
|
||||
"text/rtf",
|
||||
"text/cpp",
|
||||
"text/css",
|
||||
0
|
||||
};
|
||||
|
||||
static char* gXMLTypes[] = {
|
||||
"text/xml",
|
||||
"application/xml",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
static char* gRDFTypes[] = {
|
||||
"text/rdf",
|
||||
"text/xul",
|
||||
"text/cached-xul",
|
||||
0
|
||||
};
|
||||
|
||||
static char* gImageTypes[] = {
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/x-png",
|
||||
"image/x-art",
|
||||
"image/x-jg",
|
||||
0
|
||||
};
|
||||
|
||||
class nsContentDLF : public nsIDocumentLoaderFactory,
|
||||
public nsIDocStreamLoaderFactory
|
||||
{
|
||||
public:
|
||||
nsContentDLF();
|
||||
virtual ~nsContentDLF();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// for nsIDocumentLoaderFactory
|
||||
NS_IMETHOD CreateInstance(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
|
||||
nsIDocument* aDocument,
|
||||
const char *aCommand,
|
||||
nsIContentViewer** aDocViewerResult);
|
||||
|
||||
// for nsIDocStreamLoaderFactory
|
||||
NS_METHOD CreateInstance(nsIInputStream& aInputStream,
|
||||
const char* aContentType,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult InitUAStyleSheet();
|
||||
|
||||
nsresult CreateDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsISupports* aContainer,
|
||||
const nsCID& aDocumentCID,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult CreateRDFDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult CreateXULDocumentFromStream(nsIInputStream& aXULStream,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer);
|
||||
|
||||
nsresult CreateRDFDocument(nsISupports*,
|
||||
nsCOMPtr<nsIDocument>*,
|
||||
nsCOMPtr<nsIDocumentViewer>*);
|
||||
|
||||
static nsICSSStyleSheet* GetUAStyleSheet() {
|
||||
return nsContentModule::gUAStyleSheet;
|
||||
}
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult, "null OUT ptr");
|
||||
if (!aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsContentDLF* it = new nsContentDLF();
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(NS_GET_IID(nsIDocumentLoaderFactory), (void**)aResult);
|
||||
}
|
||||
|
||||
nsContentDLF::nsContentDLF()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsContentDLF::~nsContentDLF()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsContentDLF)
|
||||
NS_IMPL_RELEASE(nsContentDLF)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(NS_GET_IID(nsIDocumentLoaderFactory))) {
|
||||
nsIDocumentLoaderFactory *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsIDocStreamLoaderFactory))) {
|
||||
nsIDocStreamLoaderFactory *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDocumentLoaderFactory *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::CreateInstance(const char *aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (!GetUAStyleSheet()) {
|
||||
// Load the UA style sheet
|
||||
nsCOMPtr<nsIURI> uaURL;
|
||||
rv = NS_NewURI(getter_AddRefs(uaURL), UA_CSS_URL);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsICSSLoader> cssLoader;
|
||||
rv = NS_NewCSSLoader(getter_AddRefs(cssLoader));
|
||||
if (cssLoader) {
|
||||
PRBool complete;
|
||||
rv = cssLoader->LoadAgentSheet(uaURL, nsContentModule::gUAStyleSheet, complete,
|
||||
nsnull);
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv);
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if(0==PL_strcmp(aCommand,"view-source")) {
|
||||
#ifdef VIEW_SOURCE_HTML
|
||||
aContentType=gHTMLTypes[0];
|
||||
#else
|
||||
if(0==PL_strcmp(aContentType,gHTMLTypes[1])) {
|
||||
aContentType=gHTMLTypes[0];
|
||||
}
|
||||
else if(0==PL_strcmp(aContentType,gHTMLTypes[2])) {
|
||||
aContentType=gHTMLTypes[0];
|
||||
}
|
||||
else
|
||||
aContentType=gXMLTypes[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
// Try html
|
||||
int typeIndex=0;
|
||||
while(gHTMLTypes[typeIndex]) {
|
||||
if (0== PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
|
||||
return CreateDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContainer, kHTMLDocumentCID,
|
||||
aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// Try XML
|
||||
typeIndex = 0;
|
||||
while(gXMLTypes[typeIndex]) {
|
||||
if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
|
||||
return CreateDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContainer, kXMLDocumentCID,
|
||||
aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// Try RDF
|
||||
typeIndex = 0;
|
||||
while (gRDFTypes[typeIndex]) {
|
||||
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
|
||||
return CreateRDFDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContentType, aContainer,
|
||||
aExtraInfo, aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// Try image types
|
||||
typeIndex = 0;
|
||||
while(gImageTypes[typeIndex]) {
|
||||
if (0== PL_strcmp(gImageTypes[typeIndex++], aContentType)) {
|
||||
return CreateDocument(aCommand,
|
||||
aChannel, aLoadGroup,
|
||||
aContainer, kImageDocumentCID,
|
||||
aDocListener, aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, then we weren't able to create anything. Sorry!
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
|
||||
nsIDocument* aDocument,
|
||||
const char *aCommand,
|
||||
nsIContentViewer** aDocViewerResult)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
do {
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
// Create the document viewer
|
||||
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
docv->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
|
||||
|
||||
// Bind the document to the Content Viewer
|
||||
rv = docv->BindToDocument(aDocument, aCommand);
|
||||
*aDocViewerResult = docv;
|
||||
NS_IF_ADDREF(*aDocViewerResult);
|
||||
} while (PR_FALSE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsContentDLF::CreateDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsISupports* aContainer,
|
||||
const nsCID& aDocumentCID,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIURI> aURL;
|
||||
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#ifdef NOISY_CREATE_DOC
|
||||
if (nsnull != aURL) {
|
||||
nsAutoString tmp;
|
||||
aURL->ToString(tmp);
|
||||
fputs(tmp, stdout);
|
||||
printf(": creating document\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
do {
|
||||
// Create the document
|
||||
rv = nsComponentManager::CreateInstance(aDocumentCID, nsnull,
|
||||
NS_GET_IID(nsIDocument),
|
||||
getter_AddRefs(doc));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
// Create the document viewer XXX: could reuse document viewer here!
|
||||
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
docv->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
|
||||
|
||||
// Initialize the document to begin loading the data. An
|
||||
// nsIStreamListener connected to the parser is returned in
|
||||
// aDocListener.
|
||||
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
// Bind the document to the Content Viewer
|
||||
rv = docv->BindToDocument(doc, aCommand);
|
||||
*aDocViewer = docv;
|
||||
NS_IF_ADDREF(*aDocViewer);
|
||||
} while (PR_FALSE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::CreateInstance(nsIInputStream& aInputStream,
|
||||
const char* aContentType,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer)
|
||||
|
||||
{
|
||||
nsresult status = NS_ERROR_FAILURE;
|
||||
|
||||
// Try RDF
|
||||
int typeIndex = 0;
|
||||
while (gRDFTypes[typeIndex]) {
|
||||
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
|
||||
return CreateXULDocumentFromStream(aInputStream,
|
||||
aCommand,
|
||||
aContainer,
|
||||
aExtraInfo,
|
||||
aDocViewer);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// ...common work for |CreateRDFDocument| and |CreateXULDocumentFromStream|
|
||||
nsresult
|
||||
nsContentDLF::CreateRDFDocument(nsISupports* aExtraInfo,
|
||||
nsCOMPtr<nsIDocument>* doc,
|
||||
nsCOMPtr<nsIDocumentViewer>* docv)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// Create the XUL document
|
||||
rv = nsComponentManager::CreateInstance(kXULDocumentCID, nsnull,
|
||||
NS_GET_IID(nsIDocument),
|
||||
getter_AddRefs(*doc));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create the image content viewer...
|
||||
rv = NS_NewDocumentViewer(getter_AddRefs(*docv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Load the UA style sheet if we haven't already done that
|
||||
(*docv)->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// ...note, this RDF document _may_ be XUL :-)
|
||||
nsresult
|
||||
nsContentDLF::CreateRDFDocument(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
const char* aContentType,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIStreamListener** aDocListener,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
nsresult rv = CreateRDFDocument(aExtraInfo, address_of(doc), address_of(docv));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> aURL;
|
||||
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
/*
|
||||
* Initialize the document to begin loading the data...
|
||||
*
|
||||
* An nsIStreamListener connected to the parser is returned in
|
||||
* aDocListener.
|
||||
*/
|
||||
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
/*
|
||||
* Bind the document to the Content Viewer...
|
||||
*/
|
||||
rv = docv->BindToDocument(doc, aCommand);
|
||||
*aDocViewer = docv;
|
||||
NS_IF_ADDREF(*aDocViewer);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsContentDLF::CreateXULDocumentFromStream(nsIInputStream& aXULStream,
|
||||
const char* aCommand,
|
||||
nsISupports* aContainer,
|
||||
nsISupports* aExtraInfo,
|
||||
nsIContentViewer** aDocViewer)
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
|
||||
do
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIDocumentViewer> docv;
|
||||
if ( NS_FAILED(status = CreateRDFDocument(aExtraInfo, address_of(doc), address_of(docv))) )
|
||||
break;
|
||||
|
||||
if ( NS_FAILED(status = docv->BindToDocument(doc, aCommand)) )
|
||||
break;
|
||||
|
||||
*aDocViewer = docv;
|
||||
NS_IF_ADDREF(*aDocViewer);
|
||||
|
||||
nsCOMPtr<nsIStreamLoadableDocument> loader = do_QueryInterface(doc, &status);
|
||||
if ( NS_FAILED(status) )
|
||||
break;
|
||||
|
||||
status = loader->LoadFromStream(aXULStream, aContainer, aCommand);
|
||||
}
|
||||
while (0);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
|
||||
|
||||
static nsresult
|
||||
RegisterTypes(nsIComponentManager* aCompMgr,
|
||||
const char* aCommand,
|
||||
nsIFile* aPath,
|
||||
char** aTypes)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
while (*aTypes) {
|
||||
char contractid[500];
|
||||
char* contentType = *aTypes++;
|
||||
PR_snprintf(contractid, sizeof(contractid),
|
||||
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "%s;1?type=%s",
|
||||
aCommand, contentType);
|
||||
#ifdef NOISY_REGISTRY
|
||||
printf("Register %s => %s\n", contractid, aPath);
|
||||
#endif
|
||||
rv = aCompMgr->RegisterComponentSpec(kDocumentFactoryImplCID, "Content",
|
||||
contractid, aPath, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsContentModule::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath)
|
||||
{
|
||||
// We do not register view or view-source document factories because
|
||||
// that is for layout. Now load-as-data might be a different story...
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsContentModule::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath)
|
||||
{
|
||||
aCompMgr->UnregisterComponentSpec(kDocumentFactoryImplCID, aPath);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user