From 7847c8941f8c78ab7cdef65aadf4dfccf645bbf3 Mon Sep 17 00:00:00 2001
From: callum <none@none>
Date: Thu, 9 Jun 2011 13:48:35 -0700
Subject: [PATCH] EXP-676 FIX As a web developer, I want to access information
 about the current state of the SL client, such as avatar location

---
 autobuild.xml                                 |  8 +--
 indra/llplugin/llpluginclassmedia.cpp         | 18 +----
 indra/llplugin/llpluginclassmedia.h           |  3 +-
 .../webkit/media_plugin_webkit.cpp            | 36 ++++++----
 indra/newview/llviewermedia.cpp               | 69 +++++++++----------
 5 files changed, 64 insertions(+), 70 deletions(-)

diff --git a/autobuild.xml b/autobuild.xml
index b59e3757c4a..3fb0d6a9bee 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -1206,9 +1206,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>82798d0da3ac3d97c91517a575d9ea1c</string>
+              <string>a7c80fd8516df3b879b669b2b220067f</string>
               <key>url</key>
-              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-llqtwebkit/rev/231093/arch/Darwin/installer/llqtwebkit-4.7.1-darwin-20110526.tar.bz2</string>
+              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-llqtwebkit/rev/232420/arch/Darwin/installer/llqtwebkit-4.7.1-darwin-20110608.tar.bz2</string>
             </map>
             <key>name</key>
             <string>darwin</string>
@@ -1230,9 +1230,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>f0708d18943a05013493f69ab7dc6429</string>
+              <string>b9cc0333cc274c9cc40256ab7146b4fc</string>
               <key>url</key>
-              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-llqtwebkit/rev/231093/arch/CYGWIN/installer/llqtwebkit-4.7.1-windows-20110526.tar.bz2</string>
+              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-llqtwebkit/rev/232420/arch/CYGWIN/installer/llqtwebkit-4.7.1-windows-20110608.tar.bz2</string>
             </map>
             <key>name</key>
             <string>windows</string>
diff --git a/indra/llplugin/llpluginclassmedia.cpp b/indra/llplugin/llpluginclassmedia.cpp
index 8f161201f43..d3d0403bbbe 100644
--- a/indra/llplugin/llpluginclassmedia.cpp
+++ b/indra/llplugin/llpluginclassmedia.cpp
@@ -436,27 +436,15 @@ std::string LLPluginClassMedia::translateModifiers(MASK modifiers)
 	return result;
 }
 
-void LLPluginClassMedia::jsExposeObjectEvent( bool expose )
+void LLPluginClassMedia::jsEnableObject( bool enable )
 {
 	if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
 	{
 		return;
 	}
 
-	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_expose_object");
-	message.setValueBoolean( "expose", expose );
-	sendMessage( message );
-}
-
-void LLPluginClassMedia::jsValuesValidEvent( bool valid )
-{
-	if( ! mPlugin || !mPlugin->isRunning() || mPlugin->isBlocked() )
-	{
-		return;
-	}
-
-	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_values_valid");
-	message.setValueBoolean( "valid", valid );
+	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "js_enable_object");
+	message.setValueBoolean( "enable", enable );
 	sendMessage( message );
 }
 
diff --git a/indra/llplugin/llpluginclassmedia.h b/indra/llplugin/llpluginclassmedia.h
index c061390699d..f8ed89f644a 100644
--- a/indra/llplugin/llpluginclassmedia.h
+++ b/indra/llplugin/llpluginclassmedia.h
@@ -119,8 +119,7 @@ class LLPluginClassMedia : public LLPluginProcessParentOwner
 	void scrollEvent(int x, int y, MASK modifiers);
 
 	// Javascript <-> viewer events
-	void jsExposeObjectEvent( bool expose );
-	void jsValuesValidEvent( bool valid );
+	void jsEnableObject( bool enable );
 	void jsAgentLocationEvent( double x, double y, double z );
 	void jsAgentGlobalLocationEvent( double x, double y, double z );
 	void jsAgentOrientationEvent( double angle );
diff --git a/indra/media_plugins/webkit/media_plugin_webkit.cpp b/indra/media_plugins/webkit/media_plugin_webkit.cpp
index 27f3c7260e3..fca071c628e 100644
--- a/indra/media_plugins/webkit/media_plugin_webkit.cpp
+++ b/indra/media_plugins/webkit/media_plugin_webkit.cpp
@@ -1168,19 +1168,11 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
 				authResponse(message_in);
 			}
 			else
-			if(message_name == "js_expose_object")
+			if(message_name == "js_enable_object")
 			{
 #if LLQTWEBKIT_API_VERSION >= 9
-				bool expose_object = message_in.getValueBoolean( "expose" );
-				LLQtWebKit::getInstance()->setExposeObject( expose_object );
-#endif
-			}
-			else
-			if(message_name == "js_values_valid")
-			{
-#if LLQTWEBKIT_API_VERSION >= 9
-				bool valid = message_in.getValueBoolean( "valid" );
-				LLQtWebKit::getInstance()->setValuesValid( valid );
+				bool enable = message_in.getValueBoolean( "enable" );
+				LLQtWebKit::getInstance()->setSLObjectEnabled( enable );
 #endif
 			}
 			else
@@ -1191,6 +1183,7 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
 				F32 y = message_in.getValueReal("y");
 				F32 z = message_in.getValueReal("z");
 				LLQtWebKit::getInstance()->setAgentLocation( x, y, z );
+				LLQtWebKit::getInstance()->emitLocation();
 #endif
 			}
 			else
@@ -1201,6 +1194,7 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
 				F32 y = message_in.getValueReal("y");
 				F32 z = message_in.getValueReal("z");
 				LLQtWebKit::getInstance()->setAgentGlobalLocation( x, y, z );
