mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-30 01:59:29 +00:00
Throb, baby, throb
This commit is contained in:
parent
53ac660970
commit
3af600d45f
@ -60,18 +60,14 @@ static NS_DEFINE_IID(kBrowserAppCoreCID, NS_BROWSERAPPCORE_CID);
|
||||
|
||||
/* Define Interface IDs */
|
||||
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIBrowserAppCoreIID, NS_IDOMBROWSERAPPCORE_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDOMDocumentIID, nsIDOMDocument::GetIID());
|
||||
static NS_DEFINE_IID(kIDocumentIID, nsIDocument::GetIID());
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
|
||||
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
|
||||
static NS_DEFINE_IID(kIURLListenerIID, NS_IURL_LISTENER_IID);
|
||||
|
||||
#define APP_DEBUG 0
|
||||
|
||||
@ -90,6 +86,7 @@ nsBrowserAppCore::nsBrowserAppCore()
|
||||
mContentScriptContext = nsnull;
|
||||
mWebShellWin = nsnull;
|
||||
mWebShell = nsnull;
|
||||
mContentAreaWebShell = nsnull;
|
||||
|
||||
IncInstanceCount();
|
||||
NS_INIT_REFCNT();
|
||||
@ -103,6 +100,7 @@ nsBrowserAppCore::~nsBrowserAppCore()
|
||||
NS_IF_RELEASE(mContentScriptContext);
|
||||
NS_IF_RELEASE(mWebShellWin);
|
||||
NS_IF_RELEASE(mWebShell);
|
||||
NS_IF_RELEASE(mContentAreaWebShell);
|
||||
DecInstanceCount();
|
||||
}
|
||||
|
||||
@ -136,6 +134,11 @@ nsBrowserAppCore::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIURLListenerIID)) {
|
||||
*aInstancePtr = (void*) ((nsIURLListener*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
return nsBaseAppCore::QueryInterface(aIID, aInstancePtr);
|
||||
@ -227,6 +230,17 @@ nsBrowserAppCore::SetEnableCallback(const nsString& aScript)
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::LoadUrl(const nsString& aUrl)
|
||||
{
|
||||
char * urlstr = nsnull;
|
||||
urlstr = aUrl.ToNewCString();
|
||||
|
||||
if (!urlstr)
|
||||
return NS_OK;
|
||||
|
||||
printf("URL to load in nsBrowserAppCore is %s\n", urlstr);
|
||||
|
||||
/* Ask nsWebShell to load the URl */
|
||||
mContentAreaWebShell->LoadURL(nsString(urlstr), nsnull, nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -254,13 +268,19 @@ nsBrowserAppCore::SetContentWindow(nsIDOMWindow* aWin)
|
||||
nsIWebShell * webShell;
|
||||
globalObj->GetWebShell(&webShell);
|
||||
if (nsnull != webShell) {
|
||||
mContentAreaWebShell = webShell;
|
||||
NS_ADDREF(webShell);
|
||||
webShell->SetObserver(this);
|
||||
const PRUnichar * name;
|
||||
webShell->GetName( &name);
|
||||
nsAutoString str(name);
|
||||
|
||||
if (APP_DEBUG) printf("Attaching to Content WebShell [%s]\n", str.ToNewCString()); // this leaks
|
||||
NS_RELEASE(webShell);
|
||||
if (APP_DEBUG) {
|
||||
char *name = str.ToNewCString();
|
||||
printf("Attaching to Content WebShell [%s]\n", name);
|
||||
delete [] name;
|
||||
}
|
||||
mContentAreaWebShell->SetURLListener(this);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -301,6 +321,89 @@ nsBrowserAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIURLListener methods
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL,
|
||||
nsLoadType aReason)
|
||||
{
|
||||
|
||||
// Notify the AppCore
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult setAttribute( nsIWebShell *shell,
|
||||
const char *id,
|
||||
const char *name,
|
||||
const nsString &value ) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
rv = shell->GetContentViewer(getter_AddRefs(cv));
|
||||
if ( cv ) {
|
||||
// Up-cast.
|
||||
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
||||
if ( docv ) {
|
||||
// Get the document from the doc viewer.
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
rv = docv->GetDocument(*getter_AddRefs(doc));
|
||||
if ( doc ) {
|
||||
// Up-cast.
|
||||
nsCOMPtr<nsIDOMXULDocument> xulDoc( do_QueryInterface(doc) );
|
||||
if ( xulDoc ) {
|
||||
// Find specified element.
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
rv = xulDoc->GetElementById( id, getter_AddRefs(elem) );
|
||||
if ( elem ) {
|
||||
// Set the text attribute.
|
||||
rv = elem->SetAttribute( name, value );
|
||||
if ( APP_DEBUG ) {
|
||||
char *p = value.ToNewCString();
|
||||
delete [] p;
|
||||
}
|
||||
if ( rv != NS_OK ) {
|
||||
if (APP_DEBUG) printf("SetAttribute failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetElementByID failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("Upcast to nsIDOMXULDocument failed\n");
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetDocument failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("Upcast to nsIDocumentViewer failed\n");
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetContentViewer failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
||||
{
|
||||
setAttribute( mWebShell, "Browser:Throbber", "busy", "true" );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL,
|
||||
PRInt32 aProgress, PRInt32 aProgressMax)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::EndLoadURL(nsIWebShell* aWebShell, const PRUnichar* aURL,
|
||||
PRInt32 aStatus)
|
||||
{
|
||||
setAttribute( mWebShell, "Browser:Throbber", "busy", "false" );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::NewWindow()
|
||||
{
|
||||
@ -557,57 +660,6 @@ done:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult setAttribute( nsIWebShell *shell,
|
||||
const char *id,
|
||||
const char *name,
|
||||
const nsString &value ) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
rv = shell->GetContentViewer(getter_AddRefs(cv));
|
||||
if ( cv ) {
|
||||
// Up-cast.
|
||||
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
||||
if ( docv ) {
|
||||
// Get the document from the doc viewer.
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
rv = docv->GetDocument(*getter_AddRefs(doc));
|
||||
if ( doc ) {
|
||||
// Up-cast.
|
||||
nsCOMPtr<nsIDOMXULDocument> xulDoc( do_QueryInterface(doc) );
|
||||
if ( xulDoc ) {
|
||||
// Find specified element.
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
rv = xulDoc->GetElementById( id, getter_AddRefs(elem) );
|
||||
if ( elem ) {
|
||||
// Set the text attribute.
|
||||
rv = elem->SetAttribute( name, value );
|
||||
if ( APP_DEBUG ) {
|
||||
char *p = value.ToNewCString();
|
||||
//printf( "Set %s %s=\"%s\", rv=0x%08X\n", id, name, p, (int)rv );
|
||||
delete [] p;
|
||||
}
|
||||
if ( rv != NS_OK ) {
|
||||
if (APP_DEBUG) printf("SetAttribute failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetElementByID failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("Upcast to nsIDOMXULDocument failed\n");
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetDocument failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("Upcast to nsIDocumentViewer failed\n");
|
||||
}
|
||||
} else {
|
||||
if (APP_DEBUG) printf("GetContentViewer failed, rv=0x%X\n",(int)rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::OnStartBinding(nsIURL* aURL, const char *aContentType)
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "nsBaseAppCore.h"
|
||||
#include "nsINetSupport.h"
|
||||
#include "nsIStreamObserver.h"
|
||||
#include "nsIURLListener.h"
|
||||
|
||||
class nsIBrowserWindow;
|
||||
class nsIWebShell;
|
||||
@ -36,6 +37,7 @@ class nsIDOMWindow;
|
||||
class nsIURL;
|
||||
class nsIWebShellWindow;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsBrowserAppCore:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -43,7 +45,8 @@ class nsIWebShellWindow;
|
||||
class nsBrowserAppCore : public nsBaseAppCore,
|
||||
public nsIDOMBrowserAppCore,
|
||||
public nsINetSupport,
|
||||
public nsIStreamObserver
|
||||
public nsIStreamObserver,
|
||||
public nsIURLListener
|
||||
{
|
||||
public:
|
||||
|
||||
@ -55,7 +58,6 @@ class nsBrowserAppCore : public nsBaseAppCore,
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD Init(const nsString& aId);
|
||||
NS_IMETHOD GetId(nsString& aId) { return nsBaseAppCore::GetId(aId); }
|
||||
NS_IMETHOD SetDocumentCharset(const nsString& aCharset);
|
||||
|
||||
NS_IMETHOD Back();
|
||||
NS_IMETHOD Forward();
|
||||
@ -69,7 +71,7 @@ class nsBrowserAppCore : public nsBaseAppCore,
|
||||
NS_IMETHOD PrintPreview();
|
||||
NS_IMETHOD Close();
|
||||
NS_IMETHOD Exit();
|
||||
|
||||
NS_IMETHOD SetDocumentCharset(const nsString& aCharset);
|
||||
|
||||
// nsIStreamObserver
|
||||
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
|
||||
@ -77,6 +79,24 @@ class nsBrowserAppCore : public nsBaseAppCore,
|
||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
|
||||
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
||||
|
||||
|
||||
// nsIURlListener methods
|
||||
NS_IMETHOD WillLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
nsLoadType aReason);
|
||||
|
||||
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL);
|
||||
|
||||
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
PRInt32 aProgress,
|
||||
PRInt32 aProgressMax);
|
||||
|
||||
NS_IMETHOD EndLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
PRInt32 aStatus);
|
||||
|
||||
// nsINetSupport
|
||||
NS_IMETHOD_(void) Alert(const nsString &aText);
|
||||
|
||||
@ -109,6 +129,7 @@ class nsBrowserAppCore : public nsBaseAppCore,
|
||||
|
||||
nsIWebShellWindow *mWebShellWin;
|
||||
nsIWebShell * mWebShell;
|
||||
nsIWebShell * mContentAreaWebShell;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user