Bug 1297961 (part 1) - Introduce nsURI::GetSpecOrDefault(). r=hurley.

This function is an infallible alternative to nsIURI::GetSpec(). It's useful
when it's appropriate to handle a GetSpec() failure with a failure string, e.g.
for log/warning/error messages. It allows code like this:

  nsAutoCString spec;
  uri->GetSpec(spec);
  printf("uri: %s", spec.get());

to be changed to this:

  printf("uri: %s", uri->GetSpecOrDefault().get());

This introduces a slight behavioural change. Previously, if GetSpec() failed,
an empty string would be used here. Now, "[nsIURI::GetSpec failed]" will be
produced instead. In most cases this failure string will make for a clearer
log/warning/error message than the empty string.
* * *
Bug 1297961 (part 1b) - More GetSpecOrDefault() additions. r=hurley.

I will fold this into part 1 before landing.

--HG--
extra : rebase_source : ddc19a5624354ac098be019ca13cc24b99b80ddc
This commit is contained in:
Nicholas Nethercote 2016-08-26 16:02:31 +10:00
Родитель 445be7ebea
Коммит 742fc7eb48
48 изменённых файлов: 243 добавлений и 424 удалений

Просмотреть файл

@ -90,10 +90,7 @@ EnableLogging(const char* aModulesStr)
static void
LogDocURI(nsIDocument* aDocumentNode)
{
nsIURI* uri = aDocumentNode->GetDocumentURI();
nsAutoCString spec;
uri->GetSpec(spec);
printf("uri: %s", spec.get());
printf("uri: %s", aDocumentNode->GetDocumentURI()->GetSpecOrDefault().get());
}
static void

Просмотреть файл

