More appCore killing. bug=46200, r=ben, a=alecf

This commit is contained in:
disttsc%bart.nl 2001-01-19 01:19:07 +00:00
Родитель 3806e2973b
Коммит 6c87329333
5 изменённых файлов: 36 добавлений и 187 удалений

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

@ -38,12 +38,8 @@ interface nsIBrowserInstance : nsISupports {
// Infrastructure.
void init();
void getContentDocShell(out nsIDocShell aDocShell);
void getContentDocShell(out nsIDocShell aDocShell);
void setWebShellWindow( in nsIDOMWindowInternal aWindow );
void SetDocumentCharset(in wstring charset);
wstring GetDocumentCharset();
void SetForcedCharset(in wstring charset);
void SetForcedDetector();
attribute nsIUrlbarHistory urlbarHistory;
attribute nsIInputStream postData;

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

@ -451,7 +451,7 @@ function Startup()
var arrayArgComponents = window.arguments[1].split("=");
if (arrayArgComponents) {
//we should "inherit" the charset menu setting in a new window
appCore.SetDocumentCharset(arrayArgComponents[1]);
BrowserSetDefaultCharacterSet(arrayArgComponents[1]);
}
}
}
@ -807,8 +807,7 @@ function BrowserEditBookmarks()
function BrowserPrintPreview()
{
// this is currently a do-nothing on appCore which is going to die
// ???.printPreview();
// implement me
}
function BrowserPrint()
@ -819,18 +818,21 @@ function BrowserPrint()
function BrowserSetDefaultCharacterSet(aCharset)
{
appCore.SetDocumentCharset(aCharset);
getMarkupDocumentViewer().defaultCharacterSet = aCharset;
getWebNavigation().reload(nsIWebNavigation.LOAD_FLAGS_NONE);
}
function BrowserSetForcedCharacterSet(aCharset)
{
appCore.SetForcedCharset(aCharset);
var charsetConverterManager = Components.classes["@mozilla.org/charset-converter-manager;1"]
.getService(Components.interfaces.nsICharsetConverterManager2);
var characterSet = charsetConverterManager.GetCharsetAtom(aCharset);
getBrowser().documentCharsetInfo.forcedCharset = characterSet;
}
function BrowserSetForcedDetector()
{
appCore.SetForcedDetector();
getBrowser().documentCharsetInfo.forcedDetector = true;
}
function BrowserClose()
@ -1126,11 +1128,7 @@ function checkForDirectoryListing()
if ("HTTPIndex" in _content &&
typeof _content.HTTPIndex == "object" &&
!_content.HTTPIndex.constructor) {
// Give directory .xul/.js access to browser instance.
// XXX The following line leaks (bug 61821), so the next line is a hack
// to avoid the leak.
// _content.defaultCharacterset = getBrowser().markupDocumentViewer.defaultCharacterSet;
_content.defaultCharacterset = getBrowser().docShell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer).defaultCharacterSet;
_content.defaultCharacterset = getMarkupDocumentViewer().defaultCharacterSet;
_content.parentWindow = window;
}
}

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

@ -27,6 +27,8 @@
<broadcasterset id="broadcasterset"/>
<stringbundleset id="stringbundleset"/>
<commands id="commands">
<commandset id="globalEditMenuItems"/>
<commandset id="selectEditMenuItems"/>
@ -44,7 +46,7 @@
ondraggesture="nsDragAndDrop.startDrag(event, contentAreaDNDObserver);"
ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);">
<iframe id="content-frame" type="content-primary" name="content" src="about:blank" flex="1"/>
<browser id="content" type="content-primary" name="content" src="about:blank" flex="1"/>
</box>

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

