Просмотр исходного кода

Merge pull request #732 from AtomicGameEngine/JME-ATOMIC-POPUPREQUESTS

Handle Popup Requests by sending event on UI thread
JoshEngebretson 9 лет назад
Родитель
Сommit
8c7e33853b
2 измененных файлов с 46 добавлено и 0 удалено
  1. 39 0
      Source/AtomicWebView/WebClient.cpp
  2. 7 0
      Source/AtomicWebView/WebViewEvents.h

+ 39 - 0
Source/AtomicWebView/WebClient.cpp

@@ -423,6 +423,45 @@ public:
 
     }
 
+    virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
+                               CefRefPtr<CefFrame> frame,
+                               const CefString& target_url,
+                               const CefString& target_frame_name,
+                               CefLifeSpanHandler::WindowOpenDisposition target_disposition,
+                               bool user_gesture,
+                               const CefPopupFeatures& popupFeatures,
+                               CefWindowInfo& windowInfo,
+                               CefRefPtr<CefClient>& client,
+                               CefBrowserSettings& settings,
+                               bool* no_javascript_access)  OVERRIDE
+    {
+        // Called on the IO thread, cancel and convert to popup request
+
+        assert(!CefCurrentlyOn(TID_UI));
+
+        // Execute on the UI thread.
+        CefPostTask(TID_UI,
+                    base::Bind(&WebClientPrivate::OnPopupRequest, this, target_url));
+
+        return true;
+    }
+
+    void OnPopupRequest(const CefString& target_url)
+    {
+        if (webClient_.Null())
+            return;
+
+        String url;
+        ConvertCEFString(target_url, url);
+
+        VariantMap eventData;
+        eventData[WebViewPopupRequest::P_CLIENT] = webClient_;
+        eventData[WebViewPopupRequest::P_URL] = url;
+
+        webClient_->SendEvent(E_WEBVIEWPOPUPREQUEST, eventData);
+
+    }
+
     void CloseBrowser(bool force_close)
     {
         if (!CefCurrentlyOn(TID_UI))

+ 7 - 0
Source/AtomicWebView/WebViewEvents.h

@@ -73,6 +73,13 @@ EVENT(E_WEBVIEWJSEVALRESULT, WebViewJSEvalResult)
     PARAM(P_VALUE, Value);   // String (sucess: eval's value, error: exception message)
 }
 
+/// WebView popup request
+EVENT(E_WEBVIEWPOPUPREQUEST, WebViewPopupRequest)
+{
+    PARAM(P_CLIENT, Client);   // WebClient*
+    PARAM(P_URL, Url);   // String
+}
+
 /// WebView load state change
 EVENT(E_WEBVIEWGLOBALPROPERTIESCHANGED, WebViewGlobalPropertiesChanged)
 {