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

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

Issue 152003: Fix some issues with extension messaging: (Closed)
Patch Set: Created 11 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/event_bindings.h" 5 #include "chrome/renderer/extensions/event_bindings.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 GURL url = frame->GetView()->GetMainFrame()->GetURL(); 138 GURL url = frame->GetView()->GetMainFrame()->GetURL();
139 std::string extension_id; 139 std::string extension_id;
140 if (url.SchemeIs(chrome::kExtensionScheme)) 140 if (url.SchemeIs(chrome::kExtensionScheme))
141 extension_id = url.host(); 141 extension_id = url.host();
142 142
143 v8::Persistent<v8::Context> persistent_context = 143 v8::Persistent<v8::Context> persistent_context =
144 v8::Persistent<v8::Context>::New(context); 144 v8::Persistent<v8::Context>::New(context);
145 GetContexts().push_back(linked_ptr<ContextInfo>( 145 GetContexts().push_back(linked_ptr<ContextInfo>(
146 new ContextInfo(persistent_context, extension_id))); 146 new ContextInfo(persistent_context, extension_id)));
147
148 v8::Handle<v8::Value> argv[1];
149 argv[0] = v8::String::New(extension_id.c_str());
150 CallFunctionInContext(context, "dispatchOnLoad", arraysize(argv), argv);
147 } 151 }
148 152
149 // static 153 // static
150 void EventBindings::HandleContextDestroyed(WebFrame* frame) { 154 void EventBindings::HandleContextDestroyed(WebFrame* frame) {
151 if (!bindings_registered) 155 if (!bindings_registered)
152 return; 156 return;
153 157
154 v8::HandleScope handle_scope; 158 v8::HandleScope handle_scope;
155 v8::Local<v8::Context> context = frame->GetScriptContext(); 159 v8::Local<v8::Context> context = frame->GetScriptContext();
156 DCHECK(!context.IsEmpty()); 160 DCHECK(!context.IsEmpty());
(...skipping 18 matching lines...) Expand all
175 179
176 // Remove it from our registered contexts. 180 // Remove it from our registered contexts.
177 (*it)->context.Dispose(); 181 (*it)->context.Dispose();
178 (*it)->context.Clear(); 182 (*it)->context.Clear();
179 GetContexts().erase(it); 183 GetContexts().erase(it);
180 } 184 }
181 185
182 // static 186 // static
183 void EventBindings::CallFunction(const std::string& function_name, 187 void EventBindings::CallFunction(const std::string& function_name,
184 int argc, v8::Handle<v8::Value>* argv) { 188 int argc, v8::Handle<v8::Value>* argv) {
185 v8::HandleScope handle_scope;
186 for (ContextList::iterator it = GetContexts().begin(); 189 for (ContextList::iterator it = GetContexts().begin();
187 it != GetContexts().end(); ++it) { 190 it != GetContexts().end(); ++it) {
188 CallFunctionInContext((*it)->context, function_name, argc, argv); 191 CallFunctionInContext((*it)->context, function_name, argc, argv);
189 } 192 }
190 } 193 }
191 194
192 // static 195 // static
193 void EventBindings::HandleResponse(int request_id, bool success, 196 void EventBindings::HandleResponse(int request_id, bool success,
194 const std::string& response, 197 const std::string& response,
195 const std::string& error) { 198 const std::string& error) {
196 PendingRequest* request = GetPendingRequestMap()[request_id].get(); 199 PendingRequest* request = GetPendingRequestMap()[request_id].get();
197 if (!request) 200 if (!request)
198 return; // The frame went away. 201 return; // The frame went away.
199 202
200 v8::HandleScope handle_scope; 203 v8::HandleScope handle_scope;
201 v8::Handle<v8::Value> argv[5]; 204 v8::Handle<v8::Value> argv[5];
202 argv[0] = v8::Integer::New(request_id); 205 argv[0] = v8::Integer::New(request_id);
203 argv[1] = v8::String::New(request->name.c_str()); 206 argv[1] = v8::String::New(request->name.c_str());
204 argv[2] = v8::Boolean::New(success); 207 argv[2] = v8::Boolean::New(success);
205 argv[3] = v8::String::New(response.c_str()); 208 argv[3] = v8::String::New(response.c_str());
206 argv[4] = v8::String::New(error.c_str()); 209 argv[4] = v8::String::New(error.c_str());
207 CallFunctionInContext( 210 CallFunctionInContext(
208 request->context, "handleResponse", arraysize(argv), argv); 211 request->context, "handleResponse", arraysize(argv), argv);
209 212
210 GetPendingRequestMap().erase(request_id); 213 GetPendingRequestMap().erase(request_id);
211 } 214 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_messages_unittest.cc ('k') | chrome/renderer/renderer_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698