Esempio n. 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 );
}
Esempio n. 2
0
void AddWebView(CefWindowHandle parent, RECT windowRect, char* url, Settings* settings) {
  CefWindowInfo windowInfo;
  windowInfo.SetAsChild(parent, windowRect);
  windowInfo.SetTransparentPainting(true);
  g_handler->browserSettings_.web_security_disabled = settings->getBoolean("disableSecurity", false);
  CefBrowser::CreateBrowser(windowInfo, static_cast<CefRefPtr<CefClient>>(g_handler), url, g_handler->browserSettings_);
}
Esempio n. 3
0
bool QCefWebView::CreateBrowser(const QSize& size) {
    //qDebug() << __FUNCTION__ << __LINE__;
    if (browser_state_ != kNone || size.isEmpty()) {
        return false;
    }
    mutex_.lock();
    if (browser_state_ != kNone) {
        mutex_.unlock();
        return false;
    }
    //qDebug() << __FUNCTION__ << __LINE__;
    RECT rect;
    rect.left = 0;
    rect.top = 0;
    rect.right = size.width();
    rect.bottom = size.height();
    CefWindowInfo info;
    CefBrowserSettings settings;
    info.SetAsChild((HWND) this->winId(), rect);
    qcef_client_handler->set_listener(this);
    QString url = url_.isEmpty() ? kUrlBlank : url_.toString();
    CefBrowserHost::CreateBrowser(info,
                                  qcef_client_handler.get(),
                                  CefString(url.toStdWString()),
                                  settings,
                                  NULL);

    browser_state_ = kCreating;
    mutex_.unlock();
    return true;
}
Esempio n. 4
0
int CefJamCEFHtmlView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  Add your specialized creation code here


    CRect rcClient;
    this->GetClientRect(&rcClient);

    // TODO:  Add your specialized creation code here
    CefRefPtr<CefJamClientHandler> client(new CefJamClientHandler());
    m_pClientHandler = client;

    CefWindowInfo info;
    info.SetAsChild( m_hWnd, rcClient);

    CefBrowserSettings browserSettings;

    //static_cast<CefRefPtr<CefClient> >(client)
    bool bCreate = CefBrowserHost::CreateBrowser( info,static_cast<CefRefPtr<CefClient> >(client),
                   "http://www.baidu.com", browserSettings);

    return 0;
}
Esempio n. 5
0
NPError NPP_SetWindowImpl(NPP instance, NPWindow* window_info) {
  if (instance == NULL)
    return NPERR_INVALID_INSTANCE_ERROR;

  if (window_info == NULL)
    return NPERR_GENERIC_ERROR;

  ClientPlugin* plugin = reinterpret_cast<ClientPlugin*>(instance->pdata);
  HWND parent_hwnd = reinterpret_cast<HWND>(window_info->window);

  if (plugin->hWnd == NULL) {
    WNDCLASS wc;
    HINSTANCE hInstance = GetModuleHandle(NULL);

    // Register the window class.
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = PluginWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = L"ClientOSRPlugin";
    RegisterClass(&wc);

    // Create the main window.
    plugin->hWnd = CreateWindow(L"ClientOSRPlugin", L"Client OSR Plugin",
        WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, 0, 0, 0, 0, parent_hwnd, NULL,
        hInstance, NULL);

    SetWindowLongPtr(plugin->hWnd, GWLP_USERDATA,
        reinterpret_cast<LONG_PTR>(plugin));

    // Enable GL drawing for the window.
    EnableGL(plugin->hWnd, &(plugin->hDC), &(plugin->hRC));

    // Create the off-screen rendering window.
    CefWindowInfo windowInfo;
    CefBrowserSettings settings;
    windowInfo.SetAsOffScreen(plugin->hWnd);
    if (g_offscreenTransparent)
      windowInfo.SetTransparentPainting(TRUE);
    CefBrowser::CreateBrowser(windowInfo, new ClientOSRHandler(plugin),
        "http://www.google.com", settings);
  }

  // Position the plugin window and make sure it's visible.
  RECT parent_rect;
  GetClientRect(parent_hwnd, &parent_rect);
  SetWindowPos(plugin->hWnd, NULL, parent_rect.left, parent_rect.top,
      parent_rect.right - parent_rect.left,
      parent_rect.bottom - parent_rect.top, SWP_SHOWWINDOW);

  UpdateWindow(plugin->hWnd);
  ShowWindow(plugin->hWnd, SW_SHOW);

  return NPERR_NO_ERROR;
}
Esempio n. 6
0
TSharedPtr<IWebBrowserWindow> FWebBrowserSingleton::CreateBrowserWindow(void* OSWindowHandle, FString InitialURL, uint32 Width, uint32 Height, bool bUseTransparency, TOptional<FString> ContentsToLoad, bool ShowErrorMessage)
{
#if WITH_CEF3
	// Create new window
	TSharedPtr<FWebBrowserWindow> NewWindow(new FWebBrowserWindow(FIntPoint(Width, Height), InitialURL, ContentsToLoad, ShowErrorMessage));

	// 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.SetAsOffScreen(WindowHandle);
	WindowInfo.SetTransparentPainting(bUseTransparency);

	// Specify CEF browser settings here.
	CefBrowserSettings BrowserSettings;

	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;
}
// WM_CREATE handler
BOOL cef_main_window::HandleCreate() 
{
    // Create the single static handler class instance
    g_handler = new ClientHandler();
    g_handler->SetMainHwnd(mWnd);

    RECT rect;

    GetCefBrowserRect(rect);

    CefWindowInfo info;
    CefBrowserSettings settings;

    settings.web_security = STATE_DISABLED;

    // Initialize window info to the defaults for a child window
    info.SetAsChild(mWnd, rect);

    // Creat the new child browser window
    CefBrowserHost::CreateBrowser(info,
        static_cast<CefRefPtr<CefClient> >(g_handler),
        ::AppGetInitialURL(), settings);

    return TRUE;
}
Esempio n. 8
0
	void __showDev(HWND hWnd){
		BrowserWindowInfo * bw = getBrowserWindowInfo(hWnd);
		if (bw != NULL){
			CefWindowInfo windowInfo;
			windowInfo.SetAsPopup(NULL, "cef_debug");
			bw->browser->GetHost()->ShowDevTools(windowInfo, new DEBUG_Handler(), CefBrowserSettings(), CefPoint());
		}
	}
