Reviewed by Kevin Ollivier.
authorkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2009 02:37:12 +0000 (02:37 +0000)
committerkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2009 02:37:12 +0000 (02:37 +0000)
Add events to allow apps to override handling for JS prompts and
window object cleared events.

https://bugs.webkit.org/show_bug.cgi?id=24948

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@42122 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/wx/ChangeLog
WebKit/wx/WebFrame.h
WebKit/wx/WebKitSupport/ChromeClientWx.cpp
WebKit/wx/WebKitSupport/EditorClientWx.cpp
WebKit/wx/WebKitSupport/FrameLoaderClientWx.cpp
WebKit/wx/WebView.cpp
WebKit/wx/WebView.h

index c06a0b9b3f4faa020f3358140de24ee2b55f34aa..c01fc63736e208be151476f4b5d259c2f7f46309 100644 (file)
@@ -1,3 +1,29 @@
+2009-03-30  Kevin Watters  <kevinwatters@gmail.com>
+
+        Reviewed by Kevin Ollivier.
+        
+        Add events to allow apps to override handling for JS prompts and 
+        window object cleared events.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=24948
+
+        * WebFrame.h:
+        * WebKitSupport/ChromeClientWx.cpp:
+        (WebCore::ChromeClientWx::runJavaScriptAlert):
+        (WebCore::ChromeClientWx::runJavaScriptConfirm):
+        (WebCore::ChromeClientWx::runJavaScriptPrompt):
+        * WebKitSupport/EditorClientWx.cpp:
+        (WebCore::EditorClientWx::pageDestroyed):
+        * WebKitSupport/FrameLoaderClientWx.cpp:
+        (WebCore::FrameLoaderClientWx::hasWebView):
+        (WebCore::FrameLoaderClientWx::windowObjectCleared):
+        * WebView.cpp:
+        (wxWebViewAlertEvent::wxWebViewAlertEvent):
+        (wxWebViewConfirmEvent::wxWebViewConfirmEvent):
+        (wxWebViewPromptEvent::wxWebViewPromptEvent):
+        (wxWebViewWindowObjectClearedEvent::wxWebViewWindowObjectClearedEvent):
+        * WebView.h:
+
 2009-03-28  Kevin Ollivier  <kevino@theolliviers.com>
 
         wx build fix. Remove call to now private method.
index 5c697d6720f0514443fc0a77dff2063f9579f32c..fb9526e5caf49f119ef451f06ba7e22391a0e87f 100644 (file)
@@ -98,6 +98,7 @@ class WXDLLIMPEXP_WEBKIT wxWebFrame
     friend class WebCore::EditorClientWx;
     friend class wxWebView;
 
+public:
     wxWebFrame(wxWebView* container, wxWebFrame* parent = NULL, WebViewFrameData* data = NULL);
     
     ~wxWebFrame();
index 29fef0eb0c6771353f551c6007add4f22912cb5a..897572de8b7e7a21d54e4a036a5cb52b216eb378 100644 (file)
@@ -239,25 +239,50 @@ void ChromeClientWx::closeWindowSoon()
 
 void ChromeClientWx::runJavaScriptAlert(Frame* frame, const String& string)
 {
-    wxMessageBox(string, wxT("JavaScript Alert"), wxOK);
+    if (m_webView) {
+        wxWebViewAlertEvent wkEvent(m_webView);
+        wkEvent.SetMessage(string);
+        if (!m_webView->GetEventHandler()->ProcessEvent(wkEvent))
+            wxMessageBox(string, wxT("JavaScript Alert"), wxOK);
+    }
 }
 
 bool ChromeClientWx::runJavaScriptConfirm(Frame* frame, const String& string)
 {
-    wxMessageDialog dialog(NULL, string, wxT("JavaScript Confirm"), wxYES_NO);
-    dialog.Centre();
-    return (dialog.ShowModal() == wxID_YES);
+    bool result = false;
+    if (m_webView) {
+        wxWebViewConfirmEvent wkEvent(m_webView);
+        wkEvent.SetMessage(string);
+        if (m_webView->GetEventHandler()->ProcessEvent(wkEvent))
+            result = wkEvent.GetReturnCode() == wxID_YES;
+        else {
+            wxMessageDialog dialog(NULL, string, wxT("JavaScript Confirm"), wxYES_NO);
+            dialog.Centre();
+            result = (dialog.ShowModal() == wxID_YES);
+        }
+    }
+    return result;
 }
 
 bool ChromeClientWx::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
 {
-    wxTextEntryDialog dialog(NULL, message, wxT("JavaScript Prompt"), wxEmptyString, wxOK | wxCANCEL);
-    dialog.Centre();
-    if (dialog.ShowModal() == wxID_OK) {
-        result = dialog.GetValue();
-        return true;
+    if (m_webView) {
+        wxWebViewPromptEvent wkEvent(m_webView);
+        wkEvent.SetMessage(message);
+        wkEvent.SetResponse(defaultValue);
+        if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
+            result = wkEvent.GetResponse();
+            return true;
+        }
+        else {
+            wxTextEntryDialog dialog(NULL, message, wxT("JavaScript Prompt"), wxEmptyString, wxOK | wxCANCEL);
+            dialog.Centre();
+            if (dialog.ShowModal() == wxID_OK) {
+                result = dialog.GetValue();
+                return true;
+            }
+        }
     }
-    
     return false;
 }
 
