accessible/src/atk/nsMaiInterfaceHypertext.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.h"
michael@0 11 #include "nsMai.h"
michael@0 12 #include "nsMaiHyperlink.h"
michael@0 13 #include "mozilla/Likely.h"
michael@0 14
michael@0 15 using namespace mozilla::a11y;
michael@0 16
michael@0 17 extern "C" {
michael@0 18
michael@0 19 static AtkHyperlink*
michael@0 20 getLinkCB(AtkHypertext *aText, gint aLinkIndex)
michael@0 21 {
michael@0 22 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
michael@0 23 if (!accWrap)
michael@0 24 return nullptr;
michael@0 25
michael@0 26 HyperTextAccessible* hyperText = accWrap->AsHyperText();
michael@0 27 NS_ENSURE_TRUE(hyperText, nullptr);
michael@0 28
michael@0 29 Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
michael@0 30 if (!hyperLink)
michael@0 31 return nullptr;
michael@0 32
michael@0 33 AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink);
michael@0 34 AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj);
michael@0 35 NS_ENSURE_TRUE(accChild, nullptr);
michael@0 36
michael@0 37 MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink();
michael@0 38 NS_ENSURE_TRUE(maiHyperlink, nullptr);
michael@0 39 return maiHyperlink->GetAtkHyperlink();
michael@0 40 }
michael@0 41
michael@0 42 static gint
michael@0 43 getLinkCountCB(AtkHypertext *aText)
michael@0 44 {
michael@0 45 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
michael@0 46 if (!accWrap)
michael@0 47 return -1;
michael@0 48
michael@0 49 HyperTextAccessible* hyperText = accWrap->AsHyperText();
michael@0 50 NS_ENSURE_TRUE(hyperText, -1);
michael@0 51
michael@0 52 return hyperText->LinkCount();
michael@0 53 }
michael@0 54
michael@0 55 static gint
michael@0 56 getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
michael@0 57 {
michael@0 58 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
michael@0 59 if (!accWrap)
michael@0 60 return -1;
michael@0 61
michael@0 62 HyperTextAccessible* hyperText = accWrap->AsHyperText();
michael@0 63 NS_ENSURE_TRUE(hyperText, -1);
michael@0 64
michael@0 65 return hyperText->LinkIndexAtOffset(aCharIndex);
michael@0 66 }
michael@0 67 }
michael@0 68
michael@0 69 void
michael@0 70 hypertextInterfaceInitCB(AtkHypertextIface* aIface)
michael@0 71 {
michael@0 72 NS_ASSERTION(aIface, "no interface!");
michael@0 73 if (MOZ_UNLIKELY(!aIface))
michael@0 74 return;
michael@0 75
michael@0 76 aIface->get_link = getLinkCB;
michael@0 77 aIface->get_n_links = getLinkCountCB;
michael@0 78 aIface->get_link_index = getLinkIndexCB;
michael@0 79 }

mercurial