void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser) {
  CefWindowInfo windowInfo;
  CefBrowserSettings settings;

#if defined(OS_WIN)
  windowInfo.SetAsPopup(browser->GetHost()->GetWindowHandle(), "DevTools");
#endif

  browser->GetHost()->ShowDevTools(windowInfo, this, settings);
}
Esempio n. 10
0
int CTransChatWebWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!theApp.GetWindowManager()->Attach(GetSafeHwnd(), _T("trans_chat_web_wnd")))
		return -1;
	
	SetWindowText(_T("专人翻译"));

	g_SessionData.chat_hwnd = GetSafeHwnd();

	m_shadow_win.create(GetSafeHwnd());

	m_Recorder.Attach(GetSafeHwnd());

	//m_pV8Exthandler = new ClientV8ExtHandler(this);

	CefRefPtr<CefWebClient> client(new CefWebClient());
	m_cWebClient = client;

	CefSettings cSettings;
	CefSettingsTraits::init(&cSettings);
	cSettings.multi_threaded_message_loop = true;
	CefRefPtr<CefApp> spApp;
	CefInitialize(cSettings, spApp);

	//CefRegisterExtension("v8/Ext", s_JsExt, m_pV8Exthandler);

	duHwndObj* pWebHwndobj = (duHwndObj*)GetPluginByName(GetSafeHwnd(), _T("chat_web_hwndobj"));
	RECT rc = { 0, 0, 0, 0 };
	pWebHwndobj->GetRect(&rc);
	CefWindowInfo info;
	info.SetAsChild(GetSafeHwnd(), rc);

	TCHAR szHtml[MAX_PATH] = { 0 };
	::GetModuleFileName(GetModuleHandle(NULL), szHtml, _countof(szHtml));
	::PathRemoveFileSpec(szHtml);
	::PathAppend(szHtml, _T("html\\trans.html"));

	CefBrowserSettings browserSettings;
	CefBrowser::CreateBrowser(info, static_cast<CefRefPtr<CefClient>>(client),
		szHtml, browserSettings);

	InitExtension();
	//RunExtensionTest(m_cWebClient->GetBrowser());

	//pWebHwndobj->Attach(m_cWebClient->GetBrowser()->GetWindowHandle());

	//m_Recorder.StartRecord();
	
	//StrCpy(m_szVoicePath, _T("C:\\Users\\Administrator\\AppData\\Roaming\\MyEcho\\oDHO7Q3LRUtxLg4E9R1adjrsv5irzYa8\\task\\test.amr"));

	return 0;
}
Esempio n. 11
0
bool WindowlessBoltBrowser::Create( HWND hHostWnd )
{
	assert(hHostWnd);
	assert(::IsWindow(hHostWnd));

	CefWindowInfo info;
	info.SetAsOffScreen(hHostWnd);
	info.SetTransparentPainting(m_transparent? TRUE : FALSE);
	
	return BaseBoltBrowser::Create(info);
}
Esempio n. 12
0
inline void ShowDevTools(CWebClient * pthis, CefRefPtr<CefBrowser> browser,
	const CefPoint& inspect_element_at) {
	CefWindowInfo windowInfo;
	CefBrowserSettings settings;

#if defined(OS_WIN)
	windowInfo.SetAsPopup(browser->GetHost()->GetWindowHandle(), "DevTools");
#endif

	browser->GetHost()->ShowDevTools(windowInfo, pthis, settings,
		inspect_element_at);
}
Esempio n. 13
0
bool ShowDevTools(CefRefPtr<CefBrowser> browser) {
    CefWindowInfo windowInfo;
    CefBrowserSettings settings;

    #if defined(OS_WIN)
    windowInfo.SetAsPopup(browser->GetHost()->GetWindowHandle(), "DevTools");
    #endif

    browser->GetHost()->ShowDevTools(windowInfo, browser->GetHost()->GetClient(),
                                     settings, CefPoint());
    return true;
}
Esempio n. 14
0
void Client::showDevTools( CefRefPtr<CefBrowser> browser )
{
  std::stringstream ss;
  ss << "showDevTools, id=" << browser->GetIdentifier();
  HL_DEBUG(logger, ss.str());
  CefWindowInfo windowInfo;
  CefBrowserSettings settings;

#if defined(OS_WIN)
  windowInfo.SetAsPopup(browser->GetHost()->GetWindowHandle(), "DevTools");
#endif

  browser->GetHost()->ShowDevTools(windowInfo, this, settings, CefPoint());
}
Esempio n. 15
0
void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser) {
  CefWindowInfo info;
  CefBrowserSettings settings;

  // Initialize window info to the defaults for a popup window
  info.SetAsPopup(NULL, "TransparentPopup");
  info.SetTransparentPainting(TRUE);
  info.m_nWidth = 500;
  info.m_nHeight = 500;

  // Creat the popup browser window
  CefBrowser::CreateBrowser(info,
      static_cast<CefRefPtr<CefClient> >(g_handler),
      "http://tests/transparency", settings);
}
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;
}
Esempio n. 17
0
void CefFacade::CreateBrowser(HWND Parent_,const char* startUrl_,pFun pFn_)
{	
	m_clientHandler = new ClientHandler(pFn_); 

	CefWindowInfo info;  
	CefBrowserSettings b_settings;  

	RECT rect;
	GetClientRect(Parent_,&rect);
	info.SetAsChild(Parent_, rect);  

	if(strlen(startUrl_)==0)
		m_StartupURL="about://blank";
	else
		m_StartupURL = string_To_UTF8(startUrl_);
	CefBrowserHost::CreateBrowser(info, m_clientHandler.get(), m_StartupURL, b_settings, NULL);
}
Esempio n. 18
0
	void __stdcall CreateBrowser(HWND Parent_,const char* startUrl_=NULL)
	{
		s_clientHandler = new ClientHandler(NULL); 

		CefWindowInfo info;  
		CefBrowserSettings b_settings;  

		RECT rect;
		GetClientRect(Parent_,&rect);
		info.SetAsChild(Parent_, rect);  
		
		std::string m_StartupURL;
		if(strlen(startUrl_)==0)
			m_StartupURL="about://blank";
		else
			m_StartupURL = string_To_UTF8(startUrl_);
		CefBrowserHost::CreateBrowser(info, s_clientHandler.get(), m_StartupURL, b_settings, NULL);
	}
