LCOV - code coverage report
Current view: top level - uriloader/exthandler - ContentHandlerService.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 91 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 24 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "ContentHandlerService.h"
       2             : #include "HandlerServiceChild.h"
       3             : #include "ContentChild.h"
       4             : #include "nsIMutableArray.h"
       5             : #include "nsIMIMEInfo.h"
       6             : 
       7             : using mozilla::dom::ContentChild;
       8             : using mozilla::dom::PHandlerServiceChild;
       9             : using mozilla::dom::HandlerInfo;
      10             : 
      11             : namespace mozilla {
      12             : namespace dom {
      13             : 
      14           0 : NS_IMPL_ISUPPORTS(ContentHandlerService, nsIHandlerService)
      15             : 
      16           0 : ContentHandlerService::ContentHandlerService()
      17             : {
      18           0 : }
      19             : 
      20             : nsresult
      21           0 : ContentHandlerService::Init()
      22             : {
      23           0 :   if (!XRE_IsContentProcess()) {
      24           0 :     return NS_ERROR_FAILURE;
      25             :   }
      26           0 :   ContentChild* cpc = ContentChild::GetSingleton();
      27             : 
      28           0 :   mHandlerServiceChild = static_cast<HandlerServiceChild*>(cpc->SendPHandlerServiceConstructor());
      29           0 :   return NS_OK;
      30             : }
      31             : 
      32             : void
      33           0 : ContentHandlerService::nsIHandlerInfoToHandlerInfo(nsIHandlerInfo* aInfo,
      34             :                                                    HandlerInfo* aHandlerInfo)
      35             : {
      36           0 :   nsCString type;
      37           0 :   aInfo->GetType(type);
      38           0 :   nsCOMPtr<nsIMIMEInfo> mimeInfo = do_QueryInterface(aInfo);
      39           0 :   bool isMIMEInfo = !!mimeInfo;
      40           0 :   nsString description;
      41           0 :   aInfo->GetDescription(description);
      42             :   bool alwaysAskBeforeHandling;
      43           0 :   aInfo->GetAlwaysAskBeforeHandling(&alwaysAskBeforeHandling);
      44           0 :   nsCOMPtr<nsIHandlerApp> app;
      45           0 :   aInfo->GetPreferredApplicationHandler(getter_AddRefs(app));
      46           0 :   nsString name;
      47           0 :   nsString detailedDescription;
      48           0 :   if (app) {
      49           0 :     app->GetName(name);
      50           0 :     app->GetDetailedDescription(detailedDescription);
      51             :   }
      52           0 :   HandlerApp happ(name, detailedDescription);
      53           0 :   nsTArray<HandlerApp> happs;
      54           0 :   nsCOMPtr<nsIMutableArray> apps;
      55           0 :   aInfo->GetPossibleApplicationHandlers(getter_AddRefs(apps));
      56           0 :   if (apps) {
      57             :     unsigned int length;
      58           0 :     apps->GetLength(&length);
      59           0 :     for (unsigned int i = 0; i < length; i++) {
      60           0 :       apps->QueryElementAt(i, NS_GET_IID(nsIHandlerApp), getter_AddRefs(app));
      61           0 :       app->GetName(name);
      62           0 :       app->GetDetailedDescription(detailedDescription);
      63           0 :       happs.AppendElement(HandlerApp(name, detailedDescription));
      64             :     }
      65             :   }
      66             :   nsHandlerInfoAction action;
      67           0 :   aInfo->GetPreferredAction(&action);
      68           0 :   HandlerInfo info(type, isMIMEInfo, description, alwaysAskBeforeHandling, happ, happs, action);
      69           0 :   *aHandlerInfo = info;
      70           0 : }
      71             : 
      72             : 
      73           0 : NS_IMETHODIMP RemoteHandlerApp::GetName(nsAString & aName)
      74             : {
      75           0 :   aName.Assign(mAppChild.name());
      76           0 :   return NS_OK;
      77             : }
      78             : 
      79           0 : NS_IMETHODIMP RemoteHandlerApp::SetName(const nsAString & aName)
      80             : {
      81           0 :   return NS_ERROR_NOT_IMPLEMENTED;
      82             : }
      83             : 
      84           0 : NS_IMETHODIMP RemoteHandlerApp::GetDetailedDescription(nsAString & aDetailedDescription)
      85             : {
      86           0 :   aDetailedDescription.Assign(mAppChild.detailedDescription());
      87           0 :   return NS_OK;
      88             : }
      89             : 
      90           0 : NS_IMETHODIMP RemoteHandlerApp::SetDetailedDescription(const nsAString & aDetailedDescription)
      91             : {
      92           0 :   return NS_ERROR_NOT_IMPLEMENTED;
      93             : }
      94             : 
      95           0 : NS_IMETHODIMP RemoteHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval)
      96             : {
      97           0 :   return NS_ERROR_NOT_IMPLEMENTED;
      98             : }
      99             : 
     100           0 : NS_IMETHODIMP RemoteHandlerApp::LaunchWithURI(nsIURI *aURI, nsIInterfaceRequestor *aWindowContext)
     101             : {
     102           0 :   return NS_ERROR_NOT_IMPLEMENTED;
     103             : }
     104             : 
     105           0 : NS_IMPL_ISUPPORTS(RemoteHandlerApp, nsIHandlerApp)
     106             : 
     107           0 : static inline void CopyHanderInfoTonsIHandlerInfo(HandlerInfo info, nsIHandlerInfo* aHandlerInfo)
     108             : {
     109           0 :   HandlerApp preferredApplicationHandler = info.preferredApplicationHandler();
     110           0 :   nsCOMPtr<nsIHandlerApp> preferredApp(new RemoteHandlerApp(preferredApplicationHandler));
     111           0 :   aHandlerInfo->SetPreferredApplicationHandler(preferredApp);
     112           0 :   nsCOMPtr<nsIMutableArray> possibleHandlers;
     113           0 :   aHandlerInfo->GetPossibleApplicationHandlers(getter_AddRefs(possibleHandlers));
     114           0 :   possibleHandlers->AppendElement(preferredApp, false);
     115           0 : }
     116           0 : ContentHandlerService::~ContentHandlerService()
     117             : {
     118           0 : }
     119             : 
     120           0 : NS_IMETHODIMP ContentHandlerService::Enumerate(nsISimpleEnumerator * *_retval)
     121             : {
     122           0 :   return NS_ERROR_NOT_IMPLEMENTED;
     123             : }
     124             : 
     125           0 : NS_IMETHODIMP ContentHandlerService::FillHandlerInfo(nsIHandlerInfo *aHandlerInfo, const nsACString & aOverrideType)
     126             : {
     127           0 :   HandlerInfo info;
     128           0 :   nsIHandlerInfoToHandlerInfo(aHandlerInfo, &info);
     129           0 :   mHandlerServiceChild->SendFillHandlerInfo(info, nsCString(aOverrideType), &info);
     130           0 :   CopyHanderInfoTonsIHandlerInfo(info, aHandlerInfo);
     131           0 :   return NS_OK;
     132             : }
     133             : 
     134           0 : NS_IMETHODIMP ContentHandlerService::Store(nsIHandlerInfo *aHandlerInfo)
     135             : {
     136           0 :   return NS_ERROR_NOT_IMPLEMENTED;
     137             : }
     138             : 
     139           0 : NS_IMETHODIMP ContentHandlerService::Exists(nsIHandlerInfo *aHandlerInfo, bool *_retval)
     140             : {
     141           0 :   HandlerInfo info;
     142           0 :   nsIHandlerInfoToHandlerInfo(aHandlerInfo, &info);
     143           0 :   mHandlerServiceChild->SendExists(info, _retval);
     144           0 :   return NS_OK;
     145             : }
     146             : 
     147           0 : NS_IMETHODIMP ContentHandlerService::Remove(nsIHandlerInfo *aHandlerInfo)
     148             : {
     149           0 :   return NS_ERROR_NOT_IMPLEMENTED;
     150             : }
     151             : 
     152             : 
     153           0 : NS_IMETHODIMP ContentHandlerService::GetTypeFromExtension(const nsACString & aFileExtension, nsACString & _retval)
     154             : {
     155           0 :   nsCString* cachedType = nullptr;
     156           0 :   if (!!mExtToTypeMap.Get(aFileExtension, &cachedType) && !!cachedType) {
     157           0 :     _retval.Assign(*cachedType);
     158           0 :     return NS_OK;
     159             :   }
     160           0 :   nsCString type;
     161           0 :   mHandlerServiceChild->SendGetTypeFromExtension(nsCString(aFileExtension), &type);
     162           0 :   _retval.Assign(type);
     163           0 :   mExtToTypeMap.Put(nsCString(aFileExtension), new nsCString(type));
     164             : 
     165           0 :   return NS_OK;
     166             : }
     167             : 
     168             : }
     169             : }

Generated by: LCOV version 1.13