Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientAdapter is now CefJSDialogHandler #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CefSharp.WinForms/WebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ namespace WinForms
void set(IKeyboardHandler^ handler) { _browserCore->KeyboardHandler = handler; }
}

virtual property IJsDialogHandler^ JsDialogHandler
{
IJsDialogHandler^ get() { return _browserCore->JsDialogHandler; }
void set(IJsDialogHandler^ handler) { _browserCore->JsDialogHandler = handler; }
}

virtual void OnInitialized();

virtual void Load(String^ url);
Expand Down
8 changes: 7 additions & 1 deletion CefSharp.Wpf/WebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ namespace Wpf
void set(IKeyboardHandler^ handler) { _browserCore->KeyboardHandler = handler; }
}

virtual property IJsDialogHandler^ JsDialogHandler
{
IJsDialogHandler^ get() { return _browserCore->JsDialogHandler; }
void set(IJsDialogHandler^ handler) { _browserCore->JsDialogHandler = handler; }
}

virtual void OnInitialized();

virtual void Load(String^ url);
Expand Down Expand Up @@ -271,4 +277,4 @@ namespace Wpf
virtual void SetPopupSizeAndPosition(const CefRect& rect);

};
}}
}}
8 changes: 8 additions & 0 deletions CefSharp/BrowserCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace CefSharp
interface class IRequestHandler;
interface class IMenuHandler;
interface class IKeyboardHandler;
interface class IJsDialogHandler;

public ref class BrowserCore : INotifyPropertyChanged
{
Expand All @@ -37,6 +38,7 @@ namespace CefSharp
IRequestHandler^ _requestHandler;
IMenuHandler^ _menuHandler;
IKeyboardHandler^ _keyboardHandler;
IJsDialogHandler^ _jsDialogHandler;

IDictionary<String^, Object^>^ _boundObjects;

Expand Down Expand Up @@ -172,6 +174,12 @@ namespace CefSharp
void set(IKeyboardHandler^ handler) { _keyboardHandler = handler; }
}

virtual property IJsDialogHandler^ JsDialogHandler
{
IJsDialogHandler^ get() { return _jsDialogHandler; }
void set(IJsDialogHandler^ handler) { _jsDialogHandler = handler; }
}

void CheckBrowserInitialization();

void RegisterJsObject(String^ name, Object^ objectToBind);
Expand Down
4 changes: 4 additions & 0 deletions CefSharp/CefSharp.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@
RelativePath=".\IDownloadHandler.h"
>
</File>
<File
RelativePath=".\IJsDialogHandler.h"
>
</File>
<File
RelativePath=".\IKeyboardHandler.h"
>
Expand Down
47 changes: 47 additions & 0 deletions CefSharp/ClientAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "IRequestHandler.h"
#include "IMenuHandler.h"
#include "IKeyboardHandler.h"
#include "IJsDialogHandler.h"

using namespace std;

Expand Down Expand Up @@ -320,4 +321,50 @@ namespace CefSharp
{
_browserControl->OnTakeFocus(next);
}

bool ClientAdapter::OnJSAlert(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message)
{
IJsDialogHandler^ handler = _browserControl->JsDialogHandler;
if (handler == nullptr)
{
return false;
}

bool handled = handler->OnJSAlert(_browserControl, toClr(frame->GetURL()), toClr(message));

return handled;
}

bool ClientAdapter::OnJSConfirm(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message, bool& retval)
{
IJsDialogHandler^ handler = _browserControl->JsDialogHandler;
if (handler == nullptr)
{
return false;
}

bool handled = handler->OnJSConfirm(_browserControl, toClr(frame->GetURL()), toClr(message), retval);

return handled;
}

bool ClientAdapter::OnJSPrompt(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message, const CefString& defaultValue, bool& retval, CefString& result)
{
IJsDialogHandler^ handler = _browserControl->JsDialogHandler;
if (handler == nullptr)
{
return false;
}

String^ resultString = nullptr;

bool handled = handler->OnJSPrompt(_browserControl, toClr(frame->GetURL()), toClr(message), toClr(defaultValue), retval, resultString);

if(resultString != nullptr)
{
result = toNative(resultString);
}

return handled;
}
}
9 changes: 8 additions & 1 deletion CefSharp/ClientAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace CefSharp
public CefV8ContextHandler,
public CefMenuHandler,
public CefFocusHandler,
public CefKeyboardHandler
public CefKeyboardHandler,
public CefJSDialogHandler
{
private:
gcroot<IWebBrowser^> _browserControl;
Expand All @@ -42,6 +43,7 @@ namespace CefSharp
virtual CefRefPtr<CefMenuHandler> GetMenuHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE { return this; }

// CefLifeSpanHandler
virtual DECL bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, const CefString& url, CefRefPtr<CefClient>& client, CefBrowserSettings& settings) OVERRIDE;
Expand Down Expand Up @@ -80,6 +82,11 @@ namespace CefSharp
// CefKeyboardHandler
virtual DECL bool OnKeyEvent(CefRefPtr<CefBrowser> browser, KeyEventType type, int code, int modifiers, bool isSystemKey, bool isAfterJavaScript) OVERRIDE;

// CefJSDialogHandler
virtual DECL bool OnJSAlert(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message) OVERRIDE;
virtual DECL bool OnJSConfirm(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message, bool& retval) OVERRIDE;
virtual DECL bool OnJSPrompt(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message, const CefString& defaultValue, bool& retval, CefString& result) OVERRIDE;

IMPLEMENT_LOCKING(ClientAdapter);
IMPLEMENT_REFCOUNTING(ClientAdapter);
};
Expand Down
14 changes: 14 additions & 0 deletions CefSharp/IJsDialogHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

using namespace System;

namespace CefSharp
{
public interface class IJsDialogHandler
{
public:
bool OnJSAlert(IWebBrowser^ browser, String^ url, String^ message);
bool OnJSConfirm(IWebBrowser^ browser, String^ url, String^ message, bool& retval);
bool OnJSPrompt(IWebBrowser^ browser, String^ url, String^ message, String^ defaultValue, bool& retval, String^% result);
};
}
2 changes: 2 additions & 0 deletions CefSharp/IWebBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace CefSharp
interface class IRequestHandler;
interface class IMenuHandler;
interface class IKeyboardHandler;
interface class IJsDialogHandler;

public interface class IWebBrowser : IDisposable, INotifyPropertyChanged
{
Expand All @@ -38,6 +39,7 @@ namespace CefSharp
property IRequestHandler^ RequestHandler;
property IMenuHandler^ MenuHandler;
property IKeyboardHandler^ KeyboardHandler;
property IJsDialogHandler^ JsDialogHandler;

void OnInitialized();

Expand Down