| 1 | | /** |
|---|
| 2 | | * @file llembeddedbrowser.cpp |
|---|
| 3 | | * @brief LLEmbeddedBrowser implementation. |
|---|
| 4 | | * |
|---|
| 5 | | * $LicenseInfo:firstyear=2006&license=viewergpl$ |
|---|
| 6 | | * |
|---|
| 7 | | * Copyright (c) 2006-2007, 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://secondlife.com/developers/opensource/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 http://secondlife.com/developers/opensource/flossexception |
|---|
| 21 | | * |
|---|
| 22 | | * By copying, modifying or distributing this software, you acknowledge |
|---|
| 23 | | * that you have read and understood your obligations described above, |
|---|
| 24 | | * and agree to abide by those obligations. |
|---|
| 25 | | * |
|---|
| 26 | | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO |
|---|
| 27 | | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, |
|---|
| 28 | | * COMPLETENESS OR PERFORMANCE. |
|---|
| 29 | | * $/LicenseInfo$ |
|---|
| 30 | | */ |
|---|
| | 1 | /* ***** BEGIN LICENSE BLOCK ***** |
|---|
| | 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
|---|
| | 3 | * |
|---|
| | 4 | * The contents of this file are subject to the Mozilla Public License Version |
|---|
| | 5 | * 1.1 (the "License"); you may not use this file except in compliance with |
|---|
| | 6 | * the License. You may obtain a copy of the License at |
|---|
| | 7 | * http://www.mozilla.org/MPL/ |
|---|
| | 8 | * |
|---|
| | 9 | * Software distributed under the License is distributed on an "AS IS" basis, |
|---|
| | 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
|---|
| | 11 | * for the specific language governing rights and limitations under the |
|---|
| | 12 | * License. |
|---|
| | 13 | * |
|---|
| | 14 | * The Original Code is Linden Lab Inc. (http://lindenlab.com) code. |
|---|
| | 15 | * |
|---|
| | 16 | * The Initial Developer of the Original Code is: |
|---|
| | 17 | * Callum Prentice (callum@ubrowser.com) |
|---|
| | 18 | * |
|---|
| | 19 | * Portions created by the Initial Developer are Copyright (C) 2006 |
|---|
| | 20 | * the Initial Developer. All Rights Reserved. |
|---|
| | 21 | * |
|---|
| | 22 | * Contributor(s): |
|---|
| | 23 | * Callum Prentice (callum@ubrowser.com) |
|---|
| | 24 | * |
|---|
| | 25 | * Alternatively, the contents of this file may be used under the terms of |
|---|
| | 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
|---|
| | 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
|---|
| | 28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
|---|
| | 29 | * of those above. If you wish to allow use of your version of this file only |
|---|
| | 30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
|---|
| | 31 | * use your version of this file under the terms of the MPL, indicate your |
|---|
| | 32 | * decision by deleting the provisions above and replace them with the notice |
|---|
| | 33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
|---|
| | 34 | * the provisions above, a recipient may use your version of this file under |
|---|
| | 35 | * the terms of any one of the MPL, the GPL or the LGPL. |
|---|
| | 36 | * |
|---|
| | 37 | * ***** END LICENSE BLOCK ***** */ |
|---|
| 243 | | |
|---|
| 244 | | return true; |
|---|
| 245 | | } |
|---|
| 246 | | |
|---|
| 247 | | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 248 | | // |
|---|
| 249 | | std::string LLEmbeddedBrowser::getGREVersion() |
|---|
| 250 | | { |
|---|
| 251 | | // take the string directly from Mozilla |
|---|
| 252 | | return std::string( GRE_BUILD_ID ); |
|---|
| 253 | | } |
|---|
| 254 | | |
|---|
| 255 | | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 256 | | // |
|---|
| 257 | | void LLEmbeddedBrowser::setBrowserAgentId( std::string idIn ) |
|---|
| 258 | | { |
|---|
| 259 | | nsCOMPtr<nsIPref> pref = do_CreateInstance( NS_PREF_CONTRACTID ); |
|---|
| 260 | | if ( pref ) |
|---|
| 261 | | { |
|---|
| 262 | | pref->SetCharPref( "general.useragent.extra.* ", idIn.c_str() ); |
|---|
| 263 | | }; |
|---|
| 264 | | } |
|---|
| 265 | | |
|---|
| 266 | | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 267 | | // |
|---|
| 268 | | LLEmbeddedBrowserWindow* createWindow( void* nativeWindowHandleIn, int widthIn, int heightIn, PRUint32 aChromeFlags, nsIWebBrowserChrome* aParent, nsIWebBrowserChrome** aNewWindow ) |
|---|
| 269 | | { |
|---|
| 270 | | LLEmbeddedBrowserWindow* chrome = new LLEmbeddedBrowserWindow(); |
|---|
| 271 | | if ( ! chrome ) |
|---|
| 272 | | { |
|---|
| 273 | | return 0; |
|---|
| 274 | | }; |
|---|
| 275 | | |
|---|
| 276 | | CallQueryInterface( NS_STATIC_CAST( nsIWebBrowserChrome*, chrome ), aNewWindow ); |
|---|
| 277 | | |
|---|
| 278 | | NS_ADDREF( *aNewWindow ); |
|---|
| 279 | | |
|---|
| 280 | | chrome->SetChromeFlags( aChromeFlags ); |
|---|
| 281 | | |
|---|
| 282 | | nsCOMPtr< nsIWebBrowser > newBrowser; |
|---|
| 283 | | |
|---|
| 284 | | chrome->createBrowser( nativeWindowHandleIn, widthIn, heightIn, getter_AddRefs( newBrowser ) ); |
|---|
| 285 | | if ( ! newBrowser ) |
|---|
| 286 | | { |
|---|
| 287 | | return 0; |
|---|
| 288 | | }; |
|---|
| 289 | | |
|---|
| 290 | | return chrome; |
|---|
| 291 | | } |
|---|
| 292 | | |
|---|
| 293 | | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 294 | | // |
|---|
| 295 | | LLEmbeddedBrowserWindow* LLEmbeddedBrowser::createBrowserWindow( void* nativeWindowHandleIn, int browserWidthIn, int browserHeightIn ) |
|---|
| 296 | | { |
|---|
| 297 | | nsCOMPtr< nsIWebBrowserChrome > chrome; |
|---|
| 298 | | LLEmbeddedBrowserWindow* newWin = createWindow( nativeWindowHandleIn, browserWidthIn, browserHeightIn, nsIWebBrowserChrome::CHROME_ALL, nsnull, getter_AddRefs( chrome ) ); |
|---|
| 299 | | if ( newWin && chrome ) |
|---|
| 300 | | { |
|---|
| 301 | | nsCOMPtr< nsIWebBrowser > newBrowser; |
|---|
| 302 | | chrome->GetWebBrowser( getter_AddRefs( newBrowser ) ); |
|---|
| 303 | | nsCOMPtr< nsIWebNavigation > webNav( do_QueryInterface ( newBrowser ) ); |
|---|
| 304 | | webNav->LoadURI( NS_ConvertUTF8toUTF16( "about:blank" ).get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull ); |
|---|
| 305 | | |
|---|
| 306 | | |
|---|
| 307 | | clearLastError(); |
|---|
| 308 | | |
|---|
| 309 | | return newWin; |
|---|
| 310 | | }; |
|---|
| 311 | | |
|---|
| 312 | | setLastError( 0x2001 ); |
|---|
| 313 | | |
|---|
| 314 | | return 0; |
|---|
| 315 | | }; |
|---|
| 316 | | |
|---|
| 317 | | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 318 | | // |
|---|
| 319 | | bool LLEmbeddedBrowser::destroyBrowserWindow( LLEmbeddedBrowserWindow* browserWindowIn ) |
|---|
| 320 | | { |
|---|
| 321 | | nsCOMPtr< nsIWebBrowser > webBrowser; |
|---|
| 322 | | nsCOMPtr< nsIWebNavigation > webNavigation; |
|---|
| 323 | | |
|---|
| 324 | | browserWindowIn->GetWebBrowser( getter_AddRefs( webBrowser ) ); |
|---|
| 325 | | webNavigation = do_QueryInterface( webBrowser ); |
|---|
| 326 | | if ( webNavigation ) |
|---|
| 327 | | { |
|---|
| 328 | | webNavigation->Stop( nsIWebNavigation::STOP_ALL ); |
|---|
| 329 | | }; |
|---|
| 330 | | |
|---|
| 331 | | nsCOMPtr< nsIWebBrowser > browser = nsnull; |
|---|
| 332 | | browserWindowIn->GetWebBrowser( getter_AddRefs( browser ) ); |
|---|
| 333 | | nsCOMPtr< nsIBaseWindow > browserAsWin = do_QueryInterface( browser ); |
|---|
| 334 | | if ( browserAsWin ) |
|---|
| 335 | | { |
|---|
| 336 | | browserAsWin->Destroy(); |
|---|
| 337 | | }; |
|---|
| 338 | | |
|---|
| 339 | | browserWindowIn->SetWebBrowser( nsnull ); |
|---|
| 340 | | |
|---|
| 341 | | NS_RELEASE( browserWindowIn ); |
|---|
| 342 | | |
|---|
| 343 | | delete browserWindowIn; |
|---|
| 344 | | |
|---|
| 345 | | clearLastError(); |
|---|
| | 343 | } |
|---|
| | 344 | |
|---|
| | 345 | //////////////////////////////////////////////////////////////////////////////// |
|---|
| | 346 | // |
|---|
| | 347 | void LLEmbeddedBrowser::setBrowserAgentId( std::string idIn ) |
|---|
| | 348 | { |
|---|
| | 349 | nsCOMPtr<nsIPref> pref = do_CreateInstance( NS_PREF_CONTRACTID ); |
|---|
| | 350 | if ( pref ) |
|---|
| | 351 | { |
|---|
| | 352 | pref->SetCharPref( "general.useragent.extra.* ", idIn.c_str() ); |
|---|
| | 353 | }; |
|---|
| | 354 | } |
|---|
| | 355 | |
|---|
| | 356 | //////////////////////////////////////////////////////////////////////////////// |
|---|
| | 357 | // |
|---|
| | 358 | LLEmbeddedBrowserWindow* LLEmbeddedBrowser::createBrowserWindow( int browserWidthIn, int browserHeightIn ) |
|---|
| | 359 | { |
|---|
| | 360 | nsCOMPtr< nsIWebBrowserChrome > chrome; |
|---|
| | 361 | |
|---|
| | 362 | LLEmbeddedBrowserWindow* newWin = new LLEmbeddedBrowserWindow(); |
|---|
| | 363 | if ( ! newWin ) |
|---|
| | 364 | { |
|---|
| | 365 | return 0; |
|---|
| | 366 | }; |
|---|
| | 367 | |
|---|
| | 368 | nsIWebBrowserChrome** aNewWindow = getter_AddRefs( chrome ); |
|---|
| | 369 | |
|---|
| | 370 | CallQueryInterface( NS_STATIC_CAST( nsIWebBrowserChrome*, newWin ), aNewWindow ); |
|---|
| | 371 | |
|---|
| | 372 | NS_ADDREF( *aNewWindow ); |
|---|
| | 373 | |
|---|
| | 374 | newWin->SetChromeFlags( nsIWebBrowserChrome::CHROME_ALL ); |
|---|
| | 375 | |
|---|
| | 376 | nsCOMPtr< nsIWebBrowser > newBrowser; |
|---|
| | 377 | |
|---|
| | 378 | newWin->createBrowser( mNativeWindowHandle, browserWidthIn, browserHeightIn, getter_AddRefs( newBrowser ) ); |
|---|
| | 379 | if ( ! newBrowser ) |
|---|
| | 380 | { |
|---|
| | 381 | return 0; |
|---|
| | 382 | }; |
|---|
| | 383 | |
|---|
| | 384 | if ( newWin && chrome ) |
|---|
| | 385 | { |
|---|
| | 386 | newWin->setParent( this ); |
|---|
| | 387 | nsCOMPtr< nsIWebBrowser > newBrowser; |
|---|
| | 388 | chrome->GetWebBrowser( getter_AddRefs( newBrowser ) ); |
|---|
| | 389 | nsCOMPtr< nsIWebNavigation > webNav( do_QueryInterface ( newBrowser ) ); |
|---|
| | 390 | webNav->LoadURI( NS_ConvertUTF8toUTF16( "about:blank" ).get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull ); |
|---|
| | 391 | |
|---|
| | 392 | clearLastError(); |
|---|
| | 393 | |
|---|
| | 394 | return newWin; |
|---|
| | 395 | }; |
|---|
| | 396 | |
|---|
| | 397 | setLastError( 0x2001 ); |
|---|
| | 398 | return 0; |
|---|
| | 399 | }; |
|---|
| | 400 | |
|---|
| | 401 | //////////////////////////////////////////////////////////////////////////////// |
|---|
| | 402 | // |
|---|
| | 403 | bool LLEmbeddedBrowser::destroyBrowserWindow( LLEmbeddedBrowserWindow* browserWindowIn ) |
|---|
| | 404 | { |
|---|
| | 405 | nsCOMPtr< nsIWebBrowser > webBrowser; |
|---|
| | 406 | nsCOMPtr< nsIWebNavigation > webNavigation; |
|---|
| | 407 | |
|---|
| | 408 | browserWindowIn->GetWebBrowser( getter_AddRefs( webBrowser ) ); |
|---|
| | 409 | webNavigation = do_QueryInterface( webBrowser ); |
|---|
| | 410 | if ( webNavigation ) |
|---|
| | 411 | { |
|---|
| | 412 | webNavigation->Stop( nsIWebNavigation::STOP_ALL ); |
|---|
| | 413 | }; |
|---|
| | 414 | |
|---|
| | 415 | nsCOMPtr< nsIWebBrowser > browser = nsnull; |
|---|
| | 416 | browserWindowIn->GetWebBrowser( getter_AddRefs( browser ) ); |
|---|
| | 417 | nsCOMPtr< nsIBaseWindow > browserAsWin = do_QueryInterface( browser ); |
|---|
| | 418 | if ( browserAsWin ) |
|---|
| | 419 | { |
|---|
| | 420 | browserAsWin->Destroy(); |
|---|
| | 421 | }; |
|---|
| | 422 | |
|---|
| | 423 | browserWindowIn->SetWebBrowser( nsnull ); |
|---|
| | 424 | |
|---|
| | 425 | NS_RELEASE( browserWindowIn ); |
|---|
| | 426 | |
|---|
| | 427 | delete browserWindowIn; |
|---|
| | 428 | |
|---|
| | 429 | clearLastError(); |
|---|
| | 430 | |
|---|
| | 431 | return true; |
|---|