TSharedPtr<IWebBrowserWindow> FWebBrowserSingleton::CreateBrowserWindow(
	void* OSWindowHandle, 
	FString InitialURL, 
	uint32 Width, 
	uint32 Height, 
	bool bUseTransparency,
	bool bThumbMouseButtonNavigation,
	TOptional<FString> ContentsToLoad, 
	bool ShowErrorMessage,
	FColor BackgroundColor)
{
#if WITH_CEF3
	// Create new window
	TSharedPtr<FWebBrowserWindow> NewWindow(new FWebBrowserWindow(FIntPoint(Width, Height), InitialURL, ContentsToLoad, ShowErrorMessage, bThumbMouseButtonNavigation, bUseTransparency));

	// WebBrowserHandler implements browser-level callbacks.
	CefRefPtr<FWebBrowserHandler> NewHandler(new FWebBrowserHandler);
	NewWindow->SetHandler(NewHandler);

	// Information used when creating the native window.
	CefWindowHandle WindowHandle = (CefWindowHandle)OSWindowHandle; // TODO: check this is correct for all platforms
	CefWindowInfo WindowInfo;

	// Always use off screen rendering so we can integrate with our windows
	WindowInfo.SetAsWindowless(WindowHandle, bUseTransparency);

	// Specify CEF browser settings here.
	CefBrowserSettings BrowserSettings;
	
	// Set max framerate to maximum supported.
	BrowserSettings.windowless_frame_rate = 60;
	BrowserSettings.background_color = CefColorSetARGB(BackgroundColor.A, BackgroundColor.R, BackgroundColor.G, BackgroundColor.B);

	// Disable plugins
	BrowserSettings.plugins = STATE_DISABLED;

	CefString URL = *InitialURL;

	// Create the CEF browser window.
	if (CefBrowserHost::CreateBrowser(WindowInfo, NewHandler.get(), URL, BrowserSettings, NULL))
	{
		WindowInterfaces.Add(NewWindow);
		return NewWindow;
	}
#endif
	return NULL;
}
Пример #2
0
bool FWebBrowserHandler::ShowDevTools(const CefRefPtr<CefBrowser>& Browser)
{
	CefPoint Point;
	CefString TargetUrl = "chrome-devtools://devtools/devtools.html";
	CefString TargetFrameName = "devtools";
	CefPopupFeatures PopupFeatures;
	CefWindowInfo WindowInfo;
	CefRefPtr<CefClient> NewClient;
	CefBrowserSettings BrowserSettings;
	bool NoJavascriptAccess = false;

	PopupFeatures.xSet = false;
	PopupFeatures.ySet = false;
	PopupFeatures.heightSet = false;
	PopupFeatures.widthSet = false;
	PopupFeatures.locationBarVisible = false;
	PopupFeatures.menuBarVisible = false;
	PopupFeatures.toolBarVisible  = false;
	PopupFeatures.statusBarVisible  = false;
	PopupFeatures.resizable = true;
	PopupFeatures.additionalFeatures = cef_string_list_alloc();

	// Override the parent window setting for transparency, as the Dev Tools require a solid background
	CefString OverrideTransparencyFeature = "Epic_NoTransparency";
	cef_string_list_append(PopupFeatures.additionalFeatures, OverrideTransparencyFeature.GetStruct());

	// Set max framerate to maximum supported.
	BrowserSettings.windowless_frame_rate = 60;
	// Disable plugins
	BrowserSettings.plugins = STATE_DISABLED;
	// Dev Tools look best with a white background color
	BrowserSettings.background_color = CefColorSetARGB(255, 255, 255, 255);

	// OnBeforePopup already takes care of all the details required to ask the host application to create a new browser window.
	bool bSuppressWindowCreation = OnBeforePopup(Browser, Browser->GetFocusedFrame(), TargetUrl, TargetFrameName, PopupFeatures, WindowInfo, NewClient, BrowserSettings, &NoJavascriptAccess);

	if(! bSuppressWindowCreation)
	{
		Browser->GetHost()->ShowDevTools(WindowInfo, NewClient, BrowserSettings, Point);
	}
	return !bSuppressWindowCreation;
}