Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: chrome/renderer/extensions/custom_bindings_util.cc

Issue 9460002: Convert app_bindings.js to the schema_generated_bindings.js infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: aa comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/common/extensions/api/extension_api.h" 11 #include "chrome/common/extensions/api/extension_api.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/renderer/extensions/app_bindings.h"
13 #include "chrome/renderer/extensions/chrome_v8_extension.h" 14 #include "chrome/renderer/extensions/chrome_v8_extension.h"
14 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h" 15 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h"
15 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" 16 #include "chrome/renderer/extensions/context_menus_custom_bindings.h"
16 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h" 17 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h"
17 #include "chrome/renderer/extensions/extension_custom_bindings.h" 18 #include "chrome/renderer/extensions/extension_custom_bindings.h"
18 #include "chrome/renderer/extensions/extension_dispatcher.h" 19 #include "chrome/renderer/extensions/extension_dispatcher.h"
19 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" 20 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h"
20 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" 21 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h"
21 #include "chrome/renderer/extensions/i18n_custom_bindings.h" 22 #include "chrome/renderer/extensions/i18n_custom_bindings.h"
22 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" 23 #include "chrome/renderer/extensions/page_actions_custom_bindings.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 static const size_t kResourceIDsSize = arraysize(kResourceIDs); 66 static const size_t kResourceIDsSize = arraysize(kResourceIDs);
66 67
67 static const char* kDependencies[] = { 68 static const char* kDependencies[] = {
68 "extensions/schema_generated_bindings.js", 69 "extensions/schema_generated_bindings.js",
69 }; 70 };
70 static const size_t kDependencyCount = arraysize(kDependencies); 71 static const size_t kDependencyCount = arraysize(kDependencies);
71 72
72 std::vector<v8::Extension*> result; 73 std::vector<v8::Extension*> result;
73 74
74 // Custom bindings that have native code parts. 75 // Custom bindings that have native code parts.
76 result.push_back(new AppBindings(
77 kDependencyCount, kDependencies, extension_dispatcher));
75 result.push_back(new ChromePrivateCustomBindings( 78 result.push_back(new ChromePrivateCustomBindings(
76 kDependencyCount, kDependencies, extension_dispatcher)); 79 kDependencyCount, kDependencies, extension_dispatcher));
77 result.push_back(new ContextMenusCustomBindings( 80 result.push_back(new ContextMenusCustomBindings(
78 kDependencyCount, kDependencies)); 81 kDependencyCount, kDependencies));
79 result.push_back(new ExtensionCustomBindings( 82 result.push_back(new ExtensionCustomBindings(
80 kDependencyCount, kDependencies, extension_dispatcher)); 83 kDependencyCount, kDependencies, extension_dispatcher));
81 result.push_back(new ExperimentalSocketCustomBindings( 84 result.push_back(new ExperimentalSocketCustomBindings(
82 kDependencyCount, kDependencies)); 85 kDependencyCount, kDependencies));
83 result.push_back(new FileBrowserHandlerCustomBindings( 86 result.push_back(new FileBrowserHandlerCustomBindings(
84 kDependencyCount, kDependencies)); 87 kDependencyCount, kDependencies));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } else { 145 } else {
143 camelcase.push_back(*it); 146 camelcase.push_back(*it);
144 } 147 }
145 } 148 }
146 149
147 return camelcase; 150 return camelcase;
148 } 151 }
149 152
150 bool AllowAPIInjection(const std::string& api_name, 153 bool AllowAPIInjection(const std::string& api_name,
151 const Extension& extension, 154 const Extension& extension,
152 ExtensionDispatcher* extension_dispatcher) { 155 ChromeV8Context::ContextType context_type) {
153 CHECK(api_name != ""); 156 CHECK(api_name != "");
154 157
155 // As in ExtensionAPI::GetSchemasForExtension, we need to allow any bindings 158 // As in ExtensionAPI::GetSchemasForExtension, we need to allow any bindings
156 // for an API that the extension *might* have permission to use. 159 // for an API that the extension *might* have permission to use.
157 bool allowed = 160 bool allowed =
158 extension.required_permission_set()->HasAnyAccessToAPI(api_name) || 161 extension.required_permission_set()->HasAnyAccessToAPI(api_name) ||
159 extension.optional_permission_set()->HasAnyAccessToAPI(api_name); 162 extension.optional_permission_set()->HasAnyAccessToAPI(api_name);
160 163
161 if (extension_dispatcher->is_extension_process()) { 164 switch (context_type) {
162 return allowed; 165 case ChromeV8Context::PRIVILEGED:
163 } else { 166 return allowed;
164 return allowed && 167
165 !ExtensionAPI::GetInstance()->IsWholeAPIPrivileged(api_name); 168 case ChromeV8Context::CONTENT_SCRIPT:
169 case ChromeV8Context::UNPRIVILEGED:
170 return allowed &&
171 !ExtensionAPI::GetInstance()->IsWholeAPIPrivileged(api_name);
172
173 case ChromeV8Context::WEB_PAGE:
174 NOTREACHED();
166 } 175 }
176
177 return false;
167 } 178 }
168 179
169 } // namespace custom_bindings_util 180 } // namespace custom_bindings_util
170 181
171 } // namespace extensions 182 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698