LCOV - code coverage report
Current view: top level - netwerk/protocol/res - nsResProtocolHandler.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 26 32 81.2 %
Date: 2017-07-14 16:53:18 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "mozilla/chrome/RegistryMessageUtils.h"
       7             : #include "mozilla/dom/ContentParent.h"
       8             : #include "mozilla/Unused.h"
       9             : 
      10             : #include "nsResProtocolHandler.h"
      11             : #include "nsIIOService.h"
      12             : #include "nsIFile.h"
      13             : #include "nsNetCID.h"
      14             : #include "nsNetUtil.h"
      15             : #include "nsURLHelper.h"
      16             : #include "nsEscape.h"
      17             : 
      18             : #include "mozilla/Omnijar.h"
      19             : 
      20             : using mozilla::dom::ContentParent;
      21             : using mozilla::LogLevel;
      22             : using mozilla::Unused;
      23             : 
      24             : #define kAPP           "app"
      25             : #define kGRE           "gre"
      26             : 
      27             : nsresult
      28           3 : nsResProtocolHandler::Init()
      29             : {
      30             :     nsresult rv;
      31           3 :     rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, mAppURI);
      32           3 :     NS_ENSURE_SUCCESS(rv, rv);
      33           3 :     rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, mGREURI);
      34           3 :     NS_ENSURE_SUCCESS(rv, rv);
      35             : 
      36             :     // mozilla::Omnijar::GetURIString always returns a string ending with /,
      37             :     // and we want to remove it.
      38           3 :     mGREURI.Truncate(mGREURI.Length() - 1);
      39           3 :     if (mAppURI.Length()) {
      40           3 :       mAppURI.Truncate(mAppURI.Length() - 1);
      41             :     } else {
      42           0 :       mAppURI = mGREURI;
      43             :     }
      44             : 
      45             :     //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir...
      46             :     // but once I finish multiple chrome registration I'm not sure that it is needed
      47             : 
      48             :     // XXX dveditz: resource://pchrome/ defeats profile directory salting
      49             :     // if web content can load it. Tread carefully.
      50             : 
      51           3 :     return rv;
      52             : }
      53             : 
      54             : //----------------------------------------------------------------------------
      55             : // nsResProtocolHandler::nsISupports
      56             : //----------------------------------------------------------------------------
      57             : 
      58        8350 : NS_IMPL_QUERY_INTERFACE(nsResProtocolHandler, nsIResProtocolHandler,
      59             :                         nsISubstitutingProtocolHandler, nsIProtocolHandler,
      60             :                         nsISupportsWeakReference)
      61        6209 : NS_IMPL_ADDREF_INHERITED(nsResProtocolHandler, SubstitutingProtocolHandler)
      62        6206 : NS_IMPL_RELEASE_INHERITED(nsResProtocolHandler, SubstitutingProtocolHandler)
      63             : 
      64             : nsresult
      65           0 : nsResProtocolHandler::GetSubstitutionInternal(const nsACString& root, nsIURI **result)
      66             : {
      67           0 :     nsAutoCString uri;
      68             : 
      69           0 :     if (!ResolveSpecialCases(root, NS_LITERAL_CSTRING("/"), NS_LITERAL_CSTRING("/"), uri)) {
      70           0 :         return NS_ERROR_NOT_AVAILABLE;
      71             :     }
      72             : 
      73           0 :     return NS_NewURI(result, uri);
      74             : }
      75             : 
      76             : bool
      77        1611 : nsResProtocolHandler::ResolveSpecialCases(const nsACString& aHost,
      78             :                                           const nsACString& aPath,
      79             :                                           const nsACString& aPathname,
      80             :                                           nsACString& aResult)
      81             : {
      82        1611 :     if (aHost.Equals("") || aHost.Equals(kAPP)) {
      83         185 :         aResult.Assign(mAppURI);
      84        1426 :     } else if (aHost.Equals(kGRE)) {
      85        1257 :         aResult.Assign(mGREURI);
      86             :     } else {
      87         169 :         return false;
      88             :     }
      89        1442 :     aResult.Append(aPath);
      90        1442 :     return true;
      91             : }
      92             : 
      93             : nsresult
      94          33 : nsResProtocolHandler::SetSubstitution(const nsACString& aRoot, nsIURI* aBaseURI)
      95             : {
      96          33 :     MOZ_ASSERT(!aRoot.Equals(""));
      97          33 :     MOZ_ASSERT(!aRoot.Equals(kAPP));
      98          33 :     MOZ_ASSERT(!aRoot.Equals(kGRE));
      99          33 :     return SubstitutingProtocolHandler::SetSubstitution(aRoot, aBaseURI);
     100           9 : }

Generated by: LCOV version 1.13