Bug 1411121 - Part 1: Return NS_ERROR_FAILURE if nsIPrintDialogService doesn't exist on GTK when showing print dialog. r?karlt draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Mon, 06 Nov 2017 09:27:04 +0900
changeset 693377 ddc4e5c925bb49a7a453e05f27f569f63495ade4
parent 693376 179dae92e4d794e7f45ad080ff01908c80691f31
child 693378 56a77b81c616cb0e6f2b46140030e47180c1f0ae
push id87770
push userbmo:mantaroh@gmail.com
push dateMon, 06 Nov 2017 00:27:52 +0000
reviewerskarlt
bugs1411121
milestone58.0a1
Bug 1411121 - Part 1: Return NS_ERROR_FAILURE if nsIPrintDialogService doesn't exist on GTK when showing print dialog. r?karlt A printingui uses the xul print dialog(i.e. printdialog.xul) if there are not nsIPrintDialogService. But this code is unreachable code since current gtk widget has nsIPrintDialogService always. So this patch will remove this code. MozReview-Commit-ID: EeM6YytEfdW
toolkit/components/printingui/unixshared/nsPrintingPromptService.cpp
toolkit/components/printingui/unixshared/nsPrintingPromptService.h
--- a/toolkit/components/printingui/unixshared/nsPrintingPromptService.cpp
+++ b/toolkit/components/printingui/unixshared/nsPrintingPromptService.cpp
@@ -1,62 +1,27 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsPrintingPromptService.h"
 
-#include "nsArray.h"
-#include "nsIComponentManager.h"
-#include "nsIDialogParamBlock.h"
 #include "nsIDOMWindow.h"
 #include "nsIServiceManager.h"
 #include "nsISupportsUtils.h"
 #include "nsString.h"
 #include "nsIPrintDialogService.h"
 
 // Printing Progress Includes
 #include "nsPrintProgress.h"
 #include "nsPrintProgressParams.h"
 
-static const char *kPrintDialogURL         = "chrome://global/content/printdialog.xul";
 static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
 static const char *kPrtPrvProgressDialogURL = "chrome://global/content/printPreviewProgress.xul";
-static const char *kPageSetupDialogURL     = "chrome://global/content/printPageSetup.xul";
-static const char *kPrinterPropertiesURL   = "chrome://global/content/printjoboptions.xul";
-
-/****************************************************************
- ************************* ParamBlock ***************************
- ****************************************************************/
-
-class ParamBlock {
-
-public:
-    ParamBlock()
-    {
-        mBlock = 0;
-    }
-    ~ParamBlock()
-    {
-        NS_IF_RELEASE(mBlock);
-    }
-    nsresult Init() {
-      return CallCreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID, &mBlock);
-    }
-    nsIDialogParamBlock * operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN { return mBlock; }
-    operator nsIDialogParamBlock * () const { return mBlock; }
-
-private:
-    nsIDialogParamBlock *mBlock;
-};
-
-/****************************************************************
- ***************** nsPrintingPromptService **********************
- ****************************************************************/
 
 NS_IMPL_ISUPPORTS(nsPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)
 
 nsPrintingPromptService::nsPrintingPromptService()
 {
 }
 
 nsPrintingPromptService::~nsPrintingPromptService()
