mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Expose CefLoadHandler in the render process (issue #1077).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1442 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -24,9 +24,11 @@
|
||||
#include "content/public/renderer/document_state.h"
|
||||
#include "content/public/renderer/navigation_state.h"
|
||||
#include "content/public/renderer/render_view.h"
|
||||
#include "content/renderer/render_view_impl.h"
|
||||
#include "net/http/http_util.h"
|
||||
#include "third_party/WebKit/public/platform/WebString.h"
|
||||
#include "third_party/WebKit/public/platform/WebURL.h"
|
||||
#include "third_party/WebKit/public/platform/WebURLError.h"
|
||||
#include "third_party/WebKit/public/platform/WebURLResponse.h"
|
||||
#include "third_party/WebKit/public/web/WebDataSource.h"
|
||||
#include "third_party/WebKit/public/web/WebDocument.h"
|
||||
@@ -443,6 +445,12 @@ void CefBrowserImpl::AddFrameObject(int64 frame_id,
|
||||
manager->Add(tracked_object);
|
||||
}
|
||||
|
||||
bool CefBrowserImpl::is_swapped_out() const {
|
||||
content::RenderViewImpl* render_view_impl =
|
||||
static_cast<content::RenderViewImpl*>(render_view());
|
||||
return (!render_view_impl || render_view_impl->is_swapped_out());
|
||||
}
|
||||
|
||||
|
||||
// RenderViewObserver methods.
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -462,6 +470,21 @@ void CefBrowserImpl::OnDestruct() {
|
||||
CefContentRendererClient::Get()->OnBrowserDestroyed(this);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::DidStartLoading() {
|
||||
OnLoadingStateChange(true);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::DidStopLoading() {
|
||||
OnLoadingStateChange(false);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::DidFailLoad(
|
||||
WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLError& error) {
|
||||
OnLoadError(frame, error);
|
||||
OnLoadEnd(frame);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::DidFinishLoad(WebKit::WebFrame* frame) {
|
||||
WebKit::WebDataSource* ds = frame->dataSource();
|
||||
Send(new CefHostMsg_DidFinishLoad(routing_id(),
|
||||
@@ -469,6 +492,7 @@ void CefBrowserImpl::DidFinishLoad(WebKit::WebFrame* frame) {
|
||||
ds->request().url(),
|
||||
!frame->parent(),
|
||||
ds->response().httpStatusCode()));
|
||||
OnLoadEnd(frame);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::DidStartProvisionalLoad(WebKit::WebFrame* frame) {
|
||||
@@ -476,6 +500,17 @@ void CefBrowserImpl::DidStartProvisionalLoad(WebKit::WebFrame* frame) {
|
||||
GetWebFrameImpl(frame);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::DidFailProvisionalLoad(
|
||||
WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLError& error) {
|
||||
OnLoadError(frame, error);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::DidCommitProvisionalLoad(WebKit::WebFrame* frame,
|
||||
bool is_new_navigation) {
|
||||
OnLoadStart(frame);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::FrameDetached(WebFrame* frame) {
|
||||
int64 frame_id = frame->identifier();
|
||||
|
||||
@@ -713,3 +748,92 @@ void CefBrowserImpl::OnResponse(const Cef_Response_Params& params) {
|
||||
void CefBrowserImpl::OnResponseAck(int request_id) {
|
||||
response_manager_->RunAckHandler(request_id);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::OnLoadingStateChange(bool isLoading) {
|
||||
content::RenderViewImpl* render_view_impl =
|
||||
static_cast<content::RenderViewImpl*>(render_view());
|
||||
if (is_swapped_out())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
||||
if (app.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
app->GetRenderProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefLoadHandler> load_handler = handler->GetLoadHandler();
|
||||
if (load_handler.get()) {
|
||||
WebView* web_view = render_view()->GetWebView();
|
||||
const bool canGoBack = webkit_glue::CanGoBack(web_view);
|
||||
const bool canGoForward = webkit_glue::CanGoForward(web_view);
|
||||
|
||||
load_handler->OnLoadingStateChange(this, isLoading, canGoBack,
|
||||
canGoForward);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::OnLoadStart(WebKit::WebFrame* frame) {
|
||||
content::RenderViewImpl* render_view_impl =
|
||||
static_cast<content::RenderViewImpl*>(render_view());
|
||||
if (is_swapped_out())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
||||
if (app.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
app->GetRenderProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefLoadHandler> load_handler = handler->GetLoadHandler();
|
||||
if (load_handler.get()) {
|
||||
CefRefPtr<CefFrameImpl> cef_frame = GetWebFrameImpl(frame);
|
||||
load_handler->OnLoadStart(this, cef_frame.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::OnLoadEnd(WebKit::WebFrame* frame) {
|
||||
content::RenderViewImpl* render_view_impl =
|
||||
static_cast<content::RenderViewImpl*>(render_view());
|
||||
if (is_swapped_out())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
||||
if (app.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
app->GetRenderProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefLoadHandler> load_handler = handler->GetLoadHandler();
|
||||
if (load_handler.get()) {
|
||||
CefRefPtr<CefFrameImpl> cef_frame = GetWebFrameImpl(frame);
|
||||
int httpStatusCode = frame->dataSource()->response().httpStatusCode();
|
||||
load_handler->OnLoadEnd(this, cef_frame.get(), httpStatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::OnLoadError(WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLError& error) {
|
||||
if (is_swapped_out())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
||||
if (app.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
app->GetRenderProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefLoadHandler> load_handler = handler->GetLoadHandler();
|
||||
if (load_handler.get()) {
|
||||
CefRefPtr<CefFrameImpl> cef_frame = GetWebFrameImpl(frame);
|
||||
const cef_errorcode_t errorCode =
|
||||
static_cast<cef_errorcode_t>(error.reason);
|
||||
const std::string& errorText = error.localizedDescription.utf8();
|
||||
const GURL& failedUrl = error.unreachableURL;
|
||||
load_handler->OnLoadError(this, cef_frame.get(), errorCode, errorText,
|
||||
failedUrl.spec());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -103,15 +103,26 @@ class CefBrowserImpl : public CefBrowser,
|
||||
bool is_window_rendering_disabled() const {
|
||||
return is_window_rendering_disabled_;
|
||||
}
|
||||
content::RenderView* render_view() {
|
||||
content::RenderView* render_view() const {
|
||||
return content::RenderViewObserver::render_view();
|
||||
}
|
||||
|
||||
bool is_swapped_out() const;
|
||||
|
||||
private:
|
||||
// RenderViewObserver methods.
|
||||
virtual void OnDestruct() OVERRIDE;
|
||||
virtual void DidStartLoading() OVERRIDE;
|
||||
virtual void DidStopLoading() OVERRIDE;
|
||||
virtual void DidFailLoad(WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLError& error) OVERRIDE;
|
||||
virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE;
|
||||
virtual void DidStartProvisionalLoad(WebKit::WebFrame* frame) OVERRIDE;
|
||||
virtual void DidFailProvisionalLoad(
|
||||
WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLError& error) OVERRIDE;
|
||||
virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
|
||||
bool is_new_navigation) OVERRIDE;
|
||||
virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE;
|
||||
virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE;
|
||||
virtual void DidCreateDataSource(WebKit::WebFrame* frame,
|
||||
@@ -123,6 +134,11 @@ class CefBrowserImpl : public CefBrowser,
|
||||
void OnResponse(const Cef_Response_Params& params);
|
||||
void OnResponseAck(int request_id);
|
||||
|
||||
void OnLoadingStateChange(bool isLoading);
|
||||
void OnLoadStart(WebKit::WebFrame* frame);
|
||||
void OnLoadEnd(WebKit::WebFrame* frame);
|
||||
void OnLoadError(WebKit::WebFrame* frame, const WebKit::WebURLError& error);
|
||||
|
||||
// ID of the browser that this RenderView is associated with. During loading
|
||||
// of cross-origin requests multiple RenderViews may be associated with the
|
||||
// same browser ID.
|
||||
|
Reference in New Issue
Block a user