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