Hiroyuki Ikezoe
ikezo****@users*****
Fri Apr 21 14:56:55 JST 2006
Index: kazehakase/src/mozilla/kz-mozembed.cpp diff -u kazehakase/src/mozilla/kz-mozembed.cpp:1.198 kazehakase/src/mozilla/kz-mozembed.cpp:1.199 --- kazehakase/src/mozilla/kz-mozembed.cpp:1.198 Thu Apr 20 11:08:45 2006 +++ kazehakase/src/mozilla/kz-mozembed.cpp Fri Apr 21 14:56:54 2006 @@ -202,6 +202,9 @@ GList **list, gboolean selected_only); +static gboolean kz_moz_embed_get_dest_anchors (KzEmbed *kzembed, + GList **list); + static void kz_moz_embed_copy_page (KzEmbed *kzembed, KzEmbed *dkzembed); static gboolean kz_moz_embed_shistory_copy (KzEmbed *source, @@ -342,6 +345,7 @@ iface->incremental_search = kz_moz_embed_incremental_search; iface->selection_is_collapsed = kz_moz_embed_selection_is_collapsed; iface->get_links = kz_moz_embed_get_links; + iface->get_dest_anchors = kz_moz_embed_get_dest_anchors; iface->copy_page = kz_moz_embed_copy_page; iface->shistory_copy = kz_moz_embed_shistory_copy; iface->shistory_get_pos = kz_moz_embed_shistory_get_pos; @@ -1921,6 +1925,32 @@ } +static gboolean +kz_moz_embed_get_dest_anchors (KzEmbed *kzembed, GList **list) +{ + g_return_val_if_fail(KZ_IS_MOZ_EMBED(kzembed), FALSE); + KzMozEmbed *mozembed = KZ_MOZ_EMBED(kzembed); + KzMozEmbedPrivate *priv = KZ_MOZ_EMBED_GET_PRIVATE (kzembed); + g_return_val_if_fail(priv->wrapper, FALSE); + g_return_val_if_fail(list, FALSE); + + // get all anchor nodes in the document. + nsCOMPtr<nsIDOMDocument> mainDoc; + nsresult rv = priv->wrapper->GetMainDomDocument(getter_AddRefs(mainDoc)); + if (NS_FAILED(rv) || !mainDoc) return FALSE; + + // get main DOMWindow + nsCOMPtr<nsIDOMWindow> mainDOMWindow; + rv = priv->wrapper->GetDOMWindow(getter_AddRefs(mainDOMWindow)); + if (NS_FAILED(rv)) return FALSE; + + rv = priv->wrapper->GetDestAnchorsFromWindow(mainDOMWindow, + list); + + return NS_FAILED(rv) ? FALSE : TRUE; +} + + glong kz_moz_embed_get_key_event_info(KzMozEmbed *kzembed, gpointer event, KzEmbedEventKey **info_ret) Index: kazehakase/src/mozilla/kz-mozwrapper.cpp diff -u kazehakase/src/mozilla/kz-mozwrapper.cpp:1.108 kazehakase/src/mozilla/kz-mozwrapper.cpp:1.109 --- kazehakase/src/mozilla/kz-mozwrapper.cpp:1.108 Fri Feb 24 03:38:14 2006 +++ kazehakase/src/mozilla/kz-mozwrapper.cpp Fri Apr 21 14:56:54 2006 @@ -1553,6 +1553,86 @@ } nsresult +KzMozWrapper::GetDestAnchorsFromWindow (nsIDOMWindow *domWindow, + GList **list) +{ + nsresult rv; + PRUint32 num = 0; + gboolean flag = FALSE; + const PRUnichar aLiteral[] = { 'a', '\0' }; + + // get frame window + nsCOMPtr<nsIDOMWindowCollection> frames; + domWindow->GetFrames(getter_AddRefs(frames)); + + if (frames) + { + frames->GetLength(&num); + } + + if (num != 0) + { + for (PRUint32 i = 0; i < num; i++) + { + nsCOMPtr<nsIDOMWindow> childWindow; + frames->Item(i, getter_AddRefs(childWindow)); + rv = GetLinksFromWindow(childWindow, list, + NULL, TRUE); + if (NS_SUCCEEDED(rv)) + flag |= TRUE; + } + } + else + { + nsCOMPtr<nsIDOMDocument> domDoc; + domWindow->GetDocument(getter_AddRefs(domDoc)); + + nsCOMPtr<nsIDOMNodeList> nodeList; + rv = domDoc->GetElementsByTagName(nsEmbedString(aLiteral), + getter_AddRefs(nodeList)); + if (NS_FAILED(rv) || !nodeList) return NS_ERROR_FAILURE; + + PRUint32 num; + rv = nodeList->GetLength(&num); + if (NS_FAILED(rv) || num < 1) return NS_ERROR_FAILURE; + + // store links to GList + nsCOMPtr<nsIDOMNode> node; + for (PRUint32 i = 0; i < num; i++) + { + rv = nodeList->Item(i, getter_AddRefs(node)); + if (NS_FAILED(rv) || !node) continue; + + // check the node has name attribute or id attribure. + char *value = NULL; + GetAttributeFromNode(node, "name", &value); + if (!value) + GetAttributeFromNode(node, "id", &value); + if (!value) + continue; + + char *uri; + nsEmbedCString cValue,cURI; + cValue.Assign(value); + g_free(value); + + ResolveURI(domDoc, cValue, cURI); + + uri = g_strdup(cURI.get()); + + KzBookmark *link; + link = kz_bookmark_new_with_attrs(NULL, uri, NULL); + *list = g_list_append(*list, link); + g_free(uri); + + flag |= TRUE; + } + } + + return flag ? NS_OK : NS_ERROR_FAILURE; +} + +nsresult KzMozWrapper::GetLinksFromWindow (nsIDOMWindow *domWindow, GList **list, nsISelection *selection, @@ -1672,20 +1752,7 @@ nsEmbedCString hrefc,linkc; hrefc.Assign(hrefattr); - nsCOMPtr<nsIDOM3Node> domnode = do_QueryInterface(domDoc); - if(!domnode) return NS_ERROR_FAILURE; - - nsEmbedString spec; - domnode->GetBaseURI(spec); - - nsEmbedCString cSpec; - NS_UTF16ToCString(spec, - NS_CSTRING_ENCODING_UTF8, cSpec); - - nsCOMPtr<nsIURI> baseURI; - NewURI(getter_AddRefs(baseURI), cSpec.get()); - - nsresult rv = baseURI->Resolve(hrefc,linkc); + ResolveURI(domDoc, hrefc, linkc); *url = g_strdup(linkc.get()); Index: kazehakase/src/mozilla/kz-mozwrapper.h diff -u kazehakase/src/mozilla/kz-mozwrapper.h:1.50 kazehakase/src/mozilla/kz-mozwrapper.h:1.51 --- kazehakase/src/mozilla/kz-mozwrapper.h:1.50 Sat Oct 1 02:27:54 2005 +++ kazehakase/src/mozilla/kz-mozwrapper.h Fri Apr 21 14:56:54 2006 @@ -127,6 +127,8 @@ GList **list, nsISelection *selection, gboolean selected_only); + nsresult GetDestAnchorsFromWindow (nsIDOMWindow *domWindow, + GList **list); nsresult GetPostData (nsIHistoryEntry *he, nsAString &postData); nsresult SetPostData (nsIHistoryEntry *he,