bool WyciwygChannelParent::RecvInit(const IPC::URI& aURI) { nsresult rv; nsCOMPtr<nsIURI> uri(aURI); nsCString uriSpec; uri->GetSpec(uriSpec); LOG(("WyciwygChannelParent RecvInit [this=%x uri=%s]\n", this, uriSpec.get())); nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv)); if (NS_FAILED(rv)) return SendCancelEarly(rv); nsCOMPtr<nsIChannel> chan; rv = NS_NewChannel(getter_AddRefs(chan), uri, ios); if (NS_FAILED(rv)) return SendCancelEarly(rv); mChannel = do_QueryInterface(chan, &rv); if (NS_FAILED(rv)) return SendCancelEarly(rv); return true; }
nsresult nsResProtocolHandler::Init() { if (!mSubstitutions.Init(32)) return NS_ERROR_UNEXPECTED; nsresult rv; mIOService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); // // make resource:/// point to the application directory // rv = AddSpecialDir(NS_OS_CURRENT_PROCESS_DIR, EmptyCString()); NS_ENSURE_SUCCESS(rv, rv); // // make resource://gre/ point to the GRE directory // rv = AddSpecialDir(NS_GRE_DIR, NS_LITERAL_CSTRING("gre")); NS_ENSURE_SUCCESS(rv, rv); //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir... // but once I finish multiple chrome registration I'm not sure that it is needed return rv; }
void CTests::OnTestsIOServiceNewURI() { nsCOMPtr<nsIIOService> ioService(do_GetIOService(&rv)); if (!ioService) { QAOutput("We didn't get the IOService object.", 2); return; } if (myDialog.DoModal() == IDOK) { nsCAutoString theStr, retURI; theStr = myDialog.m_urlfield; rv = ioService->NewURI(theStr, nsnull, nsnull, getter_AddRefs(theURI)); RvTestResult(rv, "ioService->NewURI() test", 2); if (!theURI) QAOutput("We didn't get the nsIURI object for IOService test.", 2); else { retURI = GetTheURI(theURI, 1); FormatAndPrintOutput("The ioService->NewURI() output uri = ", retURI, 2); } } }
void SubstitutingProtocolHandler::ConstructInternal() { nsresult rv; mIOService = do_GetIOService(&rv); MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mIOService); }
void nsPACMan::StartLoading() { mLoadPending = false; // CancelExistingLoad was called... if (!mLoader) { ProcessPendingQ(NS_ERROR_ABORT); return; } if (NS_SUCCEEDED(mLoader->Init(this))) { // Always hit the origin server when loading PAC. nsCOMPtr<nsIIOService> ios = do_GetIOService(); if (ios) { nsCOMPtr<nsIChannel> channel; // NOTE: This results in GetProxyForURI being called ios->NewChannelFromURI(mPACURI, getter_AddRefs(channel)); if (channel) { channel->SetLoadFlags(nsIRequest::LOAD_BYPASS_CACHE); channel->SetNotificationCallbacks(this); if (NS_SUCCEEDED(channel->AsyncOpen(mLoader, nsnull))) return; } } } CancelExistingLoad(); ProcessPendingQ(NS_ERROR_UNEXPECTED); }
void nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource) { nsCOMPtr<nsIIOService> io (do_GetIOService()); if (!io) return; nsCOMPtr<nsIProtocolHandler> ph; nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph)); if (NS_FAILED(rv)) return; nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph)); if (!rph) return; nsCOMPtr<nsIURI> resolvedURI; if (aResource.resolvedURI.spec.Length()) { nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), aResource.resolvedURI.spec, aResource.resolvedURI.charset.get(), nullptr, io); if (NS_FAILED(rv)) return; } rv = rph->SetSubstitution(aResource.resource, resolvedURI); if (NS_FAILED(rv)) return; }
void nsChromeRegistryContent::RegisterSubstitution(const SubstitutionMapping& aSubstitution) { nsCOMPtr<nsIIOService> io (do_GetIOService()); if (!io) return; nsCOMPtr<nsIProtocolHandler> ph; nsresult rv = io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph)); if (NS_FAILED(rv)) return; nsCOMPtr<nsISubstitutingProtocolHandler> sph (do_QueryInterface(ph)); if (!sph) return; nsCOMPtr<nsIURI> resolvedURI; if (aSubstitution.resolvedURI.spec.Length()) { rv = NS_NewURI(getter_AddRefs(resolvedURI), aSubstitution.resolvedURI.spec, aSubstitution.resolvedURI.charset.get(), nullptr, io); if (NS_FAILED(rv)) return; } rv = sph->SetSubstitution(aSubstitution.path, resolvedURI); if (NS_FAILED(rv)) return; }
NS_IMETHODIMP nsAboutFeeds::NewChannel(nsIURI* uri, nsIChannel** result) { nsresult rv; nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIChannel> channel; rv = ios->NewChannel(NS_LITERAL_CSTRING(FEEDS_PAGE_URI), nsnull, nsnull, getter_AddRefs(channel)); if (NS_FAILED(rv)) return rv; channel->SetOriginalURI(uri); nsCOMPtr<nsIScriptSecurityManager> ssm = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIPrincipal> principal; rv = ssm->GetCodebasePrincipal(uri, getter_AddRefs(principal)); if (NS_FAILED(rv)) return rv; rv = channel->SetOwner(principal); if (NS_FAILED(rv)) return rv; NS_ADDREF(*result = channel); return NS_OK; }
void nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) { nsCOMPtr<nsIIOService> io(do_GetIOService()); if (!io) return; nsCOMPtr<nsIURI> content, locale, skin; if (aPackage.contentBaseURI.spec.Length()) { nsresult rv = NS_NewURI(getter_AddRefs(content), aPackage.contentBaseURI.spec, nullptr, nullptr, io); if (NS_FAILED(rv)) return; } if (aPackage.localeBaseURI.spec.Length()) { nsresult rv = NS_NewURI(getter_AddRefs(locale), aPackage.localeBaseURI.spec, nullptr, nullptr, io); if (NS_FAILED(rv)) return; } if (aPackage.skinBaseURI.spec.Length()) { nsresult rv = NS_NewURI(getter_AddRefs(skin), aPackage.skinBaseURI.spec, nullptr, nullptr, io); if (NS_FAILED(rv)) return; } PackageEntry* entry = new PackageEntry; entry->flags = aPackage.flags; entry->contentBaseURI = content; entry->localeBaseURI = locale; entry->skinBaseURI = skin; mPackagesHash.Put(aPackage.package, entry); }
NS_IMETHODIMP nsURIChecker::Init(nsIURI *aURI) { nsresult rv; nsCOMPtr<nsIIOService> ios = do_GetIOService(&rv); if (NS_FAILED(rv)) return rv; rv = ios->NewChannelFromURI(aURI, getter_AddRefs(mChannel)); if (NS_FAILED(rv)) return rv; if (mAllowHead) { mAllowHead = false; // See if it's an http channel, which needs special treatment: nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel); if (httpChannel) { // We can have an HTTP channel that has a non-HTTP URL if // we're doing FTP via an HTTP proxy, for example. See for // example bug 148813 bool isReallyHTTP = false; aURI->SchemeIs("http", &isReallyHTTP); if (!isReallyHTTP) aURI->SchemeIs("https", &isReallyHTTP); if (isReallyHTTP) { httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("HEAD")); // set back to true so we'll know that this request is issuing // a HEAD request. this is used down in OnStartRequest to // handle cases where we need to repeat the request as a normal // GET to deal with server borkage. mAllowHead = true; } } } return NS_OK; }
bool mozTXTToHTMLConv::CheckURLAndCreateHTML( const nsString& txtURL, const nsString& desc, const modetype mode, nsString& outputHTML) { // Create *uri from txtURL nsCOMPtr<nsIURI> uri; nsresult rv; // Lazily initialize mIOService if (!mIOService) { mIOService = do_GetIOService(); if (!mIOService) return false; } // See if the url should be linkified. NS_ConvertUTF16toUTF8 utf8URL(txtURL); if (!ShouldLinkify(utf8URL)) return false; // it would be faster if we could just check to see if there is a protocol // handler for the url and return instead of actually trying to create a url... rv = mIOService->NewURI(utf8URL, nsnull, nsnull, getter_AddRefs(uri)); // Real work if (NS_SUCCEEDED(rv) && uri) { outputHTML.AssignLiteral("<a class=\"moz-txt-link-"); switch(mode) { case RFC1738: outputHTML.AppendLiteral("rfc1738"); break; case RFC2396E: outputHTML.AppendLiteral("rfc2396E"); break; case freetext: outputHTML.AppendLiteral("freetext"); break; case abbreviated: outputHTML.AppendLiteral("abbreviated"); break; default: break; } nsAutoString escapedURL(txtURL); EscapeStr(escapedURL, true); outputHTML.AppendLiteral("\" href=\""); outputHTML += escapedURL; outputHTML.AppendLiteral("\">"); outputHTML += desc; outputHTML.AppendLiteral("</a>"); return true; } else return false; }
static PRBool IsOffline() { PRBool offline = PR_TRUE; nsCOMPtr<nsIIOService> ios(do_GetIOService()); if (ios) ios->GetOffline(&offline); return offline; }
NS_INTERFACE_MAP_END nsresult nsViewSourceChannel::Init(nsIURI* uri) { mOriginalURI = uri; nsAutoCString path; nsresult rv = uri->GetPath(path); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIIOService> pService(do_GetIOService(&rv)); if (NS_FAILED(rv)) return rv; nsAutoCString scheme; rv = pService->ExtractScheme(path, scheme); if (NS_FAILED(rv)) return rv; // prevent viewing source of javascript URIs (see bug 204779) if (scheme.LowerCaseEqualsLiteral("javascript")) { NS_WARNING("blocking view-source:javascript:"); return NS_ERROR_INVALID_ARG; } // This function is called from within nsViewSourceHandler::NewChannel2 // and sets the right loadInfo right after returning from this function. // Until then we follow the principal of least privilege and use // nullPrincipal as the loadingPrincipal. nsCOMPtr<nsIPrincipal> nullPrincipal = nsNullPrincipal::Create(); NS_ENSURE_TRUE(nullPrincipal, NS_ERROR_FAILURE); rv = pService->NewChannel2(path, nullptr, // aOriginCharset nullptr, // aCharSet nullptr, // aLoadingNode nullPrincipal, nullptr, // aTriggeringPrincipal nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_OTHER, getter_AddRefs(mChannel)); NS_ENSURE_SUCCESS(rv, rv); mIsSrcdocChannel = false; mChannel->SetOriginalURI(mOriginalURI); mHttpChannel = do_QueryInterface(mChannel); mHttpChannelInternal = do_QueryInterface(mChannel); mCachingChannel = do_QueryInterface(mChannel); mCacheInfoChannel = do_QueryInterface(mChannel); mApplicationCacheChannel = do_QueryInterface(mChannel); mUploadChannel = do_QueryInterface(mChannel); mPostChannel = do_QueryInterface(mChannel); return NS_OK; }
inline nsCOMPtr<nsIIOService> GetIOService(nsresult & rv) { // Get the IO service. if (NS_IsMainThread()) { return do_GetIOService(&rv); } return do_ProxiedGetService(NS_IOSERVICE_CONTRACTID, &rv); }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result) { NS_ENSURE_ARG_POINTER(aURI); NS_ASSERTION(result, "must not be null"); nsresult rv; nsCAutoString path; rv = NS_GetAboutModuleName(aURI, path); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); if (NS_FAILED(rv)) return rv; for (int i=0; i<kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; rv = ioService->NewChannel(nsDependentCString(kRedirMap[i].url), nsnull, nsnull, getter_AddRefs(tempChannel)); if (NS_FAILED(rv)) return rv; tempChannel->SetOriginalURI(aURI); // Keep the page from getting unnecessary privileges unless it needs them if (kRedirMap[i].flags & nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT) { nsCOMPtr<nsIScriptSecurityManager> securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIPrincipal> principal; rv = securityManager->GetCodebasePrincipal(aURI, getter_AddRefs(principal)); if (NS_FAILED(rv)) return rv; rv = tempChannel->SetOwner(principal); if (NS_FAILED(rv)) return rv; } NS_ADDREF(*result = tempChannel); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
nsresult sbLocalDatabaseLibraryFactory::SetQueryDatabaseFile (sbIDatabaseQuery* aQuery, nsIFile* aDatabaseFile) { NS_ENSURE_ARG_POINTER(aQuery); NS_ENSURE_ARG_POINTER(aDatabaseFile); nsresult rv; nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); // Figure out a GUID based on the filename. All our database files use the // '.db' extension, so if someone requests another extension then that's just // too bad. nsCOMPtr<nsIURI> fileURI; rv = NS_NewFileURI(getter_AddRefs(fileURI), aDatabaseFile, ioService); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURL> fileURL = do_QueryInterface(fileURI, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString fileBaseName; rv = fileURL->GetFileBaseName(fileBaseName); NS_ENSURE_SUCCESS(rv, rv); rv = aQuery->SetDatabaseGUID(NS_ConvertUTF8toUTF16(fileBaseName)); NS_ENSURE_SUCCESS(rv, rv); #ifdef DEBUG // Warn anyone if they passed in an extension other than '.db'. nsCAutoString fileExtension; rv = fileURL->GetFileExtension(fileExtension); if (NS_SUCCEEDED(rv)) { if (!fileExtension.IsEmpty() && !fileExtension.Equals("db", CaseInsensitiveCompare)) { NS_WARNING("All database files are forced to use the '.db' extension."); } } #endif // Set the parent directory as the location for the library database file. nsCOMPtr<nsIFile> parentDirectory; rv = aDatabaseFile->GetParent(getter_AddRefs(parentDirectory)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> parentURI; rv = NS_NewFileURI(getter_AddRefs(parentURI), parentDirectory, ioService); NS_ENSURE_SUCCESS(rv, rv); rv = aQuery->SetDatabaseLocation(parentURI); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** aResult) { NS_ENSURE_ARG_POINTER(aURI); NS_ASSERTION(aResult, "must not be null"); nsAutoCString path; nsresult rv = NS_GetAboutModuleName(aURI, path); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); for (int i = 0; i < kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; nsCOMPtr<nsIURI> tempURI; rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); NS_ENSURE_SUCCESS(rv, rv); // If tempURI links to an external URI (i.e. something other than // chrome:// or resource://) then set the LOAD_REPLACE flag on the // channel which forces the channel owner to reflect the displayed // URL rather then being the systemPrincipal. bool isUIResource = false; rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE, &isUIResource); NS_ENSURE_SUCCESS(rv, rv); bool isAboutBlank = NS_IsAboutBlank(tempURI); nsLoadFlags loadFlags = isUIResource || isAboutBlank ? static_cast<nsLoadFlags>(nsIChannel::LOAD_NORMAL) : static_cast<nsLoadFlags>(nsIChannel::LOAD_REPLACE); rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), tempURI, aLoadInfo, nullptr, // aLoadGroup nullptr, // aCallbacks loadFlags); NS_ENSURE_SUCCESS(rv, rv); tempChannel->SetOriginalURI(aURI); tempChannel.forget(aResult); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
bool NeckoChild::RecvAppOfflineStatus(const uint32_t& aId, const bool& aOffline) { // Instantiate the service to make sure gIOService is initialized nsCOMPtr<nsIIOService> ioService = do_GetIOService(); if (gIOService) { gIOService->SetAppOfflineInternal(aId, aOffline ? nsIAppOfflineInfo::OFFLINE : nsIAppOfflineInfo::ONLINE); } return true; }
void SubstitutingProtocolHandler::ConstructInternal() { nsresult rv; mIOService = do_GetIOService(&rv); MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mIOService); if (!gResLog) { gResLog = PR_NewLogModule("nsResProtocol"); } }
nsresult nsWebDAVService::EnsureIOService() { if (!mIOService) { nsresult rv; mIOService = do_GetIOService(&rv); if (!mIOService) return rv; } return NS_OK; }
nsresult nsResProtocolHandler::Init() { if (!mSubstitutions.Init(32)) return NS_ERROR_UNEXPECTED; nsresult rv; mIOService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString appURI, greURI; rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, appURI); NS_ENSURE_SUCCESS(rv, rv); rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, greURI); NS_ENSURE_SUCCESS(rv, rv); // // make resource:/// point to the application directory or omnijar // nsCOMPtr<nsIURI> uri; rv = NS_NewURI(getter_AddRefs(uri), appURI.Length() ? appURI : greURI); NS_ENSURE_SUCCESS(rv, rv); rv = SetSubstitution(EmptyCString(), uri); NS_ENSURE_SUCCESS(rv, rv); // // make resource://app/ point to the application directory or omnijar // rv = SetSubstitution(kAPP, uri); NS_ENSURE_SUCCESS(rv, rv); // // make resource://gre/ point to the GRE directory // if (appURI.Length()) { // We already have greURI in uri if appURI.Length() is 0. rv = NS_NewURI(getter_AddRefs(uri), greURI); NS_ENSURE_SUCCESS(rv, rv); } rv = SetSubstitution(kGRE, uri); NS_ENSURE_SUCCESS(rv, rv); //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir... // but once I finish multiple chrome registration I'm not sure that it is needed // XXX dveditz: resource://pchrome/ defeats profile directory salting // if web content can load it. Tread carefully. return rv; }
nsresult nsResProtocolHandler::Init() { if (!mSubstitutions.Init(32)) return NS_ERROR_UNEXPECTED; nsresult rv; mIOService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); #ifdef MOZ_OMNIJAR nsCOMPtr<nsIFile> omniJar(mozilla::OmnijarPath()); if (omniJar) return Init(omniJar); #endif // these entries should be kept in sync with the omnijar Init function // // make resource:/// point to the application directory // rv = AddSpecialDir(NS_OS_CURRENT_PROCESS_DIR, EmptyCString()); NS_ENSURE_SUCCESS(rv, rv); // // make resource://gre/ point to the GRE directory // rv = AddSpecialDir(NS_GRE_DIR, kGRE); NS_ENSURE_SUCCESS(rv, rv); // make resource://gre-resources/ point to gre toolkit[.jar]/res nsCOMPtr<nsIURI> greURI; nsCOMPtr<nsIURI> greResURI; GetSubstitution(kGRE, getter_AddRefs(greURI)); #ifdef MOZ_CHROME_FILE_FORMAT_JAR NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "jar:chrome/toolkit.jar!/res/"); #else NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "chrome/toolkit/res/"); #endif rv = mIOService->NewURI(strGRE_RES_URL, nsnull, greURI, getter_AddRefs(greResURI)); SetSubstitution(kGRE_RESOURCES, greResURI); //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir... // but once I finish multiple chrome registration I'm not sure that it is needed // XXX dveditz: resource://pchrome/ defeats profile directory salting // if web content can load it. Tread carefully. return rv; }
void nsPACMan::StartLoading() { MOZ_ASSERT(NS_IsMainThread(), "wrong thread"); mLoadPending = false; // CancelExistingLoad was called... if (!mLoader) { PostCancelPendingQ(NS_ERROR_ABORT); return; } if (NS_SUCCEEDED(mLoader->Init(this, nullptr))) { // Always hit the origin server when loading PAC. nsCOMPtr<nsIIOService> ios = do_GetIOService(); if (ios) { nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIURI> pacURI; NS_NewURI(getter_AddRefs(pacURI), mPACURISpec); // NOTE: This results in GetProxyForURI being called if (pacURI) { nsresult rv = pacURI->GetSpec(mNormalPACURISpec); MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv)); NS_NewChannel(getter_AddRefs(channel), pacURI, nsContentUtils::GetSystemPrincipal(), nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsIContentPolicy::TYPE_OTHER, nullptr, // aLoadGroup nullptr, // aCallbacks nsIRequest::LOAD_NORMAL, ios); } else { LOG(("nsPACMan::StartLoading Failed pacspec uri conversion %s\n", mPACURISpec.get())); } if (channel) { channel->SetLoadFlags(nsIRequest::LOAD_BYPASS_CACHE); channel->SetNotificationCallbacks(this); if (NS_SUCCEEDED(channel->AsyncOpen2(mLoader))) return; } } } CancelExistingLoad(); PostCancelPendingQ(NS_ERROR_UNEXPECTED); }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** result) { NS_ENSURE_ARG_POINTER(aURI); NS_ASSERTION(result, "must not be null"); nsAutoCString path; nsresult rv = NS_GetAboutModuleName(aURI, path); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); for (int i=0; i<kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; nsCOMPtr<nsIURI> tempURI; rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url); NS_ENSURE_SUCCESS(rv, rv); // Bug 1087720 (and Bug 1099296): // Once all callsites have been updated to call NewChannel2() // instead of NewChannel() we should have a non-null loadInfo // consistently. Until then we have to branch on the loadInfo. if (aLoadInfo) { rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), tempURI, aLoadInfo); } else { rv = ioService->NewChannelFromURI(tempURI, getter_AddRefs(tempChannel)); } if (NS_FAILED(rv)) return rv; tempChannel->SetOriginalURI(aURI); NS_ADDREF(*result = tempChannel); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
NS_IMETHODIMP nsAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result) { NS_ENSURE_ARG_POINTER(aURI); NS_ASSERTION(result, "must not be null"); nsresult rv; nsAutoCString path; rv = NS_GetAboutModuleName(aURI, path); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); if (NS_FAILED(rv)) return rv; for (int i=0; i<kRedirTotal; i++) { if (!strcmp(path.get(), kRedirMap[i].id)) { nsCOMPtr<nsIChannel> tempChannel; rv = ioService->NewChannel(nsDependentCString(kRedirMap[i].url), nullptr, nullptr, getter_AddRefs(tempChannel)); if (NS_FAILED(rv)) return rv; tempChannel->SetOriginalURI(aURI); // Keep the page from getting unnecessary privileges unless it needs them if (kRedirMap[i].flags & nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT) { // Setting the owner to null means that we'll go through the normal // path in GetChannelPrincipal and create a codebase principal based // on the channel's originalURI rv = tempChannel->SetOwner(nullptr); if (NS_FAILED(rv)) return rv; } NS_ADDREF(*result = tempChannel); return rv; } } NS_ERROR("nsAboutRedirector called for unknown case"); return NS_ERROR_ILLEGAL_VALUE; }
ThrottleQueue::ThrottleQueue() : mMeanBytesPerSecond(0) , mMaxBytesPerSecond(0) , mBytesProcessed(0) , mTimerArmed(false) { nsresult rv; nsCOMPtr<nsIEventTarget> sts; nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); if (NS_SUCCEEDED(rv)) sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) mTimer = do_CreateInstance("@mozilla.org/timer;1"); if (mTimer) mTimer->SetTarget(sts); }
void nsChromeRegistryContent::RegisterOverride( const OverrideMapping& aOverride) { nsCOMPtr<nsIIOService> io(do_GetIOService()); if (!io) return; nsCOMPtr<nsIURI> chromeURI, overrideURI; nsresult rv = NS_NewURI(getter_AddRefs(chromeURI), aOverride.originalURI.spec, nullptr, nullptr, io); if (NS_FAILED(rv)) return; rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec, nullptr, nullptr, io); if (NS_FAILED(rv)) return; mOverrideTable.Put(chromeURI, overrideURI); }
void CTests::OnToolsRemoveGHPage() { PRBool theRetVal = PR_FALSE; nsCOMPtr<nsIGlobalHistory> myGHistory(do_GetService(NS_GLOBALHISTORY_CONTRACTID)); if (!myGHistory) { QAOutput("Could not get the global history object.", 2); return; } nsCOMPtr<nsIBrowserHistory> myHistory = do_QueryInterface(myGHistory, &rv); if(NS_FAILED(rv)) { QAOutput("Could not get the history object.", 2); return; } if (myDialog.DoModal() == IDOK) { QAOutput("Begin URL removal from the GH file.", 2); myGHistory->IsVisited(myDialog.m_urlfield, &theRetVal); if (theRetVal) { nsCOMPtr<nsIIOService> ios = do_GetIOService(); if (ios) { nsCOMPtr<nsIURI> uri; ios->NewURI(nsDependentCString(myDialog.m_urlfield), nsnull, nsnull, getter_AddRefs(uri)); if (uri) { rv = myHistory->RemovePage(uri); RvTestResult(rv, "RemovePage() test (url removal from GH file)", 2); } } } else { QAOutput("The URL wasn't in the GH file.\r\n", 1); } QAOutput("End URL removal from the GH file.", 2); } else QAOutput("URL removal from the GH file not executed.", 2); }
/** Ensures basic sanity of attribute value. This function also (tries to :-( ) makes sure, that no unwanted / dangerous URLs appear in the document (like javascript: and data:). Pass the value as |aValue| arg. It will be modified in-place. If the value is not allowed at all, we return with NS_ERROR_ILLEGAL_VALUE. In that case, do not use the |aValue|, but output nothing. */ nsresult mozSanitizingHTMLSerializer::SanitizeAttrValue(nsHTMLTag aTag, const nsAString& anAttrName, nsString& aValue /*inout*/) { /* First, cut the attribute to 1000 chars. Attributes with values longer than 1000 chars seem bogus, considering that we don't support any JS. The longest attributes I can think of are URLs, and URLs with 1000 chars are likely to be bogus, too. */ aValue = Substring(aValue, 0, 1000); //aValue.Truncate(1000); //-- this cuts half of the document !!?!! aValue.Adopt(escape(aValue)); /* Check some known bad stuff. Add more! I don't care too much, if it happens to trigger in some innocent cases (like <img alt="Statistical data: Mortage rates and newspapers">) - security first. */ if (aValue.Find("javascript:") != kNotFound || aValue.Find("data:") != kNotFound || aValue.Find("base64") != kNotFound) return NS_ERROR_ILLEGAL_VALUE; // Check img src scheme if (aTag == eHTMLTag_img && anAttrName.LowerCaseEqualsLiteral("src")) { nsresult rv; nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString scheme; rv = ioService->ExtractScheme(NS_LossyConvertUTF16toASCII(aValue), scheme); NS_ENSURE_SUCCESS(rv, rv); if (!scheme.Equals("cid", nsCaseInsensitiveCStringComparator())) return NS_ERROR_ILLEGAL_VALUE; } #ifdef DEBUG_BenB printf("attribute value for %s: -%s-\n", NS_LossyConvertUTF16toASCII(anAttrName).get(), NS_LossyConvertUTF16toASCII(aValue).get()); #endif return NS_OK; }
NS_INTERFACE_MAP_END nsresult nsViewSourceChannel::Init(nsIURI* uri) { mOriginalURI = uri; nsAutoCString path; nsresult rv = uri->GetPath(path); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIIOService> pService(do_GetIOService(&rv)); if (NS_FAILED(rv)) return rv; nsAutoCString scheme; rv = pService->ExtractScheme(path, scheme); if (NS_FAILED(rv)) return rv; // prevent viewing source of javascript URIs (see bug 204779) if (scheme.LowerCaseEqualsLiteral("javascript")) { NS_WARNING("blocking view-source:javascript:"); return NS_ERROR_INVALID_ARG; } rv = pService->NewChannel(path, nullptr, nullptr, getter_AddRefs(mChannel)); if (NS_FAILED(rv)) return rv; mIsSrcdocChannel = false; mChannel->SetOriginalURI(mOriginalURI); mHttpChannel = do_QueryInterface(mChannel); mHttpChannelInternal = do_QueryInterface(mChannel); mCachingChannel = do_QueryInterface(mChannel); mApplicationCacheChannel = do_QueryInterface(mChannel); mUploadChannel = do_QueryInterface(mChannel); return NS_OK; }