Index: embed/mozilla/EventContext.h =================================================================== RCS file: /cvs/gnome/epiphany/embed/mozilla/EventContext.h,v retrieving revision 1.14 diff -p -u -u -p -U5 -r1.14 EventContext.h --- embed/mozilla/EventContext.h 23 Jan 2005 15:38:02 -0000 1.14 +++ embed/mozilla/EventContext.h 29 Apr 2005 21:45:57 -0000 @@ -33,10 +33,15 @@ #include #include #include #include #include +#include + +#ifdef ALLOW_PRIVATE_API +#include +#endif class EventContext { public: EventContext(); @@ -49,10 +54,12 @@ public: private: EphyBrowser *mBrowser; MozillaEmbedEvent *mEmbedEvent; nsCOMPtr mDOMDocument; + nsCOMPtr mURI; + nsCOMPtr mViewCSS; nsresult GetTargetCoords (nsIDOMEventTarget *aTarget, PRInt32 *aX, PRInt32 *aY); nsresult GatherTextUnder (nsIDOMNode* aNode, nsAString& aResult); nsresult ResolveBaseURL (const nsAString &relurl, nsACString &url); nsresult Unescape (const nsACString &aEscaped, nsACString &aUnescaped); @@ -63,8 +70,10 @@ private: nsresult CheckInput (nsIDOMNode *node); nsresult CheckLinkScheme (const nsAString &link); nsresult SetIntProperty (const char *name, int value); nsresult SetStringProperty (const char *name, const char *value); nsresult SetStringProperty (const char *name, const nsAString &value); + nsresult SetURIProperty (const char *name, const nsAString &value); + nsresult SetURIProperty (const char *name, const nsACString &value); }; #endif Index: embed/mozilla/EventContext.cpp =================================================================== RCS file: /cvs/gnome/epiphany/embed/mozilla/EventContext.cpp,v retrieving revision 1.52 diff -p -u -u -p -U5 -r1.52 EventContext.cpp --- embed/mozilla/EventContext.cpp 26 Apr 2005 12:01:39 -0000 1.52 +++ embed/mozilla/EventContext.cpp 29 Apr 2005 21:45:57 -0000 @@ -24,14 +24,16 @@ #include "config.h" #include "EventContext.h" #include "EphyUtils.h" +#include "ephy-debug.h" #include #include +#include #include #undef MOZILLA_INTERNAL_API #include #define MOZILLA_INTERNAL_API 1 #include @@ -63,14 +65,16 @@ #define KEY_CODE 256 EventContext::EventContext () { + LOG ("EventContext ctor [%p]", this); } EventContext::~EventContext () { + LOG ("EventContext dtor [%p]", this); } nsresult EventContext::Init (EphyBrowser *browser) { mBrowser = browser; @@ -157,24 +161,16 @@ nsresult EventContext::GatherTextUnder ( return NS_OK; } nsresult EventContext::ResolveBaseURL (const nsAString &relurl, nsACString &url) { - nsresult rv; - - nsCOMPtr node(do_QueryInterface (mDOMDocument)); - nsEmbedString spec; - node->GetBaseURI (spec); - - nsCOMPtr base; - rv = EphyUtils::NewURI (getter_AddRefs(base), spec); - if (!base) return NS_ERROR_FAILURE; + if (!mURI) return NS_ERROR_NOT_INITIALIZED; nsEmbedCString cRelURL; NS_UTF16ToCString (relurl, NS_CSTRING_ENCODING_UTF8, cRelURL); - return base->Resolve (cRelURL, url); + return mURI->Resolve (cRelURL, url); } nsresult EventContext::Unescape (const nsACString &aEscaped, nsACString &aUnescaped) { if (!aEscaped.Length()) return NS_ERROR_FAILURE; @@ -225,19 +221,44 @@ nsresult EventContext::GetEventContext ( nsCOMPtr domDoc; rv = node->GetOwnerDocument(getter_AddRefs(domDoc)); if (NS_FAILED(rv) || !domDoc) return NS_ERROR_FAILURE; - mDOMDocument = domDoc; - nsCOMPtr xul_document = do_QueryInterface(domDoc); if (xul_document) { info->context = EPHY_EMBED_CONTEXT_NONE; return NS_ERROR_FAILURE; } + mDOMDocument = domDoc; + + /* Get base URI and CSS view */ + nsCOMPtr docView (do_QueryInterface (domDoc)); + NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); + + nsCOMPtr abstractView; + docView->GetDefaultView (getter_AddRefs (abstractView)); + NS_ENSURE_TRUE (abstractView, NS_ERROR_FAILURE); + /* the abstract view is really the DOM window */ + + nsCOMPtr webNav (do_GetInterface (abstractView, &rv)); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr uri; + rv = webNav->GetCurrentURI (getter_AddRefs (uri)); + NS_ENSURE_SUCCESS (rv, rv); + + rv = uri->Clone (getter_AddRefs (mURI)); + NS_ENSURE_SUCCESS (rv, rv); + + /* Hide password part in resolved URIs */ + mURI->SetPassword (nsEmbedCString()); + + mViewCSS = do_QueryInterface (abstractView); + NS_ENSURE_TRUE (mViewCSS, NS_ERROR_FAILURE); + // Now we know that the page isn't a xul window, we can try and // do something useful with it. PRUint16 type; rv = node->GetNodeType(&type); @@ -363,11 +384,11 @@ nsresult EventContext::GetEventContext ( { info->context |= EPHY_EMBED_CONTEXT_LINK; dom_elem->GetAttributeNS (nsEmbedString(xlinknsLiteral), nsEmbedString(hrefLiteral), value); - SetStringProperty ("link", value); + SetURIProperty ("link", value); CheckLinkScheme (value); } } rv = node->GetNodeType(&type); @@ -419,11 +440,11 @@ nsresult EventContext::GetEventContext ( if (anchor && tmp.Length()) { info->context |= EPHY_EMBED_CONTEXT_LINK; - SetStringProperty ("link", tmp); + SetURIProperty ("link", tmp); CheckLinkScheme (tmp); rv = anchor->GetHreflang (tmp); if (NS_SUCCEEDED(rv)) SetStringProperty ("link_lang", tmp); rv = anchor->GetTarget (tmp); @@ -489,11 +510,11 @@ nsresult EventContext::GetEventContext ( nsEmbedString href; rv = area->GetHref (href); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - SetStringProperty ("link", href); + SetURIProperty ("link", href); CheckLinkScheme (href); } } else if (g_ascii_strcasecmp (tag.get(), "input") == 0) { @@ -531,30 +552,23 @@ nsresult EventContext::GetEventContext ( return NS_OK; } nsresult EventContext::GetCSSBackground (nsIDOMNode *node, nsAString& url) { + if (!mViewCSS) return NS_ERROR_NOT_INITIALIZED; + nsresult rv; const PRUnichar bgimage[] = {'b', 'a', 'c', 'k', 'g', 'r', 'o', 'u', 'n', 'd', '-', 'i', 'm', 'a', 'g', 'e', '\0'}; nsCOMPtr element = do_QueryInterface (node); NS_ENSURE_TRUE (element, NS_ERROR_FAILURE); - nsCOMPtr docView = do_QueryInterface (mDOMDocument); - NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); - - nsCOMPtr abstractView; - docView->GetDefaultView (getter_AddRefs (abstractView)); - - nsCOMPtr viewCSS = do_QueryInterface (abstractView); - NS_ENSURE_TRUE (viewCSS, NS_ERROR_FAILURE); - nsCOMPtr decl; - viewCSS->GetComputedStyle (element, nsEmbedString(), - getter_AddRefs (decl)); + mViewCSS->GetComputedStyle (element, nsEmbedString(), + getter_AddRefs (decl)); NS_ENSURE_TRUE (decl, NS_ERROR_FAILURE); nsCOMPtr CSSValue; decl->GetPropertyCSSValue (nsEmbedString(bgimage), getter_AddRefs (CSSValue)); @@ -881,6 +895,31 @@ nsresult EventContext::SetStringProperty nsresult EventContext::SetStringProperty (const char *name, const nsAString &value) { nsEmbedCString cValue; NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); return SetStringProperty (name, cValue.get()); +} + +nsresult EventContext::SetURIProperty (const char *name, const nsACString &value) +{ + nsresult rv; + nsCOMPtr uri; + rv = EphyUtils::NewURI (getter_AddRefs (uri), value, nsnull /* use origin charset of mURI */, mURI); + if (NS_SUCCEEDED (rv)) + { + /* Hide password part */ + uri->SetPassword (nsEmbedCString()); + + nsEmbedCString spec; + uri->GetSpec (spec); + return SetStringProperty (name, spec.get()); + } + + return SetStringProperty (name, nsEmbedCString(value).get()); +} + +nsresult EventContext::SetURIProperty (const char *name, const nsAString &value) +{ + nsEmbedCString cValue; + NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); + return SetURIProperty (name, cValue); } Index: embed/mozilla/EphyBrowser.h =================================================================== RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyBrowser.h,v retrieving revision 1.38 diff -p -u -u -p -U5 -r1.38 EphyBrowser.h --- embed/mozilla/EphyBrowser.h 8 Apr 2005 12:58:18 -0000 1.38 +++ embed/mozilla/EphyBrowser.h 29 Apr 2005 21:45:58 -0000 @@ -161,12 +161,12 @@ public: nsresult PushTargetDocument (nsIDOMDocument *domDoc); nsresult PopTargetDocument (); nsresult GetDocument (nsIDOMDocument **aDOMDocument); nsresult GetTargetDocument (nsIDOMDocument **aDOMDocument); - nsresult GetDocumentUrl (nsACString &url); - nsresult GetTargetDocumentUrl (nsACString &url); + nsresult GetDocumentURI (nsIURI **aURI); + nsresult GetTargetDocumentURI (nsIURI **aURI); nsresult GetDOMWindow (nsIDOMWindow **window); nsresult GetHasModifiedForms (PRBool *modified); nsresult GetSecurityInfo (PRUint32 *aState, nsACString &aDescription); Index: embed/mozilla/EphyBrowser.cpp =================================================================== RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyBrowser.cpp,v retrieving revision 1.78 diff -p -u -u -p -U5 -r1.78 EphyBrowser.cpp --- embed/mozilla/EphyBrowser.cpp 8 Apr 2005 12:58:18 -0000 1.78 +++ embed/mozilla/EphyBrowser.cpp 29 Apr 2005 21:45:58 -0000 @@ -274,23 +274,23 @@ EphyDOMLinkEventListener::GetDocURI (nsI nsIURI **aDocURI) { nsCOMPtr domDoc; aElement->GetOwnerDocument (getter_AddRefs(domDoc)); - nsCOMPtr doc (do_QueryInterface (domDoc)); - NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); + nsCOMPtr docView (do_QueryInterface (domDoc)); + NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); - nsresult rv; - nsEmbedString spec; - rv = doc->GetDocumentURI (spec); - NS_ENSURE_SUCCESS (rv, rv); + nsCOMPtr abstractView; + docView->GetDefaultView (getter_AddRefs (abstractView)); + NS_ENSURE_TRUE (abstractView, NS_ERROR_FAILURE); + /* the abstract view is really the DOM window */ - nsEmbedCString encoding; - rv = mOwner->GetEncoding (encoding); + nsresult rv; + nsCOMPtr webNav (do_GetInterface (abstractView, &rv)); NS_ENSURE_SUCCESS (rv, rv); - return EphyUtils::NewURI (aDocURI, spec, encoding.get()); + return webNav->GetCurrentURI (aDocURI); } NS_IMETHODIMP EphyPopupBlockEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) { @@ -963,52 +963,42 @@ nsresult EphyBrowser::GetDOMWindow (nsID NS_IF_ADDREF (*aDOMWindow = mDOMWindow); return NS_OK; } -nsresult EphyBrowser::GetDocumentUrl (nsACString &url) +nsresult EphyBrowser::GetDocumentURI (nsIURI **aURI) { - nsresult rv; - - NS_ENSURE_TRUE (mDOMWindow, NS_ERROR_FAILURE); - - nsCOMPtr DOMDocument; - mDOMWindow->GetDocument (getter_AddRefs(DOMDocument)); - NS_ENSURE_TRUE (DOMDocument, NS_ERROR_FAILURE); - - nsCOMPtr doc = do_QueryInterface(DOMDocument); - NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); + if (!mDOMWindow) return NS_ERROR_NOT_INITIALIZED; - nsEmbedString docURI; - rv = doc->GetDocumentURI (docURI); + nsresult rv; + nsCOMPtr webNav (do_GetInterface (mDOMWindow, &rv)); NS_ENSURE_SUCCESS (rv, rv); - NS_UTF16ToCString (docURI, NS_CSTRING_ENCODING_UTF8, url); - - return NS_OK; + return webNav->GetCurrentURI (aURI); } -nsresult EphyBrowser::GetTargetDocumentUrl (nsACString &url) +nsresult EphyBrowser::GetTargetDocumentURI (nsIURI **aURI) { - nsresult rv; + if (!mWebBrowser) return NS_ERROR_NOT_INITIALIZED; - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + nsCOMPtr domDoc; + GetTargetDocument (getter_AddRefs(domDoc)); + NS_ENSURE_TRUE (domDoc, NS_ERROR_FAILURE); - nsCOMPtr DOMDocument; - GetTargetDocument (getter_AddRefs(DOMDocument)); - NS_ENSURE_TRUE (DOMDocument, NS_ERROR_FAILURE); + nsCOMPtr docView (do_QueryInterface (domDoc)); + NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); - nsCOMPtr doc = do_QueryInterface(DOMDocument); - NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); + nsCOMPtr abstractView; + docView->GetDefaultView (getter_AddRefs (abstractView)); + NS_ENSURE_TRUE (abstractView, NS_ERROR_FAILURE); + /* the abstract view is really the DOM window */ - nsEmbedString docURI; - rv = doc->GetDocumentURI (docURI); + nsresult rv; + nsCOMPtr webNav (do_GetInterface (abstractView, &rv)); NS_ENSURE_SUCCESS (rv, rv); - NS_UTF16ToCString (docURI, NS_CSTRING_ENCODING_UTF8, url); - - return NS_OK; + return webNav->GetCurrentURI (aURI); } nsresult EphyBrowser::ForceEncoding (const char *encoding) { NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); Index: embed/mozilla/mozilla-embed.cpp =================================================================== RCS file: /cvs/gnome/epiphany/embed/mozilla/mozilla-embed.cpp,v retrieving revision 1.102 diff -p -u -u -p -U5 -r1.102 mozilla-embed.cpp --- embed/mozilla/mozilla-embed.cpp 6 Apr 2005 14:29:55 -0000 1.102 +++ embed/mozilla/mozilla-embed.cpp 29 Apr 2005 21:45:58 -0000 @@ -477,28 +477,34 @@ impl_get_js_status (EphyEmbed *embed) static char * impl_get_location (EphyEmbed *embed, gboolean toplevel) { MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - char *l; nsresult rv; - nsEmbedCString url; + nsCOMPtr uri; if (toplevel) { - rv = mpriv->browser->GetDocumentUrl (url); - l = (NS_SUCCEEDED (rv) && url.Length()) ? - g_strdup (url.get()) : NULL; + rv = mpriv->browser->GetDocumentURI (getter_AddRefs (uri)); } else { - rv = mpriv->browser->GetTargetDocumentUrl (url); - l = (NS_SUCCEEDED (rv) && url.Length()) ? - g_strdup (url.get()) : NULL; + rv = mpriv->browser->GetTargetDocumentURI (getter_AddRefs (uri)); } - return l; + if (NS_FAILED (rv)) return NULL; + + nsCOMPtr furi; + rv = uri->Clone (getter_AddRefs (furi)); + if (NS_FAILED (rv)) return NULL; + + furi->SetPassword (nsEmbedCString()); + + nsEmbedCString url; + furi->GetSpec (url); + + return url.Length() ? g_strdup (url.get()) : NULL; } static void impl_reload (EphyEmbed *embed, gboolean force) Index: src/ephy-tab.c =================================================================== RCS file: /cvs/gnome/epiphany/src/ephy-tab.c,v retrieving revision 1.141 diff -p -u -u -p -U5 -r1.141 ephy-tab.c --- src/ephy-tab.c 19 Apr 2005 09:37:13 -0000 1.141 +++ src/ephy-tab.c 29 Apr 2005 21:45:59 -0000 @@ -1107,13 +1107,16 @@ ephy_tab_link_message_cb (EphyEmbed *emb { ephy_tab_set_link_message (tab, ephy_embed_get_link_message (embed)); } static void -ephy_tab_address_cb (EphyEmbed *embed, const char *address, EphyTab *tab) +ephy_tab_address_cb (EphyEmbed *embed, + const char *address, + EphyTab *tab) { const char *uv_address; + char *freeme = NULL; LOG ("ephy_tab_address_cb tab %p address %s", tab, address); /* Do not expose about:blank to the user, an empty address bar will do better */ @@ -1121,21 +1124,23 @@ ephy_tab_address_cb (EphyEmbed *embed, c { uv_address = ""; } else { - uv_address = address; + uv_address = freeme = ephy_embed_get_location (embed, TRUE); } if (tab->priv->address_expire == EPHY_TAB_ADDRESS_EXPIRE_NOW) { ephy_tab_set_location (tab, uv_address, EPHY_TAB_ADDRESS_EXPIRE_NOW); } ephy_tab_set_link_message (tab, NULL); ephy_tab_set_icon_address (tab, NULL); ephy_tab_update_navigation_flags (tab, embed); + + g_free (freeme); } static void ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab) {