/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com

Copyright (c) 2011 I-maginer

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt
-----------------------------------------------------------------------------
*/

#ifndef _SCOL_EMBEDDED_WEB_NAVIGATOR_LOAD_
#define _SCOL_EMBEDDED_WEB_NAVIGATOR_LOAD_

#include "embeddedWebNavigatorPrerequisites.h"

/** \defgroup grpWebNavigatorLoad Web navigator loading pages reflexives functions
 *  Callbacks related to browser load status
 *  @{
 */
/** @} */

/** \ingroup grpWebNavigatorLoad
 * \brief WebNavigatorCbOnLoadStart : Called when the browser begins loading a frame.
 * The |frame| value will never be empty -- call the IsMain() method to check if this frame is the main frame.
 * Multiple frames may be loading at the same time. Sub-frames may start or continue loading after the main 
 * frame load has ended. This method may not be called for a particular frame if the load request for that frame fails.
 *
 * <b>Prototype:</b> TODO OBJWEBNAVIGATORSCOL
 * \param OBJWEBNAVIGATORSCOL : The object on which we want to catch the event
 * \param fun [OBJWEBNAVIGATORSCOL u0 S] u1 : Scol function to call
 * \param u0 : Optionnal user parameter
 * \param S : Frame name
 *
 * \return OBJWEBNAVIGATORSCOL : Web navigator object if success
 */
int WebNavigatorCbOnLoadStart(mmachine m);

/**
 * Execute the WEB_NAVIGATOR_LOAD_ON_START_CB reflexive function
 * \param m : Current machine
 * \param hwnd : Main scol window
 * \param msg : Window message
 * \param wParam : WebNavigator pointer
 * \param lParam : data pointer
 * \param ret : user parameter
 */
int FireWebNavigatorReflexiveOnLoadStart(mmachine m, ScolWindowHandle hwnd, unsigned int msg, UINT wParam, LONG lParam, int* ret);

/** \ingroup grpWebNavigatorLoad
 * \brief WebNavigatorCbOnLoadEnd : Called when the browser is done loading a frame.
 * The |frame| value will never be empty -- call the IsMain() method to check if this frame is the main frame.
 * Multiple frames may be loading at the same time. Sub-frames may start or continue loading after the main
 * frame load has ended. This method will always be called for all frames irrespective of whether the request
 * completes successfully.
 *
 * <b>Prototype:</b> TODO OBJWEBNAVIGATORSCOL
 * \param OBJWEBNAVIGATORSCOL : The object on which we want to catch the event
 * \param fun [OBJWEBNAVIGATORSCOL u0 S S] u1 : Scol function to call
 * \param u0 : Optionnal user parameter
 * \param S : Frame name
 * \param S : http status code
 *
 * \return OBJWEBNAVIGATORSCOL : Web navigator object if success
 */
int WebNavigatorCbOnLoadEnd(mmachine m);

/**
 * Execute the WEB_NAVIGATOR_LOAD_ON_END_CB reflexive function
 * \param m : Current machine
 * \param hwnd : Main scol window
 * \param msg : Window message
 * \param wParam : WebNavigator pointer
 * \param lParam : data pointer
 * \param ret : user parameter
 */
int FireWebNavigatorReflexiveOnLoadEnd(mmachine m, ScolWindowHandle hwnd, unsigned int msg, UINT wParam, LONG lParam, int* ret);

