コード例 #1
0
ファイル: cef.go プロジェクト: kayon/cef2go
func CreateBrowser(hwnd unsafe.Pointer, browserSettings BrowserSettings,
	url string) {
	Logger.Println("CreateBrowser, url=", url)

	// Initialize cef_window_info_t structure.
	var windowInfo *C.cef_window_info_t
	windowInfo = (*C.cef_window_info_t)(
		C.calloc(1, C.sizeof_cef_window_info_t))
	FillWindowInfo(windowInfo, hwnd)

	// url
	var cefUrl *C.cef_string_t
	cefUrl = (*C.cef_string_t)(
		C.calloc(1, C.sizeof_cef_string_t))
	var charUrl *C.char = C.CString(url)
	defer C.free(unsafe.Pointer(charUrl))
	C.cef_string_from_utf8(charUrl, C.strlen(charUrl), cefUrl)

	// Initialize cef_browser_settings_t structure.
	var cefBrowserSettings *C.struct__cef_browser_settings_t
	cefBrowserSettings = (*C.struct__cef_browser_settings_t)(
		C.calloc(1, C.sizeof_struct__cef_browser_settings_t))
	cefBrowserSettings.size = C.sizeof_struct__cef_browser_settings_t

	// Do not create the browser synchronously using the
	// cef_browser_host_create_browser_sync() function, as
	// it is unreliable. Instead obtain browser object in
	// life_span_handler::on_after_created. In that callback
	// keep CEF browser objects in a global map (cef window
	// handle -> cef browser) and introduce
	// a GetBrowserByWindowHandle() function. This function
	// will first guess the CEF window handle using for example
	// WinAPI functions and then search the global map of cef
	// browser objects.
	C.cef_browser_host_create_browser(windowInfo, _ClientHandler, cefUrl,
		cefBrowserSettings, nil)
}
コード例 #2
0
ファイル: cef.go プロジェクト: regiontog/cef
func (b BrowserSettings) toC() *C.struct__cef_browser_settings_t {
	var cefBrowserSettings *C.struct__cef_browser_settings_t
	cefBrowserSettings = (*C.struct__cef_browser_settings_t)(
		C.calloc(1, C.sizeof_struct__cef_browser_settings_t))
	cefBrowserSettings.size = C.sizeof_struct__cef_browser_settings_t

	go_AddRef(unsafe.Pointer(cefBrowserSettings))

	if b.StandardFontFamily != "" {
		toCefStringCopy(b.StandardFontFamily, &cefBrowserSettings.standard_font_family)
	}
	if b.FixedFontFamily != "" {
		toCefStringCopy(b.FixedFontFamily, &cefBrowserSettings.fixed_font_family)
	}
	if b.SerifFontFamily != "" {
		toCefStringCopy(b.SerifFontFamily, &cefBrowserSettings.serif_font_family)
	}
	if b.SansSerifFontFamily != "" {
		toCefStringCopy(b.SansSerifFontFamily, &cefBrowserSettings.sans_serif_font_family)
	}
	if b.CursiveFontFamily != "" {
		toCefStringCopy(b.CursiveFontFamily, &cefBrowserSettings.cursive_font_family)
	}
	if b.FantasyFontFamily != "" {
		toCefStringCopy(b.FantasyFontFamily, &cefBrowserSettings.fantasy_font_family)
	}
	cefBrowserSettings.default_font_size = C.int(b.DefaultFontSize)
	cefBrowserSettings.default_fixed_font_size = C.int(b.DefaultFixedFontSize)
	cefBrowserSettings.minimum_font_size = C.int(b.MinimumFontSize)
	cefBrowserSettings.minimum_logical_font_size = C.int(b.MinimumLogicalFontSize)
	if b.DefaultEncoding != "" {
		toCefStringCopy(b.DefaultEncoding, &cefBrowserSettings.default_encoding)
	}
	cefBrowserSettings.remote_fonts = C.cef_state_t(b.RemoteFonts)
	cefBrowserSettings.javascript = C.cef_state_t(b.Javascript)
	cefBrowserSettings.javascript_open_windows = C.cef_state_t(b.JavascriptOpenWindows)
	cefBrowserSettings.javascript_close_windows = C.cef_state_t(b.JavascriptCloseWindows)
	cefBrowserSettings.javascript_access_clipboard = C.cef_state_t(b.JavascriptAccessClipboard)
	cefBrowserSettings.javascript_dom_paste = C.cef_state_t(b.JavascriptDomPaste)
	cefBrowserSettings.caret_browsing = C.cef_state_t(b.CaretBrowsing)
	cefBrowserSettings.java = C.cef_state_t(b.Java)
	cefBrowserSettings.plugins = C.cef_state_t(b.Plugins)
	cefBrowserSettings.universal_access_from_file_urls = C.cef_state_t(b.UniversalAccessFromFileUrls)
	cefBrowserSettings.file_access_from_file_urls = C.cef_state_t(b.FileAccessFromFileUrls)
	cefBrowserSettings.web_security = C.cef_state_t(b.WebSecurity)
	cefBrowserSettings.image_loading = C.cef_state_t(b.ImageLoading)
	cefBrowserSettings.image_shrink_standalone_to_fit = C.cef_state_t(b.ImageShrinkStandaloneToFit)
	cefBrowserSettings.text_area_resize = C.cef_state_t(b.TextAreaResize)
	cefBrowserSettings.tab_to_links = C.cef_state_t(b.TabToLinks)
	cefBrowserSettings.local_storage = C.cef_state_t(b.LocalStorage)
	cefBrowserSettings.databases = C.cef_state_t(b.Databases)
	cefBrowserSettings.application_cache = C.cef_state_t(b.ApplicationCache)
	cefBrowserSettings.webgl = C.cef_state_t(b.Webgl)
	cefBrowserSettings.background_color = C.cef_color_t(b.BackgroundColor)
	return cefBrowserSettings
}