Fix crash when the main frame is replaced
This commit is contained in:
parent
24574f7299
commit
1709e74958
2 changed files with 12 additions and 6 deletions
|
@ -206,7 +206,8 @@ std::vector<std::string> ParseSchemesCLISwitch(const char* switch_name) {
|
|||
} // namespace
|
||||
|
||||
AtomRendererClient::AtomRendererClient()
|
||||
: node_bindings_(NodeBindings::Create(false)),
|
||||
: node_integration_initialized_(false),
|
||||
node_bindings_(NodeBindings::Create(false)),
|
||||
atom_bindings_(new AtomBindings) {
|
||||
isolated_world_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kContextIsolation);
|
||||
|
@ -342,11 +343,9 @@ void AtomRendererClient::DidCreateScriptContext(
|
|||
if (!render_frame->IsMainFrame() && !IsDevToolsExtension(render_frame))
|
||||
return;
|
||||
|
||||
// Whether the node binding has been initialized.
|
||||
bool first_time = node_bindings_->uv_env() == nullptr;
|
||||
|
||||
// Prepare the node bindings.
|
||||
if (first_time) {
|
||||
if (!node_integration_initialized_) {
|
||||
node_integration_initialized_ = true;
|
||||
node_bindings_->Initialize();
|
||||
node_bindings_->PrepareMessageLoop();
|
||||
}
|
||||
|
@ -362,7 +361,7 @@ void AtomRendererClient::DidCreateScriptContext(
|
|||
// Load everything.
|
||||
node_bindings_->LoadEnvironment(env);
|
||||
|
||||
if (first_time) {
|
||||
if (node_bindings_->uv_env() == nullptr) {
|
||||
// Make uv loop being wrapped by window context.
|
||||
node_bindings_->set_uv_env(env);
|
||||
|
||||
|
@ -382,6 +381,10 @@ void AtomRendererClient::WillReleaseScriptContext(
|
|||
if (env)
|
||||
mate::EmitEvent(env->isolate(), env->process_object(), "exit");
|
||||
|
||||
// The main frame may be replaced.
|
||||
if (env == node_bindings_->uv_env())
|
||||
node_bindings_->set_uv_env(nullptr);
|
||||
|
||||
// Destroy the node environment.
|
||||
node::FreeEnvironment(env);
|
||||
atom_bindings_->EnvironmentDestroyed(env);
|
||||
|
|
|
@ -66,6 +66,9 @@ class AtomRendererClient : public content::ContentRendererClient {
|
|||
std::vector<std::unique_ptr<::media::KeySystemProperties>>* key_systems)
|
||||
override;
|
||||
|
||||
// Whether the node integration has been initialized.
|
||||
bool node_integration_initialized_;
|
||||
|
||||
std::unique_ptr<NodeBindings> node_bindings_;
|
||||
std::unique_ptr<AtomBindings> atom_bindings_;
|
||||
std::unique_ptr<PreferencesManager> preferences_manager_;
|
||||
|
|
Loading…
Reference in a new issue