OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "extensions/renderer/api_bindings_system.h" | 5 #include "extensions/renderer/api_bindings_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "extensions/renderer/api_binding_hooks.h" | 10 #include "extensions/renderer/api_binding_hooks.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 *hooks_interface_out = binding->GetJSHookInterface(context); | 38 *hooks_interface_out = binding->GetJSHookInterface(context); |
39 return binding->CreateInstance( | 39 return binding->CreateInstance( |
40 context, isolate, &event_handler_, is_available); | 40 context, isolate, &event_handler_, is_available); |
41 } | 41 } |
42 | 42 |
43 std::unique_ptr<APIBinding> APIBindingsSystem::CreateNewAPIBinding( | 43 std::unique_ptr<APIBinding> APIBindingsSystem::CreateNewAPIBinding( |
44 const std::string& api_name) { | 44 const std::string& api_name) { |
45 const base::DictionaryValue& api_schema = get_api_schema_.Run(api_name); | 45 const base::DictionaryValue& api_schema = get_api_schema_.Run(api_name); |
46 | 46 |
47 const base::ListValue* function_definitions = nullptr; | 47 const base::ListValue* function_definitions = nullptr; |
48 CHECK(api_schema.GetList("functions", &function_definitions)); | 48 api_schema.GetList("functions", &function_definitions); |
49 const base::ListValue* type_definitions = nullptr; | 49 const base::ListValue* type_definitions = nullptr; |
50 // Type definitions might not exist for the given API. | |
51 api_schema.GetList("types", &type_definitions); | 50 api_schema.GetList("types", &type_definitions); |
52 const base::ListValue* event_definitions = nullptr; | 51 const base::ListValue* event_definitions = nullptr; |
53 api_schema.GetList("events", &event_definitions); | 52 api_schema.GetList("events", &event_definitions); |
54 | 53 |
55 // Find the hooks for the API. If none exist, an empty set will be created so | 54 // Find the hooks for the API. If none exist, an empty set will be created so |
56 // we can use JS custom bindings. | 55 // we can use JS custom bindings. |
57 // TODO(devlin): Once all legacy custom bindings are converted, we don't have | 56 // TODO(devlin): Once all legacy custom bindings are converted, we don't have |
58 // to unconditionally pass in binding hooks. | 57 // to unconditionally pass in binding hooks. |
59 std::unique_ptr<APIBindingHooks> hooks; | 58 std::unique_ptr<APIBindingHooks> hooks; |
60 auto iter = binding_hooks_.find(api_name); | 59 auto iter = binding_hooks_.find(api_name); |
61 if (iter != binding_hooks_.end()) { | 60 if (iter != binding_hooks_.end()) { |
62 hooks = std::move(iter->second); | 61 hooks = std::move(iter->second); |
63 binding_hooks_.erase(iter); | 62 binding_hooks_.erase(iter); |
64 } else { | 63 } else { |
65 hooks = base::MakeUnique<APIBindingHooks>(call_js_); | 64 hooks = base::MakeUnique<APIBindingHooks>(call_js_); |
66 } | 65 } |
67 | 66 |
68 return base::MakeUnique<APIBinding>( | 67 return base::MakeUnique<APIBinding>( |
69 api_name, *function_definitions, type_definitions, event_definitions, | 68 api_name, function_definitions, type_definitions, event_definitions, |
70 base::Bind(&APIBindingsSystem::OnAPICall, base::Unretained(this)), | 69 base::Bind(&APIBindingsSystem::OnAPICall, base::Unretained(this)), |
71 std::move(hooks), &type_reference_map_); | 70 std::move(hooks), &type_reference_map_); |
72 } | 71 } |
73 | 72 |
74 void APIBindingsSystem::CompleteRequest(int request_id, | 73 void APIBindingsSystem::CompleteRequest(int request_id, |
75 const base::ListValue& response) { | 74 const base::ListValue& response) { |
76 request_handler_.CompleteRequest(request_id, response); | 75 request_handler_.CompleteRequest(request_id, response); |
77 } | 76 } |
78 | 77 |
79 void APIBindingsSystem::FireEventInContext(const std::string& event_name, | 78 void APIBindingsSystem::FireEventInContext(const std::string& event_name, |
(...skipping 25 matching lines...) Expand all Loading... |
105 } | 104 } |
106 // TODO(devlin): Query and curry user gestures around. | 105 // TODO(devlin): Query and curry user gestures around. |
107 request->has_user_gesture = false; | 106 request->has_user_gesture = false; |
108 request->arguments = std::move(arguments); | 107 request->arguments = std::move(arguments); |
109 request->method_name = name; | 108 request->method_name = name; |
110 | 109 |
111 send_request_.Run(std::move(request), context); | 110 send_request_.Run(std::move(request), context); |
112 } | 111 } |
113 | 112 |
114 } // namespace extensions | 113 } // namespace extensions |
OLD | NEW |