diff options
Diffstat (limited to 'linden/indra/newview/llpanelweb.cpp')
-rw-r--r-- | linden/indra/newview/llpanelweb.cpp | 368 |
1 files changed, 75 insertions, 293 deletions
diff --git a/linden/indra/newview/llpanelweb.cpp b/linden/indra/newview/llpanelweb.cpp index e1e4247..5b0b7e6 100644 --- a/linden/indra/newview/llpanelweb.cpp +++ b/linden/indra/newview/llpanelweb.cpp | |||
@@ -1,8 +1,8 @@ | |||
1 | /** | 1 | /** |
2 | * @file llpanelweb.cpp | 2 | * @file LLPanelWeb.cpp |
3 | * @brief Web browser options | 3 | * @brief Network preferences panel |
4 | * | 4 | * |
5 | * Copyright (c) 2003-2007, Linden Research, Inc. | 5 | * Copyright (c) 2001-2007, Linden Research, Inc. |
6 | * | 6 | * |
7 | * Second Life Viewer Source Code | 7 | * Second Life Viewer Source Code |
8 | * The source code in this file ("Source Code") is provided by Linden Lab | 8 | * The source code in this file ("Source Code") is provided by Linden Lab |
@@ -28,345 +28,127 @@ | |||
28 | 28 | ||
29 | #include "llviewerprecompiledheaders.h" | 29 | #include "llviewerprecompiledheaders.h" |
30 | 30 | ||
31 | // file include | ||
31 | #include "llpanelweb.h" | 32 | #include "llpanelweb.h" |
32 | 33 | ||
34 | // linden library includes | ||
35 | #include "llerror.h" | ||
36 | #include "llrect.h" | ||
37 | #include "llstring.h" | ||
38 | |||
39 | // project includes | ||
33 | #include "llbutton.h" | 40 | #include "llbutton.h" |
34 | #include "llscrolllistctrl.h" | 41 | #include "llui.h" |
42 | #include "lluictrlfactory.h" | ||
35 | #include "llcheckboxctrl.h" | 43 | #include "llcheckboxctrl.h" |
36 | #include "llradiogroup.h" | ||
37 | #include "lllineeditor.h" | ||
38 | #include "llfirstuse.h" | ||
39 | #include "llviewercontrol.h" | 44 | #include "llviewercontrol.h" |
40 | #include "llmediaengine.h" | ||
41 | #include "llstartup.h" | ||
42 | #include "llurlwhitelist.h" | ||
43 | #include "llvieweruictrlfactory.h" | 45 | #include "llvieweruictrlfactory.h" |
46 | #include "llviewerwindow.h" | ||
47 | |||
48 | #if LL_LIBXUL_ENABLED | ||
49 | #include "llmozlib.h" | ||
50 | #endif // LL_LIBXUL_ENABLED | ||
44 | 51 | ||
45 | LLPanelWeb::LLPanelWeb() | 52 | LLPanelWeb::LLPanelWeb() |
46 | : LLPanel("Web Panel"), | ||
47 | mExternalBrowserCheck(NULL), | ||
48 | mBrowserHomePage(NULL), | ||
49 | mWebPagesOnPrimsCheck(NULL), | ||
50 | mTrustedSitesList(NULL), | ||
51 | mProxyEnabled(NULL), | ||
52 | mProxyAddress(NULL), | ||
53 | mProxyPort(NULL), | ||
54 | mProxySocks45(NULL), | ||
55 | mProxyExclusions(NULL), | ||
56 | mAddTrustedSite(NULL), | ||
57 | mTrustedSiteEntry(NULL), | ||
58 | mRemTrustedSite(NULL) | ||
59 | { | 53 | { |
60 | mLoggedIn = ( gStartupState >= STATE_STARTED ); | 54 | gUICtrlFactory->buildPanel(this, "panel_preferences_web.xml"); |
61 | } | 55 | } |
62 | 56 | ||
63 | //----------------------------------------------------------------------------- | ||
64 | // postBuild() | ||
65 | //----------------------------------------------------------------------------- | ||
66 | BOOL LLPanelWeb::postBuild() | 57 | BOOL LLPanelWeb::postBuild() |
67 | { | 58 | { |
68 | mExternalBrowserCheck = LLViewerUICtrlFactory::getCheckBoxByName(this, "external_browser_check"); | 59 | childSetAction( "clear_cache", onClickClearCache, this ); |
69 | mExternalBrowserCheck->setCallbackUserData ( this ); | 60 | childSetAction( "clear_cookies", onClickClearCookies, this ); |
70 | mExternalBrowserCheck->setCommitCallback ( onCommitExternalBrowser ); | 61 | childSetEnabled( "connection_port", gSavedSettings.getBOOL( "CookiesEnabled" ) ); |
71 | 62 | childSetCommitCallback( "cookies_enabled", onCommitCookies, this ); | |
72 | mWebPagesOnPrimsCheck = LLViewerUICtrlFactory::getCheckBoxByName(this, "web_pages_on_prims_check"); | ||
73 | |||
74 | mBrowserHomePage = LLViewerUICtrlFactory::getLineEditorByName(this, "home_page"); | ||
75 | |||
76 | mProxyEnabled = LLViewerUICtrlFactory::getCheckBoxByName(this, "proxy_enabled"); | ||
77 | mProxyEnabled->setCallbackUserData ( this ); | ||
78 | mProxyEnabled->setCommitCallback ( onCommitProxyEnabled ); | ||
79 | mProxyAddress = LLViewerUICtrlFactory::getLineEditorByName(this, "proxy_address"); | ||
80 | mProxyPort = LLViewerUICtrlFactory::getLineEditorByName(this, "proxy_port"); | ||
81 | mProxySocks45 = LLViewerUICtrlFactory::getRadioGroupByName(this, "socks_4_5"); | ||
82 | mProxyExclusions = LLViewerUICtrlFactory::getLineEditorByName(this, "proxy_exclusions"); | ||
83 | |||
84 | mAddTrustedSite = LLViewerUICtrlFactory::getButtonByName(this, "add_trusted"); | ||
85 | mAddTrustedSite->setEnabled ( FALSE ); | ||
86 | mAddTrustedSite->setCallbackUserData ( this ); | ||
87 | mAddTrustedSite->setClickedCallback ( onAddTrustedSite ); | ||
88 | |||
89 | mTrustedSitesList = LLViewerUICtrlFactory::getScrollListByName(this, "trusted_sites_list"); | ||
90 | mTrustedSitesList->setAllowMultipleSelection ( TRUE ); | ||
91 | mTrustedSitesList->setCommitOnSelectionChange ( TRUE ); | ||
92 | mTrustedSitesList->setCallbackUserData ( this ); | ||
93 | mTrustedSitesList->setCommitCallback ( onTrustedSiteListCommit ); | ||
94 | |||
95 | mTrustedSiteEntry = LLViewerUICtrlFactory::getLineEditorByName(this, "trusted_site_entry"); | ||
96 | mTrustedSiteEntry->setCallbackUserData ( this ); | ||
97 | mTrustedSiteEntry->setKeystrokeCallback ( onTrustedSiteEntryKeystroke ); | ||
98 | |||
99 | mRemTrustedSite = LLViewerUICtrlFactory::getButtonByName(this, "rem_trusted"); | ||
100 | mRemTrustedSite->setEnabled ( FALSE ); | ||
101 | mRemTrustedSite->setCallbackUserData ( this ); | ||
102 | mRemTrustedSite->setClickedCallback ( onRemTrustedSite ); | ||
103 | |||
104 | BOOL use_external_browser = gSavedSettings.getBOOL("UseExternalBrowser"); | ||
105 | mExternalBrowserCheck->set(use_external_browser); | ||
106 | |||
107 | LLString strVal = gSavedSettings.getString ( "BrowserHomePage" ); | ||
108 | mBrowserHomePage->setText ( strVal ); | ||
109 | |||
110 | BOOL boolVal = gSavedSettings.getBOOL ( "BrowserProxyEnabled" ); | ||
111 | mProxyEnabled->set ( boolVal ); | ||
112 | |||
113 | strVal = gSavedSettings.getString ( "BrowserProxyAddress" ); | ||
114 | mProxyAddress->setText ( strVal ); | ||
115 | |||
116 | S32 port = gSavedSettings.getS32 ( "BrowserProxyPort" ); | ||
117 | std::stringstream codec; | ||
118 | codec << port; | ||
119 | mProxyPort->setText ( codec.str () ); | ||
120 | |||
121 | S32 numVal = gSavedSettings.getS32 ( "BrowserProxySocks45" ); | ||
122 | mProxySocks45->setSelectedIndex ( numVal - 4 ); | ||
123 | |||
124 | strVal = gSavedSettings.getString ( "BrowserProxyExclusions" ); | ||
125 | mProxyExclusions->setText ( strVal ); | ||
126 | |||
127 | // switch on/off UI depending on state of 'use external browser' checkbox | ||
128 | configExternaBrowserEnabledUI ( mExternalBrowserCheck->get() ); | ||
129 | |||
130 | // switch on/off UI depending on which type of proxy is chosen (only if internal browseR) | ||
131 | if ( ! mExternalBrowserCheck->get() ) | ||
132 | configProxyEnabledUI ( mProxyEnabled->get() ); | ||
133 | 63 | ||
134 | BOOL use_web_pages_on_prims = gSavedSettings.getBOOL("UseWebPagesOnPrims"); | 64 | refresh(); |
135 | mWebPagesOnPrimsCheck->set(use_web_pages_on_prims); | ||
136 | |||
137 | // load the list of trusted sites | ||
138 | loadTrustedSiteList (); | ||
139 | 65 | ||
140 | return TRUE; | 66 | return TRUE; |
141 | } | 67 | } |
142 | 68 | ||
143 | // helper function to enable/disable proxy UI based on what type of proxy is selected | 69 | LLPanelWeb::~LLPanelWeb() |
144 | void LLPanelWeb::configProxyEnabledUI ( BOOL enabled ) | ||
145 | { | 70 | { |
146 | if ( enabled ) | 71 | // Children all cleaned up by default view destructor. |
147 | { | ||
148 | mProxyAddress->setEnabled ( TRUE ); | ||
149 | mProxyPort->setEnabled ( TRUE ); | ||
150 | mProxySocks45->setEnabled ( TRUE); | ||
151 | mProxyExclusions->setEnabled ( TRUE ); | ||
152 | } | ||
153 | else | ||
154 | { | ||
155 | mProxyAddress->setEnabled ( FALSE ); | ||
156 | mProxyPort->setEnabled ( FALSE ); | ||
157 | mProxySocks45->setEnabled ( FALSE ); | ||
158 | mProxyExclusions->setEnabled ( FALSE ); | ||
159 | }; | ||
160 | } | 72 | } |
161 | 73 | ||
162 | // helper function to enable/disable proxy UI based on what type of proxy is selected | 74 | void LLPanelWeb::apply() |
163 | void LLPanelWeb::configExternaBrowserEnabledUI ( BOOL enabled ) | ||
164 | { | 75 | { |
165 | if ( enabled ) | ||
166 | { | ||
167 | mBrowserHomePage->setEnabled ( FALSE ); | ||
168 | mWebPagesOnPrimsCheck->setEnabled ( FALSE ); | ||
169 | mTrustedSitesList->setEnabled ( FALSE ); | ||
170 | mProxyEnabled->setEnabled ( FALSE ); | ||
171 | mProxyAddress->setEnabled ( FALSE ); | ||
172 | mProxyPort->setEnabled ( FALSE ); | ||
173 | mProxySocks45->setEnabled ( FALSE ); | ||
174 | mProxyExclusions->setEnabled ( FALSE ); | ||
175 | mAddTrustedSite->setEnabled ( FALSE ); | ||
176 | mTrustedSiteEntry->setEnabled ( FALSE ); | ||
177 | mRemTrustedSite->setEnabled ( FALSE ); | ||
178 | } | ||
179 | else | ||
180 | { | ||
181 | mBrowserHomePage->setEnabled ( TRUE ); | ||
182 | mWebPagesOnPrimsCheck->setEnabled ( TRUE ); | ||
183 | mTrustedSitesList->setEnabled ( TRUE ); | ||
184 | mProxyEnabled->setEnabled ( TRUE ); | ||
185 | mProxyAddress->setEnabled ( TRUE ); | ||
186 | mProxyPort->setEnabled ( TRUE ); | ||
187 | mProxySocks45->setEnabled ( TRUE); | ||
188 | mProxyExclusions->setEnabled ( TRUE ); | ||
189 | mAddTrustedSite->setEnabled ( TRUE ); | ||
190 | mTrustedSiteEntry->setEnabled ( TRUE ); | ||
191 | |||
192 | // only set this to enabled if there is text in the entry widget | ||
193 | if ( mTrustedSiteEntry->getLength() ) | ||
194 | mAddTrustedSite->setEnabled ( TRUE ); | ||
195 | else | ||
196 | mAddTrustedSite->setEnabled ( FALSE ); | ||
197 | |||
198 | // only set this to enabled if something is selected in the list of trusted sites | ||
199 | if ( mTrustedSitesList->getFirstSelected () ) | ||
200 | mRemTrustedSite->setEnabled ( TRUE ); | ||
201 | else | ||
202 | mRemTrustedSite->setEnabled ( FALSE ); | ||
203 | }; | ||
204 | |||
205 | // final check - disable the white list options if not | ||
206 | // logged in since they are on a per-user basis | ||
207 | if ( ! mLoggedIn ) | ||
208 | { | ||
209 | mTrustedSitesList->setEnabled ( FALSE ); | ||
210 | mAddTrustedSite->setEnabled ( FALSE ); | ||
211 | mTrustedSiteEntry->setEnabled ( FALSE ); | ||
212 | mRemTrustedSite->setEnabled ( FALSE ); | ||
213 | }; | ||
214 | } | 76 | } |
215 | 77 | ||
216 | void LLPanelWeb::onCommitExternalBrowser ( LLUICtrl* ctrl, void* data ) | 78 | void LLPanelWeb::refresh() |
217 | { | 79 | { |
218 | LLPanelWeb* self = (LLPanelWeb*)data; | 80 | LLPanel::refresh(); |
219 | 81 | ||
220 | // update state of UI when proxy type changes | 82 | mCookiesEnabled = gSavedSettings.getBOOL("CookiesEnabled"); |
221 | BOOL value = self->mExternalBrowserCheck->get (); | ||
222 | self->configExternaBrowserEnabledUI ( value ); | ||
223 | } | ||
224 | 83 | ||
225 | void LLPanelWeb::onCommitProxyEnabled ( LLUICtrl* ctrl, void* data ) | 84 | #if LL_LIBXUL_ENABLED |
226 | { | 85 | llinfos << "setting cookies enabled to " << mCookiesEnabled << llendl; |
227 | LLPanelWeb* self = (LLPanelWeb*)data; | 86 | LLMozLib::getInstance()->enableCookies( mCookiesEnabled ); |
87 | #endif // LL_LIBXUL_ENABLED | ||
228 | 88 | ||
229 | // update state of UI when proxy type changes | ||
230 | BOOL value = self->mProxyEnabled->get (); | ||
231 | self->configProxyEnabledUI ( value ); | ||
232 | } | 89 | } |
233 | 90 | ||
234 | void LLPanelWeb::onTrustedSiteListCommit ( LLUICtrl* ctrl, void* data ) | 91 | void LLPanelWeb::cancel() |
235 | { | ||
236 | LLPanelWeb* self = (LLPanelWeb*)data; | ||
237 | |||
238 | // something was selected so enable the REMOVE button | ||
239 | self->mRemTrustedSite->setEnabled ( TRUE ); | ||
240 | }; | ||
241 | |||
242 | void LLPanelWeb::onTrustedSiteEntryKeystroke ( LLLineEditor* caller, void* data ) | ||
243 | { | 92 | { |
244 | LLPanelWeb* self = (LLPanelWeb*)data; | 93 | #if LL_LIBXUL_ENABLED |
94 | llinfos << "setting cookies enabled to " << mCookiesEnabled << llendl; | ||
95 | LLMozLib::getInstance()->enableCookies( mCookiesEnabled ); | ||
96 | #endif // LL_LIBXUL_ENABLED | ||
245 | 97 | ||
246 | if ( caller->getLength () ) | 98 | gSavedSettings.setBOOL( "CookiesEnabled", mCookiesEnabled ); |
247 | self->mAddTrustedSite->setEnabled ( TRUE ); | ||
248 | else | ||
249 | self->mAddTrustedSite->setEnabled ( FALSE ); | ||
250 | } | 99 | } |
251 | 100 | ||
252 | // add site to list | 101 | // static |
253 | void LLPanelWeb::onAddTrustedSite ( void* data ) | 102 | void LLPanelWeb::onClickClearCache(void*) |
254 | { | 103 | { |
255 | LLPanelWeb* self = (LLPanelWeb*)data; | 104 | #if LL_LIBXUL_ENABLED |
256 | 105 | gViewerWindow->alertXml("ConfirmClearBrowserCache", callback_clear_browser_cache, 0); | |
257 | if ( self->mTrustedSiteEntry->getLength () ) | 106 | #endif // LL_LIBXUL_ENABLED |
258 | { | ||
259 | // add to list | ||
260 | self->mTrustedSitesList->addSimpleItem ( self->mTrustedSiteEntry->getText () ); | ||
261 | |||
262 | // remove from entry field | ||
263 | self->mTrustedSiteEntry->clear (); | ||
264 | |||
265 | // nothing in entry field so disable add button | ||
266 | self->mAddTrustedSite->setEnabled ( FALSE ); | ||
267 | }; | ||
268 | } | 107 | } |
269 | 108 | ||
270 | // remove site from list | 109 | //static |
271 | void LLPanelWeb::onRemTrustedSite ( void* data ) | 110 | void LLPanelWeb::callback_clear_browser_cache(S32 option, void* userdata) |
272 | { | 111 | { |
273 | LLPanelWeb* self = (LLPanelWeb*)data; | 112 | #if LL_LIBXUL_ENABLED |
274 | 113 | if ( option == 0 ) // YES | |
275 | self->mTrustedSitesList->deleteSelectedItems (); | 114 | { |
276 | 115 | llinfos << "clearing browser cache" << llendl; | |
277 | // once we delete something, nothing is selected so disable the REMOVE button | 116 | LLMozLib::getInstance()->clearCache(); |
278 | self->mRemTrustedSite->setEnabled ( FALSE ); | 117 | } |
118 | #endif // LL_LIBXUL_ENABLED | ||
279 | } | 119 | } |
280 | 120 | ||
281 | // save off the list of trusted sites | 121 | // static |
282 | void LLPanelWeb::loadTrustedSiteList () | 122 | void LLPanelWeb::onClickClearCookies(void*) |
283 | { | 123 | { |
284 | // can't access white list file when not logged in since | 124 | #if LL_LIBXUL_ENABLED |
285 | // the filename is based on the SL username | 125 | gViewerWindow->alertXml("ConfirmClearCookies", callback_clear_cookies, 0); |
286 | if ( ! mLoggedIn ) | 126 | #endif // LL_LIBXUL_ENABLED |
287 | return; | ||
288 | |||
289 | LLUrlWhiteList* theWhiteList = LLUrlWhiteList::getInstance (); | ||
290 | |||
291 | if ( theWhiteList->load () ) | ||
292 | { | ||
293 | mTrustedSitesList->clear (); | ||
294 | |||
295 | LLString each; | ||
296 | if ( theWhiteList->getFirst ( each ) ) | ||
297 | { | ||
298 | mTrustedSitesList->addSimpleItem ( each ); | ||
299 | |||
300 | while ( theWhiteList->getNext ( each ) ) | ||
301 | { | ||
302 | mTrustedSitesList->addSimpleItem ( each ); | ||
303 | }; | ||
304 | }; | ||
305 | }; | ||
306 | } | 127 | } |
307 | 128 | ||
308 | // save off the list of trusted sites | 129 | //static |
309 | void LLPanelWeb::saveTrustedSiteList () | 130 | void LLPanelWeb::callback_clear_cookies(S32 option, void* userdata) |
310 | { | 131 | { |
311 | // can't access white list file when not logged in since | 132 | #if LL_LIBXUL_ENABLED |
312 | // the filename is based on the SL username | 133 | if ( option == 0 ) // YES |
313 | if ( ! mLoggedIn ) | ||
314 | return; | ||
315 | |||
316 | // erase the white list before we re-add items to it | ||
317 | LLUrlWhiteList::getInstance ()->clear (); | ||
318 | |||
319 | // step through each item in the scroll list | ||
320 | std::vector<LLScrollListItem*> data_list = mTrustedSitesList->getAllData(); | ||
321 | std::vector<LLScrollListItem*>::iterator data_itor; | ||
322 | for (data_itor = data_list.begin(); data_itor != data_list.end(); ++data_itor) | ||
323 | { | 134 | { |
324 | LLScrollListItem* each = *data_itor; | 135 | llinfos << "clearing browser cookies" << llendl; |
325 | LLUrlWhiteList::getInstance ()->addItem ( each->getColumn ( 0 )->getText (), false ); | 136 | LLMozLib::getInstance()->clearAllCookies(); |
326 | } | 137 | } |
327 | 138 | #endif // LL_LIBXUL_ENABLED | |
328 | LLUrlWhiteList::getInstance ()->save (); | ||
329 | } | 139 | } |
330 | 140 | ||
331 | // save off the list of trusted sites | 141 | // static |
332 | void LLPanelWeb::apply() | 142 | void LLPanelWeb::onCommitCookies(LLUICtrl* ctrl, void* data) |
333 | { | 143 | { |
144 | LLPanelWeb* self = (LLPanelWeb*)data; | ||
145 | LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl; | ||
334 | 146 | ||
335 | BOOL use_external_browser = mExternalBrowserCheck->get(); | 147 | if (!self || !check) return; |
336 | gSavedSettings.setBOOL("UseExternalBrowser", use_external_browser); | ||
337 | |||
338 | gSavedSettings.setString ( "BrowserHomePage", mBrowserHomePage->getText() ); | ||
339 | |||
340 | BOOL enabled = mProxyEnabled->get (); | ||
341 | gSavedSettings.setBOOL ( "BrowserProxyEnabled", enabled ); | ||
342 | |||
343 | gSavedSettings.setString ( "BrowserProxyAddress", mProxyAddress->getText() ); | ||
344 | |||
345 | S32 port; | ||
346 | std::stringstream codec ( mProxyPort->getText () ); | ||
347 | codec >> port; | ||
348 | gSavedSettings.setS32 ( "BrowserProxyPort", port ); | ||
349 | |||
350 | S32 socks = mProxySocks45->getSelectedIndex () + 4; | ||
351 | gSavedSettings.setS32 ( "BrowserProxySocks45", socks ); | ||
352 | 148 | ||
353 | gSavedSettings.setString ( "BrowserProxyExclusions", mProxyExclusions->getText() ); | 149 | #if LL_LIBXUL_ENABLED |
354 | 150 | llinfos << "setting cookies enabled to " << check->get() << llendl; | |
355 | BOOL use_web_pages_on_prims = mWebPagesOnPrimsCheck->get(); | 151 | LLMozLib::getInstance()->enableCookies( check->get() ); |
356 | gSavedSettings.setBOOL("UseWebPagesOnPrims", use_web_pages_on_prims); | 152 | #endif // LL_LIBXUL_ENABLED |
357 | 153 | ||
358 | // save off the list of trusted sites | ||
359 | saveTrustedSiteList (); | ||
360 | |||
361 | // update the media engine with the proxy information | ||
362 | if ( LLMediaEngine::getInstance() && LLMediaEngine::getInstance()->isAvailable() ) | ||
363 | { | ||
364 | LLMediaEngine::getInstance()->setNetworkProxy ( enabled, | ||
365 | mProxyAddress->getText(), port, socks, | ||
366 | mProxyExclusions->getText() ); | ||
367 | }; | ||
368 | } | ||
369 | |||
370 | void LLPanelWeb::cancel() | ||
371 | { | ||
372 | } | 154 | } |