Permalink
Browse files

Add bool to force links to be opened in the default OS browser

  • Loading branch information...
1 parent d027d6b commit 795859079cb6da27373afd545eeb5aa59bd428d1 @paulcbetts committed Feb 2, 2012
@@ -38,6 +38,8 @@ namespace CefSharp
RtzCountdownEvent^ _loadCompleted;
ManualResetEvent^ _browserInitialized;
+ bool _shouldOpenLinksInExternalBrowser;
+
protected:
virtual void OnHandleCreated(EventArgs^ e) override;
virtual void OnSizeChanged(EventArgs^ e) override;
@@ -138,6 +140,12 @@ namespace CefSharp
void set(IAfterResponse^ handler) { _afterResponseHandler = handler; }
}
+ property bool ShouldOpenLinksInExternalBrowser
+ {
+ virtual bool get() { return _shouldOpenLinksInExternalBrowser; }
+ virtual void set(bool value) { _shouldOpenLinksInExternalBrowser = value; }
+ }
+
property bool CanGoForward
{
bool get() { return _canGoForward; }
@@ -27,6 +27,7 @@ namespace CefSharp
bool _canGoForward;
bool _canGoBack;
bool _isLoading;
+ bool _shouldOpenLinksInExternalBrowser;
String^ _address;
String^ _title;
@@ -170,6 +171,12 @@ namespace CefSharp
}
}
+ property bool ShouldOpenLinksInExternalBrowser
+ {
+ virtual bool get() { return _shouldOpenLinksInExternalBrowser; }
+ virtual void set(bool value) { _shouldOpenLinksInExternalBrowser = value; }
+ }
+
event EventHandler^ LoadFinished;
void WaitForInitialized();
@@ -18,6 +18,23 @@ namespace CefSharp
handler->HandleBeforePopup(toClr(url), windowInfo.m_x, windowInfo.m_y, windowInfo.m_nWidth, windowInfo.m_nHeight);
}
+ bool ClientAdapter::OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, NavType navType, bool isRedirect)
+ {
+ if (!_browserControl->ShouldOpenLinksInExternalBrowser)
+ {
+ return false;
+ }
+
+ String^ s;
+ s = toClr(request->GetURL());
+ if (s->ToLowerInvariant()->StartsWith("http"))
+ {
+ System::Diagnostics::Process::Start(s);
+ }
+
+ return true;
+ }
+
void ClientAdapter::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
if(!browser->IsPopup())
@@ -64,6 +64,7 @@ namespace CefSharp
// CefRequestHandler
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefRefPtr<CefResponse> response, int loadFlags) OVERRIDE;
virtual void OnResourceResponse(CefRefPtr<CefBrowser> browser, const CefString& url, CefRefPtr<CefResponse> response, CefRefPtr<CefContentFilter>& filter) OVERRIDE;
+ virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, NavType navType, bool isRedirect) OVERRIDE;
// CefDisplayHandler
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& url) OVERRIDE;
@@ -18,6 +18,7 @@ namespace CefSharp
property IBeforeResourceLoad^ BeforeResourceLoadHandler;
property IBeforeMenu^ BeforeMenuHandler;
property IAfterResponse^ AfterResponseHandler;
+ property bool ShouldOpenLinksInExternalBrowser;
void OnInitialized();

0 comments on commit 7958590

Please sign in to comment.