11/* *
22 * @file llfloatersearch.cpp
3- * @author Martin Reddy
4- * @brief Search floater - uses an embedded web browser control
3+ * @brief Floater for Search (update 2025, preload)
54 *
6- * $LicenseInfo:firstyear=2009 &license=viewerlgpl$
5+ * $LicenseInfo:firstyear=2011 &license=viewerlgpl$
76 * Second Life Viewer Source Code
8- * Copyright (C) 2010 , Linden Research, Inc.
7+ * Copyright (C) 2011 , Linden Research, Inc.
98 *
109 * This library is free software; you can redistribute it and/or
1110 * modify it under the terms of the GNU Lesser General Public
2726
2827#include " llviewerprecompiledheaders.h"
2928
29+ #include " llfloatersearch.h"
30+
31+ #include " llagent.h"
3032#include " llcommandhandler.h"
3133#include " llfloaterreg.h"
32- #include " llfloatersearch.h"
33- #include " llhttpconstants.h"
3434#include " llmediactrl.h"
35- #include " llnotificationsutil.h"
36- #include " lllogininstance.h"
37- #include " lluri.h"
38- #include " llagent.h"
39- #include " llui.h"
35+ #include " lluictrlfactory.h"
4036#include " llviewercontrol.h"
4137#include " llweb.h"
4238
4339// support secondlife:///app/search/{CATEGORY}/{QUERY} SLapps
44- class LLSearchHandler : public LLCommandHandler
45- {
46- public:
47- // requires trusted browser to trigger
48- LLSearchHandler () : LLCommandHandler(" search" , UNTRUSTED_CLICK_ONLY) { }
49- bool handle (const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
50- {
51- const size_t parts = tokens.size ();
52-
53- // get the (optional) category for the search
54- std::string collection;
55- if (parts > 0 )
56- {
57- collection = tokens[0 ].asString ();
40+ class LLSearchHandler : public LLCommandHandler {
41+ public:
42+ // requires trusted browser to trigger
43+ LLSearchHandler () : LLCommandHandler(" search" , UNTRUSTED_CLICK_ONLY) { }
44+ bool handle (const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web) {
45+ const size_t parts = tokens.size ();
46+
47+ // open the search floater and perform the requested search
48+ LLFloaterReg::showInstance (" search" , tokens);
49+ return true ;
5850 }
59-
60- // get the (optional) search string
61- std::string search_text;
62- if (parts > 1 )
63- {
64- search_text = tokens[1 ].asString ();
65- }
66-
67- // create the LLSD arguments for the search floater
68- LLFloaterSearch::Params p;
69- p.search .collection = collection;
70- p.search .query = LLURI::unescape (search_text);
71-
72- // open the search floater and perform the requested search
73- LLFloaterReg::showInstance (" search" , p);
74- return true ;
75- }
7651};
7752LLSearchHandler gSearchHandler ;
7853
79- LLFloaterSearch::SearchQuery::SearchQuery ()
80- : category(" category" , " " ),
81- collection(" collection" , " " ),
82- query(" query" )
83- {}
84-
85- LLFloaterSearch::LLFloaterSearch (const Params& key) :
86- LLFloaterWebContent(key),
87- mSearchGodLevel(0 )
54+ LLFloaterSearch::LLFloaterSearch (const LLSD& key)
55+ : LLFloater(key)
8856{
89- // declare a map that transforms a category name into
90- // the URL suffix that is used to search that category
91-
9257 mSearchType .insert (" standard" );
9358 mSearchType .insert (" land" );
9459 mSearchType .insert (" classified" );
@@ -100,76 +65,61 @@ LLFloaterSearch::LLFloaterSearch(const Params& key) :
10065 mCollectionType .insert (" people" );
10166}
10267
103- bool LLFloaterSearch::postBuild ()
68+ LLFloaterSearch::~LLFloaterSearch ()
10469{
105- LLFloaterWebContent::postBuild ();
106- mWebBrowser ->addObserver (this );
107-
108- return true ;
10970}
11071
111- void LLFloaterSearch::onOpen (const LLSD& key )
72+ void LLFloaterSearch::onOpen (const LLSD& tokens )
11273{
113- Params p (key);
114- p.trusted_content = true ;
115- p.allow_address_entry = false ;
116-
117- LLFloaterWebContent::onOpen (p);
118- mWebBrowser ->setFocus (true );
119- search (p.search );
74+ initiateSearch (tokens);
12075}
12176
122- void LLFloaterSearch::onClose ( bool app_quitting )
77+ void LLFloaterSearch::initiateSearch ( const LLSD& tokens )
12378{
124- LLFloaterWebContent::onClose (app_quitting);
125- // tear down the web view so we don't show the previous search
126- // result when the floater is opened next time
127- destroy ();
128- }
79+ std::string url = gSavedSettings .getString (" SearchURL" );
12980
130- void LLFloaterSearch::godLevelChanged (U8 godlevel)
131- {
132- // search results can change based upon god level - if the user
133- // changes god level, then give them a warning (we don't refresh
134- // the search as this might undo any page navigation or
135- // AJAX-driven changes since the last search).
81+ LLSD subs;
13682
137- // FIXME: set status bar text
83+ // Setting this substitution here results in a full set of collections being
84+ // substituted into the final URL using the logic from the original search.
85+ subs[" TYPE" ] = " standard" ;
13886
139- // getChildView("refresh_search")->setVisible( (godlevel != mSearchGodLevel));
140- }
87+ const size_t parts = tokens.size ();
14188
142- void LLFloaterSearch::search ( const SearchQuery &p)
143- {
144- if (! mWebBrowser || !p. validateBlock () )
89+ // get the (optional) category for the search
90+ std::string collection;
91+ if (parts > 0 )
14592 {
146- return ;
93+ collection = tokens[ 0 ]. asString () ;
14794 }
14895
149- // reset the god level warning as we're sending the latest state
150- getChildView (" refresh_search" )->setVisible (false );
151- mSearchGodLevel = gAgent .getGodLevel ();
96+ // get the (optional) search string
97+ std::string search_text;
98+ if (parts > 1 )
99+ {
100+ search_text = tokens[1 ].asString ();
101+ }
152102
153- // work out the subdir to use based on the requested category
154- LLSD subs;
155- if (mSearchType .find (p.category ) != mSearchType .end ())
103+ // TODO: where does category get set? I cannot find a reference to
104+ // it in internal docs - might be conflated with values in mSearchType
105+ std::string category;
106+ if (mSearchType .find (category) != mSearchType .end ())
156107 {
157- subs[" TYPE" ] = p. category ;
108+ subs[" TYPE" ] = category;
158109 }
159110 else
160111 {
161112 subs[" TYPE" ] = " standard" ;
162113 }
163114
164- // add the search query string
165- subs[" QUERY" ] = LLURI::escape (p.query );
115+ subs[" QUERY" ] = LLURI::escape (search_text);
166116
167117 subs[" COLLECTION" ] = " " ;
168118 if (subs[" TYPE" ] == " standard" )
169119 {
170- if (mCollectionType .find (p. collection ) != mCollectionType .end ())
120+ if (mCollectionType .find (collection) != mCollectionType .end ())
171121 {
172- subs[" COLLECTION" ] = " &collection_chosen=" + std::string (p. collection );
122+ subs[" COLLECTION" ] = " &collection_chosen=" + std::string (collection);
173123 }
174124 else
175125 {
@@ -182,30 +132,41 @@ void LLFloaterSearch::search(const SearchQuery &p)
182132 }
183133 }
184134
185- // add the user's preferred maturity (can be changed via prefs)
186- std::string maturity;
135+ // Default to PG
136+ std::string maturity = " g " ;
187137 if (gAgent .prefersAdult ())
188138 {
189- maturity = " gma" ; // PG,Mature,Adult
139+ // PG,Mature,Adult
140+ maturity = " gma" ;
190141 }
191142 else if (gAgent .prefersMature ())
192143 {
193- maturity = " gm" ; // PG,Mature
194- }
195- else
196- {
197- maturity = " g" ; // PG
144+ // PG,Mature
145+ maturity = " gm" ;
198146 }
199147 subs[" MATURITY" ] = maturity;
200148
201- // add the user's god status
149+ // God status
202150 subs[" GODLIKE" ] = gAgent .isGodlike () ? " 1" : " 0" ;
203151
204- // get the search URL and expand all of the substitutions
205- // (also adds things like [LANGUAGE], [VERSION], [OS], etc.)
206- std::string url = gSavedSettings .getString (" SearchURL" );
152+ // This call expands a set of generic substitutions like language, viewer version
153+ // etc. and then also does the same with the list of subs passed in.
207154 url = LLWeb::expandURLSubstitutions (url, subs);
208155
209- // and load the URL in the web view
210- mWebBrowser ->navigateTo (url, HTTP_CONTENT_TEXT_HTML);
156+ // Naviation to the calculated URL - we know it's HTML so we can
157+ // tell the media system not to bother with the MIME type check.
158+ LLMediaCtrl* search_browser = findChild<LLMediaCtrl>(" search_contents" );
159+ search_browser->navigateTo (url, HTTP_CONTENT_TEXT_HTML);
160+ }
161+
162+ bool LLFloaterSearch::postBuild ()
163+ {
164+ enableResizeCtrls (true , true , false );
165+
166+ // This call is actioned by the preload code in llViewerWindow
167+ // that creates the search floater during the login process
168+ // using a generic search with no query
169+ initiateSearch (LLSD ());
170+
171+ return true ;
211172}
0 commit comments