callback);
virtual void Cancel();
+ static CefResponse::HeaderMap ToHeaderMap(NameValueCollection^ headers);
+
IMPLEMENT_REFCOUNTING(SchemeHandlerWrapper);
};
diff --git a/CefSharp.Example/RequestHandler.cs b/CefSharp.Example/RequestHandler.cs
index d4853f011..545ca7f07 100644
--- a/CefSharp.Example/RequestHandler.cs
+++ b/CefSharp.Example/RequestHandler.cs
@@ -1,6 +1,4 @@
using System;
-using System.IO;
-using System.Text;
namespace CefSharp.Example
{
@@ -21,17 +19,20 @@ namespace CefSharp.Example
// TODO: Add your own code here for handling scenarios where a plugin crashed, for one reason or another.
}
- bool IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse)
+ bool IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IResponse response)
+ {
+ return false;
+ }
+
+ public ResourceHandler GetResourceHandler(IWebBrowser browser, IRequest request)
{
- IRequest request = requestResponse.Request;
if (request.Url.StartsWith(ResourceUrl.ToString()))
{
- Stream resourceStream = new MemoryStream(Encoding.UTF8.GetBytes(
- "Success
This document is loaded from a System.IO.Stream
"));
- requestResponse.RespondWith(resourceStream, "text/html");
+ const string responseBody = "Success
This document is loaded from a System.IO.Stream
";
+ return ResourceHandler.FromString(responseBody);
}
- return false;
+ return null;
}
bool IRequestHandler.GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme, ref string username, ref string password)
diff --git a/CefSharp.WinForms.Example/BrowserForm.cs b/CefSharp.WinForms.Example/BrowserForm.cs
index 8b5c85dd9..697bcb2ee 100644
--- a/CefSharp.WinForms.Example/BrowserForm.cs
+++ b/CefSharp.WinForms.Example/BrowserForm.cs
@@ -40,7 +40,11 @@ namespace CefSharp.WinForms.Example
{
Dock = DockStyle.Fill
};
-
+
+ //This call isn't required for the sample to work.
+ //It's sole purpose is to demonstrate that #553 has been resolved.
+ browser.CreateControl();
+
tabPage.Controls.Add(browser);
if (insertIndex == null)
diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs
index e8c3951e3..c8349b801 100644
--- a/CefSharp.WinForms/ChromiumWebBrowser.cs
+++ b/CefSharp.WinForms/ChromiumWebBrowser.cs
@@ -53,18 +53,11 @@ namespace CefSharp.WinForms
Cef.AddDisposable(this);
Address = address;
- Paint += OnPaint;
-
- //Redraw on Resize so Cef is notified and updates accordingly
- SetStyle(ControlStyles.ResizeRedraw, true);
-
Dock = DockStyle.Fill;
}
protected override void Dispose(bool disposing)
{
- Paint -= OnPaint;
-
Cef.RemoveDisposable(this);
if (disposing)
@@ -82,6 +75,8 @@ namespace CefSharp.WinForms
{
IsBrowserInitialized = true;
+ ResizeBrowser();
+
var handler = IsBrowserInitializedChanged;
if (handler != null)
@@ -349,12 +344,18 @@ namespace CefSharp.WinForms
return taskStringVisitor.Task;
}
- private void OnPaint(object sender, PaintEventArgs e)
+ protected override void OnSizeChanged(EventArgs e)
{
- // Size is 0x0 when we are on a modeless Form which is minimized.
- if (!Size.IsEmpty && managedCefBrowserAdapter != null)
+ base.OnSizeChanged(e);
+
+ ResizeBrowser();
+ }
+
+ private void ResizeBrowser()
+ {
+ if (IsBrowserInitialized && managedCefBrowserAdapter != null)
{
- managedCefBrowserAdapter.OnPaint(Handle);
+ managedCefBrowserAdapter.Resize(Width, Height);
}
}
diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj
index 5bef8c830..b439c3d43 100644
--- a/CefSharp/CefSharp.csproj
+++ b/CefSharp/CefSharp.csproj
@@ -109,6 +109,9 @@
+
+
+
@@ -131,7 +134,7 @@
-
+
diff --git a/CefSharp/IRequestHandler.cs b/CefSharp/IRequestHandler.cs
index df10479fe..672a8bc34 100644
--- a/CefSharp/IRequestHandler.cs
+++ b/CefSharp/IRequestHandler.cs
@@ -29,13 +29,19 @@ namespace CefSharp
/// Called before a resource request is loaded.
///
/// the browser object
- /// the request response object - can be modified in this callback
+ /// the request object - can be modified in this callback.
+ /// the request object - can be modified in this callback.
/// To cancel loading of the resource return true or false o allow the resource to load normally.
- bool OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse);
-
- // TODO: Investigate how we can support in CEF3.
- //void OnResourceResponse(IWebBrowser browser, string url, int status, string statusText, string mimeType, WebHeaderCollection headers);
+ bool OnBeforeResourceLoad(IWebBrowser browser, IRequest request, IResponse response);
+ ///
+ /// Called before a resource is loaded. To specify a handler for the resource return a ResourceHandler object
+ ///
+ /// the browser object
+ /// the request object - cannot be modified in this callback
+ /// To allow the resource to load normally return NULL otherwise return an instance of ResourceHandler with a valid stream
+ ResourceHandler GetResourceHandler(IWebBrowser browser, IRequest request);
+
///
/// Called when the browser needs credentials from the user.
///
diff --git a/CefSharp/IRequestResponse.cs b/CefSharp/IResponse.cs
similarity index 58%
rename from CefSharp/IRequestResponse.cs
rename to CefSharp/IResponse.cs
index d50bf3958..d95b7ede5 100644
--- a/CefSharp/IRequestResponse.cs
+++ b/CefSharp/IResponse.cs
@@ -2,24 +2,14 @@
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
-using System.IO;
-
namespace CefSharp
{
- public interface IRequestResponse
+ public interface IResponse
{
- // TODO: Improve these comments.
-
/// cancel the request, return nothing
void Cancel();
- /// the current request
- IRequest Request { get; }
-
/// respond with redirection to the provided URL
void Redirect(string url);
-
- /// respond with data from Stream
- void RespondWith(Stream stream, string mimeType);
}
}
diff --git a/CefSharp/ResourceHandler.cs b/CefSharp/ResourceHandler.cs
new file mode 100644
index 000000000..f5af6c55c
--- /dev/null
+++ b/CefSharp/ResourceHandler.cs
@@ -0,0 +1,36 @@
+// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using System.Collections.Specialized;
+using System.IO;
+using System.Text;
+
+namespace CefSharp
+{
+ public class ResourceHandler
+ {
+ public string MimeType { get; set; }
+ public Stream Stream { get; set; }
+ public int StatusCode { get; set; }
+ public string StatusText { get; set; }
+ public NameValueCollection Headers { get; set; }
+
+ public ResourceHandler()
+ {
+ StatusCode = 200;
+ StatusText = "OK";
+ MimeType = "text/html";
+ }
+
+ public static ResourceHandler FromFileName(string fileName)
+ {
+ return new ResourceHandler { Stream = File.OpenRead(fileName) };
+ }
+
+ public static ResourceHandler FromString(string text)
+ {
+ return new ResourceHandler { Stream = new MemoryStream(Encoding.UTF8.GetBytes(text)) };
+ }
+ }
+}
diff --git a/CefSharp/Response.cs b/CefSharp/Response.cs
new file mode 100644
index 000000000..a5eda1fca
--- /dev/null
+++ b/CefSharp/Response.cs
@@ -0,0 +1,30 @@
+// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using System;
+
+namespace CefSharp
+{
+ public class Response : IResponse
+ {
+ public String RedirectUrl { get; private set; }
+ public ResponseAction Action { get; private set; }
+
+ public Response()
+ {
+ Action = ResponseAction.Continue;
+ }
+
+ public void Cancel()
+ {
+ Action = ResponseAction.Cancel;
+ }
+
+ public void Redirect(String url)
+ {
+ RedirectUrl = url;
+ Action = ResponseAction.Redirect;
+ }
+ }
+}
diff --git a/CefSharp/ResponseAction.cs b/CefSharp/ResponseAction.cs
new file mode 100644
index 000000000..9571a014e
--- /dev/null
+++ b/CefSharp/ResponseAction.cs
@@ -0,0 +1,13 @@
+// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp
+{
+ public enum ResponseAction
+ {
+ Continue,
+ Cancel,
+ Redirect
+ }
+}