| OLD | NEW | 
|    1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |    1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 
|    2 /* vim:set ts=4 sw=4 sts=4 et cindent: */ |    2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ | 
|    3 /* This Source Code Form is subject to the terms of the Mozilla Public |    3 /* This Source Code Form is subject to the terms of the Mozilla Public | 
|    4  * License, v. 2.0. If a copy of the MPL was not distributed with this |    4  * License, v. 2.0. If a copy of the MPL was not distributed with this | 
|    5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |    5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 
|    6  |    6  | 
|    7 #include "nsAboutRedirector.h" |    7 #include "nsAboutRedirector.h" | 
|    8 #include "nsNetUtil.h" |    8 #include "nsNetUtil.h" | 
|    9 #include "nsAboutProtocolUtils.h" |    9 #include "nsAboutProtocolUtils.h" | 
|   10 #include "mozilla/ArrayUtils.h" |   10 #include "mozilla/ArrayUtils.h" | 
|   11 #include "nsDOMString.h" |   11 #include "nsDOMString.h" | 
|   12  |   12  | 
|   13 NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule) |   13 NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule) | 
|   14  |   14  | 
|   15 struct RedirEntry { |   15 struct RedirEntry | 
|   16     const char* id; |   16 { | 
|   17     const char* url; |   17   const char* id; | 
|   18     uint32_t flags; |   18   const char* url; | 
 |   19   uint32_t flags; | 
|   19 }; |   20 }; | 
|   20  |   21  | 
|   21 /* |   22 /* | 
|   22   Entries which do not have URI_SAFE_FOR_UNTRUSTED_CONTENT will run with chrome |   23   Entries which do not have URI_SAFE_FOR_UNTRUSTED_CONTENT will run with chrome | 
|   23   privileges. This is potentially dangerous. Please use |   24   privileges. This is potentially dangerous. Please use | 
|   24   URI_SAFE_FOR_UNTRUSTED_CONTENT in the third argument to each map item below |   25   URI_SAFE_FOR_UNTRUSTED_CONTENT in the third argument to each map item below | 
|   25   unless your about: page really needs chrome privileges. Security review is |   26   unless your about: page really needs chrome privileges. Security review is | 
|   26   required before adding new map entries without |   27   required before adding new map entries without | 
|   27   URI_SAFE_FOR_UNTRUSTED_CONTENT.  Also note, however, that adding |   28   URI_SAFE_FOR_UNTRUSTED_CONTENT.  Also note, however, that adding | 
|   28   URI_SAFE_FOR_UNTRUSTED_CONTENT will allow random web sites to link to that |   29   URI_SAFE_FOR_UNTRUSTED_CONTENT will allow random web sites to link to that | 
|   29   URI.  Perhaps we should separate the two concepts out... |   30   URI.  Perhaps we should separate the two concepts out... | 
|   30  */ |   31  */ | 
|   31 static RedirEntry kRedirMap[] = { |   32 static RedirEntry kRedirMap[] = { | 
|   32     { "", "chrome://global/content/about.xhtml", |   33   { | 
|   33       nsIAboutModule::ALLOW_SCRIPT }, |   34     "", "chrome://global/content/about.xhtml", | 
|   34     { "about", "chrome://global/content/aboutAbout.xhtml", 0 }, |   35     nsIAboutModule::ALLOW_SCRIPT | 
 |   36   }, | 
 |   37   { "about", "chrome://global/content/aboutAbout.xhtml", 0 }, | 
|   35 /* |   38 /* | 
|   36   Removed as part of https://issues.adblockplus.org/ticket/2531 |   39   Removed as part of https://issues.adblockplus.org/ticket/2531 | 
|   37     { "credits", "http://www.mozilla.org/credits/", |   40   { | 
|   38       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, |   41     "credits", "http://www.mozilla.org/credits/", | 
|   39     { "mozilla", "chrome://global/content/mozilla.xhtml", |   42     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | 
|   40       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, |   43   }, | 
 |   44   { | 
 |   45     "mozilla", "chrome://global/content/mozilla.xhtml", | 
 |   46     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | 
 |   47   }, | 
|   41 */ |   48 */ | 
|   42     { "plugins", "chrome://global/content/plugins.html", 0 }, |   49   { | 
|   43     { "config", "chrome://global/content/config.xul", 0 }, |   50     "plugins", "chrome://global/content/plugins.html", | 
 |   51     nsIAboutModule::URI_MUST_LOAD_IN_CHILD | 
 |   52   }, | 
 |   53   { "config", "chrome://global/content/config.xul", 0 }, | 
|   44 #ifdef MOZ_CRASHREPORTER |   54 #ifdef MOZ_CRASHREPORTER | 
|   45     { "crashes", "chrome://global/content/crashes.xhtml", 0 }, |   55   { "crashes", "chrome://global/content/crashes.xhtml", 0 }, | 
|   46 #endif |   56 #endif | 
|   47     { "logo", "chrome://branding/content/about.png", |   57   { | 
|   48       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT}, |   58     "logo", "chrome://branding/content/about.png", | 
|   49     { "buildconfig", "chrome://global/content/buildconfig.html", |   59     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | 
|   50       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, |   60   }, | 
 |   61   { | 
 |   62     "buildconfig", "chrome://global/content/buildconfig.html", | 
 |   63     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | 
 |   64   }, | 
|   51 /* |   65 /* | 
|   52   Removed as part of https://issues.adblockplus.org/ticket/2531 |   66   Removed as part of https://issues.adblockplus.org/ticket/2531 | 
|   53     { "license", "chrome://global/content/license.html", |   67   { | 
|   54       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, |   68     "license", "chrome://global/content/license.html", | 
 |   69     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | 
 |   70   }, | 
|   55 */ |   71 */ | 
|   56     { "neterror", "chrome://global/content/netError.xhtml", |   72   { | 
|   57       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |   73     "neterror", "chrome://global/content/netError.xhtml", | 
 |   74     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | | 
 |   75       nsIAboutModule::URI_CAN_LOAD_IN_CHILD | | 
|   58       nsIAboutModule::ALLOW_SCRIPT | |   76       nsIAboutModule::ALLOW_SCRIPT | | 
|   59       nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |   77       nsIAboutModule::HIDE_FROM_ABOUTABOUT | 
|   60     { "compartments", "chrome://global/content/aboutCompartments.xhtml", |   78   }, | 
|   61       nsIAboutModule::ALLOW_SCRIPT | |   79   { | 
|   62       nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |   80     "memory", "chrome://global/content/aboutMemory.xhtml", | 
|   63     { "memory", "chrome://global/content/aboutMemory.xhtml", |   81     nsIAboutModule::ALLOW_SCRIPT | 
|   64       nsIAboutModule::ALLOW_SCRIPT }, |   82   }, | 
 |   83   { | 
 |   84     "compartments", "chrome://global/content/aboutCompartments.xhtml", | 
 |   85     nsIAboutModule::ALLOW_SCRIPT | 
 |   86   }, | 
|   65 /* |   87 /* | 
|   66   Removed as part of https://issues.adblockplus.org/ticket/2531 |   88   Removed as part of https://issues.adblockplus.org/ticket/2531 | 
|   67     { "addons", "chrome://mozapps/content/extensions/extensions.xul", |   89   { | 
|   68       nsIAboutModule::ALLOW_SCRIPT }, |   90     "addons", "chrome://mozapps/content/extensions/extensions.xul", | 
 |   91     nsIAboutModule::ALLOW_SCRIPT | 
 |   92   }, | 
|   69 */ |   93 */ | 
|   70     { "newaddon", "chrome://mozapps/content/extensions/newaddon.xul", |   94   { | 
|   71       nsIAboutModule::ALLOW_SCRIPT | |   95     "newaddon", "chrome://mozapps/content/extensions/newaddon.xul", | 
|   72       nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |   96     nsIAboutModule::ALLOW_SCRIPT | | 
 |   97       nsIAboutModule::HIDE_FROM_ABOUTABOUT | 
 |   98   }, | 
|   73 /* |   99 /* | 
|   74   Removed as part of https://issues.adblockplus.org/ticket/2531 |  100   Removed as part of https://issues.adblockplus.org/ticket/2531 | 
|   75     { "support", "chrome://global/content/aboutSupport.xhtml", |  101   { | 
|   76       nsIAboutModule::ALLOW_SCRIPT }, |  102     "support", "chrome://global/content/aboutSupport.xhtml", | 
|   77     { "telemetry", "chrome://global/content/aboutTelemetry.xhtml", |  103     nsIAboutModule::ALLOW_SCRIPT | 
|   78       nsIAboutModule::ALLOW_SCRIPT }, |  104   }, | 
 |  105   { | 
 |  106     "telemetry", "chrome://global/content/aboutTelemetry.xhtml", | 
 |  107     nsIAboutModule::ALLOW_SCRIPT | 
 |  108   }, | 
|   79 */ |  109 */ | 
|   80     { "networking", "chrome://global/content/aboutNetworking.xhtml", |  110   { | 
|   81        nsIAboutModule::ALLOW_SCRIPT }, |  111     "networking", "chrome://global/content/aboutNetworking.xhtml", | 
|   82     { "webrtc", "chrome://global/content/aboutwebrtc/aboutWebrtc.xhtml", |  112     nsIAboutModule::ALLOW_SCRIPT | 
|   83        nsIAboutModule::ALLOW_SCRIPT }, |  113   }, | 
|   84     // about:srcdoc is unresolvable by specification.  It is included here |  114   { | 
|   85     // because the security manager would disallow srcdoc iframes otherwise. |  115     "webrtc", "chrome://global/content/aboutwebrtc/aboutWebrtc.xhtml", | 
|   86     { "srcdoc", "about:blank", |  116     nsIAboutModule::ALLOW_SCRIPT | 
|   87       nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |  117   }, | 
|   88       nsIAboutModule::HIDE_FROM_ABOUTABOUT } |  118   // about:srcdoc is unresolvable by specification.  It is included here | 
 |  119   // because the security manager would disallow srcdoc iframes otherwise. | 
 |  120   { | 
 |  121     "srcdoc", "about:blank", | 
 |  122     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | | 
 |  123       nsIAboutModule::HIDE_FROM_ABOUTABOUT | 
 |  124   } | 
|   89 }; |  125 }; | 
|   90 static const int kRedirTotal = mozilla::ArrayLength(kRedirMap); |  126 static const int kRedirTotal = mozilla::ArrayLength(kRedirMap); | 
|   91  |  127  | 
|   92 NS_IMETHODIMP |  128 NS_IMETHODIMP | 
|   93 nsAboutRedirector::NewChannel(nsIURI* aURI, |  129 nsAboutRedirector::NewChannel(nsIURI* aURI, | 
|   94                               nsILoadInfo* aLoadInfo, |  130                               nsILoadInfo* aLoadInfo, | 
|   95                               nsIChannel** result) |  131                               nsIChannel** aResult) | 
|   96 { |  132 { | 
|   97     NS_ENSURE_ARG_POINTER(aURI); |  133   NS_ENSURE_ARG_POINTER(aURI); | 
|   98     NS_ASSERTION(result, "must not be null"); |  134   NS_ASSERTION(aResult, "must not be null"); | 
|   99  |  135  | 
|  100     nsAutoCString path; |  136   nsAutoCString path; | 
|  101     nsresult rv = NS_GetAboutModuleName(aURI, path); |  137   nsresult rv = NS_GetAboutModuleName(aURI, path); | 
|  102     NS_ENSURE_SUCCESS(rv, rv); |  138   NS_ENSURE_SUCCESS(rv, rv); | 
|  103  |  139  | 
|  104     nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); |  140   nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); | 
|  105     NS_ENSURE_SUCCESS(rv, rv); |  141   NS_ENSURE_SUCCESS(rv, rv); | 
|  106  |  142  | 
 |  143   for (int i = 0; i < kRedirTotal; i++) { | 
 |  144     if (!strcmp(path.get(), kRedirMap[i].id)) { | 
 |  145       nsCOMPtr<nsIChannel> tempChannel; | 
 |  146       nsCOMPtr<nsIURI> tempURI; | 
 |  147       rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); | 
 |  148       NS_ENSURE_SUCCESS(rv, rv); | 
 |  149       rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), | 
 |  150                                  tempURI, | 
 |  151                                  aLoadInfo); | 
 |  152       if (NS_FAILED(rv)) { | 
 |  153         return rv; | 
 |  154       } | 
|  107  |  155  | 
|  108     for (int i=0; i<kRedirTotal; i++)  |  156       tempChannel->SetOriginalURI(aURI); | 
|  109     { |  | 
|  110         if (!strcmp(path.get(), kRedirMap[i].id)) |  | 
|  111         { |  | 
|  112             nsCOMPtr<nsIChannel> tempChannel; |  | 
|  113             nsCOMPtr<nsIURI> tempURI; |  | 
|  114             rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); |  | 
|  115             NS_ENSURE_SUCCESS(rv, rv); |  | 
|  116             // Bug 1087720 (and Bug 1099296): |  | 
|  117             // Once all callsites have been updated to call NewChannel2() |  | 
|  118             // instead of NewChannel() we should have a non-null loadInfo |  | 
|  119             // consistently. Until then we have to branch on the loadInfo. |  | 
|  120             if (aLoadInfo) { |  | 
|  121               rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), |  | 
|  122                                          tempURI, |  | 
|  123                                          aLoadInfo); |  | 
|  124             } |  | 
|  125             else { |  | 
|  126               rv = ioService->NewChannelFromURI(tempURI, |  | 
|  127                                                 getter_AddRefs(tempChannel)); |  | 
|  128             } |  | 
|  129             if (NS_FAILED(rv)) |  | 
|  130                 return rv; |  | 
|  131  |  157  | 
|  132             tempChannel->SetOriginalURI(aURI); |  158       NS_ADDREF(*aResult = tempChannel); | 
 |  159       return rv; | 
 |  160     } | 
 |  161   } | 
