PageRenderTime 104ms CodeModel.GetById 40ms app.highlight 31ms RepoModel.GetById 29ms app.codeStats 1ms

/indra/newview/llfloatertos.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 256 lines | 166 code | 37 blank | 53 comment | 20 complexity | 58fdb81686402fc01f2105864815b8a0 MD5 | raw file
  1/** 
  2 * @file llfloatertos.cpp
  3 * @brief Terms of Service Agreement dialog
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llfloatertos.h"
 30
 31// viewer includes
 32#include "llviewerstats.h"
 33#include "llviewerwindow.h"
 34
 35// linden library includes
 36#include "llbutton.h"
 37#include "llevents.h"
 38#include "llhttpclient.h"
 39#include "llhttpstatuscodes.h"	// for HTTP_FOUND
 40#include "llnotificationsutil.h"
 41#include "llradiogroup.h"
 42#include "lltextbox.h"
 43#include "llui.h"
 44#include "lluictrlfactory.h"
 45#include "llvfile.h"
 46#include "message.h"
 47#include "llstartup.h"              // login_alert_done
 48
 49
 50LLFloaterTOS::LLFloaterTOS(const LLSD& data)
 51:	LLModalDialog( data["message"].asString() ),
 52	mMessage(data["message"].asString()),
 53	mWebBrowserWindowId( 0 ),
 54	mLoadingScreenLoaded(false),
 55	mSiteAlive(false),
 56	mRealNavigateBegun(false),
 57	mReplyPumpName(data["reply_pump"].asString())
 58{
 59}
 60
 61// helper class that trys to download a URL from a web site and calls a method 
 62// on parent class indicating if the web server is working or not
 63class LLIamHere : public LLHTTPClient::Responder
 64{
 65	private:
 66		LLIamHere( LLFloaterTOS* parent ) :
 67		   mParent( parent )
 68		{}
 69
 70		LLFloaterTOS* mParent;
 71
 72	public:
 73
 74		static boost::intrusive_ptr< LLIamHere > build( LLFloaterTOS* parent )
 75		{
 76			return boost::intrusive_ptr< LLIamHere >( new LLIamHere( parent ) );
 77		};
 78		
 79		virtual void  setParent( LLFloaterTOS* parentIn )
 80		{
 81			mParent = parentIn;
 82		};
 83		
 84		virtual void result( const LLSD& content )
 85		{
 86			if ( mParent )
 87				mParent->setSiteIsAlive( true );
 88		};
 89
 90		virtual void error( U32 status, const std::string& reason )
 91		{
 92			if ( mParent )
 93			{
 94				// *HACK: For purposes of this alive check, 302 Found
 95				// (aka Moved Temporarily) is considered alive.  The web site
 96				// redirects this link to a "cache busting" temporary URL. JC
 97				bool alive = (status == HTTP_FOUND);
 98				mParent->setSiteIsAlive( alive );
 99			}
100		};
101};
102
103// this is global and not a class member to keep crud out of the header file
104namespace {
105	boost::intrusive_ptr< LLIamHere > gResponsePtr = 0;
106};
107
108BOOL LLFloaterTOS::postBuild()
109{	
110	childSetAction("Continue", onContinue, this);
111	childSetAction("Cancel", onCancel, this);
112	childSetCommitCallback("agree_chk", updateAgree, this);
113	
114	if (hasChild("tos_text"))
115	{
116		// this displays the critical message
117		LLUICtrl *tos_text = getChild<LLUICtrl>("tos_text");
118		tos_text->setEnabled( FALSE );
119		tos_text->setFocus(TRUE);
120		tos_text->setValue(LLSD(mMessage));
121
122		return TRUE;
123	}
124
125	// disable Agree to TOS radio button until the page has fully loaded
126	LLCheckBoxCtrl* tos_agreement = getChild<LLCheckBoxCtrl>("agree_chk");
127	tos_agreement->setEnabled( false );
128
129	// hide the SL text widget if we're displaying TOS with using a browser widget.
130	LLUICtrl *editor = getChild<LLUICtrl>("tos_text");
131	editor->setVisible( FALSE );
132
133	LLMediaCtrl* web_browser = getChild<LLMediaCtrl>("tos_html");
134	if ( web_browser )
135	{
136		web_browser->addObserver(this);
137
138		// Don't use the start_url parameter for this browser instance -- it may finish loading before we get to add our observer.
139		// Store the URL separately and navigate here instead.
140		web_browser->navigateTo( getString( "loading_url" ) );
141	}
142
143	return TRUE;
144}
145
146void LLFloaterTOS::setSiteIsAlive( bool alive )
147{
148	mSiteAlive = alive;
149	
150	// only do this for TOS pages
151	if (hasChild("tos_html"))
152	{
153		// if the contents of the site was retrieved
154		if ( alive )
155		{
156			// navigate to the "real" page 
157			if(!mRealNavigateBegun && mSiteAlive)
158			{
159				LLMediaCtrl* web_browser = getChild<LLMediaCtrl>("tos_html");
160				if(web_browser)
161				{
162					mRealNavigateBegun = true;
163					web_browser->navigateTo( getString( "real_url" ) );
164				}
165			}
166		}
167		else
168		{
169			LL_INFOS("TOS") << "ToS page: ToS page unavailable!" << LL_ENDL;
170			// normally this is set when navigation to TOS page navigation completes (so you can't accept before TOS loads)
171			// but if the page is unavailable, we need to do this now
172			LLCheckBoxCtrl* tos_agreement = getChild<LLCheckBoxCtrl>("agree_chk");
173			tos_agreement->setEnabled( true );
174		}
175	}
176}
177
178LLFloaterTOS::~LLFloaterTOS()
179{
180	// tell the responder we're not here anymore
181	if ( gResponsePtr )
182		gResponsePtr->setParent( 0 );
183}
184
185// virtual
186void LLFloaterTOS::draw()
187{
188	// draw children
189	LLModalDialog::draw();
190}
191
192// static
193void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata )
194{
195	LLFloaterTOS* self = (LLFloaterTOS*) userdata;
196	bool agree = self->getChild<LLUICtrl>("agree_chk")->getValue().asBoolean(); 
197	self->getChildView("Continue")->setEnabled(agree);
198}
199
200// static
201void LLFloaterTOS::onContinue( void* userdata )
202{
203	LLFloaterTOS* self = (LLFloaterTOS*) userdata;
204	LL_INFOS("TOS") << "User agrees with TOS." << LL_ENDL;
205
206	if(self->mReplyPumpName != "")
207	{
208		LLEventPumps::instance().obtain(self->mReplyPumpName).post(LLSD(true));
209	}
210
211	self->closeFloater(); // destroys this object
212}
213
214// static
215void LLFloaterTOS::onCancel( void* userdata )
216{
217	LLFloaterTOS* self = (LLFloaterTOS*) userdata;
218	LL_INFOS("TOS") << "User disagrees with TOS." << LL_ENDL;
219	LLNotificationsUtil::add("MustAgreeToLogIn", LLSD(), LLSD(), login_alert_done);
220
221	if(self->mReplyPumpName != "")
222	{
223		LLEventPumps::instance().obtain(self->mReplyPumpName).post(LLSD(false));
224	}
225
226	// reset state for next time we come to TOS
227	self->mLoadingScreenLoaded = false;
228	self->mSiteAlive = false;
229	self->mRealNavigateBegun = false;
230	
231	// destroys this object
232	self->closeFloater(); 
233}
234
235//virtual 
236void LLFloaterTOS::handleMediaEvent(LLPluginClassMedia* /*self*/, EMediaEvent event)
237{
238	if(event == MEDIA_EVENT_NAVIGATE_COMPLETE)
239	{
240		if(!mLoadingScreenLoaded)
241		{
242			mLoadingScreenLoaded = true;
243
244			gResponsePtr = LLIamHere::build( this );
245			LLHTTPClient::get( getString( "real_url" ), gResponsePtr );
246		}
247		else if(mRealNavigateBegun)
248		{
249			LL_INFOS("TOS") << "TOS: NAVIGATE COMPLETE" << LL_ENDL;
250			// enable Agree to TOS radio button now that page has loaded
251			LLCheckBoxCtrl * tos_agreement = getChild<LLCheckBoxCtrl>("agree_chk");
252			tos_agreement->setEnabled( true );
253		}
254	}
255}
256