@ -1,7 +1,6 @@
var appCore = null;
function onLoadViewSource()
{
viewSource(window.arguments[0]);
@ -11,57 +10,49 @@ function viewSource(url)
{
if (!url)
return false; // throw Components.results.NS_ERROR_FAILURE;
try {
createBrowserInstance();
if (appCore == null) {
// Give up.
window.close();
return false;
}
appCore = Components.classes["@mozilla.org/appshell/component/browser/instance;1"]
.createInstance(Components.interfaces.nsIBrowserInstance);
// Initialize browser instance..
appCore.setWebShellWindow(window);
} catch(ex) {
// Give up.
window.close();
return false;
}
catch(ex) {
}
var docShellElement = document.getElementById("content-frame");
var docShell = docShellElement.docShell;
docShell.viewMode = Components.interfaces.nsIDocShell.viewSource;
var webNav = docShell.QueryInterface(Components.interfaces.nsIWebNavigation);
var docShellElement = document.getElementById("content");
docShellElement.docShell.viewMode = Components.interfaces.nsIDocShell.viewSource;
try {
if (window.arguments && window.arguments[1]) {
if (window.arguments[1].indexOf('charset=') != -1) {
var arrayArgComponents = window.arguments[1].split('=');
if (arrayArgComponents) {
appCore.SetDocumentCharset(arrayArgComponents[1]);
}
}
if ("arguments" in window && window.arguments.length >= 2) {
if (window.arguments[1].indexOf('charset=') != -1) {
var arrayArgComponents = window.arguments[1].split('=');
if (arrayArgComponents) {
docShellElement.markupDocumentViewer.defaultCharacterSet = arrayArgComponents[1];
}
}
}
catch(ex) {
}
} catch(ex) {
}
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
webNav.loadURI(url, loadFlags);
docShellElement.webNavigation.loadURI(url, loadFlags);
return true;
}
function createBrowserInstance()
{
appCore = Components
.classes[ "@mozilla.org/appshell/component/browser/instance;1" ]
.createInstance( Components.interfaces.nsIBrowserInstance );
}
function BrowserClose()
{
window.close();
}
function getMarkupDocumentViewer()
{
return document.getElementById("content").markupDocumentViewer;
}
function BrowserFind()
{
if (appCore)

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

@ -792,144 +792,6 @@ nsBrowserInstance::SetWebShellWindow(nsIDOMWindowInternal* aWin)
return NS_OK;
}
NS_IMETHODIMP
nsBrowserInstance::GetDocumentCharset(PRUnichar **aCharset)
{
nsCOMPtr<nsIDOMWindowInternal> contentWindow;
GetContentWindow(getter_AddRefs(contentWindow));
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(contentWindow));
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
if (docShell)
{
nsCOMPtr<nsIContentViewer> childCV;
NS_ENSURE_SUCCESS(docShell->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
// This allocates a new buffer
NS_ENSURE_SUCCESS(markupCV->GetDefaultCharacterSet(aCharset), NS_ERROR_FAILURE);
}
}
}
if (!*aCharset) {
nsAutoString blank;
*aCharset = blank.ToNewUnicode();
}
return NS_OK;
}
NS_IMETHODIMP
nsBrowserInstance::SetDocumentCharset(const PRUnichar *aCharset)
{
nsCOMPtr<nsIDOMWindowInternal> contentWindow;
GetContentWindow(getter_AddRefs(contentWindow));
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(contentWindow));
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
if (docShell)
{
nsCOMPtr<nsIContentViewer> childCV;
NS_ENSURE_SUCCESS(docShell->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
NS_ENSURE_SUCCESS(markupCV->SetDefaultCharacterSet(aCharset), NS_ERROR_FAILURE);
}
}
}
return NS_OK;
}
// XXX isolate the common code in the next two methods into a common method
NS_IMETHODIMP
nsBrowserInstance::SetForcedCharset(const PRUnichar * aCharset)
{
nsCOMPtr<nsIDOMWindowInternal> contentWindow;
GetContentWindow(getter_AddRefs(contentWindow));
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(contentWindow));
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
if (!docShell) return NS_OK;
nsresult res = NS_OK;
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo = NULL;
res = docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
if (dcInfo.get() == NULL) {
res = nsComponentManager::CreateInstance(kDocumentCharsetInfoCID, NULL,
NS_GET_IID(nsIDocumentCharsetInfo), getter_AddRefs(dcInfo));
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
res = docShell->SetDocumentCharsetInfo(dcInfo);
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
}
NS_WITH_SERVICE(nsICharsetConverterManager2, ccMan, kCharsetConverterManagerCID, &res);
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
nsCOMPtr<nsIAtom> csAtom;
res = ccMan->GetCharsetAtom(aCharset, getter_AddRefs(csAtom));
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
res = dcInfo->SetForcedCharset(csAtom);
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsBrowserInstance::SetForcedDetector()
{
nsCOMPtr<nsIDOMWindowInternal> contentWindow;
GetContentWindow(getter_AddRefs(contentWindow));
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(contentWindow));
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
if (!docShell) return NS_OK;
nsresult res = NS_OK;
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo = NULL;
res = docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
if (dcInfo.get() == NULL) {
res = nsComponentManager::CreateInstance(kDocumentCharsetInfoCID, NULL,
NS_GET_IID(nsIDocumentCharsetInfo), getter_AddRefs(dcInfo));
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
res = docShell->SetDocumentCharsetInfo(dcInfo);
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
}
res = dcInfo->SetForcedDetector(PR_TRUE);
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsBrowserInstance::Close()
{