Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (171354 => 171355)
--- trunk/Source/_javascript_Core/ChangeLog 2014-07-22 19:46:41 UTC (rev 171354)
+++ trunk/Source/_javascript_Core/ChangeLog 2014-07-22 19:48:24 UTC (rev 171355)
@@ -1,3 +1,13 @@
+2014-07-21 Sam Weinig <s...@webkit.org>
+
+ [Cocoa] WKScriptMessageHandlers don't seem to function properly after navigating
+ https://bugs.webkit.org/show_bug.cgi?id=135148
+
+ Reviewed by Geoffrey Garen.
+
+ * runtime/CommonIdentifiers.h:
+ Add a common identifier for the string "webkit".
+
2014-07-22 Filip Pizlo <fpi...@apple.com>
ASSERTION FAILED: info.spillFormat() & DataFormatJS in JSC::DFG::SpeculativeJIT::fillSpeculateCell
Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (171354 => 171355)
--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2014-07-22 19:46:41 UTC (rev 171354)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2014-07-22 19:48:24 UTC (rev 171355)
@@ -166,6 +166,7 @@
macro(value) \
macro(valueOf) \
macro(values) \
+ macro(webkit) \
macro(window) \
macro(writable)
Modified: trunk/Source/WebCore/ChangeLog (171354 => 171355)
--- trunk/Source/WebCore/ChangeLog 2014-07-22 19:46:41 UTC (rev 171354)
+++ trunk/Source/WebCore/ChangeLog 2014-07-22 19:48:24 UTC (rev 171355)
@@ -1,3 +1,26 @@
+2014-07-21 Sam Weinig <s...@webkit.org>
+
+ [Cocoa] WKScriptMessageHandlers don't seem to function properly after navigating
+ https://bugs.webkit.org/show_bug.cgi?id=135148
+
+ Reviewed by Geoffrey Garen.
+
+ The "webkit" property on the window was not getting installed for subsequent
+ loads due to intricate dance playing setting the JSDOMWindow where the DOMWindow
+ object is not yet in a Frame when the JSDOMWindow is created. Since we were
+ adding the "webkit" property on construction, the property was returning null
+ thinking it had no Frame and was in a bad state. We can fix this by making the
+ "webkit" property behave like all the other window properties moving its getting
+ to JSDOMWindow::getOwnPropertySlot.
+
+ Added API test (WebKit2Cocoa/UserContentController).
+
+ * bindings/js/JSDOMWindowBase.cpp:
+ (WebCore::JSDOMWindowBase::finishCreation):
+ * bindings/js/JSDOMWindowCustom.cpp:
+ (WebCore::jsDOMWindowWebKit):
+ (WebCore::JSDOMWindow::getOwnPropertySlot):
+
2014-07-22 Brent Fulgham <bfulg...@apple.com>
[Win] Fix Leak in WebCore::createGlobalImageFileDescriptor
Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp (171354 => 171355)
--- trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp 2014-07-22 19:46:41 UTC (rev 171354)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp 2014-07-22 19:48:24 UTC (rev 171355)
@@ -39,10 +39,6 @@
#include <runtime/Microtask.h>
#include <wtf/MainThread.h>
-#if ENABLE(USER_MESSAGE_HANDLERS)
-#include "JSWebKitNamespace.h"
-#endif
-
#if PLATFORM(IOS)
#include "ChromeClient.h"
#include "WebSafeGCActivityCallbackIOS.h"
@@ -81,11 +77,6 @@
};
addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
-
-#if ENABLE(USER_MESSAGE_HANDLERS)
- if (m_impl->shouldHaveWebKitNamespaceForWorld(world()))
- putDirect(vm, Identifier(&vm, "webkit"), toJS(globalExec(), this, m_impl->webkitNamespace()), DontDelete | ReadOnly);
-#endif
}
void JSDOMWindowBase::destroy(JSCell* cell)
Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp (171354 => 171355)
--- trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp 2014-07-22 19:46:41 UTC (rev 171354)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp 2014-07-22 19:48:24 UTC (rev 171355)
@@ -54,6 +54,10 @@
#include "JSWebSocket.h"
#endif
+#if ENABLE(USER_MESSAGE_HANDLERS)
+#include "JSWebKitNamespace.h"
+#endif
+
using namespace JSC;
namespace WebCore {
@@ -91,6 +95,16 @@
return JSValue::encode(toJS(exec, thisObj->globalObject(), toHTMLDocument(document)->windowNamedItem(*atomicPropertyName)));
}
+#if ENABLE(USER_MESSAGE_HANDLERS)
+static EncodedJSValue jsDOMWindowWebKit(ExecState* exec, JSObject*, EncodedJSValue thisValue, PropertyName)
+{
+ JSDOMWindow* castedThis = toJSDOMWindow(JSValue::decode(thisValue));
+ if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))
+ return JSValue::encode(jsUndefined());
+ return JSValue::encode(toJS(exec, castedThis->globalObject(), castedThis->impl().webkitNamespace()));
+}
+#endif
+
bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object);
@@ -174,6 +188,13 @@
return true;
}
+#if ENABLE(USER_MESSAGE_HANDLERS)
+ if (propertyName == exec->propertyNames().webkit && thisObject->impl().shouldHaveWebKitNamespaceForWorld(thisObject->world())) {
+ slot.setCacheableCustom(thisObject, allowsAccess ? DontDelete | ReadOnly : ReadOnly | DontDelete | DontEnum, jsDOMWindowWebKit);
+ return true;
+ }
+#endif
+
// Do prototype lookup early so that functions and attributes in the prototype can have
// precedence over the index and name getters.
JSValue proto = thisObject->prototype();
Modified: trunk/Tools/ChangeLog (171354 => 171355)
--- trunk/Tools/ChangeLog 2014-07-22 19:46:41 UTC (rev 171354)
+++ trunk/Tools/ChangeLog 2014-07-22 19:48:24 UTC (rev 171355)
@@ -1,3 +1,15 @@
+2014-07-21 Sam Weinig <s...@webkit.org>
+
+ [Cocoa] WKScriptMessageHandlers don't seem to function properly after navigating
+ https://bugs.webkit.org/show_bug.cgi?id=135148
+
+ Reviewed by Geoffrey Garen.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm: Added.
+ (-[SimpleNavigationDelegate webView:didFinishNavigation:]):
+ (-[ScriptMessageHandler userContentController:didReceiveScriptMessage:]):
+
2014-07-22 Brent Fulgham <bfulg...@apple.com>
Correct handling of __VERSION_TEXT__ for 4+-tuple versions
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (171354 => 171355)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2014-07-22 19:46:41 UTC (rev 171354)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2014-07-22 19:48:24 UTC (rev 171355)
@@ -122,6 +122,7 @@
7C74D42F188228F300E5ED57 /* StringView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C74D42D188228F300E5ED57 /* StringView.cpp */; };
7C8DDAAB1735DEEE00EA5AC0 /* CloseThenTerminate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C8DDAA91735DE1D00EA5AC0 /* CloseThenTerminate.cpp */; };
7C9ED98B17A19F4B00E4DC33 /* attributedStringStrikethrough.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7C9ED98A17A19D0600E4DC33 /* attributedStringStrikethrough.html */; };
+ 7CC3E1FC197E234100BE6252 /* UserContentController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CC3E1FA197E234100BE6252 /* UserContentController.mm */; };
7CFBCADF1743234F00B2BFCF /* WillLoad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */; };
7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81B50192140F232300D9EB58 /* StringBuilder.cpp */; };
@@ -462,6 +463,7 @@
7C74D42D188228F300E5ED57 /* StringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringView.cpp; sourceTree = "<group>"; };
7C8DDAA91735DE1D00EA5AC0 /* CloseThenTerminate.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CloseThenTerminate.cpp; sourceTree = "<group>"; };
7C9ED98A17A19D0600E4DC33 /* attributedStringStrikethrough.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = attributedStringStrikethrough.html; sourceTree = "<group>"; };
+ 7CC3E1FA197E234100BE6252 /* UserContentController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UserContentController.mm; sourceTree = "<group>"; };
7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
@@ -702,6 +704,7 @@
children = (
A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
+ 7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
);
name = "WebKit2 Cocoa";
path = WebKit2Cocoa;
@@ -1245,6 +1248,7 @@
290F427B172A23A500939FF0 /* TestProtocol.mm in Sources */,
1AA9E55914980A9900001A8A /* Functional.cpp in Sources */,
C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
+ 7CC3E1FC197E234100BE6252 /* UserContentController.mm in Sources */,
F660AA0D15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */,
0BCD833514857CE400EA2003 /* HashMap.cpp in Sources */,
2DD7D3AA178205D00026E1E3 /* ResizeReversePaginatedWebView.cpp in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm (0 => 171355)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm 2014-07-22 19:48:24 UTC (rev 171355)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+
+static bool isDoneWithNavigation;
+
+@interface SimpleNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation SimpleNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+ isDoneWithNavigation = true;
+}
+
+@end
+
+static bool receivedScriptMessage;
+static RetainPtr<WKScriptMessage> lastScriptMessage;
+
+@interface ScriptMessageHandler : NSObject <WKScriptMessageHandler>
+@end
+
+@implementation ScriptMessageHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+ receivedScriptMessage = true;
+ lastScriptMessage = message;
+}
+
+@end
+
+TEST(WKUserContentController, ScriptMessageHandlerSimple)
+{
+ RetainPtr<ScriptMessageHandler> handler = adoptNS([[ScriptMessageHandler alloc] init]);
+ RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+ [webView loadRequest:request];
+
+ TestWebKitAPI::Util::run(&isDoneWithNavigation);
+
+ [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Hello')" completionHandler:nil];
+
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ receivedScriptMessage = false;
+
+ EXPECT_WK_STREQ(@"Hello", (NSString *)[lastScriptMessage body]);
+}
+
+TEST(WKUserContentController, ScriptMessageHandlerWithNavigation)
+{
+ RetainPtr<ScriptMessageHandler> handler = adoptNS([[ScriptMessageHandler alloc] init]);
+ RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ [webView loadRequest:request];
+
+ TestWebKitAPI::Util::run(&isDoneWithNavigation);
+ isDoneWithNavigation = false;
+
+ [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('First Message')" completionHandler:nil];
+
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+
+ EXPECT_WK_STREQ(@"First Message", (NSString *)[lastScriptMessage body]);
+
+ receivedScriptMessage = false;
+ lastScriptMessage = nullptr;
+
+
+ [webView loadRequest:request];
+ TestWebKitAPI::Util::run(&isDoneWithNavigation);
+ isDoneWithNavigation = false;
+
+ [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Second Message')" completionHandler:nil];
+
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+
+ EXPECT_WK_STREQ(@"Second Message", (NSString *)[lastScriptMessage body]);
+}
+
+#endif