96364 - Register html tag observers directly to parser service rather than nsObserverService. Doing so, reduces a lot of overhead. Also, the observers are now notified via sink. This eliminates the need for parser bundle.
r=dp,shanjian,sfraser, sr=rpotts. git-svn-id: svn://10.0.0.236/trunk@104152 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -38,9 +38,11 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIParserService.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsEditorParserObserver.h"
|
||||
|
||||
static NS_DEFINE_IID(kParserServiceCID, NS_PARSERSERVICE_CID);
|
||||
|
||||
NS_IMPL_ADDREF(nsEditorParserObserver);
|
||||
NS_IMPL_RELEASE(nsEditorParserObserver);
|
||||
@@ -62,15 +64,6 @@ nsEditorParserObserver::~nsEditorParserObserver()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const char*) nsEditorParserObserver::GetTagNameAt(PRUint32 aTagIndex)
|
||||
{
|
||||
nsCString* theString = mWatchTags[aTagIndex];
|
||||
if (theString)
|
||||
return theString->get();
|
||||
else
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEditorParserObserver::Notify(
|
||||
PRUint32 aDocumentID,
|
||||
const PRUnichar* aTag,
|
||||
@@ -98,8 +91,11 @@ NS_IMETHODIMP nsEditorParserObserver::Notify(
|
||||
else
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
NS_IMETHODIMP nsEditorParserObserver::Notify(nsISupports* aDocumentID, const PRUnichar* aTag,
|
||||
const nsStringArray* aKeys, const nsStringArray* aValues)
|
||||
NS_IMETHODIMP nsEditorParserObserver::Notify(nsISupports* aWebShell,
|
||||
nsISupports* aChannel,
|
||||
const PRUnichar* aTag,
|
||||
const nsStringArray* aKeys,
|
||||
const nsStringArray* aValues)
|
||||
{
|
||||
Notify();
|
||||
return NS_OK;
|
||||
@@ -115,26 +111,34 @@ void nsEditorParserObserver::Notify()
|
||||
mBadTagFound = PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEditorParserObserver::Start()
|
||||
NS_IMETHODIMP nsEditorParserObserver::Start(eHTMLTags* aWatchTags)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsAutoString parserService; parserService.AssignWithConversion("text/html");
|
||||
|
||||
nsCOMPtr<nsIParserService> parserService(do_GetService(kParserServiceCID));
|
||||
|
||||
if (!parserService) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> anObserverService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &res);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
return anObserverService->AddObserver(this, parserService.get());
|
||||
res = parserService->RegisterObserver(this,
|
||||
NS_LITERAL_STRING("text/html"),
|
||||
aWatchTags);
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEditorParserObserver::End()
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsAutoString parserService; parserService.AssignWithConversion("text/html");
|
||||
nsCOMPtr<nsIParserService> parserService(do_GetService(kParserServiceCID));
|
||||
|
||||
nsCOMPtr<nsIObserverService> anObserverService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &res);
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!parserService) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return anObserverService->RemoveObserver(this, parserService.get());
|
||||
res = parserService->UnregisterObserver(this,
|
||||
NS_LITERAL_STRING("text/html"));
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsEditorParserObserver::GetBadTagFound(PRBool *aFound)
|
||||
@@ -145,12 +149,4 @@ NS_IMETHODIMP nsEditorParserObserver::GetBadTagFound(PRBool *aFound)
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsEditorParserObserver::RegisterTagToWatch(const char* tagName)
|
||||
{
|
||||
nsCString theTagString(tagName);
|
||||
mWatchTags.AppendCString(theTagString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user