Commit d006497c authored by darin@apple.com's avatar darin@apple.com

2008-07-07 Darin Adler <darin@apple.com>

        Reviewed by Mark Rowe.

        - fix <rdar://problem/6020441> REGRESSION: Layers on NWA.com render ugly

        The old version of the OpenCube QuickMenu library used on this site still has code
        that detects Netscape 4 by checking appVersion to see if it has the substring "4."
        in it. We decided to special-case the filename of the script and tweak the appVersion
        for files with that name.

        * bindings/js/ScriptController.cpp:
        (WebCore::ScriptController::ScriptController): Replace m_processingInlineCode with
        m_sourceURL. Use false instead of 0 to initialize a boolean.
        (WebCore::ScriptController::evaluate): Call argument sourceURL, not filename.
        Store current sourceURL in m_sourceURL. This fixes a mistake in the code that
        maintained the value of m_processingInlineCode, since the old code set it to
        false rather than restoring it. Renamed a local variable named sourceURL to
        exceptionSourceURL for clarity.
        (WebCore::ScriptController::processingUserGesture): Code that formerly used
        m_processingInlineCode to detect that it was evaluating code with no URL now
        uses m_sourceURL to do the same check.

        * bindings/js/ScriptController.h: Renamed filename argument to sourceURL; it has always
        been a URL, not a file path. Added a public sourceURL function and m_sourceURL and
        removed m_processingInlineCode.

        * page/Navigator.cpp:
        (WebCore::shouldHideFourDot): Added. Returns true if the currently running script has
        a source URL ending in "/dqm_script.js" and if the settings say we should do
        site-specific quirks (really JavaScript-library-specific in this case).
        (WebCore::Navigator::appVersion): Replace "4." with "4_" if shouldHideFourDot is true.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35050 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5aa7aa31
