右クリックメニュー(2) リンク先・画像のURIを取得
はい、要するに、clickしたもののURIを取得します。これは簡単。
リンク先のURIの取得
- nsIContextMenuInfo::GetAssociatedLink(nsAString&)
文字列(nsString : UTF-16)でもらう。
sampleは、こんな感じ。
// * link先のURI(文字列)とURI(nsIURI)を取得 //* これだけではないけど // #include <webbrwsr/nsIContextMenuListener2.h> // #include <necko/nsNetUtil.h> // #include <nsIURI.h> NS_IMETHODIMP nmnWebBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aUtils) { if (aContextFlags & nsIContextMenuListener2::CONTEXT_LINK) { nsString targetstring; aUtils->GetAssociatedLink(targetstring); // nsIURIに変換 // * nsNetUtil.h::NS_NewURI(nsIURI**, nsACString&) // * nsACStringはこの場合、UTF-8をほりこむ。よって、要変換。 nsCOMPtr<nsIURI> targeturi; NS_NewURI(getter_AddRefs(targeturi), NS_ConvertUTF16toUTF8(targetstring)); //あとはほげほげ } return NS_OK; }
画像のURIの取得
- nsIContextMenuInfo::GetImageSrc(nsIURI**)
URI(nsIURI)でもらう。
NS_IMETHODIMP nmnWebBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aUtils) { if (aContextFlags & nsIContextMenuListener2::CONTEXT_IMAGE) { nsCOMPtr<nsIURI> imgsrc; aUtils->GetImageSrc(getter_AddRefs(imgsrc)); //あとはほげほげ } return NS_OK; }
で、なんで違うの?
…さぁ?
reference
- Mozillaのsrc
- webbrwsr/nsIContextMenuListener2.h
- necko/nsNetUtil.h