OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 UnregisterContext(it, true); | 280 UnregisterContext(it, true); |
281 return; | 281 return; |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 NOTREACHED(); | 285 NOTREACHED(); |
286 } | 286 } |
287 | 287 |
288 void EventBindings::HandleContextCreated( | 288 void EventBindings::HandleContextCreated( |
289 WebFrame* frame, | 289 WebFrame* frame, |
290 bool content_script, | 290 v8::Handle<v8::Context> context, |
291 ExtensionDispatcher* extension_dispatcher) { | 291 ExtensionDispatcher* extension_dispatcher, |
292 int isolated_world_id) { | |
292 if (!bindings_registered) | 293 if (!bindings_registered) |
293 return; | 294 return; |
294 | 295 |
296 bool content_script = isolated_world_id == 0; | |
297 | |
295 v8::HandleScope handle_scope; | 298 v8::HandleScope handle_scope; |
296 ContextList& contexts = GetContexts(); | 299 ContextList& contexts = GetContexts(); |
297 v8::Local<v8::Context> frame_context = frame->mainWorldScriptContext(); | 300 // v8::Local<v8::Context> frame_context = frame->mainWorldScriptContext(); |
298 v8::Local<v8::Context> context = v8::Context::GetCurrent(); | 301 // v8::Local<v8::Context> context = v8::Context::GetCurrent(); |
Matt Perry
2011/08/15 22:22:18
kill dead code
| |
299 DCHECK(!context.IsEmpty()); | |
300 DCHECK(bindings_utils::FindContext(context) == contexts.end()); | |
301 | 302 |
302 // Figure out the frame's URL. If the frame is loading, use its provisional | 303 // Figure out the frame's URL. If the frame is loading, use its provisional |
303 // URL, since we get this notification before commit. | 304 // URL, since we get this notification before commit. |
304 WebDataSource* ds = frame->provisionalDataSource(); | 305 WebDataSource* ds = frame->provisionalDataSource(); |
305 if (!ds) | 306 if (!ds) |
306 ds = frame->dataSource(); | 307 ds = frame->dataSource(); |
307 GURL url = ds->request().url(); | 308 GURL url = ds->request().url(); |
308 const ExtensionSet* extensions = extension_dispatcher->extensions(); | 309 const ExtensionSet* extensions = extension_dispatcher->extensions(); |
309 std::string extension_id = extensions->GetIdByURL(url); | 310 std::string extension_id = extensions->GetIdByURL(url); |
310 | 311 |
311 if (!extensions->ExtensionBindingsAllowed(url) && | 312 if (!extensions->ExtensionBindingsAllowed(url) && |
312 !content_script) { | 313 !content_script) { |
313 // This context is a regular non-extension web page or an unprivileged | 314 // This context is a regular non-extension web page or an unprivileged |
314 // chrome app. Ignore it. We only care about content scripts and extension | 315 // chrome app. Ignore it. We only care about content scripts and extension |
315 // frames. | 316 // frames. |
316 // (Unless we're in unit tests, in which case we don't care what the URL | 317 // (Unless we're in unit tests, in which case we don't care what the URL |
317 // is). | 318 // is). |
318 DCHECK(frame_context.IsEmpty() || frame_context == context); | |
319 if (!in_unit_tests) | 319 if (!in_unit_tests) |
320 return; | 320 return; |
321 | 321 |
322 // For tests, we want the dispatchOnLoad to actually setup our bindings, | 322 // For tests, we want the dispatchOnLoad to actually setup our bindings, |
323 // so we give a fake extension id; | 323 // so we give a fake extension id; |
324 extension_id = kTestingExtensionId; | 324 extension_id = kTestingExtensionId; |
325 } | 325 } |
326 | 326 |
327 v8::Persistent<v8::Context> persistent_context = | 327 v8::Persistent<v8::Context> persistent_context = |
328 v8::Persistent<v8::Context>::New(context); | 328 v8::Persistent<v8::Context>::New(context); |
329 WebFrame* parent_frame = NULL; | 329 WebFrame* parent_frame = NULL; |
330 | 330 |
331 if (content_script) { | 331 if (content_script) { |
332 DCHECK(frame_context != context); | |
333 parent_frame = frame; | 332 parent_frame = frame; |
334 // Content script contexts can get GCed before their frame goes away, so | 333 // Content script contexts can get GCed before their frame goes away, so |
335 // set up a GC callback. | 334 // set up a GC callback. |
336 persistent_context.MakeWeak(NULL, &ContextWeakReferenceCallback); | 335 persistent_context.MakeWeak(NULL, &ContextWeakReferenceCallback); |
337 } | 336 } |
338 | 337 |
339 RenderView* render_view = NULL; | 338 RenderView* render_view = NULL; |
340 if (frame->view()) | 339 if (frame->view()) |
341 render_view = RenderView::FromWebView(frame->view()); | 340 render_view = RenderView::FromWebView(frame->view()); |
342 | 341 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 // TODO(rafaelw): Consider only doing this check if function_name == | 422 // TODO(rafaelw): Consider only doing this check if function_name == |
424 // "Event.dispatchJSON". | 423 // "Event.dispatchJSON". |
425 #ifndef NDEBUG | 424 #ifndef NDEBUG |
426 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 425 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
427 std::string error = *v8::String::AsciiValue(retval); | 426 std::string error = *v8::String::AsciiValue(retval); |
428 DCHECK(false) << error; | 427 DCHECK(false) << error; |
429 } | 428 } |
430 #endif | 429 #endif |
431 } | 430 } |
432 } | 431 } |
OLD | NEW |