index 6c443ed542336b2d52fb274115c1edcf1dbba928..9e81a6b61458d45ee0a193d62b5cafc952a9e972 100644 (file)
@@ -61,7 +61,7 @@ void EditorClientWx::setPage(Page* page)
 
 void EditorClientWx::pageDestroyed()
 {
-    notImplemented();
+    delete this;
 }
 
 bool EditorClientWx::shouldDeleteRange(Range*)
index 786fa622786a564ec3a35a309fa489a90f48f30f..aad26283ba496fd9205d4311048ef6312fda8c80 100644 (file)
@@ -28,6 +28,9 @@
 #include "config.h"
 #include "FrameLoaderClientWx.h"
 
+#include <JavaScriptCore/JavaScript.h>
+#include <JavaScriptCore/APICast.h>
+
 #include "DocumentLoader.h"
 #include "Frame.h"
 #include "FrameLoaderTypes.h"
 #include "RenderPart.h"
 #include "ResourceError.h"
 #include "ResourceResponse.h"
+#include "ScriptController.h"
 
 #include <stdio.h>
 
+#include "WebFrame.h"
 #include "WebView.h"
 #include "WebViewPrivate.h"
 
@@ -96,8 +101,7 @@ void FrameLoaderClientWx::detachFrameLoader()
 
 bool FrameLoaderClientWx::hasWebView() const
 {
-    notImplemented();
-    return true;
+    return m_webView != NULL;
 }
 
 bool FrameLoaderClientWx::hasBackForwardList() const
@@ -817,7 +821,15 @@ String FrameLoaderClientWx::overrideMediaType() const
 
 void FrameLoaderClientWx::windowObjectCleared()
 {
-    notImplemented();
+    if (m_webView) {
+        wxWebViewWindowObjectClearedEvent wkEvent(m_webView);
+        Frame* coreFrame = m_webView->GetMainFrame()->GetFrame();
+        JSGlobalContextRef context = toGlobalRef(coreFrame->script()->globalObject()->globalExec());
+        JSObjectRef windowObject = toRef(coreFrame->script()->globalObject());
+        wkEvent.SetJSContext(context);
+        wkEvent.SetWindowObject(windowObject);
+        m_webView->GetEventHandler()->ProcessEvent(wkEvent);
+    }
 }
 
 void FrameLoaderClientWx::documentElementAvailable()
index 94c760be93f832bca0f4b8e0b573d87aa416b1b1..c41795711f8660c02cb9aae4ac8be91aa388421c 100644 (file)
@@ -147,6 +147,42 @@ wxWebViewConsoleMessageEvent::wxWebViewConsoleMessageEvent(wxWindow* win)
         SetId(win->GetId());
 }
 
+IMPLEMENT_DYNAMIC_CLASS(wxWebViewAlertEvent, wxCommandEvent)
+
+DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_JS_ALERT)
+
+wxWebViewAlertEvent::wxWebViewAlertEvent(wxWindow* win)
+{
+    SetEventType(wxEVT_WEBVIEW_JS_ALERT);
+    SetEventObject(win);
+    if (win)
+        SetId(win->GetId());
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxWebViewConfirmEvent, wxCommandEvent)
+
+DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_JS_CONFIRM)
+
+wxWebViewConfirmEvent::wxWebViewConfirmEvent(wxWindow* win)
+{
+    SetEventType(wxEVT_WEBVIEW_JS_CONFIRM);
+    SetEventObject(win);
+    if (win)
+        SetId(win->GetId());
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxWebViewPromptEvent, wxCommandEvent)
+
+DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_JS_PROMPT)
+
+wxWebViewPromptEvent::wxWebViewPromptEvent(wxWindow* win)
+{
+    SetEventType(wxEVT_WEBVIEW_JS_PROMPT);
+    SetEventObject(win);
+    if (win)
+        SetId(win->GetId());
+}
+
 IMPLEMENT_DYNAMIC_CLASS(wxWebViewReceivedTitleEvent, wxCommandEvent)
 
 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_RECEIVED_TITLE)
