Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "nsString.h" |
michael@0 | 7 | #include "nsIComponentManager.h" |
michael@0 | 8 | #include "nsBaseCommandController.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsString.h" |
michael@0 | 11 | #include "nsWeakPtr.h" |
michael@0 | 12 | |
michael@0 | 13 | NS_IMPL_ADDREF(nsBaseCommandController) |
michael@0 | 14 | NS_IMPL_RELEASE(nsBaseCommandController) |
michael@0 | 15 | |
michael@0 | 16 | NS_INTERFACE_MAP_BEGIN(nsBaseCommandController) |
michael@0 | 17 | NS_INTERFACE_MAP_ENTRY(nsIController) |
michael@0 | 18 | NS_INTERFACE_MAP_ENTRY(nsICommandController) |
michael@0 | 19 | NS_INTERFACE_MAP_ENTRY(nsIControllerContext) |
michael@0 | 20 | NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) |
michael@0 | 21 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllerContext) |
michael@0 | 22 | NS_INTERFACE_MAP_END |
michael@0 | 23 | |
michael@0 | 24 | nsBaseCommandController::nsBaseCommandController() |
michael@0 | 25 | : mCommandContextRawPtr(nullptr) |
michael@0 | 26 | { |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | nsBaseCommandController::~nsBaseCommandController() |
michael@0 | 30 | { |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | NS_IMETHODIMP |
michael@0 | 34 | nsBaseCommandController::Init(nsIControllerCommandTable *aCommandTable) |
michael@0 | 35 | { |
michael@0 | 36 | nsresult rv = NS_OK; |
michael@0 | 37 | |
michael@0 | 38 | if (aCommandTable) |
michael@0 | 39 | mCommandTable = aCommandTable; // owning addref |
michael@0 | 40 | else |
michael@0 | 41 | mCommandTable = do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); |
michael@0 | 42 | |
michael@0 | 43 | return rv; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | NS_IMETHODIMP |
michael@0 | 47 | nsBaseCommandController::SetCommandContext(nsISupports *aCommandContext) |
michael@0 | 48 | { |
michael@0 | 49 | mCommandContextWeakPtr = nullptr; |
michael@0 | 50 | mCommandContextRawPtr = nullptr; |
michael@0 | 51 | |
michael@0 | 52 | if (aCommandContext) { |
michael@0 | 53 | nsCOMPtr<nsISupportsWeakReference> weak = do_QueryInterface(aCommandContext); |
michael@0 | 54 | if (weak) { |
michael@0 | 55 | nsresult rv = |
michael@0 | 56 | weak->GetWeakReference(getter_AddRefs(mCommandContextWeakPtr)); |
michael@0 | 57 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 58 | } |
michael@0 | 59 | else { |
michael@0 | 60 | mCommandContextRawPtr = aCommandContext; |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | return NS_OK; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | NS_IMETHODIMP |
michael@0 | 68 | nsBaseCommandController::GetInterface(const nsIID & aIID, void * *result) |
michael@0 | 69 | { |
michael@0 | 70 | NS_ENSURE_ARG_POINTER(result); |
michael@0 | 71 | |
michael@0 | 72 | if (NS_SUCCEEDED(QueryInterface(aIID, result))) |
michael@0 | 73 | return NS_OK; |
michael@0 | 74 | |
michael@0 | 75 | if (aIID.Equals(NS_GET_IID(nsIControllerCommandTable))) |
michael@0 | 76 | { |
michael@0 | 77 | if (mCommandTable) |
michael@0 | 78 | return mCommandTable->QueryInterface(aIID, result); |
michael@0 | 79 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | return NS_NOINTERFACE; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | |
michael@0 | 87 | /* ======================================================================= |
michael@0 | 88 | * nsIController |
michael@0 | 89 | * ======================================================================= */ |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHODIMP |
michael@0 | 92 | nsBaseCommandController::IsCommandEnabled(const char *aCommand, |
michael@0 | 93 | bool *aResult) |
michael@0 | 94 | { |
michael@0 | 95 | NS_ENSURE_ARG_POINTER(aCommand); |
michael@0 | 96 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 97 | NS_ENSURE_STATE(mCommandTable); |
michael@0 | 98 | |
michael@0 | 99 | nsISupports* context = mCommandContextRawPtr; |
michael@0 | 100 | nsCOMPtr<nsISupports> weak; |
michael@0 | 101 | if (!context) { |
michael@0 | 102 | weak = do_QueryReferent(mCommandContextWeakPtr); |
michael@0 | 103 | context = weak; |
michael@0 | 104 | } |
michael@0 | 105 | return mCommandTable->IsCommandEnabled(aCommand, context, aResult); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | NS_IMETHODIMP |
michael@0 | 109 | nsBaseCommandController::SupportsCommand(const char *aCommand, bool *aResult) |
michael@0 | 110 | { |
michael@0 | 111 | NS_ENSURE_ARG_POINTER(aCommand); |
michael@0 | 112 | NS_ENSURE_ARG_POINTER(aResult); |
michael@0 | 113 | NS_ENSURE_STATE(mCommandTable); |
michael@0 | 114 | |
michael@0 | 115 | nsISupports* context = mCommandContextRawPtr; |
michael@0 | 116 | nsCOMPtr<nsISupports> weak; |
michael@0 | 117 | if (!context) { |
michael@0 | 118 | weak = do_QueryReferent(mCommandContextWeakPtr); |
michael@0 | 119 | context = weak; |
michael@0 | 120 | } |
michael@0 | 121 | return mCommandTable->SupportsCommand(aCommand, context, aResult); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | NS_IMETHODIMP |
michael@0 | 125 | nsBaseCommandController::DoCommand(const char *aCommand) |
michael@0 | 126 | { |
michael@0 | 127 | NS_ENSURE_ARG_POINTER(aCommand); |
michael@0 | 128 | NS_ENSURE_STATE(mCommandTable); |
michael@0 | 129 | |
michael@0 | 130 | nsISupports* context = mCommandContextRawPtr; |
michael@0 | 131 | nsCOMPtr<nsISupports> weak; |
michael@0 | 132 | if (!context) { |
michael@0 | 133 | weak = do_QueryReferent(mCommandContextWeakPtr); |
michael@0 | 134 | context = weak; |
michael@0 | 135 | } |
michael@0 | 136 | return mCommandTable->DoCommand(aCommand, context); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | NS_IMETHODIMP |
michael@0 | 140 | nsBaseCommandController::DoCommandWithParams(const char *aCommand, |
michael@0 | 141 | nsICommandParams *aParams) |
michael@0 | 142 | { |
michael@0 | 143 | NS_ENSURE_ARG_POINTER(aCommand); |
michael@0 | 144 | NS_ENSURE_STATE(mCommandTable); |
michael@0 | 145 | |
michael@0 | 146 | nsISupports* context = mCommandContextRawPtr; |
michael@0 | 147 | nsCOMPtr<nsISupports> weak; |
michael@0 | 148 | if (!context) { |
michael@0 | 149 | weak = do_QueryReferent(mCommandContextWeakPtr); |
michael@0 | 150 | context = weak; |
michael@0 | 151 | } |
michael@0 | 152 | return mCommandTable->DoCommandParams(aCommand, aParams, context); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | NS_IMETHODIMP |
michael@0 | 156 | nsBaseCommandController::GetCommandStateWithParams(const char *aCommand, |
michael@0 | 157 | nsICommandParams *aParams) |
michael@0 | 158 | { |
michael@0 | 159 | NS_ENSURE_ARG_POINTER(aCommand); |
michael@0 | 160 | NS_ENSURE_STATE(mCommandTable); |
michael@0 | 161 | |
michael@0 | 162 | nsISupports* context = mCommandContextRawPtr; |
michael@0 | 163 | nsCOMPtr<nsISupports> weak; |
michael@0 | 164 | if (!context) { |
michael@0 | 165 | weak = do_QueryReferent(mCommandContextWeakPtr); |
michael@0 | 166 | context = weak; |
michael@0 | 167 | } |
michael@0 | 168 | return mCommandTable->GetCommandState(aCommand, aParams, context); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | NS_IMETHODIMP |
michael@0 | 172 | nsBaseCommandController::OnEvent(const char * aEventName) |
michael@0 | 173 | { |
michael@0 | 174 | NS_ENSURE_ARG_POINTER(aEventName); |
michael@0 | 175 | return NS_OK; |
michael@0 | 176 | } |