aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-01-10 19:43:55 +0800
committerChristian Persch <chpe@src.gnome.org>2004-01-10 19:43:55 +0800
commit468ea4523520f5de74707d42a5167e3f97ad6fba (patch)
tree916ab09b38186730580ad050b2f8402e47a1151a /embed/mozilla
parent137a5961bbd03f74a90927ae1a03ed5e19e5d666 (diff)
downloadgsoc2013-epiphany-468ea4523520f5de74707d42a5167e3f97ad6fba.tar
gsoc2013-epiphany-468ea4523520f5de74707d42a5167e3f97ad6fba.tar.gz
gsoc2013-epiphany-468ea4523520f5de74707d42a5167e3f97ad6fba.tar.bz2
gsoc2013-epiphany-468ea4523520f5de74707d42a5167e3f97ad6fba.tar.lz
gsoc2013-epiphany-468ea4523520f5de74707d42a5167e3f97ad6fba.tar.xz
gsoc2013-epiphany-468ea4523520f5de74707d42a5167e3f97ad6fba.tar.zst
gsoc2013-epiphany-468ea4523520f5de74707d42a5167e3f97ad6fba.zip
Use NS_ENSURE_SUCCESS/NS_ENSURE_TRUE at appropriate places.
2004-01-10 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/mozilla-embed-persist.cpp: * embed/mozilla/mozilla-embed-single.cpp: Use NS_ENSURE_SUCCESS/NS_ENSURE_TRUE at appropriate places.
Diffstat (limited to 'embed/mozilla')
-rw-r--r--embed/mozilla/mozilla-embed-persist.cpp35
-rw-r--r--embed/mozilla/mozilla-embed-single.cpp226
2 files changed, 121 insertions, 140 deletions
diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp
index 2818bb3b4..8f302d713 100644
--- a/embed/mozilla/mozilla-embed-persist.cpp
+++ b/embed/mozilla/mozilla-embed-persist.cpp
@@ -116,7 +116,7 @@ static void
impl_cancel (EphyEmbedPersist *persist)
{
nsCOMPtr<nsIWebBrowserPersist> bpersist =
- MOZILLA_EMBED_PERSIST (persist)->priv->mPersist;
+ MOZILLA_EMBED_PERSIST (persist)->priv->mPersist;
if (bpersist)
{
bpersist->CancelSave ();
@@ -155,17 +155,21 @@ impl_save (EphyEmbedPersist *persist)
if (embed)
{
browser = (EphyBrowser *) _mozilla_embed_get_ephy_browser (MOZILLA_EMBED(embed));
- g_return_val_if_fail (browser != NULL, FALSE);
+ NS_ENSURE_TRUE (browser, FALSE);
}
/* we must have one of uri or browser */
g_assert (browser != NULL || uri != NULL);
/* Get a temp filename to save to */
- nsCOMPtr<nsIProperties> dirService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
- if (!dirService) return FALSE;
+ nsCOMPtr<nsIProperties> dirService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
+ NS_ENSURE_TRUE (dirService, FALSE);
+
nsCOMPtr<nsIFile> tmpFile;
dirService->Get("TmpD", NS_GET_IID(nsIFile), getter_AddRefs(tmpFile));
+ if (!tmpFile) return FALSE;
+
+ /* FIXME: make this filename non-guessable */
static short unsigned int tmpRandom = 0;
nsAutoString tmpNo;
tmpNo.AppendInt(tmpRandom++);
@@ -184,10 +188,10 @@ impl_save (EphyEmbedPersist *persist)
else
{
rv = browser->GetDocumentUrl (sURI);
- if (NS_FAILED(rv)) return FALSE;
+ NS_ENSURE_SUCCESS (rv, FALSE);
}
- rv = NS_NewURI(getter_AddRefs(inURI), sURI);
- if (NS_FAILED(rv) || !inURI) return FALSE;
+ NS_NewURI(getter_AddRefs(inURI), sURI);
+ if (!inURI) return FALSE;
/* Get post data */
nsCOMPtr<nsIInputStream> postData;
@@ -214,13 +218,13 @@ impl_save (EphyEmbedPersist *persist)
{
if (flags & EMBED_PERSIST_MAINDOC)
{
- rv = browser->GetDocument (getter_AddRefs(DOMDocument));
+ browser->GetDocument (getter_AddRefs(DOMDocument));
}
else
{
- rv = browser->GetTargetDocument (getter_AddRefs(DOMDocument));
+ browser->GetTargetDocument (getter_AddRefs(DOMDocument));
}
- if (NS_FAILED(rv) || !DOMDocument) return FALSE;
+ NS_ENSURE_TRUE (DOMDocument, FALSE);
}
@@ -228,7 +232,8 @@ impl_save (EphyEmbedPersist *persist)
nsCOMPtr<nsISupports> pageDescriptor;
if (flags & EMBED_PERSIST_COPY_PAGE)
{
- rv = browser->GetPageDescriptor(getter_AddRefs(pageDescriptor));
+ browser->GetPageDescriptor(getter_AddRefs(pageDescriptor));
+ NS_ENSURE_TRUE (pageDescriptor, FALSE);
}
if (filename == NULL)
@@ -236,7 +241,7 @@ impl_save (EphyEmbedPersist *persist)
/* Create an header sniffer and do the save */
nsCOMPtr<nsIWebBrowserPersist> webPersist =
MOZILLA_EMBED_PERSIST (persist)->priv->mPersist;
- if (!webPersist) return FALSE;
+ NS_ENSURE_TRUE (webPersist, FALSE);
EphyHeaderSniffer* sniffer = new EphyHeaderSniffer
(webPersist, MOZILLA_EMBED_PERSIST (persist),
@@ -251,9 +256,9 @@ impl_save (EphyEmbedPersist *persist)
{
/* Filename to save to */
nsCOMPtr<nsILocalFile> destFile;
- rv = NS_NewNativeLocalFile (nsDependentCString(filename),
- PR_TRUE, getter_AddRefs(destFile));
- if (NS_FAILED(rv) || !destFile) return FALSE;
+ NS_NewNativeLocalFile (nsDependentCString(filename),
+ PR_TRUE, getter_AddRefs(destFile));
+ NS_ENSURE_TRUE (destFile, FALSE);
rv = InitiateMozillaDownload (DOMDocument, inURI, destFile,
nsnull, inURI, MOZILLA_EMBED_PERSIST (persist),
diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp
index 0f13254d6..7d67227a9 100644
--- a/embed/mozilla/mozilla-embed-single.cpp
+++ b/embed/mozilla/mozilla-embed-single.cpp
@@ -186,15 +186,14 @@ mozilla_set_default_prefs (MozillaEmbedSingle *mes)
nsCOMPtr<nsIPrefService> prefService;
prefService = do_GetService (NS_PREFSERVICE_CONTRACTID);
- if (prefService == NULL) return FALSE;
+ NS_ENSURE_TRUE (prefService, FALSE);
/* read our predefined default prefs */
nsresult rv;
nsCOMPtr<nsILocalFile> file;
- rv = NS_NewNativeLocalFile(
- NS_LITERAL_CSTRING(DEFAULT_PROFILE_FILE),
- PR_TRUE, getter_AddRefs(file));
- if (NS_FAILED (rv)) return FALSE;
+ NS_NewNativeLocalFile(NS_LITERAL_CSTRING(DEFAULT_PROFILE_FILE),
+ PR_TRUE, getter_AddRefs(file));
+ if (!file) return FALSE;
rv = prefService->ReadUserPrefs (file);
if (NS_FAILED(rv))
@@ -214,7 +213,7 @@ mozilla_set_default_prefs (MozillaEmbedSingle *mes)
nsCOMPtr<nsIPrefBranch> pref;
prefService->GetBranch ("", getter_AddRefs(pref));
- if (pref == NULL) return FALSE;
+ NS_ENSURE_TRUE (pref, FALSE);
/* FIXME We need to do this because mozilla doesnt set product
sub for embedding apps */
@@ -228,9 +227,9 @@ static char *
color_to_string (GdkColor color)
{
return g_strdup_printf ("#%.2x%.2x%.2x",
- color.red >> 8,
- color.green >> 8,
- color.blue >> 8);
+ color.red >> 8,
+ color.green >> 8,
+ color.blue >> 8);
}
static void
@@ -243,11 +242,11 @@ mozilla_update_colors (GtkWidget *window,
char *str;
prefService = do_GetService (NS_PREFSERVICE_CONTRACTID);
- g_return_if_fail (prefService != NULL);
+ if (!prefService) return;
nsCOMPtr<nsIPrefBranch> pref;
prefService->GetBranch ("", getter_AddRefs(pref));
- g_return_if_fail (pref != NULL);
+ if (!pref) return;
/* Set the bg color to the text bg color*/
color = window->style->base[GTK_STATE_NORMAL];
@@ -409,27 +408,21 @@ mozilla_init_chrome (void)
nsresult result;
nsAutoString uiLang;
- nsCOMPtr<nsIXULChromeRegistry> chromeRegistry = do_GetService (NS_CHROMEREGISTRY_CONTRACTID, &result);
- if (NS_FAILED (result) || !chromeRegistry)
- {
- g_warning ("Could not get the chrome registry!\n");
- return NS_ERROR_FAILURE;
- }
+ nsCOMPtr<nsIXULChromeRegistry> chromeRegistry = do_GetService (NS_CHROMEREGISTRY_CONTRACTID);
+ NS_ENSURE_TRUE (chromeRegistry, NS_ERROR_FAILURE);
// Set skin to 'classic' so we get native scrollbars.
result = chromeRegistry->SelectSkin (NS_LITERAL_CSTRING("classic/1.0"), PR_FALSE);
- if (NS_FAILED (result)) return NS_ERROR_FAILURE;
+ NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
// set locale
- chromeRegistry->SetRuntimeProvider(PR_TRUE);
+ result = chromeRegistry->SetRuntimeProvider(PR_TRUE);
+ NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
result = getUILang(uiLang);
- if (NS_FAILED (result)) return NS_ERROR_FAILURE;
-
- result = chromeRegistry->SelectLocale (NS_ConvertUCS2toUTF8(uiLang), PR_FALSE);
- if (NS_FAILED (result)) return NS_ERROR_FAILURE;
+ NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
- return NS_OK;
+ return chromeRegistry->SelectLocale (NS_ConvertUCS2toUTF8(uiLang), PR_FALSE);
}
static void
@@ -538,38 +531,31 @@ mozilla_embed_single_finalize (GObject *object)
static void
impl_clear_cache (EphyEmbedSingle *shell)
{
- nsresult rv;
- nsCOMPtr<nsICacheService> CacheService =
- do_GetService (NS_CACHESERVICE_CONTRACTID, &rv);
- if (NS_SUCCEEDED (rv))
- {
- CacheService->EvictEntries (nsICache::STORE_ANYWHERE);
- }
+ nsCOMPtr<nsICacheService> cacheService =
+ do_GetService (NS_CACHESERVICE_CONTRACTID);
+ if (!cacheService) return;
+
+ cacheService->EvictEntries (nsICache::STORE_ANYWHERE);
}
static void
impl_clear_auth_cache (EphyEmbedSingle *shell)
{
- nsresult rv;
- nsCOMPtr<nsIHttpAuthManager> AuthManager =
- do_GetService (NS_HTTPAUTHMANAGER_CONTRACTID, &rv);
- if (NS_SUCCEEDED (rv))
- {
- AuthManager->ClearAll();
- }
+ nsCOMPtr<nsIHttpAuthManager> authManager =
+ do_GetService (NS_HTTPAUTHMANAGER_CONTRACTID);
+ if (!authManager) return;
+
+ authManager->ClearAll();
}
static void
impl_set_offline_mode (EphyEmbedSingle *shell,
gboolean offline)
{
- nsresult rv;
+ nsCOMPtr<nsIIOService> io = do_GetService(NS_IOSERVICE_CONTRACTID);
+ if (!io) return;
- nsCOMPtr<nsIIOService> io = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
- if (NS_SUCCEEDED (rv))
- {
- io->SetOffline(offline);
- }
+ io->SetOffline(offline);
}
static void
@@ -578,14 +564,11 @@ impl_load_proxy_autoconf (EphyEmbedSingle *shell,
{
g_assert (url != NULL);
- nsresult rv;
nsCOMPtr<nsIProtocolProxyService> pps =
- do_GetService ("@mozilla.org/network/protocol-proxy-service;1",
- &rv);
- if (NS_SUCCEEDED (rv))
- {
- pps->ConfigureFromPAC (url);
- }
+ do_GetService ("@mozilla.org/network/protocol-proxy-service;1");
+ if (!pps) return;
+
+ pps->ConfigureFromPAC (url);
}
static GList *
@@ -598,18 +581,18 @@ impl_get_font_list (EphyEmbedSingle *shell,
GList *l = NULL;
nsCOMPtr<nsIFontEnumerator> mozFontEnumerator;
- mozFontEnumerator = do_CreateInstance("@mozilla.org/gfx/fontenumerator;1", &rv);
- if(NS_FAILED(rv)) return NULL;
+ mozFontEnumerator = do_CreateInstance("@mozilla.org/gfx/fontenumerator;1");
+ NS_ENSURE_TRUE (mozFontEnumerator, NULL);
rv = mozFontEnumerator->EnumerateFonts (nsnull, nsnull,
&fontCount, &fontArray);
- if (NS_FAILED (rv)) return NULL;
+ NS_ENSURE_SUCCESS (rv, NULL);
for (PRUint32 i = 0; i < fontCount; i++)
{
char *gFontString;
- gFontString = g_strdup(NS_ConvertUCS2toUTF8 (fontArray[i]).get());
+ gFontString = g_strdup (NS_ConvertUCS2toUTF8 (fontArray[i]).get());
l = g_list_prepend (l, gFontString);
nsMemory::Free (fontArray[i]);
}
@@ -627,10 +610,12 @@ impl_list_cookies (EphyCookieManager *manager)
nsCOMPtr<nsICookieManager> cookieManager =
do_GetService (NS_COOKIEMANAGER_CONTRACTID);
+ if (!cookieManager) return NULL;
+
nsCOMPtr<nsISimpleEnumerator> cookieEnumerator;
- result = cookieManager->GetEnumerator (getter_AddRefs(cookieEnumerator));
- if (NS_FAILED(result) || !cookieEnumerator) return NULL;
-
+ cookieManager->GetEnumerator (getter_AddRefs(cookieEnumerator));
+ NS_ENSURE_TRUE (cookieEnumerator, NULL);
+
PRBool enumResult;
for (cookieEnumerator->HasMoreElements(&enumResult) ;
enumResult == PR_TRUE ;
@@ -644,7 +629,7 @@ impl_list_cookies (EphyCookieManager *manager)
cookies = g_list_prepend (cookies, cookie);
}
-
+
return cookies;
}
@@ -652,10 +637,9 @@ static void
impl_remove_cookie (EphyCookieManager *manager,
const EphyCookie *cookie)
{
- nsresult rv;
nsCOMPtr<nsICookieManager> cookieManager =
- do_GetService (NS_COOKIEMANAGER_CONTRACTID, &rv);
- if (NS_FAILED (rv) || !cookieManager) return;
+ do_GetService (NS_COOKIEMANAGER_CONTRACTID);
+ if (!cookieManager) return;
cookieManager->Remove (nsDependentCString(cookie->domain),
nsDependentCString(cookie->name),
@@ -666,29 +650,26 @@ impl_remove_cookie (EphyCookieManager *manager,
static void
impl_clear_cookies (EphyCookieManager *manager)
{
- nsresult rv;
nsCOMPtr<nsICookieManager> cookieManager =
- do_GetService (NS_COOKIEMANAGER_CONTRACTID, &rv);
- if (NS_SUCCEEDED (rv))
- {
- cookieManager->RemoveAll ();
- }
+ do_GetService (NS_COOKIEMANAGER_CONTRACTID);
+ if (!cookieManager) return;
+
+ cookieManager->RemoveAll ();
}
static GList *
impl_list_passwords (EphyPasswordManager *manager)
{
GList *passwords = NULL;
+ nsresult rv;
- nsresult result;
nsCOMPtr<nsIPasswordManager> passwordManager =
do_GetService (NS_PASSWORDMANAGER_CONTRACTID);
if (!passwordManager) return NULL;
nsCOMPtr<nsISimpleEnumerator> passwordEnumerator;
- result = passwordManager->GetEnumerator
- (getter_AddRefs(passwordEnumerator));
- if (NS_FAILED(result) || !passwordEnumerator) return NULL;
+ passwordManager->GetEnumerator (getter_AddRefs(passwordEnumerator));
+ NS_ENSURE_TRUE (passwordEnumerator, NULL);
PRBool enumResult;
for (passwordEnumerator->HasMoreElements(&enumResult) ;
@@ -696,25 +677,26 @@ impl_list_passwords (EphyPasswordManager *manager)
passwordEnumerator->HasMoreElements(&enumResult))
{
nsCOMPtr<nsIPassword> nsPassword;
- result = passwordEnumerator->GetNext
- (getter_AddRefs(nsPassword));
- if (NS_FAILED(result) || !nsPassword) continue;
-
- EphyPasswordInfo *p = g_new0 (EphyPasswordInfo, 1);
+ passwordEnumerator->GetNext (getter_AddRefs(nsPassword));
+ if (!nsPassword) continue;
nsCAutoString transfer;
- nsPassword->GetHost (transfer);
- p->host = g_strdup (transfer.get());
+ rv = nsPassword->GetHost (transfer);
+ if (NS_FAILED (rv)) continue;
nsAutoString unicodeName;
- nsPassword->GetUser (unicodeName);
- p->username = g_strdup(NS_ConvertUCS2toUTF8(unicodeName).get());
+ rv = nsPassword->GetUser (unicodeName);
+ if (NS_FAILED (rv)) continue;
+
+ EphyPasswordInfo *p = g_new0 (EphyPasswordInfo, 1);
+ p->host = g_strdup (transfer.get());
+ p->username = g_strdup(NS_ConvertUCS2toUTF8(unicodeName).get());
p->password = NULL;
passwords = g_list_prepend (passwords, p);
- }
-
+ }
+
return passwords;
}
@@ -724,11 +706,10 @@ impl_remove_password (EphyPasswordManager *manager,
{
nsCOMPtr<nsIPasswordManager> pm =
do_GetService (NS_PASSWORDMANAGER_CONTRACTID);
- if (pm)
- {
- pm->RemoveUser (nsDependentCString(info->host),
- NS_ConvertUTF8toUCS2(nsDependentCString(info->username)));
- }
+ if (!pm) return;
+
+ pm->RemoveUser (nsDependentCString(info->host),
+ NS_ConvertUTF8toUCS2(nsDependentCString(info->username)));
}
static const char *permission_type_string [] =
@@ -747,14 +728,13 @@ impl_permission_manager_add (EphyPermissionManager *manager,
/* can only set allow or deny */
g_return_if_fail (permission != EPHY_PERMISSION_DEFAULT);
- nsresult result;
nsCOMPtr<nsIPermissionManager> pm
- (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID, &result));
- if (NS_FAILED (result) || !pm) return;
+ (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID));
+ if (!pm) return;
nsCOMPtr<nsIURI> uri;
- result = NS_NewURI(getter_AddRefs(uri), host);
- if (NS_FAILED(result) || !uri) return;
+ NS_NewURI(getter_AddRefs(uri), host);
+ if (!uri) return;
gboolean allow = (permission == EPHY_PERMISSION_ALLOWED);
@@ -773,29 +753,25 @@ impl_permission_manager_remove (EphyPermissionManager *manager,
const char *host,
EphyPermissionType type)
{
- nsresult result;
nsCOMPtr<nsIPermissionManager> pm
- (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID, &result));
- if (NS_SUCCEEDED (result))
- {
+ (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID));
+ if (!pm) return;
+
#if MOZILLA_SNAPSHOT >= 10
- pm->Remove (nsDependentCString (host), permission_type_string [type]);
+ pm->Remove (nsDependentCString (host), permission_type_string [type]);
#else
- pm->Remove (nsDependentCString (host), type);
+ pm->Remove (nsDependentCString (host), type);
#endif
- }
}
void
impl_permission_manager_clear (EphyPermissionManager *manager)
{
- nsresult result;
nsCOMPtr<nsIPermissionManager> pm
- (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID, &result));
- if (NS_SUCCEEDED (result))
- {
- pm->RemoveAll ();
- }
+ (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID));
+ if (!pm) return;
+
+ pm->RemoveAll ();
}
EphyPermission
@@ -803,22 +779,22 @@ impl_permission_manager_test (EphyPermissionManager *manager,
const char *host,
EphyPermissionType type)
{
- nsresult result;
nsCOMPtr<nsIPermissionManager> pm
- (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID, &result));
- if (NS_FAILED (result) || !pm) return EPHY_PERMISSION_DEFAULT;
+ (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID));
+ if (!pm) return EPHY_PERMISSION_DEFAULT;
nsCOMPtr<nsIURI> uri;
- result = NS_NewURI(getter_AddRefs(uri), host);
- if (NS_FAILED(result) || !uri) return EPHY_PERMISSION_DEFAULT;
+ NS_NewURI(getter_AddRefs(uri), host);
+ if (!uri) return EPHY_PERMISSION_DEFAULT;
+ nsresult rv;
PRUint32 action;
#if MOZILLA_SNAPSHOT >= 10
- result = pm->TestPermission (uri, permission_type_string [type], &action);
+ rv = pm->TestPermission (uri, permission_type_string [type], &action);
#else
- result = pm->TestPermission (uri, type, &action);
+ rv = pm->TestPermission (uri, type, &action);
#endif
- if (NS_FAILED (result)) return EPHY_PERMISSION_DEFAULT;
+ NS_ENSURE_SUCCESS (rv, EPHY_PERMISSION_DEFAULT);
EphyPermission permission;
@@ -845,32 +821,32 @@ impl_permission_manager_list (EphyPermissionManager *manager,
{
GList *list = NULL;
- nsresult result;
nsCOMPtr<nsIPermissionManager> pm
- (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID, &result));
- if (NS_FAILED (result) || !pm) return NULL;
+ (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID));
+ if (!pm) return NULL;
nsCOMPtr<nsISimpleEnumerator> pe;
- result = pm->GetEnumerator(getter_AddRefs(pe));
- if (NS_FAILED(result) || !pe) return NULL;
+ pm->GetEnumerator(getter_AddRefs(pe));
+ NS_ENSURE_TRUE (pe, NULL);
PRBool more;
for (pe->HasMoreElements (&more); more == PR_TRUE; pe->HasMoreElements (&more))
{
nsCOMPtr<nsIPermission> perm;
- result = pe->GetNext(getter_AddRefs(perm));
- if (NS_FAILED(result) || !perm) continue;
+ pe->GetNext(getter_AddRefs(perm));
+ if (!perm) continue;
+ nsresult rv;
#if MOZILLA_SNAPSHOT >= 10
nsCAutoString str;
- result = perm->GetType(str);
- if (NS_FAILED (result)) continue;
+ rv = perm->GetType(str);
+ if (NS_FAILED (rv)) continue;
if (str.Equals(permission_type_string[type]))
#else
PRUint32 num;
- result = perm->GetType(&num);
- if (NS_FAILED (result)) continue;
+ rv = perm->GetType(&num);
+ if (NS_FAILED (rv)) continue;
if ((PRUint32) num == (PRUint32) type)
#endif