Esempio n. 19
0
//Create the browser in our previously created window with hWnd handle
//and the url to load. This function must be called in WM_CREATE
void SimpleCEFDLL_CreateBrowser( HWND hWnd, const wchar_t* url )
{
	CefRefPtr<zSimpleCefHandler> simpleCefHandler = new zSimpleCefHandler;

	g_App->SetCEFHandler( hWnd, simpleCefHandler );

	//We fill the info to adapt our window to embedd the browser
	CefWindowInfo info;

	//Get the window rect
	RECT rect;
	GetClientRect( hWnd, &rect);
	
	//We will create the browser as a child of our window
	info.SetAsChild( hWnd,rect);

	CefBrowserSettings settingsBrowser;
    CefBrowserHost::CreateBrowser(info, simpleCefHandler.get(), CefString( url ), settingsBrowser, NULL);
}
Esempio n. 20
0
CefRefPtr< CefBrowser > ClientAppCreateBrowser(std::shared_ptr<ofxCEFBrowser> ofx, std::string startResource) {
	// OSR Browser =======================================================
	CefBrowserSettings settings;

	// Create the single static handler class instance
	HWND hWnd = WindowFromDC(wglGetCurrentDC());
	
	CefWindowInfo info;
	info.width = ofx->getWidth();
	info.height = ofx->getHeight();
	info.SetAsOffScreen(hWnd);
	info.SetTransparentPainting(true);
	//info.SetAsChild(hWnd, rect); 
	//info.SetAsPopup(hWnd, "hehe"); 

	// Create the new child browser window using an offscreen window
	auto browser =  CefBrowserHost::CreateBrowserSync(info, ofx->getClientHandler().get(), CefString(startResource), settings);

	return browser;
}
Esempio n. 21
0
value cef_init()
{
	CefSettings settings;
	CefMainArgs args;
	settings.multi_threaded_message_loop = true;
	printf("before init\n");
	CefInitialize(args, settings, NULL);
	printf("after init\n");
	
	HWND hWnd;
	RECT rect;

	// Init First Chrome
	CefBrowserSettings browserSettings;
	CefWindowInfo info;

	g_handler = new myClientHandler();
	DWORD dwProcID = GetCurrentProcessId();
	hWnd = GetTopWindow(GetDesktopWindow());
	while(hWnd)
    {
		DWORD dwWndProcID = 0;
		GetWindowThreadProcessId(hWnd, &dwWndProcID);
		if(dwWndProcID == dwProcID)
			break; 
		hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);
    }
	
	printf("hwnd %d\n", hWnd);

	GetClientRect(hWnd, &rect);
	printf("before client rect\n");
	info.SetAsChild(hWnd,rect);
	printf("set as child\n");

	CefBrowserHost::CreateBrowser(info,static_cast< CefRefPtr<CefClient> >(g_handler),"http://www.google.com", browserSettings);
	printf("create browser\n");
	
	return alloc_null();
}
Esempio n. 22
0
void BrowserClient::initBrowser(const std::string& url)
{
    //Setup our main view that will show the cef ui
    setupMainView( _width, _height );
    _viewer->addView( _mainView );

    {
        CefWindowInfo windowInfo;
        CefBrowserSettings browserSettings;

        // in linux set a gtk widget, in windows a hwnd. If not available set nullptr - may cause some render errors, in context-menu and plugins.
        windowInfo.SetAsOffScreen(0L);
        windowInfo.SetTransparentPainting(true);
        //windowInfo.SetAsWindowless(0L, true);

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

    addExecuteCallback(new MapExecuteCallback(this));
    _mainView->addEventHandler(new BrowserEventHandler(_mainView.get(), this, _browser));
}
Esempio n. 23
0
void CCEFView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

    CefRefPtr<ClientHandler> client(new ClientHandler());
	m_clientHandler = client;

    CefWindowInfo info;
	RECT rect;
	GetClientRect(&rect);
	info.SetAsChild(GetSafeHwnd(), rect);

	CefBrowserSettings browserSettings;
  browserSettings.web_security_disabled = true;

	char path_buffer[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	errno_t err;
	GetModuleFileNameA(NULL, path_buffer, sizeof(path_buffer));
	err = _splitpath_s(path_buffer, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
	if (err != 0)
	{
		//TODO: Add Error Handler
	}
	std::string s = dir;
	s += "html";
	err = _makepath_s(path_buffer, _MAX_PATH, drive, s.c_str(), "index", "html");
	if (err != 0)
	{
		//TODO: Add Error Handler
	}
	CefBrowser::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(client), path_buffer, browserSettings); 

	// TODO: Add your specialized code here and/or call the base class
}
Esempio n. 24
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; 
}
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);
}
Esempio n. 26
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