@ -139,9 +139,8 @@ nsChromeProtocolHandler::NewChannel2(nsIURI* aURI,
rv = nsChromeRegistry::gChromeRegistry->ConvertChromeURL(aURI, getter_AddRefs(resolvedURI));
if (NS_FAILED(rv)) {
#ifdef DEBUG
nsAutoCString spec;
aURI->GetSpec(spec);
printf("Couldn't convert chrome URL: %s\n", spec.get());
printf("Couldn't convert chrome URL: %s\n",
aURI->GetSpecOrDefault().get());
#endif
return rv;
}

Просмотреть файл

@ -1877,11 +1877,8 @@ nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
bool aFireOnLocationChange, uint32_t aLocationFlags)
{
if (gDocShellLeakLog && MOZ_LOG_TEST(gDocShellLeakLog, LogLevel::Debug)) {
nsAutoCString spec;
if (aURI) {
aURI->GetSpec(spec);
}
PR_LogPrint("DOCSHELL %p SetCurrentURI %s\n", this, spec.get());
PR_LogPrint("DOCSHELL %p SetCurrentURI %s\n",
this, aURI ? aURI->GetSpecOrDefault().get() : "");
}
// We don't want to send a location change when we're displaying an error
@ -5249,9 +5246,6 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
{
#if defined(DEBUG)
if (MOZ_LOG_TEST(gDocShellLog, LogLevel::Debug)) {
nsAutoCString spec;
aURI->GetSpec(spec);
nsAutoCString chanName;
if (aFailedChannel) {
aFailedChannel->GetName(chanName);
@ -5261,7 +5255,8 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
MOZ_LOG(gDocShellLog, LogLevel::Debug,
("nsDocShell[%p]::LoadErrorPage(\"%s\", \"%s\", {...}, [%s])\n", this,
spec.get(), NS_ConvertUTF16toUTF8(aURL).get(), chanName.get()));
aURI->GetSpecOrDefault().get(), NS_ConvertUTF16toUTF8(aURL).get(),
chanName.get()));
}
#endif
mFailedChannel = aFailedChannel;
@ -9718,11 +9713,8 @@ nsDocShell::InternalLoad(nsIURI* aURI,
mOriginalUriString.Truncate();
if (gDocShellLeakLog && MOZ_LOG_TEST(gDocShellLeakLog, LogLevel::Debug)) {
nsAutoCString spec;
if (aURI) {
aURI->GetSpec(spec);
}
PR_LogPrint("DOCSHELL %p InternalLoad %s\n", this, spec.get());
PR_LogPrint("DOCSHELL %p InternalLoad %s\n",
this, aURI ? aURI->GetSpecOrDefault().get() : "");
}
// Initialize aDocShell/aRequest
if (aDocShell) {
@ -11433,9 +11425,6 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
#if defined(DEBUG)
if (MOZ_LOG_TEST(gDocShellLog, LogLevel::Debug)) {
nsAutoCString spec;
aURI->GetSpec(spec);
nsAutoCString chanName;
if (aChannel) {
aChannel->GetName(chanName);
@ -11444,8 +11433,8 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
}
MOZ_LOG(gDocShellLog, LogLevel::Debug,
("nsDocShell[%p]::OnNewURI(\"%s\", [%s], 0x%x)\n", this, spec.get(),
chanName.get(), aLoadType));
("nsDocShell[%p]::OnNewURI(\"%s\", [%s], 0x%x)\n",
this, aURI->GetSpecOrDefault().get(), chanName.get(), aLoadType));
}
#endif
@ -12079,9 +12068,6 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
#if defined(DEBUG)
if (MOZ_LOG_TEST(gDocShellLog, LogLevel::Debug)) {
nsAutoCString spec;
aURI->GetSpec(spec);
nsAutoCString chanName;
if (aChannel) {
aChannel->GetName(chanName);
@ -12090,8 +12076,8 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
}
MOZ_LOG(gDocShellLog, LogLevel::Debug,
("nsDocShell[%p]::AddToSessionHistory(\"%s\", [%s])\n",
this, spec.get(), chanName.get()));
("nsDocShell[%p]::AddToSessionHistory(\"%s\", [%s])\n",
this, aURI->GetSpecOrDefault().get(), chanName.get()));
}
#endif

Просмотреть файл

@ -74,7 +74,7 @@ static LazyLogModule gSHistoryLog("nsSHistory");
if (MOZ_LOG_TEST(gSHistoryLog, LogLevel::Debug)) { \
nsAutoCString _specStr(NS_LITERAL_CSTRING("(null)"));\
if (uri) { \
uri->GetSpec(_specStr); \
_specStr = uri->GetSpecOrDefault(); \
} \
const char* _spec = _specStr.get(); \
LOG(format); \

Просмотреть файл

@ -203,29 +203,25 @@ nsContentPolicy::CheckPolicy(CPMethod policyMethod,
//uses the parameters from ShouldXYZ to produce and log a message
//logType must be a literal string constant
#define LOG_CHECK(logType) \
PR_BEGIN_MACRO \
/* skip all this nonsense if the call failed or logging is disabled */ \
if (NS_SUCCEEDED(rv) && MOZ_LOG_TEST(gConPolLog, LogLevel::Debug)) { \
const char *resultName; \
if (decision) { \
resultName = NS_CP_ResponseName(*decision); \
} else { \
resultName = "(null ptr)"; \
} \
nsAutoCString spec("None"); \
if (contentLocation) { \
contentLocation->GetSpec(spec); \
} \
nsAutoCString refSpec("None"); \
if (requestingLocation) { \
requestingLocation->GetSpec(refSpec); \
} \
MOZ_LOG(gConPolLog, LogLevel::Debug, \
("Content Policy: " logType ": <%s> <Ref:%s> result=%s", \
spec.get(), refSpec.get(), resultName) \
); \
} \
#define LOG_CHECK(logType) \
PR_BEGIN_MACRO \
/* skip all this nonsense if the call failed or logging is disabled */ \
if (NS_SUCCEEDED(rv) && MOZ_LOG_TEST(gConPolLog, LogLevel::Debug)) { \
const char *resultName; \
if (decision) { \
resultName = NS_CP_ResponseName(*decision); \
} else { \
resultName = "(null ptr)"; \
} \
MOZ_LOG(gConPolLog, LogLevel::Debug, \
("Content Policy: " logType ": <%s> <Ref:%s> result=%s", \
contentLocation ? contentLocation->GetSpecOrDefault().get() \
: "None", \
requestingLocation ? requestingLocation->GetSpecOrDefault().get()\
: "None", \
resultName) \
); \
} \
PR_END_MACRO
NS_IMETHODIMP

Просмотреть файл

@ -5157,9 +5157,7 @@ nsContentUtils::WarnScriptWasIgnored(nsIDocument* aDocument)
if (aDocument) {
nsCOMPtr<nsIURI> uri = aDocument->GetDocumentURI();
if (uri) {
nsCString spec;
uri->GetSpec(spec);
msg.Append(NS_ConvertUTF8toUTF16(spec));
msg.Append(NS_ConvertUTF8toUTF16(uri->GetSpecOrDefault()));
msg.AppendLiteral(" : ");
}
}

Просмотреть файл

@ -1792,7 +1792,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
uint32_t nsid = tmp->GetDefaultNamespaceID();
nsAutoCString uri;
if (tmp->mDocumentURI)
tmp->mDocumentURI->GetSpec(uri);
uri = tmp->mDocumentURI->GetSpecOrDefault();
if (nsid < ArrayLength(kNSURIs)) {
SprintfLiteral(name, "nsDocument %s %s %s",
loadedAsData.get(), kNSURIs[nsid], uri.get());
@ -2187,9 +2187,8 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
NS_PRECONDITION(aURI, "Null URI passed to ResetToURI");
if (gDocumentLeakPRLog && MOZ_LOG_TEST(gDocumentLeakPRLog, LogLevel::Debug)) {
nsAutoCString spec;
aURI->GetSpec(spec);
PR_LogPrint("DOCUMENT %p ResetToURI %s", this, spec.get());
PR_LogPrint("DOCUMENT %p ResetToURI %s", this,
aURI->GetSpecOrDefault().get());
}
mSecurityInfo = nullptr;
@ -2528,10 +2527,8 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
if (gDocumentLeakPRLog && MOZ_LOG_TEST(gDocumentLeakPRLog, LogLevel::Debug)) {
nsCOMPtr<nsIURI> uri;
aChannel->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
if (uri)
uri->GetSpec(spec);
PR_LogPrint("DOCUMENT %p StartDocumentLoad %s", this, spec.get());
PR_LogPrint("DOCUMENT %p StartDocumentLoad %s",
this, uri ? uri->GetSpecOrDefault().get() : "");
}
MOZ_ASSERT(NodePrincipal()->GetAppId() != nsIScriptSecurityManager::UNKNOWN_APP_ID,
@ -13055,8 +13052,7 @@ nsDocument::ReportUseCounters()
}
if (sDebugUseCounters) {
nsCString spec;
uri->GetSpec(spec);
nsCString spec = uri->GetSpecOrDefault();
// URIs can be rather long for data documents, so truncate them to
// some reasonable length.

Просмотреть файл

@ -512,9 +512,9 @@ nsFocusManager::MoveFocus(mozIDOMWindowProxy* aWindow, nsIDOMElement* aStartElem
if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug) && mFocusedWindow) {
nsIDocument* doc = mFocusedWindow->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
nsAutoCString spec;
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Focused Window: %p %s", mFocusedWindow.get(), spec.get()));
LOGFOCUS((" Focused Window: %p %s",
mFocusedWindow.get(),
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
}
@ -664,17 +664,16 @@ nsFocusManager::WindowRaised(mozIDOMWindowProxy* aWindow)
if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug)) {
LOGFOCUS(("Window %p Raised [Currently: %p %p]", aWindow, mActiveWindow.get(), mFocusedWindow.get()));
nsAutoCString spec;
nsIDocument* doc = window->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Raised Window: %p %s", aWindow, spec.get()));
LOGFOCUS((" Raised Window: %p %s", aWindow,
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
if (mActiveWindow) {
doc = mActiveWindow->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Active Window: %p %s", mActiveWindow.get(), spec.get()));
LOGFOCUS((" Active Window: %p %s", mActiveWindow.get(),
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
}
}
@ -750,17 +749,16 @@ nsFocusManager::WindowLowered(mozIDOMWindowProxy* aWindow)
if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug)) {
LOGFOCUS(("Window %p Lowered [Currently: %p %p]", aWindow, mActiveWindow.get(), mFocusedWindow.get()));
nsAutoCString spec;
nsIDocument* doc = window->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Lowered Window: %s", spec.get()));
LOGFOCUS((" Lowered Window: %s",
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
if (mActiveWindow) {
doc = mActiveWindow->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Active Window: %s", spec.get()));
LOGFOCUS((" Active Window: %s",
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
}
}
@ -879,18 +877,17 @@ nsFocusManager::WindowShown(mozIDOMWindowProxy* aWindow, bool aNeedsFocus)
if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug)) {
LOGFOCUS(("Window %p Shown [Currently: %p %p]", window.get(), mActiveWindow.get(), mFocusedWindow.get()));
nsAutoCString spec;
nsIDocument* doc = window->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS(("Shown Window: %s", spec.get()));
LOGFOCUS(("Shown Window: %s",
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
if (mFocusedWindow) {
doc = mFocusedWindow->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Focused Window: %s", spec.get()));
LOGFOCUS((" Focused Window: %s",
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
}
}
@ -937,23 +934,23 @@ nsFocusManager::WindowHidden(mozIDOMWindowProxy* aWindow)
nsAutoCString spec;
nsIDocument* doc = window->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Hide Window: %s", spec.get()));
LOGFOCUS((" Hide Window: %s",
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
if (mFocusedWindow) {
doc = mFocusedWindow->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Focused Window: %s", spec.get()));
LOGFOCUS((" Focused Window: %s",
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
}
if (mActiveWindow) {
doc = mActiveWindow->GetExtantDoc();
if (doc && doc->GetDocumentURI()) {
doc->GetDocumentURI()->GetSpec(spec);
LOGFOCUS((" Active Window: %s", spec.get()));
LOGFOCUS((" Active Window: %s",
doc->GetDocumentURI()->GetSpecOrDefault().get()));
}
}
}

Просмотреть файл

@ -1359,7 +1359,7 @@ nsGlobalWindow::~nsGlobalWindow()
if (!PR_GetEnv("MOZ_QUIET")) {
nsAutoCString url;
if (mLastOpenedURI) {
mLastOpenedURI->GetSpec(url);
url = mLastOpenedURI->GetSpecOrDefault();
// Data URLs can be very long, so truncate to avoid flooding the log.
const uint32_t maxURLLength = 1000;
@ -1846,7 +1846,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
char name[512];
nsAutoCString uri;
if (tmp->mDoc && tmp->mDoc->GetDocumentURI()) {
tmp->mDoc->GetDocumentURI()->GetSpec(uri);
uri = tmp->mDoc->GetDocumentURI()->GetSpecOrDefault();
}
SprintfLiteral(name, "nsGlobalWindow # %" PRIu64 " %s %s", tmp->mWindowID,
tmp->IsInnerWindow() ? "inner" : "outer", uri.get());
@ -2993,10 +2993,8 @@ nsGlobalWindow::InnerSetNewDocument(JSContext* aCx, nsIDocument* aDocument)
if (gDOMLeakPRLog && MOZ_LOG_TEST(gDOMLeakPRLog, LogLevel::Debug)) {
nsIURI *uri = aDocument->GetDocumentURI();
nsAutoCString spec;
if (uri)
uri->GetSpec(spec);
PR_LogPrint("DOMWINDOW %p SetNewDocument %s", this, spec.get());
PR_LogPrint("DOMWINDOW %p SetNewDocument %s",
this, uri ? uri->GetSpecOrDefault().get() : "");
}
mDoc = aDocument;

Просмотреть файл

@ -531,9 +531,7 @@ PrintWinURI(nsGlobalWindow *win)
return;
}
nsAutoCString spec;
uri->GetSpec(spec);
printf("%s\n", spec.get());
printf("%s\n", uri->GetSpecOrDefault().get());
}
void
@ -557,9 +555,7 @@ PrintWinCodebase(nsGlobalWindow *win)
return;
}
nsAutoCString spec;
uri->GetSpec(spec);
printf("%s\n", spec.get());
printf("%s\n", uri->GetSpecOrDefault().get());
}
void

Просмотреть файл

@ -1139,10 +1139,8 @@ nsObjectLoadingContent::OnStartRequest(nsIRequest *aRequest,
if (console) {
nsCOMPtr<nsIURI> uri;
chan->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
nsString message = NS_LITERAL_STRING("Blocking ") +
NS_ConvertASCIItoUTF16(spec.get()) +
NS_ConvertASCIItoUTF16(uri->GetSpecOrDefault().get()) +
NS_LITERAL_STRING(" since it was found on an internal Firefox blocklist.");
console->LogStringMessage(message.get());
}
@ -1649,12 +1647,8 @@ nsObjectLoadingContent::CheckLoadPolicy(int16_t *aContentPolicy)
nsContentUtils::GetSecurityManager());
NS_ENSURE_SUCCESS(rv, false);
if (NS_CP_REJECTED(*aContentPolicy)) {
nsAutoCString uri;
nsAutoCString baseUri;
mURI->GetSpec(uri);
mURI->GetSpec(baseUri);
LOG(("OBJLC [%p]: Content policy denied load of %s (base %s)",
this, uri.get(), baseUri.get()));
LOG(("OBJLC [%p]: Content policy denied load of %s",
this, mURI->GetSpecOrDefault().get()));
return false;
}

Просмотреть файл

@ -170,8 +170,7 @@ AppendWindowURI(nsGlobalWindow *aWindow, nsACString& aStr, bool aAnonymize)
if (aAnonymize && !aWindow->IsChromeWindow()) {
aStr.AppendPrintf("<anonymized-%llu>", aWindow->WindowID());
} else {
nsCString spec;
uri->GetSpec(spec);
nsCString spec = uri->GetSpecOrDefault();
// A hack: replace forward slashes with '\\' so they aren't
// treated as path separators. Users of the reporters

Просмотреть файл

@ -1506,15 +1506,9 @@ nsHTMLDocument::Open(JSContext* cx,
#ifdef DEBUG
nsCOMPtr<nsIURI> callerDocURI = callerDoc->GetDocumentURI();
nsCOMPtr<nsIURI> thisURI = nsIDocument::GetDocumentURI();
nsAutoCString callerSpec;
nsAutoCString thisSpec;
if (callerDocURI) {
callerDocURI->GetSpec(callerSpec);
}
if (thisURI) {
thisURI->GetSpec(thisSpec);
}
printf("nsHTMLDocument::Open callerDoc %s this %s\n", callerSpec.get(), thisSpec.get());
printf("nsHTMLDocument::Open callerDoc %s this %s\n",
callerDocURI ? callerDocURI->GetSpecOrDefault().get() : "",
thisURI ? thisURI->GetSpecOrDefault().get() : "");
#endif
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);

Просмотреть файл

@ -949,12 +949,10 @@ nsPluginHost::TrySetUpPluginInstance(const nsACString &aMimeType,
nsPluginInstanceOwner *aOwner)
{
#ifdef PLUGIN_LOGGING
nsAutoCString urlSpec;
if (aURL != nullptr) aURL->GetSpec(urlSpec);
MOZ_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
("nsPluginHost::TrySetupPluginInstance Begin mime=%s, owner=%p, url=%s\n",
PromiseFlatCString(aMimeType).get(), aOwner, urlSpec.get()));
("nsPluginHost::TrySetupPluginInstance Begin mime=%s, owner=%p, url=%s\n",
PromiseFlatCString(aMimeType).get(), aOwner,
aURL ? aURL->GetSpecOrDefault().get() : ""));
PR_LogFlush();
#endif
@ -1013,13 +1011,10 @@ nsPluginHost::TrySetUpPluginInstance(const nsACString &aMimeType,
}
#ifdef PLUGIN_LOGGING
nsAutoCString urlSpec2;
if (aURL)
aURL->GetSpec(urlSpec2);
MOZ_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_BASIC,
("nsPluginHost::TrySetupPluginInstance Finished mime=%s, rv=%d, owner=%p, url=%s\n",
PromiseFlatCString(aMimeType).get(), rv, aOwner, urlSpec2.get()));
PromiseFlatCString(aMimeType).get(), rv, aOwner,
aURL ? aURL->GetSpecOrDefault().get() : ""));
PR_LogFlush();
#endif

Просмотреть файл

@ -310,11 +310,9 @@ nsresult nsPluginStreamListenerPeer::Initialize(nsIURI *aURL,
nsNPAPIPluginStreamListener* aListener)
{
#ifdef PLUGIN_LOGGING
nsAutoCString urlSpec;
if (aURL != nullptr) aURL->GetSpec(urlSpec);
MOZ_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL,
("nsPluginStreamListenerPeer::Initialize instance=%p, url=%s\n", aInstance, urlSpec.get()));
("nsPluginStreamListenerPeer::Initialize instance=%p, url=%s\n",
aInstance, aURL ? aURL->GetSpecOrDefault().get() : ""));
PR_LogFlush();
#endif

Просмотреть файл

@ -63,13 +63,11 @@ IsEligible(nsIChannel* aChannel, const CORSMode aCORSMode,
NS_ENSURE_SUCCESS(rv, rv);
if (MOZ_LOG_TEST(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug)) {
nsAutoCString documentSpec, finalSpec;
nsAutoCString documentSpec;
aDocument->GetDocumentURI()->GetAsciiSpec(documentSpec);
if (finalURI) {
finalURI->GetSpec(finalSpec);
}
SRILOG(("SRICheck::IsEligible, documentURI=%s; requestURI=%s; finalURI=%s",
documentSpec.get(), requestSpec.get(), finalSpec.get()));
documentSpec.get(), requestSpec.get(),
finalURI ? finalURI->GetSpecOrDefault().get() : ""));
}
// Is the sub-resource same-origin?

Просмотреть файл

@ -109,9 +109,8 @@ nsCSPContext::ShouldLoad(nsContentPolicyType aContentType,
int16_t* outDecision)
{
if (CSPCONTEXTLOGENABLED()) {
nsAutoCString spec;
aContentLocation->GetSpec(spec);
CSPCONTEXTLOG(("nsCSPContext::ShouldLoad, aContentLocation: %s", spec.get()));
CSPCONTEXTLOG(("nsCSPContext::ShouldLoad, aContentLocation: %s",
aContentLocation->GetSpecOrDefault().get()));
CSPCONTEXTLOG((">>>> aContentType: %d", aContentType));
}
@ -185,9 +184,10 @@ nsCSPContext::ShouldLoad(nsContentPolicyType aContentType,
}
if (CSPCONTEXTLOGENABLED()) {
nsAutoCString spec;
aContentLocation->GetSpec(spec);
CSPCONTEXTLOG(("nsCSPContext::ShouldLoad, decision: %s, aContentLocation: %s", *outDecision > 0 ? "load" : "deny", spec.get()));
CSPCONTEXTLOG(("nsCSPContext::ShouldLoad, decision: %s, "
"aContentLocation: %s",
*outDecision > 0 ? "load" : "deny",
aContentLocation->GetSpecOrDefault().get()));
}
return NS_OK;
}
@ -1226,9 +1226,8 @@ nsCSPContext::PermitsAncestry(nsIDocShell* aDocShell, bool* outPermitsAncestry)
uriClone->SetUserPass(EmptyCString());
if (CSPCONTEXTLOGENABLED()) {
nsAutoCString spec;
uriClone->GetSpec(spec);
CSPCONTEXTLOG(("nsCSPContext::PermitsAncestry, found ancestor: %s", spec.get()));
CSPCONTEXTLOG(("nsCSPContext::PermitsAncestry, found ancestor: %s",
uriClone->GetSpecOrDefault().get()));
}
ancestorsArray.AppendElement(uriClone);
}
@ -1246,9 +1245,8 @@ nsCSPContext::PermitsAncestry(nsIDocShell* aDocShell, bool* outPermitsAncestry)
for (uint32_t a = 0; a < ancestorsArray.Length(); a++) {
if (CSPCONTEXTLOGENABLED()) {
nsAutoCString spec;
ancestorsArray[a]->GetSpec(spec);
CSPCONTEXTLOG(("nsCSPContext::PermitsAncestry, checking ancestor: %s", spec.get()));
CSPCONTEXTLOG(("nsCSPContext::PermitsAncestry, checking ancestor: %s",
ancestorsArray[a]->GetSpecOrDefault().get()));
}
// omit the ancestor URI in violation reports if cross-origin as per spec
// (it is a violation of the same-origin policy).
@ -1293,11 +1291,9 @@ nsCSPContext::Permits(nsIURI* aURI,
true); // send blocked URI in violation reports
if (CSPCONTEXTLOGENABLED()) {
nsAutoCString spec;
aURI->GetSpec(spec);
CSPCONTEXTLOG(("nsCSPContext::Permits, aUri: %s, aDir: %d, isAllowed: %s",
spec.get(), aDir,
*outPermits ? "allow" : "deny"));
aURI->GetSpecOrDefault().get(), aDir,
*outPermits ? "allow" : "deny"));
}
return NS_OK;

Просмотреть файл

@ -1303,9 +1303,8 @@ nsCSPParser::parseContentSecurityPolicy(const nsAString& aPolicyString,
if (CSPPARSERLOGENABLED()) {
CSPPARSERLOG(("nsCSPParser::parseContentSecurityPolicy, policy: %s",
NS_ConvertUTF16toUTF8(aPolicyString).get()));
nsAutoCString spec;
aSelfURI->GetSpec(spec);
CSPPARSERLOG(("nsCSPParser::parseContentSecurityPolicy, selfURI: %s", spec.get()));
CSPPARSERLOG(("nsCSPParser::parseContentSecurityPolicy, selfURI: %s",
aSelfURI->GetSpecOrDefault().get()));
CSPPARSERLOG(("nsCSPParser::parseContentSecurityPolicy, reportOnly: %s",
(aReportOnly ? "true" : "false")));
CSPPARSERLOG(("nsCSPParser::parseContentSecurityPolicy, deliveredViaMetaTag: %s",

Просмотреть файл

@ -117,10 +117,9 @@ CSPService::ShouldLoad(uint32_t aContentType,
}
if (MOZ_LOG_TEST(gCspPRLog, LogLevel::Debug)) {
nsAutoCString location;
aContentLocation->GetSpec(location);
MOZ_LOG(gCspPRLog, LogLevel::Debug,
("CSPService::ShouldLoad called for %s", location.get()));
("CSPService::ShouldLoad called for %s",
aContentLocation->GetSpecOrDefault().get()));
}
// default decision, CSP can revise it if there's a policy to enforce
@ -210,10 +209,9 @@ CSPService::ShouldProcess(uint32_t aContentType,
}
if (MOZ_LOG_TEST(gCspPRLog, LogLevel::Debug)) {
nsAutoCString location;
aContentLocation->GetSpec(location);
MOZ_LOG(gCspPRLog, LogLevel::Debug,
("CSPService::ShouldProcess called for %s", location.get()));
("CSPService::ShouldProcess called for %s",
aContentLocation->GetSpecOrDefault().get()));
}
// ShouldProcess is only relevant to TYPE_OBJECT, so let's convert the

Просмотреть файл

@ -370,9 +370,8 @@ nsCSPBaseSrc::permits(nsIURI* aUri, const nsAString& aNonce, bool aWasRedirected
bool aReportOnly, bool aUpgradeInsecure) const
{
if (CSPUTILSLOGENABLED()) {
nsAutoCString spec;
aUri->GetSpec(spec);
CSPUTILSLOG(("nsCSPBaseSrc::permits, aUri: %s", spec.get()));
CSPUTILSLOG(("nsCSPBaseSrc::permits, aUri: %s",
aUri->GetSpecOrDefault().get()));
}
return false;
}
@ -406,9 +405,8 @@ nsCSPSchemeSrc::permits(nsIURI* aUri, const nsAString& aNonce, bool aWasRedirect
bool aReportOnly, bool aUpgradeInsecure) const
{
if (CSPUTILSLOGENABLED()) {
nsAutoCString spec;
aUri->GetSpec(spec);
CSPUTILSLOG(("nsCSPSchemeSrc::permits, aUri: %s", spec.get()));
CSPUTILSLOG(("nsCSPSchemeSrc::permits, aUri: %s",
aUri->GetSpecOrDefault().get()));
}
MOZ_ASSERT((!mScheme.EqualsASCII("")), "scheme can not be the empty string");
return permitsScheme(mScheme, aUri, aReportOnly, aUpgradeInsecure);
@ -527,9 +525,8 @@ nsCSPHostSrc::permits(nsIURI* aUri, const nsAString& aNonce, bool aWasRedirected
bool aReportOnly, bool aUpgradeInsecure) const
{
if (CSPUTILSLOGENABLED()) {
nsAutoCString spec;
aUri->GetSpec(spec);
CSPUTILSLOG(("nsCSPHostSrc::permits, aUri: %s", spec.get()));
CSPUTILSLOG(("nsCSPHostSrc::permits, aUri: %s",
aUri->GetSpecOrDefault().get()));
}
// we are following the enforcement rules from the spec, see:
@ -752,10 +749,9 @@ nsCSPNonceSrc::permits(nsIURI* aUri, const nsAString& aNonce, bool aWasRedirecte
bool aReportOnly, bool aUpgradeInsecure) const
{
if (CSPUTILSLOGENABLED()) {
nsAutoCString spec;
aUri->GetSpec(spec);
CSPUTILSLOG(("nsCSPNonceSrc::permits, aUri: %s, aNonce: %s",
spec.get(), NS_ConvertUTF16toUTF8(aNonce).get()));
aUri->GetSpecOrDefault().get(),
NS_ConvertUTF16toUTF8(aNonce).get()));
}
return mNonce.Equals(aNonce);
@ -923,9 +919,8 @@ nsCSPDirective::permits(nsIURI* aUri, const nsAString& aNonce, bool aWasRedirect
bool aReportOnly, bool aUpgradeInsecure) const
{
if (CSPUTILSLOGENABLED()) {
nsAutoCString spec;
aUri->GetSpec(spec);
CSPUTILSLOG(("nsCSPDirective::permits, aUri: %s", spec.get()));
CSPUTILSLOG(("nsCSPDirective::permits, aUri: %s",
aUri->GetSpecOrDefault().get()));
}
for (uint32_t i = 0; i < mSrcs.Length(); i++) {
@ -1278,10 +1273,9 @@ nsCSPPolicy::permits(CSPDirective aDir,
nsAString& outViolatedDirective) const
{
if (CSPUTILSLOGENABLED()) {
nsAutoCString spec;
aUri->GetSpec(spec);
CSPUTILSLOG(("nsCSPPolicy::permits, aUri: %s, aDir: %d, aSpecific: %s",
spec.get(), aDir, aSpecific ? "true" : "false"));
aUri->GetSpecOrDefault().get(), aDir,
aSpecific ? "true" : "false"));
}
NS_ASSERTION(aUri, "permits needs an uri to perform the check!");

Просмотреть файл

@ -231,10 +231,7 @@ LogMixedContentMessage(MixedContentTypes aClassification,
}
}
nsAutoCString locationSpec;
aContentLocation->GetSpec(locationSpec);
NS_ConvertUTF8toUTF16 locationSpecUTF16(locationSpec);
NS_ConvertUTF8toUTF16 locationSpecUTF16(aContentLocation->GetSpecOrDefault());
const char16_t* strings[] = { locationSpecUTF16.get() };
nsContentUtils::ReportToConsole(severityFlag, messageCategory, aRootDoc,
nsContentUtils::eSECURITY_PROPERTIES,

Просмотреть файл

@ -86,9 +86,7 @@ IsAncestorBinding(nsIDocument* aDocument,
if (bindingRecursion < NS_MAX_XBL_BINDING_RECURSION) {
continue;
}
nsAutoCString spec;
aChildBindingURI->GetSpec(spec);
NS_ConvertUTF8toUTF16 bindingURI(spec);
NS_ConvertUTF8toUTF16 bindingURI(aChildBindingURI->GetSpecOrDefault());
const char16_t* params[] = { bindingURI.get() };
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("XBL"), aDocument,
@ -457,9 +455,7 @@ nsXBLService::LoadBindings(nsIContent* aContent, nsIURI* aURL,
if (!newBinding) {
#ifdef DEBUG
nsAutoCString spec;
aURL->GetSpec(spec);
nsAutoCString str(NS_LITERAL_CSTRING("Failed to locate XBL binding. XBL is now using id instead of name to reference bindings. Make sure you have switched over. The invalid binding name is: ") + spec);
nsAutoCString str(NS_LITERAL_CSTRING("Failed to locate XBL binding. XBL is now using id instead of name to reference bindings. Make sure you have switched over. The invalid binding name is: ") + aURL->GetSpecOrDefault());
NS_ERROR(str.get());
#endif
return NS_OK;
@ -713,14 +709,10 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
if (!protoBinding) {
#ifdef DEBUG
nsAutoCString uriSpec;
aURI->GetSpec(uriSpec);
nsAutoCString doc;
boundDocument->GetDocumentURI()->GetSpec(doc);
nsAutoCString message("Unable to locate an XBL binding for URI ");
message += uriSpec;
message += aURI->GetSpecOrDefault();
message += " in document ";
message += doc;
message += boundDocument->GetDocumentURI()->GetSpecOrDefault();
NS_WARNING(message.get());
#endif
return NS_ERROR_FAILURE;
@ -730,10 +722,8 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
// doesn't subsume it (modulo a few exceptions).
if (!MayBindToContent(protoBinding, aBoundElement, aURI)) {
#ifdef DEBUG
nsAutoCString uriSpec;
aURI->GetSpec(uriSpec);
nsAutoCString message("Permission denied to apply binding ");
message += uriSpec;
message += aURI->GetSpecOrDefault();
message += " to unprivileged content. Set bindToUntrustedContent=true on "
"the binding to override this restriction.";
NS_WARNING(message.get());
@ -773,12 +763,10 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
rv = aDontExtendURIs[index]->Equals(baseBindingURI, &equal);
NS_ENSURE_SUCCESS(rv, rv);
if (equal) {
nsAutoCString spec, basespec;
protoBinding->BindingURI()->GetSpec(spec);
NS_ConvertUTF8toUTF16 protoSpec(spec);
baseBindingURI->GetSpec(basespec);
NS_ConvertUTF8toUTF16 baseSpecUTF16(basespec);
const char16_t* params[] = { protoSpec.get(), baseSpecUTF16.get() };
NS_ConvertUTF8toUTF16
protoSpec(protoBinding->BindingURI()->GetSpecOrDefault());
NS_ConvertUTF8toUTF16 baseSpec(baseBindingURI->GetSpecOrDefault());
const char16_t* params[] = { protoSpec.get(), baseSpec.get() };
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("XBL"), nullptr,
nsContentUtils::eXBL_PROPERTIES,

Просмотреть файл

@ -2534,18 +2534,13 @@ XULDocument::LoadOverlayInternal(nsIURI* aURI, bool aIsDynamic,
*aFailureFromContent = false;
if (MOZ_LOG_TEST(gXULLog, LogLevel::Debug)) {
nsAutoCString urlspec;
aURI->GetSpec(urlspec);
nsAutoCString parentDoc;
nsCOMPtr<nsIURI> uri;
nsresult rv = mChannel->GetOriginalURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv))
rv = uri->GetSpec(parentDoc);
if (!(parentDoc.get()))
parentDoc = "";
mChannel->GetOriginalURI(getter_AddRefs(uri));
MOZ_LOG(gXULLog, LogLevel::Debug,
("xul: %s loading overlay %s", parentDoc.get(), urlspec.get()));
("xul: %s loading overlay %s",
uri ? uri->GetSpecOrDefault().get() : "",
aURI->GetSpecOrDefault().get()));
}
if (aIsDynamic)
@ -3192,11 +3187,8 @@ void
XULDocument::ReportMissingOverlay(nsIURI* aURI)
{
NS_PRECONDITION(aURI, "Must have a URI");
nsAutoCString spec;
aURI->GetSpec(spec);
NS_ConvertUTF8toUTF16 utfSpec(spec);
NS_ConvertUTF8toUTF16 utfSpec(aURI->GetSpecOrDefault());
const char16_t* params[] = { utfSpec.get() };
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("XUL Document"), this,
@ -3305,9 +3297,7 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (uri) {
nsAutoCString uriSpec;
uri->GetSpec(uriSpec);
printf("Failed to load %s\n", uriSpec.get());
printf("Failed to load %s\n", uri->GetSpecOrDefault().get());
}
}
}
@ -3987,17 +3977,14 @@ XULDocument::OverlayForwardReference::~OverlayForwardReference()
idC.AssignWithConversion(id);
nsIURI *protoURI = mDocument->mCurrentPrototype->GetURI();
nsAutoCString urlspec;
protoURI->GetSpec(urlspec);
nsCOMPtr<nsIURI> docURI;
nsAutoCString parentDoc;
nsresult rv = mDocument->mChannel->GetOriginalURI(getter_AddRefs(docURI));
if (NS_SUCCEEDED(rv))
docURI->GetSpec(parentDoc);
mDocument->mChannel->GetOriginalURI(getter_AddRefs(docURI));
MOZ_LOG(gXULLog, LogLevel::Warning,
("xul: %s overlay failed to resolve '%s' in %s",
urlspec.get(), idC.get(), parentDoc.get()));
protoURI->GetSpecOrDefault().get(), idC.get(),
docURI ? docURI->GetSpecOrDefault().get() : ""));
}
}

Просмотреть файл

@ -483,11 +483,10 @@ gfxUserFontEntry::LoadNextSrc()
mPlatformFontEntry = fe;
SetLoadState(STATUS_LOADED);
if (LOG_ENABLED()) {
nsAutoCString fontURI;
currSrc.mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] "
"loaded uri from cache: (%s) for (%s)\n",
mFontSet, mSrcIndex, fontURI.get(),
mFontSet, mSrcIndex,
currSrc.mURI->GetSpecOrDefault().get(),
NS_ConvertUTF16toUTF8(mFamilyName).get()));
}
return;
@ -532,10 +531,9 @@ gfxUserFontEntry::LoadNextSrc()
if (loadOK) {
if (LOG_ENABLED()) {
nsAutoCString fontURI;
currSrc.mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] loading uri: (%s) for (%s)\n",
mFontSet, mSrcIndex, fontURI.get(),
mFontSet, mSrcIndex,
currSrc.mURI->GetSpecOrDefault().get(),
NS_ConvertUTF16toUTF8(mFamilyName).get()));
}
return;
@ -703,11 +701,10 @@ gfxUserFontEntry::LoadPlatformFont(const uint8_t* aFontData, uint32_t& aLength)
StoreUserFontData(fe, mFontSet->GetPrivateBrowsing(), originalFullName,
&metadata, metaOrigLen, compression);
if (LOG_ENABLED()) {
nsAutoCString fontURI;
mSrcList[mSrcIndex].mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] loaded uri: (%s) for (%s) "
"(%p) gen: %8.8x compress: %d%%\n",
mFontSet, mSrcIndex, fontURI.get(),
mFontSet, mSrcIndex,
mSrcList[mSrcIndex].mURI->GetSpecOrDefault().get(),
NS_ConvertUTF16toUTF8(mFamilyName).get(),
this, uint32_t(mFontSet->mGeneration), fontCompressionRatio));
}
@ -716,11 +713,10 @@ gfxUserFontEntry::LoadPlatformFont(const uint8_t* aFontData, uint32_t& aLength)
gfxUserFontSet::UserFontCache::CacheFont(fe);
} else {
if (LOG_ENABLED()) {
nsAutoCString fontURI;
mSrcList[mSrcIndex].mURI->GetSpec(fontURI);
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s)"
" error making platform font\n",
mFontSet, mSrcIndex, fontURI.get(),
mFontSet, mSrcIndex,
mSrcList[mSrcIndex].mURI->GetSpecOrDefault().get(),
NS_ConvertUTF16toUTF8(mFamilyName).get()));
}
}
@ -1313,8 +1309,7 @@ gfxUserFontSet::UserFontCache::Entry::ReportMemory(
NS_ConvertUTF16toUTF8 familyName(mFontEntry->mFamilyName);
path.AppendPrintf("family=%s", familyName.get());
if (mURI) {
nsCString spec;
mURI->GetSpec(spec);
nsCString spec = mURI->GetSpecOrDefault();
spec.ReplaceChar('/', '\\');
// Some fonts are loaded using horrendously-long data: URIs;
// truncate those before reporting them.
@ -1330,8 +1325,7 @@ gfxUserFontSet::UserFontCache::Entry::ReportMemory(
nsCOMPtr<nsIURI> uri;
mPrincipal->GetURI(getter_AddRefs(uri));
if (uri) {
nsCString spec;
uri->GetSpec(spec);
nsCString spec = uri->GetSpecOrDefault();
if (!spec.IsEmpty()) {
// Include a clue as to who loaded this resource. (Note
// that because of font entry sharing, other pages may now

Просмотреть файл

@ -1757,12 +1757,9 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
("imgLoader::ValidateEntry validating cache entry. "
"validateRequest = %d", validateRequest));
} else if (!key && MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString spec;
aURI->GetSpec(spec);
MOZ_LOG(gImgLog, LogLevel::Debug,
("imgLoader::ValidateEntry BYPASSING cache validation for %s "
"because of NULL LoadID", spec.get()));
"because of NULL LoadID", aURI->GetSpecOrDefault().get()));
}
// We can't use a cached request if it comes from a different
@ -2007,9 +2004,8 @@ imgLoader::LoadImage(nsIURI* aURI,
return NS_ERROR_NULL_POINTER;
}
nsAutoCString spec;
aURI->GetSpec(spec);
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::LoadImage", "aURI", spec.get());
LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::LoadImage", "aURI",
aURI->GetSpecOrDefault().get());
*_retval = nullptr;
@ -2101,10 +2097,6 @@ imgLoader::LoadImage(nsIURI* aURI,
entry->Touch();
#ifdef DEBUG_joe
printf("CACHEGET: %d %s %d\n", time(nullptr), spec.get(),
entry->SizeOfData());
#endif
} else {
// We can't use this entry. We'll try to load it off the network, and if
// successful, overwrite the old entry in the cache with a new one.
@ -2763,11 +2755,9 @@ imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
}
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
nsAutoCString spec;
uri->GetSpec(spec);
LOG_MSG_WITH_PARAM(gImgLog,
"imgCacheValidator::OnStartRequest creating new request",
"uri", spec.get());
"uri", uri->GetSpecOrDefault().get());
}
int32_t corsmode = mRequest->GetCORSMode();

