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 "HyperTextAccessible-inl.h" |
michael@0 | 11 | #include "nsMai.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsString.h" |
michael@0 | 14 | #include "mozilla/Likely.h" |
michael@0 | 15 | |
michael@0 | 16 | using namespace mozilla::a11y; |
michael@0 | 17 | |
michael@0 | 18 | extern "C" { |
michael@0 | 19 | static void |
michael@0 | 20 | setTextContentsCB(AtkEditableText *aText, const gchar *aString) |
michael@0 | 21 | { |
michael@0 | 22 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 23 | if (!accWrap) |
michael@0 | 24 | return; |
michael@0 | 25 | |
michael@0 | 26 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 27 | if (!text || !text->IsTextRole()) |
michael@0 | 28 | return; |
michael@0 | 29 | |
michael@0 | 30 | NS_ConvertUTF8toUTF16 strContent(aString); |
michael@0 | 31 | text->ReplaceText(strContent); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | static void |
michael@0 | 35 | insertTextCB(AtkEditableText *aText, |
michael@0 | 36 | const gchar *aString, gint aLength, gint *aPosition) |
michael@0 | 37 | { |
michael@0 | 38 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 39 | if (!accWrap) |
michael@0 | 40 | return; |
michael@0 | 41 | |
michael@0 | 42 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 43 | if (!text || !text->IsTextRole()) |
michael@0 | 44 | return; |
michael@0 | 45 | |
michael@0 | 46 | NS_ConvertUTF8toUTF16 strContent(aString, aLength); |
michael@0 | 47 | text->InsertText(strContent, *aPosition); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | static void |
michael@0 | 51 | copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
michael@0 | 52 | { |
michael@0 | 53 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 54 | if (!accWrap) |
michael@0 | 55 | return; |
michael@0 | 56 | |
michael@0 | 57 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 58 | if (!text || !text->IsTextRole()) |
michael@0 | 59 | return; |
michael@0 | 60 | |
michael@0 | 61 | text->CopyText(aStartPos, aEndPos); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | static void |
michael@0 | 65 | cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
michael@0 | 66 | { |
michael@0 | 67 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 68 | if (!accWrap) |
michael@0 | 69 | return; |
michael@0 | 70 | |
michael@0 | 71 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 72 | if (!text || !text->IsTextRole()) |
michael@0 | 73 | return; |
michael@0 | 74 | |
michael@0 | 75 | text->CutText(aStartPos, aEndPos); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | static void |
michael@0 | 79 | deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
michael@0 | 80 | { |
michael@0 | 81 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 82 | if (!accWrap) |
michael@0 | 83 | return; |
michael@0 | 84 | |
michael@0 | 85 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 86 | if (!text || !text->IsTextRole()) |
michael@0 | 87 | return; |
michael@0 | 88 | |
michael@0 | 89 | text->DeleteText(aStartPos, aEndPos); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | static void |
michael@0 | 93 | pasteTextCB(AtkEditableText *aText, gint aPosition) |
michael@0 | 94 | { |
michael@0 | 95 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 96 | if (!accWrap) |
michael@0 | 97 | return; |
michael@0 | 98 | |
michael@0 | 99 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 100 | if (!text || !text->IsTextRole()) |
michael@0 | 101 | return; |
michael@0 | 102 | |
michael@0 | 103 | text->PasteText(aPosition); |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | void |
michael@0 | 108 | editableTextInterfaceInitCB(AtkEditableTextIface* aIface) |
michael@0 | 109 | { |
michael@0 | 110 | NS_ASSERTION(aIface, "Invalid aIface"); |
michael@0 | 111 | if (MOZ_UNLIKELY(!aIface)) |
michael@0 | 112 | return; |
michael@0 | 113 | |
michael@0 | 114 | aIface->set_text_contents = setTextContentsCB; |
michael@0 | 115 | aIface->insert_text = insertTextCB; |
michael@0 | 116 | aIface->copy_text = copyTextCB; |
michael@0 | 117 | aIface->cut_text = cutTextCB; |
michael@0 | 118 | aIface->delete_text = deleteTextCB; |
michael@0 | 119 | aIface->paste_text = pasteTextCB; |
michael@0 | 120 | } |