Show
Ignore:
Timestamp:
02/29/08 19:32:35 (2 years ago)
Author:
rob.linden
Message:

Latest internal snapshot
Last Changed Rev: 80909
Last Changed Date: 2008-02-27 15:08:55 -0800 (Wed, 27 Feb 2008)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/llmozlib2/llembeddedbrowser.cpp

    r3 r8  
    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 ***** */ 
    3138 
    3239// Windows specific switches 
     
    3643                #define DEBUG 1 
    3744        #endif 
    38 #endif 
     45#endif // WIN32 
    3946 
    4047#include "llembeddedbrowser.h" 
     
    4249 
    4350#ifdef WIN32 
    44         #pragma warning( disable : 4265 ) // "class has virtual functions, but destructor is not virtual" 
    45         #pragma warning( disable : 4291 ) // (no matching operator delete found; memory will not be freed if initialization throws an exception) 
     51        #pragma warning( disable : 4265 )      // "class has virtual functions, but destructor is not virtual" 
     52        #pragma warning( disable : 4291 )      // (no matching operator delete found; memory will not be freed if initialization throws an exception) 
    4653#endif  // WIN32 
    4754 
    4855#include "nsBuildID.h" 
    49 #include "nsNetCID.h" 
    50 #include "nsCWebBrowser.h" 
    51 #include "nsGUIEvent.h" 
    5256#include "nsICacheService.h" 
    5357#include "nsICookieManager.h" 
    54 #include "nsICaret.h" 
    55 #include "nsIComponentRegistrar.h" 
    56 #include "nsIContent.h" 
    57 #include "nsIDOMDocument.h" 
    58 #include "nsIDOMElement.h" 
    59 #include "nsIDOMWindow.h" 
    60 #include "nsIDocShell.h" 
    61 #include "nsIDocShellTreeItem.h" 
    62 #include "nsIDocument.h" 
    63 #include "nsIFactory.h" 
    64 #include "nsIFrame.h" 
    65 #include "nsIInterfaceRequestorUtils.h" 
    6658#include "nsIPref.h" 
    67 #include "nsIPromptService.h" 
    68 #include "nsIScrollableView.h" 
    69 #include "nsISelection.h" 
    70 #include "nsISelectionController.h" 
    71 #include "nsIWebBrowserChrome.h" 
    72 #include "nsIWebBrowserChromeFocus.h" 
    73 #include "nsIWebBrowserFocus.h" 
    74 #include "nsPresContext.h" 
     59#include "nsNetCID.h" 
    7560#include "nsProfileDirServiceProvider.h" 
    76 #include "nsXPCOMGlue.h" 
    7761#include "nsXULAppAPI.h" 
    78 #include "nsWidgetsCID.h" // for NS_APPSHELL_CID 
    7962#include "nsIAppShell.h" 
    80 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); 
     63 
     64#if defined(LL_LINUX) || defined(LL_DARWIN) 
     65#include "nsWidgetsCID.h" 
     66static nsIAppShell *sAppShell = nsnull; 
     67#endif // defined(LL_LINUX) || defined(LL_DARWIN) 
    8168 
    8269// singleton pattern - initialization 
     
    8673// 
    8774LLEmbeddedBrowser::LLEmbeddedBrowser() : 
    88         mErrorNum( 0 ) 
     75        mErrorNum( 0 ), 
     76        mNativeWindowHandle( 0 ) 
    8977{ 
    9078} 
     
    131119//////////////////////////////////////////////////////////////////////////////// 
    132120// 
    133 static nsIAppShell *sAppShell = nsnull; 
    134  
    135 bool LLEmbeddedBrowser::init( std::string applicationDir, std::string componentDir, std::string profileDir ) 
    136 
     121std::string LLEmbeddedBrowser::getGREVersion() 
     122
     123        // take the string directly from Mozilla 
     124        return std::string( GRE_BUILD_ID ); 
     125
     126 
     127//////////////////////////////////////////////////////////////////////////////// 
     128// 
     129bool LLEmbeddedBrowser::init( std::string applicationDir, 
     130                                                                std::string componentDir, 
     131                                                                        std::string profileDir, 
     132                                                                                void* nativeWindowHandleIn ) 
     133
     134        mNativeWindowHandle = nativeWindowHandleIn; 
     135 
    137136        nsCOMPtr< nsILocalFile > applicationDirNative; 
    138137        nsresult result = NS_NewNativeLocalFile( nsCString( applicationDir.c_str() ), PR_FALSE, getter_AddRefs( applicationDirNative ) ); 
     
    193192        if ( pref ) 
    194193        { 
    195                 //pref->SetBoolPref( "viewmanager.do_doublebuffering", PR_FALSE ); 
    196194                pref->SetBoolPref( "security.warn_entering_secure", PR_FALSE ); 
    197195                pref->SetBoolPref( "security.warn_entering_weak", PR_FALSE ); 
     
    208206        enableProxy( false, "", 0 ); 
    209207 
    210 #ifdef LL_LINUX 
     208#if defined(LL_LINUX) || defined(LL_DARWIN) 
    211209        // Essential on Linux/GTK to add the gecko pump to the GTK event 
    212210        // loop.  Might be harmless/good on other platforms too. 
     211        nsresult rv; 
    213212        nsCOMPtr<nsIAppShell> appShell; 
    214         appShell = do_CreateInstance(kAppShellCID); 
     213        NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); 
     214        appShell = do_CreateInstance(kAppShellCID, &rv); 
    215215        if (!appShell) 
    216216        { 
     
    233233bool LLEmbeddedBrowser::reset() 
    234234{ 
    235         if (sAppShell) { 
    236                 // Shutdown the appshell service. 
    237                 sAppShell->Spindown(); 
    238                 NS_RELEASE(sAppShell); 
    239                 sAppShell = NULL; 
    240         } 
    241  
    242235        XRE_TermEmbedding(); 
    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(); 
    346236 
    347237        return true; 
     
    361251} 
    362252 
    363 /////////////////////////////////////////////////////////////////////////////// 
     253//////////////////////////////////////////////////////////////////////////////// 
    364254// 
    365255bool LLEmbeddedBrowser::enableProxy( bool proxyEnabledIn, std::string proxyHostNameIn, int proxyPortIn ) 
     
    440330                        pref->SetBoolPref( "plugin.scan.plid.all", PR_FALSE ); 
    441331                        pref->SetBoolPref( "xpinstall-enabled", PR_FALSE ); 
     332                        pref->SetBoolPref( "plugin.scan.4xPluginFolder", PR_FALSE ); 
     333                        pref->SetCharPref( "plugin.scan.Quicktime", "20.0" ); 
     334                        pref->SetCharPref( "plugin.scan.Acrobat", "99.0" ); 
     335                        pref->SetCharPref( "plugin.scan.SunJRE", "99.0" ); 
     336                        pref->SetCharPref( "plugin.scan.WindowsMediaPlayer", "99.0" ); 
    442337                }; 
    443338 
     
    446341 
    447342        return false; 
     343} 
     344 
     345//////////////////////////////////////////////////////////////////////////////// 
     346// 
     347void 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// 
     358LLEmbeddedBrowserWindow* 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// 
     403bool 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; 
    448432} 
    449433 
    450434// Windows specific switches 
    451435#ifdef WIN32 
    452  
    453         #pragma warning( 3 : 4265 ) // "class has virtual functions, but destructor is not virtual" 
    454436        #pragma warning( 3 : 4291 ) // (no matching operator delete found; memory will not be freed if initialization throws an exception) 
     437        #pragma warning( 3 : 4265 )     // "class has virtual functions, but destructor is not virtual" 
    455438 
    456439        // #define required by this file for LibXUL/Mozilla code to avoid crashes in their debug code