Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; 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 "nsISupports.h" |
michael@0 | 7 | #include "nsRegressionTester.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "nsXPIDLString.h" |
michael@0 | 10 | #include "nsReadableUtils.h" |
michael@0 | 11 | #include "nsIWindowWatcher.h" |
michael@0 | 12 | #include "nsPIDOMWindow.h" |
michael@0 | 13 | #include "nsIPresShell.h" |
michael@0 | 14 | #include "nsIURI.h" |
michael@0 | 15 | #include "nsISimpleEnumerator.h" |
michael@0 | 16 | #include "nsIDocShell.h" |
michael@0 | 17 | #include "nsIContentViewer.h" |
michael@0 | 18 | #include "nsIContentViewerFile.h" |
michael@0 | 19 | #include "nsIFrame.h" |
michael@0 | 20 | #include "nsStyleStruct.h" |
michael@0 | 21 | #include "nsIFrameUtil.h" |
michael@0 | 22 | #include "nsLayoutCID.h" |
michael@0 | 23 | #include "nsNetUtil.h" |
michael@0 | 24 | #include "nsIFile.h" |
michael@0 | 25 | #include "nsViewManager.h" |
michael@0 | 26 | #include "nsView.h" |
michael@0 | 27 | |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | static NS_DEFINE_CID(kFrameUtilCID, NS_FRAME_UTIL_CID); |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | nsRegressionTester::nsRegressionTester() |
michael@0 | 34 | { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | nsRegressionTester::~nsRegressionTester() |
michael@0 | 38 | { |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | NS_IMPL_ISUPPORTS(nsRegressionTester, nsILayoutRegressionTester) |
michael@0 | 42 | |
michael@0 | 43 | NS_IMETHODIMP |
michael@0 | 44 | nsRegressionTester::DumpFrameModel(nsIDOMWindow *aWindowToDump, |
michael@0 | 45 | nsIFile *aDestFile, |
michael@0 | 46 | uint32_t aFlagsMask, int32_t *aResult) |
michael@0 | 47 | { |
michael@0 | 48 | NS_ENSURE_ARG(aWindowToDump); |
michael@0 | 49 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 50 | |
michael@0 | 51 | *aResult = DUMP_RESULT_ERROR; |
michael@0 | 52 | |
michael@0 | 53 | #ifndef DEBUG |
michael@0 | 54 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 55 | #else |
michael@0 | 56 | nsresult rv = NS_ERROR_NOT_AVAILABLE; |
michael@0 | 57 | uint32_t busyFlags; |
michael@0 | 58 | bool stillLoading; |
michael@0 | 59 | |
michael@0 | 60 | nsCOMPtr<nsIDocShell> docShell; |
michael@0 | 61 | rv = GetDocShellFromWindow(aWindowToDump, getter_AddRefs(docShell)); |
michael@0 | 62 | if (NS_FAILED(rv)) return rv; |
michael@0 | 63 | |
michael@0 | 64 | // find out if the document is loaded |
michael@0 | 65 | docShell->GetBusyFlags(&busyFlags); |
michael@0 | 66 | stillLoading = busyFlags & (nsIDocShell::BUSY_FLAGS_BUSY | |
michael@0 | 67 | nsIDocShell::BUSY_FLAGS_PAGE_LOADING); |
michael@0 | 68 | if (stillLoading) |
michael@0 | 69 | { |
michael@0 | 70 | *aResult = DUMP_RESULT_LOADING; |
michael@0 | 71 | return NS_OK; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell(); |
michael@0 | 75 | |
michael@0 | 76 | nsIFrame* root = presShell->GetRootFrame(); |
michael@0 | 77 | |
michael@0 | 78 | FILE* fp = stdout; |
michael@0 | 79 | if (aDestFile) |
michael@0 | 80 | { |
michael@0 | 81 | rv = aDestFile->OpenANSIFileDesc("w", &fp); |
michael@0 | 82 | if (NS_FAILED(rv)) return rv; |
michael@0 | 83 | } |
michael@0 | 84 | if (aFlagsMask & DUMP_FLAGS_MASK_PRINT_MODE) { |
michael@0 | 85 | nsCOMPtr <nsIContentViewer> viewer; |
michael@0 | 86 | docShell->GetContentViewer(getter_AddRefs(viewer)); |
michael@0 | 87 | if (viewer){ |
michael@0 | 88 | nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer); |
michael@0 | 89 | if (viewerFile) { |
michael@0 | 90 | viewerFile->Print(true, fp, nullptr); |
michael@0 | 91 | } |
michael@0 | 92 | } |
michael@0 | 93 | } |
michael@0 | 94 | else { |
michael@0 | 95 | root->DumpRegressionData(presShell->GetPresContext(), fp, 0); |
michael@0 | 96 | } |
michael@0 | 97 | if (fp != stdout) |
michael@0 | 98 | fclose(fp); |
michael@0 | 99 | *aResult = DUMP_RESULT_COMPLETED; |
michael@0 | 100 | return NS_OK; |
michael@0 | 101 | #endif |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | NS_IMETHODIMP |
michael@0 | 105 | nsRegressionTester::CompareFrameModels(nsIFile *aBaseFile, nsIFile *aVerFile, |
michael@0 | 106 | uint32_t aFlags, bool *aResult) |
michael@0 | 107 | { |
michael@0 | 108 | NS_ENSURE_ARG(aBaseFile); |
michael@0 | 109 | NS_ENSURE_ARG(aVerFile); |
michael@0 | 110 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 111 | |
michael@0 | 112 | *aResult = false; |
michael@0 | 113 | |
michael@0 | 114 | nsresult rv; |
michael@0 | 115 | FILE* baseFile; |
michael@0 | 116 | rv = aBaseFile->OpenANSIFileDesc("r", &baseFile); |
michael@0 | 117 | if (NS_FAILED(rv)) return rv; |
michael@0 | 118 | |
michael@0 | 119 | FILE* verFile; |
michael@0 | 120 | rv = aVerFile->OpenANSIFileDesc("r", &verFile); |
michael@0 | 121 | if (NS_FAILED(rv)) { |
michael@0 | 122 | fclose(baseFile); |
michael@0 | 123 | return rv; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | nsCOMPtr<nsIFrameUtil> frameUtil = do_CreateInstance(kFrameUtilCID, &rv); |
michael@0 | 127 | if (NS_SUCCEEDED(rv)) |
michael@0 | 128 | { |
michael@0 | 129 | int32_t outputLevel = (aFlags == COMPARE_FLAGS_VERBOSE) ? 0 : 1; |
michael@0 | 130 | rv = frameUtil->CompareRegressionData(baseFile, verFile, outputLevel); |
michael@0 | 131 | // CompareRegressionData closes |baseFile| and |verFile|. |
michael@0 | 132 | } else { |
michael@0 | 133 | fclose(verFile); |
michael@0 | 134 | fclose(baseFile); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | *aResult = NS_FAILED(rv); |
michael@0 | 138 | return NS_OK; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | nsresult |
michael@0 | 142 | nsRegressionTester::GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell** outShell) |
michael@0 | 143 | { |
michael@0 | 144 | nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(inWindow)); |
michael@0 | 145 | if (!window) return NS_ERROR_FAILURE; |
michael@0 | 146 | |
michael@0 | 147 | *outShell = window->GetDocShell(); |
michael@0 | 148 | NS_IF_ADDREF(*outShell); |
michael@0 | 149 | |
michael@0 | 150 | return NS_OK; |
michael@0 | 151 | } |