Reviewed by Kevin Ollivier.
authorkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2009 23:31:59 +0000 (23:31 +0000)
committerkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2009 23:31:59 +0000 (23:31 +0000)
Add sanity checks to RunScript to ensure it doesn't run when the document hasn't yet
loaded nor when JavaScript is disabled.

https://bugs.webkit.org/show_bug.cgi?id=31309

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@50777 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/wx/ChangeLog
WebKit/wx/WebFrame.cpp

index 7202b7f..2e8c284 100644 (file)
@@ -1,3 +1,15 @@
+2009-11-10  Robin Dunn  <robin@alldunn.com>
+
+        Reviewed by Kevin Ollivier.
+
+        Add sanity checks to RunScript to ensure it doesn't run when the document hasn't yet
+        loaded nor when JavaScript is disabled.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=31309
+
+        * WebFrame.cpp:
+        (wxWebFrame::RunScript):
+
 2009-11-04  Kevin Watters  <kevinwatters@gmail.com>
 
         Reviewed by Kevin Ollivier.
index a497e65..c7e6d6b 100644 (file)
@@ -187,10 +187,19 @@ wxString wxWebFrame::GetExternalRepresentation()
 wxString wxWebFrame::RunScript(const wxString& javascript)
 {
     wxString returnValue = wxEmptyString;
-    if (m_impl->frame) {
-        JSC::JSValue result = m_impl->frame->script()->executeScript(javascript, true).jsValue();
-        if (result)
-            returnValue = wxString(result.toString(m_impl->frame->script()->globalObject(WebCore::mainThreadNormalWorld())->globalExec()).UTF8String().c_str(), wxConvUTF8);        
+    if (m_impl->frame && m_impl->frame->loader()) {
+        bool hasLoaded = m_impl->frame->loader()->frameHasLoaded();
+        wxASSERT_MSG(hasLoaded, wxT("Document must be loaded before calling RunScript."));
+        if (hasLoaded) {
+            WebCore::ScriptController* controller = m_impl->frame->script();
+            bool jsEnabled = controller->isEnabled(); 
+            wxASSERT_MSG(jsEnabled, wxT("RunScript requires JavaScript to be enabled."));
+            if (jsEnabled) {
+                JSC::JSValue result = controller->executeScript(javascript, true).jsValue();
+                if (result)
+                    returnValue = wxString(result.toString(m_impl->frame->script()->globalObject(WebCore::mainThreadNormalWorld())->globalExec()).UTF8String().c_str(), wxConvUTF8);        
+            }
+        }
     }
     return returnValue;
 }