@@ -159,6 +195,19 @@ wxWebViewReceivedTitleEvent::wxWebViewReceivedTitleEvent(wxWindow* win)
         SetId(win->GetId());
 }
 
+IMPLEMENT_DYNAMIC_CLASS(wxWebViewWindowObjectClearedEvent, wxCommandEvent)
+
+DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_WINDOW_OBJECT_CLEARED)
+
+wxWebViewWindowObjectClearedEvent::wxWebViewWindowObjectClearedEvent(wxWindow* win)
+{
+    SetEventType(wxEVT_WEBVIEW_WINDOW_OBJECT_CLEARED);
+    SetEventObject(win);
+    if (win)
+        SetId(win->GetId());
+}
+
+
 //---------------------------------------------------------
 // DOM Element info data type
 //---------------------------------------------------------
index b041b082e2fd58b0aa92517a85a24d12ee88e75a..a8a68e81088f1be1f987464c3cdddd1559af5bf2 100644 (file)
@@ -39,6 +39,9 @@ class WebViewPrivate;
 class WebViewFrameData;
 class wxWebFrame;
 
+typedef struct OpaqueJSContext* JSGlobalContextRef;
+typedef struct OpaqueJSValue* JSObjectRef;
+
 namespace WebCore {
     class ChromeClientWx;
     class FrameLoaderClientWx;
@@ -309,6 +312,57 @@ private:
     wxString m_sourceID;
 };
 
+class WXDLLIMPEXP_WEBKIT wxWebViewAlertEvent : public wxCommandEvent
+{
+#ifndef SWIG
+    DECLARE_DYNAMIC_CLASS( wxWebViewAlertEvent )
+#endif
+
+public:
+    wxString GetMessage() const { return m_message; }
+    void SetMessage(const wxString& message) { m_message = message; }
+
+    wxWebViewAlertEvent( wxWindow* win = (wxWindow*) NULL );
+    wxEvent *Clone(void) const { return new wxWebViewAlertEvent(*this); }
+
+private:
+    wxString m_message;
+};
+
+class WXDLLIMPEXP_WEBKIT wxWebViewConfirmEvent : public wxWebViewAlertEvent
+{
+#ifndef SWIG
+    DECLARE_DYNAMIC_CLASS( wxWebViewConfirmEvent )
+#endif
+
+public:   
+    int GetReturnCode() const { return m_returnCode; }
+    void SetReturnCode(int code) { m_returnCode = code; }
+
+    wxWebViewConfirmEvent( wxWindow* win = (wxWindow*) NULL );
+    wxEvent *Clone(void) const { return new wxWebViewConfirmEvent(*this); }
+
+private:
+    int m_returnCode;
+};
+
+class WXDLLIMPEXP_WEBKIT wxWebViewPromptEvent : public wxWebViewConfirmEvent
+{
+#ifndef SWIG
+    DECLARE_DYNAMIC_CLASS( wxWebViewPromptEvent )
+#endif
+
+public:   
+    wxString GetResponse() const { return m_response; }
+    void SetResponse(const wxString& response) { m_response = response; }
+
+    wxWebViewPromptEvent( wxWindow* win = (wxWindow*) NULL );
+    wxEvent *Clone(void) const { return new wxWebViewPromptEvent(*this); }
+
+private:
+    wxString m_response;
+};
+
 class WXDLLIMPEXP_WEBKIT wxWebViewReceivedTitleEvent : public wxCommandEvent
 {
 #ifndef SWIG
@@ -326,13 +380,58 @@ private:
     wxString m_title;
 };
 
+class WXDLLIMPEXP_WEBKIT wxWebViewWindowObjectClearedEvent : public wxCommandEvent
+{
+#ifndef SWIG
+    DECLARE_DYNAMIC_CLASS( wxWebViewWindowObjectClearedEvent )
+#endif
+
+public:
+    JSGlobalContextRef GetJSContext() const { return m_jsContext; }
+    void SetJSContext(JSGlobalContextRef context) { m_jsContext = context; }
+    
+    JSObjectRef GetWindowObject() const { return m_windowObject; }
+    void SetWindowObject(JSObjectRef object) { m_windowObject = object; }
+
+    wxWebViewWindowObjectClearedEvent( wxWindow* win = static_cast<wxWindow*>(NULL));
+    wxEvent *Clone(void) const { return new wxWebViewWindowObjectClearedEvent(*this); }
+
+private:
+    JSGlobalContextRef m_jsContext;
+    JSObjectRef m_windowObject;
+};
 
 typedef void (wxEvtHandler::*wxWebViewLoadEventFunction)(wxWebViewLoadEvent&);
 typedef void (wxEvtHandler::*wxWebViewBeforeLoadEventFunction)(wxWebViewBeforeLoadEvent&);
 typedef void (wxEvtHandler::*wxWebViewNewWindowEventFunction)(wxWebViewNewWindowEvent&);
 typedef void (wxEvtHandler::*wxWebViewRightClickEventFunction)(wxWebViewRightClickEvent&);
 typedef void (wxEvtHandler::*wxWebViewConsoleMessageEventFunction)(wxWebViewConsoleMessageEvent&);
