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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/dispatcher.cc
diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc
index bf62a0669c6dc0cbae7210decbf0339cf2f37e0a..a45c5da62675f8ea1f3c4f8f650c205c59a52714 100644
--- a/chrome/renderer/extensions/dispatcher.cc
+++ b/chrome/renderer/extensions/dispatcher.cc
@@ -654,16 +654,15 @@ v8::Handle<v8::Object> Dispatcher::GetOrCreateObject(
const std::string& field) {
v8::HandleScope handle_scope;
v8::Handle<v8::String> key = v8::String::New(field.c_str());
- // This little dance is for APIs that may be unavailable but have available
- // children. For example, chrome.app can be unavailable, while
- // chrome.app.runtime is available. The lazy getter for chrome.app must be
- // deleted, so that there isn't an error when accessing chrome.app.runtime.
- if (object->Has(key)) {
+ // If the object has a callback property, it is assumed it is an unavailable
+ // API, so it is safe to delete. This is checked before GetOrCreateObject is
+ // called.
+ if (object->HasRealNamedCallbackProperty(key)) {
+ object->Delete(key);
+ } else if (object->HasRealNamedProperty(key)) {
v8::Handle<v8::Value> value = object->Get(key);
- if (value->IsObject())
- return handle_scope.Close(v8::Handle<v8::Object>::Cast(value));
- else
- object->Delete(key);
+ CHECK(value->IsObject());
+ return handle_scope.Close(v8::Handle<v8::Object>::Cast(value));
}
v8::Handle<v8::Object> new_object = v8::Object::New();
@@ -673,8 +672,7 @@ v8::Handle<v8::Object> Dispatcher::GetOrCreateObject(
void Dispatcher::RegisterSchemaGeneratedBindings(
ModuleSystem* module_system,
- ChromeV8Context* context,
- v8::Handle<v8::Context> v8_context) {
+ ChromeV8Context* context) {
std::set<std::string> apis =
ExtensionAPI::GetSharedInstance()->GetAllAPINames();
for (std::set<std::string>::iterator it = apis.begin();
@@ -689,12 +687,25 @@ void Dispatcher::RegisterSchemaGeneratedBindings(
std::vector<std::string> split;
base::SplitString(api_name, '.', &split);
- v8::Handle<v8::Object> bind_object = GetOrCreateChrome(v8_context);
- for (size_t i = 0; i < split.size() - 1; ++i)
+ v8::Handle<v8::Object> bind_object =
+ GetOrCreateChrome(context->v8_context());
+ 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.
+ 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.
+ for (size_t i = 0; i < split.size() - 1; ++i) {
+ 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.
+ if (!current_name.empty() &&
+ context->GetAvailability(current_name).is_available() &&
+ !context->GetAvailability(api_name).is_available()) {
+ only_parent_available = true;
+ break;
+ }
bind_object = GetOrCreateObject(bind_object, split[i]);
+ }
+ if (only_parent_available)
+ continue;
if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) {
- InstallBindings(module_system, v8_context, api_name);
+ InstallBindings(module_system, context->v8_context(), api_name);
} else if (!source_map_.Contains(api_name)) {
module_system->RegisterNativeHandler(
api_name,
@@ -983,31 +994,14 @@ void Dispatcher::DidCreateScriptContext(
GetOrCreateChrome(v8_context);
- // Loading JavaScript is expensive, so only run the full API bindings
- // generation mechanisms in extension pages (NOT all web pages).
- switch (context_type) {
- case Feature::UNSPECIFIED_CONTEXT:
- case Feature::WEB_PAGE_CONTEXT:
- // TODO(kalman): see comment below about ExtensionAPI.
- InstallBindings(module_system.get(), v8_context, "app");
- InstallBindings(module_system.get(), v8_context, "webstore");
- break;
- case Feature::BLESSED_EXTENSION_CONTEXT:
- case Feature::UNBLESSED_EXTENSION_CONTEXT:
- case Feature::CONTENT_SCRIPT_CONTEXT:
- if (extension && !extension->is_platform_app())
- module_system->Require("miscellaneous_bindings");
- module_system->Require("json"); // see paranoid comment in json.js
-
- // TODO(kalman): move this code back out of the switch and execute it
- // regardless of |context_type|. ExtensionAPI knows how to return the
- // correct APIs, however, until it doesn't have a 2MB overhead we can't
- // load it in every process.
- RegisterSchemaGeneratedBindings(module_system.get(),
- context,
- v8_context);
- break;
- }
+ // TODO(kalman): see comment below about ExtensionAPI.
+ InstallBindings(module_system.get(), v8_context, "app");
+ InstallBindings(module_system.get(), v8_context, "webstore");
+ if (extension && !extension->is_platform_app())
+ module_system->Require("miscellaneous_bindings");
+ module_system->Require("json"); // see paranoid comment in json.js
+
+ RegisterSchemaGeneratedBindings(module_system.get(), context);
bool is_within_platform_app = IsWithinPlatformApp(frame);
// Inject custom JS into the platform app context.
« 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