Tue, 06 Jan 2015 21:39:09 +0100
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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "XULTabAccessible.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsAccUtils.h" |
michael@0 | 9 | #include "Relation.h" |
michael@0 | 10 | #include "Role.h" |
michael@0 | 11 | #include "States.h" |
michael@0 | 12 | |
michael@0 | 13 | // NOTE: alphabetically ordered |
michael@0 | 14 | #include "nsIAccessibleRelation.h" |
michael@0 | 15 | #include "nsIDocument.h" |
michael@0 | 16 | #include "nsIDOMXULSelectCntrlEl.h" |
michael@0 | 17 | #include "nsIDOMXULSelectCntrlItemEl.h" |
michael@0 | 18 | #include "nsIDOMXULRelatedElement.h" |
michael@0 | 19 | |
michael@0 | 20 | using namespace mozilla::a11y; |
michael@0 | 21 | |
michael@0 | 22 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 23 | // XULTabAccessible |
michael@0 | 24 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 25 | |
michael@0 | 26 | XULTabAccessible:: |
michael@0 | 27 | XULTabAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 28 | AccessibleWrap(aContent, aDoc) |
michael@0 | 29 | { |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 33 | // XULTabAccessible: nsIAccessible |
michael@0 | 34 | |
michael@0 | 35 | uint8_t |
michael@0 | 36 | XULTabAccessible::ActionCount() |
michael@0 | 37 | { |
michael@0 | 38 | return 1; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | /** Return the name of our only action */ |
michael@0 | 42 | NS_IMETHODIMP |
michael@0 | 43 | XULTabAccessible::GetActionName(uint8_t aIndex, nsAString& aName) |
michael@0 | 44 | { |
michael@0 | 45 | if (aIndex == eAction_Switch) { |
michael@0 | 46 | aName.AssignLiteral("switch"); |
michael@0 | 47 | return NS_OK; |
michael@0 | 48 | } |
michael@0 | 49 | return NS_ERROR_INVALID_ARG; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | /** Tell the tab to do its action */ |
michael@0 | 53 | NS_IMETHODIMP |
michael@0 | 54 | XULTabAccessible::DoAction(uint8_t index) |
michael@0 | 55 | { |
michael@0 | 56 | if (index == eAction_Switch) { |
michael@0 | 57 | nsCOMPtr<nsIDOMXULElement> tab(do_QueryInterface(mContent)); |
michael@0 | 58 | if ( tab ) |
michael@0 | 59 | { |
michael@0 | 60 | tab->Click(); |
michael@0 | 61 | return NS_OK; |
michael@0 | 62 | } |
michael@0 | 63 | return NS_ERROR_FAILURE; |
michael@0 | 64 | } |
michael@0 | 65 | return NS_ERROR_INVALID_ARG; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 69 | // XULTabAccessible: Accessible |
michael@0 | 70 | |
michael@0 | 71 | role |
michael@0 | 72 | XULTabAccessible::NativeRole() |
michael@0 | 73 | { |
michael@0 | 74 | return roles::PAGETAB; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | uint64_t |
michael@0 | 78 | XULTabAccessible::NativeState() |
michael@0 | 79 | { |
michael@0 | 80 | // Possible states: focused, focusable, unavailable(disabled), offscreen. |
michael@0 | 81 | |
michael@0 | 82 | // get focus and disable status from base class |
michael@0 | 83 | uint64_t state = AccessibleWrap::NativeState(); |
michael@0 | 84 | |
michael@0 | 85 | // Check whether the tab is selected and/or pinned |
michael@0 | 86 | nsCOMPtr<nsIDOMXULSelectControlItemElement> tab(do_QueryInterface(mContent)); |
michael@0 | 87 | if (tab) { |
michael@0 | 88 | bool selected = false; |
michael@0 | 89 | if (NS_SUCCEEDED(tab->GetSelected(&selected)) && selected) |
michael@0 | 90 | state |= states::SELECTED; |
michael@0 | 91 | |
michael@0 | 92 | if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::pinned, |
michael@0 | 93 | nsGkAtoms::_true, eCaseMatters)) |
michael@0 | 94 | state |= states::PINNED; |
michael@0 | 95 | |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | return state; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | uint64_t |
michael@0 | 102 | XULTabAccessible::NativeInteractiveState() const |
michael@0 | 103 | { |
michael@0 | 104 | uint64_t state = Accessible::NativeInteractiveState(); |
michael@0 | 105 | return (state & states::UNAVAILABLE) ? state : state | states::SELECTABLE; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // nsIAccessible |
michael@0 | 109 | Relation |
michael@0 | 110 | XULTabAccessible::RelationByType(RelationType aType) |
michael@0 | 111 | { |
michael@0 | 112 | Relation rel = AccessibleWrap::RelationByType(aType); |
michael@0 | 113 | if (aType != RelationType::LABEL_FOR) |
michael@0 | 114 | return rel; |
michael@0 | 115 | |
michael@0 | 116 | // Expose 'LABEL_FOR' relation on tab accessible for tabpanel accessible. |
michael@0 | 117 | nsCOMPtr<nsIDOMXULRelatedElement> tabsElm = |
michael@0 | 118 | do_QueryInterface(mContent->GetParent()); |
michael@0 | 119 | if (!tabsElm) |
michael@0 | 120 | return rel; |
michael@0 | 121 | |
michael@0 | 122 | nsCOMPtr<nsIDOMNode> domNode(DOMNode()); |
michael@0 | 123 | nsCOMPtr<nsIDOMNode> tabpanelNode; |
michael@0 | 124 | tabsElm->GetRelatedElement(domNode, getter_AddRefs(tabpanelNode)); |
michael@0 | 125 | if (!tabpanelNode) |
michael@0 | 126 | return rel; |
michael@0 | 127 | |
michael@0 | 128 | nsCOMPtr<nsIContent> tabpanelContent(do_QueryInterface(tabpanelNode)); |
michael@0 | 129 | rel.AppendTarget(mDoc, tabpanelContent); |
michael@0 | 130 | return rel; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | |
michael@0 | 134 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 135 | // XULTabsAccessible |
michael@0 | 136 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 137 | |
michael@0 | 138 | XULTabsAccessible:: |
michael@0 | 139 | XULTabsAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 140 | XULSelectControlAccessible(aContent, aDoc) |
michael@0 | 141 | { |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | role |
michael@0 | 145 | XULTabsAccessible::NativeRole() |
michael@0 | 146 | { |
michael@0 | 147 | return roles::PAGETABLIST; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | uint8_t |
michael@0 | 151 | XULTabsAccessible::ActionCount() |
michael@0 | 152 | { |
michael@0 | 153 | return 0; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | void |
michael@0 | 157 | XULTabsAccessible::Value(nsString& aValue) |
michael@0 | 158 | { |
michael@0 | 159 | aValue.Truncate(); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | ENameValueFlag |
michael@0 | 163 | XULTabsAccessible::NativeName(nsString& aName) |
michael@0 | 164 | { |
michael@0 | 165 | // no name |
michael@0 | 166 | return eNameOK; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | |
michael@0 | 170 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 171 | // XULTabpanelsAccessible |
michael@0 | 172 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 173 | |
michael@0 | 174 | role |
michael@0 | 175 | XULTabpanelsAccessible::NativeRole() |
michael@0 | 176 | { |
michael@0 | 177 | return roles::PANE; |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 181 | // XULTabpanelAccessible |
michael@0 | 182 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 183 | |
michael@0 | 184 | XULTabpanelAccessible:: |
michael@0 | 185 | XULTabpanelAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 186 | AccessibleWrap(aContent, aDoc) |
michael@0 | 187 | { |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | role |
michael@0 | 191 | XULTabpanelAccessible::NativeRole() |
michael@0 | 192 | { |
michael@0 | 193 | return roles::PROPERTYPAGE; |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | Relation |
michael@0 | 197 | XULTabpanelAccessible::RelationByType(RelationType aType) |
michael@0 | 198 | { |
michael@0 | 199 | Relation rel = AccessibleWrap::RelationByType(aType); |
michael@0 | 200 | if (aType != RelationType::LABELLED_BY) |
michael@0 | 201 | return rel; |
michael@0 | 202 | |
michael@0 | 203 | // Expose 'LABELLED_BY' relation on tabpanel accessible for tab accessible. |
michael@0 | 204 | nsCOMPtr<nsIDOMXULRelatedElement> tabpanelsElm = |
michael@0 | 205 | do_QueryInterface(mContent->GetParent()); |
michael@0 | 206 | if (!tabpanelsElm) |
michael@0 | 207 | return rel; |
michael@0 | 208 | |
michael@0 | 209 | nsCOMPtr<nsIDOMNode> domNode(DOMNode()); |
michael@0 | 210 | nsCOMPtr<nsIDOMNode> tabNode; |
michael@0 | 211 | tabpanelsElm->GetRelatedElement(domNode, getter_AddRefs(tabNode)); |
michael@0 | 212 | if (!tabNode) |
michael@0 | 213 | return rel; |
michael@0 | 214 | |
michael@0 | 215 | nsCOMPtr<nsIContent> tabContent(do_QueryInterface(tabNode)); |
michael@0 | 216 | rel.AppendTarget(mDoc, tabContent); |
michael@0 | 217 | return rel; |
michael@0 | 218 | } |