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

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

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: optimize and "parent" property Created 7 years, 7 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/debug/alias.h" 9 #include "base/debug/alias.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 } 711 }
712 712
713 v8::Handle<v8::Object> new_object = v8::Object::New(); 713 v8::Handle<v8::Object> new_object = v8::Object::New();
714 object->Set(key, new_object); 714 object->Set(key, new_object);
715 return handle_scope.Close(new_object); 715 return handle_scope.Close(new_object);
716 } 716 }
717 717
718 void Dispatcher::RegisterSchemaGeneratedBindings( 718 void Dispatcher::RegisterSchemaGeneratedBindings(
719 ModuleSystem* module_system, 719 ModuleSystem* module_system,
720 ChromeV8Context* context) { 720 ChromeV8Context* context) {
721 std::set<std::string> apis = 721 std::vector<std::string> apis =
722 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); 722 BaseFeatureProvider::GetByName("api")->GetAllTopLevelFeatureNames();
723 for (std::set<std::string>::iterator it = apis.begin(); 723 for (std::vector<std::string>::iterator it = apis.begin();
724 it != apis.end(); ++it) { 724 it != apis.end(); ++it) {
725 const std::string& api_name = *it; 725 const std::string& api_name = *it;
726
726 if (!context->IsAnyFeatureAvailableToContext(api_name)) 727 if (!context->IsAnyFeatureAvailableToContext(api_name))
727 continue; 728 continue;
728 729
729 Feature* feature = 730 Feature* feature =
730 BaseFeatureProvider::GetByName("api")->GetFeature(api_name); 731 BaseFeatureProvider::GetByName("api")->GetFeature(api_name);
731 if (feature && feature->IsInternal()) 732 if (feature && feature->IsInternal())
732 continue; 733 continue;
733 734
734 std::vector<std::string> split; 735 std::vector<std::string> split;
735 base::SplitString(api_name, '.', &split); 736 base::SplitString(api_name, '.', &split);
736 737
737 v8::Handle<v8::Object> bind_object = 738 v8::Handle<v8::Object> bind_object =
738 GetOrCreateChrome(context->v8_context()); 739 GetOrCreateChrome(context->v8_context());
739 740
740 // Check if this API has an ancestor. If the API's ancestor is available and 741 // Check if this API has an ancestor. If the API's ancestor is available and
741 // the API is not available, don't install the bindings for this API. If 742 // the API is not available, don't install the bindings for this API. If
742 // the API is available and its ancestor is not, delete the ancestor and 743 // the API is available and its ancestor is not, delete the ancestor and
743 // install the bindings for the API. This is to prevent loading the ancestor 744 // install the bindings for the API. This is to prevent loading the ancestor
744 // API schema if it will not be needed. 745 // API schema if it will not be needed.
745 // 746 //
746 // For example: 747 // For example:
747 // If app is available and app.window is not, just install app. 748 // If app is available and app.window is not, just install app.
748 // If app.window is available and app is not, delete app and install 749 // If app.window is available and app is not, delete app and install
749 // app.window on a new object so app does not have to be loaded. 750 // app.window on a new object so app does not have to be loaded.
750 std::string ancestor_name; 751 std::string ancestor_name;
751 bool only_ancestor_available = false; 752 bool only_ancestor_available = false;
752 for (size_t i = 0; i < split.size() - 1; ++i) { 753 for (size_t i = 0; i < split.size() - 1; ++i) {
753 ancestor_name += (i ? ".": "") + split[i]; 754 ancestor_name += (i ? ".": "") + split[i];
754 if (!ancestor_name.empty() && 755 if (ancestor_name == "app" && // !ancestor_name.empty() &&
not at google - send to devlin 2013/05/23 00:09:40 commented out?
not at google - send to devlin 2013/05/23 00:09:40 commented out?
cduvall 2013/05/24 03:13:49 I changed this to just checking when the ancestor
not at google - send to devlin 2013/05/24 19:09:18 what check? yeah it seems like if there's no featu
755 context->GetAvailability(ancestor_name).is_available() && 756 context->GetAvailability(ancestor_name).is_available() &&
756 !context->GetAvailability(api_name).is_available()) { 757 !context->GetAvailability(api_name).is_available()) {
757 only_ancestor_available = true; 758 only_ancestor_available = true;
758 break; 759 break;
759 } 760 }
760 bind_object = GetOrCreateObject(bind_object, split[i]); 761 bind_object = GetOrCreateObject(bind_object, split[i]);
761 } 762 }
762 if (only_ancestor_available) 763 if (only_ancestor_available)
763 continue; 764 continue;
764 765
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 "You do not have permission to use '%s'. Be sure to declare" 1428 "You do not have permission to use '%s'. Be sure to declare"
1428 " in your manifest what permissions you need."; 1429 " in your manifest what permissions you need.";
1429 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1430 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1430 APIActivityLogger::LogBlockedCall(context->extension()->id(), 1431 APIActivityLogger::LogBlockedCall(context->extension()->id(),
1431 function_name); 1432 function_name);
1432 v8::ThrowException( 1433 v8::ThrowException(
1433 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1434 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1434 return false; 1435 return false;
1435 } 1436 }
1436 1437
1437 if (ExtensionAPI::GetSharedInstance()->IsPrivileged(function_name) && 1438 Feature* feature =
1438 context->context_type() != Feature::BLESSED_EXTENSION_CONTEXT) { 1439 BaseFeatureProvider::GetByName("api")->GetFeature(function_name);
1440 if (feature->GetContexts()->count(context->context_type()) == 0) {
1439 static const char kMessage[] = 1441 static const char kMessage[] =
1440 "%s can only be used in an extension process."; 1442 "%s can only be used in an extension process.";
not at google - send to devlin 2013/05/23 00:09:40 this error message will need to change
cduvall 2013/05/24 03:13:49 Switched this to just using the features and getti
1441 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1443 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1442 v8::ThrowException( 1444 v8::ThrowException(
1443 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1445 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1444 return false; 1446 return false;
1445 } 1447 }
1446 1448
1447 // Theoretically we could end up with bindings being injected into sandboxed 1449 // Theoretically we could end up with bindings being injected into sandboxed
1448 // frames, for example content scripts. Don't let them execute API functions. 1450 // frames, for example content scripts. Don't let them execute API functions.
1449 WebKit::WebFrame* frame = context->web_frame(); 1451 WebKit::WebFrame* frame = context->web_frame();
1450 ExtensionURLInfo url_info(frame->document().securityOrigin(), 1452 ExtensionURLInfo url_info(frame->document().securityOrigin(),
1451 UserScriptSlave::GetDataSourceURLForFrame(frame)); 1453 UserScriptSlave::GetDataSourceURLForFrame(frame));
1452 if (extensions_.IsSandboxedPage(url_info)) { 1454 if (extensions_.IsSandboxedPage(url_info)) {
1453 static const char kMessage[] = 1455 static const char kMessage[] =
1454 "%s cannot be used within a sandboxed frame."; 1456 "%s cannot be used within a sandboxed frame.";
1455 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1457 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1456 v8::ThrowException( 1458 v8::ThrowException(
1457 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1459 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1458 return false; 1460 return false;
1459 } 1461 }
1460 1462
1461 return true; 1463 return true;
1462 } 1464 }
1463 1465
1464 } // namespace extensions 1466 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698