func CreateBrowser(hwnd unsafe.Pointer, browserSettings BrowserSettings, url string) *Browser { log.Debug("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) // 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, CEFString(url), browserSettings.ToCStruct(), nil) b, err := globalLifespanHandler.RegisterAndWaitForBrowser() if err != nil { log.Error("ERROR:", err) panic("Failed to create a browser") } b.RenderHandler = &DefaultRenderHandler{b} browsers[b.Id] = b return b }
func CreateBrowser(browserSettings *BrowserSettings, url string, offscreenRendering bool) (browser *Browser) { log.Debug("CreateBrowser, url=%s", 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)) if offscreenRendering { windowInfo.windowless_rendering_enabled = 1 windowInfo.transparent_painting_enabled = 1 } C.cef_browser_host_create_browser(windowInfo, _ClientHandler, CEFString(url), browserSettings.ToCStruct(), nil) b, err := globalLifespanHandler.RegisterAndWaitForBrowser() if err != nil { log.Error("ERROR %v", err) panic("Failed to create a browser") } b.RenderHandler = &DefaultRenderHandler{b} browsers[b.Id] = b return b }
func CreateBrowser(hwnd unsafe.Pointer, clientHandler ClientHandler, browserSettings BrowserSettings, url string) bool { Logger.Infof("CreateBrowser, url=%s\n", 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), C.cefStringCastToCefString16(cefUrl)) // Initialize cef_browser_settings_t structure. cefBrowserSettings := browserSettings.toC() // 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. go_AddRef(unsafe.Pointer(clientHandler.GetClientHandlerT().CStruct)) result := C.cef_browser_host_create_browser( windowInfo, clientHandler.GetClientHandlerT().CStruct, cefUrl, cefBrowserSettings, nil, ) return result == C.int(1) }