mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-01-20 13:39:54 +01:00
9df142f832
- Add CefBrowserProcessHandler interface (issue #650). - Internally re-register supported schemes with CefCookieManager after changing the storage path (issue #651). - Add CefResourceHandler callbacks for blocking cookie loading and saving (issue #652). - Allow custom scheme handlers for requests that do not originate from browser content (issue #653). - Use 'int' instead of 'RequestFlags' for CefRequest::GetFlags and SetFlags (issue #654). - Rename cef_request.h CreateObject methods to Create (issue #655). - Add #ifdef guards to cef_tuple.h to allow the use of both cef_runnable.h and base/bind.h in the same unit test source file. - Retrieve cookieable schemes as part of ClientApp::RegisterCustomSchemes and register with the global cookie manager. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@697 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
86 lines
2.9 KiB
C++
86 lines
2.9 KiB
C++
// Copyright (c) 2012 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.
|
|
|
|
#include "libcef/browser/url_request_interceptor.h"
|
|
|
|
#include <string>
|
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
|
#include "libcef/browser/resource_request_job.h"
|
|
#include "libcef/browser/thread_util.h"
|
|
#include "libcef/common/request_impl.h"
|
|
|
|
#include "net/url_request/url_request_job_manager.h"
|
|
#include "net/url_request/url_request_redirect_job.h"
|
|
|
|
CefRequestInterceptor::CefRequestInterceptor() {
|
|
CEF_REQUIRE_IOT();
|
|
net::URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(this);
|
|
}
|
|
|
|
CefRequestInterceptor::~CefRequestInterceptor() {
|
|
CEF_REQUIRE_IOT();
|
|
net::URLRequestJobManager::GetInstance()->
|
|
UnregisterRequestInterceptor(this);
|
|
}
|
|
|
|
net::URLRequestJob* CefRequestInterceptor::MaybeIntercept(
|
|
net::URLRequest* request) {
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
CefBrowserHostImpl::GetBrowserForRequest(request);
|
|
if (browser.get()) {
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
if (client.get()) {
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
if (handler.get()) {
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(request);
|
|
|
|
// Populate the request data.
|
|
CefRefPtr<CefRequest> req(CefRequest::Create());
|
|
static_cast<CefRequestImpl*>(req.get())->Set(request);
|
|
|
|
// Give the client an opportunity to replace the request.
|
|
CefRefPtr<CefResourceHandler> resourceHandler =
|
|
handler->GetResourceHandler(browser.get(), frame, req);
|
|
if (resourceHandler.get())
|
|
return new CefResourceRequestJob(request, resourceHandler);
|
|
}
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
net::URLRequestJob* CefRequestInterceptor::MaybeInterceptRedirect(
|
|
net::URLRequest* request, const GURL& location) {
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
CefBrowserHostImpl::GetBrowserForRequest(request);
|
|
if (browser.get()) {
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
if (client.get()) {
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
if (handler.get()) {
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(request);
|
|
|
|
// Give the client an opportunity to redirect the request.
|
|
CefString newUrlStr = location.spec();
|
|
handler->OnResourceRedirect(browser.get(), frame, request->url().spec(),
|
|
newUrlStr);
|
|
if (newUrlStr != location.spec()) {
|
|
GURL new_url = GURL(std::string(newUrlStr));
|
|
if (!new_url.is_empty() && new_url.is_valid())
|
|
return new net::URLRequestRedirectJob(request, new_url);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
net::URLRequestJob* CefRequestInterceptor::MaybeInterceptResponse(
|
|
net::URLRequest* request) {
|
|
return NULL;
|
|
}
|