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.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.h"
7 #include "nsRegressionTester.h"
9 #include "nsXPIDLString.h"
10 #include "nsReadableUtils.h"
11 #include "nsIWindowWatcher.h"
12 #include "nsPIDOMWindow.h"
13 #include "nsIPresShell.h"
14 #include "nsIURI.h"
15 #include "nsISimpleEnumerator.h"
16 #include "nsIDocShell.h"
17 #include "nsIContentViewer.h"
18 #include "nsIContentViewerFile.h"
19 #include "nsIFrame.h"
20 #include "nsStyleStruct.h"
21 #include "nsIFrameUtil.h"
22 #include "nsLayoutCID.h"
23 #include "nsNetUtil.h"
24 #include "nsIFile.h"
25 #include "nsViewManager.h"
26 #include "nsView.h"
30 static NS_DEFINE_CID(kFrameUtilCID, NS_FRAME_UTIL_CID);
33 nsRegressionTester::nsRegressionTester()
34 {
35 }
37 nsRegressionTester::~nsRegressionTester()
38 {
39 }
41 NS_IMPL_ISUPPORTS(nsRegressionTester, nsILayoutRegressionTester)
43 NS_IMETHODIMP
44 nsRegressionTester::DumpFrameModel(nsIDOMWindow *aWindowToDump,
45 nsIFile *aDestFile,
46 uint32_t aFlagsMask, int32_t *aResult)
47 {
48 NS_ENSURE_ARG(aWindowToDump);
49 NS_ENSURE_ARG_POINTER(aResult);
51 *aResult = DUMP_RESULT_ERROR;
53 #ifndef DEBUG
54 return NS_ERROR_NOT_AVAILABLE;
55 #else
56 nsresult rv = NS_ERROR_NOT_AVAILABLE;
57 uint32_t busyFlags;
58 bool stillLoading;
60 nsCOMPtr<nsIDocShell> docShell;
61 rv = GetDocShellFromWindow(aWindowToDump, getter_AddRefs(docShell));
62 if (NS_FAILED(rv)) return rv;
64 // find out if the document is loaded
65 docShell->GetBusyFlags(&busyFlags);
66 stillLoading = busyFlags & (nsIDocShell::BUSY_FLAGS_BUSY |
67 nsIDocShell::BUSY_FLAGS_PAGE_LOADING);
68 if (stillLoading)
69 {
70 *aResult = DUMP_RESULT_LOADING;
71 return NS_OK;
72 }
74 nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
76 nsIFrame* root = presShell->GetRootFrame();
78 FILE* fp = stdout;
79 if (aDestFile)
80 {
81 rv = aDestFile->OpenANSIFileDesc("w", &fp);
82 if (NS_FAILED(rv)) return rv;
83 }
84 if (aFlagsMask & DUMP_FLAGS_MASK_PRINT_MODE) {
85 nsCOMPtr <nsIContentViewer> viewer;
86 docShell->GetContentViewer(getter_AddRefs(viewer));
87 if (viewer){
88 nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
89 if (viewerFile) {
90 viewerFile->Print(true, fp, nullptr);
91 }
92 }
93 }
94 else {
95 root->DumpRegressionData(presShell->GetPresContext(), fp, 0);
96 }
97 if (fp != stdout)
98 fclose(fp);
99 *aResult = DUMP_RESULT_COMPLETED;
100 return NS_OK;
101 #endif
102 }
104 NS_IMETHODIMP
105 nsRegressionTester::CompareFrameModels(nsIFile *aBaseFile, nsIFile *aVerFile,
106 uint32_t aFlags, bool *aResult)
107 {
108 NS_ENSURE_ARG(aBaseFile);
109 NS_ENSURE_ARG(aVerFile);
110 NS_ENSURE_ARG_POINTER(aResult);
112 *aResult = false;
114 nsresult rv;
115 FILE* baseFile;
116 rv = aBaseFile->OpenANSIFileDesc("r", &baseFile);
117 if (NS_FAILED(rv)) return rv;
119 FILE* verFile;
120 rv = aVerFile->OpenANSIFileDesc("r", &verFile);
121 if (NS_FAILED(rv)) {
122 fclose(baseFile);
123 return rv;
124 }
126 nsCOMPtr<nsIFrameUtil> frameUtil = do_CreateInstance(kFrameUtilCID, &rv);
127 if (NS_SUCCEEDED(rv))
128 {
129 int32_t outputLevel = (aFlags == COMPARE_FLAGS_VERBOSE) ? 0 : 1;
130 rv = frameUtil->CompareRegressionData(baseFile, verFile, outputLevel);
131 // CompareRegressionData closes |baseFile| and |verFile|.
132 } else {
133 fclose(verFile);
134 fclose(baseFile);
135 }
137 *aResult = NS_FAILED(rv);
138 return NS_OK;
139 }
141 nsresult
142 nsRegressionTester::GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell** outShell)
143 {
144 nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(inWindow));
145 if (!window) return NS_ERROR_FAILURE;
147 *outShell = window->GetDocShell();
148 NS_IF_ADDREF(*outShell);
150 return NS_OK;
151 }