|  133  |  162  | 
|  134             NS_ADDREF(*result = tempChannel); |  163   NS_ERROR("nsAboutRedirector called for unknown case"); | 
|  135             return rv; |  164   return NS_ERROR_ILLEGAL_VALUE; | 
|  136         } |  | 
|  137     } |  | 
|  138  |  | 
|  139     NS_ERROR("nsAboutRedirector called for unknown case"); |  | 
|  140     return NS_ERROR_ILLEGAL_VALUE; |  | 
|  141 } |  165 } | 
|  142  |  166  | 
|  143 NS_IMETHODIMP |  167 NS_IMETHODIMP | 
|  144 nsAboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result) |  168 nsAboutRedirector::GetURIFlags(nsIURI* aURI, uint32_t* aResult) | 
|  145 { |  169 { | 
|  146     NS_ENSURE_ARG_POINTER(aURI); |  170   NS_ENSURE_ARG_POINTER(aURI); | 
|  147  |  171  | 
|  148     nsAutoCString name; |  172   nsAutoCString name; | 
|  149     nsresult rv = NS_GetAboutModuleName(aURI, name); |  173   nsresult rv = NS_GetAboutModuleName(aURI, name); | 
|  150     NS_ENSURE_SUCCESS(rv, rv); |  174   NS_ENSURE_SUCCESS(rv, rv); | 
|  151  |  175  | 
|  152     for (int i=0; i < kRedirTotal; i++)  |  176   for (int i = 0; i < kRedirTotal; i++) { | 
|  153     { |  177     if (name.EqualsASCII(kRedirMap[i].id)) { | 
|  154         if (name.EqualsASCII(kRedirMap[i].id)) |  178       *aResult = kRedirMap[i].flags; | 
|  155         { |  179       return NS_OK; | 
|  156             *result = kRedirMap[i].flags; |  | 
|  157             return NS_OK; |  | 
|  158         } |  | 
|  159     } |  180     } | 
 |  181   } | 
|  160  |  182  | 
|  161     NS_ERROR("nsAboutRedirector called for unknown case"); |  183   NS_ERROR("nsAboutRedirector called for unknown case"); | 
|  162     return NS_ERROR_ILLEGAL_VALUE; |  184   return NS_ERROR_ILLEGAL_VALUE; | 
|  163 } |  185 } | 
|  164  |  186  | 
|  165 NS_IMETHODIMP |  187 NS_IMETHODIMP | 
|  166 nsAboutRedirector::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result) |  188 nsAboutRedirector::GetIndexedDBOriginPostfix(nsIURI* aURI, nsAString& aResult) | 
|  167 { |  189 { | 
|  168     SetDOMStringToNull(result); |  190   SetDOMStringToNull(aResult); | 
|  169     return NS_ERROR_NOT_IMPLEMENTED; |  191   return NS_ERROR_NOT_IMPLEMENTED; | 
|  170 } |  192 } | 
|  171  |  193  | 
|  172 nsresult |  194 nsresult | 
|  173 nsAboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) |  195 nsAboutRedirector::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) | 
|  174 { |  196 { | 
|  175     nsAboutRedirector* about = new nsAboutRedirector(); |  197   nsAboutRedirector* about = new nsAboutRedirector(); | 
|  176     if (about == nullptr) |  198   NS_ADDREF(about); | 
|  177         return NS_ERROR_OUT_OF_MEMORY; |  199   nsresult rv = about->QueryInterface(aIID, aResult); | 
|  178     NS_ADDREF(about); |  200   NS_RELEASE(about); | 
|  179     nsresult rv = about->QueryInterface(aIID, aResult); |  201   return rv; | 
|  180     NS_RELEASE(about); |  | 
|  181     return rv; |  | 
|  182 } |  202 } | 
| OLD | NEW |