Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 } | 715 } |
| 716 | 716 |
| 717 void Dispatcher::RegisterSchemaGeneratedBindings( | 717 void Dispatcher::RegisterSchemaGeneratedBindings( |
| 718 ModuleSystem* module_system, | 718 ModuleSystem* module_system, |
| 719 ChromeV8Context* context) { | 719 ChromeV8Context* context) { |
| 720 std::set<std::string> apis = | 720 std::set<std::string> apis = |
| 721 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | 721 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); |
| 722 for (std::set<std::string>::iterator it = apis.begin(); | 722 for (std::set<std::string>::iterator it = apis.begin(); |
| 723 it != apis.end(); ++it) { | 723 it != apis.end(); ++it) { |
| 724 const std::string& api_name = *it; | 724 const std::string& api_name = *it; |
| 725 if (!context->IsAnyFeatureAvailableToContext(api_name)) | 725 // TODO(cduvall): Reenable once all APIs are converted to features. |
| 726 continue; | 726 // if (!context->IsAnyFeatureAvailableToContext(api_name)) |
| 727 // continue; | |
| 727 | 728 |
| 728 Feature* feature = | 729 Feature* feature = |
| 729 BaseFeatureProvider::GetByName("api")->GetFeature(api_name); | 730 BaseFeatureProvider::GetByName("api")->GetFeature(api_name); |
| 730 if (feature && feature->IsInternal()) | 731 if (feature && feature->IsInternal()) |
| 731 continue; | 732 continue; |
| 732 | 733 |
| 733 std::vector<std::string> split; | 734 std::vector<std::string> split; |
| 734 base::SplitString(api_name, '.', &split); | 735 base::SplitString(api_name, '.', &split); |
| 735 | 736 |
| 736 v8::Handle<v8::Object> bind_object = | 737 v8::Handle<v8::Object> bind_object = |
| 737 GetOrCreateChrome(context->v8_context()); | 738 GetOrCreateChrome(context->v8_context()); |
| 738 | 739 |
| 739 // Check if this API has an ancestor. If the API's ancestor is available and | 740 // Check if this API has an ancestor. If the API's ancestor is available and |
| 740 // the API is not available, don't install the bindings for this API. If | 741 // the API is not available, don't install the bindings for this API. If |
| 741 // the API is available and its ancestor is not, delete the ancestor and | 742 // the API is available and its ancestor is not, delete the ancestor and |
| 742 // install the bindings for the API. This is to prevent loading the ancestor | 743 // install the bindings for the API. This is to prevent loading the ancestor |
| 743 // API schema if it will not be needed. | 744 // API schema if it will not be needed. |
| 744 // | 745 // |
| 745 // For example: | 746 // For example: |
| 746 // If app is available and app.window is not, just install app. | 747 // If app is available and app.window is not, just install app. |
| 747 // If app.window is available and app is not, delete app and install | 748 // If app.window is available and app is not, delete app and install |
| 748 // app.window on a new object so app does not have to be loaded. | 749 // app.window on a new object so app does not have to be loaded. |
| 749 std::string ancestor_name; | 750 std::string ancestor_name; |
| 750 bool only_ancestor_available = false; | 751 bool only_ancestor_available = false; |
| 751 for (size_t i = 0; i < split.size() - 1; ++i) { | 752 for (size_t i = 0; i < split.size() - 1; ++i) { |
| 752 ancestor_name += (i ? ".": "") + split[i]; | 753 ancestor_name += (i ? ".": "") + split[i]; |
| 753 if (!ancestor_name.empty() && | 754 // Only check if the ancestor is "app" for now, because this is the only |
| 755 // API that actually has children. If this checks every ancestor, the | |
| 756 // API schemas will need to be loaded to check availability. This can go | |
| 757 // back to checking all APIs once all the APIs have been converted to the | |
| 758 // feature system. | |
| 759 if (ancestor_name == "app" && !ancestor_name.empty() && | |
|
not at google - send to devlin
2013/05/10 02:46:45
maybe you should comment out the second of these c
cduvall
2013/05/10 03:31:07
Done.
| |
| 754 context->GetAvailability(ancestor_name).is_available() && | 760 context->GetAvailability(ancestor_name).is_available() && |
| 755 !context->GetAvailability(api_name).is_available()) { | 761 !context->GetAvailability(api_name).is_available()) { |
| 756 only_ancestor_available = true; | 762 only_ancestor_available = true; |
| 757 break; | 763 break; |
| 758 } | 764 } |
| 759 bind_object = GetOrCreateObject(bind_object, split[i]); | 765 bind_object = GetOrCreateObject(bind_object, split[i]); |
| 760 } | 766 } |
| 761 if (only_ancestor_available) | 767 if (only_ancestor_available) |
| 762 continue; | 768 continue; |
| 763 | 769 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1046 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1052 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 1047 module_system->RegisterNativeHandler("process", | 1053 module_system->RegisterNativeHandler("process", |
| 1048 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1054 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 1049 this, v8_context, context->GetExtensionID(), | 1055 this, v8_context, context->GetExtensionID(), |
| 1050 context->GetContextTypeDescription(), | 1056 context->GetContextTypeDescription(), |
| 1051 ChromeRenderProcessObserver::is_incognito_process(), | 1057 ChromeRenderProcessObserver::is_incognito_process(), |
| 1052 manifest_version, send_request_disabled))); | 1058 manifest_version, send_request_disabled))); |
| 1053 | 1059 |
| 1054 GetOrCreateChrome(v8_context); | 1060 GetOrCreateChrome(v8_context); |
| 1055 | 1061 |
| 1056 // Loading JavaScript is expensive, so only run the full API bindings | 1062 if (extension && !extension->is_platform_app()) |
|
not at google - send to devlin
2013/05/10 02:46:45
Maybe this _is_ a bit premature if there's still a
cduvall
2013/05/10 03:31:07
Tried the extension api thing, commented there.
| |
| 1057 // generation mechanisms in extension pages (NOT all web pages). | 1063 module_system->Require("miscellaneous_bindings"); |
| 1058 switch (context_type) { | 1064 if (context_type != Feature::WEB_PAGE_CONTEXT) |
| 1059 case Feature::UNSPECIFIED_CONTEXT: | 1065 module_system->Require("json"); // see paranoid comment in json.js |
| 1060 case Feature::WEB_PAGE_CONTEXT: | |
| 1061 // TODO(kalman): see comment below about ExtensionAPI. | |
| 1062 InstallBindings(module_system.get(), v8_context, "app"); | |
| 1063 InstallBindings(module_system.get(), v8_context, "webstore"); | |
| 1064 break; | |
| 1065 case Feature::BLESSED_EXTENSION_CONTEXT: | |
| 1066 case Feature::UNBLESSED_EXTENSION_CONTEXT: | |
| 1067 case Feature::CONTENT_SCRIPT_CONTEXT: | |
| 1068 if (extension && !extension->is_platform_app()) | |
| 1069 module_system->Require("miscellaneous_bindings"); | |
| 1070 module_system->Require("json"); // see paranoid comment in json.js | |
| 1071 | 1066 |
| 1072 // TODO(kalman): move this code back out of the switch and execute it | 1067 RegisterSchemaGeneratedBindings(module_system.get(), context); |
| 1073 // regardless of |context_type|. ExtensionAPI knows how to return the | |
| 1074 // correct APIs, however, until it doesn't have a 2MB overhead we can't | |
| 1075 // load it in every process. | |
| 1076 RegisterSchemaGeneratedBindings(module_system.get(), context); | |
| 1077 break; | |
| 1078 } | |
| 1079 | 1068 |
| 1080 bool is_within_platform_app = IsWithinPlatformApp(frame); | 1069 bool is_within_platform_app = IsWithinPlatformApp(frame); |
| 1081 // Inject custom JS into the platform app context. | 1070 // Inject custom JS into the platform app context. |
| 1082 if (is_within_platform_app) | 1071 if (is_within_platform_app) |
| 1083 module_system->Require("platformApp"); | 1072 module_system->Require("platformApp"); |
| 1084 | 1073 |
| 1085 // Only platform apps support the <webview> tag, because the "webView" and | 1074 // Only platform apps support the <webview> tag, because the "webView" and |
| 1086 // "denyWebView" modules will affect the performance of DOM modifications | 1075 // "denyWebView" modules will affect the performance of DOM modifications |
| 1087 // (http://crbug.com/196453). | 1076 // (http://crbug.com/196453). |
| 1088 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && | 1077 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1451 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1440 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1452 v8::ThrowException( | 1441 v8::ThrowException( |
| 1453 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1442 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1454 return false; | 1443 return false; |
| 1455 } | 1444 } |
| 1456 | 1445 |
| 1457 return true; | 1446 return true; |
| 1458 } | 1447 } |
| 1459 | 1448 |
| 1460 } // namespace extensions | 1449 } // namespace extensions |
| OLD | NEW |