mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 03:32:37 +00:00
Revert "Split RequestResponse into Request and Response objects"
This reverts commit 66d953d2b3.
This commit is contained in:
@@ -224,7 +224,7 @@
|
||||
<ClCompile Include="Internals\CookieVisitor.cpp" />
|
||||
<ClCompile Include="Internals\CefRequestWrapper.cpp" />
|
||||
<ClCompile Include="Internals\DownloadAdapter.cpp" />
|
||||
<ClCompile Include="Internals\Response.cpp" />
|
||||
<ClCompile Include="Internals\RequestResponse.cpp" />
|
||||
<ClCompile Include="Internals\StringVisitor.cpp" />
|
||||
<ClCompile Include="SchemeHandlerResponse.cpp" />
|
||||
<ClCompile Include="SchemeHandlerWrapper.cpp" />
|
||||
@@ -253,7 +253,7 @@
|
||||
<ClInclude Include="Internals\StringVisitor.h" />
|
||||
<ClInclude Include="MouseButtonType.h" />
|
||||
<ClInclude Include="ManagedCefBrowserAdapter.h" />
|
||||
<ClInclude Include="Internals\Response.h" />
|
||||
<ClInclude Include="Internals\RequestResponse.h" />
|
||||
<ClInclude Include="CefSettings.h" />
|
||||
<ClInclude Include="SchemeHandlerResponse.h" />
|
||||
<ClInclude Include="SchemeHandlerWrapper.h" />
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
<ClCompile Include="Internals\CefWebPluginInfoWrapper.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Internals\RequestResponse.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Internals\StringVisitor.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -53,9 +56,6 @@
|
||||
<ClCompile Include="Internals\CefContextMenuParamsWrapper.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Internals\Response.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="vcclr_local.h">
|
||||
@@ -115,6 +115,9 @@
|
||||
<ClInclude Include="Internals\CefWebPluginInfoWrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Internals\RequestResponse.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Internals\StringVisitor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -127,9 +130,6 @@
|
||||
<ClInclude Include="Internals\CefContextMenuParamsWrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Internals\Response.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -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.");
|
||||
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
@@ -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);
|
||||
@@ -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(
|
||||
"<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>"));
|
||||
response.RespondWith(resourceStream, "text/html");
|
||||
requestResponse.RespondWith(resourceStream, "text/html");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -89,7 +89,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CefFileDialogMode.cs" />
|
||||
<Compile Include="IResponse.cs" />
|
||||
<Compile Include="IsBrowserInitializedChangedEventArgs.cs" />
|
||||
<Compile Include="CefTerminationStatus.cs" />
|
||||
<Compile Include="IDialogHandler.cs" />
|
||||
@@ -131,6 +130,7 @@
|
||||
<Compile Include="IWebPluginInfo.cs" />
|
||||
<Compile Include="IRequest.cs" />
|
||||
<Compile Include="IRequestHandler.cs" />
|
||||
<Compile Include="IRequestResponse.cs" />
|
||||
<Compile Include="ISchemeHandler.cs" />
|
||||
<Compile Include="ISchemeHandlerFactory.cs" />
|
||||
<Compile Include="ISchemeHandlerResponse.cs" />
|
||||
|
||||
@@ -29,10 +29,9 @@ namespace CefSharp
|
||||
/// Called before a resource request is loaded.
|
||||
/// </summary>
|
||||
/// <param name="browser">the browser object</param>
|
||||
/// <param name="request">the request</param>
|
||||
/// <param name="response">the response - can be modified in this callback</param>
|
||||
/// <param name="requestResponse">the request response object - can be modified in this callback</param>
|
||||
/// <returns>To cancel loading of the resource return true or false o allow the resource to load normally.</returns>
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user