From 273f420e23b511ae2f28fdf6c76c12d7b02577e4 Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Fri, 8 Oct 1999 14:39:20 +0000 Subject: [PATCH] fixed my part of bug 15814 (Cleanup build warnings) so trivial, no reviewer needed fixed my part of bug 5403 (Services improperly released: Use NS_WITH_SERVICE) a handful of subtle error handling bugs were fixed as a side effect r=Akkana git-svn-id: svn://10.0.0.236/trunk@50222 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditor.cpp | 7 +- .../editor/base/nsEditorEventListeners.cpp | 201 ++++++++---------- mozilla/editor/base/nsEditorShell.cpp | 103 +++------ mozilla/editor/base/nsHTMLEditor.cpp | 18 +- mozilla/editor/base/nsTextEditRules.cpp | 2 +- mozilla/editor/composer/src/nsEditorShell.cpp | 103 +++------ mozilla/editor/libeditor/base/nsEditor.cpp | 7 +- .../editor/libeditor/html/nsHTMLEditor.cpp | 18 +- .../libeditor/text/nsEditorEventListeners.cpp | 201 ++++++++---------- .../editor/libeditor/text/nsTextEditRules.cpp | 2 +- 10 files changed, 278 insertions(+), 384 deletions(-) diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index ed6695e6d44..26c55b0329a 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -144,15 +144,14 @@ nsEditor::nsEditor() : mPresShellWeak(nsnull) , mViewManager(nsnull) , mUpdateCount(0) -, mActionListeners(nsnull) -, mDocDirtyState(-1) -, mDocWeak(nsnull) , mPlaceHolderTxn(nsnull) , mPlaceHolderName(nsnull) , mPlaceHolderBatch(0) , mTxnStartNode(nsnull) , mTxnStartOffset(0) - +, mActionListeners(nsnull) +, mDocDirtyState(-1) +, mDocWeak(nsnull) { //initialize member variables here NS_INIT_REFCNT(); diff --git a/mozilla/editor/base/nsEditorEventListeners.cpp b/mozilla/editor/base/nsEditorEventListeners.cpp index 59dc1394eca..e9917cc3c89 100644 --- a/mozilla/editor/base/nsEditorEventListeners.cpp +++ b/mozilla/editor/base/nsEditorEventListeners.cpp @@ -996,64 +996,54 @@ nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) doc->CreateXIF(XIFBuffer, sel); // Get the Clipboard - nsIClipboard* clipboard; - rv = nsServiceManager::GetService(kCClipboardCID, - nsIClipboard::GetIID(), - (nsISupports **)&clipboard); - if (NS_OK == rv) - { - // Create a data flavor to tell the transferable - // that it is about to receive XIF - nsAutoString flavor(kXIFMime); + NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv); + if (NS_FAILED(rv)) return rv; + + // Create a data flavor to tell the transferable + // that it is about to receive XIF + nsAutoString flavor(kXIFMime); - // Create a transferable for putting data on the Clipboard - nsCOMPtr trans; - rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, - nsITransferable::GetIID(), - (void**) getter_AddRefs(trans)); - if (NS_OK == rv) { - // The data on the clipboard will be in "XIF" format - // so give the clipboard transferable a "XIFConverter" for - // converting from XIF to other formats - nsCOMPtr xifConverter; - rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, - nsIFormatConverter::GetIID(), - (void**) getter_AddRefs(xifConverter)); - if (NS_OK == rv) { - // Add the XIF DataFlavor to the transferable - // this tells the transferable that it can handle receiving the XIF format - trans->AddDataFlavor(&flavor); + // Create a transferable for putting data on the Clipboard + nsCOMPtr trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + nsITransferable::GetIID(), + (void**) getter_AddRefs(trans)); + if (NS_OK == rv) { + // The data on the clipboard will be in "XIF" format + // so give the clipboard transferable a "XIFConverter" for + // converting from XIF to other formats + nsCOMPtr xifConverter; + rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, + nsIFormatConverter::GetIID(), + (void**) getter_AddRefs(xifConverter)); + if (NS_OK == rv) { + // Add the XIF DataFlavor to the transferable + // this tells the transferable that it can handle receiving the XIF format + trans->AddDataFlavor(&flavor); - // Add the converter for going from XIF to other formats - trans->SetConverter(xifConverter); + // Add the converter for going from XIF to other formats + trans->SetConverter(xifConverter); - // Now add the XIF data to the transferable - // the transferable wants the number bytes for the data and since it is double byte - // we multiply by 2 - trans->SetTransferData(&flavor, XIFBuffer.ToNewUnicode(), XIFBuffer.Length()*2); + // Now add the XIF data to the transferable + // the transferable wants the number bytes for the data and since it is double byte + // we multiply by 2 + trans->SetTransferData(&flavor, XIFBuffer.ToNewUnicode(), XIFBuffer.Length()*2); - // Now invoke the drag session - nsIDragService* dragService; - nsresult rv = nsServiceManager::GetService(kCDragServiceCID, - nsIDragService::GetIID(), - (nsISupports **)&dragService); - if (NS_OK == rv) { - nsCOMPtr items; - NS_NewISupportsArray(getter_AddRefs(items)); - if ( items ) { - items->AppendElement(trans); - dragService->InvokeDragSession(items, nsnull, - nsIDragService::DRAGDROP_ACTION_COPY | - nsIDragService::DRAGDROP_ACTION_MOVE); - } - nsServiceManager::ReleaseService(kCDragServiceCID, dragService); - } - } - } - nsServiceManager::ReleaseService(kCClipboardCID, clipboard); - } - return NS_ERROR_BASE; // return that we've handled the event - } + // Now invoke the drag session + NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr items; + NS_NewISupportsArray(getter_AddRefs(items)); + if ( items ) { + items->AppendElement(trans); + dragService->InvokeDragSession(items, nsnull, + nsIDragService::DRAGDROP_ACTION_COPY | + nsIDragService::DRAGDROP_ACTION_MOVE); + } + } + } + } + return NS_ERROR_BASE; // return that we've handled the event #endif } // middle-mouse click (paste); @@ -1347,66 +1337,63 @@ nsresult nsTextEditorDragListener::DragDrop(nsIDOMEvent* aMouseEvent) { // Create drag service for getting state of drag - nsIDragService* dragService; - nsresult rv = nsServiceManager::GetService(kCDragServiceCID, - nsIDragService::GetIID(), - (nsISupports **)&dragService); - if (NS_OK == rv) { - nsCOMPtr dragSession(do_QueryInterface(dragService)); + nsresult rv; + NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr dragSession(do_QueryInterface(dragService)); - if (dragSession) { + if (dragSession) { - // Create transferable for getting the drag data - nsCOMPtr trans; - rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, - nsITransferable::GetIID(), - (void**) getter_AddRefs(trans)); - if ( NS_SUCCEEDED(rv) && trans ) { - // Add the text Flavor to the transferable, - // because that is the only type of data we are - // looking for at the moment. - trans->AddDataFlavor(kTextMime); - //trans->AddDataFlavor(mImageDataFlavor); + // Create transferable for getting the drag data + nsCOMPtr trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + nsITransferable::GetIID(), + (void**) getter_AddRefs(trans)); + if ( NS_SUCCEEDED(rv) && trans ) { + // Add the text Flavor to the transferable, + // because that is the only type of data we are + // looking for at the moment. + trans->AddDataFlavor(kTextMime); + //trans->AddDataFlavor(mImageDataFlavor); - // Fill the transferable with data for each drag item in succession - PRUint32 numItems = 0; - if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) { + // Fill the transferable with data for each drag item in succession + PRUint32 numItems = 0; + if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) { - printf("Num Drop Items %d\n", numItems); + printf("Num Drop Items %d\n", numItems); - PRUint32 i; - for (i=0;iGetData(trans, i))) { - - // Get the string data out of the transferable - // Note: the transferable owns the pointer to the data - nsCOMPtr genericDataObj; - PRUint32 len; - char* whichFlavor = nsnull; - trans->GetAnyTransferData(&whichFlavor, getter_AddRefs(genericDataObj), &len); - nsCOMPtr textDataObj( do_QueryInterface(genericDataObj) ); - // If the string was not empty then paste it in - if ( textDataObj ) - { - char* text = nsnull; - textDataObj->ToString(&text); - nsCOMPtr htmlEditor = do_QueryInterface(mEditor); - if ( htmlEditor && text ) - htmlEditor->InsertText(text); - dragSession->SetCanDrop(PR_TRUE); - } + PRUint32 i; + for (i=0;iGetData(trans, i))) { - nsCRT::free(whichFlavor); - // XXX This is where image support might go - //void * data; - //trans->GetTransferData(mImageDataFlavor, (void **)&data, &len); + // Get the string data out of the transferable + // Note: the transferable owns the pointer to the data + nsCOMPtr genericDataObj; + PRUint32 len; + char* whichFlavor = nsnull; + trans->GetAnyTransferData(&whichFlavor, getter_AddRefs(genericDataObj), &len); + nsCOMPtr textDataObj( do_QueryInterface(genericDataObj) ); + // If the string was not empty then paste it in + if ( textDataObj ) + { + char* text = nsnull; + textDataObj->ToString(&text); + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if ( htmlEditor && text ) + htmlEditor->InsertText(text); + dragSession->SetCanDrop(PR_TRUE); } - } // foreach drag item - } - } // if valid transferable - } // if valid drag session - nsServiceManager::ReleaseService(kCDragServiceCID, dragService); - } // if valid drag service + + nsCRT::free(whichFlavor); + // XXX This is where image support might go + //void * data; + //trans->GetTransferData(mImageDataFlavor, (void **)&data, &len); + } + } // foreach drag item + } + } // if valid transferable + } // if valid drag session return NS_OK; } diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index f158675416b..7585f2ac8ba 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -260,23 +260,19 @@ nsEditorShell::Init() mEditorTypeString = editorType; mEditorTypeString.ToLowerCase(); - nsIStringBundleService* service; - // Get pointer to our string bundle - nsresult res = nsServiceManager::GetService(kCStringBundleServiceCID, - nsIStringBundleService::GetIID(), - (nsISupports**)&service); - if (NS_SUCCEEDED(res) && service) - { - nsILocale* locale = nsnull; - res = service->CreateBundle(EDITOR_BUNDLE_URL, locale, - getter_AddRefs(mStringBundle)); - // We don't need to keep service around once we created the bundle - nsServiceManager::ReleaseService(kCStringBundleServiceCID, service); - } else { + nsresult res; + NS_WITH_SERVICE(nsIStringBundleService, service, kCStringBundleServiceCID, &res); + if (NS_FAILED(res)) { printf("ERROR: Failed to get StringBundle Service instance.\n"); + return res; } + nsILocale* locale = nsnull; + res = service->CreateBundle(EDITOR_BUNDLE_URL, locale, + getter_AddRefs(mStringBundle)); + // XXX: why are we returning NS_OK here rather than res? + // is it ok to fail to get a string bundle? if so, it should be documented. return NS_OK; } @@ -1044,28 +1040,20 @@ nsEditorShell::CreateWindowWithURL(const char* urlStr) /* * Create the Application Shell instance... */ - nsIAppShellService* appShell = nsnull; - rv = nsServiceManager::GetService(kAppShellServiceCID, - nsIAppShellService::GetIID(), - (nsISupports**)&appShell); - if (NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); + if (NS_FAILED(rv)) { return rv; } nsCOMPtr url = nsnull; nsCOMPtr newWindow; rv = NS_NewURL(getter_AddRefs(url), urlStr); - if (NS_FAILED(rv) || !url) - goto done; - + if (NS_FAILED(rv)) return rv; + if (!url) { return NS_ERROR_NULL_POINTER; } + + // XXX: does CreateTopLevelWindow return a result we should be returning? appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, NS_CHROME_ALL_CHROME, nsnull, 615, 480, getter_AddRefs(newWindow)); -done: - /* Release the shell... */ - if (nsnull != appShell) { - nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); - } #else @@ -1075,22 +1063,13 @@ done: /* * Create the toolkit core instance... */ - nsIDOMToolkitCore* toolkit = nsnull; - rv = nsServiceManager::GetService(kToolkitCoreCID, - nsIDOMToolkitCore::GetIID(), - (nsISupports**)&toolkit); - if (NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIDOMToolkitCore, toolkit, kToolkitCoreCID, &rv); + if (NS_FAILED(rv)) { return rv; } //nsIWebShellWindow* newWindow = nsnull; toolkit->ShowWindowWithArgs( urlStr, nsnull, "chrome://editor/content/EditorInitPage.html" ); - /* Release the toolkit... */ - if (nsnull != toolkit) { - nsServiceManager::ReleaseService(kToolkitCoreCID, toolkit); - } - #endif return rv; @@ -1381,18 +1360,13 @@ nsEditorShell::Exit() // user canceled an action along the way if (NS_SUCCEEDED(rv) && result) { - nsIAppShellService* appShell = nsnull; /* * Create the Application Shell instance... */ - rv = nsServiceManager::GetService(kAppShellServiceCID, - nsIAppShellService::GetIID(), - (nsISupports**)&appShell); - if (NS_SUCCEEDED(rv)) { - appShell->Quit(); - nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); - } + NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); + if (NS_FAILED(rv)) { return rv; } + appShell->Quit(); } return NS_OK; //Why not return rv? } @@ -1880,32 +1854,23 @@ nsEditorShell::DoFind(PRBool aFindNext) PRBool foundIt = PR_FALSE; // Get find component. - nsIFindComponent *findComponent; - nsresult rv = nsServiceManager::GetService( NS_IFINDCOMPONENT_PROGID, - nsIFindComponent::GetIID(), - (nsISupports**)&findComponent ); - if ( NS_SUCCEEDED(rv) && findComponent ) + nsresult rv; + NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_PROGID, &rv); + NS_ASSERTION(((NS_SUCCEEDED(rv)) && findComponent), "GetService failed for find component."); + if (NS_FAILED(rv)) { return rv; } + + // make the search context if we need to + if (!mSearchContext) { - // make the search context if we need to - if (!mSearchContext) - { - rv = findComponent->CreateContext( mContentAreaWebShell, nsnull, getter_AddRefs(mSearchContext)); - } - - if (NS_SUCCEEDED(rv)) - { - if (aFindNext) - rv = findComponent->FindNext(mSearchContext, &foundIt); - else - rv = findComponent->Find(mSearchContext, &foundIt); - } - - // Release the service. - nsServiceManager::ReleaseService( NS_IFINDCOMPONENT_PROGID, findComponent ); + rv = findComponent->CreateContext( mContentAreaWebShell, nsnull, getter_AddRefs(mSearchContext)); } - else + + if (NS_SUCCEEDED(rv)) { - NS_ASSERTION(0, "GetService failed for find component."); + if (aFindNext) + rv = findComponent->FindNext(mSearchContext, &foundIt); + else + rv = findComponent->Find(mSearchContext, &foundIt); } return rv; diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 5b65038480c..15b3652fa82 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -3170,10 +3170,9 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation) NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation() { // Get Clipboard Service - nsIClipboard* clipboard; - nsresult rv = nsServiceManager::GetService(kCClipboardCID, - nsIClipboard::GetIID(), - (nsISupports **)&clipboard); + nsresult rv; + NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv); + if (NS_FAILED(rv)) return rv; // Create generic Transferable for getting the data nsCOMPtr trans; @@ -3205,7 +3204,6 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation() } } } - nsServiceManager::ReleaseService(kCClipboardCID, clipboard); return rv; } @@ -3221,10 +3219,10 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsPlaintextQuotation(const nsString& aQuotedTe { // Now we have the text. Cite it appropriately: nsCOMPtr citer; - nsCOMPtr prefs; - nsresult rv = nsServiceManager::GetService(kPrefServiceCID, - nsIPref::GetIID(), - (nsISupports**)&prefs); + nsresult rv; + NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + char *citationType = 0; rv = prefs->CopyCharPref("mail.compose.citationType", &citationType); @@ -3239,8 +3237,6 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsPlaintextQuotation(const nsString& aQuotedTe else citer = new nsInternetCiter; - nsServiceManager::ReleaseService(kPrefServiceCID, prefs); - // Let the citer quote it for us: nsString quotedStuff; rv = citer->GetCiteString(aQuotedText, quotedStuff); diff --git a/mozilla/editor/base/nsTextEditRules.cpp b/mozilla/editor/base/nsTextEditRules.cpp index 63e485da079..c00c306d1c8 100644 --- a/mozilla/editor/base/nsTextEditRules.cpp +++ b/mozilla/editor/base/nsTextEditRules.cpp @@ -439,8 +439,8 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta // properties on and off, this code only turns them on if (PR_TRUE==createNewTextNode) { + offset = 0; nsCOMPtrparent = do_QueryInterface(anchor); - PRInt32 offset=0; if (parent) { // we have a selection, get the offset within the parent res = aSelection->GetAnchorOffset(&offset); diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index f158675416b..7585f2ac8ba 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -260,23 +260,19 @@ nsEditorShell::Init() mEditorTypeString = editorType; mEditorTypeString.ToLowerCase(); - nsIStringBundleService* service; - // Get pointer to our string bundle - nsresult res = nsServiceManager::GetService(kCStringBundleServiceCID, - nsIStringBundleService::GetIID(), - (nsISupports**)&service); - if (NS_SUCCEEDED(res) && service) - { - nsILocale* locale = nsnull; - res = service->CreateBundle(EDITOR_BUNDLE_URL, locale, - getter_AddRefs(mStringBundle)); - // We don't need to keep service around once we created the bundle - nsServiceManager::ReleaseService(kCStringBundleServiceCID, service); - } else { + nsresult res; + NS_WITH_SERVICE(nsIStringBundleService, service, kCStringBundleServiceCID, &res); + if (NS_FAILED(res)) { printf("ERROR: Failed to get StringBundle Service instance.\n"); + return res; } + nsILocale* locale = nsnull; + res = service->CreateBundle(EDITOR_BUNDLE_URL, locale, + getter_AddRefs(mStringBundle)); + // XXX: why are we returning NS_OK here rather than res? + // is it ok to fail to get a string bundle? if so, it should be documented. return NS_OK; } @@ -1044,28 +1040,20 @@ nsEditorShell::CreateWindowWithURL(const char* urlStr) /* * Create the Application Shell instance... */ - nsIAppShellService* appShell = nsnull; - rv = nsServiceManager::GetService(kAppShellServiceCID, - nsIAppShellService::GetIID(), - (nsISupports**)&appShell); - if (NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); + if (NS_FAILED(rv)) { return rv; } nsCOMPtr url = nsnull; nsCOMPtr newWindow; rv = NS_NewURL(getter_AddRefs(url), urlStr); - if (NS_FAILED(rv) || !url) - goto done; - + if (NS_FAILED(rv)) return rv; + if (!url) { return NS_ERROR_NULL_POINTER; } + + // XXX: does CreateTopLevelWindow return a result we should be returning? appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, NS_CHROME_ALL_CHROME, nsnull, 615, 480, getter_AddRefs(newWindow)); -done: - /* Release the shell... */ - if (nsnull != appShell) { - nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); - } #else @@ -1075,22 +1063,13 @@ done: /* * Create the toolkit core instance... */ - nsIDOMToolkitCore* toolkit = nsnull; - rv = nsServiceManager::GetService(kToolkitCoreCID, - nsIDOMToolkitCore::GetIID(), - (nsISupports**)&toolkit); - if (NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIDOMToolkitCore, toolkit, kToolkitCoreCID, &rv); + if (NS_FAILED(rv)) { return rv; } //nsIWebShellWindow* newWindow = nsnull; toolkit->ShowWindowWithArgs( urlStr, nsnull, "chrome://editor/content/EditorInitPage.html" ); - /* Release the toolkit... */ - if (nsnull != toolkit) { - nsServiceManager::ReleaseService(kToolkitCoreCID, toolkit); - } - #endif return rv; @@ -1381,18 +1360,13 @@ nsEditorShell::Exit() // user canceled an action along the way if (NS_SUCCEEDED(rv) && result) { - nsIAppShellService* appShell = nsnull; /* * Create the Application Shell instance... */ - rv = nsServiceManager::GetService(kAppShellServiceCID, - nsIAppShellService::GetIID(), - (nsISupports**)&appShell); - if (NS_SUCCEEDED(rv)) { - appShell->Quit(); - nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); - } + NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); + if (NS_FAILED(rv)) { return rv; } + appShell->Quit(); } return NS_OK; //Why not return rv? } @@ -1880,32 +1854,23 @@ nsEditorShell::DoFind(PRBool aFindNext) PRBool foundIt = PR_FALSE; // Get find component. - nsIFindComponent *findComponent; - nsresult rv = nsServiceManager::GetService( NS_IFINDCOMPONENT_PROGID, - nsIFindComponent::GetIID(), - (nsISupports**)&findComponent ); - if ( NS_SUCCEEDED(rv) && findComponent ) + nsresult rv; + NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_PROGID, &rv); + NS_ASSERTION(((NS_SUCCEEDED(rv)) && findComponent), "GetService failed for find component."); + if (NS_FAILED(rv)) { return rv; } + + // make the search context if we need to + if (!mSearchContext) { - // make the search context if we need to - if (!mSearchContext) - { - rv = findComponent->CreateContext( mContentAreaWebShell, nsnull, getter_AddRefs(mSearchContext)); - } - - if (NS_SUCCEEDED(rv)) - { - if (aFindNext) - rv = findComponent->FindNext(mSearchContext, &foundIt); - else - rv = findComponent->Find(mSearchContext, &foundIt); - } - - // Release the service. - nsServiceManager::ReleaseService( NS_IFINDCOMPONENT_PROGID, findComponent ); + rv = findComponent->CreateContext( mContentAreaWebShell, nsnull, getter_AddRefs(mSearchContext)); } - else + + if (NS_SUCCEEDED(rv)) { - NS_ASSERTION(0, "GetService failed for find component."); + if (aFindNext) + rv = findComponent->FindNext(mSearchContext, &foundIt); + else + rv = findComponent->Find(mSearchContext, &foundIt); } return rv; diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index ed6695e6d44..26c55b0329a 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -144,15 +144,14 @@ nsEditor::nsEditor() : mPresShellWeak(nsnull) , mViewManager(nsnull) , mUpdateCount(0) -, mActionListeners(nsnull) -, mDocDirtyState(-1) -, mDocWeak(nsnull) , mPlaceHolderTxn(nsnull) , mPlaceHolderName(nsnull) , mPlaceHolderBatch(0) , mTxnStartNode(nsnull) , mTxnStartOffset(0) - +, mActionListeners(nsnull) +, mDocDirtyState(-1) +, mDocWeak(nsnull) { //initialize member variables here NS_INIT_REFCNT(); diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 5b65038480c..15b3652fa82 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -3170,10 +3170,9 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation) NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation() { // Get Clipboard Service - nsIClipboard* clipboard; - nsresult rv = nsServiceManager::GetService(kCClipboardCID, - nsIClipboard::GetIID(), - (nsISupports **)&clipboard); + nsresult rv; + NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv); + if (NS_FAILED(rv)) return rv; // Create generic Transferable for getting the data nsCOMPtr trans; @@ -3205,7 +3204,6 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation() } } } - nsServiceManager::ReleaseService(kCClipboardCID, clipboard); return rv; } @@ -3221,10 +3219,10 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsPlaintextQuotation(const nsString& aQuotedTe { // Now we have the text. Cite it appropriately: nsCOMPtr citer; - nsCOMPtr prefs; - nsresult rv = nsServiceManager::GetService(kPrefServiceCID, - nsIPref::GetIID(), - (nsISupports**)&prefs); + nsresult rv; + NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + char *citationType = 0; rv = prefs->CopyCharPref("mail.compose.citationType", &citationType); @@ -3239,8 +3237,6 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsPlaintextQuotation(const nsString& aQuotedTe else citer = new nsInternetCiter; - nsServiceManager::ReleaseService(kPrefServiceCID, prefs); - // Let the citer quote it for us: nsString quotedStuff; rv = citer->GetCiteString(aQuotedText, quotedStuff); diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index 59dc1394eca..e9917cc3c89 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -996,64 +996,54 @@ nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) doc->CreateXIF(XIFBuffer, sel); // Get the Clipboard - nsIClipboard* clipboard; - rv = nsServiceManager::GetService(kCClipboardCID, - nsIClipboard::GetIID(), - (nsISupports **)&clipboard); - if (NS_OK == rv) - { - // Create a data flavor to tell the transferable - // that it is about to receive XIF - nsAutoString flavor(kXIFMime); + NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv); + if (NS_FAILED(rv)) return rv; + + // Create a data flavor to tell the transferable + // that it is about to receive XIF + nsAutoString flavor(kXIFMime); - // Create a transferable for putting data on the Clipboard - nsCOMPtr trans; - rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, - nsITransferable::GetIID(), - (void**) getter_AddRefs(trans)); - if (NS_OK == rv) { - // The data on the clipboard will be in "XIF" format - // so give the clipboard transferable a "XIFConverter" for - // converting from XIF to other formats - nsCOMPtr xifConverter; - rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, - nsIFormatConverter::GetIID(), - (void**) getter_AddRefs(xifConverter)); - if (NS_OK == rv) { - // Add the XIF DataFlavor to the transferable - // this tells the transferable that it can handle receiving the XIF format - trans->AddDataFlavor(&flavor); + // Create a transferable for putting data on the Clipboard + nsCOMPtr trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + nsITransferable::GetIID(), + (void**) getter_AddRefs(trans)); + if (NS_OK == rv) { + // The data on the clipboard will be in "XIF" format + // so give the clipboard transferable a "XIFConverter" for + // converting from XIF to other formats + nsCOMPtr xifConverter; + rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, + nsIFormatConverter::GetIID(), + (void**) getter_AddRefs(xifConverter)); + if (NS_OK == rv) { + // Add the XIF DataFlavor to the transferable + // this tells the transferable that it can handle receiving the XIF format + trans->AddDataFlavor(&flavor); - // Add the converter for going from XIF to other formats - trans->SetConverter(xifConverter); + // Add the converter for going from XIF to other formats + trans->SetConverter(xifConverter); - // Now add the XIF data to the transferable - // the transferable wants the number bytes for the data and since it is double byte - // we multiply by 2 - trans->SetTransferData(&flavor, XIFBuffer.ToNewUnicode(), XIFBuffer.Length()*2); + // Now add the XIF data to the transferable + // the transferable wants the number bytes for the data and since it is double byte + // we multiply by 2 + trans->SetTransferData(&flavor, XIFBuffer.ToNewUnicode(), XIFBuffer.Length()*2); - // Now invoke the drag session - nsIDragService* dragService; - nsresult rv = nsServiceManager::GetService(kCDragServiceCID, - nsIDragService::GetIID(), - (nsISupports **)&dragService); - if (NS_OK == rv) { - nsCOMPtr items; - NS_NewISupportsArray(getter_AddRefs(items)); - if ( items ) { - items->AppendElement(trans); - dragService->InvokeDragSession(items, nsnull, - nsIDragService::DRAGDROP_ACTION_COPY | - nsIDragService::DRAGDROP_ACTION_MOVE); - } - nsServiceManager::ReleaseService(kCDragServiceCID, dragService); - } - } - } - nsServiceManager::ReleaseService(kCClipboardCID, clipboard); - } - return NS_ERROR_BASE; // return that we've handled the event - } + // Now invoke the drag session + NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr items; + NS_NewISupportsArray(getter_AddRefs(items)); + if ( items ) { + items->AppendElement(trans); + dragService->InvokeDragSession(items, nsnull, + nsIDragService::DRAGDROP_ACTION_COPY | + nsIDragService::DRAGDROP_ACTION_MOVE); + } + } + } + } + return NS_ERROR_BASE; // return that we've handled the event #endif } // middle-mouse click (paste); @@ -1347,66 +1337,63 @@ nsresult nsTextEditorDragListener::DragDrop(nsIDOMEvent* aMouseEvent) { // Create drag service for getting state of drag - nsIDragService* dragService; - nsresult rv = nsServiceManager::GetService(kCDragServiceCID, - nsIDragService::GetIID(), - (nsISupports **)&dragService); - if (NS_OK == rv) { - nsCOMPtr dragSession(do_QueryInterface(dragService)); + nsresult rv; + NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr dragSession(do_QueryInterface(dragService)); - if (dragSession) { + if (dragSession) { - // Create transferable for getting the drag data - nsCOMPtr trans; - rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, - nsITransferable::GetIID(), - (void**) getter_AddRefs(trans)); - if ( NS_SUCCEEDED(rv) && trans ) { - // Add the text Flavor to the transferable, - // because that is the only type of data we are - // looking for at the moment. - trans->AddDataFlavor(kTextMime); - //trans->AddDataFlavor(mImageDataFlavor); + // Create transferable for getting the drag data + nsCOMPtr trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + nsITransferable::GetIID(), + (void**) getter_AddRefs(trans)); + if ( NS_SUCCEEDED(rv) && trans ) { + // Add the text Flavor to the transferable, + // because that is the only type of data we are + // looking for at the moment. + trans->AddDataFlavor(kTextMime); + //trans->AddDataFlavor(mImageDataFlavor); - // Fill the transferable with data for each drag item in succession - PRUint32 numItems = 0; - if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) { + // Fill the transferable with data for each drag item in succession + PRUint32 numItems = 0; + if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) { - printf("Num Drop Items %d\n", numItems); + printf("Num Drop Items %d\n", numItems); - PRUint32 i; - for (i=0;iGetData(trans, i))) { - - // Get the string data out of the transferable - // Note: the transferable owns the pointer to the data - nsCOMPtr genericDataObj; - PRUint32 len; - char* whichFlavor = nsnull; - trans->GetAnyTransferData(&whichFlavor, getter_AddRefs(genericDataObj), &len); - nsCOMPtr textDataObj( do_QueryInterface(genericDataObj) ); - // If the string was not empty then paste it in - if ( textDataObj ) - { - char* text = nsnull; - textDataObj->ToString(&text); - nsCOMPtr htmlEditor = do_QueryInterface(mEditor); - if ( htmlEditor && text ) - htmlEditor->InsertText(text); - dragSession->SetCanDrop(PR_TRUE); - } + PRUint32 i; + for (i=0;iGetData(trans, i))) { - nsCRT::free(whichFlavor); - // XXX This is where image support might go - //void * data; - //trans->GetTransferData(mImageDataFlavor, (void **)&data, &len); + // Get the string data out of the transferable + // Note: the transferable owns the pointer to the data + nsCOMPtr genericDataObj; + PRUint32 len; + char* whichFlavor = nsnull; + trans->GetAnyTransferData(&whichFlavor, getter_AddRefs(genericDataObj), &len); + nsCOMPtr textDataObj( do_QueryInterface(genericDataObj) ); + // If the string was not empty then paste it in + if ( textDataObj ) + { + char* text = nsnull; + textDataObj->ToString(&text); + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if ( htmlEditor && text ) + htmlEditor->InsertText(text); + dragSession->SetCanDrop(PR_TRUE); } - } // foreach drag item - } - } // if valid transferable - } // if valid drag session - nsServiceManager::ReleaseService(kCDragServiceCID, dragService); - } // if valid drag service + + nsCRT::free(whichFlavor); + // XXX This is where image support might go + //void * data; + //trans->GetTransferData(mImageDataFlavor, (void **)&data, &len); + } + } // foreach drag item + } + } // if valid transferable + } // if valid drag session return NS_OK; } diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.cpp b/mozilla/editor/libeditor/text/nsTextEditRules.cpp index 63e485da079..c00c306d1c8 100644 --- a/mozilla/editor/libeditor/text/nsTextEditRules.cpp +++ b/mozilla/editor/libeditor/text/nsTextEditRules.cpp @@ -439,8 +439,8 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta // properties on and off, this code only turns them on if (PR_TRUE==createNewTextNode) { + offset = 0; nsCOMPtrparent = do_QueryInterface(anchor); - PRInt32 offset=0; if (parent) { // we have a selection, get the offset within the parent res = aSelection->GetAnchorOffset(&offset);