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

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

Issue 12522004: Lazily load extension API schemas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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/api_definitions_natives.h" 5 #include "chrome/renderer/extensions/api_definitions_natives.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "chrome/common/extensions/api/extension_api.h"
10
9 namespace { 11 namespace {
10 const char kInvalidExtensionNamespace[] = "Invalid extension namespace"; 12 const char kInvalidExtensionNamespace[] = "Invalid extension namespace";
11 } 13 }
12 14
13 namespace extensions { 15 namespace extensions {
14 16
15 ApiDefinitionsNatives::ApiDefinitionsNatives(Dispatcher* dispatcher, 17 ApiDefinitionsNatives::ApiDefinitionsNatives(Dispatcher* dispatcher,
16 ChromeV8Context* context) 18 ChromeV8Context* context)
17 : ChromeV8Extension(dispatcher, context->v8_context()), 19 : ChromeV8Extension(dispatcher, context->v8_context()),
18 context_(context) { 20 context_(context) {
19 RouteFunction("GetExtensionAPIDefinition", 21 RouteFunction("GetExtensionAPIDefinitions",
20 base::Bind(&ApiDefinitionsNatives::GetExtensionAPIDefinition, 22 base::Bind(&ApiDefinitionsNatives::GetExtensionAPIDefinitions,
21 base::Unretained(this))); 23 base::Unretained(this)));
22 } 24 }
23 25
24 v8::Handle<v8::Value> ApiDefinitionsNatives::GetExtensionAPIDefinition( 26 v8::Handle<v8::Value> ApiDefinitionsNatives::GetExtensionAPIDefinitions(
25 const v8::Arguments& args) { 27 const v8::Arguments& args) {
26 std::set<std::string> available_apis(context_->GetAvailableExtensionAPIs()); 28 return dispatcher()->v8_schema_registry()->GetSchemas(
27 if (args.Length() == 0) 29 ExtensionAPI::GetSharedInstance()->GetAllAPINames());
28 return dispatcher()->v8_schema_registry()->GetSchemas(available_apis);
29
30 // Build set of APIs requested by the user.
31 std::set<std::string> requested_apis;
32 for (int i = 0; i < args.Length(); ++i) {
33 if (!args[i]->IsString()) {
34 v8::ThrowException(v8::String::New(kInvalidExtensionNamespace));
35 return v8::Undefined();
36 }
37 requested_apis.insert(*v8::String::Utf8Value(args[i]->ToString()));
38 }
39
40 // Filter those that are unknown.
41 std::set<std::string> apis_to_check;
42 std::set_intersection(requested_apis.begin(), requested_apis.end(),
43 available_apis.begin(), available_apis.end(),
44 std::inserter(apis_to_check, apis_to_check.begin()));
45 return dispatcher()->v8_schema_registry()->GetSchemas(apis_to_check);
46 } 30 }
47 31
48 } // namespace extensions 32 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/api_definitions_natives.h ('k') | chrome/renderer/extensions/chrome_v8_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698