NS_IMETHODIMP nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { NS_ENSURE_ARG_POINTER(aParams); NS_ENSURE_ARG_POINTER(refCon); // The base editor owns most state info nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); if (!editor) return NS_ERROR_INVALID_ARG; // Always get the enabled state PRBool outCmdEnabled = PR_FALSE; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled); NS_ENSURE_SUCCESS(rv, rv); // get pres context nsCOMPtr<nsPresContext> presContext; rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); if (NS_FAILED(rv)) return rv; if (!presContext) return NS_ERROR_FAILURE; PRInt32 animationMode; rv = aParams->GetLongValue("imageAnimation", &animationMode); if (NS_SUCCEEDED(rv)) { // for possible values of animation mode, see // http://lxr.mozilla.org/seamonkey/source/modules/libpr0n/public/imgIContainer.idl rv = aParams->SetLongValue("imageAnimation", presContext->ImageAnimationMode()); if (NS_FAILED(rv)) return rv; } PRBool allowPlugins; rv = aParams->GetBooleanValue("plugins", &allowPlugins); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsISupports> container = presContext->GetContainer(); if (!container) return NS_ERROR_FAILURE; nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container, &rv)); if (NS_FAILED(rv)) return rv; if (!docShell) return NS_ERROR_FAILURE; rv = docShell->GetAllowPlugins(&allowPlugins); if (NS_FAILED(rv)) return rv; rv = aParams->SetBooleanValue("plugins", allowPlugins); if (NS_FAILED(rv)) return rv; } return NS_OK; }
nsresult nsLocation::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase, PRBool aReplace) { nsresult result; nsCOMPtr<nsIURI> newUri; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); nsCAutoString docCharset; if (NS_SUCCEEDED(GetDocumentCharacterSetForURI(aHref, docCharset))) result = NS_NewURI(getter_AddRefs(newUri), aHref, docCharset.get(), aBase); else result = NS_NewURI(getter_AddRefs(newUri), aHref, nsnull, aBase); if (newUri) { /* Check with the scriptContext if it is currently processing a script tag. * If so, this must be a <script> tag with a location.href in it. * we want to do a replace load, in such a situation. * In other cases, for example if a event handler or a JS timer * had a location.href in it, we want to do a normal load, * so that the new url will be appended to Session History. * This solution is tricky. Hopefully it isn't going to bite * anywhere else. This is part of solution for bug # 39938, 72197 * */ PRBool inScriptTag=PR_FALSE; // Get JSContext from stack. nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result)); if (stack) { JSContext *cx; result = GetContextFromStack(stack, &cx); if (cx) { nsIScriptContext *scriptContext = nsJSUtils::GetDynamicScriptContext(cx); if (scriptContext) { if (scriptContext->GetProcessingScriptTag()) { // Now check to make sure that the script is running in our window, // since we only want to replace if the location is set by a // <script> tag in the same window. See bug 178729. nsCOMPtr<nsIScriptGlobalObject> ourGlobal(do_GetInterface(docShell)); inScriptTag = (ourGlobal == scriptContext->GetGlobalObject()); } } } //cx } // stack return SetURI(newUri, aReplace || inScriptTag); } return result; }
NS_IMETHODIMP nsLocation::Reload(bool aForceget) { if (!CallerSubsumes()) return NS_ERROR_DOM_SECURITY_ERR; nsresult rv; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell)); nsCOMPtr<nsPIDOMWindow> window(do_GetInterface(docShell)); if (window && window->IsHandlingResizeEvent()) { // location.reload() was called on a window that is handling a // resize event. Sites do this since Netscape 4.x needed it, but // we don't, and it's a horrible experience for nothing. In stead // of reloading the page, just clear style data and reflow the // page since some sites may use this trick to work around gecko // reflow bugs, and this should have the same effect. nsCOMPtr<nsIDocument> doc(do_QueryInterface(window->GetExtantDocument())); nsIPresShell *shell; nsPresContext *pcx; if (doc && (shell = doc->GetShell()) && (pcx = shell->GetPresContext())) { pcx->RebuildAllStyleData(NS_STYLE_HINT_REFLOW); } return NS_OK; } if (webNav) { uint32_t reloadFlags = nsIWebNavigation::LOAD_FLAGS_NONE; if (aForceget) { reloadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; } rv = webNav->Reload(reloadFlags); if (rv == NS_BINDING_ABORTED) { // This happens when we attempt to reload a POST result and the user says // no at the "do you want to reload?" prompt. Don't propagate this one // back to callers. rv = NS_OK; } } else { rv = NS_ERROR_FAILURE; } return rv; }
nsresult MediaDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, nsISupports* aContainer, nsIStreamListener** aDocListener, bool aReset, nsIContentSink* aSink) { nsresult rv = nsDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink); if (NS_FAILED(rv)) { return rv; } // We try to set the charset of the current document to that of the // 'genuine' (as opposed to an intervening 'chrome') parent document // that may be in a different window/tab. Even if we fail here, // we just return NS_OK because another attempt is made in // |UpdateTitleAndCharset| and the worst thing possible is a mangled // filename in the titlebar and the file picker. // Note that we // exclude UTF-8 as 'invalid' because UTF-8 is likely to be the charset // of a chrome document that has nothing to do with the actual content // whose charset we want to know. Even if "the actual content" is indeed // in UTF-8, we don't lose anything because the default empty value is // considered synonymous with UTF-8. nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); // not being able to set the charset is not critical. NS_ENSURE_TRUE(docShell, NS_OK); nsAutoCString charset; int32_t source; nsCOMPtr<nsIPrincipal> principal; // opening in a new tab docShell->GetParentCharset(charset, &source, getter_AddRefs(principal)); if (!charset.IsEmpty() && !charset.Equals("UTF-8") && NodePrincipal()->Equals(principal)) { SetDocumentCharacterSetSource(source); SetDocumentCharacterSet(charset); } return NS_OK; }
float ImageDocument::GetZoomLevel() { float zoomLevel = mOriginalZoomLevel; nsCOMPtr<nsIDocShell> docShell(mDocumentContainer); if (docShell) { nsCOMPtr<nsIContentViewer> cv; docShell->GetContentViewer(getter_AddRefs(cv)); if (cv) { cv->GetFullZoom(&zoomLevel); } } return zoomLevel; }
NS_IMETHODIMP nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { NS_ENSURE_ARG_POINTER(aParams); NS_ENSURE_ARG_POINTER(refCon); // The base editor owns most state info nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); // Always get the enabled state bool outCmdEnabled = false; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled); NS_ENSURE_SUCCESS(rv, rv); // get pres context nsRefPtr<nsPresContext> presContext; rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); int32_t animationMode; rv = aParams->GetLongValue("imageAnimation", &animationMode); if (NS_SUCCEEDED(rv)) { // for possible values of animation mode, see // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl rv = aParams->SetLongValue("imageAnimation", presContext->ImageAnimationMode()); NS_ENSURE_SUCCESS(rv, rv); } bool allowPlugins = false; rv = aParams->GetBooleanValue("plugins", &allowPlugins); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIDocShell> docShell(presContext->GetDocShell()); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); allowPlugins = docShell->PluginsAllowedInCurrentDoc(); rv = aParams->SetBooleanValue("plugins", allowPlugins); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }
nsresult Location::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase, bool aReplace) { nsresult result; nsCOMPtr<nsIURI> newUri; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); nsAutoCString docCharset; if (NS_SUCCEEDED(GetDocumentCharacterSetForURI(aHref, docCharset))) result = NS_NewURI(getter_AddRefs(newUri), aHref, docCharset.get(), aBase); else result = NS_NewURI(getter_AddRefs(newUri), aHref, nullptr, aBase); if (newUri) { /* Check with the scriptContext if it is currently processing a script tag. * If so, this must be a <script> tag with a location.href in it. * we want to do a replace load, in such a situation. * In other cases, for example if a event handler or a JS timer * had a location.href in it, we want to do a normal load, * so that the new url will be appended to Session History. * This solution is tricky. Hopefully it isn't going to bite * anywhere else. This is part of solution for bug # 39938, 72197 * */ bool inScriptTag = false; nsIScriptContext* scriptContext = nullptr; nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(GetEntryGlobal()); if (win) { scriptContext = nsGlobalWindow::Cast(win)->GetContextInternal(); } if (scriptContext) { if (scriptContext->GetProcessingScriptTag()) { // Now check to make sure that the script is running in our window, // since we only want to replace if the location is set by a // <script> tag in the same window. See bug 178729. nsCOMPtr<nsIScriptGlobalObject> ourGlobal = docShell ? docShell->GetScriptGlobalObject() : nullptr; inScriptTag = (ourGlobal == scriptContext->GetGlobalObject()); } } return SetURI(newUri, aReplace || inScriptTag); } return result; }
NS_IMETHODIMP nsWebNavigationInfo::IsTypeSupported(const nsACString& aType, nsIWebNavigation* aWebNav, uint32_t* aIsTypeSupported) { NS_PRECONDITION(aIsTypeSupported, "null out param?"); // Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or // an nsSHistory, but not much we can do with that). So if we start using // it here, we need to be careful to get to the docshell correctly. // For now just report what the Gecko-Content-Viewers category has // to say for itself. *aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED; const nsCString& flatType = PromiseFlatCString(aType); nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported); NS_ENSURE_SUCCESS(rv, rv); if (*aIsTypeSupported) { return rv; } // If this request is for a docShell that isn't going to allow plugins, // there's no need to try and find a plugin to handle it. nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav)); bool allowed; if (docShell && NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) && !allowed) { return NS_OK; } // Try reloading plugins in case they've changed. nsCOMPtr<nsIPluginHost> pluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID); if (pluginHost) { // false will ensure that currently running plugins will not // be shut down rv = pluginHost->ReloadPlugins(); if (NS_SUCCEEDED(rv)) { // OK, we reloaded plugins and there were new ones // (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have // been returned). Try checking whether we can handle the // content now. return IsTypeSupportedInternal(flatType, aIsTypeSupported); } } return NS_OK; }
void ImageDocument::ResetZoomLevel() { nsCOMPtr<nsIDocShell> docShell(mDocumentContainer); if (docShell) { if (nsContentUtils::IsChildOfSameType(this)) { return; } nsCOMPtr<nsIContentViewer> cv; docShell->GetContentViewer(getter_AddRefs(cv)); if (cv) { cv->SetFullZoom(mOriginalZoomLevel); } } }
NS_IMETHODIMP nsMsgWindow::GetAuthPrompt(nsIAuthPrompt * *aAuthPrompt) { NS_ENSURE_ARG_POINTER(aAuthPrompt); if (!mRootDocShellWeak) return NS_ERROR_FAILURE; nsresult rv; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mRootDocShellWeak.get(), &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAuthPrompt> prompt = do_GetInterface(docShell, &rv); NS_ENSURE_SUCCESS(rv, rv); prompt.swap(*aAuthPrompt); return rv; }
NS_IMETHODIMP nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { NS_ENSURE_ARG_POINTER(aParams); nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); nsRefPtr<nsPresContext> presContext; nsresult rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); PRInt32 animationMode; rv = aParams->GetLongValue("imageAnimation", &animationMode); if (NS_SUCCEEDED(rv)) { // for possible values of animation mode, see: // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl presContext->SetImageAnimationMode(animationMode); } bool allowPlugins; rv = aParams->GetBooleanValue("plugins", &allowPlugins); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsISupports> container = presContext->GetContainer(); NS_ENSURE_TRUE(container, NS_ERROR_FAILURE); nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container, &rv)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); rv = docShell->SetAllowPlugins(allowPlugins); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }
NS_IMETHODIMP MailEwsMsgMessageService::OpenAttachment(const char *aContentType, const char *aFileName, const char *aUrl, const char *aMessageUri, nsISupports *aDisplayConsumer, nsIMsgWindow *aMsgWindow, nsIUrlListener *aUrlListener) { nsCOMPtr <nsIURI> URL; nsresult rv; nsAutoCString urlString(aUrl); urlString += "&type="; urlString += aContentType; urlString += "&filename="; urlString += aFileName; nsCOMPtr<nsIMailboxUrl> aMailboxUrl; URL = do_CreateInstance(MAIL_EWS_MSG_URL_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); URL->SetSpec(urlString); // try to run the url in the docshell... nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aDisplayConsumer, &rv)); // if we were given a docShell, run the url in the docshell..otherwise just run it normally. if (NS_SUCCEEDED(rv) && docShell) { nsCOMPtr<nsIDocShellLoadInfo> loadInfo; // DIRTY LITTLE HACK --> since we are opening an attachment we want the docshell to // treat this load as if it were a user click event. Then the dispatching stuff will be much // happier. docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); loadInfo->SetLoadType(nsIDocShellLoadInfo::loadLink); return docShell->LoadURI(URL, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, false); } return RunMailboxUrl(URL, aDisplayConsumer); }
nsresult Location::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL) { *sourceURL = nullptr; nsIDocument* doc = GetEntryDocument(); // If there's no entry document, we either have no Script Entry Point or one // that isn't a DOM Window. This doesn't generally happen with the DOM, but // can sometimes happen with extension code in certain IPC configurations. If // this happens, try falling back on the current document associated with the // docshell. If that fails, just return null and hope that the caller passed // an absolute URI. nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); if (!doc && docShell) { nsCOMPtr<nsPIDOMWindowOuter> docShellWin = do_QueryInterface(docShell->GetScriptGlobalObject()); if (docShellWin) { doc = docShellWin->GetDoc(); } } NS_ENSURE_TRUE(doc, NS_OK); *sourceURL = doc->GetBaseURI().take(); return NS_OK; }
nsresult nsLocation::SetURI(nsIURI* aURI, bool aReplace) { nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); if (docShell) { nsCOMPtr<nsIDocShellLoadInfo> loadInfo; nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell)); if(NS_FAILED(CheckURL(aURI, getter_AddRefs(loadInfo)))) return NS_ERROR_FAILURE; if (aReplace) { loadInfo->SetLoadType(nsIDocShellLoadInfo::loadStopContentAndReplace); } else { loadInfo->SetLoadType(nsIDocShellLoadInfo::loadStopContent); } return docShell->LoadURI(aURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, true); } return NS_OK; }
static bool IsImageLoadInEditorAppType(nsILoadInfo* aLoadInfo) { // Editor apps get special treatment here, editors can load images // from anywhere. This allows editor to insert images from file:// // into documents that are being edited. nsContentPolicyType type = aLoadInfo->InternalContentPolicyType(); if (type != nsIContentPolicy::TYPE_INTERNAL_IMAGE && type != nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD && type != nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON && type != nsIContentPolicy::TYPE_IMAGESET) { return false; } uint32_t appType = nsIDocShell::APP_TYPE_UNKNOWN; nsINode* node = aLoadInfo->LoadingNode(); if (!node) { return false; } nsIDocument* doc = node->OwnerDoc(); if (!doc) { return false; } nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = doc->GetDocShell(); if (!docShellTreeItem) { return false; } nsCOMPtr<nsIDocShellTreeItem> root; docShellTreeItem->GetRootTreeItem(getter_AddRefs(root)); nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(root)); if (!docShell || NS_FAILED(docShell->GetAppType(&appType))) { appType = nsIDocShell::APP_TYPE_UNKNOWN; } return appType == nsIDocShell::APP_TYPE_EDITOR; }
NS_IMETHODIMP nsMailboxService::OpenAttachment(const char *aContentType, const char *aFileName, const char *aUrl, const char *aMessageUri, nsISupports *aDisplayConsumer, nsIMsgWindow *aMsgWindow, nsIUrlListener *aUrlListener) { nsCOMPtr <nsIURI> URL; nsCAutoString urlString(aUrl); urlString += "&type="; urlString += aContentType; urlString += "&filename="; urlString += aFileName; CreateStartupUrl(urlString.get(), getter_AddRefs(URL)); nsresult rv; nsCOMPtr<nsIMsgMailNewsUrl> mailboxUrl(do_QueryInterface(URL, &rv)); if (NS_SUCCEEDED(rv) && mailboxUrl) mailboxUrl->SetMsgWindow(aMsgWindow); // try to run the url in the docshell... nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aDisplayConsumer, &rv)); // if we were given a docShell, run the url in the docshell..otherwise just run it normally. if (NS_SUCCEEDED(rv) && docShell) { nsCOMPtr<nsIDocShellLoadInfo> loadInfo; // DIRTY LITTLE HACK --> since we are opening an attachment we want the docshell to // treat this load as if it were a user click event. Then the dispatching stuff will be much // happier. docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); loadInfo->SetLoadType(nsIDocShellLoadInfo::loadLink); return docShell->LoadURI(URL, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, PR_FALSE); } return RunMailboxUrl(URL, aDisplayConsumer); }
nsresult Location::GetURI(nsIURI** aURI, bool aGetInnermostURI) { *aURI = nullptr; nsresult rv; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell, &rv)); if (NS_FAILED(rv)) { return rv; } nsCOMPtr<nsIURI> uri; rv = webNav->GetCurrentURI(getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, rv); // It is valid for docshell to return a null URI. Don't try to fixup // if this happens. if (!uri) { return NS_OK; } if (aGetInnermostURI) { nsCOMPtr<nsIJARURI> jarURI(do_QueryInterface(uri)); while (jarURI) { jarURI->GetJARFile(getter_AddRefs(uri)); jarURI = do_QueryInterface(uri); } } NS_ASSERTION(uri, "nsJARURI screwed up?"); nsCOMPtr<nsIURIFixup> urifixup(do_GetService(NS_URIFIXUP_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); return urifixup->CreateExposableURI(uri, aURI); }
NS_IMETHODIMP nsMsgWindow::GetMessageWindowDocShell(nsIDocShell ** aDocShell) { *aDocShell = nullptr; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mMessageWindowDocShellWeak)); if (!docShell) { // if we don't have a docshell, then we need to look up the message pane docshell nsCOMPtr<nsIDocShell> rootShell(do_QueryReferent(mRootDocShellWeak)); if (rootShell) { nsCOMPtr<nsIDocShellTreeItem> msgDocShellItem; if(rootShell) rootShell->FindChildWithName(MOZ_UTF16("messagepane"), true, false, nullptr, nullptr, getter_AddRefs(msgDocShellItem)); NS_ENSURE_TRUE(msgDocShellItem, NS_ERROR_FAILURE); docShell = do_QueryInterface(msgDocShellItem); // we don't own mMessageWindowDocShell so don't try to keep a reference to it! mMessageWindowDocShellWeak = do_GetWeakReference(docShell); } } docShell.swap(*aDocShell); return NS_OK; }
NS_IMETHODIMP nsLocation::SetHref(const nsAString& aHref) { nsAutoString oldHref; nsresult rv = NS_OK; JSContext *cx = nsContentUtils::GetCurrentJSContext(); // According to HTML5 spec, |location.href = ...| must act as if // it were |location.replace(...)| before the page load finishes. // // http://www.w3.org/TR/2011/WD-html5-20110113/history.html#location // // > The href attribute must return the current address of the // > associated Document object, as an absolute URL. // > // > On setting, if the Location object's associated Document // > object has completely loaded, then the user agent must act // > as if the assign() method had been called with the new value // > as its argument. Otherwise, the user agent must act as if // > the replace() method had been called with the new value as its // > argument. // // Note: The spec says the condition is "Document object has completely // loaded", but that may break some websites. If the user was // willing to move from one page to another, and was able to do // so, we should not overwrite the session history entry even // if the loading has not finished yet. // // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17041 // // See bug 39938, bug 72197, bug 178729 and bug 754029. // About other browsers: // http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-July/027372.html bool replace = false; if (!nsEventStateManager::IsHandlingUserInput()) { // "completely loaded" is defined at: // // http://www.w3.org/TR/2012/WD-html5-20120329/the-end.html#completely-loaded // // > 7. document readiness to "complete", and fire "load". // > // > 8. "pageshow" // > // > 9. ApplicationCache // > // > 10. Print in the pending list. // > // > 12. Queue a task to mark the Document as completely loaded. // // Since Gecko doesn't (yet) have a flag corresponding to no. "12. // ... completely loaded", here the logic is a little tricky. nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); nsCOMPtr<nsIDocument> document(do_GetInterface(docShell)); if (document) { replace = nsIDocument::READYSTATE_COMPLETE != document->GetReadyStateEnum(); // nsIDocShell::isExecutingOnLoadHandler is true while // the document is handling "load", "pageshow", // "readystatechange" for "complete" and "beforeprint"/"afterprint". // // Maybe this API property needs a better name. if (!replace) { docShell->GetIsExecutingOnLoadHandler(&replace); } } } if (cx) { rv = SetHrefWithContext(cx, aHref, replace); } else { rv = GetHref(oldHref); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIURI> oldUri; rv = NS_NewURI(getter_AddRefs(oldUri), oldHref); if (oldUri) { rv = SetHrefWithBase(aHref, oldUri, replace); } } } return rv; }
nsresult Location::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) { *aLoadInfo = nullptr; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); NS_ENSURE_TRUE(docShell, NS_ERROR_NOT_AVAILABLE); nsCOMPtr<nsIPrincipal> triggeringPrincipal; nsCOMPtr<nsIURI> sourceURI; net::ReferrerPolicy referrerPolicy = net::RP_Default; if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) { // No cx means that there's no JS running, or at least no JS that // was run through code that properly pushed a context onto the // context stack (as all code that runs JS off of web pages // does). We won't bother with security checks in this case, but // we need to create the loadinfo etc. // Get security manager. nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); NS_ENSURE_STATE(ssm); // Check to see if URI is allowed. nsresult rv = ssm->CheckLoadURIFromScript(cx, aURI); NS_ENSURE_SUCCESS(rv, rv); // Make the load's referrer reflect changes to the document's URI caused by // push/replaceState, if possible. First, get the document corresponding to // fp. If the document's original URI (i.e. its URI before // push/replaceState) matches the principal's URI, use the document's // current URI as the referrer. If they don't match, use the principal's // URI. // // The triggering principal for this load should be the principal of the // incumbent document (which matches where the referrer information is // coming from) when there is an incumbent document, and the subject // principal otherwise. Note that the URI in the triggering principal // may not match the referrer URI in various cases, notably including // the cases when the incumbent document's document URI was modified // after the document was loaded. nsCOMPtr<nsPIDOMWindowInner> incumbent = do_QueryInterface(mozilla::dom::GetIncumbentGlobal()); nsCOMPtr<nsIDocument> doc = incumbent ? incumbent->GetDoc() : nullptr; if (doc) { nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI; docOriginalURI = doc->GetOriginalURI(); docCurrentURI = doc->GetDocumentURI(); rv = doc->NodePrincipal()->GetURI(getter_AddRefs(principalURI)); NS_ENSURE_SUCCESS(rv, rv); triggeringPrincipal = doc->NodePrincipal(); referrerPolicy = doc->GetReferrerPolicy(); bool urisEqual = false; if (docOriginalURI && docCurrentURI && principalURI) { principalURI->Equals(docOriginalURI, &urisEqual); } if (urisEqual) { sourceURI = docCurrentURI; } else { // Use principalURI as long as it is not an nsNullPrincipalURI. We // could add a method such as GetReferrerURI to principals to make this // cleaner, but given that we need to start using Source Browsing // Context for referrer (see Bug 960639) this may be wasted effort at // this stage. if (principalURI) { bool isNullPrincipalScheme; rv = principalURI->SchemeIs(NS_NULLPRINCIPAL_SCHEME, &isNullPrincipalScheme); if (NS_SUCCEEDED(rv) && !isNullPrincipalScheme) { sourceURI = principalURI; } } } } else { // No document; determine triggeringPrincipal by quering the // subjectPrincipal, wich is the principal of the current JS // compartment, or a null principal in case there is no // compartment yet. triggeringPrincipal = nsContentUtils::SubjectPrincipal(); } } // Create load info nsCOMPtr<nsIDocShellLoadInfo> loadInfo; docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); loadInfo->SetTriggeringPrincipal(triggeringPrincipal); if (sourceURI) { loadInfo->SetReferrer(sourceURI); loadInfo->SetReferrerPolicy(referrerPolicy); } loadInfo.swap(*aLoadInfo); return NS_OK; }
nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, nsISelectionController *aSelectionController, bool aIsFirstVisiblePreferred, bool aFindPrev, nsIPresShell **aPresShell, nsPresContext **aPresContext) { NS_ENSURE_ARG_POINTER(aContainer); NS_ENSURE_ARG_POINTER(aPresShell); NS_ENSURE_ARG_POINTER(aPresContext); *aPresShell = nullptr; *aPresContext = nullptr; nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); if (!docShell) return NS_ERROR_FAILURE; nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell(); nsRefPtr<nsPresContext> presContext; docShell->GetPresContext(getter_AddRefs(presContext)); if (!presShell || !presContext) return NS_ERROR_FAILURE; nsIDocument* doc = presShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; nsCOMPtr<nsIContent> rootContent; nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc)); if (htmlDoc) { nsCOMPtr<nsIDOMHTMLElement> bodyEl; htmlDoc->GetBody(getter_AddRefs(bodyEl)); rootContent = do_QueryInterface(bodyEl); } if (!rootContent) rootContent = doc->GetRootElement(); nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootContent)); if (!rootNode) return NS_ERROR_FAILURE; if (!mSearchRange) { mSearchRange = new nsRange(doc); } nsCOMPtr<nsIDOMNode> searchRootNode = rootNode; // Hack for XMLPrettyPrinter. nsFind can't handle complex anonymous content. // If the root node has an XBL binding then there's not much we can do in // in general, but we can try searching the binding's first child, which // in the case of XMLPrettyPrinter contains the visible pretty-printed // content. nsXBLBinding* binding = rootContent->GetXBLBinding(); if (binding) { nsIContent* anonContent = binding->GetAnonymousContent(); if (anonContent) { searchRootNode = do_QueryInterface(anonContent->GetFirstChild()); } } mSearchRange->SelectNodeContents(searchRootNode); if (!mStartPointRange) { mStartPointRange = new nsRange(doc); } mStartPointRange->SetStart(searchRootNode, 0); mStartPointRange->Collapse(true); // collapse to start if (!mEndPointRange) { mEndPointRange = new nsRange(doc); } nsCOMPtr<nsINode> searchRootTmp = do_QueryInterface(searchRootNode); mEndPointRange->SetEnd(searchRootNode, searchRootTmp->Length()); mEndPointRange->Collapse(false); // collapse to end // Consider current selection as null if // it's not in the currently focused document nsCOMPtr<nsIDOMRange> currentSelectionRange; nsCOMPtr<nsIPresShell> selectionPresShell = GetPresShell(); if (aSelectionController && selectionPresShell && selectionPresShell == presShell) { nsCOMPtr<nsISelection> selection; aSelectionController->GetSelection( nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (selection) selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange)); } if (!currentSelectionRange) { // Ensure visible range, move forward if necessary // This uses ignores the return value, but usese the side effect of // IsRangeVisible. It returns the first visible range after searchRange IsRangeVisible(presShell, presContext, mSearchRange, aIsFirstVisiblePreferred, true, getter_AddRefs(mStartPointRange), nullptr); } else { int32_t startOffset; nsCOMPtr<nsIDOMNode> startNode; if (aFindPrev) { currentSelectionRange->GetStartContainer(getter_AddRefs(startNode)); currentSelectionRange->GetStartOffset(&startOffset); } else { currentSelectionRange->GetEndContainer(getter_AddRefs(startNode)); currentSelectionRange->GetEndOffset(&startOffset); } if (!startNode) startNode = rootNode; // We need to set the start point this way, other methods haven't worked mStartPointRange->SelectNode(startNode); mStartPointRange->SetStart(startNode, startOffset); } mStartPointRange->Collapse(true); // collapse to start presShell.forget(aPresShell); presContext.forget(aPresContext); return NS_OK; }
nsresult nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) { *aLoadInfo = nsnull; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); if (!docShell) { return NS_ERROR_NOT_AVAILABLE; } nsresult result; // Get JSContext from stack. nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result)); if (NS_FAILED(result)) return NS_ERROR_FAILURE; JSContext *cx; if (NS_FAILED(GetContextFromStack(stack, &cx))) return NS_ERROR_FAILURE; nsCOMPtr<nsISupports> owner; if (cx) { // No cx means that there's no JS running, or at least no JS that // was run through code that properly pushed a context onto the // context stack (as all code that runs JS off of web pages // does). We won't bother with security checks in this case, but // we need to create the loadinfo etc. // Get security manager. nsCOMPtr<nsIScriptSecurityManager> secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &result)); if (NS_FAILED(result)) return NS_ERROR_FAILURE; // Check to see if URI is allowed. result = secMan->CheckLoadURIFromScript(cx, aURI); if (NS_FAILED(result)) return result; // Now get the principal to use when loading the URI nsCOMPtr<nsIPrincipal> principal; if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))) || !principal) return NS_ERROR_FAILURE; owner = do_QueryInterface(principal); } // Create load info nsCOMPtr<nsIDocShellLoadInfo> loadInfo; docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); loadInfo->SetOwner(owner); // Now set the referrer on the loadinfo. We need to do this in order to get // the correct referrer URI from a document which was pushStated. nsCOMPtr<nsIURI> sourceURI; result = GetURI(getter_AddRefs(sourceURI)); if (NS_SUCCEEDED(result)) loadInfo->SetReferrer(sourceURI); loadInfo.swap(*aLoadInfo); return NS_OK; }
nsresult nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) { *aLoadInfo = nsnull; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); NS_ENSURE_TRUE(docShell, NS_ERROR_NOT_AVAILABLE); nsresult rv; // Get JSContext from stack. nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); JSContext *cx; NS_ENSURE_SUCCESS(GetContextFromStack(stack, &cx), NS_ERROR_FAILURE); nsCOMPtr<nsISupports> owner; nsCOMPtr<nsIURI> sourceURI; if (cx) { // No cx means that there's no JS running, or at least no JS that // was run through code that properly pushed a context onto the // context stack (as all code that runs JS off of web pages // does). We won't bother with security checks in this case, but // we need to create the loadinfo etc. // Get security manager. nsCOMPtr<nsIScriptSecurityManager> secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); // Check to see if URI is allowed. rv = secMan->CheckLoadURIFromScript(cx, aURI); NS_ENSURE_SUCCESS(rv, rv); // Now get the principal to use when loading the URI // First, get the principal and frame. JSStackFrame *fp; nsIPrincipal* principal = secMan->GetCxSubjectPrincipalAndFrame(cx, &fp); NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE); nsCOMPtr<nsIURI> principalURI; principal->GetURI(getter_AddRefs(principalURI)); // Make the load's referrer reflect changes to the document's URI caused by // push/replaceState, if possible. First, get the document corresponding to // fp. If the document's original URI (i.e. its URI before // push/replaceState) matches the principal's URI, use the document's // current URI as the referrer. If they don't match, use the principal's // URI. nsCOMPtr<nsIDocument> frameDoc = GetFrameDocument(cx, fp); nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI; if (frameDoc) { docOriginalURI = frameDoc->GetOriginalURI(); docCurrentURI = frameDoc->GetDocumentURI(); } bool urisEqual = false; if (docOriginalURI && docCurrentURI && principalURI) { principalURI->Equals(docOriginalURI, &urisEqual); } if (urisEqual) { sourceURI = docCurrentURI; } else { sourceURI = principalURI; } owner = do_QueryInterface(principal); } // Create load info nsCOMPtr<nsIDocShellLoadInfo> loadInfo; docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); loadInfo->SetOwner(owner); if (sourceURI) { loadInfo->SetReferrer(sourceURI); } loadInfo.swap(*aLoadInfo); return NS_OK; }
nsresult nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, nsISelectionController *aSelectionController, PRBool aIsFirstVisiblePreferred, PRBool aFindPrev, nsIPresShell **aPresShell, nsPresContext **aPresContext) { NS_ENSURE_ARG_POINTER(aContainer); NS_ENSURE_ARG_POINTER(aPresShell); NS_ENSURE_ARG_POINTER(aPresContext); *aPresShell = nsnull; *aPresContext = nsnull; nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); if (!docShell) return NS_ERROR_FAILURE; nsCOMPtr<nsIPresShell> presShell; docShell->GetPresShell(getter_AddRefs(presShell)); nsRefPtr<nsPresContext> presContext; docShell->GetPresContext(getter_AddRefs(presContext)); if (!presShell || !presContext) return NS_ERROR_FAILURE; nsIDocument* doc = presShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; nsCOMPtr<nsIContent> rootContent; nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc)); if (htmlDoc) { nsCOMPtr<nsIDOMHTMLElement> bodyEl; htmlDoc->GetBody(getter_AddRefs(bodyEl)); rootContent = do_QueryInterface(bodyEl); } if (!rootContent) rootContent = doc->GetRootElement(); nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootContent)); if (!rootNode) return NS_ERROR_FAILURE; PRUint32 childCount = rootContent->GetChildCount(); mSearchRange->SelectNodeContents(rootNode); mEndPointRange->SetEnd(rootNode, childCount); mEndPointRange->Collapse(PR_FALSE); // collapse to end // Consider current selection as null if // it's not in the currently focused document nsCOMPtr<nsIDOMRange> currentSelectionRange; nsCOMPtr<nsIPresShell> selectionPresShell = GetPresShell(); if (aSelectionController && selectionPresShell && selectionPresShell == presShell) { nsCOMPtr<nsISelection> selection; aSelectionController->GetSelection( nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (selection) selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange)); } if (!currentSelectionRange) { // Ensure visible range, move forward if necessary // This uses ignores the return value, but usese the side effect of // IsRangeVisible. It returns the first visible range after searchRange IsRangeVisible(presShell, presContext, mSearchRange, aIsFirstVisiblePreferred, PR_TRUE, getter_AddRefs(mStartPointRange), nsnull); } else { PRInt32 startOffset; nsCOMPtr<nsIDOMNode> startNode; if (aFindPrev) { currentSelectionRange->GetStartContainer(getter_AddRefs(startNode)); currentSelectionRange->GetStartOffset(&startOffset); } else { currentSelectionRange->GetEndContainer(getter_AddRefs(startNode)); currentSelectionRange->GetEndOffset(&startOffset); } if (!startNode) startNode = rootNode; // We need to set the start point this way, other methods haven't worked mStartPointRange->SelectNode(startNode); mStartPointRange->SetStart(startNode, startOffset); } mStartPointRange->Collapse(PR_TRUE); // collapse to start *aPresShell = presShell; NS_ADDREF(*aPresShell); *aPresContext = presContext; NS_ADDREF(*aPresContext); return NS_OK; }
nsresult nsMailboxService::FetchMessage(const char* aMessageURI, nsISupports * aDisplayConsumer, nsIMsgWindow * aMsgWindow, nsIUrlListener * aUrlListener, const char * aFileName, /* only used by open attachment... */ nsMailboxAction mailboxAction, const char * aCharsetOverride, nsIURI ** aURL) { nsresult rv = NS_OK; nsCOMPtr<nsIMailboxUrl> mailboxurl; nsMailboxAction actionToUse = mailboxAction; nsCOMPtr <nsIURI> url; nsCAutoString uriString(aMessageURI); if (!strncmp(aMessageURI, "file:", 5)) { PRInt64 fileSize; nsCOMPtr<nsIURI> fileUri; rv = NS_NewURI(getter_AddRefs(fileUri), aMessageURI); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr <nsIFileURL> fileUrl = do_QueryInterface(fileUri, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr <nsIFile> file; rv = fileUrl->GetFile(getter_AddRefs(file)); NS_ENSURE_SUCCESS(rv, rv); file->GetFileSize(&fileSize); nsCAutoString uriString(aMessageURI); uriString.ReplaceSubstring(NS_LITERAL_CSTRING("file:"), NS_LITERAL_CSTRING("mailbox:")); uriString.Append(NS_LITERAL_CSTRING("&number=0")); rv = NS_NewURI(getter_AddRefs(url), uriString); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIMsgMailNewsUrl> msgurl = do_QueryInterface(url); if (msgurl) { msgurl->SetMsgWindow(aMsgWindow); nsCOMPtr <nsIMailboxUrl> mailboxUrl = do_QueryInterface(msgurl, &rv); mailboxUrl->SetMessageSize((PRUint32) fileSize); nsCOMPtr <nsIMsgHeaderSink> headerSink; // need to tell the header sink to capture some headers to create a fake db header // so we can do reply to a .eml file or a rfc822 msg attachment. if (aMsgWindow) aMsgWindow->GetMsgHeaderSink(getter_AddRefs(headerSink)); if (headerSink) { nsCOMPtr <nsIMsgDBHdr> dummyHeader; headerSink->GetDummyMsgHeader(getter_AddRefs(dummyHeader)); if (dummyHeader) dummyHeader->SetMessageSize((PRUint32) fileSize); } } } else { // this happens with forward inline of message/rfc822 attachment // opened in a stand-alone msg window. PRInt32 typeIndex = typeIndex = uriString.Find("&type=application/x-message-display"); if (typeIndex != kNotFound) { uriString.Cut(typeIndex, sizeof("&type=application/x-message-display") - 1); rv = NS_NewURI(getter_AddRefs(url), uriString.get()); mailboxurl = do_QueryInterface(url); } else rv = PrepareMessageUrl(aMessageURI, aUrlListener, actionToUse , getter_AddRefs(mailboxurl), aMsgWindow); if (NS_SUCCEEDED(rv)) { url = do_QueryInterface(mailboxurl); nsCOMPtr<nsIMsgMailNewsUrl> msgUrl (do_QueryInterface(url)); msgUrl->SetMsgWindow(aMsgWindow); nsCOMPtr<nsIMsgI18NUrl> i18nurl (do_QueryInterface(msgUrl)); i18nurl->SetCharsetOverRide(aCharsetOverride); if (aFileName) msgUrl->SetFileName(nsDependentCString(aFileName)); } } // instead of running the mailbox url like we used to, let's try to run the url in the docshell... nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aDisplayConsumer, &rv)); // if we were given a docShell, run the url in the docshell..otherwise just run it normally. if (NS_SUCCEEDED(rv) && docShell) { nsCOMPtr<nsIDocShellLoadInfo> loadInfo; // DIRTY LITTLE HACK --> if we are opening an attachment we want the docshell to // treat this load as if it were a user click event. Then the dispatching stuff will be much // happier. if (mailboxAction == nsIMailboxUrl::ActionFetchPart) { docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); loadInfo->SetLoadType(nsIDocShellLoadInfo::loadLink); } rv = docShell->LoadURI(url, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, PR_FALSE); } else rv = RunMailboxUrl(url, aDisplayConsumer); if (aURL && mailboxurl) mailboxurl->QueryInterface(NS_GET_IID(nsIURI), (void **) aURL); return rv; }
NS_IMETHODIMP nsCanvasFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { nsresult rv; if (GetPrevInFlow()) { DisplayOverflowContainers(aBuilder, aDirtyRect, aLists); } // Force a background to be shown. We may have a background propagated to us, // in which case GetStyleBackground wouldn't have the right background // and the code in nsFrame::DisplayBorderBackgroundOutline might not give us // a background. // We don't have any border or outline, and our background draws over // the overflow area, so just add nsDisplayCanvasBackground instead of // calling DisplayBorderBackgroundOutline. if (IsVisibleForPainting(aBuilder)) { nsStyleContext* bgSC; const nsStyleBackground* bg = nullptr; bool isThemed = IsThemed(); if (!isThemed && nsCSSRendering::FindBackground(PresContext(), this, &bgSC)) { bg = bgSC->GetStyleBackground(); } aLists.BorderBackground()->AppendNewToTop( new (aBuilder) nsDisplayCanvasBackgroundColor(aBuilder, this)); if (isThemed) { return aLists.BorderBackground()->AppendNewToTop( new (aBuilder) nsDisplayCanvasBackgroundImage(aBuilder, this, 0, isThemed, nullptr)); } if (!bg) { return NS_OK; } // Create separate items for each background layer. NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) { if (bg->mLayers[i].mImage.IsEmpty()) { continue; } rv = aLists.BorderBackground()->AppendNewToTop( new (aBuilder) nsDisplayCanvasBackgroundImage(aBuilder, this, i, isThemed, bg)); NS_ENSURE_SUCCESS(rv, rv); } } nsIFrame* kid; for (kid = GetFirstPrincipalChild(); kid; kid = kid->GetNextSibling()) { // Put our child into its own pseudo-stack. rv = BuildDisplayListForChild(aBuilder, kid, aDirtyRect, aLists); NS_ENSURE_SUCCESS(rv, rv); } #ifdef DEBUG_CANVAS_FOCUS nsCOMPtr<nsIContent> focusContent; aPresContext->EventStateManager()-> GetFocusedContent(getter_AddRefs(focusContent)); bool hasFocus = false; nsCOMPtr<nsISupports> container; aPresContext->GetContainer(getter_AddRefs(container)); nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container)); if (docShell) { docShell->GetHasFocus(&hasFocus); printf("%p - nsCanvasFrame::Paint R:%d,%d,%d,%d DR: %d,%d,%d,%d\n", this, mRect.x, mRect.y, mRect.width, mRect.height, aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); } printf("%p - Focus: %s c: %p DoPaint:%s\n", docShell.get(), hasFocus?"Y":"N", focusContent.get(), mDoPaintFocus?"Y":"N"); #endif if (!mDoPaintFocus) return NS_OK; // Only paint the focus if we're visible if (!GetStyleVisibility()->IsVisible()) return NS_OK; return aLists.Outlines()->AppendNewToTop(new (aBuilder) nsDisplayCanvasFocus(aBuilder, this)); }
nsresult MediaDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, nsISupports* aContainer, nsIStreamListener** aDocListener, bool aReset, nsIContentSink* aSink) { nsresult rv = nsDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, aReset, aSink); if (NS_FAILED(rv)) { return rv; } // We try to set the charset of the current document to that of the // 'genuine' (as opposed to an intervening 'chrome') parent document // that may be in a different window/tab. Even if we fail here, // we just return NS_OK because another attempt is made in // |UpdateTitleAndCharset| and the worst thing possible is a mangled // filename in the titlebar and the file picker. // When this document is opened in the window/tab of the referring // document (by a simple link-clicking), |prevDocCharacterSet| contains // the charset of the referring document. On the other hand, if the // document is opened in a new window, it is |defaultCharacterSet| of |muCV| // where the charset of our interest is stored. In case of openining // in a new tab, we get the charset from the docShell. Note that we // exclude UTF-8 as 'invalid' because UTF-8 is likely to be the charset // of a chrome document that has nothing to do with the actual content // whose charset we want to know. Even if "the actual content" is indeed // in UTF-8, we don't lose anything because the default empty value is // considered synonymous with UTF-8. nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); // not being able to set the charset is not critical. NS_ENSURE_TRUE(docShell, NS_OK); nsAutoCString charset; // opening in a new tab docShell->GetParentCharset(charset); if (charset.IsEmpty() || charset.Equals("UTF-8")) { nsCOMPtr<nsIContentViewer> cv; docShell->GetContentViewer(getter_AddRefs(cv)); // not being able to set the charset is not critical. NS_ENSURE_TRUE(cv, NS_OK); nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv); if (muCV) { muCV->GetPrevDocCharacterSet(charset); // opening in the same window/tab if (charset.Equals("UTF-8") || charset.IsEmpty()) { muCV->GetDefaultCharacterSet(charset); // opening in a new window } } } if (!charset.IsEmpty() && !charset.Equals("UTF-8")) { SetDocumentCharacterSet(charset); mCharacterSetSource = kCharsetFromUserDefault; } return NS_OK; }
static nsresult FetchMessage(const char* aMessageURI, nsISupports * aDisplayConsumer, nsIMsgWindow * aMsgWindow, nsIUrlListener * aUrlListener, const char * aFileName, /* only used by open attachment... */ nsMailboxAction mailboxAction, const char * aCharsetOverride, nsIURI ** aURL) { nsresult rv; nsCOMPtr<nsIMsgFolder> folder; nsAutoCString mimePart; nsAutoCString folderURI; nsAutoCString messageURI(aMessageURI); nsCOMPtr <nsIURI> uri; nsCOMPtr<nsIMailboxUrl> mailboxurl; nsCOMPtr<nsIMsgMailNewsUrl> msgUrl; int32_t typeIndex = messageURI.Find("&type=application/x-message-display"); if (typeIndex != kNotFound) { // This happens with forward inline of a message/rfc822 attachment opened in // a standalone msg window. // So, just cut to the chase and call AsyncOpen on a channel. messageURI.Cut(typeIndex, sizeof("&type=application/x-message-display") - 1); rv = NS_NewURI(getter_AddRefs(uri), messageURI.get()); mailboxurl = do_QueryInterface(uri); mailews_logger << "display message with uri 2:" << messageURI.get() << std::endl; } else { rv = PrepareMessageUrl(aMessageURI, aUrlListener, nsIMailboxUrl::ActionFetchMessage, getter_AddRefs(mailboxurl), aMsgWindow); NS_ENSURE_SUCCESS(rv, rv); } uri = do_QueryInterface(mailboxurl); if (aURL) NS_IF_ADDREF(*aURL = uri); nsCOMPtr<nsIMsgI18NUrl> i18nurl(do_QueryInterface(msgUrl)); if (i18nurl) i18nurl->SetCharsetOverRide(aCharsetOverride); nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aDisplayConsumer, &rv)); if (NS_SUCCEEDED(rv) && docShell) { rv = docShell->LoadURI(uri, nullptr, nsIWebNavigation::LOAD_FLAGS_NONE, false); NS_ENSURE_SUCCESS(rv, rv); mailews_logger << "uri loaded" << uri << std::endl; } else { mailews_logger << "unable to get doc shell" << std::endl; rv = RunMailboxUrl(uri, aDisplayConsumer); } return rv; }
NS_IMETHODIMP nsWebNavigationInfo::IsTypeSupported(const nsACString& aType, nsIWebNavigation* aWebNav, uint32_t* aIsTypeSupported) { MOZ_ASSERT(aIsTypeSupported, "null out param?"); // Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or // an nsSHistory, but not much we can do with that). So if we start using // it here, we need to be careful to get to the docshell correctly. // For now just report what the Gecko-Content-Viewers category has // to say for itself. *aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED; // We want to claim that the type for PDF documents is unsupported, // so that the internal PDF viewer's stream converted will get used. if (aType.LowerCaseEqualsLiteral("application/pdf") && nsContentUtils::IsPDFJSEnabled()) { return NS_OK; } const nsCString& flatType = PromiseFlatCString(aType); nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported); NS_ENSURE_SUCCESS(rv, rv); if (*aIsTypeSupported) { return rv; } // As of FF 52, we only support flash and test plugins, so if the mime types // don't match for that, exit before we start loading plugins. if (!nsPluginHost::CanUsePluginForMIMEType(aType)) { return NS_OK; } // If this request is for a docShell that isn't going to allow plugins, // there's no need to try and find a plugin to handle it. nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav)); bool allowed; if (docShell && NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) && !allowed) { return NS_OK; } // Try reloading plugins in case they've changed. nsCOMPtr<nsIPluginHost> pluginHost = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID); if (pluginHost) { // false will ensure that currently running plugins will not // be shut down rv = pluginHost->ReloadPlugins(); if (NS_SUCCEEDED(rv)) { // OK, we reloaded plugins and there were new ones // (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have // been returned). Try checking whether we can handle the // content now. return IsTypeSupportedInternal(flatType, aIsTypeSupported); } } return NS_OK; }
nsresult nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) { *aLoadInfo = nullptr; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); NS_ENSURE_TRUE(docShell, NS_ERROR_NOT_AVAILABLE); nsCOMPtr<nsISupports> owner; nsCOMPtr<nsIURI> sourceURI; if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) { // No cx means that there's no JS running, or at least no JS that // was run through code that properly pushed a context onto the // context stack (as all code that runs JS off of web pages // does). We won't bother with security checks in this case, but // we need to create the loadinfo etc. // Get security manager. nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); NS_ENSURE_STATE(ssm); // Check to see if URI is allowed. nsresult rv = ssm->CheckLoadURIFromScript(cx, aURI); NS_ENSURE_SUCCESS(rv, rv); // Make the load's referrer reflect changes to the document's URI caused by // push/replaceState, if possible. First, get the document corresponding to // fp. If the document's original URI (i.e. its URI before // push/replaceState) matches the principal's URI, use the document's // current URI as the referrer. If they don't match, use the principal's // URI. nsCOMPtr<nsIDocument> doc; nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI; nsCOMPtr<nsPIDOMWindow> entryPoint = do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx)); if (entryPoint) { doc = entryPoint->GetDoc(); } if (doc) { docOriginalURI = doc->GetOriginalURI(); docCurrentURI = doc->GetDocumentURI(); rv = doc->NodePrincipal()->GetURI(getter_AddRefs(principalURI)); NS_ENSURE_SUCCESS(rv, rv); } bool urisEqual = false; if (docOriginalURI && docCurrentURI && principalURI) { principalURI->Equals(docOriginalURI, &urisEqual); } if (urisEqual) { sourceURI = docCurrentURI; } else { sourceURI = principalURI; } owner = do_QueryInterface(ssm->GetCxSubjectPrincipal(cx)); } // Create load info nsCOMPtr<nsIDocShellLoadInfo> loadInfo; docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); loadInfo->SetOwner(owner); if (sourceURI) { loadInfo->SetReferrer(sourceURI); } loadInfo.swap(*aLoadInfo); return NS_OK; }