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: 4 -*- */ |
michael@0 | 2 | // vim:cindent:tabstop=4:expandtab:shiftwidth=4: |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsLayoutDebuggingTools.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIDocShell.h" |
michael@0 | 10 | #include "nsPIDOMWindow.h" |
michael@0 | 11 | #include "nsIContentViewer.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsIServiceManager.h" |
michael@0 | 14 | #include "nsIAtom.h" |
michael@0 | 15 | #include "nsQuickSort.h" |
michael@0 | 16 | |
michael@0 | 17 | #include "nsIContent.h" |
michael@0 | 18 | #include "nsIDocument.h" |
michael@0 | 19 | #include "nsIDOMDocument.h" |
michael@0 | 20 | |
michael@0 | 21 | #include "nsIPresShell.h" |
michael@0 | 22 | #include "nsViewManager.h" |
michael@0 | 23 | #include "nsIFrame.h" |
michael@0 | 24 | |
michael@0 | 25 | #include "nsILayoutDebugger.h" |
michael@0 | 26 | #include "nsLayoutCID.h" |
michael@0 | 27 | static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID); |
michael@0 | 28 | |
michael@0 | 29 | #include "nsISelectionController.h" |
michael@0 | 30 | #include "mozilla/dom/Element.h" |
michael@0 | 31 | #include "mozilla/Preferences.h" |
michael@0 | 32 | |
michael@0 | 33 | using namespace mozilla; |
michael@0 | 34 | |
michael@0 | 35 | static already_AddRefed<nsIContentViewer> |
michael@0 | 36 | doc_viewer(nsIDocShell *aDocShell) |
michael@0 | 37 | { |
michael@0 | 38 | if (!aDocShell) |
michael@0 | 39 | return nullptr; |
michael@0 | 40 | nsCOMPtr<nsIContentViewer> result; |
michael@0 | 41 | aDocShell->GetContentViewer(getter_AddRefs(result)); |
michael@0 | 42 | return result.forget(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | static already_AddRefed<nsIPresShell> |
michael@0 | 46 | pres_shell(nsIDocShell *aDocShell) |
michael@0 | 47 | { |
michael@0 | 48 | nsCOMPtr<nsIContentViewer> cv = doc_viewer(aDocShell); |
michael@0 | 49 | if (!cv) |
michael@0 | 50 | return nullptr; |
michael@0 | 51 | nsCOMPtr<nsIPresShell> result; |
michael@0 | 52 | cv->GetPresShell(getter_AddRefs(result)); |
michael@0 | 53 | return result.forget(); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | static nsViewManager* |
michael@0 | 57 | view_manager(nsIDocShell *aDocShell) |
michael@0 | 58 | { |
michael@0 | 59 | nsCOMPtr<nsIPresShell> shell(pres_shell(aDocShell)); |
michael@0 | 60 | if (!shell) |
michael@0 | 61 | return nullptr; |
michael@0 | 62 | return shell->GetViewManager(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | #ifdef DEBUG |
michael@0 | 66 | static already_AddRefed<nsIDocument> |
michael@0 | 67 | document(nsIDocShell *aDocShell) |
michael@0 | 68 | { |
michael@0 | 69 | nsCOMPtr<nsIContentViewer> cv(doc_viewer(aDocShell)); |
michael@0 | 70 | if (!cv) |
michael@0 | 71 | return nullptr; |
michael@0 | 72 | nsCOMPtr<nsIDOMDocument> domDoc; |
michael@0 | 73 | cv->GetDOMDocument(getter_AddRefs(domDoc)); |
michael@0 | 74 | if (!domDoc) |
michael@0 | 75 | return nullptr; |
michael@0 | 76 | nsCOMPtr<nsIDocument> result = do_QueryInterface(domDoc); |
michael@0 | 77 | return result.forget(); |
michael@0 | 78 | } |
michael@0 | 79 | #endif |
michael@0 | 80 | |
michael@0 | 81 | nsLayoutDebuggingTools::nsLayoutDebuggingTools() |
michael@0 | 82 | : mPaintFlashing(false), |
michael@0 | 83 | mPaintDumping(false), |
michael@0 | 84 | mInvalidateDumping(false), |
michael@0 | 85 | mEventDumping(false), |
michael@0 | 86 | mMotionEventDumping(false), |
michael@0 | 87 | mCrossingEventDumping(false), |
michael@0 | 88 | mReflowCounts(false) |
michael@0 | 89 | { |
michael@0 | 90 | NewURILoaded(); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | nsLayoutDebuggingTools::~nsLayoutDebuggingTools() |
michael@0 | 94 | { |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | NS_IMPL_ISUPPORTS(nsLayoutDebuggingTools, nsILayoutDebuggingTools) |
michael@0 | 98 | |
michael@0 | 99 | NS_IMETHODIMP |
michael@0 | 100 | nsLayoutDebuggingTools::Init(nsIDOMWindow *aWin) |
michael@0 | 101 | { |
michael@0 | 102 | if (!Preferences::GetService()) { |
michael@0 | 103 | return NS_ERROR_UNEXPECTED; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | { |
michael@0 | 107 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWin); |
michael@0 | 108 | if (!window) |
michael@0 | 109 | return NS_ERROR_UNEXPECTED; |
michael@0 | 110 | mDocShell = window->GetDocShell(); |
michael@0 | 111 | } |
michael@0 | 112 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_UNEXPECTED); |
michael@0 | 113 | |
michael@0 | 114 | mPaintFlashing = |
michael@0 | 115 | Preferences::GetBool("nglayout.debug.paint_flashing", mPaintFlashing); |
michael@0 | 116 | mPaintDumping = |
michael@0 | 117 | Preferences::GetBool("nglayout.debug.paint_dumping", mPaintDumping); |
michael@0 | 118 | mInvalidateDumping = |
michael@0 | 119 | Preferences::GetBool("nglayout.debug.invalidate_dumping", mInvalidateDumping); |
michael@0 | 120 | mEventDumping = |
michael@0 | 121 | Preferences::GetBool("nglayout.debug.event_dumping", mEventDumping); |
michael@0 | 122 | mMotionEventDumping = |
michael@0 | 123 | Preferences::GetBool("nglayout.debug.motion_event_dumping", |
michael@0 | 124 | mMotionEventDumping); |
michael@0 | 125 | mCrossingEventDumping = |
michael@0 | 126 | Preferences::GetBool("nglayout.debug.crossing_event_dumping", |
michael@0 | 127 | mCrossingEventDumping); |
michael@0 | 128 | mReflowCounts = |
michael@0 | 129 | Preferences::GetBool("layout.reflow.showframecounts", mReflowCounts); |
michael@0 | 130 | |
michael@0 | 131 | { |
michael@0 | 132 | nsCOMPtr<nsILayoutDebugger> ld = do_GetService(kLayoutDebuggerCID); |
michael@0 | 133 | if (ld) { |
michael@0 | 134 | ld->GetShowFrameBorders(&mVisualDebugging); |
michael@0 | 135 | ld->GetShowEventTargetFrameBorder(&mVisualEventDebugging); |
michael@0 | 136 | } |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | return NS_OK; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | NS_IMETHODIMP |
michael@0 | 143 | nsLayoutDebuggingTools::NewURILoaded() |
michael@0 | 144 | { |
michael@0 | 145 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 146 | // Reset all the state that should be reset between pages. |
michael@0 | 147 | |
michael@0 | 148 | // XXX Some of these should instead be transferred between pages! |
michael@0 | 149 | mEditorMode = false; |
michael@0 | 150 | mVisualDebugging = false; |
michael@0 | 151 | mVisualEventDebugging = false; |
michael@0 | 152 | |
michael@0 | 153 | mReflowCounts = false; |
michael@0 | 154 | |
michael@0 | 155 | ForceRefresh(); |
michael@0 | 156 | return NS_OK; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | NS_IMETHODIMP |
michael@0 | 160 | nsLayoutDebuggingTools::GetVisualDebugging(bool *aVisualDebugging) |
michael@0 | 161 | { |
michael@0 | 162 | *aVisualDebugging = mVisualDebugging; |
michael@0 | 163 | return NS_OK; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | NS_IMETHODIMP |
michael@0 | 167 | nsLayoutDebuggingTools::SetVisualDebugging(bool aVisualDebugging) |
michael@0 | 168 | { |
michael@0 | 169 | nsCOMPtr<nsILayoutDebugger> ld = do_GetService(kLayoutDebuggerCID); |
michael@0 | 170 | if (!ld) |
michael@0 | 171 | return NS_ERROR_UNEXPECTED; |
michael@0 | 172 | mVisualDebugging = aVisualDebugging; |
michael@0 | 173 | ld->SetShowFrameBorders(aVisualDebugging); |
michael@0 | 174 | ForceRefresh(); |
michael@0 | 175 | return NS_OK; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | NS_IMETHODIMP |
michael@0 | 179 | nsLayoutDebuggingTools::GetVisualEventDebugging(bool *aVisualEventDebugging) |
michael@0 | 180 | { |
michael@0 | 181 | *aVisualEventDebugging = mVisualEventDebugging; |
michael@0 | 182 | return NS_OK; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | NS_IMETHODIMP |
michael@0 | 186 | nsLayoutDebuggingTools::SetVisualEventDebugging(bool aVisualEventDebugging) |
michael@0 | 187 | { |
michael@0 | 188 | nsCOMPtr<nsILayoutDebugger> ld = do_GetService(kLayoutDebuggerCID); |
michael@0 | 189 | if (!ld) |
michael@0 | 190 | return NS_ERROR_UNEXPECTED; |
michael@0 | 191 | mVisualEventDebugging = aVisualEventDebugging; |
michael@0 | 192 | ld->SetShowEventTargetFrameBorder(aVisualEventDebugging); |
michael@0 | 193 | ForceRefresh(); |
michael@0 | 194 | return NS_OK; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | NS_IMETHODIMP |
michael@0 | 198 | nsLayoutDebuggingTools::GetPaintFlashing(bool *aPaintFlashing) |
michael@0 | 199 | { |
michael@0 | 200 | *aPaintFlashing = mPaintFlashing; |
michael@0 | 201 | return NS_OK; |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | NS_IMETHODIMP |
michael@0 | 205 | nsLayoutDebuggingTools::SetPaintFlashing(bool aPaintFlashing) |
michael@0 | 206 | { |
michael@0 | 207 | mPaintFlashing = aPaintFlashing; |
michael@0 | 208 | return SetBoolPrefAndRefresh("nglayout.debug.paint_flashing", mPaintFlashing); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | NS_IMETHODIMP |
michael@0 | 212 | nsLayoutDebuggingTools::GetPaintDumping(bool *aPaintDumping) |
michael@0 | 213 | { |
michael@0 | 214 | *aPaintDumping = mPaintDumping; |
michael@0 | 215 | return NS_OK; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | NS_IMETHODIMP |
michael@0 | 219 | nsLayoutDebuggingTools::SetPaintDumping(bool aPaintDumping) |
michael@0 | 220 | { |
michael@0 | 221 | mPaintDumping = aPaintDumping; |
michael@0 | 222 | return SetBoolPrefAndRefresh("nglayout.debug.paint_dumping", mPaintDumping); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | NS_IMETHODIMP |
michael@0 | 226 | nsLayoutDebuggingTools::GetInvalidateDumping(bool *aInvalidateDumping) |
michael@0 | 227 | { |
michael@0 | 228 | *aInvalidateDumping = mInvalidateDumping; |
michael@0 | 229 | return NS_OK; |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | NS_IMETHODIMP |
michael@0 | 233 | nsLayoutDebuggingTools::SetInvalidateDumping(bool aInvalidateDumping) |
michael@0 | 234 | { |
michael@0 | 235 | mInvalidateDumping = aInvalidateDumping; |
michael@0 | 236 | return SetBoolPrefAndRefresh("nglayout.debug.invalidate_dumping", mInvalidateDumping); |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | NS_IMETHODIMP |
michael@0 | 240 | nsLayoutDebuggingTools::GetEventDumping(bool *aEventDumping) |
michael@0 | 241 | { |
michael@0 | 242 | *aEventDumping = mEventDumping; |
michael@0 | 243 | return NS_OK; |
michael@0 | 244 | } |
michael@0 | 245 | |
michael@0 | 246 | NS_IMETHODIMP |
michael@0 | 247 | nsLayoutDebuggingTools::SetEventDumping(bool aEventDumping) |
michael@0 | 248 | { |
michael@0 | 249 | mEventDumping = aEventDumping; |
michael@0 | 250 | return SetBoolPrefAndRefresh("nglayout.debug.event_dumping", mEventDumping); |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | NS_IMETHODIMP |
michael@0 | 254 | nsLayoutDebuggingTools::GetMotionEventDumping(bool *aMotionEventDumping) |
michael@0 | 255 | { |
michael@0 | 256 | *aMotionEventDumping = mMotionEventDumping; |
michael@0 | 257 | return NS_OK; |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | NS_IMETHODIMP |
michael@0 | 261 | nsLayoutDebuggingTools::SetMotionEventDumping(bool aMotionEventDumping) |
michael@0 | 262 | { |
michael@0 | 263 | mMotionEventDumping = aMotionEventDumping; |
michael@0 | 264 | return SetBoolPrefAndRefresh("nglayout.debug.motion_event_dumping", mMotionEventDumping); |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | NS_IMETHODIMP |
michael@0 | 268 | nsLayoutDebuggingTools::GetCrossingEventDumping(bool *aCrossingEventDumping) |
michael@0 | 269 | { |
michael@0 | 270 | *aCrossingEventDumping = mCrossingEventDumping; |
michael@0 | 271 | return NS_OK; |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | NS_IMETHODIMP |
michael@0 | 275 | nsLayoutDebuggingTools::SetCrossingEventDumping(bool aCrossingEventDumping) |
michael@0 | 276 | { |
michael@0 | 277 | mCrossingEventDumping = aCrossingEventDumping; |
michael@0 | 278 | return SetBoolPrefAndRefresh("nglayout.debug.crossing_event_dumping", mCrossingEventDumping); |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | NS_IMETHODIMP |
michael@0 | 282 | nsLayoutDebuggingTools::GetReflowCounts(bool* aShow) |
michael@0 | 283 | { |
michael@0 | 284 | *aShow = mReflowCounts; |
michael@0 | 285 | return NS_OK; |
michael@0 | 286 | } |
michael@0 | 287 | |
michael@0 | 288 | NS_IMETHODIMP |
michael@0 | 289 | nsLayoutDebuggingTools::SetReflowCounts(bool aShow) |
michael@0 | 290 | { |
michael@0 | 291 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 292 | nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell)); |
michael@0 | 293 | if (shell) { |
michael@0 | 294 | #ifdef MOZ_REFLOW_PERF |
michael@0 | 295 | shell->SetPaintFrameCount(aShow); |
michael@0 | 296 | SetBoolPrefAndRefresh("layout.reflow.showframecounts", aShow); |
michael@0 | 297 | mReflowCounts = aShow; |
michael@0 | 298 | #else |
michael@0 | 299 | printf("************************************************\n"); |
michael@0 | 300 | printf("Sorry, you have not built with MOZ_REFLOW_PERF=1\n"); |
michael@0 | 301 | printf("************************************************\n"); |
michael@0 | 302 | #endif |
michael@0 | 303 | } |
michael@0 | 304 | return NS_OK; |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | static void DumpAWebShell(nsIDocShellTreeItem* aShellItem, FILE* out, int32_t aIndent) |
michael@0 | 308 | { |
michael@0 | 309 | nsString name; |
michael@0 | 310 | nsCOMPtr<nsIDocShellTreeItem> parent; |
michael@0 | 311 | int32_t i, n; |
michael@0 | 312 | |
michael@0 | 313 | for (i = aIndent; --i >= 0; ) |
michael@0 | 314 | fprintf(out, " "); |
michael@0 | 315 | |
michael@0 | 316 | fprintf(out, "%p '", static_cast<void*>(aShellItem)); |
michael@0 | 317 | aShellItem->GetName(name); |
michael@0 | 318 | aShellItem->GetSameTypeParent(getter_AddRefs(parent)); |
michael@0 | 319 | fputs(NS_LossyConvertUTF16toASCII(name).get(), out); |
michael@0 | 320 | fprintf(out, "' parent=%p <\n", static_cast<void*>(parent)); |
michael@0 | 321 | |
michael@0 | 322 | ++aIndent; |
michael@0 | 323 | aShellItem->GetChildCount(&n); |
michael@0 | 324 | for (i = 0; i < n; ++i) { |
michael@0 | 325 | nsCOMPtr<nsIDocShellTreeItem> child; |
michael@0 | 326 | aShellItem->GetChildAt(i, getter_AddRefs(child)); |
michael@0 | 327 | if (child) { |
michael@0 | 328 | DumpAWebShell(child, out, aIndent); |
michael@0 | 329 | } |
michael@0 | 330 | } |
michael@0 | 331 | --aIndent; |
michael@0 | 332 | for (i = aIndent; --i >= 0; ) |
michael@0 | 333 | fprintf(out, " "); |
michael@0 | 334 | fputs(">\n", out); |
michael@0 | 335 | } |
michael@0 | 336 | |
michael@0 | 337 | NS_IMETHODIMP |
michael@0 | 338 | nsLayoutDebuggingTools::DumpWebShells() |
michael@0 | 339 | { |
michael@0 | 340 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 341 | DumpAWebShell(mDocShell, stdout, 0); |
michael@0 | 342 | return NS_OK; |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | static |
michael@0 | 346 | void |
michael@0 | 347 | DumpContentRecur(nsIDocShell* aDocShell, FILE* out) |
michael@0 | 348 | { |
michael@0 | 349 | #ifdef DEBUG |
michael@0 | 350 | if (nullptr != aDocShell) { |
michael@0 | 351 | fprintf(out, "docshell=%p \n", static_cast<void*>(aDocShell)); |
michael@0 | 352 | nsCOMPtr<nsIDocument> doc(document(aDocShell)); |
michael@0 | 353 | if (doc) { |
michael@0 | 354 | dom::Element *root = doc->GetRootElement(); |
michael@0 | 355 | if (root) { |
michael@0 | 356 | root->List(out); |
michael@0 | 357 | } |
michael@0 | 358 | } |
michael@0 | 359 | else { |
michael@0 | 360 | fputs("no document\n", out); |
michael@0 | 361 | } |
michael@0 | 362 | // dump the frames of the sub documents |
michael@0 | 363 | int32_t i, n; |
michael@0 | 364 | aDocShell->GetChildCount(&n); |
michael@0 | 365 | for (i = 0; i < n; ++i) { |
michael@0 | 366 | nsCOMPtr<nsIDocShellTreeItem> child; |
michael@0 | 367 | aDocShell->GetChildAt(i, getter_AddRefs(child)); |
michael@0 | 368 | nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child)); |
michael@0 | 369 | if (child) { |
michael@0 | 370 | DumpContentRecur(childAsShell, out); |
michael@0 | 371 | } |
michael@0 | 372 | } |
michael@0 | 373 | } |
michael@0 | 374 | #endif |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | NS_IMETHODIMP |
michael@0 | 378 | nsLayoutDebuggingTools::DumpContent() |
michael@0 | 379 | { |
michael@0 | 380 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 381 | DumpContentRecur(mDocShell, stdout); |
michael@0 | 382 | return NS_OK; |
michael@0 | 383 | } |
michael@0 | 384 | |
michael@0 | 385 | static void |
michael@0 | 386 | DumpFramesRecur(nsIDocShell* aDocShell, FILE* out) |
michael@0 | 387 | { |
michael@0 | 388 | #ifdef DEBUG |
michael@0 | 389 | fprintf(out, "webshell=%p \n", static_cast<void*>(aDocShell)); |
michael@0 | 390 | nsCOMPtr<nsIPresShell> shell(pres_shell(aDocShell)); |
michael@0 | 391 | if (shell) { |
michael@0 | 392 | nsIFrame* root = shell->GetRootFrame(); |
michael@0 | 393 | if (root) { |
michael@0 | 394 | root->List(out); |
michael@0 | 395 | } |
michael@0 | 396 | } |
michael@0 | 397 | else { |
michael@0 | 398 | fputs("null pres shell\n", out); |
michael@0 | 399 | } |
michael@0 | 400 | |
michael@0 | 401 | // dump the frames of the sub documents |
michael@0 | 402 | int32_t i, n; |
michael@0 | 403 | aDocShell->GetChildCount(&n); |
michael@0 | 404 | for (i = 0; i < n; ++i) { |
michael@0 | 405 | nsCOMPtr<nsIDocShellTreeItem> child; |
michael@0 | 406 | aDocShell->GetChildAt(i, getter_AddRefs(child)); |
michael@0 | 407 | nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child)); |
michael@0 | 408 | if (childAsShell) { |
michael@0 | 409 | DumpFramesRecur(childAsShell, out); |
michael@0 | 410 | } |
michael@0 | 411 | } |
michael@0 | 412 | #endif |
michael@0 | 413 | } |
michael@0 | 414 | |
michael@0 | 415 | NS_IMETHODIMP |
michael@0 | 416 | nsLayoutDebuggingTools::DumpFrames() |
michael@0 | 417 | { |
michael@0 | 418 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 419 | DumpFramesRecur(mDocShell, stdout); |
michael@0 | 420 | return NS_OK; |
michael@0 | 421 | } |
michael@0 | 422 | |
michael@0 | 423 | static |
michael@0 | 424 | void |
michael@0 | 425 | DumpViewsRecur(nsIDocShell* aDocShell, FILE* out) |
michael@0 | 426 | { |
michael@0 | 427 | #ifdef DEBUG |
michael@0 | 428 | fprintf(out, "docshell=%p \n", static_cast<void*>(aDocShell)); |
michael@0 | 429 | nsRefPtr<nsViewManager> vm(view_manager(aDocShell)); |
michael@0 | 430 | if (vm) { |
michael@0 | 431 | nsView* root = vm->GetRootView(); |
michael@0 | 432 | if (root) { |
michael@0 | 433 | root->List(out); |
michael@0 | 434 | } |
michael@0 | 435 | } |
michael@0 | 436 | else { |
michael@0 | 437 | fputs("null view manager\n", out); |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | // dump the views of the sub documents |
michael@0 | 441 | int32_t i, n; |
michael@0 | 442 | aDocShell->GetChildCount(&n); |
michael@0 | 443 | for (i = 0; i < n; i++) { |
michael@0 | 444 | nsCOMPtr<nsIDocShellTreeItem> child; |
michael@0 | 445 | aDocShell->GetChildAt(i, getter_AddRefs(child)); |
michael@0 | 446 | nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child)); |
michael@0 | 447 | if (childAsShell) { |
michael@0 | 448 | DumpViewsRecur(childAsShell, out); |
michael@0 | 449 | } |
michael@0 | 450 | } |
michael@0 | 451 | #endif // DEBUG |
michael@0 | 452 | } |
michael@0 | 453 | |
michael@0 | 454 | NS_IMETHODIMP |
michael@0 | 455 | nsLayoutDebuggingTools::DumpViews() |
michael@0 | 456 | { |
michael@0 | 457 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 458 | DumpViewsRecur(mDocShell, stdout); |
michael@0 | 459 | return NS_OK; |
michael@0 | 460 | } |
michael@0 | 461 | |
michael@0 | 462 | NS_IMETHODIMP |
michael@0 | 463 | nsLayoutDebuggingTools::DumpStyleSheets() |
michael@0 | 464 | { |
michael@0 | 465 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 466 | #ifdef DEBUG |
michael@0 | 467 | FILE *out = stdout; |
michael@0 | 468 | nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell)); |
michael@0 | 469 | if (shell) |
michael@0 | 470 | shell->ListStyleSheets(out); |
michael@0 | 471 | else |
michael@0 | 472 | fputs("null pres shell\n", out); |
michael@0 | 473 | #endif |
michael@0 | 474 | return NS_OK; |
michael@0 | 475 | } |
michael@0 | 476 | |
michael@0 | 477 | NS_IMETHODIMP |
michael@0 | 478 | nsLayoutDebuggingTools::DumpStyleContexts() |
michael@0 | 479 | { |
michael@0 | 480 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 481 | #ifdef DEBUG |
michael@0 | 482 | FILE *out = stdout; |
michael@0 | 483 | nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell)); |
michael@0 | 484 | if (shell) { |
michael@0 | 485 | nsIFrame* root = shell->GetRootFrame(); |
michael@0 | 486 | if (!root) { |
michael@0 | 487 | fputs("null root frame\n", out); |
michael@0 | 488 | } else { |
michael@0 | 489 | shell->ListStyleContexts(root, out); |
michael@0 | 490 | } |
michael@0 | 491 | } else { |
michael@0 | 492 | fputs("null pres shell\n", out); |
michael@0 | 493 | } |
michael@0 | 494 | #endif |
michael@0 | 495 | return NS_OK; |
michael@0 | 496 | } |
michael@0 | 497 | |
michael@0 | 498 | NS_IMETHODIMP |
michael@0 | 499 | nsLayoutDebuggingTools::DumpReflowStats() |
michael@0 | 500 | { |
michael@0 | 501 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 502 | #ifdef DEBUG |
michael@0 | 503 | nsCOMPtr<nsIPresShell> shell(pres_shell(mDocShell)); |
michael@0 | 504 | if (shell) { |
michael@0 | 505 | #ifdef MOZ_REFLOW_PERF |
michael@0 | 506 | shell->DumpReflows(); |
michael@0 | 507 | #else |
michael@0 | 508 | printf("************************************************\n"); |
michael@0 | 509 | printf("Sorry, you have not built with MOZ_REFLOW_PERF=1\n"); |
michael@0 | 510 | printf("************************************************\n"); |
michael@0 | 511 | #endif |
michael@0 | 512 | } |
michael@0 | 513 | #endif |
michael@0 | 514 | return NS_OK; |
michael@0 | 515 | } |
michael@0 | 516 | |
michael@0 | 517 | void nsLayoutDebuggingTools::ForceRefresh() |
michael@0 | 518 | { |
michael@0 | 519 | nsRefPtr<nsViewManager> vm(view_manager(mDocShell)); |
michael@0 | 520 | if (!vm) |
michael@0 | 521 | return; |
michael@0 | 522 | nsView* root = vm->GetRootView(); |
michael@0 | 523 | if (root) { |
michael@0 | 524 | vm->InvalidateView(root); |
michael@0 | 525 | } |
michael@0 | 526 | } |
michael@0 | 527 | |
michael@0 | 528 | nsresult |
michael@0 | 529 | nsLayoutDebuggingTools::SetBoolPrefAndRefresh(const char * aPrefName, |
michael@0 | 530 | bool aNewVal) |
michael@0 | 531 | { |
michael@0 | 532 | NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 533 | |
michael@0 | 534 | nsIPrefService* prefService = Preferences::GetService(); |
michael@0 | 535 | NS_ENSURE_TRUE(prefService && aPrefName, NS_OK); |
michael@0 | 536 | |
michael@0 | 537 | Preferences::SetBool(aPrefName, aNewVal); |
michael@0 | 538 | prefService->SavePrefFile(nullptr); |
michael@0 | 539 | |
michael@0 | 540 | ForceRefresh(); |
michael@0 | 541 | |
michael@0 | 542 | return NS_OK; |
michael@0 | 543 | } |