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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 BackgroundInfo::HasLazyBackgroundPage(extension)); | 962 BackgroundInfo::HasLazyBackgroundPage(extension)); |
963 module_system->RegisterNativeHandler("process", | 963 module_system->RegisterNativeHandler("process", |
964 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 964 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
965 this, v8_context, context->GetExtensionID(), | 965 this, v8_context, context->GetExtensionID(), |
966 context->GetContextTypeDescription(), | 966 context->GetContextTypeDescription(), |
967 ChromeRenderProcessObserver::is_incognito_process(), | 967 ChromeRenderProcessObserver::is_incognito_process(), |
968 manifest_version, send_request_disabled))); | 968 manifest_version, send_request_disabled))); |
969 | 969 |
970 GetOrCreateChrome(v8_context); | 970 GetOrCreateChrome(v8_context); |
971 | 971 |
972 // Loading JavaScript is expensive, so only run the full API bindings | 972 if (extension && !extension->is_platform_app()) |
973 // generation mechanisms in extension pages (NOT all web pages). | 973 module_system->Require("miscellaneous_bindings"); |
974 switch (context_type) { | 974 // See paranoid comment in json.js. http://crbug.com/223170 |
975 case Feature::UNSPECIFIED_CONTEXT: | 975 module_system->Require("json"); |
976 case Feature::WEB_PAGE_CONTEXT: | 976 RegisterSchemaGeneratedBindings(module_system.get(), |
977 // TODO(kalman): see comment below about ExtensionAPI. | 977 context, |
978 InstallBindings(module_system.get(), v8_context, "app"); | 978 v8_context); |
979 InstallBindings(module_system.get(), v8_context, "webstore"); | |
980 break; | |
981 case Feature::BLESSED_EXTENSION_CONTEXT: | |
982 case Feature::UNBLESSED_EXTENSION_CONTEXT: | |
983 case Feature::CONTENT_SCRIPT_CONTEXT: { | |
984 if (extension && !extension->is_platform_app()) | |
985 module_system->Require("miscellaneous_bindings"); | |
986 module_system->Require("json"); // see paranoid comment in json.js | |
987 | |
988 // TODO(kalman): move this code back out of the switch and execute it | |
989 // regardless of |context_type|. ExtensionAPI knows how to return the | |
990 // correct APIs, however, until it doesn't have a 2MB overhead we can't | |
991 // load it in every process. | |
992 RegisterSchemaGeneratedBindings(module_system.get(), | |
993 context, | |
994 v8_context); | |
995 break; | |
996 } | |
997 } | |
998 | 979 |
999 bool is_within_platform_app = IsWithinPlatformApp(frame); | 980 bool is_within_platform_app = IsWithinPlatformApp(frame); |
1000 // Inject custom JS into the platform app context. | 981 // Inject custom JS into the platform app context. |
1001 if (is_within_platform_app) | 982 if (is_within_platform_app) |
1002 module_system->Require("platformApp"); | 983 module_system->Require("platformApp"); |
1003 | 984 |
1004 // Only platform apps support the <webview> tag, because the "webView" and | 985 // Only platform apps support the <webview> tag, because the "webView" and |
1005 // "denyWebView" modules will affect the performance of DOM modifications | 986 // "denyWebView" modules will affect the performance of DOM modifications |
1006 // (http://crbug.com/196453). | 987 // (http://crbug.com/196453). |
1007 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && | 988 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1326 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1346 v8::ThrowException( | 1327 v8::ThrowException( |
1347 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1328 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1348 return false; | 1329 return false; |
1349 } | 1330 } |
1350 | 1331 |
1351 return true; | 1332 return true; |
1352 } | 1333 } |
1353 | 1334 |
1354 } // namespace extensions | 1335 } // namespace extensions |
OLD | NEW |