mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add CefRequestHandler::OnBeforeBrowse callback (issue #1076).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1440 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -5,16 +5,93 @@
|
||||
#include "libcef/browser/resource_dispatcher_host_delegate.h"
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
#include "libcef/browser/origin_whitelist_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/request_impl.h"
|
||||
|
||||
#include "base/memory/scoped_vector.h"
|
||||
#include "components/navigation_interception/intercept_navigation_resource_throttle.h"
|
||||
#include "components/navigation_interception/navigation_params.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "content/public/common/resource_response.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool NavigationOnUIThread(
|
||||
int64 frame_id,
|
||||
CefRefPtr<CefRequestImpl> request,
|
||||
content::RenderViewHost* source,
|
||||
const navigation_interception::NavigationParams& params) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
bool ignore_navigation = false;
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
CefBrowserHostImpl::GetBrowserForHost(source);
|
||||
DCHECK(browser.get());
|
||||
if (browser.get()) {
|
||||
CefRefPtr<CefClient> client = browser->GetClient();
|
||||
if (client.get()) {
|
||||
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefFrame> frame;
|
||||
if (frame_id >= 0)
|
||||
frame = browser->GetFrame(frame_id);
|
||||
DCHECK(frame.get());
|
||||
if (frame.get()) {
|
||||
ignore_navigation = handler->OnBeforeBrowse(
|
||||
browser.get(), frame, request.get(), params.is_redirect());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ignore_navigation;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefResourceDispatcherHostDelegate::CefResourceDispatcherHostDelegate() {
|
||||
}
|
||||
|
||||
CefResourceDispatcherHostDelegate::~CefResourceDispatcherHostDelegate() {
|
||||
}
|
||||
|
||||
void CefResourceDispatcherHostDelegate::RequestBeginning(
|
||||
net::URLRequest* request,
|
||||
content::ResourceContext* resource_context,
|
||||
appcache::AppCacheService* appcache_service,
|
||||
ResourceType::Type resource_type,
|
||||
int child_id,
|
||||
int route_id,
|
||||
bool is_continuation_of_transferred_request,
|
||||
ScopedVector<content::ResourceThrottle>* throttles) {
|
||||
if (resource_type == ResourceType::MAIN_FRAME ||
|
||||
resource_type == ResourceType::SUB_FRAME) {
|
||||
int64 frame_id = -1;
|
||||
|
||||
// ResourceRequestInfo will not exist for requests originating from
|
||||
// WebURLLoader in the render process.
|
||||
const content::ResourceRequestInfo* info =
|
||||
content::ResourceRequestInfo::ForRequest(request);
|
||||
if (info)
|
||||
frame_id = info->GetFrameID();
|
||||
|
||||
if (frame_id >= 0) {
|
||||
CefRefPtr<CefRequestImpl> cef_request(new CefRequestImpl);
|
||||
cef_request->Set(request);
|
||||
cef_request->SetReadOnly(true);
|
||||
|
||||
content::ResourceThrottle* throttle =
|
||||
new navigation_interception::InterceptNavigationResourceThrottle(
|
||||
request,
|
||||
base::Bind(&NavigationOnUIThread, frame_id, cef_request));
|
||||
throttles->push_back(throttle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CefResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url,
|
||||
int child_id,
|
||||
int route_id) {
|
||||
|
Reference in New Issue
Block a user