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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
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 <atk/atk.h> |
michael@0 | 8 | #include "AtkSocketAccessible.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "InterfaceInitFuncs.h" |
michael@0 | 11 | #include "nsMai.h" |
michael@0 | 12 | #include "mozilla/Likely.h" |
michael@0 | 13 | |
michael@0 | 14 | using namespace mozilla::a11y; |
michael@0 | 15 | |
michael@0 | 16 | AtkSocketEmbedType AtkSocketAccessible::g_atk_socket_embed = nullptr; |
michael@0 | 17 | GType AtkSocketAccessible::g_atk_socket_type = G_TYPE_INVALID; |
michael@0 | 18 | const char* AtkSocketAccessible::sATKSocketEmbedSymbol = "atk_socket_embed"; |
michael@0 | 19 | const char* AtkSocketAccessible::sATKSocketGetTypeSymbol = "atk_socket_get_type"; |
michael@0 | 20 | |
michael@0 | 21 | bool AtkSocketAccessible::gCanEmbed = FALSE; |
michael@0 | 22 | |
michael@0 | 23 | extern "C" void mai_atk_component_iface_init(AtkComponentIface* aIface); |
michael@0 | 24 | extern "C" GType mai_atk_socket_get_type(void); |
michael@0 | 25 | |
michael@0 | 26 | /* MaiAtkSocket */ |
michael@0 | 27 | |
michael@0 | 28 | #define MAI_TYPE_ATK_SOCKET (mai_atk_socket_get_type ()) |
michael@0 | 29 | #define MAI_ATK_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ |
michael@0 | 30 | MAI_TYPE_ATK_SOCKET, MaiAtkSocket)) |
michael@0 | 31 | #define MAI_IS_ATK_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ |
michael@0 | 32 | MAI_TYPE_ATK_SOCKET)) |
michael@0 | 33 | #define MAI_ATK_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\ |
michael@0 | 34 | MAI_TYPE_ATK_SOCKET,\ |
michael@0 | 35 | MaiAtkSocketClass)) |
michael@0 | 36 | #define MAI_IS_ATK_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\ |
michael@0 | 37 | MAI_TYPE_ATK_SOCKET)) |
michael@0 | 38 | #define MAI_ATK_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\ |
michael@0 | 39 | MAI_TYPE_ATK_SOCKET,\ |
michael@0 | 40 | MaiAtkSocketClass)) |
michael@0 | 41 | |
michael@0 | 42 | typedef struct _MaiAtkSocket |
michael@0 | 43 | { |
michael@0 | 44 | AtkSocket parent; |
michael@0 | 45 | |
michael@0 | 46 | AccessibleWrap* accWrap; |
michael@0 | 47 | } MaiAtkSocket; |
michael@0 | 48 | |
michael@0 | 49 | typedef struct _MaiAtkSocketClass |
michael@0 | 50 | { |
michael@0 | 51 | AtkSocketClass parent_class; |
michael@0 | 52 | } MaiAtkSocketClass; |
michael@0 | 53 | |
michael@0 | 54 | G_DEFINE_TYPE_EXTENDED(MaiAtkSocket, mai_atk_socket, |
michael@0 | 55 | AtkSocketAccessible::g_atk_socket_type, 0, |
michael@0 | 56 | G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT, |
michael@0 | 57 | mai_atk_component_iface_init)) |
michael@0 | 58 | |
michael@0 | 59 | void |
michael@0 | 60 | mai_atk_socket_class_init(MaiAtkSocketClass* aAcc) |
michael@0 | 61 | { |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | void |
michael@0 | 65 | mai_atk_socket_init(MaiAtkSocket* aAcc) |
michael@0 | 66 | { |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | static AtkObject* |
michael@0 | 70 | mai_atk_socket_new(AccessibleWrap* aAccWrap) |
michael@0 | 71 | { |
michael@0 | 72 | NS_ENSURE_TRUE(aAccWrap, nullptr); |
michael@0 | 73 | |
michael@0 | 74 | MaiAtkSocket* acc = nullptr; |
michael@0 | 75 | acc = static_cast<MaiAtkSocket*>(g_object_new(MAI_TYPE_ATK_SOCKET, nullptr)); |
michael@0 | 76 | NS_ENSURE_TRUE(acc, nullptr); |
michael@0 | 77 | |
michael@0 | 78 | acc->accWrap = aAccWrap; |
michael@0 | 79 | return ATK_OBJECT(acc); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | extern "C" { |
michael@0 | 83 | static AtkObject* |
michael@0 | 84 | RefAccessibleAtPoint(AtkComponent* aComponent, gint aX, gint aY, |
michael@0 | 85 | AtkCoordType aCoordType) |
michael@0 | 86 | { |
michael@0 | 87 | NS_ENSURE_TRUE(MAI_IS_ATK_SOCKET(aComponent), nullptr); |
michael@0 | 88 | |
michael@0 | 89 | return refAccessibleAtPointHelper(MAI_ATK_SOCKET(aComponent)->accWrap, |
michael@0 | 90 | aX, aY, aCoordType); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | static void |
michael@0 | 94 | GetExtents(AtkComponent* aComponent, gint* aX, gint* aY, gint* aWidth, |
michael@0 | 95 | gint* aHeight, AtkCoordType aCoordType) |
michael@0 | 96 | { |
michael@0 | 97 | *aX = *aY = *aWidth = *aHeight = 0; |
michael@0 | 98 | |
michael@0 | 99 | if (!MAI_IS_ATK_SOCKET(aComponent)) |
michael@0 | 100 | return; |
michael@0 | 101 | |
michael@0 | 102 | getExtentsHelper(MAI_ATK_SOCKET(aComponent)->accWrap, |
michael@0 | 103 | aX, aY, aWidth, aHeight, aCoordType); |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | void |
michael@0 | 108 | mai_atk_component_iface_init(AtkComponentIface* aIface) |
michael@0 | 109 | { |
michael@0 | 110 | NS_ASSERTION(aIface, "Invalid Interface"); |
michael@0 | 111 | if (MOZ_UNLIKELY(!aIface)) |
michael@0 | 112 | return; |
michael@0 | 113 | |
michael@0 | 114 | aIface->ref_accessible_at_point = RefAccessibleAtPoint; |
michael@0 | 115 | aIface->get_extents = GetExtents; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | AtkSocketAccessible::AtkSocketAccessible(nsIContent* aContent, |
michael@0 | 119 | DocAccessible* aDoc, |
michael@0 | 120 | const nsCString& aPlugId) : |
michael@0 | 121 | AccessibleWrap(aContent, aDoc) |
michael@0 | 122 | { |
michael@0 | 123 | mAtkObject = mai_atk_socket_new(this); |
michael@0 | 124 | if (!mAtkObject) |
michael@0 | 125 | return; |
michael@0 | 126 | |
michael@0 | 127 | // Embeds the children of an AtkPlug, specified by plugId, as the children of |
michael@0 | 128 | // this socket. |
michael@0 | 129 | // Using G_TYPE macros instead of ATK_SOCKET macros to avoid undefined |
michael@0 | 130 | // symbols. |
michael@0 | 131 | if (gCanEmbed && G_TYPE_CHECK_INSTANCE_TYPE(mAtkObject, g_atk_socket_type) && |
michael@0 | 132 | !aPlugId.IsVoid()) { |
michael@0 | 133 | AtkSocket* accSocket = |
michael@0 | 134 | G_TYPE_CHECK_INSTANCE_CAST(mAtkObject, g_atk_socket_type, AtkSocket); |
michael@0 | 135 | g_atk_socket_embed(accSocket, (gchar*)aPlugId.get()); |
michael@0 | 136 | } |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | NS_IMETHODIMP |
michael@0 | 140 | AtkSocketAccessible::GetNativeInterface(void** aOutAccessible) |
michael@0 | 141 | { |
michael@0 | 142 | *aOutAccessible = mAtkObject; |
michael@0 | 143 | return NS_OK; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | void |
michael@0 | 147 | AtkSocketAccessible::Shutdown() |
michael@0 | 148 | { |
michael@0 | 149 | if (mAtkObject) { |
michael@0 | 150 | if (MAI_IS_ATK_SOCKET(mAtkObject)) |
michael@0 | 151 | MAI_ATK_SOCKET(mAtkObject)->accWrap = nullptr; |
michael@0 | 152 | g_object_unref(mAtkObject); |
michael@0 | 153 | mAtkObject = nullptr; |
michael@0 | 154 | } |
michael@0 | 155 | AccessibleWrap::Shutdown(); |
michael@0 | 156 | } |