Index: extensions/renderer/render_frame_observer_natives.cc |
diff --git a/extensions/renderer/render_frame_observer_natives.cc b/extensions/renderer/render_frame_observer_natives.cc |
index 1c1f06e87f3217890d3519e426f51be50ebc4542..7c507b379933d487dc0c5c9c3932c078f896da72 100644 |
--- a/extensions/renderer/render_frame_observer_natives.cc |
+++ b/extensions/renderer/render_frame_observer_natives.cc |
@@ -24,12 +24,11 @@ class LoadWatcher : public content::RenderFrameObserver { |
: content::RenderFrameObserver(frame), callback_(callback) {} |
void DidCreateDocumentElement() override { |
- // The callback must be run as soon as the root element is available. |
- // Running the callback may trigger DidCreateDocumentElement or |
- // DidFailProvisionalLoad, so delete this before running the callback. |
- base::Callback<void(bool)> callback = callback_; |
+ // Defer the callback instead of running it now to avoid re-entrancy caused |
+ // by the JavaScript callback. |
+ ExtensionFrameHelper::Get(render_frame()) |
+ ->ScheduleAtDocumentStart(base::Bind(callback_, true)); |
delete this; |
- callback.Run(true); |
} |
void DidFailProvisionalLoad(const blink::WebURLError& error) override { |