accessible/src/windows/ia2/ia2AccessibleTableCell.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:expandtab:shiftwidth=2:tabstop=2:
     3  */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include "ia2AccessibleTableCell.h"
    10 #include "Accessible2.h"
    11 #include "AccessibleTable2_i.c"
    12 #include "AccessibleTableCell_i.c"
    14 #include "AccessibleWrap.h"
    15 #include "TableAccessible.h"
    16 #include "TableCellAccessible.h"
    17 #include "IUnknownImpl.h"
    19 #include "nsCOMPtr.h"
    20 #include "nsString.h"
    22 using namespace mozilla::a11y;
    24 // IUnknown
    26 STDMETHODIMP
    27 ia2AccessibleTableCell::QueryInterface(REFIID iid, void** ppv)
    28 {
    29   if (!ppv)
    30     return E_INVALIDARG;
    32   *ppv = nullptr;
    34   if (IID_IAccessibleTableCell == iid) {
    35     *ppv = static_cast<IAccessibleTableCell*>(this);
    36     (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
    37     return S_OK;
    38   }
    40   return E_NOINTERFACE;
    41 }
    43 ////////////////////////////////////////////////////////////////////////////////
    44 // IAccessibleTableCell
    46 STDMETHODIMP
    47 ia2AccessibleTableCell::get_table(IUnknown** aTable)
    48 {
    49   A11Y_TRYBLOCK_BEGIN
    51   if (!aTable)
    52     return E_INVALIDARG;
    54   *aTable = nullptr;
    55   if (!mTableCell)
    56     return CO_E_OBJNOTCONNECTED;
    58   TableAccessible* table = mTableCell->Table();
    59   if (!table)
    60     return E_FAIL;
    62   AccessibleWrap* wrap = static_cast<AccessibleWrap*>(table->AsAccessible());
    63   *aTable = static_cast<IAccessible*>(wrap);
    64   (*aTable)->AddRef();
    65   return S_OK;
    67   A11Y_TRYBLOCK_END
    68 }
    70 STDMETHODIMP
    71 ia2AccessibleTableCell::get_columnExtent(long* aSpan)
    72 {
    73   A11Y_TRYBLOCK_BEGIN
    75   if (!aSpan)
    76     return E_INVALIDARG;
    78   *aSpan = 0;
    79   if (!mTableCell)
    80     return CO_E_OBJNOTCONNECTED;
    82   *aSpan = mTableCell->ColExtent();
    84   return S_OK;
    86   A11Y_TRYBLOCK_END
    87 }
    89 STDMETHODIMP
    90 ia2AccessibleTableCell::get_columnHeaderCells(IUnknown*** aCellAccessibles,
    91                                               long* aNColumnHeaderCells)
    92 {
    93   A11Y_TRYBLOCK_BEGIN
    95   if (!aCellAccessibles || !aNColumnHeaderCells)
    96     return E_INVALIDARG;
    98   *aCellAccessibles = nullptr;
    99   *aNColumnHeaderCells = 0;
   100   if (!mTableCell)
   101     return CO_E_OBJNOTCONNECTED;
   103   nsAutoTArray<Accessible*, 10> cells;
   104   mTableCell->ColHeaderCells(&cells);
   106   *aNColumnHeaderCells = cells.Length();
   107   *aCellAccessibles =
   108     static_cast<IUnknown**>(::CoTaskMemAlloc(sizeof(IUnknown*) *
   109                                              cells.Length()));
   111   if (!*aCellAccessibles)
   112     return E_OUTOFMEMORY;
   114   for (uint32_t i = 0; i < cells.Length(); i++) {
   115     AccessibleWrap* cell = static_cast<AccessibleWrap*>(cells[i]);
   116     (*aCellAccessibles)[i] = static_cast<IAccessible*>(cell);
   117     (*aCellAccessibles)[i]->AddRef();
   118   }
   120   return S_OK;
   122   A11Y_TRYBLOCK_END
   123 }
   125 STDMETHODIMP
   126 ia2AccessibleTableCell::get_columnIndex(long* aColIdx)
   127 {
   128   A11Y_TRYBLOCK_BEGIN
   130   if (!aColIdx)
   131     return E_INVALIDARG;
   133   *aColIdx = -1;
   134   if (!mTableCell)
   135     return CO_E_OBJNOTCONNECTED;
   137   *aColIdx = mTableCell->ColIdx();
   138   return S_OK;
   140   A11Y_TRYBLOCK_END
   141 }
   143 STDMETHODIMP
   144 ia2AccessibleTableCell::get_rowExtent(long* aSpan)
   145 {
   146   A11Y_TRYBLOCK_BEGIN
   148   if (!aSpan)
   149     return E_INVALIDARG;
   151   *aSpan = 0;
   152   if (!mTableCell)
   153     return CO_E_OBJNOTCONNECTED;
   155   *aSpan = mTableCell->RowExtent();
   156   return S_OK;
   158   A11Y_TRYBLOCK_END
   159 }
   161 STDMETHODIMP
   162 ia2AccessibleTableCell::get_rowHeaderCells(IUnknown*** aCellAccessibles,
   163                                            long* aNRowHeaderCells)
   164 {
   165   A11Y_TRYBLOCK_BEGIN
   167   if (!aCellAccessibles || !aNRowHeaderCells)
   168     return E_INVALIDARG;
   170   *aCellAccessibles = nullptr;
   171   *aNRowHeaderCells = 0;
   172   if (!mTableCell)
   173     return CO_E_OBJNOTCONNECTED;
   175   nsAutoTArray<Accessible*, 10> cells;
   176   mTableCell->RowHeaderCells(&cells);
   178   *aNRowHeaderCells = cells.Length();
   179   *aCellAccessibles =
   180     static_cast<IUnknown**>(::CoTaskMemAlloc(sizeof(IUnknown*) *
   181                                              cells.Length()));
   182   if (!*aCellAccessibles)
   183     return E_OUTOFMEMORY;
   185   for (uint32_t i = 0; i < cells.Length(); i++) {
   186     AccessibleWrap* cell = static_cast<AccessibleWrap*>(cells[i]);
   187     (*aCellAccessibles)[i] = static_cast<IAccessible*>(cell);
   188     (*aCellAccessibles)[i]->AddRef();
   189   }
   191   return S_OK;
   193   A11Y_TRYBLOCK_END
   194 }
   196 STDMETHODIMP
   197 ia2AccessibleTableCell::get_rowIndex(long* aRowIdx)
   198 {
   199   A11Y_TRYBLOCK_BEGIN
   201   if (!aRowIdx)
   202     return E_INVALIDARG;
   204   *aRowIdx = -1;
   205   if (!mTableCell)
   206     return CO_E_OBJNOTCONNECTED;
   208   *aRowIdx = mTableCell->RowIdx();
   209   return S_OK;
   211   A11Y_TRYBLOCK_END
   212 }
   214 STDMETHODIMP
   215 ia2AccessibleTableCell::get_rowColumnExtents(long* aRowIdx, long* aColIdx,
   216                                              long* aRowExtents,
   217                                              long* aColExtents,
   218                                              boolean* aIsSelected)
   219 {
   220   A11Y_TRYBLOCK_BEGIN
   222   if (!aRowIdx || !aColIdx || !aRowExtents || !aColExtents || !aIsSelected)
   223     return E_INVALIDARG;
   225   *aRowIdx = *aColIdx = *aRowExtents = *aColExtents = 0;
   226   *aIsSelected = false;
   227   if (!mTableCell)
   228     return CO_E_OBJNOTCONNECTED;
   230   *aRowIdx = mTableCell->RowIdx();
   231   *aColIdx = mTableCell->ColIdx();
   232   *aRowExtents = mTableCell->RowExtent();
   233   *aColExtents = mTableCell->ColExtent();
   234   *aIsSelected = mTableCell->Selected();
   236   return S_OK;
   238   A11Y_TRYBLOCK_END
   239 }
   241 STDMETHODIMP
   242 ia2AccessibleTableCell::get_isSelected(boolean* aIsSelected)
   243 {
   244   A11Y_TRYBLOCK_BEGIN
   246   if (!aIsSelected)
   247     return E_INVALIDARG;
   249   *aIsSelected = false;
   250   if (!mTableCell)
   251     return CO_E_OBJNOTCONNECTED;
   253   *aIsSelected = mTableCell->Selected();
   254   return S_OK;
   256   A11Y_TRYBLOCK_END
   257 }

mercurial