// 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;
}
Esempio n. 2
0
CefFacade::CefFacade(const char* startUrl,HINSTANCE hInstance,HWND pParent)
{
	CefMainArgs main_args(hInstance);  

	CefRefPtr<ClientApp> app(new ClientApp);  

	int exit_code = CefExecuteProcess(main_args, app.get(), NULL);  
	if (exit_code >= 0){  
		exit(exit_code);  
	}  

	CefSettings settings;  
	CefSettingsTraits::init(&settings);  
	settings.multi_threaded_message_loop = true;  
	settings.single_process = true;
	TCHAR szBuffer[MAX_PATH];  
	SHGetSpecialFolderPath(NULL, szBuffer, CSIDL_INTERNET_CACHE, FALSE);   
	_stprintf(szBuffer,_T("%s\\cache"), szBuffer);  
	CefString(&settings.cache_path) = szBuffer;

	settings.log_severity = LOGSEVERITY_DISABLE;
	CefString(&settings.locale) =  "zh-CN";

	CefInitialize(main_args, settings, app.get(), NULL);  

	CreateBrowser(pParent,startUrl);
}
Esempio n. 3
0
	 void __stdcall  Init(HINSTANCE hInstance,bool bSingleProcess =true)
	{
		CefMainArgs main_args(hInstance);  

		CefRefPtr<ClientApp> app(new ClientApp);  

		int exit_code = CefExecuteProcess(main_args, app.get(), NULL);  
		if (exit_code >= 0){  
			exit(exit_code);  
		}  

		CefSettings settings;  
		CefSettingsTraits::init(&settings);  
		settings.multi_threaded_message_loop = true;  
		settings.single_process = bSingleProcess;
		TCHAR szBuffer[MAX_PATH];  
		SHGetSpecialFolderPath(NULL, szBuffer, CSIDL_INTERNET_CACHE, FALSE);   
		_stprintf(szBuffer,_T("%s\\cache"), szBuffer);  
		//CefString(&settings.cache_path) = szBuffer;
		CefString(&settings.cache_path).FromWString(szBuffer);
		settings.log_severity = LOGSEVERITY_DISABLE;
		CefString(&settings.locale) =  "zh-CN";

		CefInitialize(main_args, settings, app.get(), NULL);  
	}
Esempio n. 4
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;
}
Esempio n. 5
0
int CefInit(int &argc, char **argv) {
  qDebug() << __FUNCTION__;
  HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);

  CefMainArgs main_args(hInstance);
  CefRefPtr<ClientApp> app(new ClientApp);

#ifdef SUB_PROCESS_DISABLED
  // Execute the secondary process, if any.
  int exit_code = CefExecuteProcess(main_args, app.get());
  if (exit_code >= 0)
    return exit_code;
#endif

  CefSettings settings;
  CefInitSettings(settings);
  
#ifndef SUB_PROCESS_DISABLED
  // Specify the path for the sub-process executable.
  CefString(&settings.browser_subprocess_path).FromASCII("cefclient_process.exe");
#endif

  // Initialize CEF.
  CefInitialize(main_args, settings, app.get());

  g_handler = new ClientHandler();

  return -1;
}
Esempio n. 6
0
	void __stdcall  Init(HINSTANCE hInstance,bool bSingleProcess =true)
	{
		SetErrorMode(SEM_NOGPFAULTERRORBOX|SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT|SEM_NOOPENFILEERRORBOX);
		CefMainArgs main_args(hInstance);  

		CefRefPtr<ClientApp> app(new ClientApp);  

		int exit_code = CefExecuteProcess(main_args, app.get(), NULL);  
		if (exit_code >= 0){  
			exit(exit_code);  
		}  

		CefSettings settings;  
		CefSettingsTraits::init(&settings);  
		settings.multi_threaded_message_loop = true;  
		settings.single_process = bSingleProcess;
		TCHAR szBuffer[MAX_PATH];  
		SHGetSpecialFolderPath(NULL, szBuffer, CSIDL_INTERNET_CACHE, FALSE);   
		_stprintf(szBuffer,_T("%s\\cache"), szBuffer);  
		//CefString(&settings.cache_path) = szBuffer;
		CefString(&settings.cache_path).FromWString(szBuffer);
		settings.log_severity = LOGSEVERITY_DISABLE;
		CefString(&settings.locale) =  "zh-CN";
		settings.ignore_certificate_errors = s_ignore_Cert_Err;

		CefInitialize(main_args, settings, app.get(), NULL);  
	}