2008-07-07 Darin Adler <darin@apple.com>
Reviewed by Mark Rowe.
- fix <rdar://problem/6020441> REGRESSION: Layers on NWA.com render ugly
The old version of the OpenCube QuickMenu library used on this site still has code
that detects Netscape 4 by checking appVersion to see if it has the substring "4."
in it. We decided to special-case the filename of the script and tweak the appVersion
for files with that name.
* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::ScriptController): Replace m_processingInlineCode with
m_sourceURL. Use false instead of 0 to initialize a boolean.
(WebCore::ScriptController::evaluate): Call argument sourceURL, not filename.
Store current sourceURL in m_sourceURL. This fixes a mistake in the code that
maintained the value of m_processingInlineCode, since the old code set it to
false rather than restoring it. Renamed a local variable named sourceURL to
exceptionSourceURL for clarity.
(WebCore::ScriptController::processingUserGesture): Code that formerly used
m_processingInlineCode to detect that it was evaluating code with no URL now
uses m_sourceURL to do the same check.
* bindings/js/ScriptController.h: Renamed filename argument to sourceURL; it has always
been a URL, not a file path. Added a public sourceURL function and m_sourceURL and
removed m_processingInlineCode.
* page/Navigator.cpp:
(WebCore::shouldHideFourDot): Added. Returns true if the currently running script has
a source URL ending in "/dqm_script.js" and if the settings say we should do
site-specific quirks (really JavaScript-library-specific in this case).
(WebCore::Navigator::appVersion): Replace "4." with "4_" if shouldHideFourDot is true.
2008-07-07 Cameron Zwarich <cwzwarich@uwaterloo.ca>
Reviewed by Geoff.
......@@ -52,8 +52,8 @@ namespace WebCore {
ScriptController::ScriptController(Frame* frame)
: m_frame(frame)
, m_handlerLineno(0)
, m_processingTimerCallback(0)
, m_processingInlineCode(0)
, m_sourceURL(0)
, m_processingTimerCallback(false)
, m_paused(false)
{
}
......@@ -68,7 +68,7 @@ ScriptController::~ScriptController()
}
}
JSValue* ScriptController::evaluate(const String& filename, int baseLine, const String& str)
JSValue* ScriptController::evaluate(const String& sourceURL, int baseLine, const String& str)
{
// evaluate code. Returns the JS return value or 0
// if there was none, an error occured or the type couldn't be converted.
......@@ -79,7 +79,8 @@ JSValue* ScriptController::evaluate(const String& filename, int baseLine, const
// expected value in all cases.
// See smart window.open policy for where this is used.
ExecState* exec = m_windowShell->window()->globalExec();
m_processingInlineCode = filename.isNull();
const String* savedSourceURL = m_sourceURL;
m_sourceURL = &sourceURL;
JSLock lock(false);
......@@ -88,22 +89,22 @@ JSValue* ScriptController::evaluate(const String& filename, int baseLine, const
m_frame->keepAlive();
m_windowShell->window()->startTimeoutCheck();
Completion comp = Interpreter::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), filename, baseLine, StringSourceProvider::create(str), m_windowShell);
Completion comp = Interpreter::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceURL, baseLine, StringSourceProvider::create(str), m_windowShell);
m_windowShell->window()->stopTimeoutCheck();
if (comp.complType() == Normal || comp.complType() == ReturnValue) {
m_processingInlineCode = false;
m_sourceURL = savedSourceURL;
return comp.value();
}
if (comp.complType() == Throw) {
UString errorMessage = comp.value()->toString(exec);
int lineNumber = comp.value()->toObject(exec)->get(exec, Identifier(exec, "line"))->toInt32(exec);
UString sourceURL = comp.value()->toObject(exec)->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
UString exceptionSourceURL = comp.value()->toObject(exec)->get(exec, Identifier(exec, "sourceURL"))->toString(exec);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, exceptionSourceURL);
}
m_processingInlineCode = false;
m_sourceURL = savedSourceURL;
return 0;
}
......@@ -187,7 +188,7 @@ bool ScriptController::processingUserGesture() const
type == submitEvent)
return true;
} else { // no event
if (m_processingInlineCode && !m_processingTimerCallback) {
if (m_sourceURL && m_sourceURL->isNull() && !m_processingTimerCallback) {
// This is the <a href="javascript:window.open('...')> case -> we let it through
return true;
}
......
......@@ -56,7 +56,7 @@ public:
return m_windowShell->window();
}
KJS::JSValue* evaluate(const String& filename, int baseLine, const String& code);
KJS::JSValue* evaluate(const String& sourceURL, int baseLine, const String& code);
void clear();
PassRefPtr<EventListener> createHTMLEventHandler(const String& functionName, const String& code, Node*);
#if ENABLE(SVG)
......@@ -78,6 +78,8 @@ public:
void clearFormerWindow(JSDOMWindow* window) { m_liveFormerWindows.remove(window); }
void updateDocument();
const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script
private:
void initScriptIfNeeded()
{
......@@ -90,9 +92,9 @@ private:
HashSet<JSDOMWindow*> m_liveFormerWindows;
Frame* m_frame;
int m_handlerLineno;
const String* m_sourceURL;
bool m_processingTimerCallback;
bool m_processingInlineCode;
bool m_paused;
};
......
......@@ -33,6 +33,7 @@
#include "PlatformString.h"
#include "PluginArray.h"
#include "PluginData.h"
#include "ScriptController.h"
#include "Settings.h"
#ifndef WEBCORE_NAVIGATOR_PLATFORM
......@@ -99,13 +100,31 @@ String Navigator::appName() const
return "Netscape";
}
// If this function returns true, we need to hide the substring "4." that would otherwise
// appear in the appVersion string. This is to avoid problems with old versions of a
// library called OpenCube QuickMenus, which as of this writing is still being used on
// sites such as nwa.com -- the library thinks Safari is Netscape 4 if we don't do this!
static bool shouldHideFourDot(Frame* frame)
{
const String* sourceURL = frame->script()->sourceURL();
if (!sourceURL)
return false;
Settings* settings = frame->settings();
if (!settings)
return false;
return sourceURL->endsWith("/dqm_script.js") && settings->needsSiteSpecificQuirks();
}
String Navigator::appVersion() const
{
if (!m_frame)
return String();
// Version is everything in the user agent string past the "Mozilla/" prefix.
const String& userAgent = m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->url() : KURL());
return userAgent.substring(userAgent.find('/') + 1);
String appVersion = userAgent.substring(userAgent.find('/') + 1);
if (shouldHideFourDot(m_frame))
appVersion.replace("4.", "4_");
return appVersion;
}
String Navigator::language() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment