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

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-jigged to use ModuleSystem Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/extension_dispatcher.h" 5 #include "chrome/renderer/extensions/extension_dispatcher.h"
6 6
7 #include "base/callback.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_piece.h"
8 #include "chrome/common/child_process_logging.h" 11 #include "chrome/common/child_process_logging.h"
9 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_messages.h" 14 #include "chrome/common/extensions/extension_messages.h"
12 #include "chrome/common/extensions/extension_permission_set.h" 15 #include "chrome/common/extensions/extension_permission_set.h"
13 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
14 #include "chrome/renderer/chrome_render_process_observer.h" 17 #include "chrome/renderer/chrome_render_process_observer.h"
15 #include "chrome/renderer/extensions/app_bindings.h" 18 #include "chrome/renderer/extensions/app_bindings.h"
16 #include "chrome/renderer/extensions/chrome_v8_context.h" 19 #include "chrome/renderer/extensions/chrome_v8_context.h"
17 #include "chrome/renderer/extensions/chrome_v8_extension.h" 20 #include "chrome/renderer/extensions/chrome_v8_extension.h"
18 #include "chrome/renderer/extensions/custom_bindings_util.h" 21 #include "chrome/renderer/extensions/custom_bindings_util.h"
19 #include "chrome/renderer/extensions/event_bindings.h" 22 #include "chrome/renderer/extensions/event_bindings.h"
20 #include "chrome/renderer/extensions/extension_groups.h" 23 #include "chrome/renderer/extensions/extension_groups.h"
21 #include "chrome/renderer/extensions/miscellaneous_bindings.h" 24 #include "chrome/renderer/extensions/miscellaneous_bindings.h"
22 #include "chrome/renderer/extensions/schema_generated_bindings.h" 25 #include "chrome/renderer/extensions/schema_generated_bindings.h"
23 #include "chrome/renderer/extensions/user_script_slave.h" 26 #include "chrome/renderer/extensions/user_script_slave.h"
24 #include "chrome/renderer/extensions/webstore_bindings.h" 27 #include "chrome/renderer/extensions/webstore_bindings.h"
28 #include "chrome/renderer/module_system.h"
29 #include "chrome/renderer/native_handler.h"
25 #include "content/public/renderer/render_thread.h" 30 #include "content/public/renderer/render_thread.h"
26 #include "grit/renderer_resources.h" 31 #include "grit/renderer_resources.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 36 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
34 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
35 #include "v8/include/v8.h" 40 #include "v8/include/v8.h"
36 41
42 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h"
43 #include "chrome/renderer/extensions/context_menus_custom_bindings.h"
44 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h"
45 #include "chrome/renderer/extensions/extension_custom_bindings.h"
46 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h"
47 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h"
48 #include "chrome/renderer/extensions/i18n_custom_bindings.h"
49 #include "chrome/renderer/extensions/page_actions_custom_bindings.h"
50 #include "chrome/renderer/extensions/page_capture_custom_bindings.h"
51 #include "chrome/renderer/extensions/tabs_custom_bindings.h"
52 #include "chrome/renderer/extensions/tts_custom_bindings.h"
53 #include "chrome/renderer/extensions/web_request_custom_bindings.h"
54
37 namespace { 55 namespace {
38 56
39 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; 57 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000;
40 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; 58 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000;
41 59
42 ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) { 60 ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) {
43 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) 61 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS)
44 return ChromeV8Context::CONTENT_SCRIPT; 62 return ChromeV8Context::CONTENT_SCRIPT;
45 return ChromeV8Context::OTHER; 63 return ChromeV8Context::OTHER;
46 } 64 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 121
104 void ExtensionDispatcher::WebKitInitialized() { 122 void ExtensionDispatcher::WebKitInitialized() {
105 // For extensions, we want to ensure we call the IdleHandler every so often, 123 // For extensions, we want to ensure we call the IdleHandler every so often,
106 // even if the extension keeps up activity. 124 // even if the extension keeps up activity.
107 if (is_extension_process_) { 125 if (is_extension_process_) {
108 forced_idle_timer_.Start(FROM_HERE, 126 forced_idle_timer_.Start(FROM_HERE,
109 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), 127 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs),
110 RenderThread::Get(), &RenderThread::IdleHandler); 128 RenderThread::Get(), &RenderThread::IdleHandler);
111 } 129 }
112 130
113 RegisterExtension(new AppBindings(this), false);
114 RegisterExtension(new WebstoreBindings(this), false);
115
116 // Add v8 extensions related to chrome extensions.
117 RegisterExtension(new ChromeV8Extension(
118 "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL), true);
119 RegisterExtension(EventBindings::Get(this), true);
120 RegisterExtension(MiscellaneousBindings::Get(this), true);
121 RegisterExtension(SchemaGeneratedBindings::Get(this), true);
122 RegisterExtension(new ChromeV8Extension(
123 "extensions/apitest.js", IDR_EXTENSION_APITEST_JS, NULL), true);
124
125 std::vector<v8::Extension*> custom_bindings =
126 custom_bindings_util::GetAll(this);
127 for (std::vector<v8::Extension*>::iterator it = custom_bindings.begin();
128 it != custom_bindings.end(); ++it) {
129 RegisterExtension(*it, true);
130 }
131
132 // Initialize host permissions for any extensions that were activated before 131 // Initialize host permissions for any extensions that were activated before
133 // WebKit was initialized. 132 // WebKit was initialized.
134 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 133 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
135 iter != active_extension_ids_.end(); ++iter) { 134 iter != active_extension_ids_.end(); ++iter) {
136 const Extension* extension = extensions_.GetByID(*iter); 135 const Extension* extension = extensions_.GetByID(*iter);
137 if (extension) 136 if (extension)
138 InitOriginPermissions(extension); 137 InitOriginPermissions(extension);
139 } 138 }
140 139
141 is_webkit_initialized_ = true; 140 is_webkit_initialized_ = true;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // This is what the extension_group variable will be when DidCreateScriptContext 284 // This is what the extension_group variable will be when DidCreateScriptContext
286 // is called. We know because it's the same as what AllowScriptExtension gets 285 // is called. We know because it's the same as what AllowScriptExtension gets
287 // passed, and the two functions are called sequentially from WebKit. 286 // passed, and the two functions are called sequentially from WebKit.
288 // 287 //
289 // TODO(koz): Plumb extension_group through to AllowScriptExtension() from 288 // TODO(koz): Plumb extension_group through to AllowScriptExtension() from
290 // WebKit. 289 // WebKit.
291 static int hack_DidCreateScriptContext_extension_group = 0; 290 static int hack_DidCreateScriptContext_extension_group = 0;
292 291
293 } 292 }
294 293
295 bool ExtensionDispatcher::AllowScriptExtension( 294 bool ExtensionDispatcher::AllowScriptExtension(
Aaron Boodman 2012/02/28 02:42:59 Can't this entire method and all related code be d
koz (OOO until 15th September) 2012/03/01 03:41:56 Yes, it can. I've removed the custom binding permi
296 WebFrame* frame, 295 WebFrame* frame,
297 const std::string& v8_extension_name, 296 const std::string& v8_extension_name,
298 int extension_group, 297 int extension_group,
299 int world_id) { 298 int world_id) {
300 hack_DidCreateScriptContext_extension_group = extension_group; 299 hack_DidCreateScriptContext_extension_group = extension_group;
301 300
302 // NULL in unit tests. 301 // NULL in unit tests.
303 if (!RenderThread::Get()) 302 if (!RenderThread::Get())
304 return true; 303 return true;
305 304
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 return custom_bindings_util::AllowAPIInjection( 341 return custom_bindings_util::AllowAPIInjection(
343 custom_binding_api_name, *extension, context_type); 342 custom_binding_api_name, *extension, context_type);
344 } 343 }
345 344
346 return true; 345 return true;
347 } 346 }
348 347
349 return false; 348 return false;
350 } 349 }
351 350
351 base::StringPiece GetResource(int resource_id) {
352 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id);
353 }
354
355 std::map<std::string, base::StringPiece>* GetOrCreateSourceMap() {
356 static std::map<std::string, base::StringPiece>* source_map = NULL;
Aaron Boodman 2012/02/28 02:42:59 Sadly, we do not static non-pod types in Chrome. Y
koz (OOO until 15th September) 2012/03/01 03:41:56 I've made it an instance member.
357 if (source_map == NULL) {
358 source_map = new std::map<std::string, base::StringPiece>();
359 (*source_map)["app"] = GetResource(IDR_APP_BINDINGS_JS);
360 (*source_map)["webstore"] = GetResource(IDR_WEBSTORE_BINDINGS_JS);
361 (*source_map)["event_bindings"] = GetResource(IDR_EVENT_BINDINGS_JS);
362 (*source_map)["miscellaneous_bindings"] =
363 GetResource(IDR_MISCELLANEOUS_BINDINGS_JS);
364 (*source_map)["schema_generated_bindings"] =
365 GetResource(IDR_SCHEMA_GENERATED_BINDINGS_JS);
366 (*source_map)["json_schema"] = GetResource(IDR_JSON_SCHEMA_JS);
367 (*source_map)["apitest"] = GetResource(IDR_EXTENSION_APITEST_JS);
368 (*source_map)["setup_bindings"] = GetResource(IDR_SETUP_BINDINGS_JS);
369
370 // Custom bindings.
371 (*source_map)["browserAction"] =
372 GetResource(IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS);
373 (*source_map)["chromePrivate"] =
374 GetResource(IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS);
375 (*source_map)["contentSettings"] =
376 GetResource(IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS);
377 (*source_map)["contextMenus"] =
378 GetResource(IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS);
379 (*source_map)["devtools"] = GetResource(IDR_DEVTOOLS_CUSTOM_BINDINGS_JS);
380 (*source_map)["experimental.declarative"] =
381 GetResource(IDR_EXPERIMENTAL_DECLARATIVE_CUSTOM_BINDINGS_JS);
382 (*source_map)["experimental.socket"] =
383 GetResource(IDR_EXPERIMENTAL_SOCKET_CUSTOM_BINDINGS_JS);
384 (*source_map)["extension"] = GetResource(IDR_EXTENSION_CUSTOM_BINDINGS_JS);
385 (*source_map)["fileBrowserHandler"] =
386 GetResource(IDR_FILE_BROWSER_HANDLER_CUSTOM_BINDINGS_JS);
387 (*source_map)["fileBrowserPrivate"] =
388 GetResource(IDR_FILE_BROWSER_PRIVATE_CUSTOM_BINDINGS_JS);
389 (*source_map)["i18n"] = GetResource(IDR_I18N_CUSTOM_BINDINGS_JS);
390 (*source_map)["input.ime"] = GetResource(IDR_INPUT_IME_CUSTOM_BINDINGS_JS);
391 (*source_map)["omnibox"] = GetResource(IDR_OMNIBOX_CUSTOM_BINDINGS_JS);
392 (*source_map)["pageActions"] =
393 GetResource(IDR_PAGE_ACTIONS_CUSTOM_BINDINGS_JS);
394 (*source_map)["pageAction"] =
395 GetResource(IDR_PAGE_ACTION_CUSTOM_BINDINGS_JS);
396 (*source_map)["pageCapture"] =
397 GetResource(IDR_PAGE_CAPTURE_CUSTOM_BINDINGS_JS);
398 (*source_map)["storage"] = GetResource(IDR_STORAGE_CUSTOM_BINDINGS_JS);
399 (*source_map)["tabs"] = GetResource(IDR_TABS_CUSTOM_BINDINGS_JS);
400 (*source_map)["tts"] = GetResource(IDR_TTS_CUSTOM_BINDINGS_JS);
401 (*source_map)["ttsEngine"] =
402 GetResource(IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS);
403 (*source_map)["types"] = GetResource(IDR_TYPES_CUSTOM_BINDINGS_JS);
404 (*source_map)["webRequest"] =
405 GetResource(IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS);
406 (*source_map)["windows"] = GetResource(IDR_WINDOWS_CUSTOM_BINDINGS_JS);
407 }
408
409 return source_map;
410 }
411
412 class ChromeHiddenNativeHandler : public NativeHandler {
413 public:
414 ChromeHiddenNativeHandler() {
415 RouteFunction("GetChromeHidden",
416 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden,
417 base::Unretained(this)));
418 }
419
420 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) {
421 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent());
422 }
423 };
424
425 class PrintNativeHandler : public NativeHandler {
426 public:
427 PrintNativeHandler() {
428 RouteFunction("Print",
429 base::Bind(&PrintNativeHandler::Print,
430 base::Unretained(this)));
431 }
432
433 v8::Handle<v8::Value> Print(const v8::Arguments& args) {
434 if (args.Length() < 1)
435 return v8::Undefined();
436
437 std::vector<std::string> components;
438 for (int i = 0; i < args.Length(); ++i)
439 components.push_back(*v8::String::Utf8Value(args[i]->ToString()));
440
441 LOG(ERROR) << JoinString(components, ',');
442 return v8::Undefined();
443 }
444 };
445
446 class ContextInfoNativeHandler : public NativeHandler {
447 public:
448 explicit ContextInfoNativeHandler(bool is_bindings_allowed)
449 : is_bindings_allowed_(is_bindings_allowed) {
450 RouteFunction("IsBindingsAllowed",
451 base::Bind(&ContextInfoNativeHandler::IsBindingsAllowed,
452 base::Unretained(this)));
453 }
454
455 v8::Handle<v8::Value> IsBindingsAllowed(const v8::Arguments& args) {
456 return v8::Boolean::New(is_bindings_allowed_);
457 }
458
459 private:
460 bool is_bindings_allowed_;
461 };
462
463 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
464 ChromeV8Context* context,
465 bool is_bindings_allowed) {
466 module_system->RegisterNativeHandler("app",
467 scoped_ptr<NativeHandler>(new AppBindings(this, context)));
Matt Perry 2012/02/28 20:34:20 +2 indent
Matt Perry 2012/02/28 20:34:20 fyi: make_scoped_ptr(new X) looks nicer
koz (OOO until 15th September) 2012/03/01 03:41:56 Done.
koz (OOO until 15th September) 2012/03/01 03:41:56 I think it doesn't work here because we need to up
468 module_system->RegisterNativeHandler("webstore",
469 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context)));
470 module_system->RegisterNativeHandler("event_bindings",
471 scoped_ptr<NativeHandler>(EventBindings::Get(this)));
Matt Perry 2012/02/28 20:34:20 +2 indent
koz (OOO until 15th September) 2012/03/01 03:41:56 Done.
472 module_system->RegisterNativeHandler("miscellaneous_bindings",
473 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this)));
474 module_system->RegisterNativeHandler("schema_generated_bindings",
475 scoped_ptr<NativeHandler>(SchemaGeneratedBindings::Get(this)));
476
477 // Custom bindings.
478 module_system->RegisterNativeHandler("chrome_private",
479 scoped_ptr<NativeHandler>(
480 new ChromePrivateCustomBindings(this)));
481 module_system->RegisterNativeHandler("context_menus",
482 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings()));
483 module_system->RegisterNativeHandler("extension",
484 scoped_ptr<NativeHandler>(
485 new ExtensionCustomBindings(this)));
486 module_system->RegisterNativeHandler("experimental_socket",
487 scoped_ptr<NativeHandler>(new ExperimentalSocketCustomBindings()));
488 module_system->RegisterNativeHandler("file_browser_handler",
489 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings()));
490 module_system->RegisterNativeHandler("file_browser_private",
491 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings()));
492 module_system->RegisterNativeHandler("i18n",
493 scoped_ptr<NativeHandler>(new I18NCustomBindings()));
494 module_system->RegisterNativeHandler("page_actions",
495 scoped_ptr<NativeHandler>(
496 new PageActionsCustomBindings(this)));
497 module_system->RegisterNativeHandler("page_capture",
498 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings()));
499 module_system->RegisterNativeHandler("tabs",
500 scoped_ptr<NativeHandler>(new TabsCustomBindings()));
501 module_system->RegisterNativeHandler("tts",
502 scoped_ptr<NativeHandler>(new TTSCustomBindings()));
503 module_system->RegisterNativeHandler("web_request",
504 scoped_ptr<NativeHandler>(new WebRequestCustomBindings()));
505
506 module_system->RegisterNativeHandler("chrome_hidden",
507 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler()));
508 module_system->RegisterNativeHandler("print",
509 scoped_ptr<NativeHandler>(new PrintNativeHandler()));
510 module_system->RegisterNativeHandler("context_info",
511 scoped_ptr<NativeHandler>(new ContextInfoNativeHandler(
512 is_bindings_allowed)));
513 }
514
352 void ExtensionDispatcher::DidCreateScriptContext( 515 void ExtensionDispatcher::DidCreateScriptContext(
353 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { 516 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) {
354 ChromeV8Context* context = 517 ChromeV8Context* context =
355 new ChromeV8Context( 518 new ChromeV8Context(
356 v8_context, 519 v8_context,
357 frame, 520 frame,
358 GetExtensionID(frame, world_id), 521 GetExtensionID(frame, world_id),
359 ExtensionGroupToContextType( 522 ExtensionGroupToContextType(
360 hack_DidCreateScriptContext_extension_group)); 523 hack_DidCreateScriptContext_extension_group));
361 v8_context_set_.Add(context); 524 v8_context_set_.Add(context);
362 525
526 bool is_bindings_allowed =
527 context->context_type() == ChromeV8Context::CONTENT_SCRIPT ||
528 extensions_.ExtensionBindingsAllowed(ExtensionURLInfo(
529 frame->document().securityOrigin(),
530 UserScriptSlave::GetDataSourceURLForFrame(frame)));
531
532 ModuleSystem* module_system = new ModuleSystem(GetOrCreateSourceMap());
533 RegisterNativeHandlers(module_system, context, is_bindings_allowed);
534
535 context->set_module_system(scoped_ptr<ModuleSystem>(module_system));
Matt Perry 2012/02/28 20:34:20 Why is there one module system per context, rather
koz (OOO until 15th September) 2012/03/01 03:41:56 ModuleSystem injects JS into a particular context
536
537
363 const Extension* extension = extensions_.GetByID(context->extension_id()); 538 const Extension* extension = extensions_.GetByID(context->extension_id());
364 int manifest_version = 1; 539 int manifest_version = 1;
365 if (extension) 540 if (extension)
366 manifest_version = extension->manifest_version(); 541 manifest_version = extension->manifest_version();
367 542
543 module_system->Require("setup_bindings");
544
368 context->DispatchOnLoadEvent( 545 context->DispatchOnLoadEvent(
369 is_extension_process_, 546 is_extension_process_,
370 ChromeRenderProcessObserver::is_incognito_process(), 547 ChromeRenderProcessObserver::is_incognito_process(),
371 manifest_version); 548 manifest_version);
372 549
373 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 550 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
374 } 551 }
375 552
376 std::string ExtensionDispatcher::GetExtensionID(WebFrame* frame, int world_id) { 553 std::string ExtensionDispatcher::GetExtensionID(WebFrame* frame, int world_id) {
377 if (!test_extension_id_.empty()) { 554 if (!test_extension_id_.empty()) {
(...skipping 10 matching lines...) Expand all
388 } 565 }
389 566
390 void ExtensionDispatcher::WillReleaseScriptContext( 567 void ExtensionDispatcher::WillReleaseScriptContext(
391 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { 568 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) {
392 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); 569 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context);
393 if (!context) 570 if (!context)
394 return; 571 return;
395 572
396 context->DispatchOnUnloadEvent(); 573 context->DispatchOnUnloadEvent();
397 574
398 ChromeV8Extension::InstanceSet extensions = ChromeV8Extension::GetAll();
399 for (ChromeV8Extension::InstanceSet::const_iterator iter = extensions.begin();
400 iter != extensions.end(); ++iter) {
401 (*iter)->ContextWillBeReleased(context);
402 }
403
404 v8_context_set_.Remove(context); 575 v8_context_set_.Remove(context);
405 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 576 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
406 } 577 }
407 578
408 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) { 579 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) {
409 test_extension_id_ = id; 580 test_extension_id_ = id;
410 } 581 }
411 582
412 void ExtensionDispatcher::OnActivateApplication( 583 void ExtensionDispatcher::OnActivateApplication(
413 const std::string& extension_id) { 584 const std::string& extension_id) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 699
529 RenderThread::Get()->RegisterExtension(extension); 700 RenderThread::Get()->RegisterExtension(extension);
530 } 701 }
531 702
532 void ExtensionDispatcher::OnUsingWebRequestAPI( 703 void ExtensionDispatcher::OnUsingWebRequestAPI(
533 bool adblock, bool adblock_plus, bool other) { 704 bool adblock, bool adblock_plus, bool other) {
534 webrequest_adblock_ = adblock; 705 webrequest_adblock_ = adblock;
535 webrequest_adblock_plus_ = adblock_plus; 706 webrequest_adblock_plus_ = adblock_plus;
536 webrequest_other_ = other; 707 webrequest_other_ = other;
537 } 708 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698