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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=8 et : |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "ShadowLayerParent.h" |
michael@0 | 9 | #include "Layers.h" // for Layer, ContainerLayer |
michael@0 | 10 | #include "nsDebug.h" // for NS_RUNTIMEABORT |
michael@0 | 11 | #include "nsISupportsImpl.h" // for Layer::AddRef, etc |
michael@0 | 12 | |
michael@0 | 13 | #include "mozilla/layers/ThebesLayerComposite.h" |
michael@0 | 14 | #include "mozilla/layers/CanvasLayerComposite.h" |
michael@0 | 15 | #include "mozilla/layers/ColorLayerComposite.h" |
michael@0 | 16 | #include "mozilla/layers/ImageLayerComposite.h" |
michael@0 | 17 | #include "mozilla/layers/ContainerLayerComposite.h" |
michael@0 | 18 | |
michael@0 | 19 | namespace mozilla { |
michael@0 | 20 | namespace layers { |
michael@0 | 21 | |
michael@0 | 22 | ShadowLayerParent::ShadowLayerParent() : mLayer(nullptr) |
michael@0 | 23 | { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | ShadowLayerParent::~ShadowLayerParent() |
michael@0 | 27 | { |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | void |
michael@0 | 31 | ShadowLayerParent::Bind(Layer* layer) |
michael@0 | 32 | { |
michael@0 | 33 | mLayer = layer; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | void |
michael@0 | 37 | ShadowLayerParent::Destroy() |
michael@0 | 38 | { |
michael@0 | 39 | // It's possible for Destroy() to come in just after this has been |
michael@0 | 40 | // created, but just before the transaction in which Bind() would |
michael@0 | 41 | // have been called. In that case, we'll ignore shadow-layers |
michael@0 | 42 | // transactions from there on and never get a layer here. |
michael@0 | 43 | if (mLayer) { |
michael@0 | 44 | mLayer->Disconnect(); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | ContainerLayerComposite* |
michael@0 | 49 | ShadowLayerParent::AsContainerLayerComposite() const |
michael@0 | 50 | { |
michael@0 | 51 | return mLayer && mLayer->GetType() == Layer::TYPE_CONTAINER |
michael@0 | 52 | ? static_cast<ContainerLayerComposite*>(mLayer.get()) |
michael@0 | 53 | : nullptr; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | CanvasLayerComposite* |
michael@0 | 57 | ShadowLayerParent::AsCanvasLayerComposite() const |
michael@0 | 58 | { |
michael@0 | 59 | return mLayer && mLayer->GetType() == Layer::TYPE_CANVAS |
michael@0 | 60 | ? static_cast<CanvasLayerComposite*>(mLayer.get()) |
michael@0 | 61 | : nullptr; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | ColorLayerComposite* |
michael@0 | 65 | ShadowLayerParent::AsColorLayerComposite() const |
michael@0 | 66 | { |
michael@0 | 67 | return mLayer && mLayer->GetType() == Layer::TYPE_COLOR |
michael@0 | 68 | ? static_cast<ColorLayerComposite*>(mLayer.get()) |
michael@0 | 69 | : nullptr; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | ImageLayerComposite* |
michael@0 | 73 | ShadowLayerParent::AsImageLayerComposite() const |
michael@0 | 74 | { |
michael@0 | 75 | return mLayer && mLayer->GetType() == Layer::TYPE_IMAGE |
michael@0 | 76 | ? static_cast<ImageLayerComposite*>(mLayer.get()) |
michael@0 | 77 | : nullptr; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | RefLayerComposite* |
michael@0 | 81 | ShadowLayerParent::AsRefLayerComposite() const |
michael@0 | 82 | { |
michael@0 | 83 | return mLayer && mLayer->GetType() == Layer::TYPE_REF |
michael@0 | 84 | ? static_cast<RefLayerComposite*>(mLayer.get()) |
michael@0 | 85 | : nullptr; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | ThebesLayerComposite* |
michael@0 | 89 | ShadowLayerParent::AsThebesLayerComposite() const |
michael@0 | 90 | { |
michael@0 | 91 | return mLayer && mLayer->GetType() == Layer::TYPE_THEBES |
michael@0 | 92 | ? static_cast<ThebesLayerComposite*>(mLayer.get()) |
michael@0 | 93 | : nullptr; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | void |
michael@0 | 97 | ShadowLayerParent::ActorDestroy(ActorDestroyReason why) |
michael@0 | 98 | { |
michael@0 | 99 | switch (why) { |
michael@0 | 100 | case AncestorDeletion: |
michael@0 | 101 | NS_RUNTIMEABORT("shadow layer deleted out of order!"); |
michael@0 | 102 | return; // unreached |
michael@0 | 103 | |
michael@0 | 104 | case Deletion: |
michael@0 | 105 | // See comment near Destroy() above. |
michael@0 | 106 | if (mLayer) { |
michael@0 | 107 | mLayer->Disconnect(); |
michael@0 | 108 | } |
michael@0 | 109 | break; |
michael@0 | 110 | |
michael@0 | 111 | case AbnormalShutdown: |
michael@0 | 112 | if (mLayer) { |
michael@0 | 113 | mLayer->Disconnect(); |
michael@0 | 114 | } |
michael@0 | 115 | break; |
michael@0 | 116 | |
michael@0 | 117 | case NormalShutdown: |
michael@0 | 118 | // let IPDL-generated code automatically clean up Shmems and so |
michael@0 | 119 | // forth; our channel is disconnected anyway |
michael@0 | 120 | break; |
michael@0 | 121 | |
michael@0 | 122 | case FailedConstructor: |
michael@0 | 123 | NS_RUNTIMEABORT("FailedConstructor isn't possible in PLayerTransaction"); |
michael@0 | 124 | return; // unreached |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | mLayer = nullptr; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | } // namespace layers |
michael@0 | 131 | } // namespace mozilla |