Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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 "mozilla/BasicEvents.h" |
michael@0 | 7 | #include "mozilla/EventDispatcher.h" |
michael@0 | 8 | #include "mozilla/EventListenerManager.h" |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "nsWindowRoot.h" |
michael@0 | 11 | #include "nsPIDOMWindow.h" |
michael@0 | 12 | #include "nsPresContext.h" |
michael@0 | 13 | #include "nsLayoutCID.h" |
michael@0 | 14 | #include "nsContentCID.h" |
michael@0 | 15 | #include "nsString.h" |
michael@0 | 16 | #include "nsGlobalWindow.h" |
michael@0 | 17 | #include "nsFocusManager.h" |
michael@0 | 18 | #include "nsIContent.h" |
michael@0 | 19 | #include "nsIDOMHTMLInputElement.h" |
michael@0 | 20 | #include "nsIDOMHTMLTextAreaElement.h" |
michael@0 | 21 | #include "nsIControllers.h" |
michael@0 | 22 | #include "nsIController.h" |
michael@0 | 23 | |
michael@0 | 24 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 25 | |
michael@0 | 26 | #ifdef MOZ_XUL |
michael@0 | 27 | #include "nsIDOMXULElement.h" |
michael@0 | 28 | #endif |
michael@0 | 29 | |
michael@0 | 30 | using namespace mozilla; |
michael@0 | 31 | using namespace mozilla::dom; |
michael@0 | 32 | |
michael@0 | 33 | nsWindowRoot::nsWindowRoot(nsPIDOMWindow* aWindow) |
michael@0 | 34 | { |
michael@0 | 35 | mWindow = aWindow; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | nsWindowRoot::~nsWindowRoot() |
michael@0 | 39 | { |
michael@0 | 40 | if (mListenerManager) { |
michael@0 | 41 | mListenerManager->Disconnect(); |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_4(nsWindowRoot, |
michael@0 | 46 | mWindow, |
michael@0 | 47 | mListenerManager, |
michael@0 | 48 | mPopupNode, |
michael@0 | 49 | mParent) |
michael@0 | 50 | |
michael@0 | 51 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsWindowRoot) |
michael@0 | 52 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
michael@0 | 53 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEventTarget) |
michael@0 | 54 | NS_INTERFACE_MAP_ENTRY(nsPIWindowRoot) |
michael@0 | 55 | NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget) |
michael@0 | 56 | NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget) |
michael@0 | 57 | NS_INTERFACE_MAP_END |
michael@0 | 58 | |
michael@0 | 59 | NS_IMPL_CYCLE_COLLECTING_ADDREF(nsWindowRoot) |
michael@0 | 60 | NS_IMPL_CYCLE_COLLECTING_RELEASE(nsWindowRoot) |
michael@0 | 61 | |
michael@0 | 62 | NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot) |
michael@0 | 63 | |
michael@0 | 64 | NS_IMETHODIMP |
michael@0 | 65 | nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture) |
michael@0 | 66 | { |
michael@0 | 67 | if (nsRefPtr<EventListenerManager> elm = GetExistingListenerManager()) { |
michael@0 | 68 | elm->RemoveEventListener(aType, aListener, aUseCapture); |
michael@0 | 69 | } |
michael@0 | 70 | return NS_OK; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsWindowRoot) |
michael@0 | 74 | |
michael@0 | 75 | NS_IMETHODIMP |
michael@0 | 76 | nsWindowRoot::DispatchEvent(nsIDOMEvent* aEvt, bool *aRetVal) |
michael@0 | 77 | { |
michael@0 | 78 | nsEventStatus status = nsEventStatus_eIgnore; |
michael@0 | 79 | nsresult rv = EventDispatcher::DispatchDOMEvent( |
michael@0 | 80 | static_cast<EventTarget*>(this), nullptr, aEvt, nullptr, &status); |
michael@0 | 81 | *aRetVal = (status != nsEventStatus_eConsumeNoDefault); |
michael@0 | 82 | return rv; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | nsresult |
michael@0 | 86 | nsWindowRoot::DispatchDOMEvent(WidgetEvent* aEvent, |
michael@0 | 87 | nsIDOMEvent* aDOMEvent, |
michael@0 | 88 | nsPresContext* aPresContext, |
michael@0 | 89 | nsEventStatus* aEventStatus) |
michael@0 | 90 | { |
michael@0 | 91 | return EventDispatcher::DispatchDOMEvent(static_cast<EventTarget*>(this), |
michael@0 | 92 | aEvent, aDOMEvent, |
michael@0 | 93 | aPresContext, aEventStatus); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | NS_IMETHODIMP |
michael@0 | 97 | nsWindowRoot::AddEventListener(const nsAString& aType, |
michael@0 | 98 | nsIDOMEventListener *aListener, |
michael@0 | 99 | bool aUseCapture, bool aWantsUntrusted, |
michael@0 | 100 | uint8_t aOptionalArgc) |
michael@0 | 101 | { |
michael@0 | 102 | NS_ASSERTION(!aWantsUntrusted || aOptionalArgc > 1, |
michael@0 | 103 | "Won't check if this is chrome, you want to set " |
michael@0 | 104 | "aWantsUntrusted to false or make the aWantsUntrusted " |
michael@0 | 105 | "explicit by making optional_argc non-zero."); |
michael@0 | 106 | |
michael@0 | 107 | EventListenerManager* elm = GetOrCreateListenerManager(); |
michael@0 | 108 | NS_ENSURE_STATE(elm); |
michael@0 | 109 | elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted); |
michael@0 | 110 | return NS_OK; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | void |
michael@0 | 114 | nsWindowRoot::AddEventListener(const nsAString& aType, |
michael@0 | 115 | EventListener* aListener, |
michael@0 | 116 | bool aUseCapture, |
michael@0 | 117 | const Nullable<bool>& aWantsUntrusted, |
michael@0 | 118 | ErrorResult& aRv) |
michael@0 | 119 | { |
michael@0 | 120 | bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value(); |
michael@0 | 121 | EventListenerManager* elm = GetOrCreateListenerManager(); |
michael@0 | 122 | if (!elm) { |
michael@0 | 123 | aRv.Throw(NS_ERROR_UNEXPECTED); |
michael@0 | 124 | return; |
michael@0 | 125 | } |
michael@0 | 126 | elm->AddEventListener(aType, aListener, aUseCapture, wantsUntrusted); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | |
michael@0 | 130 | NS_IMETHODIMP |
michael@0 | 131 | nsWindowRoot::AddSystemEventListener(const nsAString& aType, |
michael@0 | 132 | nsIDOMEventListener *aListener, |
michael@0 | 133 | bool aUseCapture, |
michael@0 | 134 | bool aWantsUntrusted, |
michael@0 | 135 | uint8_t aOptionalArgc) |
michael@0 | 136 | { |
michael@0 | 137 | NS_ASSERTION(!aWantsUntrusted || aOptionalArgc > 1, |
michael@0 | 138 | "Won't check if this is chrome, you want to set " |
michael@0 | 139 | "aWantsUntrusted to false or make the aWantsUntrusted " |
michael@0 | 140 | "explicit by making optional_argc non-zero."); |
michael@0 | 141 | |
michael@0 | 142 | return NS_AddSystemEventListener(this, aType, aListener, aUseCapture, |
michael@0 | 143 | aWantsUntrusted); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | EventListenerManager* |
michael@0 | 147 | nsWindowRoot::GetOrCreateListenerManager() |
michael@0 | 148 | { |
michael@0 | 149 | if (!mListenerManager) { |
michael@0 | 150 | mListenerManager = |
michael@0 | 151 | new EventListenerManager(static_cast<EventTarget*>(this)); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | return mListenerManager; |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | EventListenerManager* |
michael@0 | 158 | nsWindowRoot::GetExistingListenerManager() const |
michael@0 | 159 | { |
michael@0 | 160 | return mListenerManager; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | nsIScriptContext* |
michael@0 | 164 | nsWindowRoot::GetContextForEventHandlers(nsresult* aRv) |
michael@0 | 165 | { |
michael@0 | 166 | *aRv = NS_OK; |
michael@0 | 167 | return nullptr; |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | nsresult |
michael@0 | 171 | nsWindowRoot::PreHandleEvent(EventChainPreVisitor& aVisitor) |
michael@0 | 172 | { |
michael@0 | 173 | aVisitor.mCanHandle = true; |
michael@0 | 174 | aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119 |
michael@0 | 175 | // To keep mWindow alive |
michael@0 | 176 | aVisitor.mItemData = static_cast<nsISupports *>(mWindow); |
michael@0 | 177 | aVisitor.mParentTarget = mParent; |
michael@0 | 178 | return NS_OK; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | nsresult |
michael@0 | 182 | nsWindowRoot::PostHandleEvent(EventChainPostVisitor& aVisitor) |
michael@0 | 183 | { |
michael@0 | 184 | return NS_OK; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | nsIDOMWindow* |
michael@0 | 188 | nsWindowRoot::GetOwnerGlobal() |
michael@0 | 189 | { |
michael@0 | 190 | return GetWindow(); |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | nsPIDOMWindow* |
michael@0 | 194 | nsWindowRoot::GetWindow() |
michael@0 | 195 | { |
michael@0 | 196 | return mWindow; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | nsresult |
michael@0 | 200 | nsWindowRoot::GetControllers(nsIControllers** aResult) |
michael@0 | 201 | { |
michael@0 | 202 | *aResult = nullptr; |
michael@0 | 203 | |
michael@0 | 204 | // XXX: we should fix this so there's a generic interface that |
michael@0 | 205 | // describes controllers, so this code would have no special |
michael@0 | 206 | // knowledge of what object might have controllers. |
michael@0 | 207 | |
michael@0 | 208 | nsCOMPtr<nsPIDOMWindow> focusedWindow; |
michael@0 | 209 | nsIContent* focusedContent = |
michael@0 | 210 | nsFocusManager::GetFocusedDescendant(mWindow, true, getter_AddRefs(focusedWindow)); |
michael@0 | 211 | if (focusedContent) { |
michael@0 | 212 | #ifdef MOZ_XUL |
michael@0 | 213 | nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(focusedContent)); |
michael@0 | 214 | if (xulElement) |
michael@0 | 215 | return xulElement->GetControllers(aResult); |
michael@0 | 216 | #endif |
michael@0 | 217 | |
michael@0 | 218 | nsCOMPtr<nsIDOMHTMLTextAreaElement> htmlTextArea = |
michael@0 | 219 | do_QueryInterface(focusedContent); |
michael@0 | 220 | if (htmlTextArea) |
michael@0 | 221 | return htmlTextArea->GetControllers(aResult); |
michael@0 | 222 | |
michael@0 | 223 | nsCOMPtr<nsIDOMHTMLInputElement> htmlInputElement = |
michael@0 | 224 | do_QueryInterface(focusedContent); |
michael@0 | 225 | if (htmlInputElement) |
michael@0 | 226 | return htmlInputElement->GetControllers(aResult); |
michael@0 | 227 | |
michael@0 | 228 | if (focusedContent->IsEditable() && focusedWindow) |
michael@0 | 229 | return focusedWindow->GetControllers(aResult); |
michael@0 | 230 | } |
michael@0 | 231 | else { |
michael@0 | 232 | nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(focusedWindow); |
michael@0 | 233 | if (domWindow) |
michael@0 | 234 | return domWindow->GetControllers(aResult); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | return NS_OK; |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | nsresult |
michael@0 | 241 | nsWindowRoot::GetControllerForCommand(const char * aCommand, |
michael@0 | 242 | nsIController** _retval) |
michael@0 | 243 | { |
michael@0 | 244 | NS_ENSURE_ARG_POINTER(_retval); |
michael@0 | 245 | *_retval = nullptr; |
michael@0 | 246 | |
michael@0 | 247 | { |
michael@0 | 248 | nsCOMPtr<nsIControllers> controllers; |
michael@0 | 249 | GetControllers(getter_AddRefs(controllers)); |
michael@0 | 250 | if (controllers) { |
michael@0 | 251 | nsCOMPtr<nsIController> controller; |
michael@0 | 252 | controllers->GetControllerForCommand(aCommand, getter_AddRefs(controller)); |
michael@0 | 253 | if (controller) { |
michael@0 | 254 | controller.forget(_retval); |
michael@0 | 255 | return NS_OK; |
michael@0 | 256 | } |
michael@0 | 257 | } |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | nsCOMPtr<nsPIDOMWindow> focusedWindow; |
michael@0 | 261 | nsFocusManager::GetFocusedDescendant(mWindow, true, getter_AddRefs(focusedWindow)); |
michael@0 | 262 | while (focusedWindow) { |
michael@0 | 263 | nsCOMPtr<nsIControllers> controllers; |
michael@0 | 264 | focusedWindow->GetControllers(getter_AddRefs(controllers)); |
michael@0 | 265 | if (controllers) { |
michael@0 | 266 | nsCOMPtr<nsIController> controller; |
michael@0 | 267 | controllers->GetControllerForCommand(aCommand, |
michael@0 | 268 | getter_AddRefs(controller)); |
michael@0 | 269 | if (controller) { |
michael@0 | 270 | controller.forget(_retval); |
michael@0 | 271 | return NS_OK; |
michael@0 | 272 | } |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | // XXXndeakin P3 is this casting safe? |
michael@0 | 276 | nsGlobalWindow *win = static_cast<nsGlobalWindow*>(focusedWindow.get()); |
michael@0 | 277 | focusedWindow = win->GetPrivateParent(); |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | return NS_OK; |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | nsIDOMNode* |
michael@0 | 284 | nsWindowRoot::GetPopupNode() |
michael@0 | 285 | { |
michael@0 | 286 | return mPopupNode; |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | void |
michael@0 | 290 | nsWindowRoot::SetPopupNode(nsIDOMNode* aNode) |
michael@0 | 291 | { |
michael@0 | 292 | mPopupNode = aNode; |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | /////////////////////////////////////////////////////////////////////////////////// |
michael@0 | 296 | |
michael@0 | 297 | already_AddRefed<EventTarget> |
michael@0 | 298 | NS_NewWindowRoot(nsPIDOMWindow* aWindow) |
michael@0 | 299 | { |
michael@0 | 300 | nsCOMPtr<EventTarget> result = new nsWindowRoot(aWindow); |
michael@0 | 301 | return result.forget(); |
michael@0 | 302 | } |