How can I read the source URL of a file downloaded with FireFox from an external application? - c++

I have an C++ app I built which is registered as the default handler for a file with a specific extension. So when I download one of these files with Firefox from a website, it downloads it to a temp directory and then shell executes my app while passing the full path to the downloaded file on the command line.
What is the best way to figure out from the external app what the original download url of the file was, given only it's path on disk? Can I use XPCOM API calls to inspect the FireFox download manager database?
I've figured out that this data get's stored in the "%APPData%\Mozilla\Firefox\($profile)\downloads.sqlite" file which is a SqlLite db file, but I really rather not try to open this file directly as FireFox has an open write handle to the file while running.
After perusing the Mozilla developer center for a while, I ran accross the nsIDownloadManager service, which seems to be just the thing. But I can't seem to get access to it from XPCOM in a separate process?
Here's the code I am using:
nsresult rv;
//init XPCOM
nsCOMPtr<nsIServiceManager> servMgr;
rv = NS_InitXPCOM2(getter_AddRefs(servMgr), nsnull, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
//Get a download manager instance
nsCOMPtr<nsIDownloadManager> downloadMgr;
rv = servMgr->GetServiceByContractID(NS_DOWNLOADMANAGER_CONTRACTID,
nsIDownloadManager::GetIID(), getter_AddRefs(downloadMgr));
NS_ENSURE_SUCCESS(rv, rv);
When I run this, the GetServiceByContractID() call returns 0x8007000e, which is defined in nsError.h as NS_ERROR_OUT_OF_MEMORY. (which I find very weird).
Any ideas here? Am I barking up the right tree?

No, you can't access Firefox's XPCOM objects from an external process, and you also shouldn't open the sqlite database while Firefox has it open. I don't know that there's any straightforward way to do what you want without writing a Firefox extension that has access to the Firefox internals.

I'm a little hazy on the details right now, but, assuming that your download is served with a custom MIME type, it's possible to register a handler for that type; your handler can then cancel the download and pass the URL to your application.

Related

Using MCAP for URDFs

I'm having trouble with the transportability of my URDF files. Specifically I'm unable to get them to load in Foxglove Studio. Is it possible to add a URDF as an attachment in an MCAP file so that it's somehow fully encapsulated and just opens by robot definition at the same time as visualizing my robot data?
I've tried opening my URDF file directly in Foxglove Studio's web client and it fails. I seem to be able to open it in the desktop tool.
See the work in progress here: https://github.com/foxglove/studio/pull/4725
The basic idea is all asset fetch() requests go through a proxy function in the Studio data source (player). For MCAP, the player checks for an attachment with the name equal to the requested URL, such as package://foo/bar.dae and returns that if present, otherwise falling back to fetch().

Check, if a PDF-Reader is installed - QDesktopServices::openUrl()

i want to check, if a pdf-reader is installed. The idea was to use QDesktopServices::openUrl("path/test.pdf") and if its return "false" i know that no pdf-reader is installed. The problem is, that if a pdf-reader is installed, it opens the pdf. Can I "disable" that?
/edit: My solution:
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.pdf\\OpenWithProgids", QSettings::NativeFormat);
if (settings.allKeys().size() == 0) {...}
Can I "disable" that?
Simple answer - no.
As QDesktopServices::openUrl asks the system to open the file with the associated program, you can't disable it via Qt.
While not recommended, you could disable this on a per-platform basis, but if you're going down that route, I suggest using each platform's own features to check if there is an application associated with the pdf data file.
On Windows, it's in stored in the registry, while OS X uses LaunchServices.
However, just because a file association doesn't exist, it doesn't mean that a suitable application isn't installed, for opening a pdf.
If you want to be able to display a pdf, you're probably better off handling that directly in your program. You can read about some options for that here.

How to attach MS word document in Qt GUI application?

I wrote a Qt widget application. In the file menu I want to insert an MS word document as a user manual. Is there any way to do it? I checked Qt help and various blogs but none of them gave me a clear solution.
If it is only manual then it is not necessary to embed MS Word inside your app. Maybe try to open needed document with Word installed in computer. Try this code:
QDesktopServices::openUrl(QUrl("file:///G:/tst.docx"));
Just set needed path. As doc said:
If the URL is a reference to a local file (i.e., the URL scheme is
"file") then it will be opened with a suitable application instead of
a Web browser.
If you want to embed it in your application executable, just insert your .docx file as a resource file. To open the docx file from resources, you should first copy it to some location for example in the application directory path :
QFile HelpFile("qrc:/myFile.docx");;
HelpFile.copy(qApp->applicationDirPath().append("/myFile.docx"));
Next you can open it by :
QDesktopServices::openUrl(QUrl::fromLocalFile(qApp->applicationDirPath().append("/myFile.docx")));

IE ActiveX plugin cannot create file

I wrote an IE plugin using MFC activex. The plugin actually creates a file in CLSID_APPDATA folder and writes some data inside it. But the problem is that file which is created cannot be seen (i mean i cant see any file in CLSID_APPDATA folder on windows vista) whereas I am actually writing data inside it. The plugin is not signed.
I have the code from http://support.microsoft.com/kb/161873 to mark my activex component as safe.
Please let me know if I need to do something more to make it possible for file creation. I hope I was clear. Do let me know if I need to provide more details.
regards,
Pradip.B
It sounds like you're falling foul of IE's "Protected Mode" which redirects file writes made from IE from \Users\UserName\Local\ to \Users\Username\LocalLow (or something very similar to that).
Take a look at the following links as they should point you in the right direction:
More details on Protected Mode IE in Windows Vista
The difference between Local and LocalLow folders

How do I check if a swf file loaded correctly since put_Movie always returns S_OK?

I am using the latest flash player and have a swf file served locally from my dev machine. In one container test app I am able to play the swf and make calls to it, but in my "Real" application the same code path results in com errors (basically it looks like the swf isn;' loading properly)
Additionally this is made more challenging because no matter what nonsense I put in the call to put_Movie() the return is ALWAYS S_OK. This is confusing.
How am I supposed to determine if the swf file loaded and is working?
As a follow-on, what would cause a swf file (the same one) not to load in a different app? The code paths are the same (from what I can tell).
Obviousl something is going on, but I am not sure what.
So, I guess 2 questions
How to know when swf file doesn't load right
Why might it fail in a different container application?
I am using ATL in Visual studio 2008, latest flash, MS Vista
Thanks
Hmm, it seems that if I listen for the DISPID_READYSTATECHANGE events then that helps me.
A value of '4' seems to indicate it is ready to accept method calls.