Changeset 2

Show
Ignore:
Timestamp:
11/21/07 18:45:01 (2 years ago)
Author:
callum.linden
Message:

Added option to specify a URL to redirect to when navigateTo results in a 404 HTML status code.
Used for catching 404s from Amazon S3 site in the Web based search panel and displaying a more user-friendly page.
Reviewed by JC.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/llembeddedbrowserwindow.cpp

    r1 r2  
    5858#include "nsIDocument.h" 
    5959#include "nsIFrame.h" 
     60#include "nsIHttpChannel.h" 
    6061#include "nsIInterfaceRequestorUtils.h" 
    6162#include "nsIScrollableView.h" 
     
    9394        mBackgroundRed( 0xff ), 
    9495        mBackgroundGreen( 0xff ), 
    95         mBackgroundBlue( 0xff ) 
     96        mBackgroundBlue( 0xff ), 
     97        m404RedirectUrl( "" ) 
    9698{ 
    9799} 
     
    384386// TODO: ought to check that this change is on the top frame and 
    385387// indicate this to the consumer of this class 
    386 NS_IMETHODIMP LLEmbeddedBrowserWindow::OnLocationChange( nsIWebProgress* aWebProgress, 
    387                                                                                                                 nsIRequest* aRequest, 
    388                                                                                                                         nsIURI* aLocation ) 
    389 
     388NS_IMETHODIMP LLEmbeddedBrowserWindow::OnLocationChange( nsIWebProgress* progress, 
     389                                                                                                                        nsIRequest* request, 
     390                                                                                                                                nsIURI* location ) 
     391
     392        if ( request ) 
     393        { 
     394                nsCOMPtr< nsIHttpChannel > http_channel = do_QueryInterface( request ); 
     395                if ( http_channel ) 
     396                { 
     397                        PRUint32 response_status = 0; 
     398                        http_channel->GetResponseStatus( &response_status ); 
     399 
     400                        if ( response_status == 404 ) 
     401                        { 
     402                                if ( ! m404RedirectUrl.empty() ) 
     403                                { 
     404                                        if ( mWebNav ) 
     405                                        { 
     406                                                mWebNav->LoadURI( reinterpret_cast< const PRUnichar* > 
     407                                                        ( NS_ConvertUTF8toUTF16( m404RedirectUrl.c_str() ).get() ), 
     408                                                                nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY, 
     409                                                                        nsnull, nsnull, nsnull ); 
     410                                        }; 
     411                                }; 
     412                        }; 
     413                }; 
     414        }; 
     415 
    390416        nsCAutoString newURI; 
    391         aLocation->GetSpec( newURI ); 
     417        location->GetSpec( newURI ); 
    392418 
    393419        mCurrentUri = newURI.get(); 
     
    10781104} 
    10791105 
     1106//////////////////////////////////////////////////////////////////////////////// 
     1107// 
     1108bool LLEmbeddedBrowserWindow::set404RedirectUrl( std::string redirect_url ) 
     1109{ 
     1110        m404RedirectUrl = redirect_url; 
     1111 
     1112        return true; 
     1113} 
     1114 
     1115//////////////////////////////////////////////////////////////////////////////// 
     1116// 
     1117bool LLEmbeddedBrowserWindow::clr404RedirectUrl() 
     1118{ 
     1119        m404RedirectUrl = std::string( "" ); 
     1120 
     1121        return true; 
     1122} 
     1123 
    10801124// #define required by this file for LibXUL/Mozilla code to avoid crashes in their debug code 
    10811125#ifdef _DEBUG 
  • trunk/llembeddedbrowserwindow.h

    r1 r2  
    165165                void navigateForward(); 
    166166 
     167                bool set404RedirectUrl( std::string redirect_url ); 
     168                bool clr404RedirectUrl(); 
     169 
    167170                void mouseDown( PRInt16 xPosIn, PRInt16 yPosIn ); 
    168171                void mouseUp( PRInt16 xPosIn, PRInt16 yPosIn ); 
     
    183186                std::string mCurrentUri; 
    184187                std::string mClickHref; 
     188                std::string m404RedirectUrl; 
    185189 
    186190                nsCOMPtr< nsIWebBrowser > mWebBrowser; 
     
    193197                PRUint8 mBackgroundGreen; 
    194198                PRUint8 mBackgroundBlue; 
    195  
    196199 
    197200                unsigned char* mPageBuffer; 
  • trunk/llmozlib.cpp

    r1 r2  
    514514} 
    515515 
     516//////////////////////////////////////////////////////////////////////////////// 
     517// 
     518bool LLMozLib::set404RedirectUrl(  int browser_window_in, std::string redirect_url ) 
     519{ 
     520        LLEmbeddedBrowserWindow* browser_window = getBrowserWindowFromWindowId( browser_window_in ); 
     521        if ( browser_window ) 
     522        { 
     523                browser_window->set404RedirectUrl( redirect_url ); 
     524 
     525                return true; 
     526        }; 
     527 
     528        return false; 
     529} 
     530 
     531//////////////////////////////////////////////////////////////////////////////// 
     532// 
     533bool LLMozLib::clr404RedirectUrl( int browser_window_in ) 
     534{ 
     535        LLEmbeddedBrowserWindow* browser_window = getBrowserWindowFromWindowId( browser_window_in ); 
     536        if ( browser_window ) 
     537        { 
     538                browser_window->clr404RedirectUrl(); 
     539 
     540                return true; 
     541        }; 
     542 
     543        return false; 
     544} 
  • trunk/llmozlib.h

    r1 r2  
    143143                bool canNavigateForward( int browserWindowIdIn ); 
    144144                bool navigateForward( int browserWindowIdIn ); 
     145 
     146                // set/clear URL to redirect to when a 404 page is reached 
     147                bool set404RedirectUrl( int browser_window_in, std::string redirect_url ); 
     148                bool clr404RedirectUrl( int browser_window_in ); 
    145149 
    146150                // access to rendered bitmap data 
  • trunk/tests/ubrowser.llmozlib/ubrowser.cpp

    r1 r2  
    112112        mBookmarks.push_back( std::pair< std::string, std::string >( "DHTML Lemmings!", "http://www.elizium.nu/scripts/lemmings/" ) ); 
    113113        mBookmarks.push_back( std::pair< std::string, std::string >( "DHTML Demos", "http://www.dhteumeuleu.com/" ) ); 
     114        mBookmarks.push_back( std::pair< std::string, std::string >( "S3 404 test", "http://world.secondlife.com/parcel/jumk" ) ); 
    114115        mBookmarks.push_back( std::pair< std::string, std::string >( "about:config", "about:config" ) ); 
    115116} 
     
    222223 
    223224        LLMozLib::getInstance()->setBrowserAgentId( "[uBrowser]" ); 
     225 
     226        LLMozLib::getInstance()->set404RedirectUrl( mWindowA, "http://secondlife.com/app/search/notfound.html" ); 
    224227 
    225228        std::cout << "LLMozLib version: " << LLMozLib::getInstance()->getVersion() << std::endl;