erbrowser/src/mozilla_api.cpp File Reference

browser - API for retrieving info on the loaded XHTML page More...

#include "browserTypes.h"
#include "indexFileHandler.h"
#include "browserLog.h"
#include "mozilla_api.h"
#include <sys/stat.h>
#include <ctype.h>
#include "nsCOMPtr.h"
#include "nsMemory.h"
#include "gtkmozembed_internal.h"
#include "nsIWebBrowser.h"
#include "nsIDOMDocument.h"
#include "nsIWebNavigation.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMNode.h"
#include "nsIDOMHTMLMetaElement.h"
#include "nsIWebBrowserPersist.h"
#include "nsILocalFile.h"
#include "nsIScrollable.h"
#include "nsIViewManager.h"
#include "nsIPresShell.h"
#include "nsIBaseWindow.h"
#include "nsIDeviceContext.h"
#include "nsIDOMHTMLLinkElement.h"
#include "nsIDocShell.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIWebBrowserFocus.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMWindow.h"
#include "nsNetUtil.h"
#include "nsITextScroll.h"
#include "nsIScrollableView.h"

Go to the source code of this file.

Functions

static float GetWebPagePixelScale (nsCOMPtr< nsIWebBrowser > web_browser)
static gulong GetWebPageWindowSize (nsCOMPtr< nsIWebBrowser > web_browser)
static gboolean mozilla_link_update (GtkMozEmbed *b, gint type)
static nsIDOMWindow * GetDOMOWindowObject (nsIWebBrowser *wb)
static gboolean mozilla_link_module_goto_rel (GtkMozEmbed *b, char *value)
gboolean mozilla_get_page_type (GtkMozEmbed *b, gchar **type)
gboolean mozilla_save (GtkMozEmbed *b, gchar *file_name, gint all)
gboolean mozilla_next_link (GtkMozEmbed *embed)
gboolean mozilla_previous_link (GtkMozEmbed *embed)
gboolean mozilla_next_page (GtkMozEmbed *b)
gboolean mozilla_previous_page (GtkMozEmbed *b)
gboolean mozilla_overview_page (GtkMozEmbed *b)
gboolean mozilla_alt_page (GtkMozEmbed *b)
gboolean mozilla_handle_link (GtkMozEmbed *b)
gboolean mozilla_back (GtkMozEmbed *b)
gboolean mozilla_zoom (GtkMozEmbed *b, float size)
gboolean mozilla_scrollable (direction_t direction, GtkMozEmbed *b)
gboolean mozilla_scroll (int count, GtkMozEmbed *b)
gint mozilla_determine_page_offset (GtkMozEmbed *b)
static int htoi (char *s)
int raw_url_decode (char *str, int len)
char * mozilla_uri_to_path (const char *aUri)


Detailed Description

browser - API for retrieving info on the loaded XHTML page

<File description>="">

Definition in file mozilla_api.cpp.


Function Documentation

static nsIDOMWindow * GetDOMOWindowObject ( nsIWebBrowser *  wb  )  [static]

Definition at line 514 of file mozilla_api.cpp.

00515 {
00516     nsCOMPtr < nsIDOMWindow > oDomWindow;
00517     nsresult rv;
00518 
00519     rv = wb->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00520 
00521     BR_LOGPRINTF("GetContentDOMWindow rv %d", rv);
00522 
00523     if (!oDomWindow)
00524     {
00525         BR_WARNPRINTF("Cannot create Dom Window Object");
00526     }
00527     return oDomWindow;
00528 }

static float GetWebPagePixelScale ( nsCOMPtr< nsIWebBrowser >  web_browser  )  [static]

Definition at line 718 of file mozilla_api.cpp.

