aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla
diff options
context:
space:
mode:
Diffstat (limited to 'embed/mozilla')
-rw-r--r--embed/mozilla/EphyBrowser.cpp102
-rw-r--r--embed/mozilla/EphyBrowser.h4
-rw-r--r--embed/mozilla/MozRegisterComponents.cpp2
-rw-r--r--embed/mozilla/mozilla-embed.cpp46
4 files changed, 64 insertions, 90 deletions
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 01e0d60ca..157dceba6 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -638,6 +638,8 @@ nsresult EphyBrowser::GetTargetDocumentUrl (nsCString &url)
nsresult EphyBrowser::ForceEncoding (const char *encoding)
{
+ NS_ENSURE_TRUE (mInitialized, NS_ERROR_FAILURE);
+
nsCOMPtr<nsIContentViewer> contentViewer;
GetContentViewer (getter_AddRefs(contentViewer));
NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE);
@@ -645,107 +647,53 @@ nsresult EphyBrowser::ForceEncoding (const char *encoding)
nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer);
NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE);
- nsresult result;
- result = mdv->SetForceCharacterSet (nsDependentCString(encoding));
-
- return result;
+ return mdv->SetForceCharacterSet (nsDependentCString(encoding));
}
-nsresult EphyBrowser::PushTargetDocument (nsIDOMDocument *domDoc)
+nsresult EphyBrowser::GetEncoding (nsACString &encoding)
{
- mTargetDocument = domDoc;
-
- return NS_OK;
-}
-
-nsresult EphyBrowser::PopTargetDocument ()
-{
- mTargetDocument = nsnull;
-
- return NS_OK;
-}
-
-nsresult EphyBrowser::GetEncodingInfo (EphyEncodingInfo **infoptr)
-{
- nsresult result;
- EphyEncodingInfo *info;
+ NS_ENSURE_TRUE (mInitialized, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMDocument> domDoc;
GetTargetDocument (getter_AddRefs(domDoc));
NS_ENSURE_TRUE (domDoc, NS_ERROR_FAILURE);
- nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &result);
+ nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE);
- info = g_new0 (EphyEncodingInfo, 1);
- *infoptr = info;
-
- PRInt32 source;
- source = doc->GetDocumentCharacterSetSource ();
- info->encoding_source = (EphyEncodingSource) source;
-
- nsCOMPtr<nsIDocShell> ds;
- ds = do_GetInterface (mWebBrowser);
- NS_ENSURE_TRUE (ds, NS_ERROR_FAILURE);
-
- nsCOMPtr<nsIDocumentCharsetInfo> ci;
- result = ds->GetDocumentCharsetInfo (getter_AddRefs (ci));
- NS_ENSURE_TRUE (ci, NS_ERROR_FAILURE);
-
- nsCOMPtr<nsIAtom> atom;
- ci->GetForcedCharset (getter_AddRefs (atom));
- if (atom)
- {
- nsCAutoString atomstr;
- atom->ToUTF8String (atomstr);
- info->forced_encoding = g_strdup (atomstr.get());
- }
+ encoding = doc->GetDocumentCharacterSet ();
+ NS_ENSURE_TRUE (!encoding.IsEmpty(), NS_ERROR_FAILURE);
- ci->GetParentCharset (getter_AddRefs (atom));
- if (atom)
- {
- nsCAutoString atomstr;
- atom->ToUTF8String (atomstr);
- info->parent_encoding = g_strdup (atomstr.get());
- }
+ return NS_OK;
+}
- result = ci->GetParentCharsetSource (&source);
- NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
- info->parent_encoding_source = (EphyEncodingSource) source;
+nsresult EphyBrowser::GetForcedEncoding (nsACString &encoding)
+{
+ NS_ENSURE_TRUE (mInitialized, NS_ERROR_FAILURE);
nsCOMPtr<nsIContentViewer> contentViewer;
- ds->GetContentViewer (getter_AddRefs(contentViewer));
+ GetContentViewer (getter_AddRefs(contentViewer));
NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE);
nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer);
NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE);
- const nsACString& charsetEnc = doc->GetDocumentCharacterSet ();
- NS_ENSURE_TRUE (!charsetEnc.IsEmpty(), NS_ERROR_FAILURE);
-
- info->encoding = g_strdup (PromiseFlatCString(charsetEnc).get());
-
- nsCAutoString enc;
-
- result = mdv->GetDefaultCharacterSet (enc);
+ nsresult result = mdv->GetForceCharacterSet (encoding);
NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
- info->default_encoding = g_strdup (enc.get());
- result = mdv->GetForceCharacterSet (enc);
- NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
- info->forced_encoding = g_strdup (enc.get());
+ return NS_OK;
+}
- result = mdv->GetHintCharacterSet (enc);
- NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
- info->hint_encoding = g_strdup (enc.get());
+nsresult EphyBrowser::PushTargetDocument (nsIDOMDocument *domDoc)
+{
+ mTargetDocument = domDoc;
- result = mdv->GetPrevDocCharacterSet (enc);
- NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
- info->prev_doc_encoding = g_strdup (enc.get());
+ return NS_OK;
+}
- mdv->GetHintCharacterSetSource (&source);
- NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE);
- info->hint_encoding_source = (EphyEncodingSource) source;
+nsresult EphyBrowser::PopTargetDocument ()
+{
+ mTargetDocument = nsnull;
return NS_OK;
}
diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h
index 16a967c3b..4fef54986 100644
--- a/embed/mozilla/EphyBrowser.h
+++ b/embed/mozilla/EphyBrowser.h
@@ -101,8 +101,8 @@ public:
nsresult GoToHistoryIndex (PRInt16 index);
nsresult ForceEncoding (const char *encoding);
-
- nsresult GetEncodingInfo (EphyEncodingInfo **infoptr);
+ nsresult GetEncoding (nsACString &encoding);
+ nsresult GetForcedEncoding (nsACString &encoding);
nsresult PushTargetDocument (nsIDOMDocument *domDoc);
nsresult PopTargetDocument ();
diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp
index fc5c92a85..a99f15b10 100644
--- a/embed/mozilla/MozRegisterComponents.cpp
+++ b/embed/mozilla/MozRegisterComponents.cpp
@@ -182,7 +182,7 @@ mozilla_register_components (void)
NS_GetComponentManager (getter_AddRefs (cm));
NS_ENSURE_TRUE (cm, FALSE);
- for (int i = 0; i < G_N_ELEMENTS (sAppComps); i++)
+ for (guint i = 0; i < G_N_ELEMENTS (sAppComps); i++)
{
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory),
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index 82b8adf14..4452fa334 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -724,31 +724,56 @@ impl_set_encoding (EphyEmbed *embed,
{
MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv;
nsresult result;
+ nsCAutoString currEnc;
- result = mpriv->browser->ForceEncoding (encoding);
+ g_return_if_fail (encoding != NULL);
+
+ result = mpriv->browser->GetEncoding (currEnc);
if (NS_FAILED (result)) return;
+ if (!currEnc.Equals(encoding) ||
+ encoding[0] == '\0' && !ephy_embed_has_automatic_encoding (embed))
+ {
+ result = mpriv->browser->ForceEncoding (encoding);
+ if (NS_FAILED (result)) return;
+ }
+
gtk_moz_embed_reload (GTK_MOZ_EMBED (embed),
GTK_MOZ_EMBED_FLAG_RELOADCHARSETCHANGE);
}
-static EphyEncodingInfo *
-impl_get_encoding_info (EphyEmbed *embed)
+static char *
+impl_get_encoding (EphyEmbed *embed)
{
MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv;
nsresult result;
- EphyEncodingInfo *info = NULL;
+ nsCAutoString encoding;
- result = mpriv->browser->GetEncodingInfo (&info);
+ result = mpriv->browser->GetEncoding (encoding);
- if (NS_FAILED (result))
+ if (NS_FAILED (result) || encoding.IsEmpty())
{
- ephy_encoding_info_free (info);
-
return NULL;
}
- return info;
+ return g_strdup (encoding.get());
+}
+
+static gboolean
+impl_has_automatic_encoding (EphyEmbed *embed)
+{
+ MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv;
+ nsresult result;
+ nsCAutoString encoding;
+
+ result = mpriv->browser->GetForcedEncoding (encoding);
+
+ if (NS_FAILED (result) || encoding.IsEmpty())
+ {
+ return TRUE;
+ }
+
+ return FALSE;
}
static gboolean
@@ -1103,7 +1128,8 @@ ephy_embed_iface_init (EphyEmbedIface *iface)
iface->activate = impl_activate;
iface->find_set_properties = impl_find_set_properties;
iface->set_encoding = impl_set_encoding;
- iface->get_encoding_info = impl_get_encoding_info;
+ iface->get_encoding = impl_get_encoding;
+ iface->has_automatic_encoding = impl_has_automatic_encoding;
iface->print = impl_print;
iface->print_preview_close = impl_print_preview_close;
iface->print_preview_n_pages = impl_print_preview_n_pages;