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 }; | |
48 static const size_t kJavascriptFilesSize = arraysize(kJavascriptFiles); | |
49 | |
50 // Must match kJavascriptFiles. | |
51 static const int kResourceIDs[] = { | |
52 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS, | |
53 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS, | |
54 IDR_EXPERIMENTAL_DECLARATIVE_CUSTOM_BINDINGS_JS, | |
55 IDR_DEVTOOLS_CUSTOM_BINDINGS_JS, | |
56 IDR_INPUT_IME_CUSTOM_BINDINGS_JS, | |
57 IDR_OMNIBOX_CUSTOM_BINDINGS_JS, | |
58 IDR_PAGE_ACTION_CUSTOM_BINDINGS_JS, | |
59 IDR_STORAGE_CUSTOM_BINDINGS_JS, | |
60 IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS, | |
61 IDR_TYPES_CUSTOM_BINDINGS_JS, | |
62 }; | |
63 static const size_t kResourceIDsSize = arraysize(kResourceIDs); | |
64 | |
65 static const char* kDependencies[] = { | |
66 "extensions/schema_generated_bindings.js", | |
67 }; | |
68 static const size_t kDependencyCount = arraysize(kDependencies); | |
69 | |
70 std::vector<v8::Extension*> result; | |
71 | |
72 // Custom bindings that have native code parts. | |
73 result.push_back(new ChromePrivateCustomBindings( | |
74 kDependencyCount, kDependencies, extension_dispatcher)); | |
75 result.push_back(new ContextMenusCustomBindings( | |
76 kDependencyCount, kDependencies)); | |
77 result.push_back(new ExtensionCustomBindings( | |
78 kDependencyCount, kDependencies, extension_dispatcher)); | |
79 result.push_back(new ExperimentalSocketCustomBindings( | |
80 kDependencyCount, kDependencies)); | |
81 result.push_back(new FileBrowserHandlerCustomBindings( | |
82 kDependencyCount, kDependencies)); | |
83 result.push_back(new FileBrowserPrivateCustomBindings( | |
84 kDependencyCount, kDependencies)); | |
85 result.push_back(new I18NCustomBindings( | |
86 kDependencyCount, kDependencies)); | |
87 result.push_back(new PageActionsCustomBindings( | |
88 kDependencyCount, kDependencies, extension_dispatcher)); | |
89 result.push_back(new PageCaptureCustomBindings( | |
90 kDependencyCount, kDependencies)); | |
91 result.push_back(new TabsCustomBindings( | |
92 kDependencyCount, kDependencies)); | |
93 result.push_back(new TTSCustomBindings( | |
94 kDependencyCount, kDependencies)); | |
95 result.push_back(new WebRequestCustomBindings( | |
96 kDependencyCount, kDependencies)); | |
97 | |
98 // Pure JavaScript custom bindings. | |
99 CHECK_EQ(kJavascriptFilesSize, kResourceIDsSize); | |
100 for (size_t i = 0; i < kJavascriptFilesSize; ++i) { | |
101 result.push_back(new ChromeV8Extension( | |
102 kJavascriptFiles[i], | |
103 kResourceIDs[i], | |
104 kDependencyCount, kDependencies, | |
105 NULL)); | |
106 } | |
107 | |
108 return result; | |
109 } | |
110 | |
111 // 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 |
112 // custom bindings for it (see kCustomBindingNames). | 35 // custom bindings for it (see kCustomBindingNames). |
113 std::string GetAPIName(const std::string& v8_extension_name) { | 36 std::string GetAPIName(const std::string& v8_extension_name) { |
114 // Extract the name of the API from the v8 extension name. | 37 // Extract the name of the API from the v8 extension name. |
115 // This is "${api_name}" in "extensions/${api_name}_custom_bindings.js". | 38 // This is "${api_name}" in "extensions/${api_name}_custom_bindings.js". |
116 std::string prefix = "extensions/"; | 39 std::string prefix = "extensions/"; |
117 const bool kCaseSensitive = true; | 40 const bool kCaseSensitive = true; |
118 if (!StartsWithASCII(v8_extension_name, prefix, kCaseSensitive)) | 41 if (!StartsWithASCII(v8_extension_name, prefix, kCaseSensitive)) |
119 return ""; | 42 return ""; |
120 | 43 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 return allowed; | 83 return allowed; |
161 } else { | 84 } else { |
162 return allowed && | 85 return allowed && |
163 !ExtensionAPI::GetInstance()->IsWholeAPIPrivileged(api_name); | 86 !ExtensionAPI::GetInstance()->IsWholeAPIPrivileged(api_name); |
164 } | 87 } |
165 } | 88 } |
166 | 89 |
167 } // namespace custom_bindings_util | 90 } // namespace custom_bindings_util |
168 | 91 |
169 } // namespace extensions | 92 } // namespace extensions |
OLD | NEW |