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

Side by Side Diff: extensions/renderer/native_extension_bindings_system.cc

Issue 2512233002: [Extensions Bindings] Add ExtensionBindingsSystem interface; hook it up (Closed)
Patch Set: lazyboys Created 4 years, 1 month 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
OLDNEW
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/native_extension_bindings_system.h" 5 #include "extensions/renderer/native_extension_bindings_system.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "content/public/common/content_switches.h" 8 #include "content/public/common/content_switches.h"
9 #include "extensions/common/constants.h" 9 #include "extensions/common/constants.h"
10 #include "extensions/common/extension_api.h" 10 #include "extensions/common/extension_api.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 NativeExtensionBindingsSystem::NativeExtensionBindingsSystem( 84 NativeExtensionBindingsSystem::NativeExtensionBindingsSystem(
85 const SendIPCMethod& send_ipc) 85 const SendIPCMethod& send_ipc)
86 : send_ipc_(send_ipc), 86 : send_ipc_(send_ipc),
87 api_system_(base::Bind(&CallJsFunction), 87 api_system_(base::Bind(&CallJsFunction),
88 base::Bind(&GetAPISchema), 88 base::Bind(&GetAPISchema),
89 base::Bind(&NativeExtensionBindingsSystem::SendRequest, 89 base::Bind(&NativeExtensionBindingsSystem::SendRequest,
90 base::Unretained(this))) {} 90 base::Unretained(this))) {}
91 91
92 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {} 92 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {}
93 93
94 void NativeExtensionBindingsSystem::CreateAPIsInContext( 94 void NativeExtensionBindingsSystem::DidCreateScriptContext(
95 ScriptContext* context) {}
96
97 void NativeExtensionBindingsSystem::WillReleaseScriptContext(
98 ScriptContext* context) {}
99
100 void NativeExtensionBindingsSystem::UpdateBindingsForContext(
95 ScriptContext* context) { 101 ScriptContext* context) {
96 v8::Local<v8::Context> v8_context = context->v8_context(); 102 v8::Local<v8::Context> v8_context = context->v8_context();
97 v8::Local<v8::Object> chrome = GetOrCreateChrome(v8_context); 103 v8::Local<v8::Object> chrome = GetOrCreateChrome(v8_context);
98 if (chrome.IsEmpty()) 104 if (chrome.IsEmpty())
99 return; 105 return;
100 106
101 const FeatureProvider* api_feature_provider = 107 const FeatureProvider* api_feature_provider =
102 FeatureProvider::GetAPIFeatures(); 108 FeatureProvider::GetAPIFeatures();
103 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { 109 for (const auto& map_entry : api_feature_provider->GetAllFeatures()) {
104 // Internal APIs are included via require(api_name) from internal code 110 // Internal APIs are included via require(api_name) from internal code
(...skipping 24 matching lines...) Expand all
129 v8_context, 135 v8_context,
130 gin::StringToSymbol(v8_context->GetIsolate(), map_entry.first), 136 gin::StringToSymbol(v8_context->GetIsolate(), map_entry.first),
131 api_object); 137 api_object);
132 if (!success.IsJust() || !success.FromJust()) { 138 if (!success.IsJust() || !success.FromJust()) {
133 LOG(ERROR) << "Failed to create API on Chrome object."; 139 LOG(ERROR) << "Failed to create API on Chrome object.";
134 return; 140 return;
135 } 141 }
136 } 142 }
137 } 143 }
138 144
139 void NativeExtensionBindingsSystem::OnResponse(int request_id, 145 void NativeExtensionBindingsSystem::DispatchEventInContext(
140 bool success, 146 const std::string& event_name,
141 const base::ListValue& response, 147 const base::ListValue* event_args,
142 const std::string& error) { 148 const base::DictionaryValue* filtering_info,
149 ScriptContext* context) {
150 v8::HandleScope handle_scope(context->isolate());
151 v8::Context::Scope context_scope(context->v8_context());
152 // TODO(devlin): Take into account |filtering_info|.
153 api_system_.FireEventInContext(event_name, context->v8_context(),
154 *event_args);
155 }
156
157 void NativeExtensionBindingsSystem::HandleResponse(
158 int request_id,
159 bool success,
160 const base::ListValue& response,
161 const std::string& error) {
143 api_system_.CompleteRequest(request_id, response); 162 api_system_.CompleteRequest(request_id, response);
144 } 163 }
145 164
165 RequestSender* NativeExtensionBindingsSystem::GetRequestSender() {
166 return nullptr;
167 }
168
146 void NativeExtensionBindingsSystem::SendRequest( 169 void NativeExtensionBindingsSystem::SendRequest(
147 std::unique_ptr<APIBindingsSystem::Request> request, 170 std::unique_ptr<APIBindingsSystem::Request> request,
148 v8::Local<v8::Context> context) { 171 v8::Local<v8::Context> context) {
149 ScriptContext* script_context = 172 ScriptContext* script_context =
150 ScriptContextSet::GetContextByV8Context(context); 173 ScriptContextSet::GetContextByV8Context(context);
151 174
152 GURL url; 175 GURL url;
153 blink::WebLocalFrame* frame = script_context->web_frame(); 176 blink::WebLocalFrame* frame = script_context->web_frame();
154 if (frame && !frame->document().isNull()) 177 if (frame && !frame->document().isNull())
155 url = frame->document().url(); 178 url = frame->document().url();
(...skipping 18 matching lines...) Expand all
174 params.has_callback = request->has_callback; 197 params.has_callback = request->has_callback;
175 params.user_gesture = request->has_user_gesture; 198 params.user_gesture = request->has_user_gesture;
176 // TODO(devlin): Make this work in ServiceWorkers. 199 // TODO(devlin): Make this work in ServiceWorkers.
177 params.worker_thread_id = -1; 200 params.worker_thread_id = -1;
178 params.service_worker_version_id = kInvalidServiceWorkerVersionId; 201 params.service_worker_version_id = kInvalidServiceWorkerVersionId;
179 202
180 send_ipc_.Run(params); 203 send_ipc_.Run(params);
181 } 204 }
182 205
183 } // namespace extensions 206 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698