Просмотреть файл

@ -1225,12 +1225,10 @@ imgRequest::OnRedirectVerifyCallback(nsresult result)
mNewRedirectChannel = nullptr;
if (LOG_TEST(LogLevel::Debug)) {
nsAutoCString spec;
if (mCurrentURI) {
mCurrentURI->GetSpec(spec);
}
LOG_MSG_WITH_PARAM(gImgLog,
"imgRequest::OnChannelRedirect", "old", spec.get());
"imgRequest::OnChannelRedirect", "old",
mCurrentURI ? mCurrentURI->GetSpecOrDefault().get()
: "");
}
// If the previous URI is a non-HTTPS URI, record that fact for later use by
@ -1263,12 +1261,9 @@ imgRequest::OnRedirectVerifyCallback(nsresult result)
mChannel->GetURI(getter_AddRefs(mCurrentURI));
if (LOG_TEST(LogLevel::Debug)) {
nsAutoCString spec;
if (mCurrentURI) {
mCurrentURI->GetSpec(spec);
}
LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnChannelRedirect",
"new", spec.get());
LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnChannelRedirect", "new",
mCurrentURI ? mCurrentURI->GetSpecOrDefault().get()
: "");
}
// Make sure we have a protocol that returns data rather than opens an

Просмотреть файл

