diff --git a/libcef/browser/osr/render_widget_host_view_osr.cc b/libcef/browser/osr/render_widget_host_view_osr.cc index e8ed4a401..aa65ab808 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.cc +++ b/libcef/browser/osr/render_widget_host_view_osr.cc @@ -349,6 +349,12 @@ void CefRenderWidgetHostViewOSR::Show() { if (is_showing_) return; + if (!content::GpuDataManagerImpl::GetInstance()->IsGpuCompositingDisabled() && + !browser_impl_ && + (!parent_host_view_ || !parent_host_view_->browser_impl_)) { + return; + } + is_showing_ = true; // If the viz::LocalSurfaceIdAllocation is invalid, we may have been evicted, diff --git a/tests/ceftests/osr_display_unittest.cc b/tests/ceftests/osr_display_unittest.cc index 0fa32ba52..51cdd2284 100644 --- a/tests/ceftests/osr_display_unittest.cc +++ b/tests/ceftests/osr_display_unittest.cc @@ -172,3 +172,222 @@ TEST(OSRTest, NavigateWhileHidden) { handler->ExecuteTest(); ReleaseAndWaitForDestructor(handler); } + +namespace { + +const char kOsrPopupJSOtherClientMainUrl[] = + "http://www.tests-pjse.com/main.html"; + +class OsrPopupJSOtherClientTestHandler : public TestHandler, + public CefRenderHandler { + public: + OsrPopupJSOtherClientTestHandler(CefRefPtr other) { + other_ = other; + } + + virtual CefRefPtr GetRenderHandler() override { + return this; + } + + virtual void GetViewRect(CefRefPtr browser, + CefRect& rect) override { + rect = CefRect(0, 0, kOsrWidth, kOsrHeight); + } + + virtual void OnPaint(CefRefPtr browser, + PaintElementType type, + const RectList& dirtyRects, + const void* buffer, + int width, + int height) override {} + + void RunTest() override { + AddResource(kOsrPopupJSOtherClientMainUrl, "Main", + "text/html"); + + // Create the browser. + CreateOSRBrowser(kOsrPopupJSOtherClientMainUrl); + + // Time out the test after a reasonable period of time. + SetTestTimeout(); + } + + bool OnBeforePopup(CefRefPtr browser, + CefRefPtr frame, + const CefString& target_url, + const CefString& target_frame_name, + cef_window_open_disposition_t target_disposition, + bool user_gesture, + const CefPopupFeatures& popupFeatures, + CefWindowInfo& windowInfo, + CefRefPtr& client, + CefBrowserSettings& settings, + CefRefPtr& extra_info, + bool* no_javascript_access) override { +#if defined(OS_WIN) + windowInfo.SetAsWindowless(GetDesktopWindow()); +#else + windowInfo.SetAsWindowless(kNullWindowHandle); +#endif + + client = other_; + + got_before_popup_.yes(); + return false; + } + + void Close(CefRefPtr browser) { + browser->StopLoad(); + CloseBrowser(browser, true); + } + + void OnAfterCreated(CefRefPtr browser) override { + TestHandler::OnAfterCreated(browser); + if (browser->IsPopup()) { + got_after_created_popup_.yes(); + } + } + + void OnLoadingStateChange(CefRefPtr browser, + bool isLoading, + bool canGoBack, + bool canGoForward) override { + if (isLoading) + return; + + if (browser->IsPopup()) { + got_load_end_popup_.yes(); + CefPostDelayedTask( + TID_UI, + base::Bind(&OsrPopupJSOtherClientTestHandler::Close, this, browser), + 100); + } else { + browser->GetMainFrame()->LoadURL("javascript:window.open('about:blank')"); + } + } + + void OnBeforeClose(CefRefPtr browser) override { + TestHandler::OnBeforeClose(browser); + other_ = nullptr; + if (browser->IsPopup()) { + got_before_close_popup_.yes(); + DestroyTest(); + } + } + + private: + void CreateOSRBrowser(const CefString& url) { + CefWindowInfo windowInfo; + CefBrowserSettings settings; + +#if defined(OS_WIN) + windowInfo.SetAsWindowless(GetDesktopWindow()); +#else + windowInfo.SetAsWindowless(kNullWindowHandle); +#endif + + CefBrowserHost::CreateBrowser(windowInfo, this, url, settings, nullptr, + nullptr); + } + + void DestroyTest() override { + EXPECT_TRUE(got_after_created_popup_); + EXPECT_TRUE(got_load_end_popup_); + EXPECT_TRUE(got_before_close_popup_); + EXPECT_TRUE(got_before_popup_); + TestHandler::DestroyTest(); + } + + TrackCallback got_before_popup_; + TrackCallback got_after_created_popup_; + TrackCallback got_load_end_popup_; + TrackCallback got_before_close_popup_; + CefRefPtr other_; + + IMPLEMENT_REFCOUNTING(OsrPopupJSOtherClientTestHandler); +}; + +class OsrPopupJSOtherCefClient : public CefClient, + public CefLoadHandler, + public CefLifeSpanHandler, + public CefRenderHandler { + public: + OsrPopupJSOtherCefClient() { handler_ = NULL; } + + void SetHandler(CefRefPtr handler) { + handler_ = handler; + } + + virtual CefRefPtr GetLoadHandler() override { return this; } + + virtual CefRefPtr GetRenderHandler() override { + return this; + } + + virtual CefRefPtr GetLifeSpanHandler() override { + return this; + } + + virtual void OnLoadingStateChange(CefRefPtr browser, + bool isLoading, + bool canGoBack, + bool canGoForward) override { + if (handler_) { + handler_->OnLoadingStateChange(browser, isLoading, canGoBack, + canGoForward); + } + } + + virtual void OnAfterCreated(CefRefPtr browser) override { + handler_->OnAfterCreated(browser); + } + + virtual void OnBeforeClose(CefRefPtr browser) override { + handler_->OnBeforeClose(browser); + handler_ = nullptr; + } + + virtual bool OnBeforePopup(CefRefPtr browser, + CefRefPtr frame, + const CefString& target_url, + const CefString& target_frame_name, + cef_window_open_disposition_t target_disposition, + bool user_gesture, + const CefPopupFeatures& popupFeatures, + CefWindowInfo& windowInfo, + CefRefPtr& client, + CefBrowserSettings& settings, + CefRefPtr& extra_info, + bool* no_javascript_access) override { + return true; + } + + virtual void GetViewRect(CefRefPtr browser, + CefRect& rect) override { + rect = CefRect(0, 0, kOsrWidth, kOsrHeight); + } + + virtual void OnPaint(CefRefPtr browser, + PaintElementType type, + const RectList& dirtyRects, + const void* buffer, + int width, + int height) override {} + + private: + CefRefPtr handler_; + + IMPLEMENT_REFCOUNTING(OsrPopupJSOtherCefClient); +}; + +} // namespace + +// Test creation of an OSR-popup with another client. +TEST(OSRTest, OsrPopupJSOtherClient) { + CefRefPtr client = new OsrPopupJSOtherCefClient(); + CefRefPtr handler = + new OsrPopupJSOtherClientTestHandler(client); + client->SetHandler(handler); + handler->ExecuteTest(); + ReleaseAndWaitForDestructor(handler); +} \ No newline at end of file