fix: don't handle browser messages before document element is created (#19718)

* fix: don't handle browser messages before document element is created

* fix: bind ElectronApiServiceImpl later

DidCreateDocumentElement is called before the ElectronApiServiceImpl
gets bound.

* chore: add comment
This commit is contained in:
Cheng Zhao 2019-08-13 02:38:41 +09:00 committed by Samuel Attard
parent 398c5d553d
commit 04dbd5c53f
5 changed files with 90 additions and 35 deletions

View file

@ -227,17 +227,12 @@ void RendererClientBase::RenderFrameCreated(
std::make_unique<electron::PrintRenderFrameHelperDelegate>());
#endif
// TODO(nornagon): it might be possible for an IPC message sent to this
// service to trigger v8 context creation before the page has begun loading.
// However, it's unclear whether such a timing is possible to trigger, and we
// don't have any test to confirm it. Add a test that confirms that a
// main->renderer IPC can't cause the preload script to be executed twice. If
// it is possible to trigger the preload script before the document is ready
// through this interface, we should delay adding it to the registry until
// the document is ready.
// Note: ElectronApiServiceImpl has to be created now to capture the
// DidCreateDocumentElement event.
auto* service = new ElectronApiServiceImpl(render_frame, this);
render_frame->GetAssociatedInterfaceRegistry()->AddInterface(
base::BindRepeating(&ElectronApiServiceImpl::CreateMojoService,
render_frame, this));
base::BindRepeating(&ElectronApiServiceImpl::BindTo,
service->GetWeakPtr()));
#if BUILDFLAG(ENABLE_PDF_VIEWER)
// Allow access to file scheme from pdf viewer.