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 "InterfaceInitFuncs.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "Accessible-inl.h" |
michael@0 | 10 | #include "AccessibleWrap.h" |
michael@0 | 11 | #include "DocAccessible.h" |
michael@0 | 12 | #include "nsMai.h" |
michael@0 | 13 | #include "mozilla/Likely.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla::a11y; |
michael@0 | 16 | |
michael@0 | 17 | static const char* const kDocTypeName = "W3C-doctype"; |
michael@0 | 18 | static const char* const kDocUrlName = "DocURL"; |
michael@0 | 19 | static const char* const kMimeTypeName = "MimeType"; |
michael@0 | 20 | |
michael@0 | 21 | // below functions are vfuncs on an ATK interface so they need to be C call |
michael@0 | 22 | extern "C" { |
michael@0 | 23 | |
michael@0 | 24 | static const gchar* getDocumentLocaleCB(AtkDocument* aDocument); |
michael@0 | 25 | static AtkAttributeSet* getDocumentAttributesCB(AtkDocument* aDocument); |
michael@0 | 26 | static const gchar* getDocumentAttributeValueCB(AtkDocument* aDocument, |
michael@0 | 27 | const gchar* aAttrName); |
michael@0 | 28 | |
michael@0 | 29 | void |
michael@0 | 30 | documentInterfaceInitCB(AtkDocumentIface *aIface) |
michael@0 | 31 | { |
michael@0 | 32 | NS_ASSERTION(aIface, "Invalid Interface"); |
michael@0 | 33 | if(MOZ_UNLIKELY(!aIface)) |
michael@0 | 34 | return; |
michael@0 | 35 | |
michael@0 | 36 | /* |
michael@0 | 37 | * We don't support get_document or set_attribute right now. |
michael@0 | 38 | * get_document_type is deprecated, we return DocType in |
michael@0 | 39 | * get_document_attribute_value and get_document_attributes instead. |
michael@0 | 40 | */ |
michael@0 | 41 | aIface->get_document_attributes = getDocumentAttributesCB; |
michael@0 | 42 | aIface->get_document_attribute_value = getDocumentAttributeValueCB; |
michael@0 | 43 | aIface->get_document_locale = getDocumentLocaleCB; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | const gchar * |
michael@0 | 47 | getDocumentLocaleCB(AtkDocument *aDocument) |
michael@0 | 48 | { |
michael@0 | 49 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument)); |
michael@0 | 50 | if (!accWrap) |
michael@0 | 51 | return nullptr; |
michael@0 | 52 | |
michael@0 | 53 | nsAutoString locale; |
michael@0 | 54 | accWrap->Language(locale); |
michael@0 | 55 | return locale.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(locale); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | static inline GSList * |
michael@0 | 59 | prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue) |
michael@0 | 60 | { |
michael@0 | 61 | if (aValue.IsEmpty()) |
michael@0 | 62 | return aList; |
michael@0 | 63 | |
michael@0 | 64 | // libspi will free these |
michael@0 | 65 | AtkAttribute *atkAttr = (AtkAttribute *)g_malloc(sizeof(AtkAttribute)); |
michael@0 | 66 | atkAttr->name = g_strdup(aName); |
michael@0 | 67 | atkAttr->value = g_strdup(NS_ConvertUTF16toUTF8(aValue).get()); |
michael@0 | 68 | return g_slist_prepend(aList, atkAttr); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | AtkAttributeSet * |
michael@0 | 72 | getDocumentAttributesCB(AtkDocument *aDocument) |
michael@0 | 73 | { |
michael@0 | 74 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument)); |
michael@0 | 75 | if (!accWrap || !accWrap->IsDoc()) |
michael@0 | 76 | return nullptr; |
michael@0 | 77 | |
michael@0 | 78 | // according to atkobject.h, AtkAttributeSet is a GSList |
michael@0 | 79 | GSList* attributes = nullptr; |
michael@0 | 80 | DocAccessible* document = accWrap->AsDoc(); |
michael@0 | 81 | nsAutoString aURL; |
michael@0 | 82 | nsresult rv = document->GetURL(aURL); |
michael@0 | 83 | if (NS_SUCCEEDED(rv)) |
michael@0 | 84 | attributes = prependToList(attributes, kDocUrlName, aURL); |
michael@0 | 85 | |
michael@0 | 86 | nsAutoString aW3CDocType; |
michael@0 | 87 | rv = document->GetDocType(aW3CDocType); |
michael@0 | 88 | if (NS_SUCCEEDED(rv)) |
michael@0 | 89 | attributes = prependToList(attributes, kDocTypeName, aW3CDocType); |
michael@0 | 90 | |
michael@0 | 91 | nsAutoString aMimeType; |
michael@0 | 92 | rv = document->GetMimeType(aMimeType); |
michael@0 | 93 | if (NS_SUCCEEDED(rv)) |
michael@0 | 94 | attributes = prependToList(attributes, kMimeTypeName, aMimeType); |
michael@0 | 95 | |
michael@0 | 96 | return attributes; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | const gchar * |
michael@0 | 100 | getDocumentAttributeValueCB(AtkDocument *aDocument, |
michael@0 | 101 | const gchar *aAttrName) |
michael@0 | 102 | { |
michael@0 | 103 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument)); |
michael@0 | 104 | if (!accWrap || !accWrap->IsDoc()) |
michael@0 | 105 | return nullptr; |
michael@0 | 106 | |
michael@0 | 107 | DocAccessible* document = accWrap->AsDoc(); |
michael@0 | 108 | nsresult rv; |
michael@0 | 109 | nsAutoString attrValue; |
michael@0 | 110 | if (!strcasecmp(aAttrName, kDocTypeName)) |
michael@0 | 111 | rv = document->GetDocType(attrValue); |
michael@0 | 112 | else if (!strcasecmp(aAttrName, kDocUrlName)) |
michael@0 | 113 | rv = document->GetURL(attrValue); |
michael@0 | 114 | else if (!strcasecmp(aAttrName, kMimeTypeName)) |
michael@0 | 115 | rv = document->GetMimeType(attrValue); |
michael@0 | 116 | else |
michael@0 | 117 | return nullptr; |
michael@0 | 118 | |
michael@0 | 119 | NS_ENSURE_SUCCESS(rv, nullptr); |
michael@0 | 120 | return attrValue.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(attrValue); |
michael@0 | 121 | } |
michael@0 | 122 | } |