Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // See also: docshell/base/nsAboutRedirector.cpp |
michael@0 | 7 | |
michael@0 | 8 | #include "AboutRedirector.h" |
michael@0 | 9 | #include "nsNetUtil.h" |
michael@0 | 10 | #include "nsIScriptSecurityManager.h" |
michael@0 | 11 | #include "mozilla/ArrayUtils.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | namespace browser { |
michael@0 | 15 | |
michael@0 | 16 | NS_IMPL_ISUPPORTS(AboutRedirector, nsIAboutModule) |
michael@0 | 17 | |
michael@0 | 18 | struct RedirEntry { |
michael@0 | 19 | const char* id; |
michael@0 | 20 | const char* url; |
michael@0 | 21 | uint32_t flags; |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | /* |
michael@0 | 25 | Entries which do not have URI_SAFE_FOR_UNTRUSTED_CONTENT will run with chrome |
michael@0 | 26 | privileges. This is potentially dangerous. Please use |
michael@0 | 27 | URI_SAFE_FOR_UNTRUSTED_CONTENT in the third argument to each map item below |
michael@0 | 28 | unless your about: page really needs chrome privileges. Security review is |
michael@0 | 29 | required before adding new map entries without |
michael@0 | 30 | URI_SAFE_FOR_UNTRUSTED_CONTENT. Also note, however, that adding |
michael@0 | 31 | URI_SAFE_FOR_UNTRUSTED_CONTENT will allow random web sites to link to that |
michael@0 | 32 | URI. Perhaps we should separate the two concepts out... |
michael@0 | 33 | */ |
michael@0 | 34 | static RedirEntry kRedirMap[] = { |
michael@0 | 35 | #ifdef MOZ_SAFE_BROWSING |
michael@0 | 36 | { "blocked", "chrome://browser/content/blockedSite.xhtml", |
michael@0 | 37 | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |
michael@0 | 38 | nsIAboutModule::ALLOW_SCRIPT | |
michael@0 | 39 | nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |
michael@0 | 40 | #endif |
michael@0 | 41 | { "certerror", "chrome://browser/content/certerror/aboutCertError.xhtml", |
michael@0 | 42 | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |
michael@0 | 43 | nsIAboutModule::ALLOW_SCRIPT | |
michael@0 | 44 | nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |
michael@0 | 45 | { "socialerror", "chrome://browser/content/aboutSocialError.xhtml", |
michael@0 | 46 | nsIAboutModule::ALLOW_SCRIPT | |
michael@0 | 47 | nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |
michael@0 | 48 | { "tabcrashed", "chrome://browser/content/aboutTabCrashed.xhtml", |
michael@0 | 49 | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |
michael@0 | 50 | nsIAboutModule::ALLOW_SCRIPT | |
michael@0 | 51 | nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |
michael@0 | 52 | { "feeds", "chrome://browser/content/feeds/subscribe.xhtml", |
michael@0 | 53 | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |
michael@0 | 54 | nsIAboutModule::ALLOW_SCRIPT | |
michael@0 | 55 | nsIAboutModule::HIDE_FROM_ABOUTABOUT }, |
michael@0 | 56 | { "privatebrowsing", "chrome://browser/content/aboutPrivateBrowsing.xhtml", |
michael@0 | 57 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 58 | { "rights", |
michael@0 | 59 | #ifdef MOZ_OFFICIAL_BRANDING |
michael@0 | 60 | "chrome://global/content/aboutRights.xhtml", |
michael@0 | 61 | #else |
michael@0 | 62 | "chrome://global/content/aboutRights-unbranded.xhtml", |
michael@0 | 63 | #endif |
michael@0 | 64 | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |
michael@0 | 65 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 66 | { "robots", "chrome://browser/content/aboutRobots.xhtml", |
michael@0 | 67 | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |
michael@0 | 68 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 69 | { "sessionrestore", "chrome://browser/content/aboutSessionRestore.xhtml", |
michael@0 | 70 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 71 | { "welcomeback", "chrome://browser/content/aboutWelcomeBack.xhtml", |
michael@0 | 72 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 73 | #ifdef MOZ_SERVICES_SYNC |
michael@0 | 74 | { "sync-progress", "chrome://browser/content/sync/progress.xhtml", |
michael@0 | 75 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 76 | { "sync-tabs", "chrome://browser/content/sync/aboutSyncTabs.xul", |
michael@0 | 77 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 78 | #endif |
michael@0 | 79 | { "home", "chrome://browser/content/abouthome/aboutHome.xhtml", |
michael@0 | 80 | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | |
michael@0 | 81 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 82 | { "newtab", "chrome://browser/content/newtab/newTab.xul", |
michael@0 | 83 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 84 | { "permissions", "chrome://browser/content/preferences/aboutPermissions.xul", |
michael@0 | 85 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 86 | { "preferences", "chrome://browser/content/preferences/in-content/preferences.xul", |
michael@0 | 87 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 88 | { "downloads", "chrome://browser/content/downloads/contentAreaDownloadsView.xul", |
michael@0 | 89 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 90 | #ifdef MOZ_SERVICES_HEALTHREPORT |
michael@0 | 91 | { "healthreport", "chrome://browser/content/abouthealthreport/abouthealth.xhtml", |
michael@0 | 92 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 93 | #endif |
michael@0 | 94 | { "accounts", "chrome://browser/content/aboutaccounts/aboutaccounts.xhtml", |
michael@0 | 95 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 96 | { "app-manager", "chrome://browser/content/devtools/app-manager/index.xul", |
michael@0 | 97 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 98 | { "customizing", "chrome://browser/content/customizableui/aboutCustomizing.xul", |
michael@0 | 99 | nsIAboutModule::ALLOW_SCRIPT }, |
michael@0 | 100 | }; |
michael@0 | 101 | static const int kRedirTotal = ArrayLength(kRedirMap); |
michael@0 | 102 | |
michael@0 | 103 | static nsAutoCString |
michael@0 | 104 | GetAboutModuleName(nsIURI *aURI) |
michael@0 | 105 | { |
michael@0 | 106 | nsAutoCString path; |
michael@0 | 107 | aURI->GetPath(path); |
michael@0 | 108 | |
michael@0 | 109 | int32_t f = path.FindChar('#'); |
michael@0 | 110 | if (f >= 0) |
michael@0 | 111 | path.SetLength(f); |
michael@0 | 112 | |
michael@0 | 113 | f = path.FindChar('?'); |
michael@0 | 114 | if (f >= 0) |
michael@0 | 115 | path.SetLength(f); |
michael@0 | 116 | |
michael@0 | 117 | ToLowerCase(path); |
michael@0 | 118 | return path; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | NS_IMETHODIMP |
michael@0 | 122 | AboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result) |
michael@0 | 123 | { |
michael@0 | 124 | NS_ENSURE_ARG_POINTER(aURI); |
michael@0 | 125 | NS_ASSERTION(result, "must not be null"); |
michael@0 | 126 | |
michael@0 | 127 | nsAutoCString path = GetAboutModuleName(aURI); |
michael@0 | 128 | |
michael@0 | 129 | nsresult rv; |
michael@0 | 130 | nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); |
michael@0 | 131 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 132 | |
michael@0 | 133 | for (int i = 0; i < kRedirTotal; i++) { |
michael@0 | 134 | if (!strcmp(path.get(), kRedirMap[i].id)) { |
michael@0 | 135 | nsCOMPtr<nsIChannel> tempChannel; |
michael@0 | 136 | rv = ioService->NewChannel(nsDependentCString(kRedirMap[i].url), |
michael@0 | 137 | nullptr, nullptr, getter_AddRefs(tempChannel)); |
michael@0 | 138 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 139 | |
michael@0 | 140 | tempChannel->SetOriginalURI(aURI); |
michael@0 | 141 | |
michael@0 | 142 | NS_ADDREF(*result = tempChannel); |
michael@0 | 143 | return rv; |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | return NS_ERROR_ILLEGAL_VALUE; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | NS_IMETHODIMP |
michael@0 | 151 | AboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result) |
michael@0 | 152 | { |
michael@0 | 153 | NS_ENSURE_ARG_POINTER(aURI); |
michael@0 | 154 | |
michael@0 | 155 | nsAutoCString name = GetAboutModuleName(aURI); |
michael@0 | 156 | |
michael@0 | 157 | for (int i = 0; i < kRedirTotal; i++) { |
michael@0 | 158 | if (name.Equals(kRedirMap[i].id)) { |
michael@0 | 159 | *result = kRedirMap[i].flags; |
michael@0 | 160 | return NS_OK; |
michael@0 | 161 | } |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | return NS_ERROR_ILLEGAL_VALUE; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | nsresult |
michael@0 | 168 | AboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **result) |
michael@0 | 169 | { |
michael@0 | 170 | AboutRedirector* about = new AboutRedirector(); |
michael@0 | 171 | if (about == nullptr) |
michael@0 | 172 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 173 | NS_ADDREF(about); |
michael@0 | 174 | nsresult rv = about->QueryInterface(aIID, result); |
michael@0 | 175 | NS_RELEASE(about); |
michael@0 | 176 | return rv; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | } // namespace browser |
michael@0 | 180 | } // namespace mozilla |