mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 1389836 - Push extensions from MIME info objects to the child. r=bz
It would be really nice to push all of this back up to the parent or to at least make it asynchronous. I think it should be possible since we control when we send the DOM events, but for the moment this should work. With this patch, I extend ProxyMIMEInfo and HandlerInfo with information about the available extensions for a given MIME type. On Linux, at least, we read the system (in my case GNOME) registry in the child and handlers.json in the parent finally merging them again in the child (in ContentHandlerService::FillHandlerInfo). Even though I was unable to get my mochitest to work, it did work well enough that I could verify that this patch was getting all of the proper extensions to the nsContentAreaDragDrop.cpp code. MozReview-Commit-ID: AR3VayMUiDN --HG-- extra : rebase_source : f9861e46e92fb7e8d297eff3e5d61a3c18912b47
This commit is contained in:
parent
192a69cf57
commit
47a7f17127
@ -3,6 +3,7 @@
|
||||
#include "ContentChild.h"
|
||||
#include "nsIMutableArray.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsIStringEnumerator.h"
|
||||
|
||||
using mozilla::dom::ContentChild;
|
||||
using mozilla::dom::PHandlerServiceChild;
|
||||
@ -63,9 +64,33 @@ ContentHandlerService::nsIHandlerInfoToHandlerInfo(nsIHandlerInfo* aInfo,
|
||||
happs.AppendElement(HandlerApp(name, detailedDescription));
|
||||
}
|
||||
}
|
||||
|
||||
nsTArray<nsCString> extensions;
|
||||
|
||||
if (isMIMEInfo) {
|
||||
nsCOMPtr<nsIUTF8StringEnumerator> extensionsIter;
|
||||
mimeInfo->GetFileExtensions(getter_AddRefs(extensionsIter));
|
||||
if (extensionsIter) {
|
||||
bool hasMore = false;
|
||||
while (NS_SUCCEEDED(extensionsIter->HasMore(&hasMore)) && hasMore) {
|
||||
nsAutoCString extension;
|
||||
if (NS_SUCCEEDED(extensionsIter->GetNext(extension))) {
|
||||
extensions.AppendElement(Move(extension));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsHandlerInfoAction action;
|
||||
aInfo->GetPreferredAction(&action);
|
||||
HandlerInfo info(type, isMIMEInfo, description, alwaysAskBeforeHandling, happ, happs, action);
|
||||
HandlerInfo info(type,
|
||||
isMIMEInfo,
|
||||
description,
|
||||
alwaysAskBeforeHandling,
|
||||
Move(extensions),
|
||||
happ,
|
||||
happs,
|
||||
action);
|
||||
*aHandlerInfo = info;
|
||||
}
|
||||
|
||||
@ -104,7 +129,7 @@ NS_IMETHODIMP RemoteHandlerApp::LaunchWithURI(nsIURI *aURI, nsIInterfaceRequesto
|
||||
|
||||
NS_IMPL_ISUPPORTS(RemoteHandlerApp, nsIHandlerApp)
|
||||
|
||||
static inline void CopyHanderInfoTonsIHandlerInfo(HandlerInfo info, nsIHandlerInfo* aHandlerInfo)
|
||||
static inline void CopyHanderInfoTonsIHandlerInfo(const HandlerInfo& info, nsIHandlerInfo* aHandlerInfo)
|
||||
{
|
||||
HandlerApp preferredApplicationHandler = info.preferredApplicationHandler();
|
||||
nsCOMPtr<nsIHandlerApp> preferredApp(new RemoteHandlerApp(preferredApplicationHandler));
|
||||
@ -112,7 +137,26 @@ static inline void CopyHanderInfoTonsIHandlerInfo(HandlerInfo info, nsIHandlerIn
|
||||
nsCOMPtr<nsIMutableArray> possibleHandlers;
|
||||
aHandlerInfo->GetPossibleApplicationHandlers(getter_AddRefs(possibleHandlers));
|
||||
possibleHandlers->AppendElement(preferredApp);
|
||||
|
||||
if (info.isMIMEInfo()) {
|
||||
const auto& fileExtensions = info.extensions();
|
||||
bool first = true;
|
||||
nsAutoCString extensionsStr;
|
||||
for (const auto& extension : fileExtensions) {
|
||||
if (!first) {
|
||||
extensionsStr.Append(',');
|
||||
}
|
||||
|
||||
extensionsStr.Append(extension);
|
||||
first = false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMIMEInfo> mimeInfo(do_QueryInterface(aHandlerInfo));
|
||||
MOZ_ASSERT(mimeInfo, "parent and child don't agree on whether this is a MIME info");
|
||||
mimeInfo->SetFileExtensions(extensionsStr);
|
||||
}
|
||||
}
|
||||
|
||||
ContentHandlerService::~ContentHandlerService()
|
||||
{
|
||||
}
|
||||
@ -129,10 +173,10 @@ NS_IMETHODIMP ContentHandlerService::Enumerate(nsISimpleEnumerator * *_retval)
|
||||
|
||||
NS_IMETHODIMP ContentHandlerService::FillHandlerInfo(nsIHandlerInfo *aHandlerInfo, const nsACString & aOverrideType)
|
||||
{
|
||||
HandlerInfo info;
|
||||
HandlerInfo info, returnedInfo;
|
||||
nsIHandlerInfoToHandlerInfo(aHandlerInfo, &info);
|
||||
mHandlerServiceChild->SendFillHandlerInfo(info, nsCString(aOverrideType), &info);
|
||||
CopyHanderInfoTonsIHandlerInfo(info, aHandlerInfo);
|
||||
mHandlerServiceChild->SendFillHandlerInfo(info, nsCString(aOverrideType), &returnedInfo);
|
||||
CopyHanderInfoTonsIHandlerInfo(returnedInfo, aHandlerInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "nsIHandlerService.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "ContentHandlerService.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#ifdef MOZ_WIDGET_GTK
|
||||
#include "unix/nsGNOMERegistry.h"
|
||||
#endif
|
||||
@ -19,6 +20,11 @@ public:
|
||||
explicit ProxyHandlerInfo(const HandlerInfo& aHandlerInfo);
|
||||
NS_DECL_ISUPPORTS;
|
||||
NS_DECL_NSIHANDLERINFO;
|
||||
|
||||
nsTArray<nsCString>& Extensions() {
|
||||
return mHandlerInfo.extensions();
|
||||
}
|
||||
|
||||
protected:
|
||||
~ProxyHandlerInfo() {}
|
||||
HandlerInfo mHandlerInfo;
|
||||
@ -28,7 +34,9 @@ protected:
|
||||
|
||||
NS_IMPL_ISUPPORTS(ProxyHandlerInfo, nsIHandlerInfo)
|
||||
|
||||
ProxyHandlerInfo::ProxyHandlerInfo(const HandlerInfo& aHandlerInfo) : mHandlerInfo(aHandlerInfo), mPossibleApps(do_CreateInstance(NS_ARRAY_CONTRACTID))
|
||||
ProxyHandlerInfo::ProxyHandlerInfo(const HandlerInfo& aHandlerInfo)
|
||||
: mHandlerInfo(aHandlerInfo),
|
||||
mPossibleApps(do_CreateInstance(NS_ARRAY_CONTRACTID))
|
||||
{
|
||||
for (auto& happ : aHandlerInfo.possibleApplicationHandlers()) {
|
||||
mPossibleApps->AppendElement(new RemoteHandlerApp(happ));
|
||||
@ -73,6 +81,7 @@ NS_IMETHODIMP ProxyHandlerInfo::SetPreferredApplicationHandler(nsIHandlerApp *aA
|
||||
mHandlerInfo.isMIMEInfo(),
|
||||
mHandlerInfo.description(),
|
||||
mHandlerInfo.alwaysAskBeforeHandling(),
|
||||
mHandlerInfo.extensions(),
|
||||
happ,
|
||||
mHandlerInfo.possibleApplicationHandlers(),
|
||||
mHandlerInfo.preferredAction());
|
||||
@ -117,6 +126,7 @@ NS_IMETHODIMP ProxyHandlerInfo::SetPreferredAction(nsHandlerInfoAction aPreferre
|
||||
mHandlerInfo.isMIMEInfo(),
|
||||
mHandlerInfo.description(),
|
||||
mHandlerInfo.alwaysAskBeforeHandling(),
|
||||
mHandlerInfo.extensions(),
|
||||
mHandlerInfo.preferredApplicationHandler(),
|
||||
mHandlerInfo.possibleApplicationHandlers(),
|
||||
aPreferredAction);
|
||||
@ -136,6 +146,7 @@ NS_IMETHODIMP ProxyHandlerInfo::SetAlwaysAskBeforeHandling(bool aAlwaysAskBefore
|
||||
mHandlerInfo.isMIMEInfo(),
|
||||
mHandlerInfo.description(),
|
||||
aAlwaysAskBeforeHandling,
|
||||
mHandlerInfo.extensions(),
|
||||
mHandlerInfo.preferredApplicationHandler(),
|
||||
mHandlerInfo.possibleApplicationHandlers(),
|
||||
mHandlerInfo.preferredAction());
|
||||
@ -150,11 +161,14 @@ public:
|
||||
NS_DECL_NSIMIMEINFO
|
||||
NS_FORWARD_NSIHANDLERINFO(mProxyHandlerInfo->);
|
||||
|
||||
explicit ProxyMIMEInfo(HandlerInfo aHandlerInfo) : mProxyHandlerInfo(new ProxyHandlerInfo(aHandlerInfo)) {}
|
||||
explicit ProxyMIMEInfo(const HandlerInfo &aHandlerInfo)
|
||||
: mProxyHandlerInfo(new ProxyHandlerInfo(aHandlerInfo))
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ~ProxyMIMEInfo() {}
|
||||
nsCOMPtr<nsIHandlerInfo> mProxyHandlerInfo;
|
||||
RefPtr<ProxyHandlerInfo> mProxyHandlerInfo;
|
||||
|
||||
protected:
|
||||
/* additional members */
|
||||
@ -165,7 +179,7 @@ NS_IMPL_ISUPPORTS(ProxyMIMEInfo, nsIMIMEInfo, nsIHandlerInfo)
|
||||
/* nsIUTF8StringEnumerator getFileExtensions (); */
|
||||
NS_IMETHODIMP ProxyMIMEInfo::GetFileExtensions(nsIUTF8StringEnumerator * *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_NewUTF8StringEnumerator(_retval, &mProxyHandlerInfo->Extensions(), this);
|
||||
}
|
||||
|
||||
/* void setFileExtensions (in AUTF8String aExtensions); */
|
||||
@ -177,19 +191,26 @@ NS_IMETHODIMP ProxyMIMEInfo::SetFileExtensions(const nsACString & aExtensions)
|
||||
/* boolean extensionExists (in AUTF8String aExtension); */
|
||||
NS_IMETHODIMP ProxyMIMEInfo::ExtensionExists(const nsACString & aExtension, bool *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
*_retval = mProxyHandlerInfo->Extensions().Contains(aExtension);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void appendExtension (in AUTF8String aExtension); */
|
||||
NS_IMETHODIMP ProxyMIMEInfo::AppendExtension(const nsACString & aExtension)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
mProxyHandlerInfo->Extensions().AppendElement(aExtension);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute AUTF8String primaryExtension; */
|
||||
NS_IMETHODIMP ProxyMIMEInfo::GetPrimaryExtension(nsACString & aPrimaryExtension)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
const auto& extensions = mProxyHandlerInfo->Extensions();
|
||||
if (extensions.IsEmpty()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aPrimaryExtension = extensions[0];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ProxyMIMEInfo::SetPrimaryExtension(const nsACString & aPrimaryExtension)
|
||||
|
@ -17,6 +17,7 @@ struct HandlerInfo {
|
||||
bool isMIMEInfo;
|
||||
nsString description;
|
||||
bool alwaysAskBeforeHandling;
|
||||
nsCString[] extensions;
|
||||
HandlerApp preferredApplicationHandler;
|
||||
HandlerApp[] possibleApplicationHandlers;
|
||||
long preferredAction;
|
||||
|
@ -1785,7 +1785,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
|
||||
// notification to the dialog progress listener or nsITransfer implementation.
|
||||
void nsExternalAppHandler::SendStatusChange(ErrorType type, nsresult rv, nsIRequest *aRequest, const nsString& path)
|
||||
{
|
||||
const char* msgId;
|
||||
const char* msgId = nullptr;
|
||||
switch (rv) {
|
||||
case NS_ERROR_OUT_OF_MEMORY:
|
||||
// No memory
|
||||
|
Loading…
Reference in New Issue
Block a user