From 13349a93cfbcfd45893abdbc9bfb4eff3dabccc1 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 5 Nov 2014 13:54:50 +1000 Subject: [PATCH] Revert "Split RequestResponse into Request and Response objects" This reverts commit 66d953d2b3efc25e44c7d98ec8809022cef78d67. --- CefSharp.Core/CefSharp.Core.vcxproj | 4 +-- CefSharp.Core/CefSharp.Core.vcxproj.filters | 12 ++++----- CefSharp.Core/Internals/ClientAdapter.cpp | 14 +++++------ .../{Response.cpp => RequestResponse.cpp} | 10 ++++---- .../{Response.h => RequestResponse.h} | 8 ++++-- CefSharp.Example/RequestHandler.cs | 5 ++-- CefSharp/CefSharp.csproj | 2 +- CefSharp/IRequestHandler.cs | 5 ++-- CefSharp/IRequestResponse.cs | 25 +++++++++++++++++++ CefSharp/IResponse.cs | 20 --------------- 10 files changed, 57 insertions(+), 48 deletions(-) rename CefSharp.Core/Internals/{Response.cpp => RequestResponse.cpp} (75%) rename CefSharp.Core/Internals/{Response.h => RequestResponse.h} (84%) create mode 100644 CefSharp/IRequestResponse.cs delete mode 100644 CefSharp/IResponse.cs diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index 6f9d46947..f8a74eca6 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -224,7 +224,7 @@ - + @@ -253,7 +253,7 @@ - + diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index 235bda890..ef7967b7f 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -41,6 +41,9 @@ Source Files + + Source Files + Source Files @@ -53,9 +56,6 @@ Source Files - - Source Files - @@ -115,6 +115,9 @@ Header Files + + Header Files + Header Files @@ -127,9 +130,6 @@ Header Files - - Header Files - diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index 6fe00694f..5393b104a 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -8,7 +8,7 @@ #include "Internals/CefWebPluginInfoWrapper.h" #include "Internals/CefContextMenuParamsWrapper.h" #include "Internals/JavascriptBinding/BindingHandler.h" -#include "Internals/Response.h" +#include "Internals/RequestResponse.h" #include "ClientAdapter.h" #include "Cef.h" #include "DownloadAdapter.h" @@ -258,16 +258,16 @@ namespace CefSharp return false; } - auto requestWrapper = gcnew CefRequestWrapper(request); - auto response = gcnew Response(); + CefRequestWrapper^ wrapper = gcnew CefRequestWrapper(request); + RequestResponse^ requestResponse = gcnew RequestResponse(wrapper); - bool ret = handler->OnBeforeResourceLoad(_browserControl, requestWrapper, response); + bool ret = handler->OnBeforeResourceLoad(_browserControl, requestResponse); - if (response->Action == ResponseAction::Redirect) + if (requestResponse->Action == ResponseAction::Redirect) { - request->SetURL(StringUtils::ToNative(response->RedirectUrl)); + request->SetURL(StringUtils::ToNative(requestResponse->RedirectUrl)); } - else if (response->Action == ResponseAction::Respond) + else if (requestResponse->Action == ResponseAction::Respond) { throw gcnew NotImplementedException("Respond is not yet supported."); diff --git a/CefSharp.Core/Internals/Response.cpp b/CefSharp.Core/Internals/RequestResponse.cpp similarity index 75% rename from CefSharp.Core/Internals/Response.cpp rename to CefSharp.Core/Internals/RequestResponse.cpp index 1223a987a..9e1a8b97c 100644 --- a/CefSharp.Core/Internals/Response.cpp +++ b/CefSharp.Core/Internals/RequestResponse.cpp @@ -3,29 +3,29 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "Stdafx.h" -#include "Response.h" +#include "RequestResponse.h" namespace CefSharp { namespace Internals { - void Response::Cancel() + void RequestResponse::Cancel() { _action = ResponseAction::Cancel; } - void Response::Redirect(String^ url) + void RequestResponse::Redirect(String^ url) { _redirectUrl = url; _action = ResponseAction::Redirect; } - void Response::RespondWith(Stream^ stream, String^ mimeType) + void RequestResponse::RespondWith(Stream^ stream, String^ mimeType) { RespondWith(stream, mimeType, "OK", 200, nullptr); } - void Response::RespondWith(Stream^ stream, String^ mimeType, String^ statusText, int statusCode, NameValueCollection^ responseHeaders) + void RequestResponse::RespondWith(Stream^ stream, String^ mimeType, String^ statusText, int statusCode, NameValueCollection^ responseHeaders) { if (String::IsNullOrEmpty(mimeType)) { diff --git a/CefSharp.Core/Internals/Response.h b/CefSharp.Core/Internals/RequestResponse.h similarity index 84% rename from CefSharp.Core/Internals/Response.h rename to CefSharp.Core/Internals/RequestResponse.h index f06bfff5d..2486a646f 100644 --- a/CefSharp.Core/Internals/Response.h +++ b/CefSharp.Core/Internals/RequestResponse.h @@ -22,8 +22,9 @@ namespace CefSharp Respond }; - private ref class Response : IResponse + private ref class RequestResponse : IRequestResponse { + IRequest^ _request; Stream^ _responseStream; String^ _mimeType; String^ _redirectUrl; @@ -33,7 +34,9 @@ namespace CefSharp NameValueCollection^ _responseHeaders; internal: - Response() : _action(ResponseAction::Continue) + RequestResponse(IRequest^ request) : + _action(ResponseAction::Continue), + _request(request) { } @@ -47,6 +50,7 @@ namespace CefSharp public: virtual void Cancel(); + virtual property IRequest^ Request { IRequest^ get() { return _request; } } virtual void Redirect(String^ url); virtual void RespondWith(Stream^ stream, String^ mimeType); virtual void RespondWith(Stream^ stream, String^ mimeType, String^ statusText, int statusCode, NameValueCollection^ responseHeaders); diff --git a/CefSharp.Example/RequestHandler.cs b/CefSharp.Example/RequestHandler.cs index dc29bfb32..d4853f011 100644 --- a/CefSharp.Example/RequestHandler.cs +++ b/CefSharp.Example/RequestHandler.cs @@ -21,13 +21,14 @@ 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, IRequest request, IResponse response) + bool IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse) { + 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

