1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
6
7 #include "JaIncomingServer.h"
8 #include "nsComponentManagerUtils.h"
9
10 // This file specifies the implementation of nsIMsgIncomingServer.idl objects
11 // in the JsAccount system.
12
13 namespace mozilla {
14 namespace mailnews {
15
NS_IMPL_ISUPPORTS_INHERITED(JaBaseCppIncomingServer,nsMsgIncomingServer,nsIInterfaceRequestor)16 NS_IMPL_ISUPPORTS_INHERITED(JaBaseCppIncomingServer, nsMsgIncomingServer,
17 nsIInterfaceRequestor)
18
19 // nsMsgIncomingServer overrides
20 nsresult JaBaseCppIncomingServer::CreateRootFolderFromUri(
21 const nsACString& serverUri, nsIMsgFolder** rootFolder) {
22 return NS_ERROR_NOT_IMPLEMENTED;
23 }
24
25 // nsIInterfaceRequestor implementation
26 NS_IMETHODIMP
GetInterface(const nsIID & aIID,void ** aSink)27 JaBaseCppIncomingServer::GetInterface(const nsIID& aIID, void** aSink) {
28 return QueryInterface(aIID, aSink);
29 }
30
31 // Delegator object to bypass JS method override.
32
JaCppIncomingServerDelegator()33 JaCppIncomingServerDelegator::JaCppIncomingServerDelegator() {
34 mCppBase = do_QueryInterface(
35 NS_ISUPPORTS_CAST(nsIMsgIncomingServer*, new Super(this)));
36 mMethods = nullptr;
37 }
38
NS_IMPL_ISUPPORTS_INHERITED(JaCppIncomingServerDelegator,JaBaseCppIncomingServer,msgIOverride)39 NS_IMPL_ISUPPORTS_INHERITED(JaCppIncomingServerDelegator,
40 JaBaseCppIncomingServer, msgIOverride)
41
42 NS_IMPL_ISUPPORTS(JaCppIncomingServerDelegator::Super, nsIMsgIncomingServer,
43 nsIInterfaceRequestor)
44
45 NS_IMETHODIMP
46 JaCppIncomingServerDelegator::SetMethodsToDelegate(
47 msgIDelegateList* aDelegateList) {
48 if (!aDelegateList) {
49 NS_WARNING("Null delegate list");
50 return NS_ERROR_NULL_POINTER;
51 }
52 // We static_cast since we want to use the hash object directly.
53 mDelegateList = static_cast<DelegateList*>(aDelegateList);
54 mMethods = &(mDelegateList->mMethods);
55 return NS_OK;
56 }
57 NS_IMETHODIMP
GetMethodsToDelegate(msgIDelegateList ** aDelegateList)58 JaCppIncomingServerDelegator::GetMethodsToDelegate(
59 msgIDelegateList** aDelegateList) {
60 if (!mDelegateList) mDelegateList = new DelegateList();
61 mMethods = &(mDelegateList->mMethods);
62 NS_ADDREF(*aDelegateList = mDelegateList);
63 return NS_OK;
64 }
65
66 NS_IMETHODIMP
SetJsDelegate(nsISupports * aJsDelegate)67 JaCppIncomingServerDelegator::SetJsDelegate(nsISupports* aJsDelegate) {
68 // If these QIs fail, then overrides are not provided for methods in that
69 // interface, which is OK.
70 mJsISupports = aJsDelegate;
71 mJsIMsgIncomingServer = do_QueryInterface(aJsDelegate);
72 mJsIInterfaceRequestor = do_QueryInterface(aJsDelegate);
73 return NS_OK;
74 }
75 NS_IMETHODIMP
GetJsDelegate(nsISupports ** aJsDelegate)76 JaCppIncomingServerDelegator::GetJsDelegate(nsISupports** aJsDelegate) {
77 NS_ENSURE_ARG_POINTER(aJsDelegate);
78 if (mJsISupports) {
79 NS_ADDREF(*aJsDelegate = mJsISupports);
80 return NS_OK;
81 }
82 return NS_ERROR_NOT_INITIALIZED;
83 }
84
85 NS_IMETHODIMP
GetCppBase(nsISupports ** aCppBase)86 JaCppIncomingServerDelegator::GetCppBase(nsISupports** aCppBase) {
87 nsCOMPtr<nsISupports> cppBaseSupports;
88 cppBaseSupports = NS_ISUPPORTS_CAST(nsIMsgIncomingServer*, mCppBase);
89 NS_ENSURE_STATE(cppBaseSupports);
90 cppBaseSupports.forget(aCppBase);
91
92 return NS_OK;
93 }
94
95 } // namespace mailnews
96 } // namespace mozilla
97