@ -127,9 +127,8 @@ nsHyphenationManager::GetHyphenator(nsIAtom *aLocale)
return hyph.forget();
}
#ifdef DEBUG
nsCString msg;
uri->GetSpec(msg);
msg.Insert("failed to load patterns from ", 0);
nsCString msg("failed to load patterns from ");
msg += uri->GetSpecOrDefault();
NS_WARNING(msg.get());
#endif
mPatternFiles.Remove(aLocale);

Просмотреть файл

@ -106,13 +106,11 @@ RestyleTracker::ProcessOneRestyle(Element* aElement,
void
RestyleTracker::DoProcessRestyles()
{
nsAutoCString docURL;
nsAutoCString docURL("N/A");
if (profiler_is_active()) {
nsIURI *uri = Document()->GetDocumentURI();
if (uri) {
uri->GetSpec(docURL);
} else {
docURL = "N/A";
docURL = uri->GetSpecOrDefault();
}
}
PROFILER_LABEL_PRINTF("RestyleTracker", "ProcessRestyles",

Просмотреть файл

@ -1669,9 +1669,8 @@ PresShell::Initialize(nscoord aWidth, nscoord aHeight)
if (mDocument) {
nsIURI *uri = mDocument->GetDocumentURI();
if (uri) {
nsAutoCString url;
uri->GetSpec(url);
printf("*** PresShell::Initialize (this=%p, url='%s')\n", (void*)this, url.get());
printf("*** PresShell::Initialize (this=%p, url='%s')\n",
(void*)this, uri->GetSpecOrDefault().get());
}
}
}
@ -2512,13 +2511,9 @@ PresShell::BeginLoad(nsIDocument *aDocument)
if (shouldLog) {
nsIURI* uri = mDocument->GetDocumentURI();
nsAutoCString spec;
if (uri) {
uri->GetSpec(spec);
}
MOZ_LOG(gLog, LogLevel::Debug,
("(presshell) %p load begin [%s]\n",
this, spec.get()));
this, uri ? uri->GetSpecOrDefault().get() : ""));
}
}
@ -2547,7 +2542,7 @@ PresShell::LoadComplete()
nsIURI* uri = mDocument->GetDocumentURI();
nsAutoCString spec;
if (uri) {
uri->GetSpec(spec);
spec = uri->GetSpecOrDefault();
}
if (shouldLog) {
MOZ_LOG(gLog, LogLevel::Debug,
@ -9482,13 +9477,10 @@ PresShell::DoReflow(nsIFrame* target, bool aInterruptible)
parent = nsLayoutUtils::GetCrossDocParentFrame(parent);
}
nsAutoCString docURL("N/A");
nsIURI *uri = mDocument->GetDocumentURI();
if (uri)
uri->GetSpec(docURL);
PROFILER_LABEL_PRINTF("PresShell", "DoReflow",
js::ProfileEntry::Category::GRAPHICS, "(%s)", docURL.get());
js::ProfileEntry::Category::GRAPHICS, "(%s)",
uri ? uri->GetSpecOrDefault().get() : "N/A");
nsDocShell* docShell = static_cast<nsDocShell*>(GetPresContext()->GetDocShell());
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();