@@ -74,31 +39,23 @@ nsPrintingPromptService::Init()
 NS_IMETHODIMP
 nsPrintingPromptService::ShowPrintDialog(mozIDOMWindowProxy *parent,
                                          nsIWebBrowserPrint *webBrowserPrint,
                                          nsIPrintSettings *printSettings)
 {
     NS_ENSURE_ARG(webBrowserPrint);
     NS_ENSURE_ARG(printSettings);
 
-    // Try to access a component dialog
     nsCOMPtr<nsIPrintDialogService> dlgPrint(do_GetService(
                                              NS_PRINTDIALOGSERVICE_CONTRACTID));
     if (dlgPrint)
       return dlgPrint->Show(nsPIDOMWindowOuter::From(parent),
                             printSettings, webBrowserPrint);
 
-    // Show the built-in dialog instead
-    ParamBlock block;
-    nsresult rv = block.Init();
-    if (NS_FAILED(rv))
-      return rv;
-
-    block->SetInt(0, 0);
-    return DoDialog(parent, block, webBrowserPrint, printSettings, kPrintDialogURL);
+    return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsPrintingPromptService::ShowProgress(mozIDOMWindowProxy*      parent,
                                       nsIWebBrowserPrint*      webBrowserPrint,    // ok to be null
                                       nsIPrintSettings*        printSettings,      // ok to be null
                                       nsIObserver*             openDialogObserver, // ok to be null
                                       bool                     isForPrinting,
@@ -138,120 +95,34 @@ nsPrintingPromptService::ShowProgress(mo
 
 NS_IMETHODIMP
 nsPrintingPromptService::ShowPageSetup(mozIDOMWindowProxy *parent,
                                        nsIPrintSettings *printSettings,
                                        nsIObserver *aObs)
 {
     NS_ENSURE_ARG(printSettings);
 
-    // Try to access a component dialog
     nsCOMPtr<nsIPrintDialogService> dlgPrint(do_GetService(
                                              NS_PRINTDIALOGSERVICE_CONTRACTID));
     if (dlgPrint)
       return dlgPrint->ShowPageSetup(nsPIDOMWindowOuter::From(parent),
                                      printSettings);
 
-    ParamBlock block;
-    nsresult rv = block.Init();
-    if (NS_FAILED(rv))
-      return rv;
-
-    block->SetInt(0, 0);
-    return DoDialog(parent, block, nullptr, printSettings, kPageSetupDialogURL);
+    return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsPrintingPromptService::ShowPrinterProperties(mozIDOMWindowProxy *parent,
                                                const char16_t *printerName,
                                                nsIPrintSettings *printSettings)
 {
-    /* fixme: We simply ignore the |aPrinter| argument here
-     * We should get the supported printer attributes from the printer and
-     * populate the print job options dialog with these data instead of using
-     * the "default set" here.
-     * However, this requires changes on all platforms and is another big chunk
-     * of patches ... ;-(
-     */
-    NS_ENSURE_ARG(printerName);
-    NS_ENSURE_ARG(printSettings);
-
-    ParamBlock block;
-    nsresult rv = block.Init();
-    if (NS_FAILED(rv))
-      return rv;
-
-    block->SetInt(0, 0);
-    return DoDialog(parent, block, nullptr, printSettings, kPrinterPropertiesURL);
+    return NS_ERROR_NOT_IMPLEMENTED;
 
 }
 
-nsresult
-nsPrintingPromptService::DoDialog(mozIDOMWindowProxy *aParent,
-                                  nsIDialogParamBlock *aParamBlock,
-                                  nsIWebBrowserPrint *aWebBrowserPrint,
-                                  nsIPrintSettings* aPS,
-                                  const char *aChromeURL)
-{
-    NS_ENSURE_ARG(aParamBlock);
-    NS_ENSURE_ARG(aPS);
-    NS_ENSURE_ARG(aChromeURL);
-
-    if (!mWatcher)
-        return NS_ERROR_FAILURE;
-
-    // get a parent, if at all possible
-    // (though we'd rather this didn't fail, it's OK if it does. so there's
-    // no failure or null check.)
-    nsCOMPtr<mozIDOMWindowProxy> activeParent;
-    if (!aParent)
-    {
-        mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
-        aParent = activeParent;
-    }
-
-    // create a nsIMutableArray of the parameters
-    // being passed to the window
-    nsCOMPtr<nsIMutableArray> array = nsArray::Create();
-
-    nsCOMPtr<nsISupports> psSupports(do_QueryInterface(aPS));
-    NS_ASSERTION(psSupports, "PrintSettings must be a supports");
-    array->AppendElement(psSupports);
-
-    if (aWebBrowserPrint) {
-      nsCOMPtr<nsISupports> wbpSupports(do_QueryInterface(aWebBrowserPrint));
-      NS_ASSERTION(wbpSupports, "nsIWebBrowserPrint must be a supports");
-      array->AppendElement(wbpSupports);
-    }
-
-    nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(aParamBlock));
-    NS_ASSERTION(blkSupps, "IOBlk must be a supports");
-    array->AppendElement(blkSupps);
-
-    nsCOMPtr<mozIDOMWindowProxy> dialog;
-    nsresult rv = mWatcher->OpenWindow(aParent, aChromeURL, "_blank",
-                              "centerscreen,chrome,modal,titlebar", array,
-                              getter_AddRefs(dialog));
-
-    // if aWebBrowserPrint is not null then we are printing
-    // so we want to pass back NS_ERROR_ABORT on cancel
-    if (NS_SUCCEEDED(rv) && aWebBrowserPrint)
-    {
-        int32_t status;
-        aParamBlock->GetInt(0, &status);
-        return status == 0?NS_ERROR_ABORT:NS_OK;
-    }
-
-    return rv;
-}
-
-//////////////////////////////////////////////////////////////////////
-// nsIWebProgressListener
-//////////////////////////////////////////////////////////////////////
-
 NS_IMETHODIMP
 nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, uint32_t aStateFlags, nsresult aStatus)
 {
   if ((aStateFlags & STATE_STOP) && mWebProgressListener) {
     mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
     if (mPrintProgress) {
       mPrintProgress->CloseProgressDialog(true);
     }
--- a/toolkit/components/printingui/unixshared/nsPrintingPromptService.h
+++ b/toolkit/components/printingui/unixshared/nsPrintingPromptService.h
@@ -14,17 +14,16 @@
 
 #include "nsCOMPtr.h"
 #include "nsIPrintingPromptService.h"
 #include "nsPIPromptService.h"
 #include "nsIWindowWatcher.h"
 
 // Printing Progress Includes
 #include "nsPrintProgress.h"
-#include "nsPrintProgressParams.h"
 #include "nsIWebProgressListener.h"
 
 class nsIDOMWindow;
 class nsIDialogParamBlock;
 
 class nsPrintingPromptService: public nsIPrintingPromptService,
                                public nsIWebProgressListener
 {
@@ -38,21 +37,15 @@ public:
   NS_DECL_NSIPRINTINGPROMPTSERVICE
   NS_DECL_NSIWEBPROGRESSLISTENER
   NS_DECL_ISUPPORTS
 
 protected:
   virtual ~nsPrintingPromptService();
 
 private:
-  nsresult DoDialog(mozIDOMWindowProxy *aParent,
-                    nsIDialogParamBlock *aParamBlock,
-                    nsIWebBrowserPrint *aWebBrowserPrint,
-                    nsIPrintSettings* aPS,
-                    const char *aChromeURL);
-
   nsCOMPtr<nsIWindowWatcher> mWatcher;
   nsCOMPtr<nsIPrintProgress> mPrintProgress;
   nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
 };
 
 #endif