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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1021 BackgroundInfo::HasLazyBackgroundPage(extension)); |
1022 module_system->RegisterNativeHandler("process", | 1022 module_system->RegisterNativeHandler("process", |
1023 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1023 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
1024 this, v8_context, context->GetExtensionID(), | 1024 this, v8_context, context->GetExtensionID(), |
1025 context->GetContextTypeDescription(), | 1025 context->GetContextTypeDescription(), |
1026 ChromeRenderProcessObserver::is_incognito_process(), | 1026 ChromeRenderProcessObserver::is_incognito_process(), |
1027 manifest_version, send_request_disabled))); | 1027 manifest_version, send_request_disabled))); |
1028 | 1028 |
1029 GetOrCreateChrome(v8_context); | 1029 GetOrCreateChrome(v8_context); |
1030 | 1030 |
1031 // TODO(kalman): see comment below about ExtensionAPI. | 1031 // Loading JavaScript is expensive, so only run the full API bindings |
1032 if (extension && !extension->is_platform_app()) | 1032 // generation mechanisms in extension pages (NOT all web pages). |
1033 module_system->Require("miscellaneous_bindings"); | 1033 switch (context_type) { |
1034 if (context_type != Feature::WEB_PAGE_CONTEXT) | 1034 case Feature::UNSPECIFIED_CONTEXT: |
1035 module_system->Require("json"); // see paranoid comment in json.js | 1035 case Feature::WEB_PAGE_CONTEXT: |
| 1036 // TODO(kalman): see comment below about ExtensionAPI. |
| 1037 InstallBindings(module_system.get(), v8_context, "app"); |
| 1038 InstallBindings(module_system.get(), v8_context, "webstore"); |
| 1039 break; |
| 1040 case Feature::BLESSED_EXTENSION_CONTEXT: |
| 1041 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| 1042 case Feature::CONTENT_SCRIPT_CONTEXT: |
| 1043 if (extension && !extension->is_platform_app()) |
| 1044 module_system->Require("miscellaneous_bindings"); |
| 1045 module_system->Require("json"); // see paranoid comment in json.js |
1036 | 1046 |
1037 RegisterSchemaGeneratedBindings(module_system.get(), context); | 1047 // TODO(kalman): move this code back out of the switch and execute it |
| 1048 // regardless of |context_type|. ExtensionAPI knows how to return the |
| 1049 // correct APIs, however, until it doesn't have a 2MB overhead we can't |
| 1050 // load it in every process. |
| 1051 RegisterSchemaGeneratedBindings(module_system.get(), context); |
| 1052 break; |
| 1053 } |
1038 | 1054 |
1039 bool is_within_platform_app = IsWithinPlatformApp(frame); | 1055 bool is_within_platform_app = IsWithinPlatformApp(frame); |
1040 // Inject custom JS into the platform app context. | 1056 // Inject custom JS into the platform app context. |
1041 if (is_within_platform_app) | 1057 if (is_within_platform_app) |
1042 module_system->Require("platformApp"); | 1058 module_system->Require("platformApp"); |
1043 | 1059 |
1044 // Only platform apps support the <webview> tag, because the "webView" and | 1060 // Only platform apps support the <webview> tag, because the "webView" and |
1045 // "denyWebView" modules will affect the performance of DOM modifications | 1061 // "denyWebView" modules will affect the performance of DOM modifications |
1046 // (http://crbug.com/196453). | 1062 // (http://crbug.com/196453). |
1047 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && | 1063 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1426 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1411 v8::ThrowException( | 1427 v8::ThrowException( |
1412 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1428 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1413 return false; | 1429 return false; |
1414 } | 1430 } |
1415 | 1431 |
1416 return true; | 1432 return true; |
1417 } | 1433 } |
1418 | 1434 |
1419 } // namespace extensions | 1435 } // namespace extensions |
OLD | NEW |