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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "InterfaceInitFuncs.h"
     9 #include "Accessible-inl.h"
    10 #include "HyperTextAccessible.h"
    11 #include "nsMai.h"
    12 #include "nsMaiHyperlink.h"
    13 #include "mozilla/Likely.h"
    15 using namespace mozilla::a11y;
    17 extern "C" {
    19 static AtkHyperlink*
    20 getLinkCB(AtkHypertext *aText, gint aLinkIndex)
    21 {
    22   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    23   if (!accWrap)
    24     return nullptr;
    26   HyperTextAccessible* hyperText = accWrap->AsHyperText();
    27   NS_ENSURE_TRUE(hyperText, nullptr);
    29   Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
    30   if (!hyperLink)
    31     return nullptr;
    33   AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink);
    34   AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj);
    35   NS_ENSURE_TRUE(accChild, nullptr);
    37   MaiHyperlink *maiHyperlink = accChild->GetMaiHyperlink();
    38   NS_ENSURE_TRUE(maiHyperlink, nullptr);
    39   return maiHyperlink->GetAtkHyperlink();
    40 }
    42 static gint
    43 getLinkCountCB(AtkHypertext *aText)
    44 {
    45   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    46   if (!accWrap)
    47     return -1;
    49   HyperTextAccessible* hyperText = accWrap->AsHyperText();
    50   NS_ENSURE_TRUE(hyperText, -1);
    52   return hyperText->LinkCount();
    53 }
    55 static gint
    56 getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
    57 {
    58   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
    59   if (!accWrap)
    60     return -1;
    62   HyperTextAccessible* hyperText = accWrap->AsHyperText();
    63   NS_ENSURE_TRUE(hyperText, -1);
    65   return hyperText->LinkIndexAtOffset(aCharIndex);
    66 }
    67 }
    69 void
    70 hypertextInterfaceInitCB(AtkHypertextIface* aIface)
    71 {
    72   NS_ASSERTION(aIface, "no interface!");
    73   if (MOZ_UNLIKELY(!aIface))
    74     return;
    76   aIface->get_link = getLinkCB;
    77   aIface->get_n_links = getLinkCountCB;
    78   aIface->get_link_index = getLinkIndexCB;
    79 }

mercurial