xpcom/tests/windows/TestHelloXPLoop.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 *
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 "nsIServiceManager.h"
michael@0 8 #include "nsCOMPtr.h"
michael@0 9 #include "nsCNativeApp.h"
michael@0 10 #include "nsIEventLoop.h"
michael@0 11 #include <windows.h>
michael@0 12
michael@0 13 static NS_DEFINE_CID(kNativeAppCID, NS_NATIVE_APP_CID);
michael@0 14
michael@0 15 LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
michael@0 16
michael@0 17 void ErrorBox(LPSTR text)
michael@0 18 {
michael@0 19 MessageBox(nullptr, text, "XP Event Loop", MB_OK | MB_ICONSTOP);
michael@0 20 }
michael@0 21
michael@0 22 void InfoBox(LPSTR text)
michael@0 23 {
michael@0 24 MessageBox(nullptr, text, "XP Event Loop", MB_OK | MB_ICONINFORMATION);
michael@0 25 }
michael@0 26
michael@0 27 int WINAPI WinMain(HINSTANCE inst,
michael@0 28 HINSTANCE prevInstance,
michael@0 29 LPSTR lpszCmdLine,
michael@0 30 int nShowCmd)
michael@0 31 {
michael@0 32 char* lpszAppName = "HelloWorld";
michael@0 33 HWND wnd;
michael@0 34 WNDCLASSEX wndclass;
michael@0 35 int retCode;
michael@0 36
michael@0 37 { // Needed to scope all nsCOMPtr within XPCOM Init and Shutdown
michael@0 38 nsresult rv;
michael@0 39 nsCOMPtr<nsIServiceManager> servMan;
michael@0 40 rv = NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
michael@0 41 if(NS_FAILED(rv))
michael@0 42 {
michael@0 43 ErrorBox("Failed to initialize xpcom.");
michael@0 44 return -1;
michael@0 45 }
michael@0 46
michael@0 47 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
michael@0 48 NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
michael@0 49 registrar->AutoRegister(nullptr);
michael@0 50
michael@0 51 nsCOMPtr<nsINativeApp> nativeAppService(do_GetService(kNativeAppCID, &rv));
michael@0 52
michael@0 53 if(NS_FAILED(rv))
michael@0 54 {
michael@0 55 ErrorBox("Failed to get nativeAppService");
michael@0 56 return -1;
michael@0 57 }
michael@0 58 wndclass.cbSize = sizeof(wndclass);
michael@0 59 wndclass.style = CS_HREDRAW | CS_VREDRAW;
michael@0 60 wndclass.lpfnWndProc = WndProc;
michael@0 61 wndclass.cbClsExtra = 0;
michael@0 62 wndclass.cbWndExtra = 0;
michael@0 63 wndclass.hInstance = inst;
michael@0 64 wndclass.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
michael@0 65 wndclass.hCursor = LoadCursor(nullptr, IDC_ARROW);
michael@0 66 wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
michael@0 67 wndclass.lpszMenuName = nullptr;
michael@0 68 wndclass.lpszClassName = lpszAppName;
michael@0 69 wndclass.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);
michael@0 70
michael@0 71 RegisterClassEx(&wndclass) ;
michael@0 72
michael@0 73 wnd = CreateWindow(lpszAppName, "The Hello World",
michael@0 74 WS_OVERLAPPEDWINDOW,
michael@0 75 CW_USEDEFAULT, CW_USEDEFAULT,
michael@0 76 CW_USEDEFAULT, CW_USEDEFAULT,
michael@0 77 nullptr, nullptr, inst, nullptr);
michael@0 78
michael@0 79 ShowWindow(wnd, nShowCmd);
michael@0 80 UpdateWindow(wnd);
michael@0 81
michael@0 82 nsCOMPtr<nsIEventLoop> eventLoop;
michael@0 83
michael@0 84 if(NS_FAILED(nativeAppService->CreateEventLoop(L"_MainLoop",
michael@0 85 nsEventLoopTypes::MainAppLoop, getter_AddRefs(eventLoop))))
michael@0 86 {
michael@0 87 ErrorBox("Failed to create event Loop");
michael@0 88 return 0;
michael@0 89 }
michael@0 90
michael@0 91 eventLoop->Run(nullptr, nullptr, nullptr, &retCode);
michael@0 92 eventLoop = nullptr; // Clear out before Shutting down XPCOM
michael@0 93
michael@0 94 InfoBox("Hello World app is out of loop");
michael@0 95 }
michael@0 96 NS_ShutdownXPCOM(nullptr);
michael@0 97 InfoBox("Hello World app is exiting");
michael@0 98 return retCode;
michael@0 99 }
michael@0 100
michael@0 101 LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
michael@0 102 {
michael@0 103 HDC hdc;
michael@0 104 PAINTSTRUCT ps;
michael@0 105 RECT rect;
michael@0 106
michael@0 107 switch(msg)
michael@0 108 {
michael@0 109 case WM_PAINT:
michael@0 110 hdc = BeginPaint(wnd, &ps);
michael@0 111
michael@0 112 GetClientRect(wnd, &rect);
michael@0 113
michael@0 114 DrawText(hdc, "Hello, XP Event Loop!", -1, &rect,
michael@0 115 DT_SINGLELINE | DT_CENTER | DT_VCENTER);
michael@0 116
michael@0 117 EndPaint(wnd, &ps);
michael@0 118 return 0;
michael@0 119
michael@0 120 case WM_DESTROY:
michael@0 121 {
michael@0 122 nsresult rv;
michael@0 123 nsCOMPtr<nsINativeApp> nativeAppService =
michael@0 124 do_GetService(kNativeAppCID, &rv);
michael@0 125 if(NS_FAILED(rv))
michael@0 126 {
michael@0 127 ErrorBox("Could not get NativeAppService");
michael@0 128 return 0;
michael@0 129 }
michael@0 130 nsCOMPtr<nsIEventLoop> eventLoop;
michael@0 131
michael@0 132 if(NS_FAILED(nativeAppService->FindEventLoop(L"_MainLoop",
michael@0 133 getter_AddRefs(eventLoop))))
michael@0 134 {
michael@0 135 ErrorBox("Failed to find event Loop");
michael@0 136 return 0;
michael@0 137 }
michael@0 138 eventLoop->Exit(0);
michael@0 139 }
michael@0 140 return 0;
michael@0 141 }
michael@0 142
michael@0 143 return DefWindowProc(wnd, msg, wParam, lParam);
michael@0 144 }

mercurial