#ifdef SHOW_TOOLBAR_UI
  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }
    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else
#endif // SHOW_TOOLBAR_UI
  {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

#ifdef SHOW_TOOLBAR_UI
      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;
#endif // SHOW_TOOLBAR_UI

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      settings.file_access_from_file_urls_allowed = true;
      settings.universal_access_from_file_urls_allowed = true;

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info,
          static_cast<CefRefPtr<CefClient> >(g_handler),
          szInitialUrl, settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_EXIT:
        if (g_handler.get()) {
          g_handler->QuittingApp(true);
    	  g_handler->DispatchCloseToNextBrowser();
    	} else {
          DestroyWindow(hWnd);
		}
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
/*
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
*/
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
#ifdef SHOW_TOOLBAR_UI
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
#endif // SHOW_TOOLBAR_UI
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
#ifdef SHOW_TOOLBAR_UI
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;
#endif // SHOW_TOOLBAR_UI

          HDWP hdwp = BeginDeferWindowPos(1);
#ifdef SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
#endif // SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {

        HWND hWnd = GetActiveWindow();
        SaveWindowRect(hWnd);

        // If we already initiated the browser closing, then let default window proc handle it.
        HWND browserHwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        HANDLE closing = GetProp(browserHwnd, CLOSING_PROP);
        if (closing) {
		    RemoveProp(browserHwnd, CLOSING_PROP);
			break;
		}

        g_handler->QuittingApp(true);
        g_handler->DispatchCloseToNextBrowser();
        return 0;
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Esempio n. 27
0
//
//  FUNCTION: MainWindowWndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK MainWindowWndProc(
    HWND hWnd, 
    UINT message, 
    WPARAM wParam,
    LPARAM lParam) 
{
    PAINTSTRUCT ps;
    HDC hdc;
    HMENU sysMenu;

    // Callback for the main window
    switch (message) 
    {
        case WM_CREATE: 
        {
            DWORD bufferSize = 65535;
            wstring buff;
            buff.resize(bufferSize);
            bufferSize = ::GetEnvironmentVariable(L"lala", &buff[0], bufferSize);

            if (bufferSize)
            {
                buff.resize(bufferSize);
                SetEnvironmentVariable(L"lala", NULL);
            }

            // Add exit option to system menu
            TCHAR szDescription[INFOTIPSIZE];
            StringManager.LoadString(IDS_EXIT_CAFFEINE, szDescription, INFOTIPSIZE);

            sysMenu = GetSystemMenu(hWnd, FALSE);
            InsertMenu(sysMenu, 2, MF_SEPARATOR, 0, L"-");
            AppendMenu(sysMenu, MF_STRING, IDS_EXIT_CAFFEINE, szDescription);

            WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION);
            app->m_WindowHandler[mainUUID] = new CaffeineClientHandler();
            app->m_WindowHandler[mainUUID]->SetMainHwnd(hWnd);

            // Create the child windows used for navigation
            RECT rect;

            GetClientRect(hWnd, &rect);

            CefWindowInfo info;
            CefBrowserSettings browser_settings;
            browser_settings.universal_access_from_file_urls = STATE_ENABLED;
//            browser_settings.file_access_from_file_urls = STATE_ENABLED;
            browser_settings.web_security = STATE_DISABLED;
            browser_settings.local_storage = STATE_ENABLED;
            browser_settings.application_cache = STATE_DISABLED;
            browser_settings.javascript_open_windows = STATE_DISABLED;
//            browser_settings.accelerated_compositing = STATE_DISABLED;
            
            // Initialize window info to the defaults for a child window
            info.SetAsChild(hWnd, rect);

            // Create the new child browser window
            wstring URL(L"file:///stub.html?" + AppGetCommandLine()->GetSwitchValue("querystring").ToWString());
            if (AppGetCommandLine()->HasSwitch("yid"))
            {
                URL += L"&yid=" + ExtractYID(AppGetCommandLine()->GetSwitchValue("yid").ToWString());
            }
            //  TODO:  Can we just use the same window handler (assuming we get rid of the globals and add some sync)?
            CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync(info, app->m_WindowHandler[mainUUID].get(), URL, browser_settings, NULL);
            app->m_WindowHandler[mainUUID]->m_MainBrowser = browser;
            mainWinBrowser = browser;

            app->hwndRender = hWnd; // setup current handle to use in Show/HideWindow
        
            CefRefPtr<CefProcessMessage> process_message = CefProcessMessage::Create("setHandle");
            process_message->GetArgumentList()->SetInt(0, reinterpret_cast<int>(hWnd));
            browser->SendProcessMessage(PID_RENDERER, process_message);

            // Send the main window creation start time to the renderer
            process_message = CefProcessMessage::Create("mainWindowCreationTime");
            CefRefPtr<CefBinaryValue> startTime = CefBinaryValue::Create(&beginMainWindowCreationTime, sizeof(CefTime));
            process_message->GetArgumentList()->SetBinary(0, startTime);
            browser->SendProcessMessage(PID_RENDERER, process_message);

            if (bufferSize)
            {
                process_message = CefProcessMessage::Create("lala");
                process_message->GetArgumentList()->SetString(0, buff);
                browser->SendProcessMessage(PID_RENDERER, process_message);
            }

            SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(new WindowExtras));

            SetTimer(hWnd, IDLETIMER, IdleTimerPollIntervalMS, NULL);
            SetTimer(hWnd, NETWORKTIMER, NetworkTimerPollIntervalMS, NULL);

            return 0;
        }

        case WM_MOVE:
            if (app->m_WindowHandler[mainUUID].get())
            {
                //  TODO:  Below is a hack to work around the fact that CEF isn't updating screenX and screenY.  Periodically,
                //  TODO:  check to see if they fix it.  
                //  TODO:  See issue https://code.google.com/p/chromiumembedded/issues/detail?id=1303&thanks=1303&ts=1402082749
                WINDOWINFO wi = {sizeof(WINDOWINFO), 0};
                GetWindowInfo(hWnd, &wi);
                RECT rClient = wi.rcWindow;

                CefString JS = "window.screenLeft = window.screenX = " + to_string(_Longlong(rClient.left)) + "; window.screenTop = window.screenY = " + 
                    to_string(_Longlong(rClient.top)) + ";";
                CefRefPtr<CefFrame> frame = app->m_WindowHandler[mainUUID]->GetBrowser()->GetMainFrame();
                frame->ExecuteJavaScript(JS, frame->GetURL(), 0);

                //  TODO:  Another workaround.  For whatever reason, the window positions get updated when the size changes,
                //  TODO:  but not when the window is moved.
                CefWindowHandle hwnd = app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                if (hwnd) 
                {
                    wi.cbSize = sizeof(WINDOWINFO);
                    GetWindowInfo(hwnd, &wi);
                    RECT rWindow = wi.rcWindow;

                    MoveWindow(hwnd, 0, 0, rWindow.right - rWindow.left, rWindow.bottom - rWindow.top + 1, FALSE);
                    MoveWindow(hwnd, 0, 0, rWindow.right - rWindow.left, rWindow.bottom - rWindow.top, FALSE);
                }

                app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent("move");
            }

            break;

        case WM_POWERBROADCAST:
            if (app->m_WindowHandler[mainUUID].get())
            {
                if (wParam == PBT_APMRESUMEAUTOMATIC || wParam == PBT_APMSUSPEND)
                {
                    app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(wParam == PBT_APMSUSPEND? "suspend" : "resume");
                    //  Do we really need a return value?
                    return TRUE;
                }
            }
            break;

        case WM_WTSSESSION_CHANGE:
            if (app->m_WindowHandler[mainUUID].get())
            {
                string eventName;

                switch(wParam)
                {
                    //  Used
                    case WTS_SESSION_LOGON:
                        eventName = "os:logon";
                        break;
                    //  Used
                    case WTS_SESSION_LOGOFF:
                        eventName = "os:logoff";
                        break;
                    //  Used
                    case WTS_SESSION_LOCK:
                        eventName = "os:locked";
                        break;
                    //  Used
                    case WTS_SESSION_UNLOCK:
                        eventName = "os:unlocked";
                        break;
                }

                app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(eventName);
            }
            break;

        case WM_PAINT:
            {
                //RECT cr = {0,};
                //::GetClientRect(hWnd, &cr);
                //::InvalidateRect(hWnd, &cr, FALSE);
                hdc = BeginPaint(hWnd, &ps);
                EndPaint(hWnd, &ps);
                return 0;
            }

        case WM_ACTIVATE:
            if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) 
            {
                app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent((LOWORD(wParam)>0)? "activated" : "deactivated");
            }
            break;
        case WM_SETFOCUS:
            if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) 
            {
                // Pass focus to the browser window
                CefWindowHandle hwnd = app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                if (hwnd) PostMessage(hwnd, message, wParam, lParam);
            }
            return 0;

        case WM_SIZE:
            // Minimizing resizes the window to 0x0 which causes our layout to go all
            // screwy, so we just ignore it.
            if (wParam != SIZE_MINIMIZED && app->m_WindowHandler[mainUUID].get() && 
                app->m_WindowHandler[mainUUID]->GetBrowser()) 
            {
                    CefWindowHandle hwnd = app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                    if (hwnd) 
                    {
                        //  This will send a WM_SIZE and WM_PAINT message to the render process
                        SetWindowPos(hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); 
                        return 0;
                    }
            }
            break;

        case WM_ERASEBKGND:
            if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) {
                CefWindowHandle hwnd =
                    app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                if (hwnd) {
                    // Dont erase the background if the browser window has been loaded
                    // (this avoids flashing)
                    return 0;
                }
            }
            break;

        case WM_SYSCOMMAND:
            if (wParam == IDS_EXIT_CAFFEINE) {
                PostMessage(hWnd, WM_CLOSE, g_exitCode, 0);
                return 0;
            }
            break;

        case WM_COMMAND:
            // Currently only option from the context menu is to exit, hence the fall through to the WM_CLOSE
            wParam = g_exitCode;

        case WM_CLOSE:
        {
            if (devMode || enableClose)
            {
                wParam = g_exitCode;
            }

            CefRefPtr<CaffeineClientHandler> handler = app->m_WindowHandler[mainUUID].get();

            if (handler && !handler->IsClosing()) {
                if (wParam == g_exitCode) // Jump list exit
                {
                    for (map<string, CefRefPtr<CaffeineClientHandler> >::iterator it=app->m_WindowHandler.begin(); it!=app->m_WindowHandler.end(); ++it)
                    {
                        if(it->second.get()) 
                        {
                            CefRefPtr<CefBrowser> browser = it->second->GetBrowser();
                            browser->GetHost()->CloseBrowser(false);
                        }
                    }

					//CefRefPtr<CefBrowser> browser = handler->GetBrowser();
					//if (browser.get()) {
					//	browser->GetHost()->CloseBrowser(false);
					//}
				} else {
                    ShowWindow(hWnd, SW_MINIMIZE);
                }
                return 0;
            }

            break;
        }

        case WM_TIMER:
        {
            if(IDLETIMER == wParam)
            {
                //  TODO:  Check timer id
                LASTINPUTINFO lif = {sizeof(LASTINPUTINFO), 0};
                GetLastInputInfo(&lif);
                UINT IdleTimePassed = GetTickCount() - lif.dwTime;
                
                WindowExtras *pWE = reinterpret_cast<WindowExtras *>(::GetWindowLongPtr(hWnd, 0));
                bool CurrentlyIdle = (pWE->IdleTimeThreshold < IdleTimePassed);
                if(CurrentlyIdle != pWE->IsIdle)
                {
                    const CefString EventName = (CurrentlyIdle? "startIdle" : "stopIdle");
                    pWE->IsIdle = CurrentlyIdle;
                    app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(EventName);
                }
            }
            //  TODO:  When we drop XP support, we can use COM and get network connectivity events.
            else if(NETWORKTIMER == wParam)
            {
                WindowExtras *pWE = reinterpret_cast<WindowExtras *>(::GetWindowLongPtr(hWnd, 0));
                bool CurrentlyConnected = pWE->NetworkAvailable();
                if(CurrentlyConnected != pWE->IsConnected)
                {
                    const CefString EventName = (CurrentlyConnected? "os:online" : "os:offline");
                    pWE->IsConnected = CurrentlyConnected;
                    app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(EventName);
                }
            }
            break;
        }

        case WM_DESTROY:
        {
            WTSUnRegisterSessionNotification(hWnd);
            // The frame window has exited

            if (!devMode)
            {
                jumpList.RemoveAllTasks();
            }

            KillTimer(hWnd, IDLETIMER);
            KillTimer(hWnd, NETWORKTIMER);
            WindowExtras *pWE = reinterpret_cast<WindowExtras *>(::GetWindowLongPtr(hWnd, 0));
            delete pWE;
            SetWindowLongPtr(hWnd, 0, 0);
            SetShutdownFlag(true);
            PostQuitMessage(0);
            return 0;
        }

        case WM_GETMINMAXINFO:
        {
            LPMINMAXINFO minmaxInfoPtr = (LPMINMAXINFO) lParam;
            minmaxInfoPtr->ptMinTrackSize.x = MAIN_WINDOW_MIN_WIN_WIDTH;
            minmaxInfoPtr->ptMinTrackSize.y = MAIN_WINDOW_MIN_WIN_HEIGHT;

            // Keep the width the same
            RECT rect;
            GetWindowRect(hWnd, &rect);
            minmaxInfoPtr->ptMaxSize.x = (rect.right - rect.left);

            // Keep window at same position
            minmaxInfoPtr->ptMaxPosition.x = rect.left;
            minmaxInfoPtr->ptMaxPosition.y = 0;

            SystemParametersInfo( SPI_GETWORKAREA, 0, &rect, 0 );
            minmaxInfoPtr->ptMaxSize.y = (rect.bottom - rect.top);

            return 0;
        }

        case WM_COPYDATA:
        {
            BOOL retval = FALSE;
            PCOPYDATASTRUCT pCds = reinterpret_cast<PCOPYDATASTRUCT>(lParam);
            if (pCds->dwData == WM_PENDING_YID) 
            {
                if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) 
                {
                    CefRefPtr<CefFrame> frame = app->m_WindowHandler[mainUUID]->GetBrowser()->GetMainFrame();
                    wstring code = L"Caffeine.pendingYIDs.push(\"";
                    //  TODO:  Escape this ... otherwise there's an XSS
                    code += static_cast<LPWSTR>(pCds->lpData);
                    code += L"\");";
                    frame->ExecuteJavaScript(code, frame->GetURL(), 0);
                }

                retval = TRUE;
            }
            return retval;
        }

        case CAFFEINE_SOCKETS_MSG:
            CefRefPtr<CefProcessMessage> process_message = CefProcessMessage::Create("invokeSocketMethod");
            process_message->GetArgumentList()->SetInt(0, wParam);
            if (WSAGETSELECTERROR(lParam))
            {
                process_message->GetArgumentList()->SetString(1, "error");
                process_message->GetArgumentList()->SetInt(2, WSAGETSELECTERROR(lParam));
            }
            else
            {
                //  No error
                switch(WSAGETSELECTEVENT(lParam))
                {
                    case FD_CONNECT:
                        process_message->GetArgumentList()->SetString(1, "connect");
                        break;
                    case FD_CLOSE:
                        process_message->GetArgumentList()->SetString(1, "close");
                        break;
                    case FD_READ:
                        process_message->GetArgumentList()->SetString(1, "read");
                        break;
                    case FD_WRITE:
                        process_message->GetArgumentList()->SetString(1, "write");
                        break;
                }
            }
            mainWinBrowser->SendProcessMessage(PID_RENDERER, process_message);
            break;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}
