Пример #1
0
void CWebView::Initialise ()
{
    // Initialise the web session (which holds the actual settings) in in-memory mode
    CefBrowserSettings browserSettings;
    browserSettings.windowless_frame_rate = g_pCore->GetFrameRateLimit ();
    browserSettings.javascript_access_clipboard = cef_state_t::STATE_DISABLED;
    browserSettings.java = cef_state_t::STATE_DISABLED;
    browserSettings.caret_browsing = cef_state_t::STATE_ENABLED;
    browserSettings.universal_access_from_file_urls = cef_state_t::STATE_DISABLED; // Also filtered by resource interceptor, but set this nevertheless
    browserSettings.file_access_from_file_urls = cef_state_t::STATE_DISABLED;
    browserSettings.webgl = cef_state_t::STATE_ENABLED;
    browserSettings.javascript_open_windows = cef_state_t::STATE_DISABLED;

    bool bEnabledPlugins = g_pCore->GetWebCore ()->GetPluginsEnabled ();
    browserSettings.plugins = bEnabledPlugins ? cef_state_t::STATE_ENABLED : cef_state_t::STATE_DISABLED;
    if ( !m_bIsLocal )
    {
        bool bEnabledJavascript = g_pCore->GetWebCore ()->GetRemoteJavascriptEnabled ();
        browserSettings.javascript = bEnabledJavascript ? cef_state_t::STATE_ENABLED : cef_state_t::STATE_DISABLED;
    }

    CefWindowInfo windowInfo;
    windowInfo.SetAsWindowless ( g_pCore->GetHookedWindow (), m_bIsTransparent );
    
    CefBrowserHost::CreateBrowser ( windowInfo, this, "", browserSettings, nullptr );
}
Пример #2
0
bool FWebBrowserHandler::OnBeforePopup( CefRefPtr<CefBrowser> Browser,
									   CefRefPtr<CefFrame> Frame,
									   const CefString& TargetUrl,
									   const CefString& TArgetFrameName,
									   const CefPopupFeatures& PopupFeatures,
									   CefWindowInfo& WindowInfo,
									   CefRefPtr<CefClient>& Client,
									   CefBrowserSettings& Settings,
									   bool* NoJavascriptAccess )
{

	// By default, we ignore any popup requests unless they are handled by us in some way.
	bool bSupressCEFWindowCreation = true;
	TSharedPtr<FWebBrowserWindow> BrowserWindow = BrowserWindowPtr.Pin();

	if (BrowserWindow.IsValid())
	{
		bSupressCEFWindowCreation = BrowserWindow->OnCefBeforePopup(TargetUrl, TArgetFrameName);

		if(!bSupressCEFWindowCreation)
		{
			if(BrowserWindow->SupportsNewWindows())
			{
				CefRefPtr<FWebBrowserHandler> NewHandler(new FWebBrowserHandler);
				NewHandler->SetBrowserWindowParent(BrowserWindow);
				NewHandler->SetPopupFeatures(MakeShareable(new FWebBrowserPopupFeatures(PopupFeatures)));
				Client = NewHandler;
				
				CefWindowHandle ParentWindowHandle = BrowserWindow->GetCefBrowser()->GetHost()->GetWindowHandle();

				// Allow overriding transparency setting for child windows
				bool bUseTransparency = BrowserWindow->UseTransparency()
										? NewHandler->BrowserPopupFeatures->GetAdditionalFeatures().Find(TEXT("Epic_NoTransparency")) == INDEX_NONE
										: NewHandler->BrowserPopupFeatures->GetAdditionalFeatures().Find(TEXT("Epic_UseTransparency")) != INDEX_NONE;

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

				// We need to rely on CEF to create our window so we set the WindowInfo, BrowserSettings, Client, and then return false
				bSupressCEFWindowCreation = false;
			}
			else
			{
				bSupressCEFWindowCreation = true;
			}
		}
	}

	return bSupressCEFWindowCreation; 
}
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;
}
Пример #4
0
void BrowserClient::initBrowser(const std::string& url)
{
    //Setup our main view that will show the cef ui
    setupMainView( _width, _height );
    _viewer->addView( _mainView );

    //Setup RTT camera for screen capture
    setupRTTCamera();

    {
        CefWindowInfo windowInfo;
        CefBrowserSettings browserSettings;

        //TODO: populate settings from CLA's

        //windowInfo.SetAsOffScreen(0L);
        //windowInfo.SetTransparentPainting(true);
        windowInfo.SetAsWindowless(0L, true);

        _browser = CefBrowserHost::CreateBrowserSync(windowInfo, this, url.c_str(), browserSettings, 0L);
        _browser->GetHost()->SendFocusEvent(true);
    }

#ifdef WIN32
    //Setup native event handling on Windows
    osgViewer::GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<osgViewer::GraphicsHandleWin32*>(_mainView->getCamera()->getGraphicsContext());
    if (graphicsHandleWin32)
        _nativeEventHandler = new NativeEventHandlerWin(graphicsHandleWin32->getHWND(), this, _browser);

#endif

    addExecuteCallback(new MapExecuteCallback(this));   // handles map related calls
    addExecuteCallback(new FileExecuteCallback(this));  // handles file related calls

    _mainEventHandler = new BrowserEventHandler(_mainView.get(), this, _browser);
    _mainView->addEventHandler(_mainEventHandler);
}
Пример #5
0
    bool CreateBrowser(const String& initialURL, int width, int height)
    {
        if (browser_.get())
        {
            LOGERROR("WebClient::CreateBrowser - Browser already created");
            return false;
        }

        if (webClient_->renderHandler_.Null())
        {
            LOGERROR("WebClient::CreateBrowser - No render handler specified");
            return false;
        }

        CefWindowInfo windowInfo;
        CefBrowserSettings browserSettings;

        browserSettings.webgl = STATE_ENABLED;
        browserSettings.file_access_from_file_urls = STATE_ENABLED;
        browserSettings.universal_access_from_file_urls = STATE_ENABLED;

        windowInfo.width = width;
        windowInfo.height = height;        
        windowInfo.transparent_painting_enabled = 1;

        Graphics* graphics = webClient_->GetSubsystem<Graphics>();

        if (graphics)
        {
            SDL_Window* sdlWindow = static_cast<SDL_Window*>(graphics->GetSDLWindow());
            SDL_SysWMinfo info;
            SDL_VERSION(&info.version);

            if(SDL_GetWindowWMInfo(sdlWindow, &info))
            {
#ifdef ATOMIC_PLATFORM_OSX
                NSView* view = (NSView*) GetNSWindowContentView(info.info.cocoa.window);
                windowInfo.SetAsWindowless(view, false);
#endif

#ifdef ATOMIC_PLATFORM_WINDOWS
                windowInfo.SetAsWindowless(info.info.win.window, /*transparent*/ true);
#endif
            }

        }
        else
        {
#ifndef ATOMIC_PLATFORM_LINUX
            // headless
            windowInfo.SetAsWindowless(nullptr, true);
#endif
        }

        // TODO: There seems to be a CEF bug when loading a string into a browser
        // which was created with an empty URL, this workaround gets things going
        // NOTE: I also tried loading the string, delaying 5 seconds and still won't
        // load a string until a URL has been passed into the view
        String _initialURL = initialLoadString_.Length() ? "x" : initialURL;

        webClient_->renderHandler_->SetSize(width, height);
        CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync(windowInfo, this,
                                                                          _initialURL.CString(), browserSettings, nullptr);

        if (!browser.get())
            return false;

        browser_ = browser;

        if (initialLoadString_.Length())
        {
            webClient_->LoadString(initialLoadString_, initialLoadStringURL_);
        }

        return true;


    }