/** \ingroup grpWebNavigatorLoad
 * \brief WebNavigatorCbOnLoadError : Called when the browser fails to load a resource.
 * |errorCode| is the error code number and |failedUrl| is the URL that failed to load.
 * To provide custom error text assign the text to |errorText| and return true.
 * Otherwise, return false for the default error text. See net\base\net_error_list.h 
 * for complete descriptions of the error codes.
 *
 * <b>Prototype:</b> TODO OBJWEBNAVIGATORSCOL
 * \param OBJWEBNAVIGATORSCOL : The object on which we want to catch the event
 * \param fun [OBJWEBNAVIGATORSCOL u0 S S I S] u1 : Scol function to call
 * \param u0 : Optionnal user parameter
 * \param S : Frame name
 * \param S : Url that failed to load
 * \param I : Cef error code
 * \param S : Error text
 *
 * \return OBJWEBNAVIGATORSCOL : Web navigator object if success
 *
 * \remarks Cef error codes values are:
 * ERR_FAILED = -2
 * ERR_ABORTED = -3
 * ERR_INVALID_ARGUMENT = -4
 * ERR_INVALID_HANDLE = -5
 * ERR_FILE_NOT_FOUND = -6
 * ERR_TIMED_OUT = -7
 * ERR_FILE_TOO_BIG = -8
 * ERR_UNEXPECTED = -9
 * ERR_ACCESS_DENIED = -10
 * ERR_NOT_IMPLEMENTED = -11
 * ERR_CONNECTION_CLOSED = -100
 * ERR_CONNECTION_RESET = -101
 * ERR_CONNECTION_REFUSED = -102
 * ERR_CONNECTION_ABORTED = -103
 * ERR_CONNECTION_FAILED = -104
 * ERR_NAME_NOT_RESOLVED = -105
 * ERR_INTERNET_DISCONNECTED = -106
 * ERR_SSL_PROTOCOL_ERROR = -107
 * ERR_ADDRESS_INVALID = -108
 * ERR_ADDRESS_UNREACHABLE = -109
 * ERR_SSL_CLIENT_AUTH_CERT_NEEDED = -110
 * ERR_TUNNEL_CONNECTION_FAILED = -111
 * ERR_NO_SSL_VERSIONS_ENABLED = -112
 * ERR_SSL_VERSION_OR_CIPHER_MISMATCH = -113
 * ERR_SSL_RENEGOTIATION_REQUESTED = -114
 * ERR_CERT_COMMON_NAME_INVALID = -200
 * ERR_CERT_DATE_INVALID = -201
 * ERR_CERT_AUTHORITY_INVALID = -202
 * ERR_CERT_CONTAINS_ERRORS = -203
 * ERR_CERT_NO_REVOCATION_MECHANISM = -204
 * ERR_CERT_UNABLE_TO_CHECK_REVOCATION = -205
 * ERR_CERT_REVOKED = -206
 * ERR_CERT_INVALID = -207
 * ERR_CERT_END = -208
 * ERR_INVALID_URL = -300
 * ERR_DISALLOWED_URL_SCHEME = -301
 * ERR_UNKNOWN_URL_SCHEME = -302
 * ERR_TOO_MANY_REDIRECTS = -310
 * ERR_UNSAFE_REDIRECT = -311
 * ERR_UNSAFE_PORT = -312
 * ERR_INVALID_RESPONSE = -320
 * ERR_INVALID_CHUNKED_ENCODING = -321
 * ERR_METHOD_NOT_SUPPORTED = -322
 * ERR_UNEXPECTED_PROXY_AUTH = -323
 * ERR_EMPTY_RESPONSE = -324
 * ERR_RESPONSE_HEADERS_TOO_BIG = -325
 * ERR_CACHE_MISS = -400
 * ERR_INSECURE_RESPONSE = -501
 */
int WebNavigatorCbOnLoadError(mmachine m);

/**
 * Execute the WEB_NAVIGATOR_LOAD_ON_ERROR_CB reflexive function
 * \param m : Current machine
 * \param hwnd : Main scol window
 * \param msg : Window message
 * \param wParam : WebNavigator pointer
 * \param lParam : data pointer
 * \param ret : user parameter
 */
int FireWebNavigatorReflexiveOnLoadError(mmachine m, ScolWindowHandle hwnd, unsigned int msg, UINT wParam, LONG lParam, int* ret);


// Everything inside _cond and _endcond is ignored by doxygen
//! \cond

/**
 * \brief Load the WebNavigatorLoad package in Scol virtual machine
 * \param mmachine : the scol machine
 */
int LoadWebNavigatorLoad(mmachine m);

//! \endcond

#endif
