From f7908a50294adff3456436074075a677a9c6239b Mon Sep 17 00:00:00 2001
From: callum_linden <none@none>
Date: Tue, 30 Jun 2015 00:07:58 +0100
Subject: [PATCH] Point to new version of LLCefLib with support for second life
 URLs, version string, navigation commands

---
 autobuild.xml                                 |  10 +-
 indra/media_plugins/cef/media_plugin_cef.cpp  | 143 +++++++++++++++---
 indra/newview/llappviewer.cpp                 |   5 +-
 .../newview/skins/default/xui/en/strings.xml  |   2 +-
 4 files changed, 132 insertions(+), 28 deletions(-)

diff --git a/autobuild.xml b/autobuild.xml
index 8cf011af9fc..c3f0297c00d 100755
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -1536,11 +1536,11 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>47e50c4116920688aafe2590f0c05182</string>
+              <string>706fa86b0fd7621456d4b8a6747a8c3f</string>
               <key>hash_algorithm</key>
               <string>md5</string>
               <key>url</key>
-              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/llceflib_3p-llceflib/rev/302731/arch/Darwin/installer/llceflib-1.0.0.(CEF3.2171.2069-32).302731-darwin-302731.tar.bz2</string>
+              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/llceflib_3p-llceflib/rev/303093/arch/Darwin/installer/llceflib-1.0.0.(CEF-OSX-3.2171.2069-32).303093-darwin-303093.tar.bz2</string>
             </map>
             <key>name</key>
             <string>darwin</string>
@@ -1550,18 +1550,18 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>274594d16e60e77752935e6d73ca2637</string>
+              <string>0867f50bc1292bc0f1a66f2008feab51</string>
               <key>hash_algorithm</key>
               <string>md5</string>
               <key>url</key>
-              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/llceflib_3p-llceflib/rev/302873/arch/CYGWIN/installer/llceflib-1.0.0.(CEF-WIN-3.2272.gbda8dc7-32).302873-windows-302873.tar.bz2</string>
+              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/llceflib_3p-llceflib/rev/303093/arch/CYGWIN/installer/llceflib-1.0.0.(CEF-WIN-3.2272.gbda8dc7-32).303093-windows-303093.tar.bz2</string>
             </map>
             <key>name</key>
             <string>windows</string>
           </map>
         </map>
         <key>version</key>
-        <string>1.0.0.(CEF-WIN-3.2272.gbda8dc7-32).302873</string>
+        <string>1.0.0.(CEF-WIN-3.2272.gbda8dc7-32).303093</string>
       </map>
       <key>llphysicsextensions_source</key>
       <map>
diff --git a/indra/media_plugins/cef/media_plugin_cef.cpp b/indra/media_plugins/cef/media_plugin_cef.cpp
index 187c6a241da..3b82071ae81 100644
--- a/indra/media_plugins/cef/media_plugin_cef.cpp
+++ b/indra/media_plugins/cef/media_plugin_cef.cpp
@@ -38,8 +38,6 @@
 #include "boost/bind.hpp"
 #include "llCEFLib.h"
 
-#include <time.h>  // remove me
-
 ////////////////////////////////////////////////////////////////////////////////
 //
 class MediaPluginCEF :
@@ -55,19 +53,15 @@ class MediaPluginCEF :
 private:
 	bool init();
 
-	// TODO FIX ME
-	void pageChangedCallback(unsigned char* pixels, int width, int height)
-	{
-		if (mPixels && pixels)
-		{
-			if (mWidth == width && mHeight == height)
-			{
-				memcpy(mPixels, pixels, mWidth * mHeight * mDepth);
-			}
-			setDirty(0, 0, mWidth, mHeight);
-		}
-	}
-
+	void pageChangedCallback(unsigned char* pixels, int width, int height);
+	void onCustomSchemeURLCallback(std::string url);
+	void onConsoleMessageCallback(std::string message, std::string source, int line);
+	void onStatusMessageCallback(std::string value);
+	void onTitleChangeCallback(std::string title);
+	void onLoadStartCallback();
+	void onLoadEndCallback(int httpStatusCode);
+	void onNavigateURLCallback(std::string url);
+
 	void postDebugMessage(const std::string& msg);
 
 	bool mEnableMediaPluginDebugging;
