diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index b5aae4b261dba2..532a502f693445 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -407,6 +407,41 @@ IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationSuccess) { EXPECT_EQ(translate::TranslateErrors::NONE, GetPageTranslatedResult()); } +// Test that the translation was successful in an about:blank page. +// This is a regression test for https://crbug.com/943685. +IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, PageTranslationAboutBlank) { + SetTranslateScript(kTestValidScript); + ResetObserver(); + AddTabAtIndex(0, GURL(embedded_test_server()->GetURL("/french_page.html")), + ui::PAGE_TRANSITION_TYPED); + + // Open a pop-up window and leave it at the initial about:blank URL. + content::WebContentsAddedObserver popup_observer; + ASSERT_TRUE( + content::ExecJs(browser()->tab_strip_model()->GetActiveWebContents(), + "window.open('about:blank', 'popup')")); + content::WebContents* popup = popup_observer.GetWebContents(); + + // A round-trip to the renderer process helps avoid a race where the + // browser-side translate structures are not yet ready for the translate call. + EXPECT_EQ("ping", content::EvalJs(popup, "'ping'")); + + // Translate the about:blank page. + ChromeTranslateClient* chrome_translate_client = + ChromeTranslateClient::FromWebContents(popup); + translate::TranslateManager* manager = + chrome_translate_client->GetTranslateManager(); + manager->TranslatePage("fr", "en", true); + + // Verify that the crash from https://crbug.com/943685 didn't happen. + EXPECT_EQ("still alive", content::EvalJs(popup, "'still alive'")); + + // Wait for translation to finish and verify it was successful. + WaitUntilPageTranslated(); + EXPECT_FALSE(chrome_translate_client->GetLanguageState().translation_error()); + EXPECT_EQ(translate::TranslateErrors::NONE, GetPageTranslatedResult()); +} + // Test that hrefTranslate is propagating properly IN_PROC_BROWSER_TEST_F(TranslateManagerBrowserTest, HrefTranslateSuccess) { ChromeTranslateClient* chrome_translate_client = GetChromeTranslateClient(); diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index 9c4b0d72ff2e16..73032592f5d4c7 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -3847,10 +3847,28 @@ void RenderFrameImpl::UpdateSubresourceLoaderFactories( std::unique_ptr subresource_loader_factories) { DCHECK(loader_factories_); - // TODO(crbug/916625): CHECKing for crbug.com/916625. - CHECK(loader_factories_->IsHostChildURLLoaderFactoryBundle()); - static_cast(loader_factories_.get()) - ->UpdateThisAndAllClones(std::move(subresource_loader_factories)); + if (loader_factories_->IsHostChildURLLoaderFactoryBundle()) { + static_cast(loader_factories_.get()) + ->UpdateThisAndAllClones(std::move(subresource_loader_factories)); + } else { +#if DCHECK_IS_ON() + // In presence of the NetworkService, this situation should happen only if + // the frame hosts a document that isn't related to a real navigation (i.e. + // if the frame should "inherit" the factories from its opener/parent - for + // example for about:blank or about:srcdoc or about:blank#someHref frames, + // or for frames with no URL - like the initial frame opened by window('', + // 'popup')). + if (base::FeatureList::IsEnabled(network::features::kNetworkService)) { + WebURL url = GetWebFrame()->GetDocument().Url(); + if (url.IsValid() && !url.IsEmpty()) + DCHECK(url.ProtocolIs(url::kAboutScheme)); + } +#endif + auto partial_bundle = base::MakeRefCounted(); + static_cast(partial_bundle.get()) + ->Update(std::move(subresource_loader_factories)); + loader_factories_->Update(partial_bundle->PassInterface()); + } } void RenderFrameImpl::MarkInitiatorAsRequiringSeparateURLLoaderFactory(