/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. #include "llviewerprecompiledheaders.h"
  27. #include "llfloatertos.h"
  28. // viewer includes
  29. #include "llviewerstats.h"
  30. #include "llviewerwindow.h"
  31. // linden library includes
  32. #include "llbutton.h"
  33. #include "llevents.h"
  34. #include "llhttpclient.h"
  35. #include "llhttpstatuscodes.h" // for HTTP_FOUND
  36. #include "llnotificationsutil.h"
  37. #include "llradiogroup.h"
  38. #include "lltextbox.h"
  39. #include "llui.h"
  40. #include "lluictrlfactory.h"
  41. #include "llvfile.h"
  42. #include "message.h"
  43. #include "llstartup.h" // login_alert_done
  44. LLFloaterTOS::LLFloaterTOS(const LLSD& data)
  45. : LLModalDialog( data["message"].asString() ),
  46. mMessage(data["message"].asString()),
  47. mWebBrowserWindowId( 0 ),
  48. mLoadingScreenLoaded(false),
  49. mSiteAlive(false),
  50. mRealNavigateBegun(false),
  51. mReplyPumpName(data["reply_pump"].asString())
  52. {
  53. }
  54. // helper class that trys to download a URL from a web site and calls a method
  55. // on parent class indicating if the web server is working or not
  56. class LLIamHere : public LLHTTPClient::Responder
  57. {
  58. private:
  59. LLIamHere( LLFloaterTOS* parent ) :
  60. mParent( parent )
  61. {}
  62. LLFloaterTOS* mParent;
  63. public:
  64. static boost::intrusive_ptr< LLIamHere > build( LLFloaterTOS* parent )
  65. {
  66. return boost::intrusive_ptr< LLIamHere >( new LLIamHere( parent ) );
  67. };
  68. virtual void setParent( LLFloaterTOS* parentIn )
  69. {
  70. mParent = parentIn;
  71. };
  72. virtual void result( const LLSD& content )
  73. {
  74. if ( mParent )
  75. mParent->setSiteIsAlive( true );
  76. };
  77. virtual void error( U32 status, const std::string& reason )
  78. {
  79. if ( mParent )
  80. {
  81. // *HACK: For purposes of this alive check, 302 Found
  82. // (aka Moved Temporarily) is considered alive. The web site
  83. // redirects this link to a "cache busting" temporary URL. JC
  84. bool alive = (status == HTTP_FOUND);
  85. mParent->setSiteIsAlive( alive );
  86. }
  87. };
  88. };
  89. // this is global and not a class member to keep crud out of the header file
  90. namespace {
  91. boost::intrusive_ptr< LLIamHere > gResponsePtr = 0;
  92. };
  93. BOOL LLFloaterTOS::postBuild()
  94. {
  95. childSetAction("Continue", onContinue, this);
  96. childSetAction("Cancel", onCancel, this);
  97. childSetCommitCallback("agree_chk", updateAgree, this);
  98. if (hasChild("tos_text"))
  99. {
  100. // this displays the critical message
  101. LLUICtrl *tos_text = getChild<LLUICtrl>("tos_text");
  102. tos_text->setEnabled( FALSE );
  103. tos_text->setFocus(TRUE);
  104. tos_text->setValue(LLSD(mMessage));
  105. return TRUE;
  106. }
  107. // disable Agree to TOS radio button until the page has fully loaded
  108. LLCheckBoxCtrl* tos_agreement = getChild<LLCheckBoxCtrl>("agree_chk");
  109. tos_agreement->setEnabled( false );
  110. // hide the SL text widget if we're displaying TOS with using a browser widget.
  111. LLUICtrl *editor = getChild<LLUICtrl>("tos_text");
  112. editor->setVisible( FALSE );
  113. LLMediaCtrl* web_browser = getChild<LLMediaCtrl>("tos_html");
  114. if ( web_browser )
  115. {
  116. web_browser->addObserver(this);
  117. // Don't use the start_url parameter for this browser instance -- it may finish loading before we get to add our observer.
  118. // Store the URL separately and navigate here instead.
  119. web_browser->navigateTo( getString( "loading_url" ) );
  120. }
  121. return TRUE;
  122. }
  123. void LLFloaterTOS::setSiteIsAlive( bool alive )
  124. {
  125. mSiteAlive = alive;
  126. // only do this for TOS pages
  127. if (hasChild("tos_html"))
  128. {
  129. // if the contents of the site was retrieved
  130. if ( alive )
  131. {
  132. // navigate to the "real" page
  133. if(!mRealNavigateBegun && mSiteAlive)
  134. {
  135. LLMediaCtrl* web_browser = getChild<LLMediaCtrl>("tos_html");
  136. if(web_browser)
  137. {
  138. mRealNavigateBegun = true;
  139. web_browser->navigateTo( getString( "real_url" ) );
  140. }
  141. }
  142. }
  143. else
  144. {
  145. LL_INFOS("TOS") << "ToS page: ToS page unavailable!" << LL_ENDL;
  146. // normally this is set when navigation to TOS page navigation completes (so you can't accept before TOS loads)
  147. // but if the page is unavailable, we need to do this now
  148. LLCheckBoxCtrl* tos_agreement = getChild<LLCheckBoxCtrl>("agree_chk");
  149. tos_agreement->setEnabled( true );
  150. }
  151. }
  152. }
  153. LLFloaterTOS::~LLFloaterTOS()
  154. {
  155. // tell the responder we're not here anymore
  156. if ( gResponsePtr )
  157. gResponsePtr->setParent( 0 );
  158. }
  159. // virtual
  160. void LLFloaterTOS::draw()
  161. {
  162. // draw children
  163. LLModalDialog::draw();
  164. }
  165. // static
  166. void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata )
  167. {
  168. LLFloaterTOS* self = (LLFloaterTOS*) userdata;
  169. bool agree = self->getChild<LLUICtrl>("agree_chk")->getValue().asBoolean();
  170. self->getChildView("Continue")->setEnabled(agree);
  171. }
  172. // static
  173. void LLFloaterTOS::onContinue( void* userdata )
  174. {
  175. LLFloaterTOS* self = (LLFloaterTOS*) userdata;
  176. LL_INFOS("TOS") << "User agrees with TOS." << LL_ENDL;
  177. if(self->mReplyPumpName != "")
  178. {
  179. LLEventPumps::instance().obtain(self->mReplyPumpName).post(LLSD(true));
  180. }
  181. self->closeFloater(); // destroys this object
  182. }
  183. // static
  184. void LLFloaterTOS::onCancel( void* userdata )
  185. {
  186. LLFloaterTOS* self = (LLFloaterTOS*) userdata;
  187. LL_INFOS("TOS") << "User disagrees with TOS." << LL_ENDL;
  188. LLNotificationsUtil::add("MustAgreeToLogIn", LLSD(), LLSD(), login_alert_done);
  189. if(self->mReplyPumpName != "")
  190. {
  191. LLEventPumps::instance().obtain(self->mReplyPumpName).post(LLSD(false));
  192. }
  193. // reset state for next time we come to TOS
  194. self->mLoadingScreenLoaded = false;
  195. self->mSiteAlive = false;
  196. self->mRealNavigateBegun = false;
  197. // destroys this object
  198. self->closeFloater();
  199. }
  200. //virtual
  201. void LLFloaterTOS::handleMediaEvent(LLPluginClassMedia* /*self*/, EMediaEvent event)
  202. {
  203. if(event == MEDIA_EVENT_NAVIGATE_COMPLETE)
  204. {
  205. if(!mLoadingScreenLoaded)
  206. {
  207. mLoadingScreenLoaded = true;
  208. gResponsePtr = LLIamHere::build( this );
  209. LLHTTPClient::get( getString( "real_url" ), gResponsePtr );
  210. }
  211. else if(mRealNavigateBegun)
  212. {
  213. LL_INFOS("TOS") << "TOS: NAVIGATE COMPLETE" << LL_ENDL;
  214. // enable Agree to TOS radio button now that page has loaded
  215. LLCheckBoxCtrl * tos_agreement = getChild<LLCheckBoxCtrl>("agree_chk");
  216. tos_agreement->setEnabled( true );
  217. }
  218. }
  219. }