1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/embedding/tests/winEmbed/winEmbed.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1135 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* ***** BEGIN LICENSE BLOCK ***** 1.6 + * Version: Mozilla-sample-code 1.0 1.7 + * 1.8 + * Copyright (c) 2002 Netscape Communications Corporation and 1.9 + * other contributors 1.10 + * 1.11 + * Permission is hereby granted, free of charge, to any person obtaining a 1.12 + * copy of this Mozilla sample software and associated documentation files 1.13 + * (the "Software"), to deal in the Software without restriction, including 1.14 + * without limitation the rights to use, copy, modify, merge, publish, 1.15 + * distribute, sublicense, and/or sell copies of the Software, and to permit 1.16 + * persons to whom the Software is furnished to do so, subject to the 1.17 + * following conditions: 1.18 + * 1.19 + * The above copyright notice and this permission notice shall be included 1.20 + * in all copies or substantial portions of the Software. 1.21 + * 1.22 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1.23 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.24 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1.25 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.26 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 1.27 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 1.28 + * DEALINGS IN THE SOFTWARE. 1.29 + * 1.30 + * Contributor(s): 1.31 + * Doug Turner <dougt@netscape.com> 1.32 + * Adam Lock <adamlock@netscape.com> 1.33 + * 1.34 + * ***** END LICENSE BLOCK ***** */ 1.35 + 1.36 +// C RunTime Header Files 1.37 +#include <stdio.h> 1.38 +#include <stdlib.h> 1.39 +#include <malloc.h> 1.40 +#include <memory.h> 1.41 +#include <tchar.h> 1.42 + 1.43 +// Win32 header files 1.44 +#include <windows.h> 1.45 +#include <commctrl.h> 1.46 +#include <commdlg.h> 1.47 + 1.48 +// Mozilla Frozen APIs 1.49 +#include "nsXULAppAPI.h" 1.50 + 1.51 +XRE_InitEmbedding2Type XRE_InitEmbedding2; 1.52 +XRE_TermEmbeddingType XRE_TermEmbedding; 1.53 + 1.54 +#include "nsAppDirectoryServiceDefs.h" 1.55 +#include "nsDirectoryServiceDefs.h" 1.56 +#include "nsProfileDirServiceProvider.h" 1.57 +#include "nsStringAPI.h" 1.58 +#include "nsXPCOMGlue.h" 1.59 + 1.60 +#include "nsIClipboardCommands.h" 1.61 +#include "nsIInterfaceRequestor.h" 1.62 +#include "nsIObserverService.h" 1.63 +#include "nsIObserver.h" 1.64 +#include "nsIURI.h" 1.65 +#include "nsIWebBrowserFocus.h" 1.66 +#include "nsIWindowWatcher.h" 1.67 + 1.68 +// NON-FROZEN APIs! 1.69 +#include "nsIBaseWindow.h" 1.70 +#include "nsIWebNavigation.h" 1.71 + 1.72 +// Local header files 1.73 +#include "winEmbed.h" 1.74 +#include "WebBrowserChrome.h" 1.75 +#include "WindowCreator.h" 1.76 +#include "resource.h" 1.77 + 1.78 +#define MAX_LOADSTRING 100 1.79 + 1.80 +const TCHAR *szWindowClass = _T("WINEMBED"); 1.81 + 1.82 +// Foward declarations of functions included in this code module: 1.83 +static ATOM MyRegisterClass(HINSTANCE hInstance); 1.84 +static LRESULT CALLBACK BrowserWndProc(HWND, UINT, WPARAM, LPARAM); 1.85 +static INT_PTR CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 1.86 + 1.87 +static nsresult InitializeWindowCreator(); 1.88 +static nsresult OpenWebPage(const char * url); 1.89 +static nsresult ResizeEmbedding(nsIWebBrowserChrome* chrome); 1.90 + 1.91 +// Profile chooser stuff 1.92 +static nsresult StartupProfile(); 1.93 + 1.94 +// Global variables 1.95 +static UINT gDialogCount = 0; 1.96 +static HINSTANCE ghInstanceApp = nullptr; 1.97 +static char gFirstURL[1024]; 1.98 + 1.99 +// like strpbrk but finds the *last* char, not the first 1.100 +static char* 1.101 +ns_strrpbrk(char *string, const char *strCharSet) 1.102 +{ 1.103 + char *found = nullptr; 1.104 + for (; *string; ++string) { 1.105 + for (const char *search = strCharSet; *search; ++search) { 1.106 + if (*search == *string) { 1.107 + found = string; 1.108 + // Since we're looking for the last char, we save "found" 1.109 + // until we're at the end of the string. 1.110 + } 1.111 + } 1.112 + } 1.113 + 1.114 + return found; 1.115 +} 1.116 + 1.117 +// A list of URLs to populate the URL drop down list with 1.118 +static const TCHAR *gDefaultURLs[] = 1.119 +{ 1.120 + _T("http://www.mozilla.org/"), 1.121 + _T("http://www.netscape.com/"), 1.122 + _T("http://browsertest.web.aol.com/tests/javascript/javascpt/index.htm"), 1.123 + _T("http://127.0.0.1/"), 1.124 + _T("http://www.yahoo.com/"), 1.125 + _T("http://www.travelocity.com/"), 1.126 + _T("http://www.disney.com/"), 1.127 + _T("http://www.go.com/"), 1.128 + _T("http://www.google.com/"), 1.129 + _T("http://www.ebay.com/"), 1.130 + _T("http://www.shockwave.com/"), 1.131 + _T("http://www.slashdot.org/"), 1.132 + _T("http://www.quicken.com/"), 1.133 + _T("http://www.hotmail.com/"), 1.134 + _T("http://www.cnn.com/"), 1.135 + _T("http://www.javasoft.com/") 1.136 +}; 1.137 + 1.138 +int main(int argc, char *argv[]) 1.139 +{ 1.140 + nsresult rv; 1.141 + 1.142 + printf("You are embedded, man!\n\n"); 1.143 + printf("******************************************************************\n"); 1.144 + printf("* *\n"); 1.145 + printf("* IMPORTANT NOTE: *\n"); 1.146 + printf("* *\n"); 1.147 + printf("* WinEmbed is not supported!!! Do not raise bugs on it unless *\n"); 1.148 + printf("* it is badly broken (e.g. crash on start/exit, build errors) *\n"); 1.149 + printf("* or you have the patch to make it better! MFCEmbed is now our *\n"); 1.150 + printf("* embedding test application on Win32 and all testing should *\n"); 1.151 + printf("* be done on that. *\n"); 1.152 + printf("* *\n"); 1.153 + printf("******************************************************************\n"); 1.154 + printf("\n\n"); 1.155 + 1.156 + // Sophisticated command-line parsing in action 1.157 + char *szFirstURL = "http://www.mozilla.org/projects/embedding/"; 1.158 + int argn; 1.159 + for (argn = 1; argn < argc; argn++) 1.160 + { 1.161 + szFirstURL = argv[argn]; 1.162 + } 1.163 + strncpy(gFirstURL, szFirstURL, sizeof(gFirstURL) - 1); 1.164 + 1.165 + ghInstanceApp = GetModuleHandle(nullptr); 1.166 + 1.167 + // Initialize global strings 1.168 + TCHAR szTitle[MAX_LOADSTRING]; 1.169 + LoadString(ghInstanceApp, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 1.170 + MyRegisterClass(ghInstanceApp); 1.171 + 1.172 + char path[_MAX_PATH]; 1.173 + GetModuleFileName(ghInstanceApp, path, sizeof(path)); 1.174 + char* lastslash = ns_strrpbrk(path, "/\\"); 1.175 + if (!lastslash) 1.176 + return 7; 1.177 + 1.178 + strcpy(lastslash, "\\xulrunner\\xpcom.dll"); 1.179 + 1.180 + rv = XPCOMGlueStartup(path); 1.181 + if (NS_FAILED(rv)) 1.182 + return 3; 1.183 + 1.184 + strcpy(lastslash, "\\xulrunner\\xul.dll"); 1.185 + 1.186 + HINSTANCE xulModule = LoadLibraryEx(path, nullptr, 0); 1.187 + if (!xulModule) 1.188 + return 4; 1.189 + 1.190 + XRE_InitEmbedding2 = 1.191 + (XRE_InitEmbedding2Type) GetProcAddress(xulModule, "XRE_InitEmbedding2"); 1.192 + if (!XRE_InitEmbedding2) { 1.193 + fprintf(stderr, "Error: %i\n", GetLastError()); 1.194 + return 5; 1.195 + } 1.196 + 1.197 + XRE_TermEmbedding = 1.198 + (XRE_TermEmbeddingType) GetProcAddress(xulModule, "XRE_TermEmbedding"); 1.199 + if (!XRE_TermEmbedding) { 1.200 + fprintf(stderr, "Error: %i\n", GetLastError()); 1.201 + return 5; 1.202 + } 1.203 + 1.204 + int result = 0; 1.205 + 1.206 + // Scope all the XPCOM stuff 1.207 + { 1.208 + strcpy(lastslash, "\\xulrunner"); 1.209 + 1.210 + nsCOMPtr<nsIFile> xuldir; 1.211 + rv = NS_NewNativeLocalFile(nsCString(path), false, 1.212 + getter_AddRefs(xuldir)); 1.213 + if (NS_FAILED(rv)) 1.214 + return 6; 1.215 + 1.216 + *lastslash = '\0'; 1.217 + 1.218 + nsCOMPtr<nsIFile> appdir; 1.219 + rv = NS_NewNativeLocalFile(nsCString(path), false, 1.220 + getter_AddRefs(appdir)); 1.221 + if (NS_FAILED(rv)) 1.222 + return 8; 1.223 + 1.224 + rv = XRE_InitEmbedding2(xuldir, appdir, nullptr); 1.225 + if (NS_FAILED(rv)) 1.226 + return 9; 1.227 + 1.228 + if (NS_FAILED(StartupProfile())) { 1.229 + result = 8; 1.230 + } 1.231 + else { 1.232 + InitializeWindowCreator(); 1.233 + 1.234 + // Open the initial browser window 1.235 + OpenWebPage(gFirstURL); 1.236 + 1.237 + // Main message loop. 1.238 + // NOTE: We use a fake event and a timeout in order to process idle stuff for 1.239 + // Mozilla every 1/10th of a second. 1.240 + bool runCondition = true; 1.241 + 1.242 + result = AppCallbacks::RunEventLoop(runCondition); 1.243 + } 1.244 + } 1.245 + XRE_TermEmbedding(); 1.246 + 1.247 + return result; 1.248 +} 1.249 + 1.250 +/* InitializeWindowCreator creates and hands off an object with a callback 1.251 + to a window creation function. This is how all new windows are opened, 1.252 + except any created directly by the embedding app. */ 1.253 +nsresult 1.254 +InitializeWindowCreator() 1.255 +{ 1.256 + // create an nsWindowCreator and give it to the WindowWatcher service 1.257 + nsCOMPtr<nsIWindowCreator> creator(new WindowCreator()); 1.258 + if (!creator) 1.259 + return NS_ERROR_OUT_OF_MEMORY; 1.260 + 1.261 + nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); 1.262 + if (!wwatch) 1.263 + return NS_ERROR_UNEXPECTED; 1.264 + 1.265 + return wwatch->SetWindowCreator(creator); 1.266 +} 1.267 + 1.268 +//----------------------------------------------------------------------------- 1.269 + 1.270 +// 1.271 +// FUNCTION: OpenWebPage() 1.272 +// 1.273 +// PURPOSE: Opens a new browser dialog and starts it loading to the 1.274 +// specified url. 1.275 +// 1.276 +nsresult OpenWebPage(const char *url) 1.277 +{ 1.278 + nsresult rv; 1.279 + 1.280 + // Create the chrome object. Note that it leaves this function 1.281 + // with an extra reference so that it can released correctly during 1.282 + // destruction (via Win32UI::Destroy) 1.283 + 1.284 + nsCOMPtr<nsIWebBrowserChrome> chrome; 1.285 + rv = AppCallbacks::CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL, 1.286 + nullptr, getter_AddRefs(chrome)); 1.287 + if (NS_SUCCEEDED(rv)) 1.288 + { 1.289 + // Start loading a page 1.290 + nsCOMPtr<nsIWebBrowser> newBrowser; 1.291 + chrome->GetWebBrowser(getter_AddRefs(newBrowser)); 1.292 + nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(newBrowser)); 1.293 + 1.294 + return webNav->LoadURI(NS_ConvertASCIItoUTF16(url).get(), 1.295 + nsIWebNavigation::LOAD_FLAGS_NONE, 1.296 + nullptr, 1.297 + nullptr, 1.298 + nullptr); 1.299 + } 1.300 + 1.301 + return rv; 1.302 +} 1.303 + 1.304 +// 1.305 +// FUNCTION: GetBrowserFromChrome() 1.306 +// 1.307 +// PURPOSE: Returns the HWND for the webbrowser container associated 1.308 +// with the specified chrome. 1.309 +// 1.310 +HWND GetBrowserFromChrome(nsIWebBrowserChrome *aChrome) 1.311 +{ 1.312 + if (!aChrome) 1.313 + { 1.314 + return nullptr; 1.315 + } 1.316 + nsCOMPtr<nsIEmbeddingSiteWindow> baseWindow = do_QueryInterface(aChrome); 1.317 + HWND hwnd = nullptr; 1.318 + baseWindow->GetSiteWindow((void **) & hwnd); 1.319 + return hwnd; 1.320 +} 1.321 + 1.322 + 1.323 +// 1.324 +// FUNCTION: GetBrowserDlgFromChrome() 1.325 +// 1.326 +// PURPOSE: Returns the HWND for the browser dialog associated with 1.327 +// the specified chrome. 1.328 +// 1.329 +HWND GetBrowserDlgFromChrome(nsIWebBrowserChrome *aChrome) 1.330 +{ 1.331 + return GetParent(GetBrowserFromChrome(aChrome)); 1.332 +} 1.333 + 1.334 + 1.335 +// 1.336 +// FUNCTION: ResizeEmbedding() 1.337 +// 1.338 +// PURPOSE: Resizes the webbrowser window to fit its container. 1.339 +// 1.340 +nsresult ResizeEmbedding(nsIWebBrowserChrome* chrome) 1.341 +{ 1.342 + if (!chrome) 1.343 + return NS_ERROR_FAILURE; 1.344 + 1.345 + nsCOMPtr<nsIEmbeddingSiteWindow> embeddingSite = do_QueryInterface(chrome); 1.346 + HWND hWnd; 1.347 + embeddingSite->GetSiteWindow((void **) & hWnd); 1.348 + 1.349 + if (!hWnd) 1.350 + return NS_ERROR_NULL_POINTER; 1.351 + 1.352 + RECT rect; 1.353 + GetClientRect(hWnd, &rect); 1.354 + 1.355 + // Make sure the browser is visible and sized 1.356 + nsCOMPtr<nsIWebBrowser> webBrowser; 1.357 + chrome->GetWebBrowser(getter_AddRefs(webBrowser)); 1.358 + nsCOMPtr<nsIBaseWindow> webBrowserAsWin = do_QueryInterface(webBrowser); 1.359 + if (webBrowserAsWin) 1.360 + { 1.361 + webBrowserAsWin->SetPositionAndSize(rect.left, 1.362 + rect.top, 1.363 + rect.right - rect.left, 1.364 + rect.bottom - rect.top, 1.365 + true); 1.366 + webBrowserAsWin->SetVisibility(true); 1.367 + } 1.368 + 1.369 + return NS_OK; 1.370 +} 1.371 + 1.372 + 1.373 +// 1.374 +// FUNCTION: MyRegisterClass() 1.375 +// 1.376 +// PURPOSE: Registers the window class. 1.377 +// 1.378 +// COMMENTS: 1.379 +// 1.380 +// This function and its usage is only necessary if you want this code 1.381 +// to be compatible with Win32 systems prior to the 'RegisterClassEx' 1.382 +// function that was added to Windows 95. It is important to call this function 1.383 +// so that the application will get 'well formed' small icons associated 1.384 +// with it. 1.385 +// 1.386 +ATOM MyRegisterClass(HINSTANCE hInstance) 1.387 +{ 1.388 + WNDCLASSEX wcex; 1.389 + 1.390 + memset(&wcex, 0, sizeof(wcex)); 1.391 + wcex.cbSize = sizeof(WNDCLASSEX); 1.392 + 1.393 + wcex.style = CS_HREDRAW | CS_VREDRAW; 1.394 + wcex.lpfnWndProc = (WNDPROC) BrowserWndProc; 1.395 + wcex.cbClsExtra = 0; 1.396 + wcex.cbWndExtra = 0; 1.397 + wcex.hInstance = hInstance; 1.398 + wcex.hIcon = LoadIcon(ghInstanceApp, (LPCTSTR)IDI_WINEMBED); 1.399 + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); 1.400 + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 1.401 + wcex.lpszClassName = szWindowClass; 1.402 + wcex.hIconSm = LoadIcon(ghInstanceApp, (LPCTSTR)IDI_SMALL); 1.403 + 1.404 + return RegisterClassEx(&wcex); 1.405 +} 1.406 + 1.407 + 1.408 +// 1.409 +// FUNCTION: UpdateUI() 1.410 +// 1.411 +// PURPOSE: Refreshes the buttons and menu items in the browser dialog 1.412 +// 1.413 +void UpdateUI(nsIWebBrowserChrome *aChrome) 1.414 +{ 1.415 + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); 1.416 + nsCOMPtr<nsIWebBrowser> webBrowser; 1.417 + nsCOMPtr<nsIWebNavigation> webNavigation; 1.418 + aChrome->GetWebBrowser(getter_AddRefs(webBrowser)); 1.419 + webNavigation = do_QueryInterface(webBrowser); 1.420 + 1.421 + bool canGoBack = false; 1.422 + bool canGoForward = false; 1.423 + if (webNavigation) 1.424 + { 1.425 + webNavigation->GetCanGoBack(&canGoBack); 1.426 + webNavigation->GetCanGoForward(&canGoForward); 1.427 + } 1.428 + 1.429 + bool canCutSelection = false; 1.430 + bool canCopySelection = false; 1.431 + bool canPaste = false; 1.432 + 1.433 + nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser); 1.434 + if (clipCmds) 1.435 + { 1.436 + clipCmds->CanCutSelection(&canCutSelection); 1.437 + clipCmds->CanCopySelection(&canCopySelection); 1.438 + clipCmds->CanPaste(&canPaste); 1.439 + } 1.440 + 1.441 + HMENU hmenu = GetMenu(hwndDlg); 1.442 + if (hmenu) 1.443 + { 1.444 + EnableMenuItem(hmenu, MOZ_GoBack, MF_BYCOMMAND | 1.445 + ((canGoBack) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); 1.446 + EnableMenuItem(hmenu, MOZ_GoForward, MF_BYCOMMAND | 1.447 + ((canGoForward) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); 1.448 + 1.449 + EnableMenuItem(hmenu, MOZ_Cut, MF_BYCOMMAND | 1.450 + ((canCutSelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); 1.451 + EnableMenuItem(hmenu, MOZ_Copy, MF_BYCOMMAND | 1.452 + ((canCopySelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); 1.453 + EnableMenuItem(hmenu, MOZ_Paste, MF_BYCOMMAND | 1.454 + ((canPaste) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); 1.455 + } 1.456 + 1.457 + HWND button; 1.458 + button = GetDlgItem(hwndDlg, IDC_BACK); 1.459 + if (button) 1.460 + EnableWindow(button, canGoBack); 1.461 + button = GetDlgItem(hwndDlg, IDC_FORWARD); 1.462 + if (button) 1.463 + EnableWindow(button, canGoForward); 1.464 +} 1.465 + 1.466 + 1.467 +// 1.468 +// FUNCTION: BrowserDlgProc() 1.469 +// 1.470 +// PURPOSE: Browser dialog windows message handler. 1.471 +// 1.472 +// COMMENTS: 1.473 +// 1.474 +// The code for handling buttons and menu actions is here. 1.475 +// 1.476 +INT_PTR CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 1.477 +{ 1.478 + // Get the browser and other pointers since they are used a lot below 1.479 + HWND hwndBrowser = GetDlgItem(hwndDlg, IDC_BROWSER); 1.480 + nsIWebBrowserChrome *chrome = nullptr ; 1.481 + if (hwndBrowser) 1.482 + { 1.483 + chrome = (nsIWebBrowserChrome *) GetWindowLongPtr(hwndBrowser, GWLP_USERDATA); 1.484 + } 1.485 + nsCOMPtr<nsIWebBrowser> webBrowser; 1.486 + nsCOMPtr<nsIWebNavigation> webNavigation; 1.487 + if (chrome) 1.488 + { 1.489 + chrome->GetWebBrowser(getter_AddRefs(webBrowser)); 1.490 + webNavigation = do_QueryInterface(webBrowser); 1.491 + } 1.492 + 1.493 + // Test the message 1.494 + switch (uMsg) 1.495 + { 1.496 + case WM_INITDIALOG: 1.497 + return TRUE; 1.498 + 1.499 + case WM_INITMENU: 1.500 + UpdateUI(chrome); 1.501 + return TRUE; 1.502 + 1.503 + case WM_SYSCOMMAND: 1.504 + if (wParam == SC_CLOSE) 1.505 + { 1.506 + WebBrowserChromeUI::Destroy(chrome); 1.507 + return TRUE; 1.508 + } 1.509 + break; 1.510 + 1.511 + case WM_DESTROY: 1.512 + return TRUE; 1.513 + 1.514 + case WM_COMMAND: 1.515 + if (!webBrowser) 1.516 + { 1.517 + return TRUE; 1.518 + } 1.519 + 1.520 + // Test which command was selected 1.521 + switch (LOWORD(wParam)) 1.522 + { 1.523 + case IDC_ADDRESS: 1.524 + if (HIWORD(wParam) == CBN_EDITCHANGE || HIWORD(wParam) == CBN_SELCHANGE) 1.525 + { 1.526 + // User has changed the address field so enable the Go button 1.527 + EnableWindow(GetDlgItem(hwndDlg, IDC_GO), TRUE); 1.528 + } 1.529 + break; 1.530 + 1.531 + case IDC_GO: 1.532 + { 1.533 + TCHAR szURL[2048]; 1.534 + memset(szURL, 0, sizeof(szURL)); 1.535 + GetDlgItemText(hwndDlg, IDC_ADDRESS, szURL, 1.536 + sizeof(szURL) / sizeof(szURL[0]) - 1); 1.537 + webNavigation->LoadURI( 1.538 + NS_ConvertASCIItoUTF16(szURL).get(), 1.539 + nsIWebNavigation::LOAD_FLAGS_NONE, 1.540 + nullptr, 1.541 + nullptr, 1.542 + nullptr); 1.543 + } 1.544 + break; 1.545 + 1.546 + case IDC_STOP: 1.547 + webNavigation->Stop(nsIWebNavigation::STOP_ALL); 1.548 + UpdateUI(chrome); 1.549 + break; 1.550 + 1.551 + case IDC_RELOAD: 1.552 + webNavigation->Reload(nsIWebNavigation::LOAD_FLAGS_NONE); 1.553 + break; 1.554 + 1.555 + case IDM_EXIT: 1.556 + PostMessage(hwndDlg, WM_SYSCOMMAND, SC_CLOSE, 0); 1.557 + break; 1.558 + 1.559 + // File menu commands 1.560 + 1.561 + case MOZ_NewBrowser: 1.562 + OpenWebPage(gFirstURL); 1.563 + break; 1.564 + 1.565 + // Edit menu commands 1.566 + 1.567 + case MOZ_Cut: 1.568 + { 1.569 + nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser); 1.570 + clipCmds->CutSelection(); 1.571 + } 1.572 + break; 1.573 + 1.574 + case MOZ_Copy: 1.575 + { 1.576 + nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser); 1.577 + clipCmds->CopySelection(); 1.578 + } 1.579 + break; 1.580 + 1.581 + case MOZ_Paste: 1.582 + { 1.583 + nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser); 1.584 + clipCmds->Paste(); 1.585 + } 1.586 + break; 1.587 + 1.588 + case MOZ_SelectAll: 1.589 + { 1.590 + nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser); 1.591 + clipCmds->SelectAll(); 1.592 + } 1.593 + break; 1.594 + 1.595 + case MOZ_SelectNone: 1.596 + { 1.597 + nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser); 1.598 + clipCmds->SelectNone(); 1.599 + } 1.600 + break; 1.601 + 1.602 + // Go menu commands 1.603 + case IDC_BACK: 1.604 + case MOZ_GoBack: 1.605 + webNavigation->GoBack(); 1.606 + UpdateUI(chrome); 1.607 + break; 1.608 + 1.609 + case IDC_FORWARD: 1.610 + case MOZ_GoForward: 1.611 + webNavigation->GoForward(); 1.612 + UpdateUI(chrome); 1.613 + break; 1.614 + 1.615 + // Help menu commands 1.616 + case MOZ_About: 1.617 + { 1.618 + TCHAR szAboutTitle[MAX_LOADSTRING]; 1.619 + TCHAR szAbout[MAX_LOADSTRING]; 1.620 + LoadString(ghInstanceApp, IDS_ABOUT_TITLE, szAboutTitle, MAX_LOADSTRING); 1.621 + LoadString(ghInstanceApp, IDS_ABOUT, szAbout, MAX_LOADSTRING); 1.622 + MessageBox(nullptr, szAbout, szAboutTitle, MB_OK); 1.623 + } 1.624 + break; 1.625 + } 1.626 + 1.627 + return TRUE; 1.628 + 1.629 + case WM_ACTIVATE: 1.630 + { 1.631 + nsCOMPtr<nsIWebBrowserFocus> focus(do_GetInterface(webBrowser)); 1.632 + if(focus) 1.633 + { 1.634 + switch (wParam) 1.635 + { 1.636 + case WA_ACTIVE: 1.637 + focus->Activate(); 1.638 + break; 1.639 + case WA_INACTIVE: 1.640 + focus->Deactivate(); 1.641 + break; 1.642 + default: 1.643 + break; 1.644 + } 1.645 + } 1.646 + } 1.647 + break; 1.648 + 1.649 + case WM_SIZE: 1.650 + { 1.651 + UINT newDlgWidth = LOWORD(lParam); 1.652 + UINT newDlgHeight = HIWORD(lParam); 1.653 + 1.654 + // TODO Reposition the control bar - for the moment it's fixed size 1.655 + 1.656 + // Reposition the status area. Status bar 1.657 + // gets any space that the fixed size progress bar doesn't use. 1.658 + int progressWidth; 1.659 + int statusWidth; 1.660 + int statusHeight; 1.661 + HWND hwndStatus = GetDlgItem(hwndDlg, IDC_STATUS); 1.662 + if (hwndStatus) { 1.663 + RECT rcStatus; 1.664 + GetWindowRect(hwndStatus, &rcStatus); 1.665 + statusHeight = rcStatus.bottom - rcStatus.top; 1.666 + } else 1.667 + statusHeight = 0; 1.668 + 1.669 + HWND hwndProgress = GetDlgItem(hwndDlg, IDC_PROGRESS); 1.670 + if (hwndProgress) { 1.671 + RECT rcProgress; 1.672 + GetWindowRect(hwndProgress, &rcProgress); 1.673 + progressWidth = rcProgress.right - rcProgress.left; 1.674 + } else 1.675 + progressWidth = 0; 1.676 + statusWidth = newDlgWidth - progressWidth; 1.677 + 1.678 + if (hwndStatus) 1.679 + SetWindowPos(hwndStatus, 1.680 + HWND_TOP, 1.681 + 0, newDlgHeight - statusHeight, 1.682 + statusWidth, 1.683 + statusHeight, 1.684 + SWP_NOZORDER); 1.685 + if (hwndProgress) 1.686 + SetWindowPos(hwndProgress, 1.687 + HWND_TOP, 1.688 + statusWidth, newDlgHeight - statusHeight, 1.689 + 0, 0, 1.690 + SWP_NOSIZE | SWP_NOZORDER); 1.691 + 1.692 + // Resize the browser area (assuming the browse is 1.693 + // sandwiched between the control bar and status area) 1.694 + RECT rcBrowser; 1.695 + POINT ptBrowser; 1.696 + GetWindowRect(hwndBrowser, &rcBrowser); 1.697 + ptBrowser.x = rcBrowser.left; 1.698 + ptBrowser.y = rcBrowser.top; 1.699 + ScreenToClient(hwndDlg, &ptBrowser); 1.700 + int browserHeight = newDlgHeight - ptBrowser.y - statusHeight; 1.701 + if (browserHeight < 1) 1.702 + { 1.703 + browserHeight = 1; 1.704 + } 1.705 + SetWindowPos(hwndBrowser, 1.706 + HWND_TOP, 1.707 + 0, 0, 1.708 + newDlgWidth, 1.709 + newDlgHeight - ptBrowser.y - statusHeight, 1.710 + SWP_NOMOVE | SWP_NOZORDER); 1.711 + } 1.712 + return TRUE; 1.713 + } 1.714 + return FALSE; 1.715 +} 1.716 + 1.717 + 1.718 +// 1.719 +// FUNCTION: BrowserWndProc(HWND, UINT, WRAPAM, LPARAM) 1.720 +// 1.721 +// PURPOSE: Processes messages for the browser container window. 1.722 +// 1.723 +LRESULT CALLBACK BrowserWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 1.724 +{ 1.725 + nsIWebBrowserChrome *chrome = (nsIWebBrowserChrome *) GetWindowLongPtr(hWnd, GWLP_USERDATA); 1.726 + switch (message) 1.727 + { 1.728 + case WM_SIZE: 1.729 + // Resize the embedded browser 1.730 + ResizeEmbedding(chrome); 1.731 + return 0; 1.732 + case WM_ERASEBKGND: 1.733 + // Reduce flicker by not painting the non-visible background 1.734 + return 1; 1.735 + } 1.736 + return DefWindowProc(hWnd, message, wParam, lParam); 1.737 +} 1.738 + 1.739 +// 1.740 +// FUNCTION: StartupProfile() 1.741 +// 1.742 +// PURPOSE: 1.743 +// 1.744 +nsresult StartupProfile() 1.745 +{ 1.746 + 1.747 + nsCOMPtr<nsIFile> appDataDir; 1.748 + nsresult rv = NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_DIR, getter_AddRefs(appDataDir)); 1.749 + if (NS_FAILED(rv)) 1.750 + return rv; 1.751 + 1.752 + appDataDir->AppendNative(nsCString("winembed")); 1.753 + 1.754 + nsCOMPtr<nsProfileDirServiceProvider> locProvider; 1.755 + NS_NewProfileDirServiceProvider(true, getter_AddRefs(locProvider)); 1.756 + if (!locProvider) 1.757 + return NS_ERROR_FAILURE; 1.758 + 1.759 + rv = locProvider->Register(); 1.760 + if (NS_FAILED(rv)) 1.761 + return rv; 1.762 + 1.763 + return locProvider->SetProfileDir(appDataDir); 1.764 + 1.765 +} 1.766 + 1.767 + 1.768 +/////////////////////////////////////////////////////////////////////////////// 1.769 +// WebBrowserChromeUI 1.770 + 1.771 +// 1.772 +// FUNCTION: CreateNativeWindow() 1.773 +// 1.774 +// PURPOSE: Creates a new browser dialog. 1.775 +// 1.776 +// COMMENTS: 1.777 +// 1.778 +// This function loads the browser dialog from a resource template 1.779 +// and returns the HWND for the webbrowser container dialog item 1.780 +// to the caller. 1.781 +// 1.782 +HWND WebBrowserChromeUI::CreateNativeWindow(nsIWebBrowserChrome* chrome) 1.783 +{ 1.784 + // Load the browser dialog from resource 1.785 + HWND hwndDialog; 1.786 + uint32_t chromeFlags; 1.787 + 1.788 + chrome->GetChromeFlags(&chromeFlags); 1.789 + if ((chromeFlags & nsIWebBrowserChrome::CHROME_ALL) == nsIWebBrowserChrome::CHROME_ALL) 1.790 + hwndDialog = CreateDialog(ghInstanceApp, 1.791 + MAKEINTRESOURCE(IDD_BROWSER), 1.792 + nullptr, 1.793 + BrowserDlgProc); 1.794 + else 1.795 + hwndDialog = CreateDialog(ghInstanceApp, 1.796 + MAKEINTRESOURCE(IDD_BROWSER_NC), 1.797 + nullptr, 1.798 + BrowserDlgProc); 1.799 + if (!hwndDialog) 1.800 + return nullptr; 1.801 + 1.802 + // Stick a menu onto it 1.803 + if (chromeFlags & nsIWebBrowserChrome::CHROME_MENUBAR) { 1.804 + HMENU hmenuDlg = LoadMenu(ghInstanceApp, MAKEINTRESOURCE(IDC_WINEMBED)); 1.805 + SetMenu(hwndDialog, hmenuDlg); 1.806 + } else 1.807 + SetMenu(hwndDialog, 0); 1.808 + 1.809 + // Add some interesting URLs to the address drop down 1.810 + HWND hwndAddress = GetDlgItem(hwndDialog, IDC_ADDRESS); 1.811 + if (hwndAddress) { 1.812 + for (int i = 0; i < sizeof(gDefaultURLs) / sizeof(gDefaultURLs[0]); i++) 1.813 + { 1.814 + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) gDefaultURLs[i]); 1.815 + } 1.816 + } 1.817 + 1.818 + // Fetch the browser window handle 1.819 + HWND hwndBrowser = GetDlgItem(hwndDialog, IDC_BROWSER); 1.820 + SetWindowLongPtr(hwndBrowser, GWLP_USERDATA, (LONG_PTR)chrome); // save the browser LONG_PTR. 1.821 + SetWindowLongPtr(hwndBrowser, GWL_STYLE, GetWindowLongPtr(hwndBrowser, GWL_STYLE) | WS_CLIPCHILDREN); 1.822 + 1.823 + // Activate the window 1.824 + PostMessage(hwndDialog, WM_ACTIVATE, WA_ACTIVE, 0); 1.825 + 1.826 + gDialogCount++; 1.827 + 1.828 + return hwndBrowser; 1.829 +} 1.830 + 1.831 + 1.832 +// 1.833 +// FUNCTION: Destroy() 1.834 +// 1.835 +// PURPOSE: Destroy the window specified by the chrome 1.836 +// 1.837 +void WebBrowserChromeUI::Destroy(nsIWebBrowserChrome* chrome) 1.838 +{ 1.839 + nsCOMPtr<nsIWebBrowser> webBrowser; 1.840 + nsCOMPtr<nsIWebNavigation> webNavigation; 1.841 + 1.842 + chrome->GetWebBrowser(getter_AddRefs(webBrowser)); 1.843 + webNavigation = do_QueryInterface(webBrowser); 1.844 + if (webNavigation) 1.845 + webNavigation->Stop(nsIWebNavigation::STOP_ALL); 1.846 + 1.847 + chrome->ExitModalEventLoop(NS_OK); 1.848 + 1.849 + HWND hwndDlg = GetBrowserDlgFromChrome(chrome); 1.850 + if (hwndDlg == nullptr) 1.851 + return; 1.852 + 1.853 + // Explicitly destroy the embedded browser and then the chrome 1.854 + 1.855 + // First the browser 1.856 + nsCOMPtr<nsIWebBrowser> browser = nullptr; 1.857 + chrome->GetWebBrowser(getter_AddRefs(browser)); 1.858 + nsCOMPtr<nsIBaseWindow> browserAsWin = do_QueryInterface(browser); 1.859 + if (browserAsWin) 1.860 + browserAsWin->Destroy(); 1.861 + 1.862 + // Now the chrome 1.863 + chrome->SetWebBrowser(nullptr); 1.864 + NS_RELEASE(chrome); 1.865 +} 1.866 + 1.867 + 1.868 +// 1.869 +// FUNCTION: Called as the final act of a chrome object during its destructor 1.870 +// 1.871 +void WebBrowserChromeUI::Destroyed(nsIWebBrowserChrome* chrome) 1.872 +{ 1.873 + HWND hwndDlg = GetBrowserDlgFromChrome(chrome); 1.874 + if (hwndDlg == nullptr) 1.875 + { 1.876 + return; 1.877 + } 1.878 + 1.879 + // Clear the window user data 1.880 + HWND hwndBrowser = GetDlgItem(hwndDlg, IDC_BROWSER); 1.881 + SetWindowLongPtr(hwndBrowser, GWLP_USERDATA, 0); 1.882 + DestroyWindow(hwndBrowser); 1.883 + DestroyWindow(hwndDlg); 1.884 + 1.885 + --gDialogCount; 1.886 + if (gDialogCount == 0) 1.887 + { 1.888 + // Quit when there are no more browser objects 1.889 + PostQuitMessage(0); 1.890 + } 1.891 +} 1.892 + 1.893 + 1.894 +// 1.895 +// FUNCTION: Set the input focus onto the browser window 1.896 +// 1.897 +void WebBrowserChromeUI::SetFocus(nsIWebBrowserChrome *chrome) 1.898 +{ 1.899 + HWND hwndDlg = GetBrowserDlgFromChrome(chrome); 1.900 + if (hwndDlg == nullptr) 1.901 + { 1.902 + return; 1.903 + } 1.904 + 1.905 + HWND hwndBrowser = GetDlgItem(hwndDlg, IDC_BROWSER); 1.906 + ::SetFocus(hwndBrowser); 1.907 +} 1.908 + 1.909 +// 1.910 +// FUNCTION: UpdateStatusBarText() 1.911 +// 1.912 +// PURPOSE: Set the status bar text. 1.913 +// 1.914 +void WebBrowserChromeUI::UpdateStatusBarText(nsIWebBrowserChrome *aChrome, const char16_t* aStatusText) 1.915 +{ 1.916 + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); 1.917 + nsCString status; 1.918 + if (aStatusText) { 1.919 + nsString wStatusText(aStatusText); 1.920 + NS_UTF16ToCString(wStatusText, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, 1.921 + status); 1.922 + } 1.923 + 1.924 + SetDlgItemText(hwndDlg, IDC_STATUS, status.get()); 1.925 +} 1.926 + 1.927 + 1.928 +// 1.929 +// FUNCTION: UpdateCurrentURI() 1.930 +// 1.931 +// PURPOSE: Updates the URL address field 1.932 +// 1.933 +void WebBrowserChromeUI::UpdateCurrentURI(nsIWebBrowserChrome *aChrome) 1.934 +{ 1.935 + nsCOMPtr<nsIWebBrowser> webBrowser; 1.936 + nsCOMPtr<nsIWebNavigation> webNavigation; 1.937 + aChrome->GetWebBrowser(getter_AddRefs(webBrowser)); 1.938 + webNavigation = do_QueryInterface(webBrowser); 1.939 + 1.940 + nsCOMPtr<nsIURI> currentURI; 1.941 + webNavigation->GetCurrentURI(getter_AddRefs(currentURI)); 1.942 + if (currentURI) 1.943 + { 1.944 + nsCString uriString; 1.945 + currentURI->GetAsciiSpec(uriString); 1.946 + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); 1.947 + SetDlgItemText(hwndDlg, IDC_ADDRESS, uriString.get()); 1.948 + } 1.949 +} 1.950 + 1.951 + 1.952 +// 1.953 +// FUNCTION: UpdateBusyState() 1.954 +// 1.955 +// PURPOSE: Refreshes the stop/go buttons in the browser dialog 1.956 +// 1.957 +void WebBrowserChromeUI::UpdateBusyState(nsIWebBrowserChrome *aChrome, bool aBusy) 1.958 +{ 1.959 + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); 1.960 + HWND button; 1.961 + button = GetDlgItem(hwndDlg, IDC_STOP); 1.962 + if (button) 1.963 + EnableWindow(button, aBusy); 1.964 + button = GetDlgItem(hwndDlg, IDC_GO); 1.965 + if (button) 1.966 + EnableWindow(button, !aBusy); 1.967 + UpdateUI(aChrome); 1.968 +} 1.969 + 1.970 + 1.971 +// 1.972 +// FUNCTION: UpdateProgress() 1.973 +// 1.974 +// PURPOSE: Refreshes the progress bar in the browser dialog 1.975 +// 1.976 +void WebBrowserChromeUI::UpdateProgress(nsIWebBrowserChrome *aChrome, int32_t aCurrent, int32_t aMax) 1.977 +{ 1.978 + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); 1.979 + HWND hwndProgress = GetDlgItem(hwndDlg, IDC_PROGRESS); 1.980 + if (aCurrent < 0) 1.981 + { 1.982 + aCurrent = 0; 1.983 + } 1.984 + if (aCurrent > aMax) 1.985 + { 1.986 + aMax = aCurrent + 20; // What to do? 1.987 + } 1.988 + if (hwndProgress) 1.989 + { 1.990 + SendMessage(hwndProgress, PBM_SETRANGE, 0, MAKELPARAM(0, aMax)); 1.991 + SendMessage(hwndProgress, PBM_SETPOS, aCurrent, 0); 1.992 + } 1.993 +} 1.994 + 1.995 +// 1.996 +// FUNCTION: ShowContextMenu() 1.997 +// 1.998 +// PURPOSE: Display a context menu for the given node 1.999 +// 1.1000 +void WebBrowserChromeUI::ShowContextMenu(nsIWebBrowserChrome *aChrome, uint32_t aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode) 1.1001 +{ 1.1002 + // TODO code to test context flags and display a popup menu should go here 1.1003 +} 1.1004 + 1.1005 +// 1.1006 +// FUNCTION: ShowTooltip() 1.1007 +// 1.1008 +// PURPOSE: Show a tooltip 1.1009 +// 1.1010 +void WebBrowserChromeUI::ShowTooltip(nsIWebBrowserChrome *aChrome, int32_t aXCoords, int32_t aYCoords, const char16_t *aTipText) 1.1011 +{ 1.1012 + // TODO code to show a tooltip should go here 1.1013 +} 1.1014 + 1.1015 +// 1.1016 +// FUNCTION: HideTooltip() 1.1017 +// 1.1018 +// PURPOSE: Hide the tooltip 1.1019 +// 1.1020 +void WebBrowserChromeUI::HideTooltip(nsIWebBrowserChrome *aChrome) 1.1021 +{ 1.1022 + // TODO code to hide a tooltip should go here 1.1023 +} 1.1024 + 1.1025 +void WebBrowserChromeUI::ShowWindow(nsIWebBrowserChrome *aChrome, bool aShow) 1.1026 +{ 1.1027 + HWND win = GetBrowserDlgFromChrome(aChrome); 1.1028 + ::ShowWindow(win, aShow ? SW_RESTORE : SW_HIDE); 1.1029 +} 1.1030 + 1.1031 +void WebBrowserChromeUI::SizeTo(nsIWebBrowserChrome *aChrome, int32_t aWidth, int32_t aHeight) 1.1032 +{ 1.1033 + HWND hchrome = GetBrowserDlgFromChrome(aChrome); 1.1034 + HWND hbrowser = GetBrowserFromChrome(aChrome); 1.1035 + RECT chromeRect, browserRect; 1.1036 + 1.1037 + ::GetWindowRect(hchrome, &chromeRect); 1.1038 + ::GetWindowRect(hbrowser, &browserRect); 1.1039 + 1.1040 + int32_t decoration_x = (browserRect.left - chromeRect.left) + 1.1041 + (chromeRect.right - browserRect.right); 1.1042 + int32_t decoration_y = (browserRect.top - chromeRect.top) + 1.1043 + (chromeRect.bottom - browserRect.bottom); 1.1044 + 1.1045 + ::MoveWindow(hchrome, chromeRect.left, chromeRect.top, 1.1046 + aWidth+decoration_x, 1.1047 + aHeight+decoration_y, TRUE); 1.1048 +} 1.1049 + 1.1050 +// 1.1051 +// FUNCTION: GetResourceStringByID() 1.1052 +// 1.1053 +// PURPOSE: Get the resource string for the ID 1.1054 +// 1.1055 +void WebBrowserChromeUI::GetResourceStringById(int32_t aID, char ** aReturn) 1.1056 +{ 1.1057 + char resBuf[MAX_LOADSTRING]; 1.1058 + int retval = LoadString( ghInstanceApp, aID, (LPTSTR)resBuf, sizeof(resBuf) ); 1.1059 + if (retval != 0) 1.1060 + { 1.1061 + size_t resLen = strlen(resBuf); 1.1062 + *aReturn = (char *)calloc(resLen+1, sizeof(char *)); 1.1063 + if (!*aReturn) return; 1.1064 + strncpy(*aReturn, resBuf, resLen); 1.1065 + } 1.1066 + return; 1.1067 +} 1.1068 + 1.1069 +//----------------------------------------------------------------------------- 1.1070 +// AppCallbacks 1.1071 +//----------------------------------------------------------------------------- 1.1072 + 1.1073 +nsresult AppCallbacks::CreateBrowserWindow(uint32_t aChromeFlags, 1.1074 + nsIWebBrowserChrome *aParent, 1.1075 + nsIWebBrowserChrome **aNewWindow) 1.1076 +{ 1.1077 + WebBrowserChrome * chrome = new WebBrowserChrome(); 1.1078 + if (!chrome) 1.1079 + return NS_ERROR_FAILURE; 1.1080 + 1.1081 + // the interface to return and one addref, which we assume will be 1.1082 + // immediately released 1.1083 + *aNewWindow = static_cast<nsIWebBrowserChrome*>(chrome); 1.1084 + // now an extra addref; the window owns itself (to be released by 1.1085 + // WebBrowserChromeUI::Destroy) 1.1086 + NS_ADDREF(*aNewWindow); 1.1087 + 1.1088 + chrome->SetChromeFlags(aChromeFlags); 1.1089 + chrome->SetParent(aParent); 1.1090 + 1.1091 + // Insert the browser 1.1092 + nsCOMPtr<nsIWebBrowser> newBrowser; 1.1093 + chrome->CreateBrowser(-1, -1, -1, -1, getter_AddRefs(newBrowser)); 1.1094 + if (!newBrowser) 1.1095 + return NS_ERROR_FAILURE; 1.1096 + 1.1097 + // Place it where we want it. 1.1098 + ResizeEmbedding(static_cast<nsIWebBrowserChrome*>(chrome)); 1.1099 + 1.1100 + // if opened as chrome, it'll be made visible after the chrome has loaded. 1.1101 + // otherwise, go ahead and show it now. 1.1102 + if (!(aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)) 1.1103 + WebBrowserChromeUI::ShowWindow(*aNewWindow, true); 1.1104 + 1.1105 + return NS_OK; 1.1106 +} 1.1107 + 1.1108 +void AppCallbacks::EnableChromeWindow(nsIWebBrowserChrome *aWindow, 1.1109 + bool aEnabled) 1.1110 +{ 1.1111 + HWND hwnd = GetBrowserDlgFromChrome(aWindow); 1.1112 + ::EnableWindow(hwnd, aEnabled ? TRUE : FALSE); 1.1113 +} 1.1114 + 1.1115 +uint32_t AppCallbacks::RunEventLoop(bool &aRunCondition) 1.1116 +{ 1.1117 + MSG msg; 1.1118 + HANDLE hFakeEvent = ::CreateEvent(nullptr, TRUE, FALSE, nullptr); 1.1119 + 1.1120 + while (aRunCondition ) { 1.1121 + // Process pending messages 1.1122 + while (::PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) { 1.1123 + if (!::GetMessage(&msg, nullptr, 0, 0)) { 1.1124 + // WM_QUIT 1.1125 + aRunCondition = false; 1.1126 + break; 1.1127 + } 1.1128 + 1.1129 + ::TranslateMessage(&msg); 1.1130 + ::DispatchMessage(&msg); 1.1131 + } 1.1132 + 1.1133 + // Do idle stuff 1.1134 + ::MsgWaitForMultipleObjects(1, &hFakeEvent, FALSE, 100, QS_ALLEVENTS); 1.1135 + } 1.1136 + ::CloseHandle(hFakeEvent); 1.1137 + return (uint32_t)msg.wParam; 1.1138 +}