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 27 matching lines...) Expand all Loading... |
38 #include "ScriptCallStackFactory.h" | 38 #include "ScriptCallStackFactory.h" |
39 #include "ScriptableDocumentParser.h" | 39 #include "ScriptableDocumentParser.h" |
40 #include "DOMWindow.h" | 40 #include "DOMWindow.h" |
41 #include "Event.h" | 41 #include "Event.h" |
42 #include "EventListener.h" | 42 #include "EventListener.h" |
43 #include "EventNames.h" | 43 #include "EventNames.h" |
44 #include "Frame.h" | 44 #include "Frame.h" |
45 #include "FrameLoaderClient.h" | 45 #include "FrameLoaderClient.h" |
46 #include "Node.h" | 46 #include "Node.h" |
47 #include "NotImplemented.h" | 47 #include "NotImplemented.h" |
| 48 #include "NPObjectWrapper.h" |
48 #include "npruntime_impl.h" | 49 #include "npruntime_impl.h" |
49 #include "npruntime_priv.h" | 50 #include "npruntime_priv.h" |
50 #include "NPV8Object.h" | 51 #include "NPV8Object.h" |
51 #include "ScriptSourceCode.h" | 52 #include "ScriptSourceCode.h" |
52 #include "SecurityOrigin.h" | 53 #include "SecurityOrigin.h" |
53 #include "Settings.h" | 54 #include "Settings.h" |
54 #include "UserGestureIndicator.h" | 55 #include "UserGestureIndicator.h" |
55 #include "V8Binding.h" | 56 #include "V8Binding.h" |
56 #include "V8BindingState.h" | 57 #include "V8BindingState.h" |
57 #include "V8DOMWindow.h" | 58 #include "V8DOMWindow.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, tru
e); | 107 return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), target, tru
e); |
107 } | 108 } |
108 | 109 |
109 ScriptController::ScriptController(Frame* frame) | 110 ScriptController::ScriptController(Frame* frame) |
110 : m_frame(frame) | 111 : m_frame(frame) |
111 , m_sourceURL(0) | 112 , m_sourceURL(0) |
112 , m_inExecuteScript(false) | 113 , m_inExecuteScript(false) |
113 , m_paused(false) | 114 , m_paused(false) |
114 , m_proxy(adoptPtr(new V8Proxy(frame))) | 115 , m_proxy(adoptPtr(new V8Proxy(frame))) |
115 #if ENABLE(NETSCAPE_PLUGIN_API) | 116 #if ENABLE(NETSCAPE_PLUGIN_API) |
116 , m_windowScriptNPObject(0) | 117 , m_wrappedWindowScriptNPObject(0) |
117 #endif | 118 #endif |
118 { | 119 { |
119 } | 120 } |
120 | 121 |
121 ScriptController::~ScriptController() | 122 ScriptController::~ScriptController() |
122 { | 123 { |
123 } | 124 } |
124 | 125 |
125 void ScriptController::clearScriptObjects() | 126 void ScriptController::clearScriptObjects() |
126 { | 127 { |
127 PluginObjectMap::iterator it = m_pluginObjects.begin(); | 128 PluginObjectMap::iterator it = m_pluginObjects.begin(); |
128 for (; it != m_pluginObjects.end(); ++it) { | 129 for (; it != m_pluginObjects.end(); ++it) { |
129 _NPN_UnregisterObject(it->second); | 130 _NPN_UnregisterObject(it->second); |
130 _NPN_ReleaseObject(it->second); | 131 _NPN_ReleaseObject(it->second); |
131 } | 132 } |
132 m_pluginObjects.clear(); | 133 m_pluginObjects.clear(); |
133 | 134 |
134 #if ENABLE(NETSCAPE_PLUGIN_API) | 135 #if ENABLE(NETSCAPE_PLUGIN_API) |
135 if (m_windowScriptNPObject) { | 136 if (m_wrappedWindowScriptNPObject) { |
| 137 NPObjectWrapper* windowScriptObjectWrapper = NPObjectWrapper::getWrapper
(m_wrappedWindowScriptNPObject); |
| 138 ASSERT(windowScriptObjectWrapper); |
| 139 |
| 140 NPObject* windowScriptNPObject = NPObjectWrapper::getUnderlyingNPObject(
m_wrappedWindowScriptNPObject); |
| 141 ASSERT(windowScriptNPObject); |
136 // Call _NPN_DeallocateObject() instead of _NPN_ReleaseObject() so that
we don't leak if a plugin fails to release the window | 142 // Call _NPN_DeallocateObject() instead of _NPN_ReleaseObject() so that
we don't leak if a plugin fails to release the window |
137 // script object properly. | 143 // script object properly. |
138 // This shouldn't cause any problems for plugins since they should have
already been stopped and destroyed at this point. | 144 // This shouldn't cause any problems for plugins since they should have
already been stopped and destroyed at this point. |
139 _NPN_DeallocateObject(m_windowScriptNPObject); | 145 _NPN_DeallocateObject(windowScriptNPObject); |
140 m_windowScriptNPObject = 0; | 146 |
| 147 // Clear out the wrapped window script object pointer held by the wrappe
r. |
| 148 windowScriptObjectWrapper->clear(); |
| 149 _NPN_ReleaseObject(m_wrappedWindowScriptNPObject); |
| 150 m_wrappedWindowScriptNPObject = 0; |
141 } | 151 } |
142 #endif | 152 #endif |
143 } | 153 } |
144 | 154 |
145 void ScriptController::updateSecurityOrigin() | 155 void ScriptController::updateSecurityOrigin() |
146 { | 156 { |
147 m_proxy->windowShell()->updateSecurityOrigin(); | 157 m_proxy->windowShell()->updateSecurityOrigin(); |
148 } | 158 } |
149 | 159 |
150 void ScriptController::updatePlatformScriptObjects() | 160 void ScriptController::updatePlatformScriptObjects() |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 362 |
353 v8::Context::Scope scope(v8Context); | 363 v8::Context::Scope scope(v8Context); |
354 DOMWindow* window = frame->domWindow(); | 364 DOMWindow* window = frame->domWindow(); |
355 v8::Handle<v8::Value> global = toV8(window); | 365 v8::Handle<v8::Value> global = toV8(window); |
356 ASSERT(global->IsObject()); | 366 ASSERT(global->IsObject()); |
357 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(global), windo
w); | 367 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(global), windo
w); |
358 } | 368 } |
359 | 369 |
360 NPObject* ScriptController::windowScriptNPObject() | 370 NPObject* ScriptController::windowScriptNPObject() |
361 { | 371 { |
362 if (m_windowScriptNPObject) | 372 if (m_wrappedWindowScriptNPObject) |
363 return m_windowScriptNPObject; | 373 return m_wrappedWindowScriptNPObject; |
364 | 374 |
| 375 NPObject* windowScriptNPObject = 0; |
365 if (canExecuteScripts(NotAboutToExecuteScript)) { | 376 if (canExecuteScripts(NotAboutToExecuteScript)) { |
366 // JavaScript is enabled, so there is a JavaScript window object. | 377 // JavaScript is enabled, so there is a JavaScript window object. |
367 // Return an NPObject bound to the window object. | 378 // Return an NPObject bound to the window object. |
368 m_windowScriptNPObject = createScriptObject(m_frame); | 379 windowScriptNPObject = createScriptObject(m_frame); |
369 _NPN_RegisterObject(m_windowScriptNPObject, 0); | 380 _NPN_RegisterObject(windowScriptNPObject, 0); |
370 } else { | 381 } else { |
371 // JavaScript is not enabled, so we cannot bind the NPObject to the | 382 // JavaScript is not enabled, so we cannot bind the NPObject to the |
372 // JavaScript window object. Instead, we create an NPObject of a | 383 // JavaScript window object. Instead, we create an NPObject of a |
373 // different class, one which is not bound to a JavaScript object. | 384 // different class, one which is not bound to a JavaScript object. |
374 m_windowScriptNPObject = createNoScriptObject(); | 385 windowScriptNPObject = createNoScriptObject(); |
375 } | 386 } |
376 return m_windowScriptNPObject; | 387 |
| 388 m_wrappedWindowScriptNPObject = NPObjectWrapper::create(windowScriptNPObject
); |
| 389 return m_wrappedWindowScriptNPObject; |
377 } | 390 } |
378 | 391 |
379 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) | 392 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) |
380 { | 393 { |
381 // Can't create NPObjects when JavaScript is disabled. | 394 // Can't create NPObjects when JavaScript is disabled. |
382 if (!canExecuteScripts(NotAboutToExecuteScript)) | 395 if (!canExecuteScripts(NotAboutToExecuteScript)) |
383 return createNoScriptObject(); | 396 return createNoScriptObject(); |
384 | 397 |
385 v8::HandleScope handleScope; | 398 v8::HandleScope handleScope; |
386 v8::Handle<v8::Context> v8Context = V8Proxy::mainWorldContext(m_frame); | 399 v8::Handle<v8::Context> v8Context = V8Proxy::mainWorldContext(m_frame); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 { | 439 { |
427 m_proxy->windowShell()->namedItemAdded(doc, name); | 440 m_proxy->windowShell()->namedItemAdded(doc, name); |
428 } | 441 } |
429 | 442 |
430 void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& n
ame) | 443 void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& n
ame) |
431 { | 444 { |
432 m_proxy->windowShell()->namedItemRemoved(doc, name); | 445 m_proxy->windowShell()->namedItemRemoved(doc, name); |
433 } | 446 } |
434 | 447 |
435 } // namespace WebCore | 448 } // namespace WebCore |
OLD | NEW |