| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 { | 348 { |
| 349 const V8Extensions& extensions = registeredExtensions(); | 349 const V8Extensions& extensions = registeredExtensions(); |
| 350 for (size_t i = 0; i < extensions.size(); ++i) { | 350 for (size_t i = 0; i < extensions.size(); ++i) { |
| 351 if (extensions[i] == extension) | 351 if (extensions[i] == extension) |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 v8::RegisterExtension(extension); | 354 v8::RegisterExtension(extension); |
| 355 registeredExtensions().append(extension); | 355 registeredExtensions().append(extension); |
| 356 } | 356 } |
| 357 | 357 |
| 358 static NPObject* createNoScriptObject() | 358 static NPObject* createNoScriptValue() |
| 359 { | 359 { |
| 360 notImplemented(); | 360 notImplemented(); |
| 361 return 0; | 361 return 0; |
| 362 } | 362 } |
| 363 | 363 |
| 364 static NPObject* createScriptObject(LocalFrame* frame, v8::Isolate* isolate) | 364 static NPObject* createScriptValue(LocalFrame* frame, v8::Isolate* isolate) |
| 365 { | 365 { |
| 366 v8::HandleScope handleScope(isolate); | 366 v8::HandleScope handleScope(isolate); |
| 367 v8::Handle<v8::Context> v8Context = toV8Context(isolate, frame, DOMWrapperWo
rld::mainWorld()); | 367 v8::Handle<v8::Context> v8Context = toV8Context(isolate, frame, DOMWrapperWo
rld::mainWorld()); |
| 368 if (v8Context.IsEmpty()) | 368 if (v8Context.IsEmpty()) |
| 369 return createNoScriptObject(); | 369 return createNoScriptValue(); |
| 370 | 370 |
| 371 v8::Context::Scope scope(v8Context); | 371 v8::Context::Scope scope(v8Context); |
| 372 DOMWindow* window = frame->domWindow(); | 372 DOMWindow* window = frame->domWindow(); |
| 373 v8::Handle<v8::Value> global = toV8(window, v8::Handle<v8::Object>(), v8Cont
ext->GetIsolate()); | 373 v8::Handle<v8::Value> global = toV8(window, v8::Handle<v8::Object>(), v8Cont
ext->GetIsolate()); |
| 374 ASSERT(global->IsObject()); | 374 ASSERT(global->IsObject()); |
| 375 | 375 |
| 376 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(global), windo
w, isolate); | 376 return npCreateV8ScriptValue(0, v8::Handle<v8::Object>::Cast(global), window
, isolate); |
| 377 } | 377 } |
| 378 | 378 |
| 379 NPObject* ScriptController::windowScriptNPObject() | 379 NPObject* ScriptController::windowScriptNPObject() |
| 380 { | 380 { |
| 381 if (m_windowScriptNPObject) | 381 if (m_windowScriptNPObject) |
| 382 return m_windowScriptNPObject; | 382 return m_windowScriptNPObject; |
| 383 | 383 |
| 384 if (canExecuteScripts(NotAboutToExecuteScript)) { | 384 if (canExecuteScripts(NotAboutToExecuteScript)) { |
| 385 // JavaScript is enabled, so there is a JavaScript window object. | 385 // JavaScript is enabled, so there is a JavaScript window object. |
| 386 // Return an NPObject bound to the window object. | 386 // Return an NPObject bound to the window object. |
| 387 m_windowScriptNPObject = createScriptObject(m_frame, m_isolate); | 387 m_windowScriptNPObject = createScriptValue(m_frame, m_isolate); |
| 388 _NPN_RegisterObject(m_windowScriptNPObject, 0); | 388 _NPN_RegisterObject(m_windowScriptNPObject, 0); |
| 389 } else { | 389 } else { |
| 390 // JavaScript is not enabled, so we cannot bind the NPObject to the | 390 // JavaScript is not enabled, so we cannot bind the NPObject to the |
| 391 // JavaScript window object. Instead, we create an NPObject of a | 391 // JavaScript window object. Instead, we create an NPObject of a |
| 392 // different class, one which is not bound to a JavaScript object. | 392 // different class, one which is not bound to a JavaScript object. |
| 393 m_windowScriptNPObject = createNoScriptObject(); | 393 m_windowScriptNPObject = createNoScriptValue(); |
| 394 } | 394 } |
| 395 return m_windowScriptNPObject; | 395 return m_windowScriptNPObject; |
| 396 } | 396 } |
| 397 | 397 |
| 398 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) | 398 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) |
| 399 { | 399 { |
| 400 // Can't create NPObjects when JavaScript is disabled. | 400 // Can't create NPObjects when JavaScript is disabled. |
| 401 if (!canExecuteScripts(NotAboutToExecuteScript)) | 401 if (!canExecuteScripts(NotAboutToExecuteScript)) |
| 402 return createNoScriptObject(); | 402 return createNoScriptValue(); |
| 403 | 403 |
| 404 v8::HandleScope handleScope(m_isolate); | 404 v8::HandleScope handleScope(m_isolate); |
| 405 v8::Handle<v8::Context> v8Context = toV8Context(m_isolate, m_frame, DOMWrapp
erWorld::mainWorld()); | 405 v8::Handle<v8::Context> v8Context = toV8Context(m_isolate, m_frame, DOMWrapp
erWorld::mainWorld()); |
| 406 if (v8Context.IsEmpty()) | 406 if (v8Context.IsEmpty()) |
| 407 return createNoScriptObject(); | 407 return createNoScriptValue(); |
| 408 v8::Context::Scope scope(v8Context); | 408 v8::Context::Scope scope(v8Context); |
| 409 | 409 |
| 410 DOMWindow* window = m_frame->domWindow(); | 410 DOMWindow* window = m_frame->domWindow(); |
| 411 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); | 411 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); |
| 412 if (!v8plugin->IsObject()) | 412 if (!v8plugin->IsObject()) |
| 413 return createNoScriptObject(); | 413 return createNoScriptValue(); |
| 414 | 414 |
| 415 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), win
dow, v8Context->GetIsolate()); | 415 return npCreateV8ScriptValue(0, v8::Handle<v8::Object>::Cast(v8plugin), wind
ow, v8Context->GetIsolate()); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void ScriptController::clearWindowShell() | 418 void ScriptController::clearWindowShell() |
| 419 { | 419 { |
| 420 double start = currentTime(); | 420 double start = currentTime(); |
| 421 // V8 binding expects ScriptController::clearWindowShell only be called | 421 // V8 binding expects ScriptController::clearWindowShell only be called |
| 422 // when a frame is loading a new page. This creates a new context for the ne
w page. | 422 // when a frame is loading a new page. This creates a new context for the ne
w page. |
| 423 m_windowShell->clearForNavigation(); | 423 m_windowShell->clearForNavigation(); |
| 424 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 424 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) |
| 425 iter->value->clearForNavigation(); | 425 iter->value->clearForNavigation(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 resultArray->Set(i, evaluationResult); | 616 resultArray->Set(i, evaluationResult); |
| 617 } | 617 } |
| 618 | 618 |
| 619 if (results) { | 619 if (results) { |
| 620 for (size_t i = 0; i < resultArray->Length(); ++i) | 620 for (size_t i = 0; i < resultArray->Length(); ++i) |
| 621 results->append(ScriptValue(ScriptState::from(context), resultArray-
>Get(i))); | 621 results->append(ScriptValue(ScriptState::from(context), resultArray-
>Get(i))); |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 | 624 |
| 625 } // namespace WebCore | 625 } // namespace WebCore |
| OLD | NEW |