Просмотреть файл

@ -607,13 +607,12 @@ FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry,
new nsFontFaceLoader(aUserFontEntry, aFontFaceSrc->mURI, this, channel);
if (LOG_ENABLED()) {
nsAutoCString fontURI, referrerURI;
aFontFaceSrc->mURI->GetSpec(fontURI);
if (aFontFaceSrc->mReferrer)
aFontFaceSrc->mReferrer->GetSpec(referrerURI);
LOG(("userfonts (%p) download start - font uri: (%s) "
"referrer uri: (%s)\n",
fontLoader.get(), fontURI.get(), referrerURI.get()));
fontLoader.get(), aFontFaceSrc->mURI->GetSpecOrDefault().get(),
aFontFaceSrc->mReferrer
? aFontFaceSrc->mReferrer->GetSpecOrDefault().get()
: ""));
}
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));

Просмотреть файл

@ -277,9 +277,7 @@ static mozilla::LazyLogModule gSriPRLog("SRI");
PR_BEGIN_MACRO \
NS_ASSERTION(uri, "Logging null uri"); \
if (LOG_ENABLED()) { \
nsAutoCString _logURISpec; \
uri->GetSpec(_logURISpec); \
LOG((format, _logURISpec.get())); \
LOG((format, uri->GetSpecOrDefault().get())); \
} \
PR_END_MACRO
@ -913,10 +911,8 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
errorFlag = nsIScriptError::errorFlag;
}
nsAutoCString spec;
channelURI->GetSpec(spec);
const nsAFlatString& specUTF16 = NS_ConvertUTF8toUTF16(spec);
const nsAFlatString& specUTF16 =
NS_ConvertUTF8toUTF16(channelURI->GetSpecOrDefault());
const nsAFlatString& ctypeUTF16 = NS_ConvertASCIItoUTF16(contentType);
const char16_t *strings[] = { specUTF16.get(), ctypeUTF16.get() };

