| 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/custom_bindings_util.h" | 5 #include "chrome/renderer/extensions/custom_bindings_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 24 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
| 25 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 25 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
| 26 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | 26 #include "chrome/renderer/extensions/web_request_custom_bindings.h" |
| 27 #include "grit/renderer_resources.h" | 27 #include "grit/renderer_resources.h" |
| 28 #include "v8/include/v8.h" | 28 #include "v8/include/v8.h" |
| 29 | 29 |
| 30 namespace extensions { | 30 namespace extensions { |
| 31 | 31 |
| 32 namespace custom_bindings_util { | 32 namespace custom_bindings_util { |
| 33 | 33 |
| 34 std::vector<v8::Extension*> GetAll(ExtensionDispatcher* extension_dispatcher) { | |
| 35 // Must match kResourceIDs. | |
| 36 static const char* kJavascriptFiles[] = { | |
| 37 "extensions/browser_action_custom_bindings.js", | |
| 38 "extensions/content_settings_custom_bindings.js", | |
| 39 "extensions/experimental.declarative_custom_bindings.js", | |
| 40 "extensions/devtools_custom_bindings.js", | |
| 41 "extensions/input.ime_custom_bindings.js", | |
| 42 "extensions/omnibox_custom_bindings.js", | |
| 43 "extensions/page_action_custom_bindings.js", | |
| 44 "extensions/storage_custom_bindings.js", | |
| 45 "extensions/tts_engine_custom_bindings.js", | |
| 46 "extensions/types_custom_bindings.js", | |
| 47 "extensions/windows_custom_bindings.js", | |
| 48 }; | |
| 49 static const size_t kJavascriptFilesSize = arraysize(kJavascriptFiles); | |
| 50 | |
| 51 // Must match kJavascriptFiles. | |
| 52 static const int kResourceIDs[] = { | |
| 53 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS, | |
| 54 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS, | |
| 55 IDR_EXPERIMENTAL_DECLARATIVE_CUSTOM_BINDINGS_JS, | |
| 56 IDR_DEVTOOLS_CUSTOM_BINDINGS_JS, | |
| 57 IDR_INPUT_IME_CUSTOM_BINDINGS_JS, | |
| 58 IDR_OMNIBOX_CUSTOM_BINDINGS_JS, | |
| 59 IDR_PAGE_ACTION_CUSTOM_BINDINGS_JS, | |
| 60 IDR_STORAGE_CUSTOM_BINDINGS_JS, | |
| 61 IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS, | |
| 62 IDR_TYPES_CUSTOM_BINDINGS_JS, | |
| 63 IDR_WINDOWS_CUSTOM_BINDINGS_JS, | |
| 64 }; | |
| 65 static const size_t kResourceIDsSize = arraysize(kResourceIDs); | |
| 66 | |
| 67 static const char* kDependencies[] = { | |
| 68 "extensions/schema_generated_bindings.js", | |
| 69 }; | |
| 70 static const size_t kDependencyCount = arraysize(kDependencies); | |
| 71 | |
| 72 std::vector<v8::Extension*> result; | |
| 73 | |
| 74 // Custom bindings that have native code parts. | |
| 75 result.push_back(new ChromePrivateCustomBindings( | |
| 76 kDependencyCount, kDependencies, extension_dispatcher)); | |
| 77 result.push_back(new ContextMenusCustomBindings( | |
| 78 kDependencyCount, kDependencies)); | |
| 79 result.push_back(new ExtensionCustomBindings( | |
| 80 kDependencyCount, kDependencies, extension_dispatcher)); | |
| 81 result.push_back(new ExperimentalSocketCustomBindings( | |
| 82 kDependencyCount, kDependencies)); | |
| 83 result.push_back(new FileBrowserHandlerCustomBindings( | |
| 84 kDependencyCount, kDependencies)); | |
| 85 result.push_back(new FileBrowserPrivateCustomBindings( | |
| 86 kDependencyCount, kDependencies)); | |
| 87 result.push_back(new I18NCustomBindings( | |
| 88 kDependencyCount, kDependencies)); | |
| 89 result.push_back(new PageActionsCustomBindings( | |
| 90 kDependencyCount, kDependencies, extension_dispatcher)); | |
| 91 result.push_back(new PageCaptureCustomBindings( | |
| 92 kDependencyCount, kDependencies)); | |
| 93 result.push_back(new TabsCustomBindings( | |
| 94 kDependencyCount, kDependencies)); | |
| 95 result.push_back(new TTSCustomBindings( | |
| 96 kDependencyCount, kDependencies)); | |
| 97 result.push_back(new WebRequestCustomBindings( | |
| 98 kDependencyCount, kDependencies)); | |
| 99 | |
| 100 // Pure JavaScript custom bindings. | |
| 101 CHECK_EQ(kJavascriptFilesSize, kResourceIDsSize); | |
| 102 for (size_t i = 0; i < kJavascriptFilesSize; ++i) { | |
| 103 result.push_back(new ChromeV8Extension( | |
| 104 kJavascriptFiles[i], | |
| 105 kResourceIDs[i], | |
| 106 kDependencyCount, kDependencies, | |
| 107 NULL)); | |
| 108 } | |
| 109 | |
| 110 return result; | |
| 111 } | |
| 112 | |
| 113 // Extracts the name of an API from the name of the V8 extension which contains | 34 // Extracts the name of an API from the name of the V8 extension which contains |
| 114 // custom bindings for it (see kCustomBindingNames). | 35 // custom bindings for it (see kCustomBindingNames). |
| 115 std::string GetAPIName(const std::string& v8_extension_name) { | 36 std::string GetAPIName(const std::string& v8_extension_name) { |
| 116 // Extract the name of the API from the v8 extension name. | 37 // Extract the name of the API from the v8 extension name. |
| 117 // This is "${api_name}" in "extensions/${api_name}_custom_bindings.js". | 38 // This is "${api_name}" in "extensions/${api_name}_custom_bindings.js". |
| 118 std::string prefix = "extensions/"; | 39 std::string prefix = "extensions/"; |
| 119 const bool kCaseSensitive = true; | 40 const bool kCaseSensitive = true; |
| 120 if (!StartsWithASCII(v8_extension_name, prefix, kCaseSensitive)) | 41 if (!StartsWithASCII(v8_extension_name, prefix, kCaseSensitive)) |
| 121 return ""; | 42 return ""; |
| 122 | 43 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return allowed; | 83 return allowed; |
| 163 } else { | 84 } else { |
| 164 return allowed && | 85 return allowed && |
| 165 !ExtensionAPI::GetInstance()->IsWholeAPIPrivileged(api_name); | 86 !ExtensionAPI::GetInstance()->IsWholeAPIPrivileged(api_name); |
| 166 } | 87 } |
| 167 } | 88 } |
| 168 | 89 |
| 169 } // namespace custom_bindings_util | 90 } // namespace custom_bindings_util |
| 170 | 91 |
| 171 } // namespace extensions | 92 } // namespace extensions |
| OLD | NEW |