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