Просмотреть файл

@ -218,14 +218,12 @@ nsFontFaceLoader::OnStreamComplete(nsIStreamLoader* aLoader,
}
if (LOG_ENABLED()) {
nsAutoCString fontURI;
mFontURI->GetSpec(fontURI);
if (NS_SUCCEEDED(aStatus)) {
LOG(("userfonts (%p) download completed - font uri: (%s) time: %d ms\n",
this, fontURI.get(), downloadTimeMS));
this, mFontURI->GetSpecOrDefault().get(), downloadTimeMS));
} else {
LOG(("userfonts (%p) download failed - font uri: (%s) error: %8.8x\n",
this, fontURI.get(), aStatus));
this, mFontURI->GetSpecOrDefault().get(), aStatus));
}
}

Просмотреть файл

@ -728,12 +728,9 @@ ErrorLoadingBuiltinSheet(nsIURI* aURI, const char* aMsg)
AnnotateCrashReport(aURI);
#endif
nsAutoCString spec;
if (aURI) {
aURI->GetSpec(spec);
}
NS_RUNTIMEABORT(nsPrintfCString("%s loading built-in stylesheet '%s'",
aMsg, spec.get()).get());
NS_RUNTIMEABORT(
nsPrintfCString("%s loading built-in stylesheet '%s'",
aMsg, aURI ? aURI->GetSpecOrDefault().get() : "").get());
}
void

