Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
mozilla_api.h File Reference
#include "minimo_types.h"
#include "prenv.h"
#include "nsMemory.h"
#include "gtkmozembed_internal.h"
#include "nsIWebBrowser.h"
#include "nsIWebBrowserFind.h"
#include "nsNetUtil.h"
#include "nsIPref.h"
#include "nsIPresShell.h"
#include "nsIDocShell.h"
#include "nsIDOMDocument.h"
#include "nsIWebBrowserPersist.h"
#include "nsIWebNavigation.h"
#include "nsIDocShellTreeItem.h"
#include "nsILocalFile.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDocument.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMNSHTMLElement.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PREF_ID   NS_PREF_CONTRACTID
#define CONTEXT_NONE   0
#define CONTEXT_DEFAULT   1
#define CONTEXT_LINK   2
#define CONTEXT_IMAGE   4
#define CONTEXT_DOCUMENT   8
#define CONTEXT_INPUT   64
#define CONTEXT_OTHER   128
#define CONTEXT_XUL   256

Functions

PRUnicharmozilla_locale_to_unicode (const gchar *locStr)
gboolean mozilla_find (GtkMozEmbed *b, const char *exp, PRBool IgnoreCase, PRBool SearchBackWards, PRBool DoWrapFind, PRBool SearchEntireWord, PRBool SearchInFrames, PRBool DidFind)
gboolean mozilla_preference_set (const char *preference_name, const char *new_value)
gboolean mozilla_preference_set_boolean (const char *preference_name, gboolean new_boolean_value)
gboolean mozilla_preference_set_int (const char *preference_name, gint new_int_value)
gboolean mozilla_save (GtkMozEmbed *b, gchar *file_name, gint all)
void mozilla_save_image (GtkMozEmbed *b, gchar *location, gchar *FullPath)
gchar * mozilla_get_link_message (GtkWidget *embed)
glong mozilla_get_context_menu_type (GtkMozEmbed *b, gpointer event, gchar **img, gchar **link, gchar **linktext)
gchar * mozilla_get_attribute (nsIDOMNode *node, gchar *attribute)
gboolean mozilla_save_prefs (void)

Define Documentation

Definition at line 116 of file mozilla_api.h.

Definition at line 119 of file mozilla_api.h.

Definition at line 118 of file mozilla_api.h.

Definition at line 120 of file mozilla_api.h.

Definition at line 117 of file mozilla_api.h.

Definition at line 115 of file mozilla_api.h.

#define CONTEXT_OTHER   128

Definition at line 121 of file mozilla_api.h.

#define CONTEXT_XUL   256

Definition at line 122 of file mozilla_api.h.

Definition at line 88 of file mozilla_api.h.


Function Documentation

gboolean mozilla_find ( GtkMozEmbed *  b,
const char *  exp,
PRBool  IgnoreCase,
PRBool  SearchBackWards,
PRBool  DoWrapFind,
PRBool  SearchEntireWord,
PRBool  SearchInFrames,
PRBool  DidFind 
)

Definition at line 76 of file mozilla_api.cpp.

{
  PRUnichar *search_string;
  g_return_val_if_fail(b != NULL, FALSE);
  nsIWebBrowser *wb = nsnull;
  gtk_moz_embed_get_nsIWebBrowser( b, &wb);
  nsCOMPtr<nsIWebBrowserFind> finder(do_GetInterface(wb));
  search_string = mozilla_locale_to_unicode(exp);
  finder->SetSearchString(search_string);
  
  finder->SetFindBackwards(SearchBackWards);
  finder->SetWrapFind(DoWrapFind);
  finder->SetEntireWord(SearchEntireWord);
  finder->SetSearchFrames(SearchInFrames);
  finder->SetMatchCase(IgnoreCase);
  finder->FindNext(&DidFind);
  
  g_free(search_string);
  return ( DidFind );
}

Here is the call graph for this function:

Here is the caller graph for this function:

