| | 241 | Bindings::RootObject* ScriptController::bindingRootObject() |
|---|
| | 242 | { |
|---|
| | 243 | if (!isEnabled()) |
|---|
| | 244 | return 0; |
|---|
| | 245 | |
|---|
| | 246 | if (!m_bindingRootObject) |
|---|
| | 247 | m_bindingRootObject = Bindings::RootObject::create(0, globalObject()); |
|---|
| | 248 | return m_bindingRootObject.get(); |
|---|
| | 249 | } |
|---|
| | 250 | |
|---|
| | 251 | PassRefPtr<Bindings::RootObject> ScriptController::createRootObject(void* nativeHandle) |
|---|
| | 252 | { |
|---|
| | 253 | RootObjectMap::iterator it = m_rootObjects.find(nativeHandle); |
|---|
| | 254 | if (it != m_rootObjects.end()) |
|---|
| | 255 | return it->second; |
|---|
| | 256 | |
|---|
| | 257 | RefPtr<Bindings::RootObject> rootObject = Bindings::RootObject::create(nativeHandle, globalObject()); |
|---|
| | 258 | |
|---|
| | 259 | m_rootObjects.set(nativeHandle, rootObject); |
|---|
| | 260 | return rootObject.release(); |
|---|
| | 261 | } |
|---|
| | 262 | |
|---|
| | 263 | #if ENABLE(NETSCAPE_PLUGIN_API) |
|---|
| | 264 | NPObject* ScriptController::windowScriptNPObject() |
|---|
| | 265 | { |
|---|
| | 266 | if (!m_windowScriptNPObject) { |
|---|
| | 267 | if (isEnabled()) { |
|---|
| | 268 | // JavaScript is enabled, so there is a JavaScript window object. |
|---|
| | 269 | // Return an NPObject bound to the window object. |
|---|
| | 270 | JSObject* win = windowShell()->window(); |
|---|
| | 271 | ASSERT(win); |
|---|
| | 272 | Bindings::RootObject* root = bindingRootObject(); |
|---|
| | 273 | m_windowScriptNPObject = _NPN_CreateScriptObject(0, win, root); |
|---|
| | 274 | } else { |
|---|
| | 275 | // JavaScript is not enabled, so we cannot bind the NPObject to the JavaScript window object. |
|---|
| | 276 | // Instead, we create an NPObject of a different class, one which is not bound to a JavaScript object. |
|---|
| | 277 | m_windowScriptNPObject = _NPN_CreateNoScriptObject(); |
|---|
| | 278 | } |
|---|
| | 279 | } |
|---|
| | 280 | |
|---|
| | 281 | return m_windowScriptNPObject; |
|---|
| | 282 | } |
|---|
| | 283 | |
|---|
| | 284 | NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement* plugin) |
|---|
| | 285 | { |
|---|
| | 286 | // Can't create NPObjects when JavaScript is disabled |
|---|
| | 287 | if (!isEnabled()) |
|---|
| | 288 | return _NPN_CreateNoScriptObject(); |
|---|
| | 289 | |
|---|
| | 290 | // Create a JSObject bound to this element |
|---|
| | 291 | ExecState* exec = globalObject()->globalExec(); |
|---|
| | 292 | JSValue* jsElementValue = toJS(exec, plugin); |
|---|
| | 293 | if (!jsElementValue || !jsElementValue->isObject()) |
|---|
| | 294 | return _NPN_CreateNoScriptObject(); |
|---|
| | 295 | |
|---|
| | 296 | // Wrap the JSObject in an NPObject |
|---|
| | 297 | return _NPN_CreateScriptObject(0, jsElementValue->getObject(), bindingRootObject()); |
|---|
| | 298 | } |
|---|
| | 299 | #endif |
|---|
| | 300 | |
|---|
| | 301 | #if !PLATFORM(MAC) |
|---|
| | 302 | void ScriptController::clearPlatformScriptObjects() |
|---|
| | 303 | { |
|---|
| | 304 | } |
|---|
| | 305 | |
|---|
| | 306 | void ScriptController::disconnectPlatformScriptObjects() |
|---|
| | 307 | { |
|---|
| | 308 | } |
|---|
| | 309 | #endif |
|---|
| | 310 | |
|---|
| | 311 | void ScriptController::cleanupScriptObjectsForPlugin(void* nativeHandle) |
|---|
| | 312 | { |
|---|
| | 313 | RootObjectMap::iterator it = m_rootObjects.find(nativeHandle); |
|---|
| | 314 | |
|---|
| | 315 | if (it == m_rootObjects.end()) |
|---|
| | 316 | return; |
|---|
| | 317 | |
|---|
| | 318 | it->second->invalidate(); |
|---|
| | 319 | m_rootObjects.remove(it); |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| | 322 | void ScriptController::clearScriptObjects() |
|---|
| | 323 | { |
|---|
| | 324 | RootObjectMap::const_iterator end = m_rootObjects.end(); |
|---|
| | 325 | for (RootObjectMap::const_iterator it = m_rootObjects.begin(); it != end; ++it) |
|---|
| | 326 | it->second->invalidate(); |
|---|
| | 327 | |
|---|
| | 328 | m_rootObjects.clear(); |
|---|
| | 329 | |
|---|
| | 330 | if (m_bindingRootObject) { |
|---|
| | 331 | m_bindingRootObject->invalidate(); |
|---|
| | 332 | m_bindingRootObject = 0; |
|---|
| | 333 | } |
|---|
| | 334 | |
|---|
| | 335 | #if ENABLE(NETSCAPE_PLUGIN_API) |
|---|
| | 336 | if (m_windowScriptNPObject) { |
|---|
| | 337 | // Call _NPN_DeallocateObject() instead of _NPN_ReleaseObject() so that we don't leak if a plugin fails to release the window |
|---|
| | 338 | // script object properly. |
|---|
| | 339 | // This shouldn't cause any problems for plugins since they should have already been stopped and destroyed at this point. |
|---|
| | 340 | _NPN_DeallocateObject(m_windowScriptNPObject); |
|---|
| | 341 | m_windowScriptNPObject = 0; |
|---|
| | 342 | } |
|---|
| | 343 | #endif |
|---|
| | 344 | |
|---|
| | 345 | clearPlatformScriptObjects(); |
|---|
| | 346 | } |
|---|
| | 347 | |
|---|