Exemplo n.º 1
0
Arquivo: cef.go Projeto: regiontog/cef
func Initialize(settings Settings, appHandler AppHandler) int {
	Logger.Infof("Initialize\n")

	if _MainArgs == nil {
		// _MainArgs structure is initialized and filled in ExecuteProcess.
		// If cef_execute_process is not called, and there is a call
		// to cef_initialize, then it would result in creation of infinite
		// number of processes. See Issue 1199 in CEF:
		// https://code.google.com/p/chromiumembedded/issues/detail?id=1199
		Logger.Errorf("ERROR: missing a call to ExecuteProcess\n")
		return 0
	}

	// Initialize cef_settings_t structure.
	var cefSettings *C.struct__cef_settings_t
	cefSettings = (*C.struct__cef_settings_t)(
		C.calloc(1, C.sizeof_struct__cef_settings_t))
	cefSettings.size = C.sizeof_struct__cef_settings_t

	// cache_path
	// ----------
	if settings.CachePath != "" {
		Logger.Infof("CachePath=%s\n", settings.CachePath)
	}
	var cachePath *C.char = C.CString(settings.CachePath)
	defer C.free(unsafe.Pointer(cachePath))
	C.cef_string_from_utf8(cachePath, C.strlen(cachePath),
		C.cefStringCastToCefString16(&cefSettings.cache_path))

	// log_severity
	// ------------
	cefSettings.log_severity =
		(C.cef_log_severity_t)(C.int(settings.LogSeverity))

	// log_file
	// --------
	if settings.LogFile != "" {
		Logger.Infof("LogFile=%s\n", settings.LogFile)
	}
	var logFile *C.char = C.CString(settings.LogFile)
	defer C.free(unsafe.Pointer(logFile))
	C.cef_string_from_utf8(logFile, C.strlen(logFile),
		C.cefStringCastToCefString16(&cefSettings.log_file))

	// resources_dir_path
	// ------------------
	if settings.ResourcesDirPath == "" && runtime.GOOS != "darwin" {
		// Setting this path is required for the tests to run fine.
		cwd, _ := os.Getwd()
		settings.ResourcesDirPath = cwd
	}
	if settings.ResourcesDirPath != "" {
		Logger.Infof("ResourcesDirPath=%s\n", settings.ResourcesDirPath)
	}
	var resourcesDirPath *C.char = C.CString(settings.ResourcesDirPath)
	defer C.free(unsafe.Pointer(resourcesDirPath))
	C.cef_string_from_utf8(resourcesDirPath, C.strlen(resourcesDirPath),
		C.cefStringCastToCefString16(&cefSettings.resources_dir_path))

	// locales_dir_path
	// ----------------
	if settings.LocalesDirPath == "" && runtime.GOOS != "darwin" {
		// Setting this path is required for the tests to run fine.
		cwd, _ := os.Getwd()
		settings.LocalesDirPath = cwd + "/locales"
	}
	if settings.LocalesDirPath != "" {
		Logger.Infof("LocalesDirPath=%s\n", settings.LocalesDirPath)
	}
	var localesDirPath *C.char = C.CString(settings.LocalesDirPath)
	defer C.free(unsafe.Pointer(localesDirPath))
	C.cef_string_from_utf8(localesDirPath, C.strlen(localesDirPath),
		C.cefStringCastToCefString16(&cefSettings.locales_dir_path))

	if settings.PersistSessionCookies {
		cefSettings.persist_session_cookies = 1
	}
	cefSettings.remote_debugging_port = C.int(settings.RemoteDebuggingPort)

	cefSettings.ignore_certificate_errors = C.int(settings.IgnoreCertificateErrors)

	// no_sandbox
	// ----------
	cefSettings.no_sandbox = C.int(1)

	go_AddRef(unsafe.Pointer(_MainArgs))
	go_AddRef(unsafe.Pointer(appHandler.GetAppHandlerT().CStruct))
	go_AddRef(unsafe.Pointer(_SandboxInfo))
	ret := C.cef_initialize(_MainArgs, cefSettings, appHandler.GetAppHandlerT().CStruct, _SandboxInfo)
	return int(ret)
}
Exemplo n.º 2
0
Arquivo: cef.go Projeto: kayon/cef2go
func Initialize(settings Settings) int {
	Logger.Println("Initialize")

	if _MainArgs == nil {
		// _MainArgs structure is initialized and filled in ExecuteProcess.
		// If cef_execute_process is not called, and there is a call
		// to cef_initialize, then it would result in creation of infinite
		// number of processes. See Issue 1199 in CEF:
		// https://code.google.com/p/chromiumembedded/issues/detail?id=1199
		Logger.Println("ERROR: missing a call to ExecuteProcess")
		return 0
	}

	// Initialize cef_settings_t structure.
	var cefSettings *C.struct__cef_settings_t
	cefSettings = (*C.struct__cef_settings_t)(
		C.calloc(1, C.sizeof_struct__cef_settings_t))
	cefSettings.size = C.sizeof_struct__cef_settings_t

	// cache_path
	// ----------
	if settings.CachePath != "" {
		Logger.Println("CachePath=", settings.CachePath)
	}
	var cachePath *C.char = C.CString(settings.CachePath)
	defer C.free(unsafe.Pointer(cachePath))
	C.cef_string_from_utf8(cachePath, C.strlen(cachePath),
		&cefSettings.cache_path)

	// log_severity
	// ------------
	cefSettings.log_severity =
		(C.cef_log_severity_t)(C.int(settings.LogSeverity))

	// log_file
	// --------
	if settings.LogFile != "" {
		Logger.Println("LogFile=", settings.LogFile)
	}
	var logFile *C.char = C.CString(settings.LogFile)
	defer C.free(unsafe.Pointer(logFile))
	C.cef_string_from_utf8(logFile, C.strlen(logFile),
		&cefSettings.log_file)

	// resources_dir_path
	// ------------------
	if settings.ResourcesDirPath == "" && runtime.GOOS != "darwin" {
		// Setting this path is required for the tests to run fine.
		cwd, _ := os.Getwd()
		settings.ResourcesDirPath = cwd
	}
	if settings.ResourcesDirPath != "" {
		Logger.Println("ResourcesDirPath=", settings.ResourcesDirPath)
	}
	var resourcesDirPath *C.char = C.CString(settings.ResourcesDirPath)
	defer C.free(unsafe.Pointer(resourcesDirPath))
	C.cef_string_from_utf8(resourcesDirPath, C.strlen(resourcesDirPath),
		&cefSettings.resources_dir_path)

	// locales_dir_path
	// ----------------
	if settings.LocalesDirPath == "" && runtime.GOOS != "darwin" {
		// Setting this path is required for the tests to run fine.
		cwd, _ := os.Getwd()
		settings.LocalesDirPath = cwd + "/locales"
	}
	if settings.LocalesDirPath != "" {
		Logger.Println("LocalesDirPath=", settings.LocalesDirPath)
	}
	var localesDirPath *C.char = C.CString(settings.LocalesDirPath)
	defer C.free(unsafe.Pointer(localesDirPath))
	C.cef_string_from_utf8(localesDirPath, C.strlen(localesDirPath),
		&cefSettings.locales_dir_path)

	// no_sandbox
	// ----------
	cefSettings.no_sandbox = C.int(1)

	ret := C.cef_initialize(_MainArgs, cefSettings, _AppHandler, _SandboxInfo)
	return int(ret)
}