00719 {
00720     nsCOMPtr < nsIDocShell > doc_shell;
00721     nsCOMPtr < nsIPresShell > presShell;
00722     nsCOMPtr < nsIViewManager > vm;
00723 
00724     nsIDeviceContext *dx = NULL;
00725     float   pixelscale = 0;
00726 
00727     doc_shell = do_GetInterface(web_browser);
00728 
00729     if (doc_shell)
00730     {
00731         doc_shell->GetPresShell(getter_AddRefs(presShell));
00732 
00733         if (presShell)
00734         {
00735             // What about the "nsCOMPtr" story here ??
00736 
00737             //try out....   
00738             //nsCOMPtr <nsIDocument> dm;
00739             //dm = presShell->GetDocument();
00740 
00741             // try out....
00742             //presShell->SetPreferenceStyleRules(TRUE);
00743 
00744             vm = presShell->GetViewManager();
00745             //presShell->GetViewManager(getter_AddRefs(vm));
00746 
00747             vm->GetDeviceContext(dx);
00748             pixelscale = dx->TwipsToDevUnits();
00749 
00750 //            PRINT_TRACE(("dx->TwipsToDevUnits returned %f\n", pixelscale));
00751         }
00752     }
00753     return pixelscale;
00754 
00755 }

static gulong GetWebPageWindowSize ( nsCOMPtr< nsIWebBrowser >  web_browser  )  [static]

Definition at line 762 of file mozilla_api.cpp.

00763 {
00764     nsCOMPtr < nsIBaseWindow > baseWindow;
00765     gulong  theWindowSize = 0;
00766 
00767     // determine window size (in pixels) 
00768     baseWindow = do_QueryInterface(web_browser);
00769 
00770     if (baseWindow)
00771     {
00772         int     x, y, cx, cy;
00773 
00774         baseWindow->GetPositionAndSize(&x, &y, &cx, &cy);
00775 //        PRINT_TRACE(("baseWindow->GetPositionAndSize x %d - y %d - cx %d - cy %d\n", x, y, cx, cy));
00776 
00777         theWindowSize = cy - y;
00778 //        PRINT_TRACE(("windowSize = %d - %d = %d\n", cy, y, theWindowSize));
00779     }
00780     return theWindowSize;
00781 }

static int htoi ( char *  s  )  [static]

Method used to retrieve the page count of the currently loaded "one page" XHTML page

Parameters:
embed reference to the MozEmbed widget
Returns:
pagecount (DEFAULT_PAGE when errors occured)

Definition at line 902 of file mozilla_api.cpp.

00903 {
00904         int value;
00905         int c;
00906 
00907         c = ((unsigned char *)s)[0];
00908         if (isupper(c))
00909                 c = tolower(c);
00910         value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16;
00911 
00912         c = ((unsigned char *)s)[1];
00913         if (isupper(c))
00914                 c = tolower(c);
00915         value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10;
00916 
00917         return (value);
00918 }

gboolean mozilla_alt_page ( GtkMozEmbed *  b  ) 

Method used to select the ALT link of the currently loaded XHTML page

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 337 of file mozilla_api.cpp.

00338 {
00339     return mozilla_link_module_goto_rel(b, "ALT");
00340 }

Here is the call graph for this function:

gboolean mozilla_back ( GtkMozEmbed *  b  ) 

Method used to go one step back in the browser history

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 472 of file mozilla_api.cpp.

00473 {
00474     g_return_val_if_fail(b != NULL, FALSE);
00475 
00476     if (gtk_moz_embed_can_go_back(GTK_MOZ_EMBED(b)))
00477     {
00478         gtk_moz_embed_go_back(GTK_MOZ_EMBED(b));
00479         return TRUE;
00480     }
00481     else
00482     {
00483         return FALSE;
00484     }
00485 }

gint mozilla_determine_page_offset ( GtkMozEmbed *  b  ) 

Method used to retrieve the scrolled offset of the currently loaded "one page" XHTML page

Parameters:
embed reference to the MozEmbed widget
Returns:
offset (DEFAULT_PAGE_OFFSET when errors occured, or non-scrollable page)

Definition at line 650 of file mozilla_api.cpp.

