diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog index c53e4006f8a2e171cc4e609712f15fc21e99e653..dc4bb0e246780535a7a455bdebdb9b4ec7703989 100644 --- a/WebKit2/ChangeLog +++ b/WebKit2/ChangeLog @@ -1,3 +1,29 @@ +2010-07-26 Sam Weinig + + Reviewed by Anders Carlsson. + + Fix for https://bugs.webkit.org/show_bug.cgi?id=42986 + Add prompt and confirm client functions to WebKit2 + + * Shared/CoreIPCSupport/WebPageProxyMessageKinds.h: + (WebPageProxyMessage::): + * UIProcess/API/C/WKPage.h: + * UIProcess/WebPageProxy.cpp: + (WebKit::WebPageProxy::didReceiveSyncMessage): + (WebKit::WebPageProxy::runJavaScriptAlert): + (WebKit::WebPageProxy::runJavaScriptConfirm): + (WebKit::WebPageProxy::runJavaScriptPrompt): + * UIProcess/WebPageProxy.h: + * UIProcess/WebUIClient.cpp: + (WebKit::WebUIClient::runJavaScriptAlert): + (WebKit::WebUIClient::runJavaScriptConfirm): + (WebKit::WebUIClient::runJavaScriptPrompt): + * UIProcess/WebUIClient.h: + * WebKit2.xcodeproj/project.pbxproj: + * WebProcess/WebCoreSupport/WebChromeClient.cpp: + (WebKit::WebChromeClient::runJavaScriptConfirm): + (WebKit::WebChromeClient::runJavaScriptPrompt): + 2010-07-26 Adam Roben Windows build fix diff --git a/WebKit2/Shared/CoreIPCSupport/WebPageProxyMessageKinds.h b/WebKit2/Shared/CoreIPCSupport/WebPageProxyMessageKinds.h index 8aced4ddc82209c5f03ec83a7420e8912ce962f3..02cf099b7287ea6409ac7132010f32a02e0c85b4 100644 --- a/WebKit2/Shared/CoreIPCSupport/WebPageProxyMessageKinds.h +++ b/WebKit2/Shared/CoreIPCSupport/WebPageProxyMessageKinds.h @@ -36,6 +36,8 @@ enum Kind { CreateNewPage, ShowPage, RunJavaScriptAlert, + RunJavaScriptConfirm, + RunJavaScriptPrompt, ClosePage, DecidePolicyForMIMEType, diff --git a/WebKit2/UIProcess/API/C/WKPage.h b/WebKit2/UIProcess/API/C/WKPage.h index ea050ee85f7c060d7edc9bd212a6a6e61abe4acf..601f5553a578f72455553e8a476da03994a0d01c 100644 --- a/WebKit2/UIProcess/API/C/WKPage.h +++ b/WebKit2/UIProcess/API/C/WKPage.h @@ -116,6 +116,8 @@ typedef WKPageRef (*WKPageCreateNewPageCallback)(WKPageRef page, const void *cli typedef void (*WKPageShowPageCallback)(WKPageRef page, const void *clientInfo); typedef void (*WKPageCloseCallback)(WKPageRef page, const void *clientInfo); typedef void (*WKPageRunJavaScriptAlertCallback)(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void *clientInfo); +typedef bool (*WKPageRunJavaScriptConfirmCallback)(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo); +typedef WKStringRef (*WKPageRunJavaScriptPromptCallback)(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, const void *clientInfo); struct WKPageUIClient { int version; @@ -124,6 +126,8 @@ struct WKPageUIClient { WKPageShowPageCallback showPage; WKPageCloseCallback close; WKPageRunJavaScriptAlertCallback runJavaScriptAlert; + WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm; + WKPageRunJavaScriptPromptCallback runJavaScriptPrompt; }; typedef struct WKPageUIClient WKPageUIClient; diff --git a/WebKit2/UIProcess/WebPageProxy.cpp b/WebKit2/UIProcess/WebPageProxy.cpp index d065437a9afa2607184f7b08ab75862fc8be171a..863d6d9e6dd7892540535ffdcd1e9319bf915632 100644 --- a/WebKit2/UIProcess/WebPageProxy.cpp +++ b/WebKit2/UIProcess/WebPageProxy.cpp @@ -649,13 +649,35 @@ void WebPageProxy::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIP } case WebPageProxyMessage::RunJavaScriptAlert: { uint64_t frameID; - String alertText; - if (!arguments.decode(CoreIPC::Out(frameID, alertText))) + String message; + if (!arguments.decode(CoreIPC::Out(frameID, message))) return; - runJavaScriptAlert(webFrame(frameID), alertText); + runJavaScriptAlert(webFrame(frameID), message); break; } + case WebPageProxyMessage::RunJavaScriptConfirm: { + // FIXME: We should probably encode something in the case that the arguments do not decode correctly. + uint64_t frameID; + String message; + if (!arguments.decode(CoreIPC::Out(frameID, message))) + return; + + bool result = runJavaScriptConfirm(webFrame(frameID), message); + reply.encode(CoreIPC::In(result)); + break; + } + case WebPageProxyMessage::RunJavaScriptPrompt: { + // FIXME: We should probably encode something in the case that the arguments do not decode correctly. + uint64_t frameID; + String message; + String defaultValue; + if (!arguments.decode(CoreIPC::Out(frameID, message, defaultValue))) + return; + String result = runJavaScriptPrompt(webFrame(frameID), message, defaultValue); + reply.encode(CoreIPC::In(result)); + break; + } case WebPageProxyMessage::BackForwardCurrentItem: { WebBackForwardListItem* currentItem = m_backForwardList->currentItem(); uint64_t currentItemID = currentItem ? currentItem->itemID() : 0; @@ -832,11 +854,20 @@ void WebPageProxy::closePage() m_uiClient.close(this); } -void WebPageProxy::runJavaScriptAlert(WebFrameProxy* frame, const WebCore::String& alertText) +void WebPageProxy::runJavaScriptAlert(WebFrameProxy* frame, const String& message) { - m_uiClient.runJavaScriptAlert(this, alertText.impl(), frame); + m_uiClient.runJavaScriptAlert(this, message, frame); } +bool WebPageProxy::runJavaScriptConfirm(WebFrameProxy* frame, const String& message) +{ + return m_uiClient.runJavaScriptConfirm(this, message, frame); +} + +String WebPageProxy::runJavaScriptPrompt(WebFrameProxy* frame, const String& message, const String& defaultValue) +{ + return m_uiClient.runJavaScriptPrompt(this, message, defaultValue, frame); +} // HistoryClient diff --git a/WebKit2/UIProcess/WebPageProxy.h b/WebKit2/UIProcess/WebPageProxy.h index 0bfdef0885f81f310cc4c9d1392aa0e97374de6d..55f4d7c8b6a41641dd0ef4aaf3e3ecabfce14c81 100644 --- a/WebKit2/UIProcess/WebPageProxy.h +++ b/WebKit2/UIProcess/WebPageProxy.h @@ -187,6 +187,8 @@ private: void showPage(); void closePage(); void runJavaScriptAlert(WebFrameProxy*, const WebCore::String&); + bool runJavaScriptConfirm(WebFrameProxy* frame, const WebCore::String&); + WebCore::String runJavaScriptPrompt(WebFrameProxy* frame, const WebCore::String&, const WebCore::String&); void didNavigateWithNavigationData(WebFrameProxy*, const WebNavigationDataStore&); void didPerformClientRedirect(WebFrameProxy*, const WebCore::String& sourceURLString, const WebCore::String& destinationURLString); diff --git a/WebKit2/UIProcess/WebUIClient.cpp b/WebKit2/UIProcess/WebUIClient.cpp index ba4fc329aaeb6837969a2aba966fe648fc65dacd..bc3ea1a61d3965850374c29efc6600ef37a3bedb 100644 --- a/WebKit2/UIProcess/WebUIClient.cpp +++ b/WebKit2/UIProcess/WebUIClient.cpp @@ -26,6 +26,7 @@ #include "WebUIClient.h" #include "WKAPICast.h" +#include #include using namespace WebCore; @@ -69,13 +70,35 @@ void WebUIClient::close(WebPageProxy* page) m_pageUIClient.close(toRef(page), m_pageUIClient.clientInfo); } -void WebUIClient::runJavaScriptAlert(WebPageProxy* page, StringImpl* alertText, WebFrameProxy* frame) +void WebUIClient::runJavaScriptAlert(WebPageProxy* page, const String& message, WebFrameProxy* frame) { if (!m_pageUIClient.runJavaScriptAlert) return; - m_pageUIClient.runJavaScriptAlert(toRef(page), toRef(alertText), toRef(frame), m_pageUIClient.clientInfo); + m_pageUIClient.runJavaScriptAlert(toRef(page), toRef(message.impl()), toRef(frame), m_pageUIClient.clientInfo); } +bool WebUIClient::runJavaScriptConfirm(WebPageProxy* page, const String& message, WebFrameProxy* frame) +{ + if (!m_pageUIClient.runJavaScriptConfirm) + return false; + + return m_pageUIClient.runJavaScriptConfirm(toRef(page), toRef(message.impl()), toRef(frame), m_pageUIClient.clientInfo); +} + +String WebUIClient::runJavaScriptPrompt(WebPageProxy* page, const String& message, const String& defaultValue, WebFrameProxy* frame) +{ + if (!m_pageUIClient.runJavaScriptPrompt) + return String(); + + StringImpl* impl = toWK(m_pageUIClient.runJavaScriptPrompt(toRef(page), toRef(message.impl()), toRef(defaultValue.impl()), toRef(frame), m_pageUIClient.clientInfo)); + if (!impl) + return String(); + + String result = impl; + impl->deref(); + + return result; +} } // namespace WebKit diff --git a/WebKit2/UIProcess/WebUIClient.h b/WebKit2/UIProcess/WebUIClient.h index 55acef4cb8e352e1f76dc9e0dca3eb26163a8f9d..a6566246faf895d8610e018d94875d0671051a76 100644 --- a/WebKit2/UIProcess/WebUIClient.h +++ b/WebKit2/UIProcess/WebUIClient.h @@ -29,7 +29,7 @@ #include "WKPage.h" namespace WebCore { - class StringImpl; + class String; } namespace WebKit { @@ -45,7 +45,9 @@ public: WebPageProxy* createNewPage(WebPageProxy*); void showPage(WebPageProxy*); void close(WebPageProxy*); - void runJavaScriptAlert(WebPageProxy*, WebCore::StringImpl*, WebFrameProxy*); + void runJavaScriptAlert(WebPageProxy*, const WebCore::String&, WebFrameProxy*); + bool runJavaScriptConfirm(WebPageProxy*, const WebCore::String&, WebFrameProxy*); + WebCore::String runJavaScriptPrompt(WebPageProxy*, const WebCore::String&, const WebCore::String&, WebFrameProxy*); private: WKPageUIClient m_pageUIClient; diff --git a/WebKit2/WebKit2.xcodeproj/project.pbxproj b/WebKit2/WebKit2.xcodeproj/project.pbxproj index cde27ed909803750654fc9b02f7307b2cbd5069e..d62b4b2f12aee5bb8738219dc8e5a89f73701d7d 100644 --- a/WebKit2/WebKit2.xcodeproj/project.pbxproj +++ b/WebKit2/WebKit2.xcodeproj/project.pbxproj @@ -367,7 +367,7 @@ 32DBCF5E0370ADEE00C91783 /* WebKit2Prefix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKit2Prefix.h; sourceTree = ""; }; 5DAD7294116FF70B00EE5396 /* WebProcess.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebProcess.xcconfig; sourceTree = ""; }; 5DAD73F1116FF90C00EE5396 /* BaseTarget.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = BaseTarget.xcconfig; sourceTree = ""; }; - 6D8A91A511F0EFD100DD01FE /* com.apple.WebProcess.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.WebProcess.sb; sourceTree = ""; }; + 6D8A91A511F0EFD100DD01FE /* com.apple.WebProcess.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = com.apple.WebProcess.sb; path = WebProcess/com.apple.WebProcess.sb; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8DC2EF5B0486A6940098B216 /* WebKit2.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WebKit2.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BC0092F5115837A300E0AE2A /* RunLoopMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RunLoopMac.mm; sourceTree = ""; }; @@ -498,7 +498,6 @@ BCB63477116BF10600603215 /* WebKit2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKit2.h; sourceTree = ""; }; BCB7346D11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessProxyMessageKinds.h; sourceTree = ""; }; BCB86F4B116AAACD00CE20B7 /* WebKit2.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebKit2.xcconfig; sourceTree = ""; }; - BCB8D4E011AF78C1008F9103 /* WebKit2.exp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.exports; name = WebKit2.exp; path = mac/WebKit2.exp; sourceTree = ""; }; BCB9E2411120DACA00A137E0 /* WebContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContext.h; sourceTree = ""; }; BCB9E2421120DACA00A137E0 /* WebContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContext.cpp; sourceTree = ""; }; BCB9E2491120E15C00A137E0 /* WKContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContext.h; sourceTree = ""; }; @@ -619,8 +618,8 @@ children = ( BC8A500E11765AD400757573 /* WebKit2 */, BC8A500F11765AE300757573 /* WebProcess */, + 6D8A91A511F0EFD100DD01FE /* com.apple.WebProcess.sb */, 089C1666FE841158C02AAC07 /* InfoPlist.strings */, - BCB8D4E011AF78C1008F9103 /* WebKit2.exp */, ); name = Resources; sourceTree = ""; @@ -796,7 +795,6 @@ BC032D5C10F436D50058C15A /* WebProcess */ = { isa = PBXGroup; children = ( - 6D8A91A511F0EFD100DD01FE /* com.apple.WebProcess.sb */, BC204EDF11C83E72008F3375 /* InjectedBundle */, 1A6FA01C11E1526300DB1371 /* mac */, 1A6FB7AA11E64B4900DB1371 /* Plugins */, diff --git a/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp b/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp index 848071a5394189885e8e029f5b26178e3d718e87..2325809210e89d7b6152eb8037851b2ef233235a 100644 --- a/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp +++ b/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp @@ -229,8 +229,15 @@ bool WebChromeClient::runJavaScriptConfirm(Frame* frame, const String& message) // Notify the bundle client. m_page->injectedBundleUIClient().willRunJavaScriptConfirm(m_page, message, webFrame); - // Implement for UIProcess. - return false; + bool result = false; + if (!WebProcess::shared().connection()->sendSync(WebPageProxyMessage::RunJavaScriptConfirm, m_page->pageID(), + CoreIPC::In(webFrame->frameID(), message), + CoreIPC::Out(result), + CoreIPC::Connection::NoTimeout)) { + return false; + } + + return result; } bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result) @@ -240,8 +247,14 @@ bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& message, c // Notify the bundle client. m_page->injectedBundleUIClient().willRunJavaScriptPrompt(m_page, message, defaultValue, webFrame); - // Implement for UIProcess. - return false; + if (!WebProcess::shared().connection()->sendSync(WebPageProxyMessage::RunJavaScriptPrompt, m_page->pageID(), + CoreIPC::In(webFrame->frameID(), message, defaultValue), + CoreIPC::Out(result), + CoreIPC::Connection::NoTimeout)) { + return false; + } + + return !result.isNull(); } void WebChromeClient::setStatusbarText(const String& statusbarText) diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog index e8dbe0110411b85c97a852249b57169391fccd50..16c9dd7ec5a284f0ac780daf875872d9c8d2b480 100644 --- a/WebKitTools/ChangeLog +++ b/WebKitTools/ChangeLog @@ -1,3 +1,13 @@ +2010-07-26 Sam Weinig + + Reviewed by Anders Carlsson. + + Fix for https://bugs.webkit.org/show_bug.cgi?id=42986 + Add prompt and confirm client functions to WebKit2 + + * MiniBrowser/mac/BrowserWindowController.m: + (-[BrowserWindowController awakeFromNib]): + 2010-07-26 Adam Roben Windows build fix diff --git a/WebKitTools/Makefile b/WebKitTools/Makefile index c1f19917e9090101f10326284bb12fe5c81e6c22..57ea0979fef99d7fd214006f55b6175beb2e7044 100644 --- a/WebKitTools/Makefile +++ b/WebKitTools/Makefile @@ -1,4 +1,4 @@ -MODULES = DumpRenderTree MiniBrowser +MODULES = DumpRenderTree WebKitTestRunner MiniBrowser all: @for dir in $(MODULES); do ${MAKE} $@ -C $$dir; exit_status=$$?; \ diff --git a/WebKitTools/MiniBrowser/mac/BrowserWindowController.m b/WebKitTools/MiniBrowser/mac/BrowserWindowController.m index 234c04c3bdfa55fc21c7a2e03b96c8929698e308..cb67648c843c1a9553dca74a180bac5477d9bb01 100644 --- a/WebKitTools/MiniBrowser/mac/BrowserWindowController.m +++ b/WebKitTools/MiniBrowser/mac/BrowserWindowController.m @@ -152,105 +152,105 @@ - (void)applicationTerminating #pragma mark Loader Client Callbacks -static void _didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { [(BrowserWindowController *)clientInfo didStartProvisionalLoadForFrame:frame]; } -static void _didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { [(BrowserWindowController *)clientInfo didReceiveServerRedirectForProvisionalLoadForFrame:frame]; } -static void _didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { [(BrowserWindowController *)clientInfo didFailProvisionalLoadWithErrorForFrame:frame]; } -static void _didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { [(BrowserWindowController *)clientInfo didCommitLoadForFrame:frame]; } -static void _didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { LOG(@"didFinishLoadForFrame"); } -static void _didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { [(BrowserWindowController *)clientInfo didFailLoadWithErrorForFrame:frame]; } -static void _didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, const void *clientInfo) +static void didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, const void *clientInfo) { CFStringRef cfTitle = WKStringCopyCFString(0, title); LOG(@"didReceiveTitleForFrame \"%@\"", (NSString *)cfTitle); CFRelease(cfTitle); } -static void _didFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { LOG(@"didFirstLayoutForFrame"); } -static void _didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) +static void didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, const void *clientInfo) { LOG(@"didFirstVisuallyNonEmptyLayoutForFrame"); } -static void _didStartProgress(WKPageRef page, const void *clientInfo) +static void didStartProgress(WKPageRef page, const void *clientInfo) { [(BrowserWindowController *)clientInfo didStartProgress]; } -static void _didChangeProgress(WKPageRef page, const void *clientInfo) +static void didChangeProgress(WKPageRef page, const void *clientInfo) { [(BrowserWindowController *)clientInfo didChangeProgress:WKPageGetEstimatedProgress(page)]; } -static void _didFinishProgress(WKPageRef page, const void *clientInfo) +static void didFinishProgress(WKPageRef page, const void *clientInfo) { [(BrowserWindowController *)clientInfo didFinishProgress]; } -static void _didBecomeUnresponsive(WKPageRef page, const void *clientInfo) +static void didBecomeUnresponsive(WKPageRef page, const void *clientInfo) { LOG(@"didBecomeUnresponsive"); } -static void _didBecomeResponsive(WKPageRef page, const void *clientInfo) +static void didBecomeResponsive(WKPageRef page, const void *clientInfo) { LOG(@"didBecomeResponsive"); } -static void _didChangeBackForwardList(WKPageRef page, const void *clientInfo) +static void didChangeBackForwardList(WKPageRef page, const void *clientInfo) { [(BrowserWindowController *)clientInfo validateToolbar]; } #pragma mark Policy Client Callbacks -static void _decidePolicyForNavigationAction(WKPageRef page, WKFrameNavigationType navigationType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo) +static void decidePolicyForNavigationAction(WKPageRef page, WKFrameNavigationType navigationType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo) { LOG(@"decidePolicyForNavigationAction"); WKFramePolicyListenerUse(listener); } -static void _decidePolicyForNewWindowAction(WKPageRef page, WKFrameNavigationType navigationType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo) +static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameNavigationType navigationType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo) { LOG(@"decidePolicyForNewWindowAction"); WKFramePolicyListenerUse(listener); } -static void _decidePolicyForMIMEType(WKPageRef page, WKStringRef MIMEType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo) +static void decidePolicyForMIMEType(WKPageRef page, WKStringRef MIMEType, WKURLRef url, WKFrameRef frame, WKFramePolicyListenerRef listener, const void *clientInfo) { WKFramePolicyListenerUse(listener); } #pragma mark UI Client Callbacks -static WKPageRef _createNewPage(WKPageRef page, const void* clientInfo) +static WKPageRef createNewPage(WKPageRef page, const void* clientInfo) { LOG(@"createNewPage"); BrowserWindowController *controller = [[BrowserWindowController alloc] initWithPageNamespace:WKPageGetPageNamespace(page)]; @@ -259,13 +259,13 @@ static WKPageRef _createNewPage(WKPageRef page, const void* clientInfo) return controller->_webView.pageRef; } -static void _showPage(WKPageRef page, const void *clientInfo) +static void showPage(WKPageRef page, const void *clientInfo) { LOG(@"showPage"); [[(BrowserWindowController *)clientInfo window] orderFront:nil]; } -static void _closePage(WKPageRef page, const void *clientInfo) +static void closePage(WKPageRef page, const void *clientInfo) { LOG(@"closePage"); WKPageClose(page); @@ -273,17 +273,17 @@ static void _closePage(WKPageRef page, const void *clientInfo) WKPageRelease(page); } -static void _runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) +static void runJavaScriptAlert(WKPageRef page, WKStringRef message, WKFrameRef frame, const void* clientInfo) { NSAlert* alert = [[NSAlert alloc] init]; CFURLRef cfURL = WKURLCopyCFURL(0, WKFrameGetURL(frame)); - [alert setMessageText:[NSString stringWithFormat:@"JavaScript Alert from %@.", [(NSURL *)cfURL absoluteString]]]; + [alert setMessageText:[NSString stringWithFormat:@"JavaScript alert dialog from %@.", [(NSURL *)cfURL absoluteString]]]; CFRelease(cfURL); - CFStringRef cfAlertText = WKStringCopyCFString(0, alertText); - [alert setInformativeText:(NSString *)alertText]; - CFRelease(cfAlertText); + CFStringRef cfMessage = WKStringCopyCFString(0, message); + [alert setInformativeText:(NSString *)cfMessage]; + CFRelease(cfMessage); [alert addButtonWithTitle:@"OK"]; @@ -291,10 +291,67 @@ static void _runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRe [alert release]; } +static bool runJavaScriptConfirm(WKPageRef page, WKStringRef message, WKFrameRef frame, const void* clientInfo) +{ + NSAlert* alert = [[NSAlert alloc] init]; + + CFURLRef cfURL = WKURLCopyCFURL(0, WKFrameGetURL(frame)); + [alert setMessageText:[NSString stringWithFormat:@"JavaScript confirm dialog from %@.", [(NSURL *)cfURL absoluteString]]]; + CFRelease(cfURL); + + CFStringRef cfMessage = WKStringCopyCFString(0, message); + [alert setInformativeText:(NSString *)cfMessage]; + CFRelease(cfMessage); + + [alert addButtonWithTitle:@"OK"]; + [alert addButtonWithTitle:@"Cancel"]; + + NSInteger button = [alert runModal]; + [alert release]; + + return button == NSAlertFirstButtonReturn; +} + +static WKStringRef runJavaScriptPrompt(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, const void* clientInfo) +{ + NSAlert* alert = [[NSAlert alloc] init]; + + CFURLRef cfURL = WKURLCopyCFURL(0, WKFrameGetURL(frame)); + [alert setMessageText:[NSString stringWithFormat:@"JavaScript prompt dialog from %@.", [(NSURL *)cfURL absoluteString]]]; + CFRelease(cfURL); + + CFStringRef cfMessage = WKStringCopyCFString(0, message); + [alert setInformativeText:(NSString *)cfMessage]; + CFRelease(cfMessage); + + [alert addButtonWithTitle:@"OK"]; + [alert addButtonWithTitle:@"Cancel"]; + + NSTextField* input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)]; + CFStringRef cfDefaultValue = WKStringCopyCFString(0, defaultValue); + [input setStringValue:(NSString *)cfDefaultValue]; + CFRelease(cfDefaultValue); + + [alert setAccessoryView:input]; + + NSInteger button = [alert runModal]; + + NSString* result = nil; + if (button == NSAlertFirstButtonReturn) { + [input validateEditing]; + result = [input stringValue]; + } + + [alert release]; + + if (!result) + return 0; + return WKStringCreateWithCFString((CFStringRef)result); +} #pragma mark History Client Callbacks -static void _didNavigateWithNavigationData(WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void *clientInfo) +static void didNavigateWithNavigationData(WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef frame, const void *clientInfo) { CFStringRef title = WKStringCopyCFString(0, WKNavigationDataGetTitle(navigationData)); CFURLRef url = WKURLCopyCFURL(0, WKNavigationDataGetURL(navigationData)); @@ -303,7 +360,7 @@ static void _didNavigateWithNavigationData(WKPageRef page, WKNavigationDataRef n CFRelease(url); } -static void _didPerformClientRedirect(WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo) +static void didPerformClientRedirect(WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo) { CFURLRef cfSourceURL = WKURLCopyCFURL(0, sourceURL); CFURLRef cfDestinationURL = WKURLCopyCFURL(0, destinationURL); @@ -312,7 +369,7 @@ static void _didPerformClientRedirect(WKPageRef page, WKURLRef sourceURL, WKURLR CFRelease(cfDestinationURL); } -static void _didPerformServerRedirect(WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo) +static void didPerformServerRedirect(WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef frame, const void *clientInfo) { CFURLRef cfSourceURL = WKURLCopyCFURL(0, sourceURL); CFURLRef cfDestinationURL = WKURLCopyCFURL(0, destinationURL); @@ -321,7 +378,7 @@ static void _didPerformServerRedirect(WKPageRef page, WKURLRef sourceURL, WKURLR CFRelease(cfDestinationURL); } -static void _didUpdateHistoryTitle(WKPageRef page, WKStringRef title, WKURLRef URL, WKFrameRef frame, const void *clientInfo) +static void didUpdateHistoryTitle(WKPageRef page, WKStringRef title, WKURLRef URL, WKFrameRef frame, const void *clientInfo) { CFStringRef cfTitle = WKStringCopyCFString(0, title); CFURLRef cfURL = WKURLCopyCFURL(0, URL); @@ -342,50 +399,52 @@ - (void)awakeFromNib WKPageLoaderClient loadClient = { 0, /* version */ self, /* clientInfo */ - _didStartProvisionalLoadForFrame, - _didReceiveServerRedirectForProvisionalLoadForFrame, - _didFailProvisionalLoadWithErrorForFrame, - _didCommitLoadForFrame, - _didFinishLoadForFrame, - _didFailLoadWithErrorForFrame, - _didReceiveTitleForFrame, - _didFirstLayoutForFrame, - _didFirstVisuallyNonEmptyLayoutForFrame, - _didStartProgress, - _didChangeProgress, - _didFinishProgress, - _didBecomeUnresponsive, - _didBecomeResponsive, - _didChangeBackForwardList + didStartProvisionalLoadForFrame, + didReceiveServerRedirectForProvisionalLoadForFrame, + didFailProvisionalLoadWithErrorForFrame, + didCommitLoadForFrame, + didFinishLoadForFrame, + didFailLoadWithErrorForFrame, + didReceiveTitleForFrame, + didFirstLayoutForFrame, + didFirstVisuallyNonEmptyLayoutForFrame, + didStartProgress, + didChangeProgress, + didFinishProgress, + didBecomeUnresponsive, + didBecomeResponsive, + didChangeBackForwardList }; WKPageSetPageLoaderClient(_webView.pageRef, &loadClient); WKPagePolicyClient policyClient = { 0, /* version */ self, /* clientInfo */ - _decidePolicyForNavigationAction, - _decidePolicyForNewWindowAction, - _decidePolicyForMIMEType + decidePolicyForNavigationAction, + decidePolicyForNewWindowAction, + decidePolicyForMIMEType }; WKPageSetPagePolicyClient(_webView.pageRef, &policyClient); WKPageUIClient uiClient = { 0, /* version */ self, /* clientInfo */ - _createNewPage, - _showPage, - _closePage, - _runJavaScriptAlert + createNewPage, + showPage, + closePage, + runJavaScriptAlert, + runJavaScriptConfirm, + runJavaScriptPrompt }; WKPageSetPageUIClient(_webView.pageRef, &uiClient); WKPageHistoryClient historyClient = { 0, self, - _didNavigateWithNavigationData, - _didPerformClientRedirect, - _didPerformServerRedirect, - _didUpdateHistoryTitle, + didNavigateWithNavigationData, + didPerformClientRedirect, + didPerformServerRedirect, + didUpdateHistoryTitle, }; WKPageSetPageHistoryClient(_webView.pageRef, &historyClient);