使用XPCOM从FireFox获取URL f [英] Getting URL ffrom FireFox Using XPCOM

查看:122
本文介绍了使用XPCOM从FireFox获取URL f的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,该应用程序会在每个页面加载(用户输入的每个URL ...)中从Firefox获取URL.不使用javascript ...……

直到我创建了自动启动的组件.我注册了AddProgressListener(NOTIFY_STATE_ALL | NOTIFY_ALL)….
但是我无法获取OnStateChange()事件.我尝试了很多,但仍然遇到问题.我在i-net上搜索了代码,但是这使我感到困惑.
我在下面发送代码.我保证这是短代码(不是很大的东西.).它是Build并且正在运行程序….
您能不能用经验丰富的眼睛看一下?您可以更改代码.

还有一个问题.....

每个请求都调用OnState更改吗?

要获取url,我必须浏览所有打开的选项卡?(是否有任何方法可以直接获取url而无需执行此操作……).
希望您能帮助我……………………
等待您的答复…………..

萨钦·库特瓦德(Sachin Khutwad).

我实现了

I am creating application which gets URL from Firefox on every pageload(every url entered by user…).Without using javascript………

Uptil I have created component which is starting up automatically . I registered for AddProgressListener (NOTIFY_STATE_ALL | NOTIFY_ALL)….
But I am unable to get OnStateChange() event. I tried a lot but am still having problems. I searched codes on the i-net but it confuses me.
I am sending code below. I promise it is short code(not big stuff..). it is Build and running program….
Will you please take look by your experienced eyes? You can do changes in code.

And one one other question…..

OnState change is called for every request?

For getting url I have to navigate through all the tabs which are opened?(is there any way to get url directly without doing this stuff…).
I hope you will help me…………………
Waiting for your reply…………..

Sachin Khutwad.

I implemented

class MyComponent : public IMyComponent, public nsIWebProgressListener, public nsIObserver
{
}


在我的watch()方法中,以下代码是:::


in my observe() method following is code ::

NS_IMETHODIMP MyComponent::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{

    nsresult rv;
    WCHAR wszURL[MAX_PATH] = L"";
    nsCOMPtr<nsIObserverService> os;

    nsCOMPtr<nsIServiceManager> servMan;
    rv = NS_GetServiceManager(getter_AddRefs(servMan));
    if (NS_SUCCEEDED(rv))
    {
        servMan->GetServiceByContractID("@mozilla.org/observer-service;1",NS_GET_IID(nsIObserverService),getter_AddRefs(os));
        if (_stricmp(aTopic, "xpcom-startup") == 0)
        {

            nsCOMPtr<nsIWebProgress> progress;
            servMan->GetServiceByContractID("@mozilla.org/docloaderservice;1", NS_GET_IID(nsIWebProgress), getter_AddRefs(progress));
            progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_ALL | nsIWebProgress::NOTIFY_ALL);


            MessageBox(NULL,L"prgresslistner added",L"Success",MB_OK);
        }
    }

  return NS_OK;
}



在OnSteateChange()方法中,以下代码是::



And in OnSteateChange() Method following is code ::

NS_IMETHODIMP MyComponent::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
     {

         MessageBox(NULL,L"inside OnStateChange ()",L"Success",MB_OK);
            if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT))
           {
               MessageBox(NULL,L"inside OnStateChange ()",L"Success",MB_OK);
               //nsCString url;
               //aRequest->GetName(url);

           }

       return NS_OK;
    }



任何人都可以告诉我为什么未调用OnstateChange()方法吗?



Can anyone please tell me why OnstateChange() method is not getting called?
Please give any code sample if you have.

推荐答案

您还需要从nsSupportsWeakReference继承类MyComponent,并在实现NS_IMPL_ISUPPORTSX(CProgressListener,...,nsISupportsWeakReference ),其中X替换为您继承的正确数量的类.这会将弱引用实现添加到您的类中.请记住,您的对象至少需要一个强引用(调用AddRef)才能被运行时销毁.
You need to inherit your class MyComponent also from nsSupportsWeakReference and have following in implementation NS_IMPL_ISUPPORTSX(CProgressListener, ... , nsISupportsWeakReference) where X is replaced with correct number of classes you inherit from. This will add weak reference implementation to your class. Remember that your object needs to have at least one strong reference (call AddRef on it) in order not to be destroyed by runtime.


如果AddProgressListener失败,则可能是由于该类未继承来自nsSupportsWeakReference.
if AddProgressListener fails it might be due to the class not inherited from nsSupportsWeakReference.


这篇关于使用XPCOM从FireFox获取URL f的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