00651 {
00652     nsCOMPtr < nsIWebBrowser > wb;
00653     nsCOMPtr < nsIScrollable > scrollable;
00654     gint    offset = DEFAULT_PAGE_OFFSET;
00655 
00656     BR_PAGEBARPRINTF("mozilla_determine_page_offset -- entry\n");
00657 
00658     g_return_val_if_fail(b != NULL, DEFAULT_PAGE_OFFSET);
00659 
00660     BR_PAGEBARPRINTF("mozilla_determine_page_offset -- b != NULL\n");
00661 
00662     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00663     if (!wb)
00664     {
00665         BR_WARNPRINTF("mozilla_determine_page_offset -- wb == null\n");
00666         return (DEFAULT_PAGE_OFFSET);
00667     }
00668 
00669     // determine web page size
00670     scrollable = do_QueryInterface(wb);
00671 
00672     if (scrollable)
00673     {
00674         gint    minPos;
00675         gint    maxPos;
00676         gint    curPos;
00677         int     pixelscale, htmlSize, htmlPos;
00678         gulong  theWindowSize;
00679 
00680         scrollable->GetScrollRange(scrollable->ScrollOrientation_Y, &minPos, &maxPos);
00681         BR_PAGEBARPRINTF("scrollable->getScrollRange returned [%d,%d]\n", minPos, maxPos);
00682         scrollable->GetCurScrollPos(scrollable->ScrollOrientation_Y, &curPos);
00683         BR_PAGEBARPRINTF("scrollable->getCurScrollPos returned %d\n", curPos);
00684 
00685         // determine window size (in pixels) 
00686         theWindowSize = GetWebPageWindowSize(wb);
00687         BR_PAGEBARPRINTF("theWindowSize=%d\n", theWindowSize);
00688 
00689         // determine pixel scale to convert from twips to pixels
00690         // scaled to avoid using floats
00691         pixelscale = (int) (100 / GetWebPagePixelScale(wb));
00692         BR_PAGEBARPRINTF("100/pixelscale=%d\n", pixelscale);
00693 
00694         // Sizes in pixels, already scaled for percentage to avoid
00695         // using floats
00696         htmlSize = (maxPos - minPos);
00697         htmlPos = curPos * 100 + theWindowSize * pixelscale;
00698 
00699         // Calculate offset in percentage -- rounded to integer value
00700         offset = (gint) (htmlPos / htmlSize) + 1;
00701         if (offset > 100)
00702         {
00703             offset = 100;
00704         }
00705         BR_PAGEBARPRINTF("CALCULATED OFFSET = %d\n", offset);
00706 
00707     }
00708 
00709     return offset;
00710 }

Here is the call graph for this function:

gboolean mozilla_get_page_type ( GtkMozEmbed *  b,
gchar **  type 
)

Definition at line 71 of file mozilla_api.cpp.

