Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: extensions/renderer/module_system.cc

Issue 1083663004: Revert of Move the event attach/detach logic on unload from event.js to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/renderer/module_system.h ('k') | extensions/renderer/module_system_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/module_system.h" 5 #include "extensions/renderer/module_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h"
10 #include "base/stl_util.h" 9 #include "base/stl_util.h"
11 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
14 #include "content/public/renderer/render_frame.h" 13 #include "content/public/renderer/render_frame.h"
15 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
16 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
17 #include "extensions/common/extensions_client.h" 16 #include "extensions/common/extensions_client.h"
18 #include "extensions/renderer/console.h" 17 #include "extensions/renderer/console.h"
19 #include "extensions/renderer/safe_builtins.h" 18 #include "extensions/renderer/safe_builtins.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 global->SetHiddenValue(v8::String::NewFromUtf8(isolate, kModuleSystem), 144 global->SetHiddenValue(v8::String::NewFromUtf8(isolate, kModuleSystem),
146 v8::External::New(isolate, this)); 145 v8::External::New(isolate, this));
147 146
148 gin::ModuleRegistry::From(context->v8_context())->AddObserver(this); 147 gin::ModuleRegistry::From(context->v8_context())->AddObserver(this);
149 if (context_->GetRenderFrame()) { 148 if (context_->GetRenderFrame()) {
150 context_->GetRenderFrame()->EnsureMojoBuiltinsAreAvailable( 149 context_->GetRenderFrame()->EnsureMojoBuiltinsAreAvailable(
151 context->isolate(), context->v8_context()); 150 context->isolate(), context->v8_context());
152 } 151 }
153 } 152 }
154 153
155 ModuleSystem::~ModuleSystem() { 154 ModuleSystem::~ModuleSystem() { Invalidate(); }
156 }
157 155
158 void ModuleSystem::Invalidate() { 156 void ModuleSystem::Invalidate() {
157 if (!is_valid())
158 return;
159
159 // Clear the module system properties from the global context. It's polite, 160 // Clear the module system properties from the global context. It's polite,
160 // and we use this as a signal in lazy handlers that we no longer exist. 161 // and we use this as a signal in lazy handlers that we no longer exist.
161 { 162 {
162 v8::HandleScope scope(GetIsolate()); 163 v8::HandleScope scope(GetIsolate());
163 v8::Handle<v8::Object> global = context()->v8_context()->Global(); 164 v8::Handle<v8::Object> global = context()->v8_context()->Global();
164 global->DeleteHiddenValue( 165 global->DeleteHiddenValue(
165 v8::String::NewFromUtf8(GetIsolate(), kModulesField)); 166 v8::String::NewFromUtf8(GetIsolate(), kModulesField));
166 global->DeleteHiddenValue( 167 global->DeleteHiddenValue(
167 v8::String::NewFromUtf8(GetIsolate(), kModuleSystem)); 168 v8::String::NewFromUtf8(GetIsolate(), kModuleSystem));
168 } 169 }
169 170
170 // Invalidate all active and clobbered NativeHandlers we own. 171 // Invalidate all of the successfully required handlers we own.
171 for (const auto& handler : native_handler_map_) 172 for (NativeHandlerMap::iterator it = native_handler_map_.begin();
172 handler.second->Invalidate(); 173 it != native_handler_map_.end();
173 for (const auto& clobbered_handler : clobbered_native_handlers_) 174 ++it) {
174 clobbered_handler->Invalidate(); 175 it->second->Invalidate();
176 }
175 177
176 ObjectBackedNativeHandler::Invalidate(); 178 ObjectBackedNativeHandler::Invalidate();
177 } 179 }
178 180
179 ModuleSystem::NativesEnabledScope::NativesEnabledScope( 181 ModuleSystem::NativesEnabledScope::NativesEnabledScope(
180 ModuleSystem* module_system) 182 ModuleSystem* module_system)
181 : module_system_(module_system) { 183 : module_system_(module_system) {
182 module_system_->natives_enabled_++; 184 module_system_->natives_enabled_++;
183 } 185 }
184 186
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 result = context_->CallFunction(func, argc, argv); 294 result = context_->CallFunction(func, argc, argv);
293 if (try_catch.HasCaught()) 295 if (try_catch.HasCaught())
294 HandleException(try_catch); 296 HandleException(try_catch);
295 } 297 }
296 return handle_scope.Escape(result); 298 return handle_scope.Escape(result);
297 } 299 }
298 300
299 void ModuleSystem::RegisterNativeHandler( 301 void ModuleSystem::RegisterNativeHandler(
300 const std::string& name, 302 const std::string& name,
301 scoped_ptr<NativeHandler> native_handler) { 303 scoped_ptr<NativeHandler> native_handler) {
302 ClobberExistingNativeHandler(name);
303 native_handler_map_[name] = 304 native_handler_map_[name] =
304 linked_ptr<NativeHandler>(native_handler.release()); 305 linked_ptr<NativeHandler>(native_handler.release());
305 } 306 }
306 307
307 void ModuleSystem::OverrideNativeHandlerForTest(const std::string& name) { 308 void ModuleSystem::OverrideNativeHandlerForTest(const std::string& name) {
308 ClobberExistingNativeHandler(name);
309 overridden_native_handlers_.insert(name); 309 overridden_native_handlers_.insert(name);
310 } 310 }
311 311
312 void ModuleSystem::RunString(const std::string& code, const std::string& name) { 312 void ModuleSystem::RunString(const std::string& code, const std::string& name) {
313 v8::HandleScope handle_scope(GetIsolate()); 313 v8::HandleScope handle_scope(GetIsolate());
314 RunString(v8::String::NewFromUtf8(GetIsolate(), code.c_str()), 314 RunString(v8::String::NewFromUtf8(GetIsolate(), code.c_str()),
315 v8::String::NewFromUtf8(GetIsolate(), name.c_str())); 315 v8::String::NewFromUtf8(GetIsolate(), name.c_str()));
316 } 316 }
317 317
318 // static 318 // static
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 scoped_ptr<v8::Global<v8::Promise::Resolver>> resolver, 678 scoped_ptr<v8::Global<v8::Promise::Resolver>> resolver,
679 v8::Handle<v8::Value> value) { 679 v8::Handle<v8::Value> value) {
680 if (!is_valid()) 680 if (!is_valid())
681 return; 681 return;
682 v8::HandleScope handle_scope(GetIsolate()); 682 v8::HandleScope handle_scope(GetIsolate());
683 v8::Handle<v8::Promise::Resolver> resolver_local( 683 v8::Handle<v8::Promise::Resolver> resolver_local(
684 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); 684 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver));
685 resolver_local->Resolve(value); 685 resolver_local->Resolve(value);
686 } 686 }
687 687
688 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) {
689 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name);
690 if (existing_handler != native_handler_map_.end()) {
691 clobbered_native_handlers_.push_back(existing_handler->second);
692 native_handler_map_.erase(existing_handler);
693 }
694 }
695
696 } // namespace extensions 688 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/module_system.h ('k') | extensions/renderer/module_system_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698