")); - response.RespondWith(resourceStream, "text/html"); + requestResponse.RespondWith(resourceStream, "text/html"); } return false; diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 295db772a..cead85d64 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -89,7 +89,6 @@
- @@ -131,6 +130,7 @@ + diff --git a/CefSharp/IRequestHandler.cs b/CefSharp/IRequestHandler.cs index 1681737df..df10479fe 100644 --- a/CefSharp/IRequestHandler.cs +++ b/CefSharp/IRequestHandler.cs @@ -29,10 +29,9 @@ namespace CefSharp /// Called before a resource request is loaded. /// /// the browser object - /// the request - /// the response - can be modified in this callback + /// the request response 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, IRequest request, IResponse response); + 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); diff --git a/CefSharp/IRequestResponse.cs b/CefSharp/IRequestResponse.cs new file mode 100644 index 000000000..d50bf3958 --- /dev/null +++ b/CefSharp/IRequestResponse.cs @@ -0,0 +1,25 @@ +// 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.IO; + +namespace CefSharp +{ + public interface IRequestResponse + { + // 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/IResponse.cs b/CefSharp/IResponse.cs deleted file mode 100644 index 6fe18230b..000000000 --- a/CefSharp/IResponse.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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.IO; - -namespace CefSharp -{ - public interface IResponse - { - /// cancel the request, return nothing - void Cancel(); - - /// respond with redirection to the provided URL - void Redirect(string url); - - /// respond with data from Stream - void RespondWith(Stream stream, string mimeType); - } -}