+				LLQtWebKit::getInstance()->emitLocation();
 #endif
 			}
 			else			
@@ -1209,6 +1203,7 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
 #if LLQTWEBKIT_API_VERSION >= 9
 				F32 angle = message_in.getValueReal("angle");
 				LLQtWebKit::getInstance()->setAgentOrientation( angle );
+				LLQtWebKit::getInstance()->emitLocation();
 #endif
 			}
 			else
@@ -1217,14 +1212,25 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
 #if LLQTWEBKIT_API_VERSION >= 9
 				const std::string& region = message_in.getValue("region");
 				LLQtWebKit::getInstance()->setAgentRegion( region );
+				LLQtWebKit::getInstance()->emitLocation();
 #endif
 			}
 			else
-			if(message_name == "js_agent_maturity")
+				if(message_name == "js_agent_maturity")
+				{
+#if LLQTWEBKIT_API_VERSION >= 9
+					const std::string& maturity = message_in.getValue("maturity");
+					LLQtWebKit::getInstance()->setAgentMaturity( maturity );
+					LLQtWebKit::getInstance()->emitMaturity();
+#endif
+				}
+			else
+			if(message_name == "js_agent_language")
 			{
 #if LLQTWEBKIT_API_VERSION >= 9
-				const std::string& maturity = message_in.getValue("maturity");
-				LLQtWebKit::getInstance()->setAgentMaturity( maturity );
+				const std::string& language = message_in.getValue("language");
+				LLQtWebKit::getInstance()->setAgentLanguage( language );
+				LLQtWebKit::getInstance()->emitLanguage();
 #endif
 			}
 			else
@@ -1384,3 +1390,5 @@ int init_media_plugin(LLPluginInstance::sendMessageFunction host_send_func, void
 
 	return 0;
 }
+
+
diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp
index 1e53274cd6e..b94da4b64cc 100644
--- a/indra/newview/llviewermedia.cpp
+++ b/indra/newview/llviewermedia.cpp
@@ -2349,43 +2349,42 @@ void LLViewerMediaImpl::updateJavascriptObject()
 	if ( mMediaSource )
 	{
 		// flag to expose this information to internal browser or not.
-		bool expose_javascript_object = gSavedSettings.getBOOL("BrowserEnableJSObject");
-		mMediaSource->jsExposeObjectEvent( expose_javascript_object );
+		bool enable = gSavedSettings.getBOOL("BrowserEnableJSObject");
+		mMediaSource->jsEnableObject( enable );
 
-		// indicate if the values we have are valid (currently do this blanket-fashion for
-		// everything depending on whether you are logged in or not - this may require a 
-		// more granular approach once variables are added that ARE valid before login
+		// these values are only menaingful after login so don't set them before
 		bool logged_in = LLLoginInstance::getInstance()->authSuccess();
-		mMediaSource->jsValuesValidEvent( logged_in );
-
-		// current location within a region
-		LLVector3 agent_pos = gAgent.getPositionAgent();
-		double x = agent_pos.mV[ VX ];
-		double y = agent_pos.mV[ VY ];
-		double z = agent_pos.mV[ VZ ];
-		mMediaSource->jsAgentLocationEvent( x, y, z );
-
-		// current location within the grid
-		LLVector3d agent_pos_global = gAgent.getLastPositionGlobal();
-		double global_x = agent_pos_global.mdV[ VX ];
-		double global_y = agent_pos_global.mdV[ VY ];
-		double global_z = agent_pos_global.mdV[ VZ ];
-		mMediaSource->jsAgentGlobalLocationEvent( global_x, global_y, global_z );
-
-		// current agent orientation
-		double rotation = atan2( gAgent.getAtAxis().mV[VX], gAgent.getAtAxis().mV[VY] );
-		double angle = rotation * RAD_TO_DEG;
-		if ( angle < 0.0f ) angle = 360.0f + angle;	// TODO: has to be a better way to get orientation!
-		mMediaSource->jsAgentOrientationEvent( angle );
-
-		// current region agent is in
-		std::string region_name("");
-		LLViewerRegion* region = gAgent.getRegion();
-		if ( region )
-		{
-			region_name = region->getName();
-		};
-		mMediaSource->jsAgentRegionEvent( region_name );
+		if ( logged_in )
+		{
+			// current location within a region
+			LLVector3 agent_pos = gAgent.getPositionAgent();
+			double x = agent_pos.mV[ VX ];
+			double y = agent_pos.mV[ VY ];
+			double z = agent_pos.mV[ VZ ];
+			mMediaSource->jsAgentLocationEvent( x, y, z );
+
+			// current location within the grid
+			LLVector3d agent_pos_global = gAgent.getLastPositionGlobal();
+			double global_x = agent_pos_global.mdV[ VX ];
+			double global_y = agent_pos_global.mdV[ VY ];
+			double global_z = agent_pos_global.mdV[ VZ ];
+			mMediaSource->jsAgentGlobalLocationEvent( global_x, global_y, global_z );
+
+			// current agent orientation
+			double rotation = atan2( gAgent.getAtAxis().mV[VX], gAgent.getAtAxis().mV[VY] );
+			double angle = rotation * RAD_TO_DEG;
+			if ( angle < 0.0f ) angle = 360.0f + angle;	// TODO: has to be a better way to get orientation!
+			mMediaSource->jsAgentOrientationEvent( angle );
+
+			// current region agent is in
+			std::string region_name("");
+			LLViewerRegion* region = gAgent.getRegion();
+			if ( region )
+			{
+				region_name = region->getName();
+			};
+			mMediaSource->jsAgentRegionEvent( region_name );
+		}
 
 		// language code the viewer is set to
 		mMediaSource->jsAgentLanguageEvent( LLUI::getLanguage() );
-- 
GitLab