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

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

Issue 2436893002: [Extensions] Convert some callers of ModuleSystem::CallModuleMethod (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/module_system.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/messaging_bindings.h" 5 #include "extensions/renderer/messaging_bindings.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (message.user_gesture) { 206 if (message.user_gesture) {
207 web_user_gesture.reset(new blink::WebScopedUserGesture); 207 web_user_gesture.reset(new blink::WebScopedUserGesture);
208 208
209 if (script_context->web_frame()) { 209 if (script_context->web_frame()) {
210 blink::WebDocument document = script_context->web_frame()->document(); 210 blink::WebDocument document = script_context->web_frame()->document();
211 allow_window_focus.reset(new blink::WebScopedWindowFocusAllowedIndicator( 211 allow_window_focus.reset(new blink::WebScopedWindowFocusAllowedIndicator(
212 &document)); 212 &document));
213 } 213 }
214 } 214 }
215 215
216 script_context->module_system()->CallModuleMethod( 216 script_context->module_system()->CallModuleMethodSafe(
217 "messaging", "dispatchOnMessage", &arguments); 217 "messaging", "dispatchOnMessage", &arguments);
218 } 218 }
219 219
220 void DispatchOnDisconnectToScriptContext(int global_port_id, 220 void DispatchOnDisconnectToScriptContext(int global_port_id,
221 const std::string& error_message, 221 const std::string& error_message,
222 ScriptContext* script_context) { 222 ScriptContext* script_context) {
223 MessagingBindings* bindings = g_messaging_map.Get()[script_context]; 223 MessagingBindings* bindings = g_messaging_map.Get()[script_context];
224 DCHECK(bindings); 224 DCHECK(bindings);
225 ExtensionPort* port = bindings->GetPortWithGlobalId(global_port_id); 225 ExtensionPort* port = bindings->GetPortWithGlobalId(global_port_id);
226 if (!port) 226 if (!port)
227 return; 227 return;
228 228
229 v8::Isolate* isolate = script_context->isolate(); 229 v8::Isolate* isolate = script_context->isolate();
230 v8::HandleScope handle_scope(isolate); 230 v8::HandleScope handle_scope(isolate);
231 231
232 std::vector<v8::Local<v8::Value>> arguments; 232 std::vector<v8::Local<v8::Value>> arguments;
233 arguments.push_back(v8::Integer::New(isolate, port->local_id())); 233 arguments.push_back(v8::Integer::New(isolate, port->local_id()));
234 v8::Local<v8::String> v8_error_message; 234 v8::Local<v8::String> v8_error_message;
235 if (!error_message.empty()) 235 if (!error_message.empty())
236 ToV8String(isolate, error_message.c_str(), &v8_error_message); 236 ToV8String(isolate, error_message.c_str(), &v8_error_message);
237 if (!v8_error_message.IsEmpty()) { 237 if (!v8_error_message.IsEmpty()) {
238 arguments.push_back(v8_error_message); 238 arguments.push_back(v8_error_message);
239 } else { 239 } else {
240 arguments.push_back(v8::Null(isolate)); 240 arguments.push_back(v8::Null(isolate));
241 } 241 }
242 242
243 script_context->module_system()->CallModuleMethod( 243 script_context->module_system()->CallModuleMethodSafe(
244 "messaging", "dispatchOnDisconnect", &arguments); 244 "messaging", "dispatchOnDisconnect", &arguments);
245 } 245 }
246 246
247 } // namespace 247 } // namespace
248 248
249 MessagingBindings::MessagingBindings(ScriptContext* context) 249 MessagingBindings::MessagingBindings(ScriptContext* context)
250 : ObjectBackedNativeHandler(context), weak_ptr_factory_(this) { 250 : ObjectBackedNativeHandler(context), weak_ptr_factory_(this) {
251 g_messaging_map.Get()[context] = this; 251 g_messaging_map.Get()[context] = this;
252 RouteFunction("CloseChannel", base::Bind(&MessagingBindings::CloseChannel, 252 RouteFunction("CloseChannel", base::Bind(&MessagingBindings::CloseChannel,
253 base::Unretained(this))); 253 base::Unretained(this)));
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 DCHECK(iter != disconnected_ports_.end()); 553 DCHECK(iter != disconnected_ports_.end());
554 iter->second->SetGlobalId(global_id); 554 iter->second->SetGlobalId(global_id);
555 // Setting the global id dispatches pending messages, so we can delete the 555 // Setting the global id dispatches pending messages, so we can delete the
556 // port now. 556 // port now.
557 disconnected_ports_.erase(iter); 557 disconnected_ports_.erase(iter);
558 } 558 }
559 559
560 int MessagingBindings::GetNextLocalId() { return next_local_id_++; } 560 int MessagingBindings::GetNextLocalId() { return next_local_id_++; }
561 561
562 } // namespace extensions 562 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/module_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698