2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "ScriptController.h"
26 #include "ScriptSourceCode.h"
27 #include "ScriptValue.h"
29 #include "XSSAuditor.h"
33 ScriptValue ScriptController::executeScript(const String& script, bool forceUserGesture)
35 return executeScript(ScriptSourceCode(script, forceUserGesture ? KURL() : m_frame->loader()->url()));
38 ScriptValue ScriptController::executeScript(const ScriptSourceCode& sourceCode)
40 if (!isEnabled() || isPaused())
43 bool wasInExecuteScript = m_inExecuteScript;
44 m_inExecuteScript = true;
46 ScriptValue result = evaluate(sourceCode);
48 if (!wasInExecuteScript) {
49 m_inExecuteScript = false;
50 Document::updateStyleForAllDocuments();
57 bool ScriptController::executeIfJavaScriptURL(const KURL& url, bool userGesture, bool replaceDocument)
59 if (!protocolIsJavaScript(url))
62 if (m_frame->page() && !m_frame->page()->javaScriptURLsAreAllowed())
65 if (m_frame->inViewSourceMode())
68 const int javascriptSchemeLength = sizeof("javascript:") - 1;
70 String script = decodeURLEscapeSequences(url.string().substring(javascriptSchemeLength));
72 if (xssAuditor()->canEvaluateJavaScriptURL(script))
73 result = executeScript(script, userGesture);
76 if (!result.getString(scriptResult))
79 // FIXME: We should always replace the document, but doing so
80 // synchronously can cause crashes:
81 // http://bugs.webkit.org/show_bug.cgi?id=16782
83 m_frame->loader()->replaceDocument(scriptResult);
88 } // namespace WebCore