00072 {
00073     nsCOMPtr < nsIWebBrowser > wb;
00074     nsAutoString metaTypeName;
00075     nsAutoString metaTypeContent;
00076     nsAutoString metaTagName;
00077     nsresult result;
00078     PRUint32 numnodes = 0;
00079     char   *typeValue = NULL;
00080 
00081     metaTagName.AssignWithConversion("meta");
00082     metaTypeName.AssignWithConversion("type");
00083 
00084     g_return_val_if_fail(b != NULL, FALSE);
00085     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00086     if (!wb)
00087         return (FALSE);
00088     // retrieve the list of meta nodes
00089     nsCOMPtr < nsIWebNavigation > nav(do_QueryInterface(wb));
00090     nsCOMPtr < nsIDOMDocument > domDoc;
00091     nav->GetDocument(getter_AddRefs(domDoc));
00092     if (!domDoc)
00093         return (FALSE);
00094 
00095     nsCOMPtr < nsIDOMNodeList > nodeList;
00096     result = domDoc->GetElementsByTagName(metaTagName, getter_AddRefs(nodeList));
00097 
00098     BR_PAGEBARPRINTF("domDoc->GetElementsByTagName returned %d", result);
00099 
00100     nodeList->GetLength(&numnodes);
00101 
00102     if (numnodes != 0)
00103     {
00104         BR_PAGEBARPRINTF("page does contain %d meta tags", numnodes);
00105 
00106         // find the next page meta data tag
00107         for (unsigned int i = 0; i < numnodes; i++)
00108         {
00109             nsCOMPtr < nsIDOMNode > node;
00110             nodeList->Item(i, getter_AddRefs(node));
00111 
00112             nsCOMPtr < nsIDOMHTMLMetaElement > metaElement = do_QueryInterface(node);
00113 
00114             if (metaElement)
00115             {
00116                 nsCOMPtr < nsIDOMElement > domElement = do_QueryInterface(node);
00117                 if (!domElement)
00118                     return (FALSE);
00119 
00120                 domElement->GetAttribute(metaTypeName, metaTypeContent);
00121 
00122                 typeValue = ToNewCString(metaTypeContent);
00123                 *type = g_strdup(typeValue);
00124                 nsMemory::Free(typeValue);
00125 
00126                 BR_PAGEBARPRINTF("node [%d] is meta data with type [%s]", i, (**type == NULL) ? "none" : *type);
00127 
00128                 if (**type != NULL)
00129                 {
00130                     // leave for loop  
00131                     break;
00132                 }
00133             }                   // (meta Element)
00134         }                       // for loop
00135 
00136         if (**type == NULL)
00137         {
00138             return FALSE;
00139         }
00140         else
00141         {
00142             return TRUE;
00143         }
00144 
00145 
00146     }
00147     else
00148     {
00149         BR_PAGEBARPRINTF("page does not contain any meta data");
00150         return FALSE;
00151     }                           // (numnodes != 0)
00152     return FALSE;
00153 }

gboolean mozilla_handle_link ( GtkMozEmbed *  b  ) 

Method used to select the previous link of the currently loaded XHTML page when no "previous" link is available the last link on the page will be selected

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 425 of file mozilla_api.cpp.

00426 {
00427     nsCOMPtr < nsIWebBrowser > wb;
00428     char   *urlValue;
00429     nsAutoString aHref;
00430 
00431     g_return_val_if_fail(b != NULL, FALSE);
00432     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00433     if (!wb)
00434         return (FALSE);
00435 
00436     // see if there is a focused element
00437     nsCOMPtr < nsIWebBrowserFocus > focus = do_QueryInterface(wb);
00438     nsCOMPtr < nsIDOMElement > focusElement;
00439     focus->GetFocusedElement(getter_AddRefs(focusElement));
00440 
00441     if (focusElement)
00442     {
00443         BR_MOZILLA_DOCPRINTF("There is a focused element");
00444 
00445         nsCOMPtr < nsIDOMHTMLAnchorElement > anchor = do_QueryInterface(focusElement);
00446         if (anchor)
00447         {
00448             anchor->GetHref(aHref);
00449 
00450             // return a new |char| buffer you must free with |nsMemory::Free|
00451             urlValue = ToNewCString(aHref);
00452 
00453             BR_MOZILLA_DOCPRINTF("node is anchor with url %s", urlValue);
00454             gtk_moz_embed_load_url(GTK_MOZ_EMBED(b), urlValue);
00455 
00456             nsMemory::Free(urlValue);
00457             return TRUE;
00458         }
00459         else
00460         {
00461             BR_MOZILLA_DOCPRINTF("node is NO anchor !!!!!");
00462         }                       // (anchor)
00463     }
00464     else
00465     {
00466         BR_MOZILLA_DOCPRINTF("page does not contain a focussed element");
00467     }
00468     return FALSE;
00469 }

static gboolean mozilla_link_module_goto_rel ( GtkMozEmbed *  b,
char *  value 
) [static]

Definition at line 348 of file mozilla_api.cpp.

