Example #1
0
void FWebBrowserHandler::OnAfterCreated(CefRefPtr<CefBrowser> Browser)
{
	TSharedPtr<FWebBrowserWindow> BrowserWindow = BrowserWindowPtr.Pin();

	if (BrowserWindow.IsValid())
	{

		BrowserWindow->BindCefBrowser(Browser);
	}
	else
	{
		if(Browser->IsPopup())
		{
			TSharedPtr<FWebBrowserWindow> BrowserWindowParent = BrowserWindowParentPtr.Pin();
			if(BrowserWindowParent.IsValid() && BrowserWindowParent->SupportsNewWindows())
			{
				TSharedPtr<FWebBrowserWindowInfo> NewBrowserWindowInfo = MakeShareable(new FWebBrowserWindowInfo(Browser, this));
				TSharedPtr<IWebBrowserWindow> NewBrowserWindow = IWebBrowserModule::Get().GetSingleton()->CreateBrowserWindow( 
					BrowserWindowParent,
					NewBrowserWindowInfo
					);	

				{
					// @todo: At the moment we need to downcast since the handler does not support using the interface.
					TSharedPtr<FWebBrowserWindow> HandlerSpecificBrowserWindow = StaticCastSharedPtr<FWebBrowserWindow>(NewBrowserWindow);
					BrowserWindowPtr = HandlerSpecificBrowserWindow;
				}

				// Request a UI window for the browser.  If it is not created we do some cleanup.
				bool bUIWindowCreated = BrowserWindowParent->RequestCreateWindow(NewBrowserWindow.ToSharedRef(), BrowserPopupFeatures);
				if(!bUIWindowCreated)
				{
					NewBrowserWindow->CloseBrowser(true);
				}
			}
			else
			{
				Browser->GetHost()->CloseBrowser(true);
			}
		}
	}
}