llfloatertos.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**
  2. * @file llfloatertos.cpp
  3. * @brief Terms of Service Agreement dialog
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloatertos.h"
  34. #include "llbutton.h"
  35. #include "llcheckboxctrl.h"
  36. #include "llcorehttputil.h"
  37. #include "lluictrlfactory.h"
  38. #include "llappviewer.h"
  39. #include "llstartup.h"
  40. #include "llviewercontrol.h"
  41. #include "llviewertexteditor.h"
  42. // static
  43. LLFloaterTOS* LLFloaterTOS::sInstance = NULL;
  44. //static
  45. LLFloaterTOS* LLFloaterTOS::show(ETOSType type, const std::string& message,
  46. bool start_modal)
  47. {
  48. if (sInstance &&
  49. (sInstance->mType != type || sInstance->mMessage != message))
  50. {
  51. sInstance->close();
  52. }
  53. if (!sInstance)
  54. {
  55. sInstance = new LLFloaterTOS(type, message);
  56. if (type != TOS_CRITICAL_MESSAGE)
  57. {
  58. LLUICtrlFactory::getInstance()->buildFloater(sInstance,
  59. "floater_tos.xml");
  60. }
  61. else
  62. {
  63. LLUICtrlFactory::getInstance()->buildFloater(sInstance,
  64. "floater_critical.xml");
  65. }
  66. }
  67. if (sInstance && start_modal)
  68. {
  69. sInstance->startModal();
  70. }
  71. return sInstance;
  72. }
  73. LLFloaterTOS::LLFloaterTOS(ETOSType type, const std::string& message)
  74. : LLModalDialog(std::string(" "), 100, 100),
  75. mType(type),
  76. mMessage(message),
  77. mAgreeCheck(NULL),
  78. mWebBrowser(NULL),
  79. mLoadingScreenLoaded(false),
  80. mSiteAlive(false),
  81. mRealNavigateBegun(false)
  82. {
  83. sInstance = this;
  84. }
  85. LLFloaterTOS::~LLFloaterTOS()
  86. {
  87. sInstance = NULL;
  88. }
  89. bool LLFloaterTOS::postBuild()
  90. {
  91. mContinueButton = getChild<LLButton>("Continue");
  92. mContinueButton->setClickedCallback(onContinue, this);
  93. childSetAction("Cancel", onCancel, this);
  94. LLTextEditor* editor = getChild<LLTextEditor>("tos_text");
  95. if (mType == TOS_CRITICAL_MESSAGE)
  96. {
  97. // this displays the critical message
  98. editor->setHandleEditKeysDirectly(true);
  99. editor->setEnabled(false);
  100. editor->setWordWrap(true);
  101. editor->setFocus(true);
  102. editor->setValue(LLSD(mMessage));
  103. return true;
  104. }
  105. // hide the SL text widget if we're displaying TOS with using a browser
  106. // widget.
  107. editor->setVisible(false);
  108. mAgreeCheck = getChild<LLCheckBoxCtrl>("agree_chk");
  109. mAgreeCheck->setCommitCallback(updateAgree);
  110. mAgreeCheck->setCallbackUserData(this);
  111. // If type TOS disable Agree to TOS radio button until the page has fully
  112. // loaded, else enable it.
  113. mAgreeCheck->setEnabled(mType != TOS_TOS);
  114. mWebBrowser = getChild<LLMediaCtrl>("tos_html");
  115. if (mType == TOS_TOS)
  116. {
  117. // start to observe it so we see navigate complete events
  118. mWebBrowser->addObserver(this);
  119. // Don't use the real_url parameter for this browser instance: it
  120. // may finish loading before we get to add our observer. Store the
  121. // URL separately and navigate here instead.
  122. mWebBrowser->navigateTo(getString("loading_url"));
  123. }
  124. else
  125. {
  126. mWebBrowser->navigateToLocalPage("tpv", "tpv.html");
  127. }
  128. #if 1
  129. LLPluginClassMedia* media_plugin = mWebBrowser->getMediaPlugin();
  130. if (media_plugin)
  131. {
  132. // All links should be opened in external browser
  133. media_plugin->setOverrideClickTarget("_external");
  134. }
  135. #endif
  136. return true;
  137. }
  138. void LLFloaterTOS::setSiteIsAlive(bool alive)
  139. {
  140. mSiteAlive = alive;
  141. // only do this for TOS pages
  142. if (mType == TOS_TOS)
  143. {
  144. // if the contents of the site was retrieved
  145. if (alive)
  146. {
  147. if (mWebBrowser && mSiteAlive && !mRealNavigateBegun)
  148. {
  149. // navigate to the "real" page
  150. mRealNavigateBegun = true;
  151. mWebBrowser->navigateTo(getString("real_url"));
  152. }
  153. }
  154. else if (mAgreeCheck)
  155. {
  156. // normally this is set when navigation to TOS page navigation
  157. // completes (so you can't accept before TOS loads) but if the
  158. // page is unavailable, we need to do this now
  159. mAgreeCheck->setEnabled(true);
  160. }
  161. }
  162. }
  163. // virtual
  164. void LLFloaterTOS::draw()
  165. {
  166. // draw children
  167. LLModalDialog::draw();
  168. }
  169. //virtual
  170. void LLFloaterTOS::handleMediaEvent(LLPluginClassMedia*, EMediaEvent event)
  171. {
  172. if (event == MEDIA_EVENT_NAVIGATE_COMPLETE)
  173. {
  174. // skip past the loading screen navigate complete
  175. if (!mLoadingScreenLoaded)
  176. {
  177. mLoadingScreenLoaded = true;
  178. if (mType == TOS_TOS)
  179. {
  180. gCoros.launch("LLFloaterTOS::testSiteIsAliveCoro",
  181. boost::bind(&LLFloaterTOS::testSiteIsAliveCoro,
  182. getHandle(), getString("real_url")));
  183. }
  184. }
  185. else if (mRealNavigateBegun && mAgreeCheck)
  186. {
  187. llinfos << "Navigate complete" << llendl;
  188. // enable Agree to TOS radio button now that page has loaded
  189. mAgreeCheck->setEnabled(true);
  190. }
  191. }
  192. }
  193. //static
  194. void LLFloaterTOS::testSiteIsAliveCoro(LLHandle<LLFloater> handle,
  195. const std::string& url)
  196. {
  197. if (handle.isDead())
  198. {
  199. return; // Floater gone. Ignore and bail out silently.
  200. }
  201. LLCore::HttpOptions::ptr_t options(new LLCore::HttpOptions);
  202. options->setHeadersOnly(true);
  203. LLCoreHttpUtil::HttpCoroutineAdapter adapter("testSiteIsAliveCoro");
  204. LLSD result = adapter.getAndSuspend(url, options);
  205. LLFloaterTOS* self = handle.isDead() ? NULL
  206. : dynamic_cast<LLFloaterTOS*>(handle.get());
  207. if (!self)
  208. {
  209. llwarns << "Dialog canceled before response." << llendl;
  210. return;
  211. }
  212. LLCore::HttpStatus status =
  213. LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(result);
  214. sInstance->setSiteIsAlive(bool(status));
  215. }
  216. // static
  217. void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata)
  218. {
  219. LLFloaterTOS* self = (LLFloaterTOS*)userdata;
  220. if (self && self->mAgreeCheck)
  221. {
  222. self->mContinueButton->setEnabled(self->mAgreeCheck->get());
  223. }
  224. }
  225. // static
  226. void LLFloaterTOS::onContinue(void* userdata)
  227. {
  228. LLFloaterTOS* self = (LLFloaterTOS*)userdata;
  229. if (!self) return;
  230. llinfos << "User agrees with TOS." << llendl;
  231. if (self->mType == TOS_TOS)
  232. {
  233. gAcceptTOS = true;
  234. }
  235. else if (self->mType == TOS_CRITICAL_MESSAGE)
  236. {
  237. gAcceptCriticalMessage = true;
  238. }
  239. else
  240. {
  241. gSavedSettings.setBool("FirstRunTPV", false);
  242. LLStartUp::setStartupState(STATE_LOGIN_WAIT);
  243. self->close(); // Destroys this object
  244. return;
  245. }
  246. // Go back and finish authentication
  247. LLStartUp::setStartupState(STATE_LOGIN_AUTH_INIT);
  248. self->close(); // Destroys this object
  249. }
  250. // static
  251. void LLFloaterTOS::onCancel(void* userdata)
  252. {
  253. LLFloaterTOS* self = (LLFloaterTOS*)userdata;
  254. if (!self) return;
  255. llinfos << "User disagrees with TOS." << llendl;
  256. gNotifications.add("MustAgreeToLogIn", LLSD(), LLSD(),
  257. LLStartUp::loginAlertDone);
  258. if (self->mType == TOS_FIRST_TPV_USE)
  259. {
  260. LLStartUp::setStartupState(STATE_LOGIN_WAIT);
  261. gAppViewerp->forceQuit();
  262. }
  263. else
  264. {
  265. LLStartUp::setStartupState(STATE_LOGIN_SHOW);
  266. }
  267. // reset state for next time we come to TOS
  268. self->mLoadingScreenLoaded = false;
  269. self->mSiteAlive = false;
  270. self->mRealNavigateBegun = false;
  271. self->close(); // destroys this object
  272. }