[Extensions] Fix script injection crashes
Renderer shutdown is a funny phase. Judging by the stack traces, it would seem
that RenderFrames can outlive the extensions core and the RenderThread, the
former meaning that pending ScriptInjections can be deleted without running and
the latter meaning that when they try to message the browser, we get a crash.
Fix this by invalidating the frame during shutdown.
BUG=538312
Review URL: https://codereview.chromium.org/1374533004
Cr-Commit-Position: refs/heads/master@{#352060}
diff --git a/extensions/renderer/programmatic_script_injector.h b/extensions/renderer/programmatic_script_injector.h
index 1f5584c..159ff1c5 100644
--- a/extensions/renderer/programmatic_script_injector.h
+++ b/extensions/renderer/programmatic_script_injector.h
@@ -27,8 +27,6 @@
~ProgrammaticScriptInjector() override;
private:
- class FrameWatcher;
-
// ScriptInjector implementation.
UserScript::InjectionType script_type() const override;
bool ShouldExecuteInMainWorld() const override;
@@ -47,15 +45,17 @@
void GetRunInfo(ScriptsRunInfo* scripts_run_info,
UserScript::RunLocation run_location) const override;
void OnInjectionComplete(scoped_ptr<base::Value> execution_result,
- UserScript::RunLocation run_location) override;
- void OnWillNotInject(InjectFailureReason reason) override;
+ UserScript::RunLocation run_location,
+ content::RenderFrame* render_frame) override;
+ void OnWillNotInject(InjectFailureReason reason,
+ content::RenderFrame* render_frame) override;
// Return the run location for this injector.
UserScript::RunLocation GetRunLocation() const;
// Notify the browser that the script was injected (or never will be), and
// send along any results or errors.
- void Finish(const std::string& error);
+ void Finish(const std::string& error, content::RenderFrame* render_frame);
// The parameters for injecting the script.
scoped_ptr<ExtensionMsg_ExecuteCode_Params> params_;
@@ -68,9 +68,6 @@
// security decisions, to avoid race conditions (e.g. due to navigation).
GURL effective_url_;
- // A helper class to hold the render frame and watch for its deletion.
- scoped_ptr<FrameWatcher> frame_watcher_;
-
// The results of the script execution.
base::ListValue results_;