accessible/src/windows/ia2/ia2AccessibleHyperlink.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:expandtab:shiftwidth=2:tabstop=2:
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "Accessible2.h"
michael@0 9 #include "AccessibleHyperlink.h"
michael@0 10 #include "AccessibleHyperlink_i.c"
michael@0 11
michael@0 12 #include "AccessibleWrap.h"
michael@0 13 #include "IUnknownImpl.h"
michael@0 14 #include "nsIURI.h"
michael@0 15
michael@0 16 using namespace mozilla::a11y;
michael@0 17
michael@0 18 // IUnknown
michael@0 19
michael@0 20 STDMETHODIMP
michael@0 21 ia2AccessibleHyperlink::QueryInterface(REFIID iid, void** ppv)
michael@0 22 {
michael@0 23 if (!ppv)
michael@0 24 return E_INVALIDARG;
michael@0 25
michael@0 26 *ppv = nullptr;
michael@0 27
michael@0 28 if (IID_IAccessibleHyperlink == iid) {
michael@0 29 if (!static_cast<AccessibleWrap*>(this)->IsLink())
michael@0 30 return E_NOINTERFACE;
michael@0 31
michael@0 32 *ppv = static_cast<IAccessibleHyperlink*>(this);
michael@0 33 (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
michael@0 34 return S_OK;
michael@0 35 }
michael@0 36
michael@0 37 return ia2AccessibleAction::QueryInterface(iid, ppv);
michael@0 38 }
michael@0 39
michael@0 40 // IAccessibleHyperlink
michael@0 41
michael@0 42 STDMETHODIMP
michael@0 43 ia2AccessibleHyperlink::get_anchor(long aIndex, VARIANT* aAnchor)
michael@0 44 {
michael@0 45 A11Y_TRYBLOCK_BEGIN
michael@0 46
michael@0 47 if (!aAnchor)
michael@0 48 return E_INVALIDARG;
michael@0 49
michael@0 50 VariantInit(aAnchor);
michael@0 51
michael@0 52 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
michael@0 53 if (thisObj->IsDefunct())
michael@0 54 return CO_E_OBJNOTCONNECTED;
michael@0 55
michael@0 56 if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
michael@0 57 return E_INVALIDARG;
michael@0 58
michael@0 59 if (!thisObj->IsLink())
michael@0 60 return S_FALSE;
michael@0 61
michael@0 62 AccessibleWrap* anchor =
michael@0 63 static_cast<AccessibleWrap*>(thisObj->AnchorAt(aIndex));
michael@0 64 if (!anchor)
michael@0 65 return S_FALSE;
michael@0 66
michael@0 67 void* instancePtr = nullptr;
michael@0 68 HRESULT result = anchor->QueryInterface(IID_IUnknown, &instancePtr);
michael@0 69 if (FAILED(result))
michael@0 70 return result;
michael@0 71
michael@0 72 IUnknown* unknownPtr = static_cast<IUnknown*>(instancePtr);
michael@0 73 aAnchor->ppunkVal = &unknownPtr;
michael@0 74 aAnchor->vt = VT_UNKNOWN;
michael@0 75 return S_OK;
michael@0 76
michael@0 77 A11Y_TRYBLOCK_END
michael@0 78 }
michael@0 79
michael@0 80 STDMETHODIMP
michael@0 81 ia2AccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT* aAnchorTarget)
michael@0 82 {
michael@0 83 A11Y_TRYBLOCK_BEGIN
michael@0 84
michael@0 85 if (!aAnchorTarget)
michael@0 86 return E_INVALIDARG;
michael@0 87
michael@0 88 VariantInit(aAnchorTarget);
michael@0 89
michael@0 90 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
michael@0 91 if (thisObj->IsDefunct())
michael@0 92 return CO_E_OBJNOTCONNECTED;
michael@0 93
michael@0 94 if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
michael@0 95 return E_INVALIDARG;
michael@0 96
michael@0 97 if (!thisObj->IsLink())
michael@0 98 return S_FALSE;
michael@0 99
michael@0 100 nsCOMPtr<nsIURI> uri = thisObj->AnchorURIAt(aIndex);
michael@0 101 if (!uri)
michael@0 102 return S_FALSE;
michael@0 103
michael@0 104 nsAutoCString prePath;
michael@0 105 nsresult rv = uri->GetPrePath(prePath);
michael@0 106 if (NS_FAILED(rv))
michael@0 107 return GetHRESULT(rv);
michael@0 108
michael@0 109 nsAutoCString path;
michael@0 110 rv = uri->GetPath(path);
michael@0 111 if (NS_FAILED(rv))
michael@0 112 return GetHRESULT(rv);
michael@0 113
michael@0 114 nsAutoString stringURI;
michael@0 115 AppendUTF8toUTF16(prePath, stringURI);
michael@0 116 AppendUTF8toUTF16(path, stringURI);
michael@0 117
michael@0 118 aAnchorTarget->vt = VT_BSTR;
michael@0 119 aAnchorTarget->bstrVal = ::SysAllocStringLen(stringURI.get(),
michael@0 120 stringURI.Length());
michael@0 121 return aAnchorTarget->bstrVal ? S_OK : E_OUTOFMEMORY;
michael@0 122
michael@0 123 A11Y_TRYBLOCK_END
michael@0 124 }
michael@0 125
michael@0 126 STDMETHODIMP
michael@0 127 ia2AccessibleHyperlink::get_startIndex(long* aIndex)
michael@0 128 {
michael@0 129 A11Y_TRYBLOCK_BEGIN
michael@0 130
michael@0 131 if (!aIndex)
michael@0 132 return E_INVALIDARG;
michael@0 133
michael@0 134 *aIndex = 0;
michael@0 135
michael@0 136 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
michael@0 137 if (thisObj->IsDefunct())
michael@0 138 return CO_E_OBJNOTCONNECTED;
michael@0 139
michael@0 140 if (!thisObj->IsLink())
michael@0 141 return S_FALSE;
michael@0 142
michael@0 143 *aIndex = thisObj->StartOffset();
michael@0 144 return S_OK;
michael@0 145
michael@0 146 A11Y_TRYBLOCK_END
michael@0 147 }
michael@0 148
michael@0 149 STDMETHODIMP
michael@0 150 ia2AccessibleHyperlink::get_endIndex(long* aIndex)
michael@0 151 {
michael@0 152 A11Y_TRYBLOCK_BEGIN
michael@0 153
michael@0 154 if (!aIndex)
michael@0 155 return E_INVALIDARG;
michael@0 156
michael@0 157 *aIndex = 0;
michael@0 158
michael@0 159 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
michael@0 160 if (thisObj->IsDefunct())
michael@0 161 return CO_E_OBJNOTCONNECTED;
michael@0 162
michael@0 163 if (!thisObj->IsLink())
michael@0 164 return S_FALSE;
michael@0 165
michael@0 166 *aIndex = thisObj->EndOffset();
michael@0 167 return S_OK;
michael@0 168
michael@0 169 A11Y_TRYBLOCK_END
michael@0 170 }
michael@0 171
michael@0 172 STDMETHODIMP
michael@0 173 ia2AccessibleHyperlink::get_valid(boolean* aValid)
michael@0 174 {
michael@0 175 A11Y_TRYBLOCK_BEGIN
michael@0 176
michael@0 177 if (!aValid)
michael@0 178 return E_INVALIDARG;
michael@0 179
michael@0 180 *aValid = false;
michael@0 181
michael@0 182 Accessible* thisObj = static_cast<AccessibleWrap*>(this);
michael@0 183 if (thisObj->IsDefunct())
michael@0 184 return CO_E_OBJNOTCONNECTED;
michael@0 185
michael@0 186 if (!thisObj->IsLink())
michael@0 187 return S_FALSE;
michael@0 188
michael@0 189 *aValid = thisObj->IsLinkValid();
michael@0 190 return S_OK;
michael@0 191
michael@0 192 A11Y_TRYBLOCK_END
michael@0 193 }
michael@0 194

mercurial