00349 {
00350     nsCOMPtr < nsIWebBrowser > wb;
00351     PRUint32 numnodes = 0;
00352     nsresult result;
00353     nsAutoString aHref;
00354     nsAutoString linkTagName;
00355     nsAutoString linkRelNameContent;
00356     char   *urlValue = NULL;
00357 
00358     linkTagName.AssignWithConversion("link");
00359     //NS_NAMED_LITERAL_STRING(linkTagName,"link");
00360 
00361     g_return_val_if_fail(b != NULL, FALSE);
00362 
00363     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00364     if (!wb)
00365         return (FALSE);
00366 
00367     BR_MOZILLA_DOCPRINTF("entry %s", value);
00368 
00369     // retrieve the list of link nodes
00370     nsCOMPtr < nsIWebNavigation > nav(do_QueryInterface(wb));
00371     nsCOMPtr < nsIDOMDocument > domDoc;
00372     nav->GetDocument(getter_AddRefs(domDoc));
00373     if (!domDoc)
00374         return (FALSE);
00375 
00376     nsCOMPtr < nsIDOMNodeList > nodeList;
00377     result = domDoc->GetElementsByTagName(linkTagName, getter_AddRefs(nodeList));
00378     //result = domDoc->GetElementsByTagName(NS_LITERAL_STRING("link"), getter_AddRefs(nodeList));
00379 
00380     BR_MOZILLA_DOCPRINTF("domDoc->GetElementsByTagName returned %d", result);
00381 
00382     nodeList->GetLength(&numnodes);
00383 
00384     if (numnodes != 0)
00385     {
00386         BR_MOZILLA_DOCPRINTF("page does contain %d links\n", numnodes);
00387 
00388         // find the next page link
00389         for (unsigned int i = 0; i < numnodes; i++)
00390         {
00391             nsCOMPtr < nsIDOMNode > node;
00392             nodeList->Item(i, getter_AddRefs(node));
00393 
00394             nsCOMPtr < nsIDOMHTMLLinkElement > linkElement = do_QueryInterface(node);
00395             if (!linkElement)
00396                 return (FALSE);
00397 
00398             linkElement->GetRel(linkRelNameContent);
00399 
00400             if (linkRelNameContent.EqualsIgnoreCase(value))
00401             {
00402                 linkElement->GetHref(aHref);
00403                 // return a new |char| buffer you must free with |nsMemory::Free|
00404                 urlValue = ToNewCString(aHref);
00405 
00406                 BR_MOZILLA_DOCPRINTF("node is linkelement with url %s", urlValue);
00407                 gtk_moz_embed_load_url(GTK_MOZ_EMBED(b), urlValue);
00408 
00409                 nsMemory::Free(urlValue);
00410                 return TRUE;
00411             }
00412             else
00413             {
00414                 BR_MOZILLA_DOCPRINTF("node is linkelement with rel != %s", value);
00415             }
00416         }
00417     }
00418     else
00419     {
00420         BR_MOZILLA_DOCPRINTF("page does not contain any links");
00421     }
00422     return FALSE;
00423 }

static gboolean mozilla_link_update ( GtkMozEmbed *  b,
gint  type 
) [static]

Definition at line 237 of file mozilla_api.cpp.