Пример #6
0
HWND WebViewFactory::GetWebView(const HWND& hSameProcessWnd, const HINSTANCE& hInstance, const int& x, const int& y, const int& width,
	const int& height, const CefString& url, const int& alpha, const bool& taskbar, const bool& trans, const int& winCombination)
{
	//std::unique_lock<std::mutex> lock(factoryMutex_);
#ifdef _DEBUG
	char szTmp[8192] = { 0 };
	sprintf_s(szTmp, "------GetWebView   %s", url.ToString().c_str() );
	OutputDebugStringA(szTmp);
#endif
	CefRefPtr<CefBrowser> browser;
	{
		if (hSameProcessWnd && IsWindow(hSameProcessWnd))
		{
			CefRefPtr<WebItem> item = FindItem(hSameProcessWnd);
			if ( item.get() )
			{
				browser = item->getBrowserByHwnd(hSameProcessWnd);
			}
		}
	}

	CefRefPtr<WebItem> item = new  WebItem;
	item->m_handle = new ClientHandler();
	item->m_handle->SetMainWindowHandle(NULL);
	CefRefPtr<BrowserProvider> provider = new BrowserProvider(item->m_handle);
	
	CefBrowserSettings browser_settings;
	const bool transparent = trans;
	//cmd_line->HasSwitch(cefclient::kTransparentPaintingEnabled);
	const bool show_update_rect = false;
	RECT rect;

	CefRefPtr<OSRWindow> window =
		OSRWindow::Create(provider, transparent,
		show_update_rect);
	WCHAR szOSRWindowClass[] = L"WebViewWindowClass";
	rect.left = x;
	rect.top = y;
	rect.right = x + width;
	rect.bottom = y + height;
	window->CreateWidget(NULL, rect, hInstance, szOSRWindowClass, trans, winCombination);
	assert(IsWindow(window->hwnd()));
	bool bTest = item->m_window_map.insert(std::make_pair(window->hwnd(), window)).second;
	assert(bTest == true);

	CefWindowInfo info;
	info.SetAsWindowless(window->hwnd(), transparent);
	info.transparent_painting_enabled = trans; //是否需要?
	info.windowless_rendering_enabled = true;
	//item->m_handle->SetOSRHandler(window.get());
	if ( !taskbar )
	{
		DWORD exStyle = GetWindowLong(window->hwnd(), GWL_EXSTYLE);
		exStyle &= ~WS_EX_APPWINDOW;
		exStyle |= WS_EX_TOOLWINDOW;
		SetWindowLong(window->hwnd(), GWL_EXSTYLE, exStyle);
		SetWindowPos(window->hwnd(), NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
	}
	window->SetAlpha(alpha);
	//ShowWindow(window->hwnd(), SW_SHOW);

	//browser_settings.file_access_from_file_urls = STATE_ENABLED;
	browser_settings.universal_access_from_file_urls = STATE_ENABLED; //让xpack访问本地文件
	//browser_settings.web_security = STATE_DISABLED; //网页安全
	//browser_settings.webgl = STATE_DISABLED;
	//browser_settings.plugins = STATE_DISABLED;
	//browser_settings.java = STATE_DISABLED;
	//browser_settings.application_cache = STATE_DISABLED; //不用缓存
	// Creat the new child browser window

	//CefRequestContextSettings settings;
	//CefString(&settings.cache_path) = CefString(g_strGlobalCachePath.c_str());
	/*if (!shared_request_context_.get()) {
		shared_request_context_ =
			CefRequestContext::CreateContext(CefRequestContext::GetGlobalContext(),
			new ClientRequestContextHandler);
	}*/

	/*if ( m_requestContextHandler.get() == NULL )
	{
		m_requestContextHandler = new RequestContextHandlerPath(g_strGlobalCachePath.c_str());
	}
	CefRefPtr<CefRequestContext> request_context = CefRequestContext::CreateContext(settings, m_requestContextHandler);*/


	m_viewList.push_back(item);
	if ( browser.get() )
	{
		CefBrowserHost::CreateInheritBrowser(browser, info, item->m_handle,
			url, browser_settings, CookiesManage::getInst().getShareRequest() );
	}
	else{
		CefBrowserHost::CreateBrowser(info, item->m_handle,
			url, browser_settings, CookiesManage::getInst().getShareRequest());
	}
	//WCHAR szBuf[] = { L"D:\\work\\WebUIDemo\\bin\\Release\\uiframe\\PepperFlash1\\pepflashplayer.dll;application/x-shockwave-flash" };
	//item->m_provider->GetBrowser()->RegPlugin(szBuf, true);
	return window->hwnd();
}