// 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;
}
示例#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);
}
示例#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);  
	}
示例#4
0
void ClientAppInit() {
	
	// Init =======================================================

	HINSTANCE hInstance = GetModuleHandle(nullptr); 
	hInst = hInstance;

	CefMainArgs main_args(hInstance);

	// Create the v8-binding app so we can communicate
	// between html/js, the cef client, and ofx
	sClientApp = new ClientApp();

	// Parse command line arguments. The passed in values are ignored on Windows.
	AppInitCommandLine(0, NULL);

	CefSettings appSettings;

	// The CEF client launches multiples threads from this single process
	appSettings.single_process = true; 

	// Populate the settings based on command line arguments.
	AppGetSettings(appSettings);

	CefInitialize(main_args, appSettings, sClientApp.get());
}
示例#5
0
		bool CEFManager::Initialize(CoreApiPtr pCore)
		{
			m_pCore = pCore;
			
#ifdef WIN32
			CefMainArgs main_args(GetModuleHandle(NULL));
#endif
			
#ifdef __APPLE__
			CefMainArgs main_args;
#endif
			m_pApp = new CEFApp;

			CefSettings settings;
			settings.command_line_args_disabled = false;
			const char* szSub = "./cef_sub_process_x64.exe";
			
			CefString(&settings.browser_subprocess_path).FromASCII(szSub);
			CefString(&settings.log_file).FromString("./log/cef.log");

#ifdef __APPLE__
			if(false == CefInitialize(main_args, settings, m_pApp.get(), nullptr))
#endif
#ifdef WIN32
			if(false == CefInitialize(main_args, settings, m_pApp.get()))
#endif
			{
				return false;
			}

			return true;
		}
示例#6
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;
}
// 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;
}
示例#8
0
文件: main.cpp 项目: 116356754/libcef
	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);  
	}
// 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);
}
示例#10
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;
}
示例#13
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() );
}
示例#14
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());
}
示例#15
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;
}
示例#16
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;
}
示例#17
0
int main(int argc, char **argv) {
    romfsInit();

#if _3DS_MODE == _3DS_MODE_REPL
    main_repl(argc, argv);
#elif _3DS_MODE == _3DS_MODE_NETLOAD
    main_netload(argc, argv);
#elif _3DS_MODE == _3DS_MODE_ROMFS
    main_romfs(argc, argv);
#elif _3DS_MODE == _3DS_MODE_ARGS
    main_args(argc, argv);
#endif

    romfsExit();

    // ensure all services are exited to be a good citizen
    mod_citrus_exit_all();

    return 0;
}
示例#18
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);
}
示例#19
0
ReturnOop IsolateObj::duplicate(JVM_SINGLE_ARG_TRAPS) const {
  UsingFastOops fast_oops;
  IsolateObj::Fast dup = 
      Universe::new_instance(Universe::isolate_class() JVM_CHECK_0);

  dup().set_unique_id( unique_id() );
  dup().set_use_verifier( use_verifier() );
  dup().set_api_access_init( api_access_init() );
#if ENABLE_MULTIPLE_PROFILES_SUPPORT
  dup().set_profile_id( profile_id() );
#endif // ENABLE_MULTIPLE_PROFILES_SUPPORT

  OopDesc* p;
  // Do not use JVM_ZCHECK because result can be NULL
  p = Universe::deep_copy(main_class() JVM_CHECK_0);
  dup().set_main_class(p);
  p = Universe::deep_copy(main_args() JVM_CHECK_0);
  dup().set_main_args(p);
  p = Universe::deep_copy(app_classpath() JVM_CHECK_0);
  dup().set_app_classpath(p);

  return dup.obj();
}
示例#20
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;
}
示例#21
0
extern "C" int main( int argc, char *argv[] )
{
	std::string base_directory;

	base_directory = elix::path::GetBase( "/MokoiGaming/luxengine" , true );
	lux::engine = new LuxEngine( base_directory + "demos"LUX_DIR_SSEPARATOR"Collision"LUX_DIR_SSEPARATOR, base_directory );
	main_args( argc, argv );
	LuxPortal::open();
	if ( LuxPortal::use )
	{
		while ( LuxPortal::active )
		{
			if ( LuxPortal::run() )
			{
				if ( lux::engine->Start() )
				{
					lux::engine->Loop();
				}
				lux::engine->Close();
			}
		}
	}
	else
	{
		if ( lux::engine->Start() )
		{
			lux::engine->Loop();
		}
		lux::engine->Close();
	}
	LuxPortal::close();
	delete lux::engine;
	

	return 0;
}
示例#22
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;
}
// 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;
}
示例#24
0
		int lua_repl(int argc, char **argv)
		{
			os::MutexLock lock(m);
			return main_args(L, argc, argv);
		}