00238 {
00239     static PRInt32 currentFocus = (-1);
00240 
00241     nsCOMPtr < nsIWebBrowser > wb;
00242     PRUint32 numnodes = 0;
00243 
00244     g_return_val_if_fail(b != NULL, FALSE);
00245     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00246     if (!wb)
00247         return (FALSE);
00248 
00249     // retrieve the list of link nodes
00250     nsCOMPtr < nsIWebNavigation > nav(do_QueryInterface(wb));
00251     nsCOMPtr < nsIDOMDocument > domDoc;
00252     nav->GetDocument(getter_AddRefs(domDoc));
00253     if (!domDoc)
00254         return (FALSE);
00255 
00256     nsCOMPtr < nsIDOMHTMLDocument > htmlDoc = do_QueryInterface(domDoc);
00257     if (!htmlDoc)
00258         return (FALSE);
00259 
00260     nsCOMPtr < nsIDOMHTMLCollection > links;
00261     htmlDoc->GetLinks(getter_AddRefs(links)); // GetAnchors returns nothing
00262     nsCOMPtr < nsIDOMNode > link;
00263     links->GetLength(&numnodes);
00264 
00265     if (numnodes != 0)
00266     {
00267         // see if there is a focused element
00268         nsCOMPtr < nsIWebBrowserFocus > focus = do_QueryInterface(wb);
00269         if (!focus)
00270             return (FALSE);
00271         nsCOMPtr < nsIDOMElement > focusElement;
00272         focus->GetFocusedElement(getter_AddRefs(focusElement));
00273 
00274         if (focusElement)
00275         {
00276             BR_MOZILLA_DOCPRINTF("there is a focused element %d mode to %d\n", currentFocus, (currentFocus + numnodes - 1) % numnodes);
00277 
00278             if (type == PREVIOUS_LINK)
00279             {
00280                 currentFocus = (currentFocus + numnodes - 1) % numnodes;
00281             }
00282             else
00283             {
00284                 currentFocus = (currentFocus + 1) % numnodes;
00285             }
00286 
00287             links->Item(currentFocus, getter_AddRefs(link));
00288             nsCOMPtr < nsIDOMHTMLAnchorElement > anchor = do_QueryInterface(link);
00289             if (!anchor)
00290                 return (FALSE);
00291             if (anchor)
00292             {
00293                 BR_MOZILLA_DOCPRINTF("node is anchor");
00294                 anchor->Focus();
00295             }                   // (anchor)
00296         }
00297         else
00298         {
00299             // set the focus to the first link element
00300             links->Item(0, getter_AddRefs(link));
00301 
00302             nsCOMPtr < nsIDOMHTMLAnchorElement > anchor = do_QueryInterface(link);
00303             if (!anchor)
00304                 return (FALSE);
00305             if (anchor)
00306             {
00307                 BR_MOZILLA_DOCPRINTF("node is anchor");
00308                 anchor->Focus();
00309                 currentFocus = 0;
00310             }                   // (anchor)
00311 
00312         }                       // (focusElement)
00313     }
00314     else
00315     {
00316         BR_MOZILLA_DOCPRINTF("page does not contain any links");
00317         return FALSE;
00318     }
00319     return TRUE;
00320 }

gboolean mozilla_next_link ( GtkMozEmbed *  b  ) 

Method used to select the next link of the currently loaded XHTML page when no "next" link is available the first link on th epage will be selected

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 223 of file mozilla_api.cpp.

00224 {
00225     return mozilla_link_update(embed, NEXT_LINK);
00226 }

Here is the call graph for this function:

gboolean mozilla_next_page ( GtkMozEmbed *  b  ) 

Method used to go to the next page

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 322 of file mozilla_api.cpp.

00323 {
00324     return mozilla_link_module_goto_rel(b, "NEXT");
00325 }

Here is the call graph for this function:

gboolean mozilla_overview_page ( GtkMozEmbed *  b  ) 

Method used to select the INDEX link of the currently loaded XHTML page

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 332 of file mozilla_api.cpp.

00333 {
00334     return mozilla_link_module_goto_rel(b, "INDEX");
00335 }

Here is the call graph for this function:

gboolean mozilla_previous_link ( GtkMozEmbed *  b  ) 

Method used to select the currently focussed link

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 228 of file mozilla_api.cpp.

00229 {
00230     return mozilla_link_update(embed, PREVIOUS_LINK);
00231 }

Here is the call graph for this function:

gboolean mozilla_previous_page ( GtkMozEmbed *  b  ) 

Method used to go to the previous page

Parameters:
embed reference to the MozEmbed widget
Returns:
TRUE on succes

Definition at line 327 of file mozilla_api.cpp.

00328 {
00329     return mozilla_link_module_goto_rel(b, "PREV");
00330 }

Here is the call graph for this function:

gboolean mozilla_save ( GtkMozEmbed *  b,
gchar *  file_name,
gint  all 
)

Method used to save a webpage -- only used for debug reasons

Parameters:
embed reference to the MozEmbed widget
filename where to save
all 
Returns:
TRUE on succes

Definition at line 156 of file mozilla_api.cpp.