+typedef void (wxEvtHandler::*wxWebViewAlertEventFunction)(wxWebViewAlertEvent&);
+typedef void (wxEvtHandler::*wxWebViewConfirmEventFunction)(wxWebViewConfirmEvent&);
+typedef void (wxEvtHandler::*wxWebViewPromptEventFunction)(wxWebViewPromptEvent&);
 typedef void (wxEvtHandler::*wxWebViewReceivedTitleEventFunction)(wxWebViewReceivedTitleEvent&);
+typedef void (wxEvtHandler::*wxWebViewWindowObjectClearedFunction)(wxWebViewWindowObjectClearedEvent&);
+
+#define wxWebViewLoadEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewLoadEventFunction, &func)
+#define wxWebViewBeforeLoadEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewBeforeLoadEventFunction, &func)
+#define wxWebViewNewWindowEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewNewWindowEventFunction, &func)
+#define wxWebViewRightClickEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewRightClickEventFunction, &func)
+#define wxWebViewConsoleMessageEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewConsoleMessageEventFunction, &func)
+#define wxWebViewAlertEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewAlertEventFunction, &func)
+#define wxWebViewConfirmEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewConfirmEventFunction, &func)
+#define wxWebViewPromptEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewPromptEventFunction, &func)
+#define wxWebViewReceivedTitleEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewReceivedTitleEventFunction, &func)
+#define wxWebViewWindowObjectClearedEventHandler(func) \
+    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWebViewWindowObjectClearedFunction, &func)
 
 #ifndef SWIG
 BEGIN_DECLARE_EVENT_TYPES()
@@ -341,7 +440,11 @@ BEGIN_DECLARE_EVENT_TYPES()
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_NEW_WINDOW, wxID_ANY)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_RIGHT_CLICK, wxID_ANY)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_CONSOLE_MESSAGE, wxID_ANY)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_JS_ALERT, wxID_ANY)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_JS_CONFIRM, wxID_ANY)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_JS_PROMPT, wxID_ANY)
     DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_RECEIVED_TITLE, wxID_ANY)
+    DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_WINDOW_OBJECT_CLEARED, wxID_ANY)
 END_DECLARE_EVENT_TYPES()
 #endif
 
@@ -385,6 +488,30 @@ END_DECLARE_EVENT_TYPES()
                             (wxWebViewConsoleMessageEventFunction) & func, \
                             static_cast<wxObject*>(NULL)),
 
+#define EVT_WEBVIEW_JS_ALERT(winid, func)                       \
+            DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_JS_ALERT, \
+                            winid, \
+                            wxID_ANY, \
+                            (wxObjectEventFunction)   \
+                            (wxWebViewAlertEventFunction) & func, \
+                            static_cast<wxObject*>(NULL)),
+                            
+#define EVT_WEBVIEW_JS_CONFIRM(winid, func)                       \
+            DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_JS_CONFIRM, \
+                            winid, \
+                            wxID_ANY, \
+                            (wxObjectEventFunction)   \
+                            (wxWebViewConfirmEventFunction) & func, \
+                            static_cast<wxObject*>(NULL)),
+                            
+#define EVT_WEBVIEW_JS_PROMPT(winid, func)                       \
+            DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_JS_PROMPT, \
+                            winid, \
+                            wxID_ANY, \
+                            (wxObjectEventFunction)   \
+                            (wxWebViewPromptEventFunction) & func, \
+                            static_cast<wxObject*>(NULL)),
+                            
 #define EVT_WEBVIEW_RECEIVED_TITLE(winid, func)                       \
             DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_RECEIVED_TITLE, \
                             winid, \
@@ -392,5 +519,13 @@ END_DECLARE_EVENT_TYPES()
                             (wxObjectEventFunction)   \
                             (wxWebViewReceivedTitleEventFunction) & func, \
                             static_cast<wxObject*>(NULL)),
+                            
+#define EVT_WEBVIEW_WINDOW_OBJECT_CLEARED(winid, func)                       \
+            DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_WINDOW_OBJECT_CLEARED, \
+                            winid, \
+                            wxID_ANY, \
+                            (wxObjectEventFunction)   \
+                            (wxWebViewWindowObjectClearedFunction) & func, \
+                            static_cast<wxObject*>(NULL)),
 
 #endif // ifndef WXWEBVIEW_H