示例#25
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;
}
示例#26
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);

  // 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;
}
示例#27
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;
}
JNIEXPORT void JNICALL Java_org_embedded_browser_Chromium_browser_1init
  (JNIEnv *env, jobject jobj, jlong hwnd, jstring url, jobject chromiumset)
{
  // Make a simple argument.
  const int argc = 1;
  char** argv = (char**)malloc(argc * sizeof(*argv));
  argv[0] = strdup("java");

  CefMainArgs main_args(argc, argv);
  CefRefPtr<ClientApp> app(new ClientApp);

  // Retrieve the current working directory.
  szWorkingDir = getenv("WSO2_DEVELOPER_STUDIO_PATH");
  if (!szWorkingDir)
    szWorkingDir = (char*)calloc(1, sizeof(char));

  // Parse command line arguments. The passed in values are ignored on Windows.
  AppInitCommandLine(argc, argv);

  CefSettings settings;

  // Populate the settings based on command line arguments.
  AppGetSettings(settings);

  settings.multi_threaded_message_loop = message_loop;
  settings.log_severity = LOGSEVERITY_DISABLE;
  settings.no_sandbox = true;

  CefString path = CefString(szWorkingDir);

#ifndef __LP64__
  CefString(&settings.browser_subprocess_path) = path.ToString() + "/cef/cefclient";
  CefString(&settings.resources_dir_path) = path.ToString() + "/cef";
  CefString(&settings.locales_dir_path) = path.ToString() + "/cef/locales";
#else
  CefString(&settings.browser_subprocess_path) = path.ToString() + "/cef/cefclient";
  CefString(&settings.resources_dir_path) = path.ToString() + "/cef";
  CefString(&settings.locales_dir_path) = path.ToString() + "/cef/locales";
#endif

  BackupSignalHandlers();

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

  RestoreSignalHandlers();

  GtkWidget* canvas = (GtkWidget*)hwnd;
  GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
  gtk_fixed_put(GTK_FIXED(canvas), vbox, 0, 0);

  const char* chr = env->GetStringUTFChars(url, 0);
  CefString wc = chr;

  CefRefPtr<ClientHandler> gh = InitBrowser(vbox, wc);
  gh->id = 1;
  gh->vbox = vbox;

  env->ReleaseStringUTFChars(url, chr);

  // NOTE: This function (browser_init) should only be called ONCE in one process,
  // which means to call CefInitialize in the first broswer creation, and call 
  // CefShutdown in the exit of the process. Repeated calls to this function will 
  // NOT work, because the web page will not render. Most probably a bug in cef.
  set_jvm(env, jobj);
  send_handler(env, jobj, (jlong)(void*)gh);

  // Have to be here and use own jnienv to avoid errors.
  get_browser_settings(env, chromiumset, gh->csettings);

  //CefRunMessageLoop();
  //CefShutdown();
}
示例#29
0
// 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;
}
示例#30
0
int main(int argc, char *argv[])
{
    if (IsSubprocess(argc, argv)) {
// 		QMessageBox::about(NULL, "1", "2");
        return RunCefSubprocess(argc, argv);
    }
// 	argc = 2;
// 	argv[1] = "--ppapi-flash-path=plugins\\pepflashplayer.dll";
    QApplication a(argc, argv);

    // Enable High-DPI support on Windows 7 or newer.
    CefEnableHighDPISupport();
    void* sandbox_info = NULL;

#if defined(CEF_USE_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

    HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);

    // 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.
// 	QMessageBox::about(NULL, "main", "1");
    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.
// 	QMessageBox::about(NULL, "main", "2");
// 	int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
// 	// The sub-process has completed so return here.
// 	QMessageBox::about(NULL, "main", QString("%1").arg(exit_code));

//
// 	if (exit_code >= 0) {
// 		QMessageBox::about(NULL, "main", "3");
// 		return 0;
// 	}
// 	QMessageBox::about(NULL, "main", "4");
    // Specify CEF global settings here.

    CefSettings settings;

#if !defined(CEF_USE_SANDBOX)
    settings.no_sandbox = true;
#endif
    settings.multi_threaded_message_loop = true;
    settings.remote_debugging_port = 2012;
// 	settings.single_process = true;
    // Initialize CEF.
    CefInitialize(main_args, settings, app.get(), sandbox_info);

    QtCef w;
    w.show();

    int result = a.exec();
    // Shut down CEF.
#ifndef _DEBUG
    CefShutdown();
#endif // _DEBUG

    return result;
}