Просмотреть файл

@ -107,11 +107,9 @@ nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel *aChannel,
if (!isThirdPartyWindow || !isThirdPartyChannel) {
*result = false;
if (LOG_ENABLED()) {
nsAutoCString spec;
chanURI->GetSpec(spec);
LOG(("nsChannelClassifier[%p]: Skipping tracking protection checks "
"for first party or top-level load channel[%p] with uri %s",
this, aChannel, spec.get()));
this, aChannel, chanURI->GetSpecOrDefault().get()));
}
return NS_OK;
}
@ -186,12 +184,10 @@ nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel *aChannel,
// (page elements blocked) the state will be then updated.
if (*result) {
if (LOG_ENABLED()) {
nsAutoCString topspec, spec;
topWinURI->GetSpec(topspec);
chanURI->GetSpec(spec);
LOG(("nsChannelClassifier[%p]: Enabling tracking protection checks on "
"channel[%p] with uri %s for toplevel window %s", this, aChannel,
spec.get(), topspec.get()));
chanURI->GetSpecOrDefault().get(),
topWinURI->GetSpecOrDefault().get()));
}
return NS_OK;
}
@ -348,13 +344,11 @@ nsChannelClassifier::StartInternal()
(void)ShouldEnableTrackingProtection(mChannel, &trackingProtectionEnabled);
if (LOG_ENABLED()) {
nsAutoCString uriSpec, principalSpec;
uri->GetSpec(uriSpec);
nsCOMPtr<nsIURI> principalURI;
principal->GetURI(getter_AddRefs(principalURI));
principalURI->GetSpec(principalSpec);
LOG(("nsChannelClassifier[%p]: Classifying principal %s on channel with "
"uri %s", this, principalSpec.get(), uriSpec.get()));
"uri %s", this, principalURI->GetSpecOrDefault().get(),
uri->GetSpecOrDefault().get()));
}
rv = uriClassifier->Classify(principal, trackingProtectionEnabled, this,
&expectCallback);
@ -572,9 +566,7 @@ nsChannelClassifier::SetBlockedTrackingContent(nsIChannel *channel)
// Log a warning to the web console.
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
nsCString utf8spec;
uri->GetSpec(utf8spec);
NS_ConvertUTF8toUTF16 spec(utf8spec);
NS_ConvertUTF8toUTF16 spec(uri->GetSpecOrDefault());
const char16_t* params[] = { spec.get() };
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("Tracking Protection"),
@ -676,11 +668,9 @@ nsChannelClassifier::OnClassifyComplete(nsresult aErrorCode)
if (LOG_ENABLED()) {
nsCOMPtr<nsIURI> uri;
mChannel->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
uri->GetSpec(spec);
LOG(("nsChannelClassifier[%p]: cancelling channel %p for %s "
"with error code %s", this, mChannel.get(),
spec.get(), errorName.get()));
uri->GetSpecOrDefault().get(), errorName.get()));
}
// Channel will be cancelled (page element blocked) due to tracking.

Просмотреть файл

