Commit 016eed14 authored by timothy@apple.com's avatar timothy@apple.com

Reviewed by John.

        <rdar://problem/5103720> REGRESSION: [WebView stringByEvaluatingJavaScriptFromString:] fails if "return" is used

        Extend the linked on or after check to every application when a script passed to
        stringByEvaluatingJavaScriptFromString: has a return statement. Before the check
        was limited to VitalSource Bookshelf, but other developers are running into this.

        * Misc/WebKitVersionChecks.h: Add the WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK define.
        * WebView/WebDocumentLoaderMac.mm:
        (needsDataLoadWorkaround): Use WEBKIT_FIRST_VERSION_WITHOUT_ADOBE_INSTALLER_QUIRK sicne the
          WebKitLinkedOnOrAfter check here was about the Adobe installer, not VitalSource.
        * WebView/WebView.mm:
        (-[WebView stringByEvaluatingJavaScriptFromString:]): Remove the bundle ID check and use
          WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK for the WebKitLinkedOnOrAfter call.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27653 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 745cedc5
2007-11-09 Timothy Hatcher <timothy@apple.com>
Reviewed by John.
<rdar://problem/5103720> REGRESSION: [WebView stringByEvaluatingJavaScriptFromString:] fails if "return" is used
Extend the linked on or after check to every application when a script passed to
stringByEvaluatingJavaScriptFromString: has a return statement. Before the check
was limited to VitalSource Bookshelf, but other developers are running into this.
* Misc/WebKitVersionChecks.h: Add the WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK define.
* WebView/WebDocumentLoaderMac.mm:
(needsDataLoadWorkaround): Use WEBKIT_FIRST_VERSION_WITHOUT_ADOBE_INSTALLER_QUIRK sicne the
WebKitLinkedOnOrAfter check here was about the Adobe installer, not VitalSource.
* WebView/WebView.mm:
(-[WebView stringByEvaluatingJavaScriptFromString:]): Remove the bundle ID check and use
WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK for the WebKitLinkedOnOrAfter call.
2007-11-08 Kevin McCullough <kmccullough@apple.com>
Build Fix.
......
......@@ -38,11 +38,11 @@
#define WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION 0x020A0000 // 522.0.0
#define WEBKIT_FIRST_VERSION_WITHOUT_APERTURE_QUIRK 0x020A0000 // 522.0.0
#define WEBKIT_FIRST_VERSION_WITHOUT_QUICKBOOKS_QUIRK 0x020A0000 // 522.0.0
#define WEBKIT_FIRST_VERSION_WITHOUT_VITALSOURCE_QUIRK 0x020A0000 // 522.0.0
#define WEBKIT_FIRST_VERSION_WITH_MAIN_THREAD_EXCEPTIONS 0x020A0000 // 522.0.0
#define WEBKIT_FIRST_VERSION_WITHOUT_ADOBE_INSTALLER_QUIRK 0x020A0000 // 522.0.0
#define WEBKIT_FIRST_VERSION_WITH_INSPECT_ELEMENT_MENU_TAG 0x020A0C00 // 522.12.0
#define WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API 0x020B0500 // 523.5.0
#define WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK 0x020D0100 // 525.1.0
#define WEBKIT_FIRST_CFNETWORK_VERSION_WITH_LARGE_DISK_CACHE_FIX 0x00D30000 // 211
......
......@@ -56,7 +56,7 @@ static inline bool needsDataLoadWorkaround(WebView *webView)
return true;
return false;
#else
static bool needsWorkaround = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITHOUT_VITALSOURCE_QUIRK)
static bool needsWorkaround = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITHOUT_ADOBE_INSTALLER_QUIRK)
&& [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.adobe.Installers.Setup"];
return needsWorkaround;
#endif
......
......@@ -2263,20 +2263,21 @@ WebFrameLoadDelegateImplementationCache WebViewGetFrameLoadDelegateImplementatio
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
{
// FIXME: We can remove this workaround for VitalSource Bookshelf when they update
// their code so that it no longer calls stringByEvaluatingJavaScriptFromString with a return statement.
// Return statements are only valid in a function. See <rdar://problem/5095515> for the evangelism bug.
if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITHOUT_VITALSOURCE_QUIRK) && [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.vitalsource.bookshelf"]) {
// Return statements are only valid in a function but some applications pass in scripts
// prefixed with return (<rdar://problems/5103720&4616860>) since older WebKit versions
// silently ignored the return. If the application is linked against an earlier version
// of WebKit we will strip the return so the script wont fail.
if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK)) {
NSRange returnStringRange = [script rangeOfString:@"return "];
if (returnStringRange.length != 0 && returnStringRange.location == 0)
script = [script substringFromIndex: returnStringRange.location + returnStringRange.length];
if (returnStringRange.length && !returnStringRange.location)
script = [script substringFromIndex:returnStringRange.location + returnStringRange.length];
}
NSString *result = [[[self mainFrame] _bridge] stringByEvaluatingJavaScriptFromString:script];
// The only way stringByEvaluatingJavaScriptFromString can return nil is if the frame was removed by the script
// Since there's no way to get rid of the main frame, result will never ever be nil here.
ASSERT(result);
return result;
}
......
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