| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 /* |
| 2 // All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
| 3 // | 3 * |
| 4 // Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 // met: | 6 * met: |
| 7 // | 7 * |
| 8 // * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 // copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 // in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 // distribution. | 13 * distribution. |
| 14 // * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 // contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 // this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 // | 17 * |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 29 | 30 |
| 30 #include "config.h" | 31 #include "config.h" |
| 31 #include "ScriptController.h" | 32 #include "ScriptController.h" |
| 32 | 33 |
| 33 #include "ChromiumBridge.h" | 34 #include "ChromiumBridge.h" |
| 34 #include "CString.h" | 35 #include "CString.h" |
| 35 #include "Document.h" | 36 #include "Document.h" |
| 36 #include "DOMWindow.h" | 37 #include "DOMWindow.h" |
| 37 #include "Event.h" | 38 #include "Event.h" |
| 38 #include "EventListener.h" | 39 #include "EventListener.h" |
| 39 #include "EventNames.h" | 40 #include "EventNames.h" |
| 40 #include "Frame.h" | 41 #include "Frame.h" |
| 41 #include "Node.h" | 42 #include "Node.h" |
| 42 #include "NotImplemented.h" | 43 #include "NotImplemented.h" |
| 43 #include "npruntime_priv.h" | 44 #include "npruntime_priv.h" |
| 44 #include "NPV8Object.h" | 45 #include "NPV8Object.h" |
| 45 #include "ScriptSourceCode.h" | 46 #include "ScriptSourceCode.h" |
| 46 #include "ScriptState.h" | 47 #include "ScriptState.h" |
| 47 #include "Widget.h" | 48 #include "Widget.h" |
| 48 | 49 |
| 49 #include "v8_proxy.h" | 50 #include "V8Binding.h" |
| 50 #include "v8_binding.h" | |
| 51 #include "V8NPObject.h" | 51 #include "V8NPObject.h" |
| 52 | 52 #include "V8Proxy.h" |
| 53 NPRuntimeFunctions npruntime_functions = { | |
| 54 NPN_GetStringIdentifier, | |
| 55 NPN_GetStringIdentifiers, | |
| 56 NPN_GetIntIdentifier, | |
| 57 NPN_IdentifierIsString, | |
| 58 NPN_UTF8FromIdentifier, | |
| 59 NPN_IntFromIdentifier, | |
| 60 NPN_CreateObject, | |
| 61 NPN_RetainObject, | |
| 62 NPN_ReleaseObject, | |
| 63 NPN_Invoke, | |
| 64 NPN_InvokeDefault, | |
| 65 NPN_Evaluate, | |
| 66 NPN_GetProperty, | |
| 67 NPN_SetProperty, | |
| 68 NPN_RemoveProperty, | |
| 69 NPN_HasProperty, | |
| 70 NPN_HasMethod, | |
| 71 NPN_ReleaseVariantValue, | |
| 72 NPN_SetException | |
| 73 }; | |
| 74 | |
| 75 | 53 |
| 76 namespace WebCore { | 54 namespace WebCore { |
| 77 | 55 |
| 78 void ScriptController::setFlags(const char* str, int length) | 56 void ScriptController::setFlags(const char* string, int length) |
| 79 { | 57 { |
| 80 v8::V8::SetFlagsFromString(str, length); | 58 v8::V8::SetFlagsFromString(string, length); |
| 81 } | 59 } |
| 82 | 60 |
| 83 Frame* ScriptController::retrieveFrameForEnteredContext() | 61 Frame* ScriptController::retrieveFrameForEnteredContext() |
| 84 { | 62 { |
| 85 return V8Proxy::retrieveFrameForEnteredContext(); | 63 return V8Proxy::retrieveFrameForEnteredContext(); |
| 86 } | 64 } |
| 87 | 65 |
| 88 Frame* ScriptController::retrieveFrameForCurrentContext() | 66 Frame* ScriptController::retrieveFrameForCurrentContext() |
| 89 { | 67 { |
| 90 return V8Proxy::retrieveFrameForCurrentContext(); | 68 return V8Proxy::retrieveFrameForCurrentContext(); |
| 91 } | 69 } |
| 92 | 70 |
| 93 bool ScriptController::isSafeScript(Frame* target) | 71 bool ScriptController::isSafeScript(Frame* target) |
| 94 { | 72 { |
| 95 return V8Proxy::CanAccessFrame(target, true); | 73 return V8Proxy::CanAccessFrame(target, true); |
| 96 } | 74 } |
| 97 | 75 |
| 98 void ScriptController::gcProtectJSWrapper(void* dom_object) | 76 void ScriptController::gcProtectJSWrapper(void* domObject) |
| 99 { | 77 { |
| 100 V8Proxy::GCProtect(dom_object); | 78 V8Proxy::GCProtect(domObject); |
| 101 } | 79 } |
| 102 | 80 |
| 103 void ScriptController::gcUnprotectJSWrapper(void* dom_object) | 81 void ScriptController::gcUnprotectJSWrapper(void* domObject) |
| 104 { | 82 { |
| 105 V8Proxy::GCUnprotect(dom_object); | 83 V8Proxy::GCUnprotect(domObject); |
| 106 } | 84 } |
| 107 | 85 |
| 108 ScriptController::ScriptController(Frame* frame) | 86 ScriptController::ScriptController(Frame* frame) |
| 109 : m_frame(frame) | 87 : m_frame(frame) |
| 110 , m_sourceURL(0) | 88 , m_sourceURL(0) |
| 111 , m_processingTimerCallback(false) | 89 , m_processingTimerCallback(false) |
| 112 , m_paused(false) | 90 , m_paused(false) |
| 113 , m_scriptState(new ScriptState(frame)) | 91 , m_scriptState(new ScriptState(frame)) |
| 114 , m_proxy(new V8Proxy(frame)) | 92 , m_proxy(new V8Proxy(frame)) |
| 115 #if ENABLE(NETSCAPE_PLUGIN_API) | 93 #if ENABLE(NETSCAPE_PLUGIN_API) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 145 void ScriptController::updateSecurityOrigin() | 123 void ScriptController::updateSecurityOrigin() |
| 146 { | 124 { |
| 147 m_proxy->updateSecurityOrigin(); | 125 m_proxy->updateSecurityOrigin(); |
| 148 } | 126 } |
| 149 | 127 |
| 150 void ScriptController::updatePlatformScriptObjects() | 128 void ScriptController::updatePlatformScriptObjects() |
| 151 { | 129 { |
| 152 notImplemented(); | 130 notImplemented(); |
| 153 } | 131 } |
| 154 | 132 |
| 155 // Disconnect the proxy from its owner frame; | 133 // Disconnect the proxy from its owner frame. |
| 156 void ScriptController::disconnectFrame() | 134 void ScriptController::disconnectFrame() |
| 157 { | 135 { |
| 158 m_proxy->disconnectFrame(); | 136 m_proxy->disconnectFrame(); |
| 159 } | 137 } |
| 160 | 138 |
| 161 bool ScriptController::processingUserGesture() const | 139 bool ScriptController::processingUserGesture() const |
| 162 { | 140 { |
| 163 Frame* active_frame = V8Proxy::retrieveFrameForEnteredContext(); | 141 Frame* activeFrame = V8Proxy::retrieveFrameForEnteredContext(); |
| 164 // No script is running, must be run by users. | 142 // No script is running, so it must be run by users. |
| 165 if (!active_frame) | 143 if (!activeFrame) |
| 166 return true; | 144 return true; |
| 167 | 145 |
| 168 V8Proxy* active_proxy = active_frame->script()->proxy(); | 146 V8Proxy* activeProxy = activeFrame->script()->proxy(); |
| 169 | 147 |
| 170 v8::HandleScope handle_scope; | 148 v8::HandleScope handleScope; |
| 171 v8::Handle<v8::Context> context = V8Proxy::GetContext(active_frame); | 149 v8::Handle<v8::Context> context = V8Proxy::GetContext(activeFrame); |
| 172 // TODO(fqian): find all cases context can be empty: | 150 // FIXME: find all cases context can be empty: |
| 173 // 1) JS is disabled; | 151 // 1) JS is disabled; |
| 174 // 2) page is NULL; | 152 // 2) page is NULL; |
| 175 if (context.IsEmpty()) | 153 if (context.IsEmpty()) |
| 176 return true; | 154 return true; |
| 177 | 155 |
| 178 v8::Context::Scope scope(context); | 156 v8::Context::Scope scope(context); |
| 179 | 157 |
| 180 v8::Handle<v8::Object> global = context->Global(); | 158 v8::Handle<v8::Object> global = context->Global(); |
| 181 v8::Handle<v8::Value> jsevent = global->Get(v8::String::NewSymbol("event")); | 159 v8::Handle<v8::Value> jsEvent = global->Get(v8::String::NewSymbol("event")); |
| 182 Event* event = V8Proxy::ToNativeEvent(jsevent); | 160 Event* event = V8Proxy::ToNativeEvent(jsEvent); |
| 183 | 161 |
| 184 // Based on code from kjs_bindings.cpp. | 162 // Based on code from kjs_bindings.cpp. |
| 185 // Note: This is more liberal than Firefox's implementation. | 163 // Note: This is more liberal than Firefox's implementation. |
| 186 if (event) { | 164 if (event) { |
| 187 const AtomicString& type = event->type(); | 165 const AtomicString& type = event->type(); |
| 188 bool event_ok = | 166 bool eventOk = |
| 189 // mouse events | 167 // mouse events |
| 190 type == eventNames().clickEvent || | 168 type == eventNames().clickEvent || type == eventNames().mousedownEve
nt || type == eventNames().mouseupEvent || type == eventNames().dblclickEvent |
| 191 type == eventNames().mousedownEvent || | 169 // keyboard events |
| 192 type == eventNames().mouseupEvent || | 170 || type == eventNames().keydownEvent || type == eventNames().keypres
sEvent || type == eventNames().keyupEvent |
| 193 type == eventNames().dblclickEvent || | 171 // other accepted events |
| 194 // keyboard events | 172 || type == eventNames().selectEvent || type == eventNames().changeEv
ent || type == eventNames().focusEvent || type == eventNames().blurEvent || type
== eventNames().submitEvent; |
| 195 type == eventNames().keydownEvent || | |
| 196 type == eventNames().keypressEvent || | |
| 197 type == eventNames().keyupEvent || | |
| 198 // other accepted events | |
| 199 type == eventNames().selectEvent || | |
| 200 type == eventNames().changeEvent || | |
| 201 type == eventNames().focusEvent || | |
| 202 type == eventNames().blurEvent || | |
| 203 type == eventNames().submitEvent; | |
| 204 | 173 |
| 205 if (event_ok) | 174 if (eventOk) |
| 206 return true; | 175 return true; |
| 207 } else if (active_proxy->inlineCode() && !active_proxy->timerCallback()) | 176 } else if (activeProxy->inlineCode() && !activeProxy->timerCallback()) { |
| 208 // This is the <a href="javascript:window.open('...')> case -> we let it | 177 // This is the <a href="javascript:window.open('...')> case -> we let it
through. |
| 209 // through | |
| 210 return true; | 178 return true; |
| 179 } |
| 211 | 180 |
| 212 // This is the <script>window.open(...)</script> case or a timer callback -> | 181 // This is the <script>window.open(...)</script> case or a timer callback ->
block it. |
| 213 // block it | |
| 214 return false; | 182 return false; |
| 215 } | 183 } |
| 216 | 184 |
| 217 void ScriptController::evaluateInNewContext( | 185 void ScriptController::evaluateInNewContext(const Vector<ScriptSourceCode>& sour
ces) |
| 218 const Vector<ScriptSourceCode>& sources) { | 186 { |
| 219 m_proxy->evaluateInNewContext(sources); | 187 m_proxy->evaluateInNewContext(sources); |
| 220 } | 188 } |
| 221 | 189 |
| 222 // Evaluate a script file in the environment of this proxy. | 190 // Evaluate a script file in the environment of this proxy. |
| 223 ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode) | 191 ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode) |
| 224 { | 192 { |
| 225 v8::HandleScope hs; | 193 v8::HandleScope handleScope; |
| 226 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame()); | 194 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame()); |
| 227 if (context.IsEmpty()) | 195 if (context.IsEmpty()) |
| 228 return ScriptValue(); | 196 return ScriptValue(); |
| 229 | 197 |
| 230 v8::Context::Scope scope(context); | 198 v8::Context::Scope scope(context); |
| 231 v8::Local<v8::Value> obj = m_proxy->evaluate(sourceCode, NULL); | 199 v8::Local<v8::Value> object = m_proxy->evaluate(sourceCode, 0); |
| 232 | 200 |
| 233 if (obj.IsEmpty() || obj->IsUndefined()) | 201 if (object.IsEmpty() || object->IsUndefined()) |
| 234 return ScriptValue(); | 202 return ScriptValue(); |
| 235 | 203 |
| 236 return ScriptValue(obj); | 204 return ScriptValue(object); |
| 237 } | 205 } |
| 238 | 206 |
| 239 void ScriptController::disposeJSResult(v8::Persistent<v8::Value> result) | 207 void ScriptController::setEventHandlerLineNumber(int lineNumber) |
| 240 { | 208 { |
| 241 result.Dispose(); | 209 m_proxy->setEventHandlerLineno(lineNumber); |
| 242 result.Clear(); | |
| 243 } | 210 } |
| 244 | 211 |
| 245 void ScriptController::setEventHandlerLineNumber(int lineno) | 212 void ScriptController::finishedWithEvent(Event* event) |
| 246 { | 213 { |
| 247 m_proxy->setEventHandlerLineno(lineno); | 214 m_proxy->finishedWithEvent(event); |
| 248 } | 215 } |
| 249 | 216 |
| 250 void ScriptController::finishedWithEvent(Event* evt) | 217 // Create a V8 object with an interceptor of NPObjectPropertyGetter. |
| 218 void ScriptController::bindToWindowObject(Frame* frame, const String& key, NPObj
ect* object) |
| 251 { | 219 { |
| 252 m_proxy->finishedWithEvent(evt); | 220 v8::HandleScope handleScope; |
| 253 } | |
| 254 | |
| 255 // Create a V8 object with an interceptor of NPObjectPropertyGetter | |
| 256 void ScriptController::BindToWindowObject(Frame* frame, const String& key, NPObj
ect* object) | |
| 257 { | |
| 258 v8::HandleScope handle_scope; | |
| 259 | 221 |
| 260 v8::Handle<v8::Context> context = V8Proxy::GetContext(frame); | 222 v8::Handle<v8::Context> context = V8Proxy::GetContext(frame); |
| 261 if (context.IsEmpty()) | 223 if (context.IsEmpty()) |
| 262 return; | 224 return; |
| 263 | 225 |
| 264 v8::Context::Scope scope(context); | 226 v8::Context::Scope scope(context); |
| 265 | 227 |
| 266 v8::Handle<v8::Object> value = CreateV8ObjectForNPObject(object, NULL); | 228 v8::Handle<v8::Object> value = CreateV8ObjectForNPObject(object, 0); |
| 267 | 229 |
| 268 // Attach to the global object | 230 // Attach to the global object. |
| 269 v8::Handle<v8::Object> global = context->Global(); | 231 v8::Handle<v8::Object> global = context->Global(); |
| 270 global->Set(v8String(key), value); | 232 global->Set(v8String(key), value); |
| 271 } | 233 } |
| 272 | 234 |
| 273 void ScriptController::collectGarbage() | 235 void ScriptController::collectGarbage() |
| 274 { | 236 { |
| 275 v8::HandleScope hs; | 237 v8::HandleScope handleScope; |
| 276 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame()); | 238 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame()); |
| 277 if (context.IsEmpty()) | 239 if (context.IsEmpty()) |
| 278 return; | 240 return; |
| 279 | 241 |
| 280 v8::Context::Scope scope(context); | 242 v8::Context::Scope scope(context); |
| 281 | 243 |
| 282 m_proxy->evaluate(ScriptSourceCode("if (window.gc) void(gc());"), NULL); | 244 m_proxy->evaluate(ScriptSourceCode("if (window.gc) void(gc());"), 0); |
| 283 } | 245 } |
| 284 | 246 |
| 285 NPRuntimeFunctions* ScriptController::functions() | |
| 286 { | |
| 287 return &npruntime_functions; | |
| 288 } | |
| 289 | |
| 290 | |
| 291 bool ScriptController::haveInterpreter() const | 247 bool ScriptController::haveInterpreter() const |
| 292 { | 248 { |
| 293 return m_proxy->ContextInitialized(); | 249 return m_proxy->ContextInitialized(); |
| 294 } | 250 } |
| 295 | 251 |
| 296 bool ScriptController::isEnabled() const | 252 bool ScriptController::isEnabled() const |
| 297 { | 253 { |
| 298 return m_proxy->isEnabled(); | 254 return m_proxy->isEnabled(); |
| 299 } | 255 } |
| 300 | 256 |
| 301 PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widge
t) | 257 PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widge
t) |
| 302 { | 258 { |
| 303 ASSERT(widget != 0); | 259 ASSERT(widget); |
| 304 | 260 |
| 305 if (widget->isFrameView()) | 261 if (widget->isFrameView()) |
| 306 return 0; | 262 return 0; |
| 307 | 263 |
| 308 NPObject* npObject = ChromiumBridge::pluginScriptableObject(widget); | 264 NPObject* npObject = ChromiumBridge::pluginScriptableObject(widget); |
| 309 if (!npObject) | 265 if (!npObject) |
| 310 return 0; | 266 return 0; |
| 311 | 267 |
| 312 // Frame Memory Management for NPObjects | 268 // Frame Memory Management for NPObjects |
| 313 // ------------------------------------- | 269 // ------------------------------------- |
| 314 // NPObjects are treated differently than other objects wrapped by JS. | 270 // NPObjects are treated differently than other objects wrapped by JS. |
| 315 // NPObjects can be created either by the browser (e.g. the main | 271 // NPObjects can be created either by the browser (e.g. the main |
| 316 // window object) or by the plugin (the main plugin object | 272 // window object) or by the plugin (the main plugin object |
| 317 // for a HTMLEmbedElement). Further, | 273 // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame |
| 318 // unlike most DOM Objects, the frame is especially careful to ensure | 274 // is especially careful to ensure NPObjects terminate at frame teardown bec
ause |
| 319 // NPObjects terminate at frame teardown because if a plugin leaks a | 275 // if a plugin leaks a reference, it could leak its objects (or the browser'
s objects). |
| 320 // reference, it could leak its objects (or the browser's objects). | |
| 321 // | 276 // |
| 322 // The Frame maintains a list of plugin objects (m_pluginObjects) | 277 // The Frame maintains a list of plugin objects (m_pluginObjects) |
| 323 // which it can use to quickly find the wrapped embed object. | 278 // which it can use to quickly find the wrapped embed object. |
| 324 // | 279 // |
| 325 // Inside the NPRuntime, we've added a few methods for registering | 280 // Inside the NPRuntime, we've added a few methods for registering |
| 326 // wrapped NPObjects. The purpose of the registration is because | 281 // wrapped NPObjects. The purpose of the registration is because |
| 327 // javascript garbage collection is non-deterministic, yet we need to | 282 // javascript garbage collection is non-deterministic, yet we need to |
| 328 // be able to tear down the plugin objects immediately. When an object | 283 // be able to tear down the plugin objects immediately. When an object |
| 329 // is registered, javascript can use it. When the object is destroyed, | 284 // is registered, javascript can use it. When the object is destroyed, |
| 330 // or when the object's "owning" object is destroyed, the object will | 285 // or when the object's "owning" object is destroyed, the object will |
| 331 // be un-registered, and the javascript engine must not use it. | 286 // be un-registered, and the javascript engine must not use it. |
| 332 // | 287 // |
| 333 // Inside the javascript engine, the engine can keep a reference to the | 288 // Inside the javascript engine, the engine can keep a reference to the |
| 334 // NPObject as part of its wrapper. However, before accessing the object | 289 // NPObject as part of its wrapper. However, before accessing the object |
| 335 // it must consult the NPN_Registry. | 290 // it must consult the NPN_Registry. |
| 336 | 291 |
| 337 v8::Local<v8::Object> wrapper = CreateV8ObjectForNPObject(npObject, NULL); | 292 v8::Local<v8::Object> wrapper = CreateV8ObjectForNPObject(npObject, 0); |
| 338 | 293 |
| 339 // Track the plugin object. We've been given a reference to the object. | 294 // Track the plugin object. We've been given a reference to the object. |
| 340 m_pluginObjects.set(widget, npObject); | 295 m_pluginObjects.set(widget, npObject); |
| 341 | 296 |
| 342 return V8ScriptInstance::create(wrapper); | 297 return V8ScriptInstance::create(wrapper); |
| 343 } | 298 } |
| 344 | 299 |
| 345 void ScriptController::cleanupScriptObjectsForPlugin(void* nativeHandle) | 300 void ScriptController::cleanupScriptObjectsForPlugin(void* nativeHandle) |
| 346 { | 301 { |
| 347 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); | 302 PluginObjectMap::iterator it = m_pluginObjects.find(nativeHandle); |
| 348 if (it == m_pluginObjects.end()) | 303 if (it == m_pluginObjects.end()) |
| 349 return; | 304 return; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 374 | 329 |
| 375 NPObject* ScriptController::windowScriptNPObject() | 330 NPObject* ScriptController::windowScriptNPObject() |
| 376 { | 331 { |
| 377 if (m_windowScriptNPObject) | 332 if (m_windowScriptNPObject) |
| 378 return m_windowScriptNPObject; | 333 return m_windowScriptNPObject; |
| 379 | 334 |
| 380 if (isEnabled()) { | 335 if (isEnabled()) { |
| 381 // JavaScript is enabled, so there is a JavaScript window object. | 336 // JavaScript is enabled, so there is a JavaScript window object. |
| 382 // Return an NPObject bound to the window object. | 337 // Return an NPObject bound to the window object. |
| 383 m_windowScriptNPObject = createScriptObject(m_frame); | 338 m_windowScriptNPObject = createScriptObject(m_frame); |
| 384 _NPN_RegisterObject(m_windowScriptNPObject, NULL); | 339 _NPN_RegisterObject(m_windowScriptNPObject, 0); |
| 385 } else { | 340 } else { |
| 386 // JavaScript is not enabled, so we cannot bind the NPObject to the | 341 // JavaScript is not enabled, so we cannot bind the NPObject to the |
| 387 // JavaScript window object. Instead, we create an NPObject of a | 342 // JavaScript window object. Instead, we create an NPObject of a |
| 388 // different class, one which is not bound to a JavaScript object. | 343 // different class, one which is not bound to a JavaScript object. |
| 389 m_windowScriptNPObject = createNoScriptObject(); | 344 m_windowScriptNPObject = createNoScriptObject(); |
| 390 } | 345 } |
| 391 return m_windowScriptNPObject; | 346 return m_windowScriptNPObject; |
| 392 } | 347 } |
| 393 | 348 |
| 394 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) | 349 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) |
| 395 { | 350 { |
| 396 // Can't create NPObjects when JavaScript is disabled | 351 // Can't create NPObjects when JavaScript is disabled. |
| 397 if (!isEnabled()) | 352 if (!isEnabled()) |
| 398 return createNoScriptObject(); | 353 return createNoScriptObject(); |
| 399 | 354 |
| 400 v8::HandleScope handleScope; | 355 v8::HandleScope handleScope; |
| 401 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_frame); | 356 v8::Handle<v8::Context> context = V8Proxy::GetContext(m_frame); |
| 402 if (context.IsEmpty()) | 357 if (context.IsEmpty()) |
| 403 return createNoScriptObject(); | 358 return createNoScriptObject(); |
| 404 v8::Context::Scope scope(context); | 359 v8::Context::Scope scope(context); |
| 405 | 360 |
| 406 DOMWindow* window = m_frame->domWindow(); | 361 DOMWindow* window = m_frame->domWindow(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 423 void ScriptController::attachDebugger(void*) | 378 void ScriptController::attachDebugger(void*) |
| 424 { | 379 { |
| 425 notImplemented(); | 380 notImplemented(); |
| 426 } | 381 } |
| 427 | 382 |
| 428 void ScriptController::updateDocument() | 383 void ScriptController::updateDocument() |
| 429 { | 384 { |
| 430 m_proxy->updateDocument(); | 385 m_proxy->updateDocument(); |
| 431 } | 386 } |
| 432 | 387 |
| 433 } // namespace WebCpre | 388 } // namespace WebCore |
| OLD | NEW |