@@ -99,7 +93,7 @@ MediaPluginCEF::~MediaPluginCEF()
 //
 void MediaPluginCEF::postDebugMessage(const std::string& msg)
 {
-	//if (mEnableMediaPluginDebugging)
+	if (mEnableMediaPluginDebugging)
 	{
 		std::stringstream str;
 		str << "@Media Msg> " << msg;
@@ -111,6 +105,89 @@ void MediaPluginCEF::postDebugMessage(const std::string& msg)
 	}
 }
 
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::pageChangedCallback(unsigned char* pixels, int width, int height)
+{
+	if (mPixels && pixels)
+	{
+		if (mWidth == width && mHeight == height)
+		{
+			memcpy(mPixels, pixels, mWidth * mHeight * mDepth);
+		}
+		setDirty(0, 0, mWidth, mHeight);
+	}
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::onCustomSchemeURLCallback(std::string url)
+{
+	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_nofollow");
+	message.setValue("uri", url);
+	message.setValue("nav_type", "clicked");	// TODO: differentiate between click and navigate to
+	sendMessage(message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::onConsoleMessageCallback(std::string message, std::string source, int line)
+{
+	std::stringstream str;
+	str << "Console message: " << message << " in file(" << source << ") at line " << line;
+	postDebugMessage(str.str());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::onStatusMessageCallback(std::string value)
+{
+	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "status_text");
+	message.setValue("status", value);
+	sendMessage(message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::onTitleChangeCallback(std::string title)
+{
+	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "name_text");
+	message.setValue("name", title);
+	sendMessage(message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::onLoadStartCallback()
+{
+	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "navigate_begin");
+	//message.setValue("uri", event.getEventUri());  // not easily available here in CEF - needed?
+	message.setValueBoolean("history_back_available", mLLCEFLib->canGoBack());
+	message.setValueBoolean("history_forward_available", mLLCEFLib->canGoForward());
+	sendMessage(message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::onLoadEndCallback(int httpStatusCode)
+{
+	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "navigate_complete");
+	//message.setValue("uri", event.getEventUri());  // not easily available here in CEF - needed?
+	message.setValueS32("result_code", httpStatusCode);
+	message.setValueBoolean("history_back_available", mLLCEFLib->canGoBack());
+	message.setValueBoolean("history_forward_available", mLLCEFLib->canGoForward());
+	sendMessage(message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+void MediaPluginCEF::onNavigateURLCallback(std::string url)
+{
+	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "location_changed");
+	message.setValue("uri", url);
+	sendMessage(message);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 //
 void MediaPluginCEF::receiveMessage(const char* message_string)
@@ -133,7 +210,7 @@ void MediaPluginCEF::receiveMessage(const char* message_string)
 				versions[LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER] = LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER_VERSION;
 				message.setValueLLSD("versions", versions);
 
-				std::string plugin_version = "Example plugin 1.0..0";
+				std::string plugin_version = "CEF plugin 1.0.0";
 				message.setValue("plugin_version", plugin_version);
 				sendMessage(message);
 			}
@@ -186,8 +263,15 @@ void MediaPluginCEF::receiveMessage(const char* message_string)
 		{
 			if (message_name == "init")
 			{
-
+				// event callbacks from LLCefLib
 				mLLCEFLib->setPageChangedCallback(boost::bind(&MediaPluginCEF::pageChangedCallback, this, _1, _2, _3));
+				mLLCEFLib->setOnCustomSchemeURLCallback(boost::bind(&MediaPluginCEF::onCustomSchemeURLCallback, this, _1));
+				mLLCEFLib->setOnConsoleMessageCallback(boost::bind(&MediaPluginCEF::onConsoleMessageCallback, this, _1, _2, _3));
+				mLLCEFLib->setOnStatusMessageCallback(boost::bind(&MediaPluginCEF::onStatusMessageCallback, this, _1));
+				mLLCEFLib->setOnTitleChangeCallback(boost::bind(&MediaPluginCEF::onTitleChangeCallback, this, _1));
+				mLLCEFLib->setOnLoadStartCallback(boost::bind(&MediaPluginCEF::onLoadStartCallback, this));
+				mLLCEFLib->setOnLoadEndCallback(boost::bind(&MediaPluginCEF::onLoadEndCallback, this, _1));
+				mLLCEFLib->setOnNavigateURLCallback(boost::bind(&MediaPluginCEF::onNavigateURLCallback, this, _1));
 
 	            LLCEFLibSettings settings;
 	            settings.inital_width = 1024;
@@ -197,6 +281,7 @@ void MediaPluginCEF::receiveMessage(const char* message_string)
 				bool result = mLLCEFLib->init(settings);
 				if (!result)
 				{
+// TODO - return something to indicate failure
 					//MessageBoxA(0, "FAIL INIT", 0, 0);
 				}
 
@@ -332,6 +417,26 @@ void MediaPluginCEF::receiveMessage(const char* message_string)
 				mEnableMediaPluginDebugging = message_in.getValueBoolean("enable");
 			}
 		}
+		else if (message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER)
+		{
+			if (message_name == "browse_stop")
+			{
+				mLLCEFLib->stop();
+			}
+			else if (message_name == "browse_reload")
+			{
+				bool ignore_cache = true;
+				mLLCEFLib->reload(ignore_cache);
+			}
+			else if (message_name == "browse_forward")
+			{
+				mLLCEFLib->goForward();
+			}
+			else if (message_name == "browse_back")
+			{
+				mLLCEFLib->goBack();
+			}
+		}
 		else
 		{
 			//std::cerr << "MediaPluginWebKit::receiveMessage: unknown message class: " << message_class << std::endl;
@@ -344,7 +449,7 @@ void MediaPluginCEF::receiveMessage(const char* message_string)
 bool MediaPluginCEF::init()
 {
 	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "name_text");
-	message.setValue("name", "Example Plugin");
+	message.setValue("name", "CEF Plugin");
 	sendMessage(message);
 
 	return true;
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 6dc71bc94e3..d2b9259ef7c 100755
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -123,6 +123,7 @@
 #include "llleap.h"
 #include "stringize.h"
 #include "llcoros.h"
+#include "cef/llceflib.h"
 
 // Third party library includes
 #include <boost/bind.hpp>
@@ -130,7 +131,6 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/regex.hpp>
 
-
 #if LL_WINDOWS
 #	include <share.h> // For _SH_DENYWR in processMarkerFiles
 #else
@@ -3369,8 +3369,7 @@ LLSD LLAppViewer::getViewerInfo() const
 		info["VOICE_VERSION"] = LLTrans::getString("NotConnected");
 	}
 
-	// TODO: Implement media plugin version query
-	info["QT_WEBKIT_VERSION"] = "4.7.1 (version number hard-coded)";
+	info["LLCEFLIB_VERSION"] = LLCEFLIB_VERSION;
 
 	S32 packets_in = LLViewerStats::instance().getRecording().getSum(LLStatViewer::PACKETS_IN);
 	if (packets_in > 0)
diff --git a/indra/newview/skins/default/xui/en/strings.xml b/indra/newview/skins/default/xui/en/strings.xml
index f77678e5f89..d6ac91e45f2 100755
--- a/indra/newview/skins/default/xui/en/strings.xml
+++ b/indra/newview/skins/default/xui/en/strings.xml
@@ -50,7 +50,7 @@ OpenGL Version: [OPENGL_VERSION]
 libcurl Version: [LIBCURL_VERSION]
 J2C Decoder Version: [J2C_VERSION]
 Audio Driver Version: [AUDIO_DRIVER_VERSION]
-Qt Webkit Version: [QT_WEBKIT_VERSION]
+LLCEFLib/CEF Version: [LLCEFLIB_VERSION]
 Voice Server Version: [VOICE_VERSION]
 	</string>
 	<string name="AboutTraffic">Packets Lost: [PACKETS_LOST,number,0]/[PACKETS_IN,number,0] ([PACKETS_PCT,number,1]%)</string>
-- 
GitLab