Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsPrintData.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIStringBundle.h" |
michael@0 | 9 | #include "nsIServiceManager.h" |
michael@0 | 10 | #include "nsPrintObject.h" |
michael@0 | 11 | #include "nsPrintPreviewListener.h" |
michael@0 | 12 | #include "nsIWebProgressListener.h" |
michael@0 | 13 | #include "mozilla/Services.h" |
michael@0 | 14 | |
michael@0 | 15 | //----------------------------------------------------- |
michael@0 | 16 | // PR LOGGING |
michael@0 | 17 | #ifdef MOZ_LOGGING |
michael@0 | 18 | #define FORCE_PR_LOG /* Allow logging in the release build */ |
michael@0 | 19 | #endif |
michael@0 | 20 | |
michael@0 | 21 | #include "prlog.h" |
michael@0 | 22 | |
michael@0 | 23 | #ifdef PR_LOGGING |
michael@0 | 24 | #define DUMP_LAYOUT_LEVEL 9 // this turns on the dumping of each doucment's layout info |
michael@0 | 25 | static PRLogModuleInfo * |
michael@0 | 26 | GetPrintingLog() |
michael@0 | 27 | { |
michael@0 | 28 | static PRLogModuleInfo *sLog; |
michael@0 | 29 | if (!sLog) |
michael@0 | 30 | sLog = PR_NewLogModule("printing"); |
michael@0 | 31 | return sLog; |
michael@0 | 32 | } |
michael@0 | 33 | #define PR_PL(_p1) PR_LOG(GetPrintingLog(), PR_LOG_DEBUG, _p1); |
michael@0 | 34 | #else |
michael@0 | 35 | #define PRT_YESNO(_p) |
michael@0 | 36 | #define PR_PL(_p1) |
michael@0 | 37 | #endif |
michael@0 | 38 | |
michael@0 | 39 | //--------------------------------------------------- |
michael@0 | 40 | //-- nsPrintData Class Impl |
michael@0 | 41 | //--------------------------------------------------- |
michael@0 | 42 | nsPrintData::nsPrintData(ePrintDataType aType) : |
michael@0 | 43 | mType(aType), mDebugFilePtr(nullptr), mPrintObject(nullptr), mSelectedPO(nullptr), |
michael@0 | 44 | mPrintDocList(0), mIsIFrameSelected(false), |
michael@0 | 45 | mIsParentAFrameSet(false), mOnStartSent(false), |
michael@0 | 46 | mIsAborted(false), mPreparingForPrint(false), mDocWasToBeDestroyed(false), |
michael@0 | 47 | mShrinkToFit(false), mPrintFrameType(nsIPrintSettings::kFramesAsIs), |
michael@0 | 48 | mNumPrintablePages(0), mNumPagesPrinted(0), |
michael@0 | 49 | mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(nullptr), |
michael@0 | 50 | mBrandName(nullptr) |
michael@0 | 51 | { |
michael@0 | 52 | MOZ_COUNT_CTOR(nsPrintData); |
michael@0 | 53 | nsCOMPtr<nsIStringBundle> brandBundle; |
michael@0 | 54 | nsCOMPtr<nsIStringBundleService> svc = |
michael@0 | 55 | mozilla::services::GetStringBundleService(); |
michael@0 | 56 | if (svc) { |
michael@0 | 57 | svc->CreateBundle( "chrome://branding/locale/brand.properties", getter_AddRefs( brandBundle ) ); |
michael@0 | 58 | if (brandBundle) { |
michael@0 | 59 | brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"), &mBrandName ); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | if (!mBrandName) { |
michael@0 | 64 | mBrandName = ToNewUnicode(NS_LITERAL_STRING("Mozilla Document")); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | nsPrintData::~nsPrintData() |
michael@0 | 70 | { |
michael@0 | 71 | MOZ_COUNT_DTOR(nsPrintData); |
michael@0 | 72 | // remove the event listeners |
michael@0 | 73 | if (mPPEventListeners) { |
michael@0 | 74 | mPPEventListeners->RemoveListeners(); |
michael@0 | 75 | NS_RELEASE(mPPEventListeners); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | // Only Send an OnEndPrinting if we have started printing |
michael@0 | 79 | if (mOnStartSent && mType != eIsPrintPreview) { |
michael@0 | 80 | OnEndPrinting(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | if (mPrintDC && !mDebugFilePtr) { |
michael@0 | 84 | PR_PL(("****************** End Document ************************\n")); |
michael@0 | 85 | PR_PL(("\n")); |
michael@0 | 86 | bool isCancelled = false; |
michael@0 | 87 | mPrintSettings->GetIsCancelled(&isCancelled); |
michael@0 | 88 | |
michael@0 | 89 | nsresult rv = NS_OK; |
michael@0 | 90 | if (mType == eIsPrinting) { |
michael@0 | 91 | if (!isCancelled && !mIsAborted) { |
michael@0 | 92 | rv = mPrintDC->EndDocument(); |
michael@0 | 93 | } else { |
michael@0 | 94 | rv = mPrintDC->AbortDocument(); |
michael@0 | 95 | } |
michael@0 | 96 | if (NS_FAILED(rv)) { |
michael@0 | 97 | // XXX nsPrintData::ShowPrintErrorDialog(rv); |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | delete mPrintObject; |
michael@0 | 103 | |
michael@0 | 104 | if (mBrandName) { |
michael@0 | 105 | NS_Free(mBrandName); |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | void nsPrintData::OnStartPrinting() |
michael@0 | 110 | { |
michael@0 | 111 | if (!mOnStartSent) { |
michael@0 | 112 | DoOnProgressChange(0, 0, true, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT|nsIWebProgressListener::STATE_IS_NETWORK); |
michael@0 | 113 | mOnStartSent = true; |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | void nsPrintData::OnEndPrinting() |
michael@0 | 118 | { |
michael@0 | 119 | DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT); |
michael@0 | 120 | DoOnProgressChange(100, 100, true, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_NETWORK); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | void |
michael@0 | 124 | nsPrintData::DoOnProgressChange(int32_t aProgress, |
michael@0 | 125 | int32_t aMaxProgress, |
michael@0 | 126 | bool aDoStartStop, |
michael@0 | 127 | int32_t aFlag) |
michael@0 | 128 | { |
michael@0 | 129 | for (int32_t i=0;i<mPrintProgressListeners.Count();i++) { |
michael@0 | 130 | nsIWebProgressListener* wpl = mPrintProgressListeners.ObjectAt(i); |
michael@0 | 131 | wpl->OnProgressChange(nullptr, nullptr, aProgress, aMaxProgress, aProgress, aMaxProgress); |
michael@0 | 132 | if (aDoStartStop) { |
michael@0 | 133 | wpl->OnStateChange(nullptr, nullptr, aFlag, NS_OK); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 |