| 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/schema_generated_bindings.h" | 5 #include "chrome/renderer/extensions/schema_generated_bindings.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } else { | 153 } else { |
| 154 ExtensionAPI::GetInstance()->GetSchemasForExtension(*extension, &schemas); | 154 ExtensionAPI::GetInstance()->GetSchemasForExtension(*extension, &schemas); |
| 155 } | 155 } |
| 156 | 156 |
| 157 v8::Persistent<v8::Context> context(v8::Context::New()); | 157 v8::Persistent<v8::Context> context(v8::Context::New()); |
| 158 v8::Context::Scope context_scope(context); | 158 v8::Context::Scope context_scope(context); |
| 159 v8::Handle<v8::Array> api(v8::Array::New(schemas.size())); | 159 v8::Handle<v8::Array> api(v8::Array::New(schemas.size())); |
| 160 size_t api_index = 0; | 160 size_t api_index = 0; |
| 161 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin(); | 161 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin(); |
| 162 it != schemas.end(); ++it) { | 162 it != schemas.end(); ++it) { |
| 163 api->Set(api_index, GetV8SchemaForAPI(self, context, it->first)); | 163 std::string api_name = it->first; |
| 164 // For content scripts, only allow APIs that have unprivileged components. |
| 165 if (v8_context->is_content_script() && |
| 166 ExtensionAPI::GetInstance()->IsWholeAPIPrivileged(api_name)) { |
| 167 continue; |
| 168 } |
| 169 api->Set(api_index, GetV8SchemaForAPI(self, context, api_name)); |
| 164 ++api_index; | 170 ++api_index; |
| 165 } | 171 } |
| 166 | 172 |
| 167 // The persistent extension_api_ will keep the context alive. | 173 // The persistent extension_api_ will keep the context alive. |
| 168 context.Dispose(); | 174 context.Dispose(); |
| 169 | 175 |
| 170 return api; | 176 return api; |
| 171 } | 177 } |
| 172 | 178 |
| 173 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { | 179 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 const std::string& extension_id) { | 412 const std::string& extension_id) { |
| 407 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); | 413 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); |
| 408 it != g_pending_requests.Get().end(); ++it) { | 414 it != g_pending_requests.Get().end(); ++it) { |
| 409 if (it->second->extension_id == extension_id) | 415 if (it->second->extension_id == extension_id) |
| 410 return true; | 416 return true; |
| 411 } | 417 } |
| 412 return false; | 418 return false; |
| 413 } | 419 } |
| 414 | 420 |
| 415 } // namespace | 421 } // namespace |
| OLD | NEW |