// Entry point function for all processes. int main(int argc, char* argv[]) { // Provide CEF with command-line arguments. CefMainArgs main_args(argc, argv); // SimpleApp implements application-level callbacks. It will create the first // browser instance in OnContextInitialized() after CEF has initialized. CefRefPtr<SimpleApp> app(new SimpleApp); // CEF applications have multiple sub-processes (render, plugin, GPU, etc) // that share the same executable. This function checks the command-line and, // if this is a sub-process, executes the appropriate logic. int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) { // The sub-process has completed so return here. return exit_code; } // Specify CEF global settings here. CefSettings settings; // Initialize CEF for the browser process. CefInitialize(main_args, settings, app.get(), NULL); // Run the CEF message loop. This will block until CefQuitMessageLoop() is // called. CefRunMessageLoop(); // Shut down CEF. CefShutdown(); return 0; }
int PlexabilityApp::run() { TRACE(); // First up; we see if we're running as a child process (in which case, CEF takes care of business // for us in a blocking manner). int exitCode = CefExecuteProcess(this->args, (CefRefPtr<CefApp>)this->chromiumApp); if (exitCode >= 0) { LOG("Ran as a child process. Exited with: %d", exitCode); return exitCode; } // Nope; we're the master process. Initialize CEF. if (!CefInitialize(this->args, this->chromiumSettings, (CefRefPtr<CefApp>)this->chromiumApp)) { LOG("CEF failed to initialize! Aborting."); return 127; } // Set up the platform-specific GUI and friends. this->initializeNativeApp(); // And then kick off the run loop (this blocks until the app is ready to exit) CefRunMessageLoop(); return 0; }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { CefEnableHighDPISupport(); CefMainArgs mainArgs(hInst); CefRefPtr<CefCommandLine> cmdLine = CefCommandLine::CreateCommandLine(); cmdLine->InitFromString(::GetCommandLineW()); CefRefPtr<CefApp> app; auto appType = GetAppType(cmdLine); if (appType == AppType::BROWSER) app = new BrowserApp(); else if (appType == AppType::RENDERER) app = new RendererApp(); int exitCode = CefExecuteProcess(mainArgs, app, nullptr); if (exitCode >= 0) return exitCode; CefSettings settings; settings.no_sandbox = true; settings.remote_debugging_port = 1337; CefString(&settings.cache_path).FromASCII("./cache/"); CefInitialize(mainArgs, settings, app, nullptr); CefRunMessageLoop(); CefShutdown(); return 0; }
int main(int argc, char** argv) { HINSTANCE hInstance = GetModuleHandle(0); // Provide CEF with command-line arguments CefMainArgs args(hInstance); // TestApp implements application-level callbacks. It will create the first // browser instance in the `OnContextInitialized` callback after CEF has // initialized CefRefPtr<CefApp> app(new TestApp); // CEF applications have multiple sub-processes (render, plugin, GPU, etc) // that share can the same executable. // Create sub-process //int exit_code = CefExecuteProcess(args, app.get(), NULL); //if (exit_code >= 0) { // sub-process // // sub-process has completed, so return here // return exit_code; //} // However, separate sub-process executable is used here, so // 'browser_subprocess_path' must be set in CefSettings CefSettings settings; CefString(&settings.browser_subprocess_path).FromASCII("test_subprocess.exe"); settings.no_sandbox = true; // Initialize CEF CefInitialize(args, settings, app.get(), NULL); // Run the CEF message loop. This will block until `CefQuiMessageLoop` is // invoked. CefRunMessageLoop(); // Shutdown CEF CefShutdown(); return 0; }
BOOL CCefBrowserApp::InitInstance() { { CefMainArgs main_args(::GetModuleHandle(NULL)); CefRefPtr<XClientApp> app(new XClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get(), nullptr); if (exit_code >= 0) return exit_code; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings); // Initialize CEF. CefInitialize(main_args, settings, app.get(), nullptr); // Init plugins, like Flash etc. InitWebPlugins(); } // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinAppEx::InitInstance(); AfxEnableControlContainer(); CCefBrowserDlg* pDlg = new CCefBrowserDlg; m_pMainWnd = pDlg; pDlg->Create(MAKEINTRESOURCE(IDD_CEFBROWSER_DIALOG), NULL); m_pMainWnd->ShowWindow(SW_SHOWNORMAL); m_pMainWnd->UpdateWindow(); { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); CefShutdown(); } // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; }
//using std::ios_base; //using std::ios; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){ bool one_time_do = false; std::string folder_to_put_downloads; if (!one_time_do){ one_time_do = true; std::string path_config_file = "xxxx-geheimes-Wort!!_dl_config_file.conf3000.txt"; //std::fstream config_file_check(path+path_config_file, ios_base::binary | ios_base::in); //http://stackoverflow.com/questions/875249/how-to-get-current-directory Config_File_IO cfio(get_current_application_path()+"\\"+path_config_file); auto check = cfio.check_if_exists(); if (check.result_operation){// nur 3000 warum nicht mehr //na drauslesen,was denn sonst,was will er denn sonst mit machen??überleg.hmm.kein Rätsel.kein Quiz //std::stringstream cff_StreaM; cff_StreaM << config_file_check.rdbuf(); //folder_to_put_downloads = cff_StreaM.str(); config_file_check.close(); folder_to_put_downloads = check.contents_get(); } else{//select dir.the choice(stage)is yours /up to you //config_file_check.close(); //std::ofstream of(path + path_config_file, ios::binary | ios::out); Folder_Select_Dialog_like_FileName*fsdlf = new Folder_Select_Dialog_like_FileName(); File_Select_Result fsr; do{ fsr = fsdlf->performOpen("C:\\", "Ort wo die Downloads zu speichern sind"); } while (fsr.status != true); folder_to_put_downloads = std::string(fsr.location); //of << fsr.location; //of.close(); check.put_contents(folder_to_put_downloads); } } //CefScopedSandboxInfo scoped_sandbox; //void*sandbox_info = scoped_sandbox.sandbox_info();//sandbox hier aktiviert,muss man aber net void*sandbox_info = NULL;//sandbox deaktiviert,da bei allen winapi/file calls permission denied kommt CefMainArgs main_args(hInstance); CefRefPtr<MainApp> app(new MainApp(folder_to_put_downloads)); int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info); if (exit_code >= 0) { return exit_code; } CefSettings settings;//wird fürs initialize gebraucht settings.no_sandbox = true; CefInitialize(main_args, settings, app.get(), sandbox_info); CefRunMessageLoop(); CefShutdown(); return 0; }
// Entry point function for all processes. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); void* sandbox_info = NULL; #if CEF_ENABLE_SANDBOX // Manage the life span of the sandbox information object. This is necessary // for sandbox support on Windows. See cef_sandbox_win.h for complete details. CefScopedSandboxInfo scoped_sandbox; sandbox_info = scoped_sandbox.sandbox_info(); #endif // Provide CEF with command-line arguments. CefMainArgs main_args(hInstance); // SimpleApp implements application-level callbacks. It will create the first // browser instance in OnContextInitialized() after CEF has initialized. CefRefPtr<SimpleApp> app(new SimpleApp); // CEF applications have multiple sub-processes (render, plugin, GPU, etc) // that share the same executable. This function checks the command-line and, // if this is a sub-process, executes the appropriate logic. int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info); if (exit_code >= 0) { // The sub-process has completed so return here. return exit_code; } // Specify CEF global settings here. CefSettings settings; #if !CEF_ENABLE_SANDBOX settings.no_sandbox = true; #endif // Initialize CEF. CefInitialize(main_args, settings, app.get(), sandbox_info); // Run the CEF message loop. This will block until CefQuitMessageLoop() is // called. CefRunMessageLoop(); // Shut down CEF. CefShutdown(); return 0; }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); CefEnableHighDPISupport(); CefScopedSandboxInfo scoped_sandbox; CefMainArgs main_args(hInstance); CefRefPtr<NgineSlackApp> app(new NgineSlackApp); int exit_code = CefExecuteProcess(main_args, app.get(), scoped_sandbox.sandbox_info()); if (exit_code >= 0) { return exit_code; } LimitSingleInstance lsi(NGINESLACK); if (lsi.IsAnotherInstanceRunning()) { HWND hWnd = FindWindow(NGINESLACK, NULL); if( hWnd==NULL ) { MessageBox(NULL, L"Already running. You need to terminate it manually.", NGINESLACK, MB_OK); } else { ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); } return 0; } _AtlBaseModule.SetResourceInstance(hInstance); GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); CefSettings settings; CefSetting_SetCachePath(settings); settings.persist_session_cookies = TRUE; settings.log_severity = LOGSEVERITY_DISABLE; settings.ignore_certificate_errors = TRUE; CefInitialize(main_args, settings, app.get(), scoped_sandbox.sandbox_info()); CefRunMessageLoop(); CefShutdown(); return 0; }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QCefWebView *webView = new QCefWebView(); MainWindow w; QWidget *browserWidget = w.findChild<QWidget *>("browserWidget"); QVBoxLayout *browserLayout = new QVBoxLayout(browserWidget); browserLayout->addWidget( webView); w.show(); std::thread bthread([&] { a.exec(); }); CefRunMessageLoop(); return 0; }
int main(int argc, char* argv[]) { CefEnableHighDPISupport(); CefMainArgs mainArgs(argc, argv); auto cmdLine = CefCommandLine::CreateCommandLine(); cmdLine->InitFromArgv(argc, argv); std::string configPath = cmdLine->GetSwitchValue("config").ToString(); if (configPath.empty()) { configPath = "config.default.json"; } AppConfig config; if (!LoadAppConfig(configPath.c_str(), &config)) { return -1; } CefRefPtr<CefApp> app(new App(config)); int exitCode = CefExecuteProcess(mainArgs, app, nullptr); if (exitCode >= 0) { return exitCode; } CefSettings settings; settings.no_sandbox = true; settings.remote_debugging_port = 1337; settings.single_process = false; CefString(&settings.cache_path).FromASCII(CACHE_PATH); CefInitialize(mainArgs, settings, app, nullptr); CefRunMessageLoop(); CefShutdown(); return 0; }
// Entry point int main(int argc, char* argv[]) { CefMainArgs main_args(argc, argv); // This forks itself and does some chrome multi-process magic. int exit_code = CefExecuteProcess(main_args, NULL, NULL); if (exit_code >= 0) { // This sub-process has completed. return exit_code; } // Install xlib error handlers XSetErrorHandler(XErrorHandlerImpl); XSetIOErrorHandler(XIOErrorHandlerImpl); // Specify global CEF settings here. CefSettings settings; CefRefPtr<CHtmlToPdfApp> app(new CHtmlToPdfApp); CefInitialize(main_args, settings, app.get(), NULL); CefRunMessageLoop(); CefShutdown(); return 0; }
void BrowserManager::Impl::BrowserManagerEntry() { std::string bootstrapPath = getBootstrap(); bool thread_exit = false; PushEvent([] { CefMainArgs mainArgs; CefSettings settings; settings.log_severity = LOGSEVERITY_VERBOSE; settings.windowless_rendering_enabled = true; settings.no_sandbox = true; CefString(&settings.cache_path).FromASCII(obs_module_config_path("")); CefString(&settings.browser_subprocess_path) = getBootstrap(); CefRefPtr<BrowserApp> app(new BrowserApp()); CefExecuteProcess(mainArgs, app, nullptr); CefInitialize(mainArgs, settings, app, nullptr); CefRegisterSchemeHandlerFactory("http", "absolute", new BrowserSchemeHandlerFactory()); CefRunMessageLoop(); CefShutdown(); }); while (true) { if (os_event_timedwait(dispatchEvent, 10) != ETIMEDOUT) { pthread_mutex_lock(&dispatchLock); while (!queue.empty()) { auto event = queue[0]; event(); queue.erase(queue.begin()); } thread_exit = !threadAlive; pthread_mutex_unlock(&dispatchLock); if (thread_exit) { return; } } } }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get()); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Initialize CEF. CefInitialize(main_args, settings, app.get()); // Register the scheme handler. scheme_test::InitTest(); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } // Shut down CEF. CefShutdown(); return result; }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); g_appStartupTime = timeGetTime(); CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get()); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Initialize CEF. CefInitialize(main_args, settings, app.get()); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); HKEY hKey; DWORD lResult; #define PREF_NAME L"Software\\Brackets\\InitialURL" // Don't read the prefs if the shift key is down if (GetAsyncKeyState(VK_SHIFT) == 0) { if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, PREF_NAME, 0, KEY_READ, &hKey)) { DWORD length = MAX_PATH; RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)szInitialUrl, &length); RegCloseKey(hKey); } } if (!wcslen(szInitialUrl)) { OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szInitialUrl; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER; if (GetOpenFileName(&ofn)) { lResult = RegCreateKeyEx(HKEY_CURRENT_USER, PREF_NAME, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (lResult == ERROR_SUCCESS) { RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)szInitialUrl, (wcslen(szInitialUrl) + 1) * 2); RegCloseKey(hKey); } } } // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } // Shut down CEF. CefShutdown(); return result; }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) #endif { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); MessageBox(NULL, L"1", L"winmain", MB_OK); // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; //Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); MessageBox(NULL, L"after command line init", L"winmain", MB_OK); CefSettings settings; CefRefPtr<CefApp> app; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Initialize CEF. CefInitialize(settings, app); // Register the internal client plugin. //InitPluginTest(); // Register the internal UI client plugin. //InitUIPluginTest(); // Register the internal OSR client plugin. //InitOSRPluginTest(); // Register the V8 extension handler. InitExtensionTest(); // Register the scheme handler. InitSchemeTest(); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) { MessageBox(NULL, L"init instance fail", L"winmain", MB_OK); return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); // Register the find event message. uFindMsg = RegisterWindowMessage(FINDMSGSTRING); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { // Allow processing of find dialog messages. if (hFindDlg && IsDialogMessage(hFindDlg, &msg)) continue; if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } // Shut down CEF. CefShutdown(); return result; }
int main(int argc, char* argv[]) { CefMainArgs main_args(argc, argv); g_appStartupTime = time(NULL); gtk_init(&argc, &argv); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) return exit_code; //Retrieve the current working directory if (!getcwd(szWorkingDir, sizeof (szWorkingDir))) return -1; GtkWidget* window; // Parse command line arguments. AppInitCommandLine(argc, argv); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); settings.no_sandbox = TRUE; // Check cache_path setting if (CefString(&settings.cache_path).length() == 0) { CefString(&settings.cache_path) = AppGetCachePath(); } CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine(); if (cmdLine->HasSwitch(client::switches::kStartupPath)) { szInitialUrl = cmdLine->GetSwitchValue(client::switches::kStartupPath); } else { szInitialUrl = AppGetRunningDirectory(); szInitialUrl.append("/dev/src/index.html"); if (!FileExists(szInitialUrl)) { szInitialUrl = AppGetRunningDirectory(); szInitialUrl.append("/www/index.html"); if (!FileExists(szInitialUrl)) { if (GetInitialUrl() < 0) return 0; } } } // Initialize CEF. CefInitialize(main_args, settings, app.get(), NULL); // Set window icon std::vector<std::string> icons(APPICONS, APPICONS + sizeof(APPICONS) / sizeof(APPICONS[0]) ); GList *list = NULL; for (int i = 0; i < icons.size(); ++i) { std::string path = icons[i]; GdkPixbuf *icon = gdk_pixbuf_new_from_file(path.c_str(), NULL); if (!icon) continue; list = g_list_append(list, icon); } window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); gtk_window_set_icon_list(GTK_WINDOW(window), list); // Free icon list g_list_foreach(list, (GFunc) g_object_unref, NULL); g_list_free(list); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); GtkWidget* menuBar = gtk_menu_bar_new(); // GtkWidget* debug_menu = CreateMenu(menuBar, "Tests"); // AddMenuEntry(debug_menu, "Hello World Menu", // G_CALLBACK(GetSourceActivated)); gtk_box_pack_start(GTK_BOX(vbox), menuBar, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(HandleQuit), NULL); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_widget_destroyed), &window); add_handler_id = g_signal_connect(G_OBJECT(window), "add", G_CALLBACK(HandleAdd), NULL); // g_signal_connect(G_OBJECT(window), "destroy", // G_CALLBACK(destroy), NULL); // Create the handler. g_handler = new ClientHandler(); g_handler->SetMainHwnd(vbox); // Create the browser view. CefWindowInfo window_info; CefBrowserSettings browserSettings; browserSettings.web_security = STATE_DISABLED; window_info.SetAsChild(vbox); CefBrowserHost::CreateBrowser( window_info, static_cast<CefRefPtr<CefClient> >(g_handler), "file://"+szInitialUrl, browserSettings, NULL); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show_all(GTK_WIDGET(window)); // Install an signal handler so we clean up after ourselves. signal(SIGINT, TerminationSignalHandler); signal(SIGTERM, TerminationSignalHandler); // Start the node server process startNodeProcess(); CefRunMessageLoop(); CefShutdown(); return 0; }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); void* sandbox_info = NULL; #if CEF_ENABLE_SANDBOX // Manage the life span of the sandbox information object. This is necessary // for sandbox support on Windows. See cef_sandbox_win.h for complete details. CefScopedSandboxInfo scoped_sandbox; sandbox_info = scoped_sandbox.sandbox_info(); #endif CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; #if !CEF_ENABLE_SANDBOX settings.no_sandbox = true; #endif // Populate the settings based on command line arguments. AppGetSettings(settings); // Initialize CEF. CefInitialize(main_args, settings, app.get(), sandbox_info); // Register the scheme handler. scheme_test::InitTest(); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); LoadString(hInstance, IDS_OSR_WIDGET_CLASS, szOSRWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); // Register the find event message. uFindMsg = RegisterWindowMessage(FINDMSGSTRING); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { // Create a hidden window for message processing. hMessageWnd = CreateMessageWindow(hInstance); ASSERT(hMessageWnd); MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { // Allow processing of find dialog messages. if (hFindDlg && IsDialogMessage(hFindDlg, &msg)) continue; if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } DestroyWindow(hMessageWnd); hMessageWnd = NULL; result = static_cast<int>(msg.wParam); } // Shut down CEF. CefShutdown(); return result; }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); g_appStartupTime = timeGetTime(); CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get()); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Check command if (CefString(&settings.cache_path).length() == 0) { CefString(&settings.cache_path) = AppGetCachePath(); } // Initialize CEF. CefInitialize(main_args, settings, app.get()); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance, settings.locale); HKEY hKey; DWORD lResult; #define PREF_NAME L"Software\\" APP_NAME L"\\InitialURL" // If the Control key is down, delete the prefs BOOL bDeletePrefs = false; if (GetAsyncKeyState(VK_CONTROL) != 0) { bDeletePrefs = true; } // Don't read the prefs if the shift key is down if (GetAsyncKeyState(VK_SHIFT) == 0) { if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, PREF_NAME, 0, KEY_READ, &hKey)) { if (bDeletePrefs) { RegDeleteKey(hKey, L""); } else { DWORD length = MAX_PATH; RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)szInitialUrl, &length); RegCloseKey(hKey); } } if (!wcslen(szInitialUrl)) { // Look for www/index.html in the same directory as the application wchar_t appPath[MAX_PATH]; GetModuleFileName(NULL, appPath, MAX_PATH); wcscpy(wcsrchr(appPath, '\\'), L"\\www\\index.html"); // If the file exists, use it if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } } } if (!wcslen(szInitialUrl)) { OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szInitialUrl; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0"; ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file."; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER; if (GetOpenFileName(&ofn)) { lResult = RegCreateKeyEx(HKEY_CURRENT_USER, PREF_NAME, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); if (lResult == ERROR_SUCCESS) { RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)szInitialUrl, (wcslen(szInitialUrl) + 1) * 2); RegCloseKey(hKey); } } else { // User cancelled, exit the app CefShutdown(); return 0; } } // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; // Temporary localization hack. Default to English. Check for French. DWORD menuId = IDC_CEFCLIENT; if (settings.locale.str && (settings.locale.length > 0) && (CefString(settings.locale.str) == CefString("fr-FR"))) { menuId = IDC_CEFCLIENT_FR; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(menuId)); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } OnBeforeShutdown(); // Shut down CEF. CefShutdown(); return result; }
int CreateMainWindow() { // initialize title bar text and the main window class name TCHAR szTitle[MAX_LOADSTRING]; TCHAR szWindowClass[MAX_LOADSTRING]; LoadString(g_hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(g_hInst, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(g_hInst, szWindowClass); // create the main window Rect rectWindow; LoadWindowPlacement(&rectWindow, &g_nCmdShow); HWND hWndMain = CreateWindow( szWindowClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, rectWindow.x, rectWindow.y, rectWindow.w, rectWindow.h, NULL, NULL, g_hInst, NULL ); if (hWndMain == NULL) { App::ShowErrorMessage(); return FALSE; } HACCEL hAccelTable = LoadAccelerators(g_hInst, MAKEINTRESOURCE(IDC_CEFCLIENT)); g_handler->SetAccelTable(hAccelTable); g_isMessageLoopRunning = true; int result = 0; if (!g_isMultithreadedMessageLoop) { // run the CEF message loop // this function will block until the application recieves a WM_QUIT message CefRunMessageLoop(); } else { // create a hidden window for message processing g_hMessageWnd = CreateMessageWindow(g_hInst); ASSERT(g_hMessageWnd); MSG msg; // run the application message loop while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } DestroyWindow(g_hMessageWnd); g_hMessageWnd = NULL; result = static_cast<int>(msg.wParam); } g_isMessageLoopRunning = false; g_handler->ReleaseCefObjects(); FreeResources(); return result; }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow) { g_hInstance = hInstance; json_value* appSettings = GetApplicationSettings(); if (GetApplicationSettingsError().length()) { std::string error = GetApplicationSettingsError(); error.append("\nApplication will terminate immediately. "); FatalError(NULL, error); } // Debugging options. bool show_console = (*appSettings)["debugging"]["show_console"]; bool subprocess_show_console = (*appSettings)["debugging"]["subprocess_show_console"]; std::string log_level = (*appSettings)["debugging"]["log_level"]; std::string log_file = (*appSettings)["debugging"]["log_file"]; log_file = GetAbsolutePath(log_file); // Initialize logging. if (std::wstring(lpstrCmdLine).find(L"--type=") != std::string::npos) { // This is a subprocess. InitializeLogging(subprocess_show_console, log_level, log_file); } else { // Main browser process. InitializeLogging(show_console, log_level, log_file); } // Command line arguments LPWSTR *argv; int argc; argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argv) { for (int i = 0; i < argc; i++) { std::string argument = WideToUtf8(std::wstring(argv[i])); size_t pos = argument.find("="); if (pos != std::string::npos) { std::string name = argument.substr(0, pos); std::string value = argument.substr(pos+1, std::string::npos); if (name == "--cgi-environment" && value.length()) { g_cgiEnvironmentFromArgv.assign(value); } } } } else { LOG_WARNING << "CommandLineToArgvW() failed"; } // CEF subprocesses. CefMainArgs main_args(hInstance); CefRefPtr<App> app(new App); int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) { ShutdownLogging(); return exit_code; } LOG_INFO << "--------------------------------------------------------"; LOG_INFO << "Started application"; if (log_file.length()) LOG_INFO << "Logging to: " << log_file; else LOG_INFO << "No logging file set"; LOG_INFO << "Log level = " << FILELog::ToString(FILELog::ReportingLevel()); // Main window title option. std::string main_window_title = (*appSettings)["main_window"]["title"]; if (main_window_title.empty()) main_window_title = GetExecutableName(); // Single instance guid option. const char* single_instance_guid = (*appSettings)["application"]["single_instance_guid"]; if (single_instance_guid && single_instance_guid[0] != 0) { int guidSize = strlen(single_instance_guid) + 1; g_singleInstanceApplicationGuid = new wchar_t[guidSize]; Utf8ToWide(single_instance_guid, g_singleInstanceApplicationGuid, guidSize); } if (g_singleInstanceApplicationGuid && g_singleInstanceApplicationGuid[0] != 0) { g_singleInstanceApplication.Initialize( g_singleInstanceApplicationGuid); if (g_singleInstanceApplication.IsRunning()) { HWND hwnd = FindWindow(g_singleInstanceApplicationGuid, NULL); if (hwnd) { if (IsIconic(hwnd)) ShowWindow(hwnd, SW_RESTORE); SetForegroundWindow(hwnd); return 0; } } } // Window class name. if (g_singleInstanceApplicationGuid) { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", g_singleInstanceApplicationGuid); } else { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", Utf8ToWide(GetExecutableName()).c_str()); } if (!StartWebServer()) { FatalError(NULL, "Error while starting an internal local server.\n" "Application will terminate immediately."); } CefSettings cef_settings; // log_file std::string chrome_log_file = (*appSettings)["chrome"]["log_file"]; chrome_log_file = GetAbsolutePath(chrome_log_file); CefString(&cef_settings.log_file) = chrome_log_file; // log_severity std::string chrome_log_severity = (*appSettings)["chrome"]["log_severity"]; cef_log_severity_t log_severity = LOGSEVERITY_DEFAULT; if (chrome_log_severity == "verbose") { log_severity = LOGSEVERITY_VERBOSE; } else if (chrome_log_severity == "info") { log_severity = LOGSEVERITY_INFO; } else if (chrome_log_severity == "warning") { log_severity = LOGSEVERITY_WARNING; } else if (chrome_log_severity == "error") { log_severity = LOGSEVERITY_ERROR; } else if (chrome_log_severity == "error-report") { log_severity = LOGSEVERITY_ERROR_REPORT; } else if (chrome_log_severity == "disable") { log_severity = LOGSEVERITY_DISABLE; } cef_settings.log_severity = log_severity; // cache_path std::string cache_path = (*appSettings)["chrome"]["cache_path"]; cache_path = GetAbsolutePath(cache_path); CefString(&cef_settings.cache_path) = cache_path; // remote_debugging_port // A value of -1 will disable remote debugging. int remote_debugging_port = static_cast<long>( (*appSettings)["chrome"]["remote_debugging_port"]); if (remote_debugging_port == 0) { remote_debugging_port = random(49152, 65535+1); int i = 100; while (((i--) > 0) && remote_debugging_port == GetWebServerPort()) { remote_debugging_port = random(49152, 65535+1); } } if (remote_debugging_port > 0) { LOG_INFO << "remote_debugging_port = " << remote_debugging_port; cef_settings.remote_debugging_port = remote_debugging_port; } // Sandbox support cef_settings.no_sandbox = true; CefInitialize(main_args, cef_settings, app.get(), NULL); CreateMainWindow(hInstance, nCmdShow, main_window_title); CefRunMessageLoop(); CefShutdown(); LOG_INFO << "Ended application"; LOG_INFO << "--------------------------------------------------------"; ShutdownLogging(); return 0; }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); g_appStartupTime = timeGetTime(); // Retrieve the current working directory. if(_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; CefRefPtr<CefApp> app; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Brackets: Set persistance cache wchar_t dataPath[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dataPath); std::wstring cachePath = dataPath; cachePath += L"\\Brackets\\cefCache"; CefString(&settings.cache_path).FromWString(cachePath); // Initialize CEF. CefInitialize(settings, app); // Initialize Brackets extensions InitBracketsExtensions(); // Register the internal client plugin. //InitPluginTest(); // Register the internal UI client plugin. //InitUIPluginTest(); // Register the internal OSR client plugin. //InitOSRPluginTest(); // Register the V8 extension handler. //InitExtensionTest(); // Register the scheme handler. //InitSchemeTest(); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT)); // Register the find event message. uFindMsg = RegisterWindowMessage(FINDMSGSTRING); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { // Allow processing of find dialog messages. if (hFindDlg && IsDialogMessage(hFindDlg, &msg)) continue; if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = (int)msg.wParam; } // Shut down CEF. CefShutdown(); return result; }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); g_appStartupTime = timeGetTime(); CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get()); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Check command if (CefString(&settings.cache_path).length() == 0) { CefString(&settings.cache_path) = AppGetCachePath(); } // Initialize CEF. CefInitialize(main_args, settings, app.get()); HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance, *(app->GetCurrentLanguage().GetStruct())); CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine(); if (cmdLine->HasSwitch(cefclient::kStartupPath)) { wcscpy(szInitialUrl, cmdLine->GetSwitchValue(cefclient::kStartupPath).c_str()); } else { // If the shift key is not pressed, look for the index.html file if (GetAsyncKeyState(VK_SHIFT) == 0) { // Get the full pathname for the app. We look for the index.html // file relative to this location. wchar_t appPath[MAX_PATH]; wchar_t *pathRoot; GetModuleFileName(NULL, appPath, MAX_PATH); // Strip the .exe filename (and preceding "\") from the appPath // and store in pathRoot pathRoot = wcsrchr(appPath, '\\'); // Look for .\dev\src\index.html first wcscpy(pathRoot, L"\\dev\\src\\index.html"); // If the file exists, use it if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } if (!wcslen(szInitialUrl)) { // Look for .\www\index.html next wcscpy(pathRoot, L"\\www\\index.html"); if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } } } } if (!wcslen(szInitialUrl)) { // If we got here, either the startup file couldn't be found, or the user pressed the // shift key while launching. Prompt to select the index.html file. OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szInitialUrl; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0"; ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file."; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER; if (!GetOpenFileName(&ofn)) { // User cancelled, exit the app CefShutdown(); return 0; } } // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; // Temporary localization hack. Default to English. Check for French. DWORD menuId = IDC_CEFCLIENT; if (app->GetCurrentLanguage() == CefString("fr-FR")) { menuId = IDC_CEFCLIENT_FR; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(menuId)); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } OnBeforeShutdown(); // Shut down CEF. CefShutdown(); return result; }
int main(int argc, char* argv[]) { CefMainArgs main_args(argc, argv); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get()); if (exit_code >= 0) return exit_code; if (!getcwd(szWorkingDir, sizeof (szWorkingDir))) return -1; GtkWidget* window; gtk_init(&argc, &argv); // Parse command line arguments. AppInitCommandLine(argc, argv); CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Initialize CEF. CefInitialize(main_args, settings, app.get()); // Register the scheme handler. scheme_test::InitTest(); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); GtkWidget* menu_bar = CreateMenuBar(); gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, FALSE, 0); GtkWidget* toolbar = gtk_toolbar_new(); // Turn off the labels on the toolbar buttons. gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); GtkToolItem* back = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK); g_signal_connect(back, "clicked", G_CALLBACK(BackButtonClicked), NULL); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), back, -1 /* append */); GtkToolItem* forward = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD); g_signal_connect(forward, "clicked", G_CALLBACK(ForwardButtonClicked), NULL); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), forward, -1 /* append */); GtkToolItem* reload = gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH); g_signal_connect(reload, "clicked", G_CALLBACK(ReloadButtonClicked), NULL); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), reload, -1 /* append */); GtkToolItem* stop = gtk_tool_button_new_from_stock(GTK_STOCK_STOP); g_signal_connect(stop, "clicked", G_CALLBACK(StopButtonClicked), NULL); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), stop, -1 /* append */); GtkWidget* m_editWnd = gtk_entry_new(); g_signal_connect(G_OBJECT(m_editWnd), "activate", G_CALLBACK(URLEntryActivate), NULL); GtkToolItem* tool_item = gtk_tool_item_new(); gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd); gtk_tool_item_set_expand(tool_item, TRUE); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1); // append gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_widget_destroyed), &window); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); // Create the handler. g_handler = new ClientHandler(); g_handler->SetMainHwnd(vbox); g_handler->SetEditHwnd(m_editWnd); g_handler->SetButtonHwnds(GTK_WIDGET(back), GTK_WIDGET(forward), GTK_WIDGET(reload), GTK_WIDGET(stop)); // Create the browser view. CefWindowInfo window_info; CefBrowserSettings browserSettings; // Populate the settings based on command line arguments. AppGetBrowserSettings(browserSettings); window_info.SetAsChild(vbox); CefBrowserHost::CreateBrowserSync( window_info, g_handler.get(), g_handler->GetStartupURL(), browserSettings); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show_all(GTK_WIDGET(window)); // Install an signal handler so we clean up after ourselves. signal(SIGINT, TerminationSignalHandler); signal(SIGTERM, TerminationSignalHandler); CefRunMessageLoop(); CefShutdown(); return 0; }
// Program entry point function. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); g_appStartupTime = timeGetTime(); CefMainArgs main_args(hInstance); CefRefPtr<ClientApp> app(new ClientApp); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) return exit_code; // Retrieve the current working directory. if (_getcwd(szWorkingDir, MAX_UNC_PATH) == NULL) szWorkingDir[0] = 0; // Parse command line arguments. The passed in values are ignored on Windows. AppInitCommandLine(0, NULL); // Determine if we should use an already running instance of Brackets. HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, FIRST_INSTANCE_MUTEX_NAME); if ((hMutex != NULL) && AppGetCommandLine()->HasArguments() && (lpCmdLine != NULL)) { // for subsequent instances, re-use an already running instance if we're being called to // open an existing file on the command-line (eg. Open With.. from Windows Explorer) HWND hFirstInstanceWnd = cef_main_window::FindFirstTopLevelInstance(); if (hFirstInstanceWnd != NULL) { ::SetForegroundWindow(hFirstInstanceWnd); if (::IsIconic(hFirstInstanceWnd)) ::ShowWindow(hFirstInstanceWnd, SW_RESTORE); // message the other Brackets instance to actually open the given filename std::wstring wstrFilename = lpCmdLine; ConvertToUnixPath(wstrFilename); // note: WM_COPYDATA will manage passing the string across process space COPYDATASTRUCT data; data.dwData = ID_WM_COPYDATA_SENDOPENFILECOMMAND; data.cbData = (wstrFilename.length() + 1) * sizeof(WCHAR); data.lpData = (LPVOID)wstrFilename.c_str(); ::SendMessage(hFirstInstanceWnd, WM_COPYDATA, (WPARAM)(HWND)hFirstInstanceWnd, (LPARAM)(LPVOID)&data); // exit this instance return 0; } // otherwise, fall thru and launch a new instance } if (hMutex == NULL) { // first instance of this app, so create the mutex and continue execution of this instance. hMutex = ::CreateMutex(NULL, FALSE, FIRST_INSTANCE_MUTEX_NAME); } CefSettings settings; // Populate the settings based on command line arguments. AppGetSettings(settings, app); // Check command if (CefString(&settings.cache_path).length() == 0) { CefString(&settings.cache_path) = AppGetCachePath(); } // Initialize CEF. CefInitialize(main_args, settings, app.get(), NULL); CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine(); if (cmdLine->HasSwitch(cefclient::kStartupPath)) { wcscpy(szInitialUrl, cmdLine->GetSwitchValue(cefclient::kStartupPath).c_str()); } else { // If the shift key is not pressed, look for the index.html file if (GetAsyncKeyState(VK_SHIFT) == 0) { // Get the full pathname for the app. We look for the index.html // file relative to this location. wchar_t appPath[MAX_UNC_PATH]; wchar_t *pathRoot; GetModuleFileName(NULL, appPath, MAX_UNC_PATH); // Strip the .exe filename (and preceding "\") from the appPath // and store in pathRoot pathRoot = wcsrchr(appPath, '\\'); // Look for .\dev\src\index.html first wcscpy(pathRoot, L"\\dev\\src\\index.html"); // If the file exists, use it if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } if (!wcslen(szInitialUrl)) { // Look for .\www\index.html next wcscpy(pathRoot, L"\\www\\index.html"); if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) { wcscpy(szInitialUrl, appPath); } } } } if (!wcslen(szInitialUrl)) { // If we got here, either the startup file couldn't be found, or the user pressed the // shift key while launching. Prompt to select the index.html file. OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szInitialUrl; ofn.nMaxFile = MAX_UNC_PATH; ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0"; ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file."; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER; if (!GetOpenFileName(&ofn)) { // User cancelled, exit the app CefShutdown(); return 0; } } // Perform application initialization if (!InitInstance (hInstance, nCmdShow)) return FALSE; // Start the node server process startNodeProcess(); gFilesToOpen = GetFilenamesFromCommandLine(); int result = 0; if (!settings.multi_threaded_message_loop) { // Run the CEF message loop. This function will block until the application // recieves a WM_QUIT message. CefRunMessageLoop(); } else { MSG msg; // Run the application message loop. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } result = static_cast<int>(msg.wParam); } OnBeforeShutdown(); // Shut down CEF. CefShutdown(); // release the first instance mutex if (hMutex != NULL) ReleaseMutex(hMutex); return result; }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { #else int main(int argc, char* argv[]) { #endif // Do all the standard CEF setup stuff. //------------------------------------- void * sandbox_info = nullptr; #ifdef _WIN32 // Enable High-DPI support on Windows 7 or newer. CefEnableHighDPISupport(); // Read command line arguments. CefMainArgs main_args(hInstance); #else // Read command line arguments. CefMainArgs main_args(argc, argv); #endif // Create the process reference. CefRefPtr<loot::LootApp> app(new loot::LootApp); // Run the process. int exit_code = CefExecuteProcess(main_args, app.get(), nullptr); if (exit_code >= 0) { // The sub-process has completed so return here. return exit_code; } #ifdef _WIN32 // Check if LOOT is already running //--------------------------------- HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, L"LOOT.Shell.Instance"); if (hMutex != NULL) { // An instance of LOOT is already running, so focus its window then quit. HWND hWnd = ::FindWindow(NULL, L"LOOT"); ::SetForegroundWindow(hWnd); return 0; } else { //Create the mutex so that future instances will not run. hMutex = ::CreateMutex(NULL, FALSE, L"LOOT.Shell.Instance"); } #endif // Handle command line args (not CEF args) //---------------------------------------- processCommandLineArguments(app); // Back to CEF //------------ // Initialise CEF settings. CefSettings cef_settings = GetCefSettings(); #ifndef _WIN32 // Install xlib error handlers so that the application won't be terminated // on non-fatal errors. XSetErrorHandler(XErrorHandlerImpl); XSetIOErrorHandler(XIOErrorHandlerImpl); #endif // Initialize CEF. CefInitialize(main_args, cef_settings, app.get(), sandbox_info); // Run the CEF message loop. This will block until CefQuitMessageLoop() is called. CefRunMessageLoop(); // Shut down CEF. CefShutdown(); #ifdef _WIN32 // Release the program instance mutex. if (hMutex != NULL) ReleaseMutex(hMutex); #endif return 0; }