00157 {
00158 #ifdef SELECTION_ENABLED
00159     nsCOMPtr < nsIWebBrowser > wb;
00160     gint    i = 0;
00161     gchar  *relative_path = NULL;
00162 
00163     g_return_val_if_fail(b != NULL, FALSE);
00164 
00165 
00166     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00167     if (!wb)
00168         return (FALSE);
00169 
00170     nsCOMPtr < nsIWebNavigation > nav(do_QueryInterface(wb));
00171 
00172     nsCOMPtr < nsIDOMDocument > domDoc;
00173     nav->GetDocument(getter_AddRefs(domDoc));
00174 
00175     if (!domDoc)
00176         return (FALSE);
00177     nsCOMPtr < nsIWebBrowserPersist > persist(do_QueryInterface(wb));
00178 
00179     if (persist)
00180     {
00181         nsCOMPtr < nsILocalFile > file;
00182         nsCOMPtr < nsILocalFile > relative = nsnull;
00183         if (all)
00184         {
00185 
00186             relative_path = g_strdup(file_name);
00187             relative_path = g_strconcat(relative_path, "_files/", NULL);
00188 
00189             for (i = strlen(relative_path) - 1; i >= 0; --i)
00190                 if (relative_path[i] == '/')
00191                 {
00192                     relative_path[i] = '\0';
00193                     break;
00194                 }
00195 
00196             mkdir(relative_path, 0755);
00197 
00198             nsAutoString s;
00199 
00200             s.AssignWithConversion(relative_path);
00201             NS_NewLocalFile(s, PR_TRUE, getter_AddRefs(relative));
00202         }
00203 
00204         nsAutoString s;
00205 
00206         s.AssignWithConversion(file_name);
00207         NS_NewLocalFile(s, PR_TRUE, getter_AddRefs(file));
00208 
00209         if (file)
00210             persist->SaveDocument(domDoc, file, relative, nsnull, 0, 0);
00211 
00212         if (all)
00213             g_free(relative_path);
00214 
00215         return (TRUE);
00216     }
00217 #endif //SELECTION_ENABLED
00218     return (FALSE);
00219 }

gboolean mozilla_scroll ( int  count,
GtkMozEmbed *  b 
)

Method to scroll on page up or down in the currently displayed XHTML page

Parameters:
embed reference to the MozEmbed widget
count number of pages to scroll (positive values move down in the view)
Returns:
TRUE when possible

Definition at line 624 of file mozilla_api.cpp.

00625 {
00626     gboolean returnValue = FALSE;
00627 
00628     nsCOMPtr < nsIWebBrowser > wb;
00629     nsCOMPtr < nsITextScroll > textscrollInterface;
00630 
00631     g_return_val_if_fail(b != NULL, FALSE);
00632 
00633     BR_PAGEBARPRINTF("count %d", count);
00634 
00635     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00636     if (wb)
00637     {
00638         textscrollInterface = do_QueryInterface(wb);
00639 
00640         if (textscrollInterface)
00641         {
00642             // prevents scrolling off the end of the view
00643             textscrollInterface->ScrollByPages(count);
00644             returnValue = TRUE;
00645         }
00646     }
00647     return returnValue;
00648 }

gboolean mozilla_scrollable ( direction_t  direction,
GtkMozEmbed *  b 
)

Method used to check if it possible to scroll on page down or up in the currently displayed XHTML page

Parameters:
embed reference to the MozEmbed widget
direction 
Returns:
TRUE when possible

Definition at line 570 of file mozilla_api.cpp.

