xpcom/tests/windows/TestCOM.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 /* 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 <windows.h>
michael@0 7 #include <unknwn.h>
michael@0 8 #include <stdio.h>
michael@0 9 #include "nsISupports.h"
michael@0 10 #include "nsIFactory.h"
michael@0 11
michael@0 12 // unknwn.h is needed to build with WIN32_LEAN_AND_MEAN
michael@0 13 #include <unknwn.h>
michael@0 14
michael@0 15 // {5846BA30-B856-11d1-A98A-00805F8A7AC4}
michael@0 16 #define NS_ITEST_COM_IID \
michael@0 17 { 0x5846ba30, 0xb856, 0x11d1, \
michael@0 18 { 0xa9, 0x8a, 0x0, 0x80, 0x5f, 0x8a, 0x7a, 0xc4 } }
michael@0 19
michael@0 20 class nsITestCom: public nsISupports
michael@0 21 {
michael@0 22 public:
michael@0 23 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEST_COM_IID)
michael@0 24 NS_IMETHOD Test() = 0;
michael@0 25 };
michael@0 26
michael@0 27 NS_DEFINE_STATIC_IID_ACCESSOR(nsITestCom, NS_ITEST_COM_IID)
michael@0 28
michael@0 29 /*
michael@0 30 * nsTestCom
michael@0 31 */
michael@0 32
michael@0 33 class nsTestCom MOZ_FINAL : public nsITestCom {
michael@0 34 NS_DECL_ISUPPORTS
michael@0 35
michael@0 36 public:
michael@0 37 nsTestCom() {
michael@0 38 }
michael@0 39
michael@0 40 NS_IMETHOD Test() {
michael@0 41 printf("Accessed nsITestCom::Test() from COM\n");
michael@0 42 return NS_OK;
michael@0 43 }
michael@0 44
michael@0 45 private:
michael@0 46 ~nsTestCom() {
michael@0 47 printf("nsTestCom instance successfully deleted\n");
michael@0 48 }
michael@0 49 };
michael@0 50
michael@0 51 NS_IMPL_QUERY_INTERFACE(nsTestCom, nsITestCom)
michael@0 52
michael@0 53 MozExternalRefCountType nsTestCom::AddRef()
michael@0 54 {
michael@0 55 nsrefcnt res = ++mRefCnt;
michael@0 56 NS_LOG_ADDREF(this, mRefCnt, "nsTestCom", sizeof(*this));
michael@0 57 printf("nsTestCom: Adding ref = %d\n", res);
michael@0 58 return res;
michael@0 59 }
michael@0 60
michael@0 61 MozExternalRefCountType nsTestCom::Release()
michael@0 62 {
michael@0 63 nsrefcnt res = --mRefCnt;
michael@0 64 NS_LOG_RELEASE(this, mRefCnt, "nsTestCom");
michael@0 65 printf("nsTestCom: Releasing = %d\n", res);
michael@0 66 if (res == 0) {
michael@0 67 delete this;
michael@0 68 }
michael@0 69 return res;
michael@0 70 }
michael@0 71
michael@0 72 class nsTestComFactory MOZ_FINAL : public nsIFactory {
michael@0 73 NS_DECL_ISUPPORTS
michael@0 74 public:
michael@0 75 nsTestComFactory() {
michael@0 76 }
michael@0 77
michael@0 78 NS_IMETHOD CreateInstance(nsISupports *aOuter,
michael@0 79 const nsIID &aIID,
michael@0 80 void **aResult);
michael@0 81
michael@0 82 NS_IMETHOD LockFactory(bool aLock) {
michael@0 83 printf("nsTestComFactory: ");
michael@0 84 printf("%s", (aLock ? "Locking server" : "Unlocking server"));
michael@0 85 printf("\n");
michael@0 86 return NS_OK;
michael@0 87 }
michael@0 88 };
michael@0 89
michael@0 90 NS_IMPL_ISUPPORTS(nsTestComFactory, nsIFactory)
michael@0 91
michael@0 92 nsresult nsTestComFactory::CreateInstance(nsISupports *aOuter,
michael@0 93 const nsIID &aIID,
michael@0 94 void **aResult)
michael@0 95 {
michael@0 96 if (aOuter != nullptr) {
michael@0 97 return NS_ERROR_NO_AGGREGATION;
michael@0 98 }
michael@0 99
michael@0 100 nsTestCom *t = new nsTestCom();
michael@0 101
michael@0 102 if (t == nullptr) {
michael@0 103 return NS_ERROR_OUT_OF_MEMORY;
michael@0 104 }
michael@0 105
michael@0 106 NS_ADDREF(t);
michael@0 107 nsresult res = t->QueryInterface(aIID, aResult);
michael@0 108 NS_RELEASE(t);
michael@0 109
michael@0 110 if (NS_SUCCEEDED(res)) {
michael@0 111 printf("nsTestComFactory: successfully created nsTestCom instance\n");
michael@0 112 }
michael@0 113
michael@0 114 return res;
michael@0 115 }
michael@0 116
michael@0 117 /*
michael@0 118 * main
michael@0 119 */
michael@0 120
michael@0 121 int main(int argc, char *argv[])
michael@0 122 {
michael@0 123 nsTestComFactory *inst = new nsTestComFactory();
michael@0 124 IClassFactory *iFactory;
michael@0 125 inst->QueryInterface(NS_GET_IID(nsIFactory), (void **) &iFactory);
michael@0 126
michael@0 127 IUnknown *iUnknown;
michael@0 128 nsITestCom *iTestCom;
michael@0 129
michael@0 130 iFactory->LockServer(TRUE);
michael@0 131 iFactory->CreateInstance(nullptr, IID_IUnknown, (void **) &iUnknown);
michael@0 132 iFactory->LockServer(FALSE);
michael@0 133
michael@0 134 GUID testGUID = NS_ITEST_COM_IID;
michael@0 135 HRESULT hres;
michael@0 136 hres= iUnknown->QueryInterface(testGUID,
michael@0 137 (void **) &iTestCom);
michael@0 138
michael@0 139 iTestCom->Test();
michael@0 140
michael@0 141 iUnknown->Release();
michael@0 142 iTestCom->Release();
michael@0 143 iFactory->Release();
michael@0 144
michael@0 145 return 0;
michael@0 146 }
michael@0 147

mercurial