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

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

Issue 13604005: Prevent chrome.app JSON schema from loading on every page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | 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/dispatcher.h" 5 #include "chrome/renderer/extensions/dispatcher.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 int world_id) { 647 int world_id) {
648 g_hack_extension_group = extension_group; 648 g_hack_extension_group = extension_group;
649 return true; 649 return true;
650 } 650 }
651 651
652 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject( 652 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject(
653 v8::Handle<v8::Object> object, 653 v8::Handle<v8::Object> object,
654 const std::string& field) { 654 const std::string& field) {
655 v8::HandleScope handle_scope; 655 v8::HandleScope handle_scope;
656 v8::Handle<v8::String> key = v8::String::New(field.c_str()); 656 v8::Handle<v8::String> key = v8::String::New(field.c_str());
657 // This little dance is for APIs that may be unavailable but have available 657 // If the object has a callback property, it is assumed it is an unavailable
658 // children. For example, chrome.app can be unavailable, while 658 // API, so it is safe to delete. This is checked before GetOrCreateObject is
659 // chrome.app.runtime is available. The lazy getter for chrome.app must be 659 // called.
660 // deleted, so that there isn't an error when accessing chrome.app.runtime. 660 if (object->HasRealNamedCallbackProperty(key)) {
661 if (object->Has(key)) { 661 object->Delete(key);
662 } else if (object->HasRealNamedProperty(key)) {
662 v8::Handle<v8::Value> value = object->Get(key); 663 v8::Handle<v8::Value> value = object->Get(key);
663 if (value->IsObject()) 664 CHECK(value->IsObject());
664 return handle_scope.Close(v8::Handle<v8::Object>::Cast(value)); 665 return handle_scope.Close(v8::Handle<v8::Object>::Cast(value));
665 else
666 object->Delete(key);
667 } 666 }
668 667
669 v8::Handle<v8::Object> new_object = v8::Object::New(); 668 v8::Handle<v8::Object> new_object = v8::Object::New();
670 object->Set(key, new_object); 669 object->Set(key, new_object);
671 return handle_scope.Close(new_object); 670 return handle_scope.Close(new_object);
672 } 671 }
673 672
674 void Dispatcher::RegisterSchemaGeneratedBindings( 673 void Dispatcher::RegisterSchemaGeneratedBindings(
675 ModuleSystem* module_system, 674 ModuleSystem* module_system,
676 ChromeV8Context* context, 675 ChromeV8Context* context) {
677 v8::Handle<v8::Context> v8_context) {
678 std::set<std::string> apis = 676 std::set<std::string> apis =
679 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); 677 ExtensionAPI::GetSharedInstance()->GetAllAPINames();
680 for (std::set<std::string>::iterator it = apis.begin(); 678 for (std::set<std::string>::iterator it = apis.begin();
681 it != apis.end(); ++it) { 679 it != apis.end(); ++it) {
682 const std::string& api_name = *it; 680 const std::string& api_name = *it;
683 681
684 Feature* feature = 682 Feature* feature =
685 BaseFeatureProvider::GetAPIFeatures()->GetFeature(api_name); 683 BaseFeatureProvider::GetAPIFeatures()->GetFeature(api_name);
686 if (feature && feature->IsInternal()) 684 if (feature && feature->IsInternal())
687 continue; 685 continue;
688 686
689 std::vector<std::string> split; 687 std::vector<std::string> split;
690 base::SplitString(api_name, '.', &split); 688 base::SplitString(api_name, '.', &split);
691 689
692 v8::Handle<v8::Object> bind_object = GetOrCreateChrome(v8_context); 690 v8::Handle<v8::Object> bind_object =
693 for (size_t i = 0; i < split.size() - 1; ++i) 691 GetOrCreateChrome(context->v8_context());
692 std::string current_name;
not at google - send to devlin 2013/04/04 01:30:26 ok... I think I understand what you're doing here.
cduvall 2013/04/11 00:02:56 Done.
693 bool only_parent_available = false;
not at google - send to devlin 2013/04/04 01:30:26 only_ancestor_available?
cduvall 2013/04/11 00:02:56 Done.
694 for (size_t i = 0; i < split.size() - 1; ++i) {
695 current_name += (i ? ".": "") + split[i];
not at google - send to devlin 2013/04/04 01:30:26 ancestor_name?
cduvall 2013/04/11 00:02:56 Done.
696 if (!current_name.empty() &&
697 context->GetAvailability(current_name).is_available() &&
698 !context->GetAvailability(api_name).is_available()) {
699 only_parent_available = true;
700 break;
701 }
694 bind_object = GetOrCreateObject(bind_object, split[i]); 702 bind_object = GetOrCreateObject(bind_object, split[i]);
703 }
704 if (only_parent_available)
705 continue;
695 706
696 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { 707 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) {
697 InstallBindings(module_system, v8_context, api_name); 708 InstallBindings(module_system, context->v8_context(), api_name);
698 } else if (!source_map_.Contains(api_name)) { 709 } else if (!source_map_.Contains(api_name)) {
699 module_system->RegisterNativeHandler( 710 module_system->RegisterNativeHandler(
700 api_name, 711 api_name,
701 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler( 712 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler(
702 module_system, 713 module_system,
703 api_name, 714 api_name,
704 "binding"))); 715 "binding")));
705 module_system->SetNativeLazyField(bind_object, 716 module_system->SetNativeLazyField(bind_object,
706 split.back(), 717 split.back(),
707 api_name, 718 api_name,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 BackgroundInfo::HasLazyBackgroundPage(extension)); 987 BackgroundInfo::HasLazyBackgroundPage(extension));
977 module_system->RegisterNativeHandler("process", 988 module_system->RegisterNativeHandler("process",
978 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( 989 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler(
979 this, v8_context, context->GetExtensionID(), 990 this, v8_context, context->GetExtensionID(),
980 context->GetContextTypeDescription(), 991 context->GetContextTypeDescription(),
981 ChromeRenderProcessObserver::is_incognito_process(), 992 ChromeRenderProcessObserver::is_incognito_process(),
982 manifest_version, send_request_disabled))); 993 manifest_version, send_request_disabled)));
983 994
984 GetOrCreateChrome(v8_context); 995 GetOrCreateChrome(v8_context);
985 996
986 // Loading JavaScript is expensive, so only run the full API bindings 997 // TODO(kalman): see comment below about ExtensionAPI.
987 // generation mechanisms in extension pages (NOT all web pages). 998 InstallBindings(module_system.get(), v8_context, "app");
988 switch (context_type) { 999 InstallBindings(module_system.get(), v8_context, "webstore");
989 case Feature::UNSPECIFIED_CONTEXT: 1000 if (extension && !extension->is_platform_app())
990 case Feature::WEB_PAGE_CONTEXT: 1001 module_system->Require("miscellaneous_bindings");
991 // TODO(kalman): see comment below about ExtensionAPI. 1002 module_system->Require("json"); // see paranoid comment in json.js
992 InstallBindings(module_system.get(), v8_context, "app");
993 InstallBindings(module_system.get(), v8_context, "webstore");
994 break;
995 case Feature::BLESSED_EXTENSION_CONTEXT:
996 case Feature::UNBLESSED_EXTENSION_CONTEXT:
997 case Feature::CONTENT_SCRIPT_CONTEXT:
998 if (extension && !extension->is_platform_app())
999 module_system->Require("miscellaneous_bindings");
1000 module_system->Require("json"); // see paranoid comment in json.js
1001 1003
1002 // TODO(kalman): move this code back out of the switch and execute it 1004 RegisterSchemaGeneratedBindings(module_system.get(), context);
1003 // regardless of |context_type|. ExtensionAPI knows how to return the
1004 // correct APIs, however, until it doesn't have a 2MB overhead we can't
1005 // load it in every process.
1006 RegisterSchemaGeneratedBindings(module_system.get(),
1007 context,
1008 v8_context);
1009 break;
1010 }
1011 1005
1012 bool is_within_platform_app = IsWithinPlatformApp(frame); 1006 bool is_within_platform_app = IsWithinPlatformApp(frame);
1013 // Inject custom JS into the platform app context. 1007 // Inject custom JS into the platform app context.
1014 if (is_within_platform_app) 1008 if (is_within_platform_app)
1015 module_system->Require("platformApp"); 1009 module_system->Require("platformApp");
1016 1010
1017 // Only platform apps support the <webview> tag, because the "webView" and 1011 // Only platform apps support the <webview> tag, because the "webView" and
1018 // "denyWebView" modules will affect the performance of DOM modifications 1012 // "denyWebView" modules will affect the performance of DOM modifications
1019 // (http://crbug.com/196453). 1013 // (http://crbug.com/196453).
1020 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && 1014 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT &&
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1368 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1375 v8::ThrowException( 1369 v8::ThrowException(
1376 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1370 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1377 return false; 1371 return false;
1378 } 1372 }
1379 1373
1380 return true; 1374 return true;
1381 } 1375 }
1382 1376
1383 } // namespace extensions 1377 } // namespace extensions
OLDNEW
« chrome/common/extensions/api/_api_features.json ('K') | « chrome/renderer/extensions/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698