llprefsnetwork.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /**
  2. * @file llprefsnetwork.cpp
  3. * @brief Network preferences panel
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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 "cef/dullahan.h" // For CHROME_VERSION_MAJOR
  34. #include "llprefsnetwork.h"
  35. #include "llbutton.h"
  36. #include "llcheckboxctrl.h"
  37. #include "lldir.h"
  38. #include "hbfileselector.h"
  39. #include "llpluginclassmedia.h"
  40. #include "llradiogroup.h"
  41. #include "lluictrlfactory.h"
  42. #include "llappviewer.h" // For isSecondInstanceSiblingViewer()
  43. #include "llgridmanager.h" // For gIsInSecondLife
  44. #include "llstartup.h"
  45. #include "lltexturefetch.h"
  46. #include "llviewercontrol.h"
  47. #include "llviewermedia.h"
  48. #include "llviewerthrottle.h" // For gViewerThrottle.getSettingName()
  49. // Static members
  50. LLPrefsNetwork* LLPrefsNetwork::sInstance = NULL;
  51. bool LLPrefsNetwork::sSocksSettingsChanged = false;
  52. LLPrefsNetwork::LLPrefsNetwork()
  53. {
  54. LLUICtrlFactory* factoryp = LLUICtrlFactory::getInstance();
  55. factoryp->buildPanel(this, "panel_preferences_network.xml");
  56. sInstance = this;
  57. }
  58. //virtual
  59. LLPrefsNetwork::~LLPrefsNetwork()
  60. {
  61. sInstance = NULL;
  62. }
  63. //virtual
  64. bool LLPrefsNetwork::postBuild()
  65. {
  66. bool logged_in_sl = LLStartUp::isLoggedIn() && gIsInSecondLife;
  67. bool logged_in_os = LLStartUp::isLoggedIn() && !gIsInSecondLife;
  68. bool enabled = logged_in_sl ||
  69. gSavedSettings.getBool("ImagePipelineUseHTTP");
  70. // Network connection port, fetch concurrencies and bandwidth
  71. childSetValue("http_texture_fetch", enabled || gIsInSecondLife);
  72. childSetEnabled("http_texture_fetch", !logged_in_sl);
  73. childSetCommitCallback("http_texture_fetch", onHttpTextureFetchToggled,
  74. this);
  75. U32 max_requests =
  76. llclamp(gSavedSettings.getU32("TextureFetchConcurrency"), 2, 32);
  77. childSetValue("max_texture_http_concurrency", (F32)max_requests);
  78. childSetEnabled("max_texture_http_concurrency", enabled);
  79. max_requests =
  80. llclamp(gSavedSettings.getU32("MeshMaxConcurrentRequests"), 2, 128);
  81. childSetValue("max_mesh_http_concurrency", (F32)max_requests);
  82. max_requests =
  83. llclamp(gSavedSettings.getU32("Mesh2MaxConcurrentRequests"), 2, 32);
  84. childSetValue("max_mesh2_http_concurrency", (F32)max_requests);
  85. childSetValue("sl_http_pipelining_check",
  86. gSavedSettings.getBool("HttpPipeliningSL"));
  87. childSetEnabled("sl_http_pipelining_check", !logged_in_os);
  88. childSetValue("os_http_pipelining_check",
  89. gSavedSettings.getBool("HttpPipeliningOS"));
  90. childSetEnabled("os_http_pipelining_check", !logged_in_sl);
  91. enabled = gSavedSettings.getBool("ConnectionPortEnabled");
  92. childSetEnabled("connection_port", enabled);
  93. childSetValue("connection_port_enabled", enabled);
  94. childSetCommitCallback("connection_port_enabled", onCommitPort, this);
  95. const char* bw_name = gViewerThrottle.getSettingName();
  96. childSetValue("max_bandwidth", S32(gSavedSettings.getU32(bw_name)));
  97. childSetValue("connection_port",
  98. (F32)gSavedSettings.getU32("ConnectionPort"));
  99. // Cache settings (disabled when cache writes are disabled).
  100. bool can_write_caches = gAppViewerp &&
  101. !gAppViewerp->isSecondInstanceSiblingViewer();
  102. childSetText("cache_path", gDirUtil.getCacheDir());
  103. childSetEnabled("cache_path", can_write_caches);
  104. childSetAction("clear_disk_cache", onClickClearDiskCache, this);
  105. childSetEnabled("clear_disk_cache", can_write_caches);
  106. mSetCacheButton = getChild<LLButton>("set_cache");
  107. mSetCacheButton->setClickedCallback(onClickSetCache, this);
  108. mSetCacheButton->setEnabled(can_write_caches);
  109. childSetAction("reset_cache", onClickResetCache, this);
  110. childSetEnabled("reset_cache", can_write_caches);
  111. childSetValue("cache_size", (F32)gSavedSettings.getU32("CacheSize"));
  112. childSetEnabled("cache_size", can_write_caches);
  113. // Browser settings
  114. childSetAction("clear_browser_cache", onClickClearBrowserCache, this);
  115. childSetAction("clear_cookies", onClickClearCookies, this);
  116. childSetCommitCallback("web_proxy_enabled", onCommitWebProxyEnabled, this);
  117. std::string value =
  118. gSavedSettings.getBool("UseExternalBrowser") ? "external" : "internal";
  119. childSetValue("use_external_browser", value);
  120. childSetValue("cookies_enabled", gSavedSettings.getBool("CookiesEnabled"));
  121. childSetValue("javascript_enabled",
  122. gSavedSettings.getBool("BrowserJavascriptEnabled"));
  123. // Plugins support has been entirely gutted out from CEF 100
  124. #if CHROME_VERSION_MAJOR < 100
  125. childSetValue("plugins_enabled",
  126. gSavedSettings.getBool("BrowserPluginsEnabled"));
  127. #else
  128. childSetVisible("plugins_enabled", false);
  129. #endif
  130. // Web Proxy settings
  131. enabled = gSavedSettings.getBool("BrowserProxyEnabled");
  132. childSetValue("web_proxy_enabled", enabled);
  133. childSetEnabled("proxy_text_label", enabled);
  134. childSetEnabled("web_proxy_editor", enabled);
  135. childSetEnabled("web_proxy_port", enabled);
  136. childSetEnabled("Web", enabled);
  137. childSetValue("web_proxy_editor",
  138. gSavedSettings.getString("BrowserProxyAddress"));
  139. childSetValue("web_proxy_port", gSavedSettings.getS32("BrowserProxyPort"));
  140. // Socks 5 proxy settings, commit callbacks
  141. childSetCommitCallback("socks5_proxy_enabled", onCommitSocks5ProxyEnabled,
  142. this);
  143. childSetCommitCallback("socks5_auth", onSocksAuthChanged, this);
  144. // Socks 5 proxy settings, saved data
  145. enabled = gSavedSettings.getBool("Socks5ProxyEnabled");
  146. childSetValue("socks5_proxy_enabled", enabled);
  147. childSetValue("socks5_proxy_host",
  148. gSavedSettings.getString("Socks5ProxyHost"));
  149. childSetValue("socks5_proxy_port",
  150. (F32)gSavedSettings.getU32("Socks5ProxyPort"));
  151. childSetValue("socks5_proxy_username",
  152. gSavedSettings.getString("Socks5Username"));
  153. childSetValue("socks5_proxy_password",
  154. gSavedSettings.getString("Socks5Password"));
  155. std::string auth_type = gSavedSettings.getString("Socks5AuthType");
  156. childSetValue("socks5_auth", auth_type);
  157. // Other HTTP connections proxy setting
  158. childSetValue("http_proxy_type",
  159. gSavedSettings.getString("HttpProxyType"));
  160. // Socks 5 proxy settings, check if settings modified callbacks
  161. childSetCommitCallback("socks5_proxy_host", onSocksSettingsModified, this);
  162. childSetCommitCallback("socks5_proxy_port", onSocksSettingsModified, this);
  163. childSetCommitCallback("socks5_proxy_username", onSocksSettingsModified,
  164. this);
  165. childSetCommitCallback("socks5_proxy_password", onSocksSettingsModified,
  166. this);
  167. // Socks 5 settings, Set all controls and labels enabled state
  168. updateProxyEnabled(this, enabled, auth_type);
  169. sSocksSettingsChanged = false;
  170. return true;
  171. }
  172. //virtual
  173. void LLPrefsNetwork::draw()
  174. {
  175. bool can_write_caches = gAppViewerp &&
  176. !gAppViewerp->isSecondInstanceSiblingViewer();
  177. mSetCacheButton->setEnabled(can_write_caches && !HBFileSelector::isInUse());
  178. LLPanel::draw();
  179. }
  180. void sendMediaSettings()
  181. {
  182. LLViewerMedia::setCookiesEnabled(gSavedSettings.getBool("CookiesEnabled"));
  183. LLViewerMedia::setProxyConfig(gSavedSettings.getBool("BrowserProxyEnabled"),
  184. gSavedSettings.getString("BrowserProxyAddress"),
  185. gSavedSettings.getS32("BrowserProxyPort"));
  186. }
  187. void LLPrefsNetwork::apply()
  188. {
  189. if (!gIsInSecondLife || !LLStartUp::isLoggedIn())
  190. {
  191. gSavedSettings.setBool("ImagePipelineUseHTTP",
  192. childGetValue("http_texture_fetch"));
  193. }
  194. gSavedSettings.setU32("TextureFetchConcurrency",
  195. childGetValue("max_texture_http_concurrency").asInteger());
  196. gSavedSettings.setU32("MeshMaxConcurrentRequests",
  197. childGetValue("max_mesh_http_concurrency").asInteger());
  198. gSavedSettings.setU32("Mesh2MaxConcurrentRequests",
  199. childGetValue("max_mesh2_http_concurrency").asInteger());
  200. gSavedSettings.setBool("HttpPipeliningSL",
  201. childGetValue("sl_http_pipelining_check"));
  202. gSavedSettings.setBool("HttpPipeliningOS",
  203. childGetValue("os_http_pipelining_check"));
  204. U32 cache_size = (U32)childGetValue("cache_size").asInteger();
  205. if (gSavedSettings.getU32("CacheSize") != cache_size)
  206. {
  207. onClickClearDiskCache(this);
  208. gSavedSettings.setU32("CacheSize", cache_size);
  209. }
  210. U32 bw = childGetValue("max_bandwidth").asInteger();
  211. if (!gIsInSecondLife && bw > 1024)
  212. {
  213. gNotifications.add("OpenSimUDPBandwithLimit");
  214. }
  215. gSavedSettings.setU32(gViewerThrottle.getSettingName(), bw);
  216. gSavedSettings.setBool("ConnectionPortEnabled",
  217. childGetValue("connection_port_enabled"));
  218. gSavedSettings.setU32("ConnectionPort",
  219. childGetValue("connection_port").asInteger());
  220. gSavedSettings.setBool("Socks5ProxyEnabled",
  221. childGetValue("socks5_proxy_enabled"));
  222. gSavedSettings.setString("Socks5ProxyHost",
  223. childGetValue("socks5_proxy_host"));
  224. gSavedSettings.setU32("Socks5ProxyPort",
  225. childGetValue("socks5_proxy_port").asInteger());
  226. gSavedSettings.setString("Socks5AuthType",
  227. childGetValue("socks5_auth"));
  228. gSavedSettings.setString("Socks5Username",
  229. childGetValue("socks5_proxy_username"));
  230. gSavedSettings.setString("Socks5Password",
  231. childGetValue("socks5_proxy_password"));
  232. gSavedSettings.setBool("CookiesEnabled",
  233. childGetValue("cookies_enabled"));
  234. gSavedSettings.setBool("BrowserJavascriptEnabled",
  235. childGetValue("javascript_enabled"));
  236. #if CHROME_VERSION_MAJOR < 100
  237. gSavedSettings.setBool("BrowserPluginsEnabled",
  238. childGetValue("plugins_enabled"));
  239. #endif
  240. gSavedSettings.setBool("BrowserProxyEnabled",
  241. childGetValue("web_proxy_enabled"));
  242. gSavedSettings.setString("BrowserProxyAddress",
  243. childGetValue("web_proxy_editor"));
  244. gSavedSettings.setS32("BrowserProxyPort",
  245. childGetValue("web_proxy_port"));
  246. gSavedSettings.setString("HttpProxyType",
  247. childGetValue("http_proxy_type"));
  248. bool value =
  249. childGetValue("use_external_browser").asString() == "external";
  250. gSavedSettings.setBool("UseExternalBrowser", value);
  251. sendMediaSettings();
  252. if (sSocksSettingsChanged &&
  253. LLStartUp::getStartupState() != STATE_LOGIN_WAIT)
  254. {
  255. gNotifications.add("ProxyNeedRestart");
  256. sSocksSettingsChanged = false;
  257. }
  258. }
  259. void LLPrefsNetwork::cancel()
  260. {
  261. sendMediaSettings();
  262. }
  263. // static
  264. void LLPrefsNetwork::onHttpTextureFetchToggled(LLUICtrl* ctrl, void* data)
  265. {
  266. LLPrefsNetwork* self = (LLPrefsNetwork*)data;
  267. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  268. if (self && check)
  269. {
  270. self->childSetEnabled("max_texture_http_concurrency", check->get());
  271. }
  272. }
  273. // static
  274. void LLPrefsNetwork::onClickClearDiskCache(void*)
  275. {
  276. // Flag client cache for clearing next time the client runs
  277. gSavedSettings.setBool("PurgeCacheOnNextStartup", true);
  278. gNotifications.add("CachesWillClear");
  279. }
  280. // static
  281. void LLPrefsNetwork::setCacheCallback(std::string& dir_name, void* data)
  282. {
  283. LLPrefsNetwork* self = (LLPrefsNetwork*)data;
  284. if (!self || self != sInstance)
  285. {
  286. gNotifications.add("PreferencesClosed");
  287. return;
  288. }
  289. std::string cur_name = gSavedSettings.getString("CacheLocation");
  290. if (!dir_name.empty() && dir_name != cur_name)
  291. {
  292. self->childSetText("cache_path", dir_name);
  293. gNotifications.add("CacheWillBeMoved");
  294. gSavedSettings.setString("NewCacheLocation", dir_name);
  295. }
  296. }
  297. // static
  298. void LLPrefsNetwork::onClickSetCache(void* data)
  299. {
  300. std::string suggestion = gDirUtil.getFullPath(LL_PATH_CACHE);
  301. HBFileSelector::pickDirectory(suggestion, setCacheCallback, data);
  302. }
  303. // static
  304. void LLPrefsNetwork::onClickResetCache(void* data)
  305. {
  306. LLPrefsNetwork* self = (LLPrefsNetwork*)data;
  307. if (!gSavedSettings.getString("CacheLocation").empty())
  308. {
  309. gSavedSettings.setString("NewCacheLocation", "");
  310. gNotifications.add("CacheWillBeMoved");
  311. }
  312. self->childSetText("cache_path", gDirUtil.getCacheDir(true));
  313. }
  314. // static
  315. void LLPrefsNetwork::onCommitPort(LLUICtrl* ctrl, void* data)
  316. {
  317. LLPrefsNetwork* self = (LLPrefsNetwork*)data;
  318. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  319. if (!self || !check) return;
  320. self->childSetEnabled("connection_port", check->get());
  321. gNotifications.add("ChangeConnectionPort");
  322. }
  323. // static
  324. void LLPrefsNetwork::onCommitSocks5ProxyEnabled(LLUICtrl* ctrl, void* data)
  325. {
  326. LLPrefsNetwork* self = (LLPrefsNetwork*)data;
  327. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  328. if (!self || !check) return;
  329. sSocksSettingsChanged = true;
  330. updateProxyEnabled(self, check->get(), self->childGetValue("socks5_auth"));
  331. }
  332. // static
  333. void LLPrefsNetwork::onSocksSettingsModified(LLUICtrl* ctrl, void* data)
  334. {
  335. sSocksSettingsChanged = true;
  336. }
  337. // static
  338. void LLPrefsNetwork::onSocksAuthChanged(LLUICtrl* ctrl, void* data)
  339. {
  340. LLRadioGroup* radio = static_cast<LLRadioGroup*>(ctrl);
  341. LLPrefsNetwork* self = static_cast<LLPrefsNetwork*>(data);
  342. sSocksSettingsChanged = true;
  343. std::string selection = radio->getValue().asString();
  344. updateProxyEnabled(self, self->childGetValue("socks5_proxy_enabled"),
  345. selection);
  346. }
  347. // static
  348. void LLPrefsNetwork::updateProxyEnabled(LLPrefsNetwork* self, bool enabled,
  349. std::string authtype)
  350. {
  351. // Manage all the enable/disable of the socks5 options from this single function
  352. // to avoid code duplication
  353. // Update all socks labels and controls except auth specific ones
  354. self->childSetEnabled("socks5_proxy_port", enabled);
  355. self->childSetEnabled("socks5_proxy_host", enabled);
  356. self->childSetEnabled("socks5_host_label", enabled);
  357. self->childSetEnabled("socks5_proxy_port", enabled);
  358. self->childSetEnabled("socks5_auth", enabled);
  359. if (!enabled && self->childGetValue("http_proxy_type").asString() == "Socks")
  360. {
  361. self->childSetValue("http_proxy_type", "None");
  362. }
  363. self->childSetEnabled("Socks", enabled);
  364. // Hide the auth specific lables if authtype is none or
  365. // we are not enabled.
  366. if (!enabled || authtype.compare("None") == 0)
  367. {
  368. self->childSetEnabled("socks5_username_label", false);
  369. self->childSetEnabled("socks5_password_label", false);
  370. self->childSetEnabled("socks5_proxy_username", false);
  371. self->childSetEnabled("socks5_proxy_password", false);
  372. }
  373. // Only show the username and password boxes if we are enabled
  374. // and authtype is username pasword.
  375. if (enabled && authtype.compare("UserPass") == 0)
  376. {
  377. self->childSetEnabled("socks5_username_label", true);
  378. self->childSetEnabled("socks5_password_label", true);
  379. self->childSetEnabled("socks5_proxy_username", true);
  380. self->childSetEnabled("socks5_proxy_password", true);
  381. }
  382. }
  383. // static
  384. void LLPrefsNetwork::onClickClearBrowserCache(void*)
  385. {
  386. gNotifications.add("ConfirmClearBrowserCache", LLSD(), LLSD(),
  387. callback_clear_browser_cache);
  388. }
  389. //static
  390. bool LLPrefsNetwork::callback_clear_browser_cache(const LLSD& notification,
  391. const LLSD& response)
  392. {
  393. if (LLNotification::getSelectedOption(notification, response) == 0) // YES
  394. {
  395. LLViewerMedia::clearAllCaches();
  396. }
  397. return false;
  398. }
  399. // static
  400. void LLPrefsNetwork::onClickClearCookies(void*)
  401. {
  402. gNotifications.add("ConfirmClearCookies", LLSD(), LLSD(),
  403. callback_clear_cookies);
  404. }
  405. //static
  406. bool LLPrefsNetwork::callback_clear_cookies(const LLSD& notification,
  407. const LLSD& response)
  408. {
  409. if (LLNotification::getSelectedOption(notification, response) == 0) // YES
  410. {
  411. LLViewerMedia::clearAllCookies();
  412. }
  413. return false;
  414. }
  415. // static
  416. void LLPrefsNetwork::onCommitWebProxyEnabled(LLUICtrl* ctrl, void* data)
  417. {
  418. LLPrefsNetwork* self = (LLPrefsNetwork*)data;
  419. LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
  420. if (!self || !check) return;
  421. bool enabled = check->get();
  422. self->childSetEnabled("web_proxy_editor", enabled);
  423. self->childSetEnabled("web_proxy_port", enabled);
  424. self->childSetEnabled("proxy_text_label", enabled);
  425. self->childSetEnabled("Web", enabled);
  426. if (!enabled && self->childGetValue("http_proxy_type").asString() == "Web")
  427. {
  428. self->childSetValue("http_proxy_type", "None");
  429. }
  430. }