Bug 986976 - do_QueryInterface abuse in various .mm files. r=neil
authorSteven Michaud <smichaud@pobox.com>
Tue, 25 Mar 2014 11:32:58 -0500
changeset 175261 1f924b14ed31c7f8115bcf8f479425afb0f88845
parent 175260 e2bc23496d67bb1770d0b2a19ede335adbb12d5a
child 175262 cc6d4225d0914d6545a1f97ac51ea62dc7e6a785
push idunknown
push userunknown
push dateunknown
reviewersneil
bugs986976
milestone31.0a1
Bug 986976 - do_QueryInterface abuse in various .mm files. r=neil
widget/cocoa/nsDeviceContextSpecX.mm
widget/cocoa/nsPrintDialogX.mm
widget/cocoa/nsPrintOptionsX.mm
widget/cocoa/nsPrintSettingsX.h
--- a/widget/cocoa/nsDeviceContextSpecX.mm
+++ b/widget/cocoa/nsDeviceContextSpecX.mm
@@ -38,17 +38,17 @@ nsDeviceContextSpecX::~nsDeviceContextSp
 NS_IMPL_ISUPPORTS1(nsDeviceContextSpecX, nsIDeviceContextSpec)
 
 NS_IMETHODIMP nsDeviceContextSpecX::Init(nsIWidget *aWidget,
                                          nsIPrintSettings* aPS,
                                          bool aIsPrintPreview)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
-  nsCOMPtr<nsPrintSettingsX> settings(do_QueryInterface(aPS));
+  nsRefPtr<nsPrintSettingsX> settings(do_QueryObject(aPS));
   if (!settings)
     return NS_ERROR_NO_INTERFACE;
 
   mPrintSession = settings->GetPMPrintSession();
   ::PMRetain(mPrintSession);
   mPageFormat = settings->GetPMPageFormat();
   mPrintSettings = settings->GetPMPrintSettings();
 
--- a/widget/cocoa/nsPrintDialogX.mm
+++ b/widget/cocoa/nsPrintDialogX.mm
@@ -39,17 +39,17 @@ nsPrintDialogServiceX::Init()
 NS_IMETHODIMP
 nsPrintDialogServiceX::Show(nsIDOMWindow *aParent, nsIPrintSettings *aSettings,
                             nsIWebBrowserPrint *aWebBrowserPrint)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   NS_PRECONDITION(aSettings, "aSettings must not be null");
 
-  nsCOMPtr<nsPrintSettingsX> settingsX(do_QueryInterface(aSettings));
+  nsRefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aSettings));
   if (!settingsX)
     return NS_ERROR_FAILURE;
 
   // Set the print job title
   char16_t** docTitles;
   uint32_t titleCount;
   nsresult rv = aWebBrowserPrint->EnumerateDocumentNames(&titleCount, &docTitles);
   if (NS_SUCCEEDED(rv) && titleCount > 0) {
@@ -122,17 +122,17 @@ nsPrintDialogServiceX::Show(nsIDOMWindow
 NS_IMETHODIMP
 nsPrintDialogServiceX::ShowPageSetup(nsIDOMWindow *aParent,
                                      nsIPrintSettings *aNSSettings)
 {
   NS_PRECONDITION(aParent, "aParent must not be null");
   NS_PRECONDITION(aNSSettings, "aSettings must not be null");
   NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsPrintSettingsX> settingsX(do_QueryInterface(aNSSettings));
+  nsRefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aNSSettings));
   if (!settingsX)
     return NS_ERROR_FAILURE;
 
   NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo();
   NSPageLayout *pageLayout = [NSPageLayout pageLayout];
   nsCocoaUtils::PrepareForNativeAppModalDialog();
   int button = [pageLayout runModalWithPrintInfo:printInfo];
   nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
--- a/widget/cocoa/nsPrintOptionsX.mm
+++ b/widget/cocoa/nsPrintOptionsX.mm
@@ -19,17 +19,17 @@ nsPrintOptionsX::~nsPrintOptionsX()
 nsresult
 nsPrintOptionsX::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName, uint32_t aFlags)
 {
   nsresult rv;
   
   rv = nsPrintOptions::ReadPrefs(aPS, aPrinterName, aFlags);
   NS_ASSERTION(NS_SUCCEEDED(rv), "nsPrintOptions::ReadPrefs() failed");
   
-  nsCOMPtr<nsPrintSettingsX> printSettingsX(do_QueryInterface(aPS));
+  nsRefPtr<nsPrintSettingsX> printSettingsX(do_QueryObject(aPS));
   if (!printSettingsX)
     return NS_ERROR_NO_INTERFACE;
   rv = printSettingsX->ReadPageFormatFromPrefs();
   
   return rv;
 }
 
 nsresult nsPrintOptionsX::_CreatePrintSettings(nsIPrintSettings **_retval)
@@ -54,16 +54,16 @@ nsresult nsPrintOptionsX::_CreatePrintSe
 nsresult
 nsPrintOptionsX::WritePrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName, uint32_t aFlags)
 {
   nsresult rv;
 
   rv = nsPrintOptions::WritePrefs(aPS, aPrinterName, aFlags);
   NS_ASSERTION(NS_SUCCEEDED(rv), "nsPrintOptions::WritePrefs() failed");
 
-  nsCOMPtr<nsPrintSettingsX> printSettingsX(do_QueryInterface(aPS));
+  nsRefPtr<nsPrintSettingsX> printSettingsX(do_QueryObject(aPS));
   if (!printSettingsX)
     return NS_ERROR_NO_INTERFACE;
   rv = printSettingsX->WritePageFormatToPrefs();
   NS_ASSERTION(NS_SUCCEEDED(rv), "nsPrintSettingsX::WritePageFormatToPrefs() failed");
 
   return NS_OK;
 }
--- a/widget/cocoa/nsPrintSettingsX.h
+++ b/widget/cocoa/nsPrintSettingsX.h
@@ -4,19 +4,24 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsPrintSettingsX_h_
 #define nsPrintSettingsX_h_
 
 #include "nsPrintSettingsImpl.h"  
 #import <Cocoa/Cocoa.h>
 
+#define NS_PRINTSETTINGSX_IID \
+{ 0x0DF2FDBD, 0x906D, 0x4726, \
+  { 0x9E, 0x4D, 0xCF, 0xE0, 0x87, 0x8D, 0x70, 0x7C } }
+
 class nsPrintSettingsX : public nsPrintSettings
 {
 public:
+  NS_DECLARE_STATIC_IID_ACCESSOR(NS_PRINTSETTINGSX_IID)
   NS_DECL_ISUPPORTS_INHERITED
 
   nsPrintSettingsX();
   virtual ~nsPrintSettingsX();
   nsresult Init();
   NSPrintInfo* GetCocoaPrintInfo() { return mPrintInfo; }
   void SetCocoaPrintInfo(NSPrintInfo* aPrintInfo);
   virtual nsresult ReadPageFormatFromPrefs();
@@ -40,9 +45,11 @@ protected:
 
   // The out param has a ref count of 1 on return so caller needs to PMRelase() when done.
   OSStatus CreateDefaultPageFormat(PMPrintSession aSession, PMPageFormat& outFormat);
   OSStatus CreateDefaultPrintSettings(PMPrintSession aSession, PMPrintSettings& outSettings);
 
   NSPrintInfo* mPrintInfo;
 };
 
+NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsX, NS_PRINTSETTINGSX_IID)
+
 #endif // nsPrintSettingsX_h_