00571 {
00572     PRBool  scrollable = PR_FALSE;
00573 
00574     nsCOMPtr < nsIWebBrowser > wb;
00575     nsCOMPtr < nsIDocShell > doc_shell;
00576     nsCOMPtr < nsIPresShell > presShell;
00577     //nsCOMPtr < nsIViewManager > vm;
00578     //nsCOMPtr < nsIScrollableView > scrollview;
00579 
00580     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00581 
00582     if (wb)
00583     {
00584         doc_shell = do_GetInterface(wb);
00585 
00586         if (doc_shell)
00587         {
00588             doc_shell->GetPresShell(getter_AddRefs(presShell));
00589 
00590             if (presShell)
00591             {
00592                 nsIViewManager *vm = presShell->GetViewManager();
00593 
00594                 if (vm)
00595                 {
00596                     nsIScrollableView *scrollableView = nsnull;
00597 
00598                     vm->GetRootScrollableView(&scrollableView);
00599 
00600                     if (scrollableView)
00601                     {
00602                         switch (direction)
00603                         {
00604                         case pageDown_t:
00605                             scrollableView->CanScroll(PR_FALSE, PR_TRUE, scrollable);
00606                             break;
00607                         case pageUp_t:
00608                             scrollableView->CanScroll(PR_FALSE, PR_FALSE, scrollable);
00609                             break;
00610                         }
00611 
00612                     }
00613                 }
00614 
00615             }
00616         }
00617     }
00618 
00619     BR_PAGEBARPRINTF("return %s", (scrollable == PR_TRUE) ? "TRUE" : "FALSE");
00620 
00621     return scrollable;
00622 }

char* mozilla_uri_to_path ( const char *  uri  ) 

Method used to convert from uri to file system path.

Parameters:
uri reference to the input uri
Returns:
the path in file system, NULL if fail

Definition at line 943 of file mozilla_api.cpp.

00944 {
00945     // in fact, we should use nsIURI to get path from uri
00946     // just remove file:// prefix if there is any
00947     char * protocol = "file://";
00948     if (NULL == aUri)  return NULL;
00949     unsigned int min = strlen(protocol);
00950 
00951     if (strlen(aUri) <= min) return NULL;
00952     if (aUri != strstr(aUri, protocol))
00953     {
00954         return NULL;
00955     }
00956     
00957     char * path = strdup((char *) &aUri[min]);
00958     
00959     // we should handle the %20 %2f...
00960     raw_url_decode(path, strlen(path));
00961     return path;
00962     
00963     // the following code does not work, I don't know the reason, it once works
00964     /*
00965     nsresult rv;
00966     nsCOMPtr<nsIURI> theURI;
00967     rv = NS_NewURI(getter_AddRefs(theURI), aUri);
00968     if (NS_FAILED(rv)) return NULL;
00969     nsCAutoString  path;
00970     theURI->GetPath(path);
00971     return ToNewCString(path);
00972     */    
00973 }       

Here is the call graph for this function:

gboolean mozilla_zoom ( GtkMozEmbed *  b,
float  size 
)

Method used to zoom the currently loaded page

Parameters:
embed reference to the MozEmbed widget
size zoom factor
Returns:
TRUE on succes

Definition at line 487 of file mozilla_api.cpp.

00488 {
00489     nsCOMPtr < nsIWebBrowser > wb;
00490     nsCOMPtr < nsIDOMWindow > activeWindow;
00491 
00492     g_return_val_if_fail(b != NULL, FALSE);
00493     gtk_moz_embed_get_nsIWebBrowser(b, getter_AddRefs(wb));
00494     if (!wb)
00495         return (FALSE);
00496 
00497     BR_LOGPRINTF("mozilla_zoom -- GetDOMOWindowObject");
00498 
00499     activeWindow = GetDOMOWindowObject(wb);
00500 
00501     if ((activeWindow) && (size > 0))
00502     {
00503         activeWindow->SetTextZoom(size);
00504         return TRUE;
00505     }
00506     return FALSE;
00507 }

Here is the call graph for this function:

int raw_url_decode ( char *  str,
int  len 
)

Definition at line 920 of file mozilla_api.cpp.

00921 {
00922         char *dest = str;
00923         char *data = str;
00924 
00925         while (len--) {
00926                 if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) 
00927                         && isxdigit((int) *(data + 2))) {
00928                         *dest = (char) htoi(data + 1);
00929                         data += 2;
00930                         len -= 2;
00931                 } else {
00932                         *dest = *data;
00933                 }
00934                 data++;
00935                 dest++;
00936         }
00937         *dest = '\0';
00938         return dest - str;
00939 }

Here is the call graph for this function:


Generated on Sun Dec 14 17:14:53 2008 by  doxygen 1.5.6