@ -40,6 +40,8 @@
*/
%{C++
#include "nsStringGlue.h"
#undef GetPort // XXX Windows!
#undef SetPort // XXX Windows!
%}
@ -88,6 +90,22 @@ interface nsIURI : nsISupports
*/
attribute AUTF8String spec;
%{ C++
// An infallible wrapper for GetSpec() that returns a failure indication
// string if GetSpec() fails. It is most useful for creating
// logging/warning/error messages produced for human consumption, and when
// matching a URI spec against a fixed spec such as about:blank.
nsCString GetSpecOrDefault()
{
nsCString spec;
nsresult rv = GetSpec(spec);
if (NS_FAILED(rv)) {
spec.Assign("[nsIURI::GetSpec failed]");
}
return spec;
}
%}
/**
* The prePath (eg. scheme://user:password@host:port) returns the string
* before the path. This is useful for authentication or managing sessions.

Просмотреть файл

@ -2282,12 +2282,11 @@ NS_ShouldSecureUpgrade(nsIURI* aURI,
if (aLoadInfo->GetUpgradeInsecureRequests() && !crossOriginNavigation) {
// let's log a message to the console that we are upgrading a request
nsAutoCString spec, scheme;
aURI->GetSpec(spec);
nsAutoCString scheme;
aURI->GetScheme(scheme);
// append the additional 's' for security to the scheme :-)
scheme.AppendASCII("s");
NS_ConvertUTF8toUTF16 reportSpec(spec);
NS_ConvertUTF8toUTF16 reportSpec(aURI->GetSpecOrDefault());
NS_ConvertUTF8toUTF16 reportScheme(scheme);
const char16_t* params[] = { reportSpec.get(), reportScheme.get() };

Просмотреть файл

@ -72,11 +72,8 @@ nsSecCheckWrapChannel::nsSecCheckWrapChannel(nsIChannel* aChannel,
{
nsCOMPtr<nsIURI> uri;
mChannel->GetURI(getter_AddRefs(uri));
nsAutoCString spec;
if (uri) {
uri->GetSpec(spec);
}
CHANNELWRAPPERLOG(("nsSecCheckWrapChannel::nsSecCheckWrapChannel [%p] (%s)",this, spec.get()));
CHANNELWRAPPERLOG(("nsSecCheckWrapChannel::nsSecCheckWrapChannel [%p] (%s)",
this, uri ? uri->GetSpecOrDefault().get() : ""));
}
}

Просмотреть файл

@ -133,10 +133,8 @@ FTPChannelParent::DoAsyncOpen(const URIParams& aURI,
return false;
#ifdef DEBUG
nsCString uriSpec;
uri->GetSpec(uriSpec);
LOG(("FTPChannelParent DoAsyncOpen [this=%p uri=%s]\n",
this, uriSpec.get()));
this, uri->GetSpecOrDefault().get()));
#endif
nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv));

Просмотреть файл

@ -280,10 +280,8 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
nsCOMPtr<nsIURI> apiRedirectToUri = DeserializeURI(aAPIRedirectToURI);
nsCOMPtr<nsIURI> topWindowUri = DeserializeURI(aTopWindowURI);
nsCString uriSpec;
uri->GetSpec(uriSpec);
LOG(("HttpChannelParent RecvAsyncOpen [this=%p uri=%s]\n",
this, uriSpec.get()));
this, uri->GetSpecOrDefault().get()));
nsresult rv;

Просмотреть файл

@ -68,10 +68,8 @@ WyciwygChannelParent::RecvInit(const URIParams& aURI,
if (!uri)
return false;
nsCString uriSpec;
uri->GetSpec(uriSpec);
LOG(("WyciwygChannelParent RecvInit [this=%p uri=%s]\n",
this, uriSpec.get()));
this, uri->GetSpecOrDefault().get()));
nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv));
if (NS_FAILED(rv))

Просмотреть файл

@ -432,9 +432,7 @@ InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
NS_GET_IID(nsIURI),
getter_AddRefs(foo));
if (foo) {
nsAutoCString spec;
foo->GetSpec(spec);
LOG(("\ttest.foo: %s\n", spec.get()));
LOG(("\ttest.foo: %s\n", foo->GetSpecOrDefault().get()));
}
}

Просмотреть файл

@ -228,10 +228,7 @@ nsresult makeAbsTest(const char* i_BaseURI, const char* relativePortion,
status = baseURL->Resolve(nsDependentCString(relativePortion), newURL);
if (NS_FAILED(status)) return status;
nsAutoCString temp;
baseURL->GetSpec(temp);
printf("Analyzing %s\n", temp.get());
printf("Analyzing %s\n", baseURL->GetSpecOrDefault().get());
printf("With %s\n", relativePortion);
printf("Got %s\n", newURL.get());

Просмотреть файл

@ -827,10 +827,8 @@ RDFXMLDataSourceImpl::Flush(void)
return NS_ERROR_NOT_INITIALIZED;
if (MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
nsAutoCString spec;
mURL->GetSpec(spec);
MOZ_LOG(gLog, LogLevel::Debug,
("rdfxml[%p] flush(%s)", this, spec.get()));
("rdfxml[%p] flush(%s)", this, mURL->GetSpecOrDefault().get()));
}
nsresult rv;
@ -908,11 +906,11 @@ RDFXMLDataSourceImpl::Refresh(bool aBlocking)
{
nsAutoCString spec;
if (mURL) {
mURL->GetSpec(spec);
spec = mURL->GetSpecOrDefault();
}
MOZ_LOG(gLog, LogLevel::Debug,
("rdfxml[%p] refresh(%s) %sblocking", this, spec.get(), (aBlocking ? "" : "non")));
// If an asynchronous load is already pending, then just let it do
// the honors.
if (IsLoading()) {
@ -969,14 +967,11 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::BeginLoad(void)
{
if (MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
nsAutoCString spec;
if (mURL) {
mURL->GetSpec(spec);
}
MOZ_LOG(gLog, LogLevel::Debug,
("rdfxml[%p] begin-load(%s)", this, spec.get()));
("rdfxml[%p] begin-load(%s)", this,
mURL ? mURL->GetSpecOrDefault().get() : ""));
}
mLoadState = eLoadState_Loading;
for (int32_t i = mObservers.Count() - 1; i >= 0; --i) {
// Make sure to hold a strong reference to the observer so
@ -995,12 +990,9 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::Interrupt(void)
{
if (MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
nsAutoCString spec;
if (mURL) {
mURL->GetSpec(spec);
}
MOZ_LOG(gLog, LogLevel::Debug,
("rdfxml[%p] interrupt(%s)", this, spec.get()));
("rdfxml[%p] interrupt(%s)", this,
mURL ? mURL->GetSpecOrDefault().get() : ""));
}
for (int32_t i = mObservers.Count() - 1; i >= 0; --i) {
@ -1020,14 +1012,11 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::Resume(void)
{
if (MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
nsAutoCString spec;
if (mURL) {
mURL->GetSpec(spec);
}
MOZ_LOG(gLog, LogLevel::Debug,
("rdfxml[%p] resume(%s)", this, spec.get()));
("rdfxml[%p] resume(%s)", this,
mURL ? mURL->GetSpecOrDefault().get() : ""));
}
for (int32_t i = mObservers.Count() - 1; i >= 0; --i) {
// Make sure to hold a strong reference to the observer so
// that it doesn't go away in this call if it removes itself
@ -1045,14 +1034,11 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::EndLoad(void)
{
if (MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
nsAutoCString spec;
if (mURL) {
mURL->GetSpec(spec);
}
MOZ_LOG(gLog, LogLevel::Debug,
("rdfxml[%p] end-load(%s)", this, spec.get()));
("rdfxml[%p] end-load(%s)", this,
mURL ? mURL->GetSpecOrDefault().get() : ""));
}
mLoadState = eLoadState_Loaded;
// Clear out any unmarked assertions from the datasource.

Просмотреть файл

@ -1154,11 +1154,9 @@ nsSecureBrowserUIImpl::OnSecurityChange(nsIWebProgress* aWebProgress,
channel->GetURI(getter_AddRefs(aURI));
if (aURI) {
nsAutoCString temp;
aURI->GetSpec(temp);
MOZ_LOG(gSecureDocLog, LogLevel::Debug,
("SecureUI:%p: OnSecurityChange: (%x) %s\n", this,
state, temp.get()));
state, aURI->GetSpecOrDefault().get()));
}
#endif

Просмотреть файл

@ -111,11 +111,8 @@ nsUrlClassifierStreamUpdater::FetchUpdate(nsIURI *aUpdateUrl,
{
#ifdef DEBUG
{
nsCString spec;
aUpdateUrl->GetSpec(spec);
LOG(("Fetching update %s from %s", aRequestPayload.Data(), spec.get()));
}
LOG(("Fetching update %s from %s",
aRequestPayload.Data(), aUpdateUrl->GetSpecOrDefault().get()));
#endif
nsresult rv;

Просмотреть файл

@ -98,11 +98,9 @@ LogToConsole(const char * message, nsOfflineCacheUpdateItem * item = nullptr)
{
nsAutoString messageUTF16 = NS_ConvertUTF8toUTF16(message);
if (item && item->mURI) {
nsAutoCString uriSpec;
item->mURI->GetSpec(uriSpec);
messageUTF16.AppendLiteral(", URL=");
messageUTF16.Append(NS_ConvertUTF8toUTF16(uriSpec));
messageUTF16.Append(
NS_ConvertUTF8toUTF16(item->mURI->GetSpecOrDefault()));
}
consoleService->LogStringMessage(messageUTF16.get());
}
@ -346,9 +344,8 @@ nsresult
nsOfflineCacheUpdateItem::OpenChannel(nsOfflineCacheUpdate *aUpdate)
{
if (LOG_ENABLED()) {
nsAutoCString spec;
mURI->GetSpec(spec);
LOG(("%p: Opening channel for %s", this, spec.get()));
LOG(("%p: Opening channel for %s", this,
mURI->GetSpecOrDefault().get()));
}
if (mUpdate) {
@ -469,10 +466,8 @@ nsOfflineCacheUpdateItem::OnStopRequest(nsIRequest *aRequest,
nsresult aStatus)
{
if (LOG_ENABLED()) {
nsAutoCString spec;
mURI->GetSpec(spec);
LOG(("%p: Done fetching offline item %s [status=%x]\n",
this, spec.get(), aStatus));
this, mURI->GetSpecOrDefault().get(), aStatus));
}
if (mBytesRead == 0 && aStatus == NS_OK) {
@ -1892,9 +1887,8 @@ nsOfflineCacheUpdate::ProcessNextURI()
}
if (LOG_ENABLED()) {
nsAutoCString spec;
runItem->mURI->GetSpec(spec);
LOG(("%p: Opening channel for %s", this, spec.get()));
LOG(("%p: Opening channel for %s", this,
runItem->mURI->GetSpecOrDefault().get()));
}
++mItemsInProgress;

Просмотреть файл

@ -431,10 +431,8 @@ nsPrefetchService::ProcessNextURI(nsPrefetchNode *aFinished)
mQueue.pop_front();
if (LOG_ENABLED()) {
nsAutoCString spec;
node->mURI->GetSpec(spec);
LOG(("ProcessNextURI [%s]\n", spec.get()));
}
LOG(("ProcessNextURI [%s]\n",
node->mURI->GetSpecOrDefault().get())); }
//
// if opening the channel fails (e.g. security check returns an error),
@ -605,9 +603,7 @@ nsPrefetchService::Prefetch(nsIURI *aURI,
NS_ENSURE_ARG_POINTER(aReferrerURI);
if (LOG_ENABLED()) {
nsAutoCString spec;
aURI->GetSpec(spec);
LOG(("PrefetchURI [%s]\n", spec.get()));
LOG(("PrefetchURI [%s]\n", aURI->GetSpecOrDefault().get()));
}
if (mDisabled) {
@ -727,9 +723,7 @@ nsPrefetchService::CancelPrefetchURI(nsIURI* aURI,
NS_ENSURE_ARG_POINTER(aURI);
if (LOG_ENABLED()) {
nsAutoCString spec;
aURI->GetSpec(spec);
LOG(("CancelPrefetchURI [%s]\n", spec.get()));
LOG(("CancelPrefetchURI [%s]\n", aURI->GetSpecOrDefault().get()));
}
//

Просмотреть файл

@ -237,12 +237,11 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel) {
channel->GetURI(getter_AddRefs(uri));
if (uri) {
nsAutoCString uriSpec;
uri->GetSpec(uriSpec);
printf("Failed to load %s\n", uriSpec.get());
}
channel->GetURI(getter_AddRefs(uri));
if (uri) {
printf("Failed to load %s\n",
uri->GetSpecOrDefault().get());
}
}
}
}