gchar* mozilla_get_attribute ( nsIDOMNode node,
gchar *  attribute 
)

Definition at line 420 of file mozilla_api.cpp.

{
  nsresult result;
  
  nsCOMPtr<nsIDOMNamedNodeMap> attributes;
  result = node->GetAttributes(getter_AddRefs (attributes));
  if (!NS_SUCCEEDED (result) || !attributes) return ( NULL );
  
  nsAutoString attr;
  
  attr.AssignWithConversion (attribute);
  
  nsCOMPtr<nsIDOMNode> attrNode;
  result = attributes->GetNamedItem (attr, getter_AddRefs (attrNode));
  if (!NS_SUCCEEDED (result) || !attrNode)  return (NULL);
  
  nsAutoString nodeValue;
  
  result = attrNode->GetNodeValue (nodeValue);
  if (!NS_SUCCEEDED (result))  return (NULL);
  
  char *cstr = ToNewCString(nodeValue);
  char *lifeSucks = g_strdup (cstr);
  
  nsMemory::Free (cstr);
  
  return (lifeSucks);
}

Here is the call graph for this function:

Here is the caller graph for this function:

glong mozilla_get_context_menu_type ( GtkMozEmbed *  b,
gpointer  event,
gchar **  img,
gchar **  link,
gchar **  linktext 
)

Definition at line 267 of file mozilla_api.cpp.

{
  nsresult result;
  *img = *link = NULL;
  
  nsIDOMMouseEvent *aMouseEvent =  (nsIDOMMouseEvent*)event;
  
  nsCOMPtr<nsIDOMEventTarget> OriginalTarget;
  
  nsCOMPtr<nsIDOMNSEvent> aEvent = do_QueryInterface(aMouseEvent);
  if (!aEvent) return(CONTEXT_NONE);
  result = aEvent->GetOriginalTarget(getter_AddRefs(OriginalTarget));
  
  if (NS_FAILED(result) || !OriginalTarget) return (CONTEXT_NONE);
  
  nsCOMPtr<nsIDOMNode> OriginalNode = do_QueryInterface(OriginalTarget);
  if (!OriginalNode) return (CONTEXT_NONE);
  
  nsString nodename;
  OriginalNode->GetNodeName(nodename);
  
  if (nodename.EqualsLiteral ("xul:thumb") ||
      nodename.EqualsLiteral ("xul:slider"))
    return (CONTEXT_NONE);
  
  nsCOMPtr<nsIDOMEventTarget> EventTarget;
  result = aMouseEvent->GetTarget(getter_AddRefs(EventTarget));
  if (NS_FAILED(result) || !EventTarget) return (  CONTEXT_NONE );
  
  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(EventTarget);
  if (!node) return (CONTEXT_NONE);
  
  nsCOMPtr<nsIDOMDocument> domDoc;
  result = node->GetOwnerDocument(getter_AddRefs(domDoc));
  if (!NS_SUCCEEDED (result) || !domDoc) return (CONTEXT_NONE);
  
  nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
  if(!doc) return (CONTEXT_NONE);
  
  nsCOMPtr<nsIDOMNSDocument> nsDoc = do_QueryInterface(domDoc);
  if (!nsDoc) return (CONTEXT_NONE);
  
  nsIURI *baseURI;
  
  baseURI = doc->GetBaseURI ();
  
  if (!baseURI) return (CONTEXT_NONE);
  
  nsString mime;
  nsDoc->GetContentType(mime);
  if (mime.EqualsLiteral("text/xul"))  return (CONTEXT_NONE);
  
  PRUint32 flags = CONTEXT_NONE;
  nsCOMPtr<nsIDOMHTMLElement> element;
  
  do {
    PRUint16 type;
    node->GetNodeType(&type);
    
    element = do_QueryInterface(node);
    if (element)
    {
      nsAutoString tag;
      element->GetTagName(tag);
      
      if (tag.EqualsIgnoreCase("input"))
      {
        flags |= CONTEXT_INPUT;
      }
      else if (tag.EqualsIgnoreCase("img")) //if (tag.EqualsWithConversion("img", PR_TRUE))
      {
        flags |= CONTEXT_IMAGE;
        
        char *src = mozilla_get_attribute (node, "src");
        if (!src)  return (  CONTEXT_NONE );
        
        nsAutoString srca;
        srca.AssignWithConversion(src);
        
        nsCString srcc,imgc;
        srcc.AssignWithConversion(srca);
        result = baseURI->Resolve(srcc, imgc);
        g_free(src);
        
        *img = ToNewCString(imgc);
        
        if (!img) return (CONTEXT_NONE);
              
      }
      
      else
      {
        flags |= CONTEXT_OTHER;
      }
      
      nsCOMPtr<nsIDOMNamedNodeMap> attributes;
      node->GetAttributes(getter_AddRefs(attributes));
      if (attributes)
      {
        nsCOMPtr<nsIDOMNode> hrefNode;
        nsAutoString href;
        href.AssignWithConversion("href");
        attributes->GetNamedItem(href, getter_AddRefs(hrefNode));
        if (hrefNode)
        {
          flags |= CONTEXT_LINK;
          nsAutoString linkhtml;
          nsCOMPtr<nsIDOMNSHTMLElement> nsElement;
                     
          nsElement = do_QueryInterface (element);
          if (nsElement)
          {
            result = nsElement->GetInnerHTML(linkhtml);
            if (NS_SUCCEEDED(result) && ToNewCString(linkhtml))
              *linktext = g_strdup(ToNewCString(linkhtml));
          }
          
          char *href =  mozilla_get_attribute (node, "href");
          if (!href)   return (CONTEXT_NONE );
          
          nsAutoString hrefa;
          hrefa.AssignWithConversion(href);
          
          nsCString hrefc,linkc;
          hrefc.AssignWithConversion(hrefa);
          
          result = baseURI->Resolve(hrefc,linkc);
          g_free(href);
          
          *link = ToNewCString(linkc);
          
          if (!link)  return (CONTEXT_NONE);
          
          break;
        }
      }
    }
    nsCOMPtr<nsIDOMNode> parentNode;
    node->GetParentNode(getter_AddRefs(parentNode));
    
    if (!parentNode)
    {
      node = nsnull;
      flags |= CONTEXT_DOCUMENT;
      break;
    }
    node = parentNode;
  } while (node);
  
  return(flags);
}