Esempio n. 28
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }

    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info, g_handler.get(),
          g_handler->GetStartupURL(), settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        return 0;
      case IDM_EXIT:
        DestroyWindow(hWnd);
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
      case ID_TESTS_GETSOURCE:  // Test the GetSource function
        if (browser.get())
          RunGetSourceTest(browser);
        return 0;
      case ID_TESTS_GETTEXT:  // Test the GetText function
        if (browser.get())
          RunGetTextTest(browser);
        return 0;
      case ID_TESTS_POPUP:  // Test a popup window
        if (browser.get())
          RunPopupTest(browser);
        return 0;
      case ID_TESTS_REQUEST:  // Test a request
        if (browser.get())
          RunRequestTest(browser);
        return 0;
      case ID_TESTS_SCHEME_HANDLER:  // Test the scheme handler
        if (browser.get())
          scheme_test::RunTest(browser);
        return 0;
      case ID_TESTS_BINDING:  // Test JavaScript binding
        if (browser.get())
          binding_test::RunTest(browser);
        return 0;
      case ID_TESTS_DIALOGS:  // Test JavaScript dialogs
        if (browser.get())
          RunDialogTest(browser);
        return 0;
      case ID_TESTS_PLUGIN_INFO:  // Test plugin info
        if (browser.get())
          RunPluginInfoTest(browser);
        return 0;
      case ID_TESTS_DOM_ACCESS:  // Test DOM access
        if (browser.get())
          dom_test::RunTest(browser);
        return 0;
      case ID_TESTS_LOCALSTORAGE:  // Test localStorage
        if (browser.get())
          RunLocalStorageTest(browser);
        return 0;
      case ID_TESTS_ACCELERATED2DCANVAS:  // Test accelerated 2d canvas
        if (browser.get())
          RunAccelerated2DCanvasTest(browser);
        return 0;
      case ID_TESTS_ACCELERATEDLAYERS:  // Test accelerated layers
        if (browser.get())
          RunAcceleratedLayersTest(browser);
        return 0;
      case ID_TESTS_WEBGL:  // Test WebGL
        if (browser.get())
          RunWebGLTest(browser);
        return 0;
      case ID_TESTS_HTML5VIDEO:  // Test HTML5 video
        if (browser.get())
          RunHTML5VideoTest(browser);
        return 0;
      case ID_TESTS_XMLHTTPREQUEST:  // Test XMLHttpRequest
        if (browser.get())
          RunXMLHTTPRequestTest(browser);
        return 0;
      case ID_TESTS_DRAGDROP:  // Test drag & drop
        if (browser.get())
          RunDragDropTest(browser);
        return 0;
      case ID_TESTS_GEOLOCATION:  // Test geolocation
        if (browser.get())
          RunGeolocationTest(browser);
        return 0;
      case ID_TESTS_ZOOM_IN:
        if (browser.get())
          ModifyZoom(browser, 0.5);
        return 0;
      case ID_TESTS_ZOOM_OUT:
        if (browser.get())
          ModifyZoom(browser, -0.5);
        return 0;
      case ID_TESTS_ZOOM_RESET:
        if (browser.get())
          browser->GetHost()->SetZoomLevel(0.0);
        return 0;
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;

          HDWP hdwp = BeginDeferWindowPos(1);
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        if (browser.get()) {
          // Let the browser window know we are about to destroy it.
          browser->GetHost()->ParentWindowWillClose();
        }
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Esempio n. 29
0
void Application::createBrowser()
{
    std::string startup_document = _config->startDocument();

    // test if absolute url with http or https
    if(Helper::StringUtils::starts_with(startup_document, "http://") || Helper::StringUtils::starts_with(startup_document, "https://"))
    {
        _startupUrl = startup_document;
    }
    else
    {
        Helper::Path www_dir = _pathManager->getApplicationDir() + "www";
        std::string www_dir_str = www_dir.filePath();
        if(!Helper::StringUtils::starts_with(www_dir_str, "/"))
            www_dir_str = "/" + www_dir_str;
        _startupUrl = "file://" + www_dir_str + "/" + startup_document;
    }




    CefWindowInfo info;
    bool transparent = true;

    //bool offscreenrendering = false;
    //config()->getBoolPreference("OffScreenRendering", offscreenrendering);

    /*
    if(offscreenrendering)
    {
      CefRefPtr<Client::RenderHandler> osr_window = createOSRWindow(_mainWindow, _client.get(), transparent);
      _client->setOSRHandler(osr_window);
      // old
      //info.SetTransparentPainting(transparent ? true : false);
      //info.SetAsOffScreen(osr_window->handle());
      info.SetAsWindowless(osr_window->handle(), transparent);
    }
    else*/
    {
        RECT rect;
        GetClientRect(_mainWindow, &rect);
        info.SetAsChild(_mainWindow, rect);
    }

    /*
    RECT r;
    r.left = 0; r.top = 0; r.right = 700; r.bottom = 500;
    info.SetAsChild(_mainWindow, r);
    */

    //TODO: move the settings into config.xml
    CefBrowserSettings browserSettings;

    //browserSettings.developer_tools = STATE_ENABLED;
    browserSettings.file_access_from_file_urls = STATE_ENABLED;
    browserSettings.universal_access_from_file_urls = STATE_ENABLED;
    browserSettings.web_security = STATE_DISABLED;
    browserSettings.application_cache = STATE_ENABLED;
    browserSettings.local_storage = STATE_ENABLED;
    //browserSettings.accelerated_compositing = STATE_ENABLED; ??

    // init plugin manager (also create the plugins with onload=true)
    _pluginManager->init();

    // Create the browser asynchronously and load the startup url
    HL_DEBUG(logger, "create browser with startup url: '" + _startupUrl + "'");
    CefBrowserHost::CreateBrowser(info, _client.get(), _startupUrl, browserSettings, NULL);
}
Esempio n. 30
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
		  browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }

    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else if (message == uFindMsg) {
    // Find event.
    LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;

    if (lpfr->Flags & FR_DIALOGTERM) {
      // The find dialog box has been dismissed so invalidate the handle and
      // reset the search results.
      hFindDlg = NULL;
      if (g_handler.get()) {
        g_handler->GetBrowser()->StopFinding(true);
        szLastFindWhat[0] = 0;
        findNext = false;
      }
      return 0;
    }

    if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get())  {
      // Search for the requested string.
      bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false);
      if (matchCase != lastMatchCase ||
          (matchCase && wcsncmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) ||
          (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) {
        // The search string has changed, so reset the search results.
        if (szLastFindWhat[0] != 0) {
          g_handler->GetBrowser()->StopFinding(true);
          findNext = false;
        }
        lastMatchCase = matchCase;
		wcscpy(szLastFindWhat, szFindWhat);
        //wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR), szFindWhat);
      }

      g_handler->GetBrowser()->Find(0, lpfr->lpstrFindWhat,
          (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext);
      if (!findNext)
        findNext = true;
    }

    return 0;
  } else {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowser::CreateBrowser(info,
          static_cast<CefRefPtr<CefClient> >(g_handler),
          g_handler->GetStartupURL(), settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        return 0;
      case IDM_EXIT:
        DestroyWindow(hWnd);
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
	    /*
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
		*/
        return 0;
      case ID_FIND:
        if (!hFindDlg) {
          // Create the find dialog.
          ZeroMemory(&fr, sizeof(fr));
          fr.lStructSize = sizeof(fr);
          fr.hwndOwner = hWnd;
          fr.lpstrFindWhat = szFindWhat;
          fr.wFindWhatLen = sizeof(szFindWhat);
          fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN;

          hFindDlg = FindText(&fr);
        } else {
          // Give focus to the existing find dialog.
          ::SetFocus(hFindDlg);
        }
        return 0;
      case ID_PRINT:
        if (browser.get())
          browser->GetMainFrame()->Print();
        return 0;
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
      case ID_TESTS_GETSOURCE:  // Test the GetSource function
        if (browser.get())
          RunGetSourceTest(browser);
        return 0;
      case ID_TESTS_GETTEXT:  // Test the GetText function
        if (browser.get())
          RunGetTextTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_BINDING:  // Test the V8 binding handler
        if (browser.get())
          RunBindingTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_EXTENSION:  // Test the V8 extension handler
        if (browser.get())
          RunExtensionTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_PERFORMANCE:  // Test the V8 performance
        if (browser.get())
          RunExtensionPerfTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_EXECUTE:  // Test execution of javascript
        if (browser.get())
          RunJavaScriptExecuteTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_INVOKE:
        if (browser.get())
          RunJavaScriptInvokeTest(browser);
        return 0;
      case ID_TESTS_PLUGIN:  // Test the custom plugin
        //if (browser.get())
        //  RunPluginTest(browser);
        return 0;
      case ID_TESTS_PLUGIN_INFO:  // Test plugin info
        if (browser.get())
          RunPluginInfoTest(browser);
        return 0;
      case ID_TESTS_POPUP:  // Test a popup window
        if (browser.get())
          RunPopupTest(browser);
        return 0;
      case ID_TESTS_TRANSPARENT_POPUP:  // Test a transparent popup window
        if (browser.get())
          RunTransparentPopupTest(browser);
        return 0;
      case ID_TESTS_REQUEST:  // Test a request
        if (browser.get())
          RunRequestTest(browser);
        return 0;
      case ID_TESTS_SCHEME_HANDLER:  // Test the scheme handler
        if (browser.get())
          RunSchemeTest(browser);
        return 0;
      case ID_TESTS_UIAPP:  // Test the UI app
        //if (browser.get())
        //  RunUIPluginTest(browser);
        return 0;
      case ID_TESTS_OSRAPP:  // Test the OSR app
        //if (browser.get())
        //RunOSRPluginTest(browser, false);
        return 0;
      case ID_TESTS_TRANSPARENT_OSRAPP:  // Test the OSR app with transparency
        //if (browser.get())
        //  RunOSRPluginTest(browser, true);
        return 0;
      case ID_TESTS_DOMACCESS:  // Test DOM access
        if (browser.get())
          RunDOMAccessTest(browser);
        return 0;
      case ID_TESTS_LOCALSTORAGE:  // Test localStorage
        if (browser.get())
          RunLocalStorageTest(browser);
        return 0;
      case ID_TESTS_ACCELERATED2DCANVAS:  // Test accelerated 2d canvas
        if (browser.get())
          RunAccelerated2DCanvasTest(browser);
        return 0;
      case ID_TESTS_ACCELERATEDLAYERS:  // Test accelerated layers
        if (browser.get())
          RunAcceleratedLayersTest(browser);
        return 0;
      case ID_TESTS_WEBGL:  // Test WebGL
        if (browser.get())
          RunWebGLTest(browser);
        return 0;
      case ID_TESTS_DRAGDROP:  // Test drag & drop
        if (browser.get())
          RunDragDropTest(browser);
        return 0;
      case ID_TESTS_GEOLOCATION:  // Test geolocation
        if (browser.get())
          RunGeolocationTest(browser);
        return 0;
      case ID_TESTS_XMLHTTPREQUEST:  // Test XMLHttpRequest
        if (browser.get())
          RunXMLHTTPRequestTest(browser);
        return 0;
      case ID_TESTS_WEBURLREQUEST:
        if (browser.get())
          RunWebURLRequestTest(browser);
        return 0;
      case ID_TESTS_ZOOM_IN:
        if (browser.get())
          browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
        return 0;
      case ID_TESTS_ZOOM_OUT:
        if (browser.get())
          browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
        return 0;
      case ID_TESTS_ZOOM_RESET:
        if (browser.get())
          browser->SetZoomLevel(0.0);
        return 0;
      case ID_TESTS_DEVTOOLS_SHOW:
        if (browser.get())
          browser->ShowDevTools();
        return 0;
      case ID_TESTS_DEVTOOLS_CLOSE:
        if (browser.get())
          browser->CloseDevTools();
        return 0;
      case ID_TESTS_MODALDIALOG:
        if (browser.get())
          RunModalDialogTest(browser);
        return 0;
      case ID_TESTS_GETIMAGE:
        if (browser.get())
          RunGetImageTest(browser);
        return 0;
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Pass focus to the browser window
        PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      if (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Resize the browser window and address bar to match the new frame
        // window size
        RECT rect;
        GetClientRect(hWnd, &rect);
        rect.top += URLBAR_HEIGHT;

        int urloffset = rect.left + BUTTON_WIDTH * 4;

        HDWP hdwp = BeginDeferWindowPos(1);
        hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
          0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
        hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), NULL,
          rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
          SWP_NOZORDER);
        EndDeferWindowPos(hdwp);
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Dont erase the background if the browser window has been loaded
        // (this avoids flashing)
        return 0;
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        if (browser.get()) {
          // Let the browser window know we are about to destroy it.
          browser->ParentWindowWillClose();
        }
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}