mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add OnResourceReponse and CefContentFilter for viewing and filtering response content (issue #241).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@243 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
69
libcef_dll/cpptoc/content_filter_cpptoc.cc
Normal file
69
libcef_dll/cpptoc/content_filter_cpptoc.cc
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// A portion of this file was generated by the CEF translator tool. When
|
||||
// making changes by hand only do so within the body of existing function
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/content_filter_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/stream_reader_ctocpp.h"
|
||||
|
||||
|
||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
||||
void CEF_CALLBACK content_filter_process_data(
|
||||
struct _cef_content_filter_t* self, const void* data, int data_size,
|
||||
cef_stream_reader_t** substitute_data)
|
||||
{
|
||||
DCHECK(self);
|
||||
DCHECK(data);
|
||||
DCHECK(substitute_data);
|
||||
if (!self || !data || !substitute_data)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefStreamReader> substituteDataPtr;
|
||||
|
||||
CefContentFilterCppToC::Get(self)->ProcessData(data, data_size,
|
||||
substituteDataPtr);
|
||||
|
||||
if(substituteDataPtr.get())
|
||||
*substitute_data = CefStreamReaderCToCpp::Unwrap(substituteDataPtr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK content_filter_drain(struct _cef_content_filter_t* self,
|
||||
cef_stream_reader_t** remainder)
|
||||
{
|
||||
DCHECK(self);
|
||||
DCHECK(remainder);
|
||||
if (!self || !remainder)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefStreamReader> remainderPtr;
|
||||
|
||||
CefContentFilterCppToC::Get(self)->Drain(remainderPtr);
|
||||
|
||||
if(remainderPtr.get())
|
||||
*remainder = CefStreamReaderCToCpp::Unwrap(remainderPtr);
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefContentFilterCppToC::CefContentFilterCppToC(CefContentFilter* cls)
|
||||
: CefCppToC<CefContentFilterCppToC, CefContentFilter, cef_content_filter_t>(
|
||||
cls)
|
||||
{
|
||||
struct_.struct_.process_data = content_filter_process_data;
|
||||
struct_.struct_.drain = content_filter_drain;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
template<> long CefCppToC<CefContentFilterCppToC, CefContentFilter,
|
||||
cef_content_filter_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
35
libcef_dll/cpptoc/content_filter_cpptoc.h
Normal file
35
libcef_dll/cpptoc/content_filter_cpptoc.h
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// This file was generated by the CEF translator tool and should not edited
|
||||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
#ifndef _CONTENTFILTER_CPPTOC_H
|
||||
#define _CONTENTFILTER_CPPTOC_H
|
||||
|
||||
#ifndef USING_CEF_SHARED
|
||||
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
||||
#else // USING_CEF_SHARED
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "include/cef_capi.h"
|
||||
#include "libcef_dll/cpptoc/cpptoc.h"
|
||||
|
||||
// Wrap a C++ class with a C structure.
|
||||
// This class may be instantiated and accessed wrapper-side only.
|
||||
class CefContentFilterCppToC
|
||||
: public CefCppToC<CefContentFilterCppToC, CefContentFilter,
|
||||
cef_content_filter_t>
|
||||
{
|
||||
public:
|
||||
CefContentFilterCppToC(CefContentFilter* cls);
|
||||
virtual ~CefContentFilterCppToC() {}
|
||||
};
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
#endif // _CONTENTFILTER_CPPTOC_H
|
||||
|
@@ -10,6 +10,7 @@
|
||||
// for more information.
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/content_filter_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/download_handler_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/request_handler_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/browser_ctocpp.h"
|
||||
@@ -67,6 +68,29 @@ int CEF_CALLBACK request_handler_on_before_resource_load(
|
||||
return rv;
|
||||
}
|
||||
|
||||
void CEF_CALLBACK request_handler_on_resource_reponse(
|
||||
struct _cef_request_handler_t* self, cef_browser_t* browser,
|
||||
const cef_string_t* url, struct _cef_response_t* response,
|
||||
struct _cef_content_filter_t** filter)
|
||||
{
|
||||
DCHECK(self);
|
||||
DCHECK(browser);
|
||||
DCHECK(url);
|
||||
DCHECK(response);
|
||||
DCHECK(filter);
|
||||
if (!self || !browser || !url || !response || !filter)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefContentFilter> filterPtr;
|
||||
|
||||
CefRequestHandlerCppToC::Get(self)->OnResourceReponse(
|
||||
CefBrowserCToCpp::Wrap(browser), url, CefResponseCToCpp::Wrap(response),
|
||||
filterPtr);
|
||||
|
||||
if(filterPtr.get())
|
||||
*filter = CefContentFilterCppToC::Wrap(filterPtr);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK request_handler_on_protocol_execution(
|
||||
struct _cef_request_handler_t* self, cef_browser_t* browser,
|
||||
const cef_string_t* url, int* allowOSExecution)
|
||||
@@ -145,6 +169,7 @@ CefRequestHandlerCppToC::CefRequestHandlerCppToC(CefRequestHandler* cls)
|
||||
struct_.struct_.on_before_browse = request_handler_on_before_browse;
|
||||
struct_.struct_.on_before_resource_load =
|
||||
request_handler_on_before_resource_load;
|
||||
struct_.struct_.on_resource_reponse = request_handler_on_resource_reponse;
|
||||
struct_.struct_.on_protocol_execution = request_handler_on_protocol_execution;
|
||||
struct_.struct_.get_download_handler = request_handler_get_download_handler;
|
||||
struct_.struct_.get_auth_credentials = request_handler_get_auth_credentials;
|
||||
|
49
libcef_dll/ctocpp/content_filter_ctocpp.cc
Normal file
49
libcef_dll/ctocpp/content_filter_ctocpp.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// A portion of this file was generated by the CEF translator tool. When
|
||||
// making changes by hand only do so within the body of existing static and
|
||||
// virtual method implementations. See the translator.README.txt file in the
|
||||
// tools directory for more information.
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/stream_reader_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/content_filter_ctocpp.h"
|
||||
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
void CefContentFilterCToCpp::ProcessData(const void* data, int data_size,
|
||||
CefRefPtr<CefStreamReader>& substitute_data)
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, process_data))
|
||||
return;
|
||||
|
||||
cef_stream_reader_t* streamRet = NULL;
|
||||
struct_->process_data(struct_, data, data_size, &streamRet);
|
||||
|
||||
if(streamRet)
|
||||
substitute_data = CefStreamReaderCppToC::Unwrap(streamRet);
|
||||
}
|
||||
|
||||
void CefContentFilterCToCpp::Drain(CefRefPtr<CefStreamReader>& remainder)
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, drain))
|
||||
return;
|
||||
|
||||
cef_stream_reader_t* streamRet = NULL;
|
||||
struct_->drain(struct_, &streamRet);
|
||||
|
||||
if(streamRet)
|
||||
remainder = CefStreamReaderCppToC::Unwrap(streamRet);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
template<> long CefCToCpp<CefContentFilterCToCpp, CefContentFilter,
|
||||
cef_content_filter_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
43
libcef_dll/ctocpp/content_filter_ctocpp.h
Normal file
43
libcef_dll/ctocpp/content_filter_ctocpp.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
// This file was generated by the CEF translator tool and should not edited
|
||||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
|
||||
#ifndef _CONTENTFILTER_CTOCPP_H
|
||||
#define _CONTENTFILTER_CTOCPP_H
|
||||
|
||||
#ifndef BUILDING_CEF_SHARED
|
||||
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
|
||||
#else // BUILDING_CEF_SHARED
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "include/cef_capi.h"
|
||||
#include "libcef_dll/ctocpp/ctocpp.h"
|
||||
|
||||
// Wrap a C structure with a C++ class.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefContentFilterCToCpp
|
||||
: public CefCToCpp<CefContentFilterCToCpp, CefContentFilter,
|
||||
cef_content_filter_t>
|
||||
{
|
||||
public:
|
||||
CefContentFilterCToCpp(cef_content_filter_t* str)
|
||||
: CefCToCpp<CefContentFilterCToCpp, CefContentFilter,
|
||||
cef_content_filter_t>(str) {}
|
||||
virtual ~CefContentFilterCToCpp() {}
|
||||
|
||||
// CefContentFilter methods
|
||||
virtual void ProcessData(const void* data, int data_size,
|
||||
CefRefPtr<CefStreamReader>& substitute_data) OVERRIDE;
|
||||
virtual void Drain(CefRefPtr<CefStreamReader>& remainder) OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // BUILDING_CEF_SHARED
|
||||
#endif // _CONTENTFILTER_CTOCPP_H
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/response_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/stream_reader_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/content_filter_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/download_handler_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/request_handler_ctocpp.h"
|
||||
|
||||
@@ -54,6 +55,23 @@ bool CefRequestHandlerCToCpp::OnBeforeResourceLoad(
|
||||
return (rv ? true : false);
|
||||
}
|
||||
|
||||
void CefRequestHandlerCToCpp::OnResourceReponse(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url, CefRefPtr<CefResponse> response,
|
||||
CefRefPtr<CefContentFilter>& filter)
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, on_resource_reponse))
|
||||
return;
|
||||
|
||||
cef_content_filter_t* filterRet = NULL;
|
||||
|
||||
struct_->on_resource_reponse(struct_,
|
||||
CefBrowserCppToC::Wrap(browser), url.GetStruct(),
|
||||
CefResponseCppToC::Wrap(response), &filterRet);
|
||||
|
||||
if(filterRet)
|
||||
filter = CefContentFilterCToCpp::Wrap(filterRet);
|
||||
}
|
||||
|
||||
bool CefRequestHandlerCToCpp::OnProtocolExecution(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url, bool& allowOSExecution)
|
||||
{
|
||||
|
@@ -40,6 +40,9 @@ public:
|
||||
CefRefPtr<CefRequest> request, CefString& redirectUrl,
|
||||
CefRefPtr<CefStreamReader>& resourceStream,
|
||||
CefRefPtr<CefResponse> response, int loadFlags) OVERRIDE;
|
||||
virtual void OnResourceReponse(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url, CefRefPtr<CefResponse> response,
|
||||
CefRefPtr<CefContentFilter>& filter) OVERRIDE;
|
||||
virtual bool OnProtocolExecution(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url, bool& allowOSExecution) OVERRIDE;
|
||||
virtual bool GetDownloadHandler(CefRefPtr<CefBrowser> browser,
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "cpptoc/web_urlrequest_cpptoc.h"
|
||||
#include "cpptoc/xml_reader_cpptoc.h"
|
||||
#include "cpptoc/zip_reader_cpptoc.h"
|
||||
#include "ctocpp/content_filter_ctocpp.h"
|
||||
#include "ctocpp/cookie_visitor_ctocpp.h"
|
||||
#include "ctocpp/domevent_listener_ctocpp.h"
|
||||
#include "ctocpp/domvisitor_ctocpp.h"
|
||||
@@ -69,6 +70,7 @@ CEF_EXPORT void cef_shutdown()
|
||||
DCHECK(CefWebURLRequestCppToC::DebugObjCt == 0);
|
||||
DCHECK(CefXmlReaderCppToC::DebugObjCt == 0);
|
||||
DCHECK(CefZipReaderCppToC::DebugObjCt == 0);
|
||||
DCHECK(CefContentFilterCToCpp::DebugObjCt == 0);
|
||||
DCHECK(CefCookieVisitorCToCpp::DebugObjCt == 0);
|
||||
DCHECK(CefDOMEventListenerCToCpp::DebugObjCt == 0);
|
||||
DCHECK(CefDOMVisitorCToCpp::DebugObjCt == 0);
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "include/cef_capi.h"
|
||||
#include "include/cef_nplugin.h"
|
||||
#include "include/cef_nplugin_capi.h"
|
||||
#include "libcef_dll/cpptoc/content_filter_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/cookie_visitor_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/domevent_listener_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/domvisitor_cpptoc.h"
|
||||
@@ -45,6 +46,7 @@ void CefShutdown()
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Check that all wrapper objects have been destroyed
|
||||
DCHECK(CefContentFilterCppToC::DebugObjCt == 0);
|
||||
DCHECK(CefCookieVisitorCppToC::DebugObjCt == 0);
|
||||
DCHECK(CefDOMEventListenerCppToC::DebugObjCt == 0);
|
||||
DCHECK(CefDOMVisitorCppToC::DebugObjCt == 0);
|
||||
|
Reference in New Issue
Block a user