2009-03-05 02:10:06 +01:00
|
|
|
// Copyright (c) 2009 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 "../precompiled_libcef.h"
|
|
|
|
#include "cpptoc/browser_cpptoc.h"
|
2009-05-28 02:31:21 +02:00
|
|
|
#include "cpptoc/frame_cpptoc.h"
|
2009-03-05 02:10:06 +01:00
|
|
|
#include "cpptoc/request_cpptoc.h"
|
|
|
|
#include "cpptoc/stream_cpptoc.h"
|
2009-05-28 02:31:21 +02:00
|
|
|
#include "cpptoc/v8value_cpptoc.h"
|
2009-03-05 02:10:06 +01:00
|
|
|
#include "ctocpp/handler_ctocpp.h"
|
|
|
|
#include "transfer_util.h"
|
|
|
|
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated(
|
|
|
|
CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& windowInfo, bool popup,
|
|
|
|
CefRefPtr<CefHandler>& handler, std::wstring& url)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_before_created))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_browser_t* browserStruct = NULL;
|
|
|
|
if(parentBrowser.get())
|
|
|
|
browserStruct = CefBrowserCppToC::Wrap(parentBrowser);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_handler_t* handlerStruct = NULL;
|
|
|
|
if(handler.get())
|
|
|
|
handlerStruct = CefHandlerCToCpp::Unwrap(handler);
|
|
|
|
cef_handler_t *origHandlerStruct = handlerStruct;
|
2009-03-05 02:10:06 +01:00
|
|
|
|
|
|
|
cef_string_t urlRet = NULL;
|
|
|
|
if(!url.empty())
|
|
|
|
urlRet = cef_string_alloc(url.c_str());
|
|
|
|
|
|
|
|
cef_retval_t rv = struct_->handle_before_created(struct_,
|
2009-05-28 02:31:21 +02:00
|
|
|
browserStruct, &windowInfo, popup, &handlerStruct, &urlRet);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
if(handlerStruct && handlerStruct != origHandlerStruct) {
|
2009-03-05 02:10:06 +01:00
|
|
|
// The handler was changed.
|
2009-05-28 02:31:21 +02:00
|
|
|
if(handlerStruct)
|
|
|
|
handler = CefHandlerCToCpp::Wrap(handlerStruct);
|
|
|
|
else
|
2009-03-05 02:10:06 +01:00
|
|
|
handler = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
transfer_string_contents(urlRet, url, true);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleAfterCreated(
|
|
|
|
CefRefPtr<CefBrowser> browser)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_after_created))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_after_created(struct_,
|
|
|
|
CefBrowserCppToC::Wrap(browser));
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleAddressChange(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& url)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_address_change))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_address_change(struct_,
|
|
|
|
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
|
2009-03-05 02:10:06 +01:00
|
|
|
url.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleTitleChange(
|
|
|
|
CefRefPtr<CefBrowser> browser, const std::wstring& title)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_title_change))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_title_change(struct_, CefBrowserCppToC::Wrap(browser),
|
2009-03-05 02:10:06 +01:00
|
|
|
title.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeBrowse(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request, NavType navType, bool isRedirect)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_before_browse))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_before_browse(struct_, CefBrowserCppToC::Wrap(browser),
|
|
|
|
CefFrameCppToC::Wrap(frame), CefRequestCppToC::Wrap(request),
|
|
|
|
navType, isRedirect);
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleLoadStart(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_load_start))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_frame_t* frameStruct = NULL;
|
|
|
|
if(frame.get())
|
|
|
|
frameStruct = CefFrameCppToC::Wrap(frame);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_load_start(struct_, CefBrowserCppToC::Wrap(browser),
|
|
|
|
frameStruct);
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleLoadEnd(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_load_end))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_frame_t* frameStruct = NULL;
|
|
|
|
if(frame.get())
|
|
|
|
frameStruct = CefFrameCppToC::Wrap(frame);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_load_end(struct_, CefBrowserCppToC::Wrap(browser),
|
|
|
|
frameStruct);
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleLoadError(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode, const std::wstring& failedUrl, std::wstring& errorText)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_load_error))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
|
|
|
cef_string_t errorTextRet = NULL;
|
|
|
|
if(!errorText.empty())
|
|
|
|
errorTextRet = cef_string_alloc(errorText.c_str());
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_retval_t rv = struct_->handle_load_error(struct_,
|
|
|
|
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame), errorCode,
|
|
|
|
failedUrl.c_str(), &errorTextRet);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
|
|
|
transfer_string_contents(errorTextRet, errorText, true);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeResourceLoad(
|
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request,
|
|
|
|
std::wstring& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream,
|
|
|
|
std::wstring& mimeType, int loadFlags)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_before_resource_load))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
|
|
|
cef_string_t redirectUrlRet = NULL;
|
|
|
|
cef_string_t mimeTypeRet = NULL;
|
|
|
|
cef_stream_reader_t* streamRet = NULL;
|
|
|
|
|
|
|
|
if(!redirectUrl.empty())
|
|
|
|
redirectUrlRet = cef_string_alloc(redirectUrl.c_str());
|
|
|
|
|
|
|
|
cef_retval_t rv = struct_->handle_before_resource_load(struct_,
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Wrap(browser), CefRequestCppToC::Wrap(request),
|
|
|
|
&redirectUrlRet, &streamRet, &mimeTypeRet, loadFlags);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
|
|
|
transfer_string_contents(redirectUrlRet, redirectUrl, true);
|
|
|
|
transfer_string_contents(mimeTypeRet, mimeType, true);
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
if(streamRet)
|
|
|
|
resourceStream = CefStreamReaderCppToC::Unwrap(streamRet);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeMenu(
|
|
|
|
CefRefPtr<CefBrowser> browser, const MenuInfo& menuInfo)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_before_menu))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_before_menu(struct_, CefBrowserCppToC::Wrap(browser),
|
2009-03-05 02:10:06 +01:00
|
|
|
&menuInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleGetMenuLabel(
|
|
|
|
CefRefPtr<CefBrowser> browser, MenuId menuId, std::wstring& label)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_get_menu_label))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
|
|
|
cef_string_t labelRet = NULL;
|
|
|
|
if(!label.empty())
|
|
|
|
labelRet = cef_string_alloc(label.c_str());
|
|
|
|
|
|
|
|
cef_retval_t rv = struct_->handle_get_menu_label(struct_,
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Wrap(browser), menuId, &labelRet);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
|
|
|
transfer_string_contents(labelRet, label, true);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleMenuAction(
|
|
|
|
CefRefPtr<CefBrowser> browser, MenuId menuId)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_menu_action))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_menu_action(struct_, CefBrowserCppToC::Wrap(browser),
|
|
|
|
menuId);
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandlePrintHeaderFooter(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
CefPrintInfo& printInfo, const std::wstring& url, const std::wstring& title,
|
|
|
|
int currentPage, int maxPages, std::wstring& topLeft,
|
|
|
|
std::wstring& topCenter, std::wstring& topRight, std::wstring& bottomLeft,
|
2009-03-05 02:10:06 +01:00
|
|
|
std::wstring& bottomCenter, std::wstring& bottomRight)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_print_header_footer))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
|
|
|
cef_string_t topLeftRet = NULL, topCenterRet = NULL, topRightRet = NULL,
|
|
|
|
bottomLeftRet = NULL, bottomCenterRet = NULL, bottomRightRet = NULL;
|
|
|
|
|
|
|
|
if(!topLeft.empty())
|
|
|
|
topLeftRet = cef_string_alloc(topLeft.c_str());
|
|
|
|
if(!topCenter.empty())
|
|
|
|
topCenterRet = cef_string_alloc(topCenter.c_str());
|
|
|
|
if(!topRight.empty())
|
|
|
|
topRightRet = cef_string_alloc(topRight.c_str());
|
|
|
|
if(!bottomLeft.empty())
|
|
|
|
bottomLeftRet = cef_string_alloc(bottomLeft.c_str());
|
|
|
|
if(!bottomCenter.empty())
|
|
|
|
bottomCenterRet = cef_string_alloc(bottomCenter.c_str());
|
|
|
|
if(!bottomRight.empty())
|
|
|
|
bottomRightRet = cef_string_alloc(bottomRight.c_str());
|
|
|
|
|
|
|
|
cef_retval_t rv = struct_->handle_print_header_footer(struct_,
|
2009-05-28 02:31:21 +02:00
|
|
|
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
|
|
|
|
&printInfo, url.c_str(), title.c_str(), currentPage, maxPages,
|
|
|
|
&topLeftRet, &topCenterRet, &topRightRet, &bottomLeftRet,
|
|
|
|
&bottomCenterRet, &bottomRightRet);
|
2009-03-05 02:10:06 +01:00
|
|
|
|
|
|
|
transfer_string_contents(topLeftRet, topLeft, true);
|
|
|
|
transfer_string_contents(topCenterRet, topCenter, true);
|
|
|
|
transfer_string_contents(topRightRet, topRight, true);
|
|
|
|
transfer_string_contents(bottomLeftRet, bottomLeft, true);
|
|
|
|
transfer_string_contents(bottomCenterRet, bottomCenter, true);
|
|
|
|
transfer_string_contents(bottomRightRet, bottomRight, true);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleJSAlert(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& message)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_jsalert))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_jsalert(struct_, CefBrowserCppToC::Wrap(browser),
|
|
|
|
CefFrameCppToC::Wrap(frame), message.c_str());
|
2009-03-05 02:10:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleJSConfirm(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& message, bool& retval)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_jsconfirm))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
|
|
|
int ret = 0;
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_retval_t rv = struct_->handle_jsconfirm(struct_,
|
|
|
|
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
|
2009-03-05 02:10:06 +01:00
|
|
|
message.c_str(), &ret);
|
|
|
|
retval = (ret ? true : false);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleJSPrompt(
|
2009-05-28 02:31:21 +02:00
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
const std::wstring& message, const std::wstring& defaultValue, bool& retval,
|
|
|
|
std::wstring& result)
|
2009-03-05 02:10:06 +01:00
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_jsprompt))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
|
|
|
cef_string_t resultRet = NULL;
|
|
|
|
if(!result.empty())
|
|
|
|
resultRet = cef_string_alloc(result.c_str());
|
|
|
|
|
|
|
|
int ret = 0;
|
2009-05-28 02:31:21 +02:00
|
|
|
cef_retval_t rv = struct_->handle_jsprompt(struct_,
|
|
|
|
CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
|
2009-03-05 02:10:06 +01:00
|
|
|
message.c_str(), defaultValue.c_str(), &ret, &resultRet);
|
|
|
|
retval = (ret ? true : false);
|
|
|
|
|
|
|
|
transfer_string_contents(resultRet, result, true);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2009-03-08 03:26:16 +01:00
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeWindowClose(
|
|
|
|
CefRefPtr<CefBrowser> browser)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_before_window_close))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_before_window_close(struct_,
|
|
|
|
CefBrowserCppToC::Wrap(browser));
|
2009-03-08 03:26:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleTakeFocus(
|
|
|
|
CefRefPtr<CefBrowser> browser, bool reverse)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_take_focus))
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_take_focus(struct_, CefBrowserCppToC::Wrap(browser),
|
|
|
|
reverse);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHandler::RetVal CefHandlerCToCpp::HandleJSBinding(
|
|
|
|
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Value> object)
|
|
|
|
{
|
|
|
|
if(CEF_MEMBER_MISSING(struct_, handle_jsbinding))
|
|
|
|
return RV_CONTINUE;
|
2009-03-08 03:26:16 +01:00
|
|
|
|
2009-05-28 02:31:21 +02:00
|
|
|
return struct_->handle_jsbinding(struct_, CefBrowserCppToC::Wrap(browser),
|
|
|
|
CefFrameCppToC::Wrap(frame), CefV8ValueCppToC::Wrap(object));
|
2009-03-08 03:26:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2009-05-28 02:31:21 +02:00
|
|
|
long CefCToCpp<CefHandlerCToCpp, CefHandler, cef_handler_t>::DebugObjCt = 0;
|
2009-03-08 03:26:16 +01:00
|
|
|
#endif
|