Esempio n. 7
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;
}
// Cef的初始化接口,同时备注了使用各个版本的Cef时遇到的各种坑
// Cef1916版本较稳定,各个功能使用正常,但是某些在debug模式网页打开时会出中断警告(但并不是错误),可能是因为对新html标准支持不够,但是在release模式下正常使用
// Cef2357版本无法使用,当程序处理重定向信息并且重新加载页面后,渲染进程会崩掉
// Cef2526、2623版本对各种新页面都支持,唯一的坑就是debug模式在多线程消息循环开启下,程序退出时会中断,但是release模式正常。
//		(PS:如果开发者不使用负责Cef功能的开发,可以切换到release模式的cef dll文件,这样即使在deubg下也不会报错,修改AddCefDllToPath代码可以切换到release目录)
bool CefManager::Initialize(const std::wstring& app_data_dir, CefSettings &settings, bool is_enable_offset_render /*= true*/)
{
#if !defined(SUPPORT_CEF)
	return true;
#endif
	is_enable_offset_render_ = is_enable_offset_render;

	CefMainArgs main_args(GetModuleHandle(NULL));
	CefRefPtr<ClientApp> app(new ClientApp);
	
	// 如果是在子进程中调用,会堵塞直到子进程退出,并且exit_code返回大于等于0
	// 如果在Browser进程中调用,则立即返回-1
	int exit_code = CefExecuteProcess(main_args, app.get(), NULL);
	if (exit_code >= 0)
		return false;

	GetCefSetting(app_data_dir, settings);

	bool bRet = CefInitialize(main_args, settings, app.get(), NULL);
	
	if (is_enable_offset_render_)
	{
		HWND hwnd = CreateWindow(L"Static", L"", WS_POPUP, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
		CefPostTask(TID_UI, base::Bind(&FixContextMenuBug, hwnd));
	}

	return bRet;
}
Esempio n. 9
0
int32 RunCEFSubProcess(const CefMainArgs& MainArgs)
{
	CEF3Utils::LoadCEF3Modules();
	// Execute the sub-process logic. This will block until the sub-process should exit.
	int32 Result = CefExecuteProcess(MainArgs, nullptr, nullptr);
	CEF3Utils::UnloadCEF3Modules();
	return Result;
}
Esempio n. 10
0
// Process entry point.
int main(int argc, char* argv[]) {
  CefMainArgs main_args(argc, argv);
  
  CefRefPtr<CefApp> app(new ClientApp);

  // Execute the secondary process.
  return CefExecuteProcess(main_args, app);
}
Esempio n. 11
0
    int CefAppWrapper::Run()
    {
        auto hInstance = Process::GetCurrentProcess()->Handle;

        CefMainArgs cefMainArgs((HINSTANCE)hInstance.ToPointer());

        return CefExecuteProcess(cefMainArgs, (CefApp*)_cefApp.get(), NULL);
    }
Esempio n. 12
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;
}
Esempio n. 13
0
void Component_RunPreInit()
{
#ifdef _M_AMD64
	// again, a Win7 SP1 check (Chromium x64 isn't supported below this operating level)
	if (!IsWindows7SP1OrGreater())
	{
		FatalError("CitizenFX requires Windows 7 SP1 or higher. Please upgrade to this operating system version to run CitizenFX.");
	}
#endif

	// CEF keeps loading/unloading this - load it ourselves to make the refcount always 1
	LoadLibrary(L"bluetoothapis.dll");

	// load Chrome dependencies ourselves so that the system won't try loading from other paths
	LoadLibrary(MakeRelativeCitPath(L"bin/chrome_elf.dll").c_str());
	LoadLibrary(MakeRelativeCitPath(L"bin/libEGL.dll").c_str());
	LoadLibrary(MakeRelativeCitPath(L"bin/libGLESv2.dll").c_str());

	// load the CEF library
	HMODULE libcef = LoadLibraryW(MakeRelativeCitPath(L"bin/libcef.dll").c_str());

	if (!libcef)
	{
		MessageBoxW(NULL, L"Could not load bin/libcef.dll.", L"CitizenFX", MB_ICONSTOP | MB_OK);

		ExitProcess(0);
	}

	__HrLoadAllImportsForDll("libcef.dll");

	Instance<NUIApp>::Set(new NUIApp());

	// instantiate a NUIApp
	auto selfApp = Instance<NUIApp>::Get();

	CefMainArgs args(GetModuleHandle(NULL));
	static CefRefPtr<CefApp> app(selfApp);

    auto schemeHandlerFactory = new NUISchemeHandlerFactory();
    schemeHandlerFactory->AddRef();
    Instance<NUISchemeHandlerFactory>::Set(schemeHandlerFactory);

    InitFunctionBase::RunAll();

    OnResumeGame.Connect([] ()
    {
        FinalizeInitNUI();
    });

	// try to execute as a CEF process
	int exitCode = CefExecuteProcess(args, app, nullptr);

	// and exit if we did
	if (exitCode >= 0)
	{
		ExitProcess(0);
	}
}
//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;
}
Esempio n. 16
0
//Initialize the CEF library hInstance will be GetModuleHandle(NULL)
void SimpleCEFDLL_Initialize( HINSTANCE hInstance )
{
	g_App = new zSimpleCefApp;

	CefMainArgs main_args( hInstance );
	CefExecuteProcess( main_args, g_App.get() );

	CefSettings settings;

	//This two settings are mandatory for work in Windows XP
	settings.multi_threaded_message_loop = true;
	settings.single_process = true;

	CefInitialize( main_args, settings, g_App.get() );
}
Esempio n. 17
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;
}
Esempio n. 18
0
// Program entry point function.
int APIENTRY wWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow) {
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);

  // Structure for passing command-line arguments.
  // The definition of this structure is platform-specific.
  CefMainArgs main_args(hInstance);

  // Optional implementation of the CefApp interface.
  CefRefPtr<ClientApp> app(new ClientApp);

  // Execute the sub-process logic. This will block until the sub-process should exit.
  return CefExecuteProcess(main_args, app.get());
}
Esempio n. 19
0
int cef_init(int argc, char *argv[])
{
    CefMainArgs args(argc, argv);
    int result = CefExecuteProcess(args, NULL, NULL);
    if (result >= 0) {
        /* child proccess has endend, so exit */
        exit(result);
    }

    CefSettings settings;

    if (!CefInitialize(args, settings, NULL, NULL)) {
        return -1;
    }

    return 0;
}
Esempio n. 20
0
//
// Program entry point function.
//
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // open the log file for writing
    g_hndLogFile = App::OpenLogFile();

    g_hInst = hInstance;

    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;

    // parse command line arguments
    // the passed in values are ignored on Windows
    App::InitCommandLine(0, NULL);

    // populate the settings based on command line arguments
    CefSettings settings;
    App::GetSettings(settings);

    g_isMultithreadedMessageLoop = settings.multi_threaded_message_loop;

    // initialize CEF
    CefInitialize(main_args, settings, app.get());

    // register cookieable schemes with the global cookie manager
    std::vector<CefString> schemes;
    schemes.push_back("http");
    schemes.push_back("https");
    CefCookieManager::GetGlobalManager()->SetSupportedSchemes(schemes);

    // create the main window and run
    InitMenuCommands();
    int result = CreateMainWindow();

    // shut down CEF
    CefShutdown();

    return result;
}
Esempio n. 21
0
bool CWebCore::Initialise ()
{
    CefMainArgs mainArgs;
    void* sandboxInfo = nullptr;
    CefRefPtr<CCefApp> app { new CCefApp };

#if CEF_ENABLE_SANDBOX
    CefScopedSandboxInfo scopedSandbox;
    sandboxInfo = scopedSandbox.sandbox_info();
#endif

    if ( CefExecuteProcess ( mainArgs, app, sandboxInfo ) >= 0 )
        return false;

    CefSettings settings;
#if !CEF_ENABLE_SANDBOX
    settings.no_sandbox = true;
#endif

    // Specifiy sub process executable path
#ifndef MTA_DEBUG
    CefString ( &settings.browser_subprocess_path ).FromWString( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\CEFLauncher.exe" ) ) );
#else
    CefString ( &settings.browser_subprocess_path ).FromWString( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\CEFLauncher_d.exe" ) ) );
#endif
    CefString ( &settings.resources_dir_path ).FromWString ( FromUTF8( CalcMTASAPath( "MTA\\CEF") ) );
    CefString ( &settings.locales_dir_path ).FromWString( FromUTF8( CalcMTASAPath( "MTA\\CEF\\locales" ) ) );
    CefString ( &settings.log_file ).FromWString ( FromUTF8( CalcMTASAPath ( "MTA\\CEF\\cefdebug.txt" ) ) );
#ifdef MTA_DEBUG
    settings.log_severity = cef_log_severity_t::LOGSEVERITY_INFO;
#else
    settings.log_severity = cef_log_severity_t::LOGSEVERITY_WARNING;
#endif

    settings.multi_threaded_message_loop = true;
    settings.windowless_rendering_enabled = true;

    bool state = CefInitialize ( mainArgs, settings, app, sandboxInfo );
    
    // Register custom scheme handler factory
    CefRegisterSchemeHandlerFactory ( "mtalocal", "", app );
    CefRegisterSchemeHandlerFactory ( "http", "mta", app );

    return state;
}
Esempio n. 22
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;
}
Esempio n. 23
0
// Process entry point.
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow )
{
	//CefMainArgs main_args(argc, argv);

	HINSTANCE hinst = (HINSTANCE)GetModuleHandle(NULL);
	CefMainArgs main_args( hinst );
  
	CefRefPtr<CefApp> app(new ClientApp);

	// Execute the secondary process.
	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

	return CefExecuteProcess(main_args, app.get(), sandbox_info);
}
Esempio n. 24
0
int QCefInit(int& argc, char** argv)
{
	HINSTANCE hInstance = static_cast<HINSTANCE>(GetModuleHandle(nullptr));

	CefMainArgs mainArgs(hInstance);
	CefRefPtr<QCefClientApp> app(new QCefClientApp);

	int exit_code = CefExecuteProcess(mainArgs, app.get(), nullptr);
	if (exit_code >= 0) {
		return exit_code;
	}

	CefSettings settings;
	QCefInitSettings(settings);

	CefInitialize(mainArgs, settings, app, nullptr);

	g_handler = new QCefClientHandler();

	return -1;
}
Esempio n. 25
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;
			}
		}
	}
}
Esempio n. 27
0
int _declspec(dllexport) InitCEF()
{
    // Get absolute CEFLauncher.exe path
    TCHAR buffer[MAX_PATH];
    GetModuleFileName(NULL, buffer, MAX_PATH);
    std::wstring currentFileName(buffer);

    // Extract MTA path and set DLL directory (absolute path is required here)
    size_t       pos = currentFileName.find_last_of(L'\\');
    std::wstring mtaPath = currentFileName.substr(0, pos - 3);            // Strip "CEF"
    SetDllDirectory(mtaPath.c_str());

    // Load CEF
    CefMainArgs        mainArgs(GetModuleHandle(NULL));
    CefRefPtr<CCefApp> app{new CCefApp};

    void* sandboxInfo = nullptr;
#ifdef CEF_ENABLE_SANDBOX
    CefScopedSandboxInfo scopedSandbox;
    sandboxInfo = scopedSandbox.sandbox_info();
#endif

    return CefExecuteProcess(mainArgs, app, sandboxInfo);
}
// 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;
}
Esempio n. 29
0
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;
}
Esempio n. 30
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());
  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;
}