Here is the call graph for this function:

Here is the caller graph for this function:

gchar* mozilla_get_link_message ( GtkWidget *  embed)

Definition at line 248 of file mozilla_api.cpp.

{  
  gchar *link;
  
  link = gtk_moz_embed_get_link_message (GTK_MOZ_EMBED (embed));
  return link;  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 59 of file mozilla_api.cpp.

{
  if (locStr == NULL)
  {
    return (NULL);
  }
  nsAutoString autoStr;
  autoStr.AssignWithConversion (locStr);       
  PRUnichar *uniStr = ToNewUnicode(autoStr);
  return ( uniStr );
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean mozilla_preference_set ( const char *  preference_name,
const char *  new_value 
)

Definition at line 105 of file mozilla_api.cpp.

{
  g_return_val_if_fail (preference_name != NULL, FALSE);
  g_return_val_if_fail (new_value != NULL, FALSE);
  
  nsCOMPtr<nsIPref> pref = do_CreateInstance(PREF_ID);
  
  if (pref)
  {
    nsresult rv = pref->SetCharPref (preference_name, new_value);
    return ( NS_SUCCEEDED (rv) ? TRUE : FALSE );
  }
  return (FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean mozilla_preference_set_boolean ( const char *  preference_name,
gboolean  new_boolean_value 
)

Definition at line 125 of file mozilla_api.cpp.

{
  
  g_return_val_if_fail (preference_name != NULL, FALSE);
  
  nsCOMPtr<nsIPref> pref = do_CreateInstance(PREF_ID);
  
  if (pref)
  {
    nsresult rv = pref->SetBoolPref (preference_name,  new_boolean_value ? PR_TRUE : PR_FALSE);
    return ( NS_SUCCEEDED (rv) ? TRUE : FALSE );
  }
  
  return (FALSE);
}      

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean mozilla_preference_set_int ( const char *  preference_name,
gint  new_int_value 
)

Definition at line 146 of file mozilla_api.cpp.

{
  g_return_val_if_fail (preference_name != NULL, FALSE);
  
  nsCOMPtr<nsIPref> pref = do_CreateInstance(PREF_ID);
  
  if (pref)
  {
    nsresult rv = pref->SetIntPref (preference_name, new_int_value);
    return ( NS_SUCCEEDED (rv) ? TRUE : FALSE );
  }
  
  return (FALSE);
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 167 of file mozilla_api.cpp.

{
  
  nsCOMPtr<nsIWebBrowser> wb;
  gint i = 0;
  gchar *relative_path = NULL;
  g_return_val_if_fail(b != NULL, FALSE);
  
  gtk_moz_embed_get_nsIWebBrowser(b,getter_AddRefs(wb));
  if (!wb) return (FALSE);
  
  nsCOMPtr<nsIWebNavigation> nav(do_QueryInterface(wb));
  
  nsCOMPtr<nsIDOMDocument> domDoc;
  nav->GetDocument(getter_AddRefs(domDoc));
  
  if (!domDoc) return (FALSE);
  nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(wb));
  
  if (persist) {
    nsCOMPtr<nsILocalFile> file;
    nsCOMPtr<nsILocalFile> relative = nsnull;
    if (all) {
      
      relative_path = g_strdup(file_name);
      relative_path = g_strconcat(relative_path,"_files/", NULL);
      
      for (i=strlen(relative_path)-1 ; i >= 0; --i)
        if (relative_path[i] == '/')
        {
          relative_path[i] = '\0';
          break;
        }
      
      mkdir(relative_path,0755);
      
      nsAutoString s; s.AssignWithConversion(relative_path);
      NS_NewLocalFile(s, PR_TRUE, getter_AddRefs(relative));
    }
    
    nsAutoString s; s.AssignWithConversion(file_name);
    NS_NewLocalFile(s,PR_TRUE,getter_AddRefs(file));
    
    if (file) persist->SaveDocument(domDoc,file,relative, nsnull, 0, 0);
    
    if (all) g_free(relative_path);
    
    return (TRUE);
  }
  return (FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mozilla_save_image ( GtkMozEmbed *  b,
gchar *  location,
gchar *  FullPath 
)

Definition at line 220 of file mozilla_api.cpp.

{
  nsresult rv = NS_OK;
  if (strlen(location) == 0 || !location) return;
  nsCOMPtr<nsIURI> linkURI;
  rv = NS_NewURI(getter_AddRefs(linkURI), location);
  if (NS_FAILED(rv)) return;
  nsIWebBrowser *wb = nsnull;
  gtk_moz_embed_get_nsIWebBrowser(b,&wb);
  nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(wb));
  if (persist) {
    nsCOMPtr<nsILocalFile> file;
    nsAutoString s; s.AssignWithConversion(FullPath);
    NS_NewLocalFile(s, PR_TRUE, getter_AddRefs(file));
    if (!file) return;
    persist->SaveURI(linkURI, nsnull, nsnull, nsnull, nsnull, file);
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean mozilla_save_prefs ( void  )

Definition at line 258 of file mozilla_api.cpp.

{
  nsCOMPtr<nsIPrefService> prefService = do_GetService (PREF_ID);
  g_return_val_if_fail (prefService != nsnull, FALSE);
  nsresult rv = prefService->SavePrefFile (nsnull);
  return NS_SUCCEEDED (rv) ? TRUE : FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function: