/*
-----------------------------------------------------------------------------
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_THREAD_
#define _SCOL_EMBEDDED_WEB_NAVIGATOR_THREAD_

#include "embeddedWebNavigatorPrerequisites.h"

namespace Scol
{
  namespace EmbeddedWebNavigator
  {

class WebNavigatorThread
{
public:
protected:
private:

public:
  /*!
  Loads an URL.
  @param url The url to load
  @param frameName The target frame, main frame will be used if empty.
  */
  static void LoadURL(unsigned long webNavigatorId, const std::string url, const std::string frameName="");

  /*!
  Loads a local file.
  @param url The file to load
  @param frameName The target frame, main frame will be used if empty.
  @note	The file should reside in a scol partition.
  */
  static void LoadFile(unsigned long webNavigatorId, const std::string file, const std::string frameName="");

  /*
  Loads a string of HTML.
  @param url The html text to load
  @param frameName The target frame, main frame will be used if empty.
  @note	Relative URLs will be resolved using the base directory.
  */
  static void LoadHTML(unsigned long webNavigatorId, const std::string html, const std::string frameName="");
  
  /*!
  Returns the URL currently loaded in a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void GetURL(unsigned long webNavigatorId, std::string* frameUrl, HANDLE synchro, const std::string frameName="");

  /*!
  Execute undo on a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void Undo(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Execute redo on a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void Redo(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Execute cut on a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void Cut(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Execute copy on a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void Copy(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Execute paste on a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void Paste(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Execute delete on a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void Delete(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Execute select all on a frame.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void SelectAll(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Execute printing on a frame. The user will be prompted with the print dialog appropriate to the operating system.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void Print(unsigned long webNavigatorId, const std::string frameName="");
  
  /*!
  Save a frame's HTML source to a temporary file and open it in the default text viewing application.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void ViewSource(unsigned long webNavigatorId, const std::string frameName="");

  /*!
  Returns a frame's HTML source as a string.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void GetSource(unsigned long webNavigatorId, std::string* frameSource, HANDLE synchro, const std::string frameName="");

  /*!
  Returns a frame's display text as a string.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void GetText(unsigned long webNavigatorId, std::string* frameText, HANDLE synchro, const std::string frameName="");

  /*!
  Execute a string of JavaScript code in this frame.
  The |script_url| parameter is the URL where the script in question can be found, if any.
  The renderer may request this URL to show the developer the source of the error.
  The |start_line| parameter is the base line number to use for error reporting.
  @param frameName The target frame, main frame will be used if empty.
  */
  static void ExecuteJavaScript(unsigned long webNavigatorId, const std::string jsCode, const std::string scriptUrl, int startLine, const std::string frameName="");

  /*!
  Returns true if the browser can navigate backwards.
  */
  static void CanGoBack(unsigned long webNavigatorId, bool* canGoBack, HANDLE synchro);
  
  /*!
  Navigate backwards.
  */
  static void GoBack(unsigned long webNavigatorId);
  
  /*!
  Returns true if the browser can navigate forwards.
  */
  static void CanGoForward(unsigned long webNavigatorId, bool* canGoForward, HANDLE synchro);
  
  /*!
  Navigate forwards.
  */
  static void GoForward(unsigned long webNavigatorId);

  /*!
  Reload the current page.
  */
  static void Reload(unsigned long webNavigatorId);

  /*!
  Reload the current page ignoring any cached data.
  */
  static void ReloadIgnoreCache(unsigned long webNavigatorId);
  
  /*!
  Stop loading the page.
  */
  static void StopLoad(unsigned long webNavigatorId);

  /*!
  Search for text in the current page.
  @param identifier Can be used to have multiple searches running simultaniously (search index). 
  @param searchText The searched text
  @param forward Indicates whether to search forward or backward within the page.
  @param matchCase Indicates whether the search should be case-sensitive.
  @param findNext Indicates whether this is the first request or a follow-up.
  */
  static void Find(unsigned long webNavigatorId, int identifier, const CefString searchText, bool forward, bool matchCase, bool findNext);

  /*!
  Cancel all searches that are currently going on.
  */
  static void StopFinding(unsigned long webNavigatorId, bool clearSelection);

  /*!
  Get the zoom level.
  */
  static void GetZoomLevel(unsigned long webNavigatorId, double* zoomFactor, HANDLE synchro);

  /*!
  Change the zoom level to the specified value.
  */
  static void SetZoomLevel(unsigned long webNavigatorId, double zoomLevel);
  
  /*!
  Clear the back/forward browsing history.
  */
  static void ClearHistory(unsigned long webNavigatorId);

  /*!
  Open developer tools window.
  */
  static void ShowDevTools(unsigned long webNavigatorId);

  /*!
  Close the developer tools window if one exists for this browser instance.
  */
  static void CloseDevTools(unsigned long webNavigatorId);
protected:
private:
  /*!
  Forbidden constructor (static class).
  */
  WebNavigatorThread();
};

  }
}

#endif
