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: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsCommandHandler.h" |
michael@0 | 8 | #include "nsWebBrowser.h" |
michael@0 | 9 | #include "nsDocShellTreeOwner.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "nsMemory.h" |
michael@0 | 12 | #include "nsPIDOMWindow.h" |
michael@0 | 13 | |
michael@0 | 14 | nsCommandHandler::nsCommandHandler() : |
michael@0 | 15 | mWindow(nullptr) |
michael@0 | 16 | { |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | nsCommandHandler::~nsCommandHandler() |
michael@0 | 20 | { |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | nsresult nsCommandHandler::GetCommandHandler(nsICommandHandler **aCommandHandler) |
michael@0 | 24 | { |
michael@0 | 25 | NS_ENSURE_ARG_POINTER(aCommandHandler); |
michael@0 | 26 | |
michael@0 | 27 | *aCommandHandler = nullptr; |
michael@0 | 28 | if (mWindow == nullptr) |
michael@0 | 29 | { |
michael@0 | 30 | return NS_ERROR_FAILURE; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mWindow)); |
michael@0 | 34 | if (!window) |
michael@0 | 35 | { |
michael@0 | 36 | return NS_ERROR_FAILURE; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | // Get the document tree owner |
michael@0 | 40 | |
michael@0 | 41 | nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem = |
michael@0 | 42 | do_QueryInterface(window->GetDocShell()); |
michael@0 | 43 | nsIDocShellTreeOwner *treeOwner = nullptr; |
michael@0 | 44 | docShellAsTreeItem->GetTreeOwner(&treeOwner); |
michael@0 | 45 | |
michael@0 | 46 | // Make sure the tree owner is an an nsDocShellTreeOwner object |
michael@0 | 47 | // by QI'ing for a hidden interface. If it doesn't have the interface |
michael@0 | 48 | // then it's not safe to do the casting. |
michael@0 | 49 | |
michael@0 | 50 | nsCOMPtr<nsICDocShellTreeOwner> realTreeOwner(do_QueryInterface(treeOwner)); |
michael@0 | 51 | if (realTreeOwner) |
michael@0 | 52 | { |
michael@0 | 53 | nsDocShellTreeOwner *tree = static_cast<nsDocShellTreeOwner *>(treeOwner); |
michael@0 | 54 | if (tree->mTreeOwner) |
michael@0 | 55 | { |
michael@0 | 56 | nsresult rv; |
michael@0 | 57 | rv = tree->mTreeOwner->QueryInterface(NS_GET_IID(nsICommandHandler), (void **)aCommandHandler); |
michael@0 | 58 | NS_RELEASE(treeOwner); |
michael@0 | 59 | return rv; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | NS_RELEASE(treeOwner); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | *aCommandHandler = nullptr; |
michael@0 | 66 | |
michael@0 | 67 | return NS_OK; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | |
michael@0 | 71 | NS_IMPL_ADDREF(nsCommandHandler) |
michael@0 | 72 | NS_IMPL_RELEASE(nsCommandHandler) |
michael@0 | 73 | |
michael@0 | 74 | NS_INTERFACE_MAP_BEGIN(nsCommandHandler) |
michael@0 | 75 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandHandler) |
michael@0 | 76 | NS_INTERFACE_MAP_ENTRY(nsICommandHandlerInit) |
michael@0 | 77 | NS_INTERFACE_MAP_ENTRY(nsICommandHandler) |
michael@0 | 78 | NS_INTERFACE_MAP_END |
michael@0 | 79 | |
michael@0 | 80 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 81 | // nsICommandHandlerInit implementation |
michael@0 | 82 | |
michael@0 | 83 | /* attribute nsIDocShell docShell; */ |
michael@0 | 84 | NS_IMETHODIMP nsCommandHandler::GetWindow(nsIDOMWindow * *aWindow) |
michael@0 | 85 | { |
michael@0 | 86 | *aWindow = nullptr; |
michael@0 | 87 | return NS_OK; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | NS_IMETHODIMP nsCommandHandler::SetWindow(nsIDOMWindow * aWindow) |
michael@0 | 91 | { |
michael@0 | 92 | if (aWindow == nullptr) |
michael@0 | 93 | { |
michael@0 | 94 | return NS_ERROR_FAILURE; |
michael@0 | 95 | } |
michael@0 | 96 | mWindow = aWindow; |
michael@0 | 97 | return NS_OK; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 101 | // nsICommandHandler implementation |
michael@0 | 102 | |
michael@0 | 103 | /* string exec (in string aCommand, in string aStatus); */ |
michael@0 | 104 | NS_IMETHODIMP nsCommandHandler::Exec(const char *aCommand, const char *aStatus, char **aResult) |
michael@0 | 105 | { |
michael@0 | 106 | NS_ENSURE_ARG_POINTER(aCommand); |
michael@0 | 107 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 108 | |
michael@0 | 109 | nsCOMPtr<nsICommandHandler> commandHandler; |
michael@0 | 110 | GetCommandHandler(getter_AddRefs(commandHandler)); |
michael@0 | 111 | |
michael@0 | 112 | // Call the client's command handler to deal with this command |
michael@0 | 113 | if (commandHandler) |
michael@0 | 114 | { |
michael@0 | 115 | *aResult = nullptr; |
michael@0 | 116 | return commandHandler->Exec(aCommand, aStatus, aResult); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | // Return an empty string |
michael@0 | 120 | const char szEmpty[] = ""; |
michael@0 | 121 | *aResult = (char *) nsMemory::Clone(szEmpty, sizeof(szEmpty)); |
michael@0 | 122 | |
michael@0 | 123 | return NS_OK; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | /* string query (in string aCommand, in string aStatus); */ |
michael@0 | 127 | NS_IMETHODIMP nsCommandHandler::Query(const char *aCommand, const char *aStatus, char **aResult) |
michael@0 | 128 | { |
michael@0 | 129 | NS_ENSURE_ARG_POINTER(aCommand); |
michael@0 | 130 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 131 | |
michael@0 | 132 | nsCOMPtr<nsICommandHandler> commandHandler; |
michael@0 | 133 | GetCommandHandler(getter_AddRefs(commandHandler)); |
michael@0 | 134 | |
michael@0 | 135 | // Call the client's command handler to deal with this command |
michael@0 | 136 | if (commandHandler) |
michael@0 | 137 | { |
michael@0 | 138 | *aResult = nullptr; |
michael@0 | 139 | return commandHandler->Query(aCommand, aStatus, aResult); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | // Return an empty string |
michael@0 | 143 | const char szEmpty[] = ""; |
michael@0 | 144 | *aResult = (char *) nsMemory::Clone(szEmpty, sizeof(szEmpty)); |
michael@0 | 145 | |
michael@0 | 146 | return NS_OK; |
michael@0 | 147 | } |