accessible/src/atk/nsMaiInterfaceSelection.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 "AccessibleWrap.h"
    11 #include "nsMai.h"
    12 #include "mozilla/Likely.h"
    14 #include <atk/atk.h>
    16 using namespace mozilla::a11y;
    18 extern "C" {
    20 static gboolean
    21 addSelectionCB(AtkSelection *aSelection, gint i)
    22 {
    23   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    24   if (!accWrap || !accWrap->IsSelect())
    25     return FALSE;
    27   return accWrap->AddItemToSelection(i);
    28 }
    30 static gboolean
    31 clearSelectionCB(AtkSelection *aSelection)
    32 {
    33   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    34   if (!accWrap || !accWrap->IsSelect())
    35     return FALSE;
    37   return accWrap->UnselectAll();
    38 }
    40 static AtkObject*
    41 refSelectionCB(AtkSelection *aSelection, gint i)
    42 {
    43   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    44   if (!accWrap || !accWrap->IsSelect())
    45     return nullptr;
    47   Accessible* selectedItem = accWrap->GetSelectedItem(i);
    48   if (!selectedItem)
    49     return nullptr;
    51   AtkObject* atkObj = AccessibleWrap::GetAtkObject(selectedItem);
    52   if (atkObj)
    53     g_object_ref(atkObj);
    55   return atkObj;
    56 }
    58 static gint
    59 getSelectionCountCB(AtkSelection *aSelection)
    60 {
    61   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    62   if (!accWrap || !accWrap->IsSelect())
    63     return -1;
    65   return accWrap->SelectedItemCount();
    66 }
    68 static gboolean
    69 isChildSelectedCB(AtkSelection *aSelection, gint i)
    70 {
    71   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    72   if (!accWrap || !accWrap->IsSelect())
    73     return FALSE;
    75   return accWrap->IsItemSelected(i);
    76 }
    78 static gboolean
    79 removeSelectionCB(AtkSelection *aSelection, gint i)
    80 {
    81   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    82   if (!accWrap || !accWrap->IsSelect())
    83     return FALSE;
    85   return accWrap->RemoveItemFromSelection(i);
    86 }
    88 static gboolean
    89 selectAllSelectionCB(AtkSelection *aSelection)
    90 {
    91   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    92   if (!accWrap || !accWrap->IsSelect())
    93     return FALSE;
    95   return accWrap->SelectAll();
    96 }
    97 }
    99 void
   100 selectionInterfaceInitCB(AtkSelectionIface* aIface)
   101 {
   102   NS_ASSERTION(aIface, "Invalid aIface");
   103   if (MOZ_UNLIKELY(!aIface))
   104     return;
   106   aIface->add_selection = addSelectionCB;
   107   aIface->clear_selection = clearSelectionCB;
   108   aIface->ref_selection = refSelectionCB;
   109   aIface->get_selection_count = getSelectionCountCB;
   110   aIface->is_child_selected = isChildSelectedCB;
   111   aIface->remove_selection = removeSelectionCB;
   112   aIface->select_all_selection = selectAllSelectionCB;
   113 }

mercurial