Bug 782654 - Add Mixed Active state and an hasMixedActiveContentLoaded flag. (r=smaug)

This commit is contained in:
Tanvi Vyas 2012-12-13 14:53:06 -08:00
Родитель ac128fe507
Коммит cb8c045f43
5 изменённых файлов: 97 добавлений и 18 удалений

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

@ -79,8 +79,8 @@ class Element;
} // namespace mozilla
#define NS_IDOCUMENT_IID \
{ 0xcc604bdc, 0xd55e, 0x4918, \
{ 0xaa, 0x82, 0xb2, 0xde, 0xbf, 0x01, 0x09, 0x5d } }
{ 0xcb362f1b, 0x8a05, 0x4d4f, \
{ 0x90, 0x63, 0xf2, 0x5f, 0x8b, 0x8c, 0xb2, 0xe1 } }
// Flag for AddStyleSheet().
#define NS_STYLESHEET_FROM_CATALOG (1 << 0)
@ -400,6 +400,22 @@ public:
mBidiOptions = aBidiOptions;
}
/**
* Get the has mixed active content loaded flag for this document.
*/
bool GetHasMixedActiveContentLoaded()
{
return mHasMixedActiveContentLoaded;
}
/**
* Set the has mixed active content loaded flag for this document.
*/
void SetHasMixedActiveContentLoaded(bool aHasMixedActiveContentLoaded)
{
mHasMixedActiveContentLoaded = aHasMixedActiveContentLoaded;
}
/**
* Get the sandbox flags for this document.
@ -1899,6 +1915,9 @@ protected:
// True if a DOMMutationObserver is perhaps attached to a node in the document.
bool mMayHaveDOMMutationObservers;
// True if a document has loaded Mixed Active Script (see nsMixedContentBlocker.cpp)
bool mHasMixedActiveContentLoaded;
// The document's script global object, the object from which the
// document can get its script context and scope. This is the
// *inner* window object.

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

@ -9,12 +9,20 @@
#include "nsINode.h"
#include "nsCOMPtr.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsISecurityEventSink.h"
#include "nsIWebProgressListener.h"
#include "nsContentUtils.h"
#include "nsNetUtil.h"
#include "nsIRequest.h"
#include "nsIDocument.h"
#include "nsIContentViewer.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
#include "mozilla/Preferences.h"
#include "prlog.h"
using namespace mozilla;
// Is mixed script blocking (fonts, plugin content, scripts, stylesheets,
@ -27,13 +35,10 @@ bool nsMixedContentBlocker::sBlockMixedDisplay = false;
// Fired at the document that attempted to load mixed content. The UI could
// handle this event, for example, by displaying an info bar that offers the
// choice to reload the page with mixed content permitted.
//
// Disabled for now until bug 782654 is fixed
/*
class nsMixedContentBlockedEvent : public nsRunnable
class nsMixedContentEvent : public nsRunnable
{
public:
nsMixedContentBlockedEvent(nsISupports *aContext, unsigned short aType)
nsMixedContentEvent(nsISupports *aContext, MixedContentTypes aType)
: mContext(aContext), mType(aType)
{}
@ -47,6 +52,41 @@ public:
// calling NS_CP_GetDocShellFromContext on the context, and QI'ing to
// nsISecurityEventSink.
// Mixed content was allowed and is about to load; get the document and
// set the approriate flag to true if we are about to load Mixed Active
// Content.
nsCOMPtr<nsIDocShell> docShell = NS_CP_GetDocShellFromContext(mContext);
nsCOMPtr<nsIDocShellTreeItem> currentDocShellTreeItem(do_QueryInterface(docShell));
if(!currentDocShellTreeItem) {
return NS_OK;
}
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
currentDocShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
// now get the document from sameTypeRoot
nsCOMPtr<nsIDocument> rootDoc = do_GetInterface(sameTypeRoot);
NS_ASSERTION(rootDoc, "No root document from document shell root tree item.");
if(mType == eMixedScript) {
rootDoc->SetHasMixedActiveContentLoaded(true);
// Update the security UI in the tab with the blocked mixed content
nsCOMPtr<nsISecurityEventSink> eventSink = do_QueryInterface(docShell);
if (eventSink) {
eventSink->OnSecurityChange(mContext, nsIWebProgressListener::STATE_IS_BROKEN);
}
} else {
if(mType == eMixedDisplay) {
//Do Nothing for now; state will already be set STATE_IS_BROKEN
}
}
return NS_OK;
}
private:
@ -54,10 +94,10 @@ private:
// the document that caused the load.
nsCOMPtr<nsISupports> mContext;
// The type of mixed content that was blocked, e.g. active or display
unsigned short mType;
// The type of mixed content detected, e.g. active or display
const MixedContentTypes mType;
};
*/
nsMixedContentBlocker::nsMixedContentBlocker()
{
@ -181,7 +221,7 @@ nsMixedContentBlocker::ShouldLoad(uint32_t aContentType,
// Disabled until bug 782654 is fixed.
/*
nsContentUtils::AddScriptRunner(
new nsMixedContentBlockedEvent(aRequestingContext, eBlockedMixedScript));
new nsMixedContentEvent(aRequestingContext, eMixedScript));
*/
}
break;
@ -199,7 +239,7 @@ nsMixedContentBlocker::ShouldLoad(uint32_t aContentType,
// Disabled until bug 782654 is fixed.
/*
nsContentUtils::AddScriptRunner(
new nsMixedContentBlockedEvent(aRequestingContext, eBlockedMixedDisplay));
new nsMixedContentEvent(aRequestingContext, eMixedDisplay));
*/
}
break;

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

@ -12,14 +12,14 @@
{ 0xdaf1461b, 0xbf29, 0x4f88, \
{ 0x8d, 0x0e, 0x4b, 0xcd, 0xf3, 0x32, 0xc8, 0x62 } }
// This enum defines type of content that is blocked when an
// nsMixedContentBlockedEvent fires
enum MixedContentBlockedTypes {
// This enum defines type of content that is detected when an
// nsMixedContentEvent fires
enum MixedContentTypes {
// "Active" content, such as fonts, plugin content, JavaScript, stylesheets,
// iframes, WebSockets, and XHR
eBlockedMixedScript,
eMixedScript,
// "Display" content, such as images, audio, video, and <a ping>
eBlockedMixedDisplay
eMixedDisplay
};
#include "nsIContentPolicy.h"

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

@ -1960,6 +1960,14 @@ nsDocShell::GetChannelIsUnsafe(bool *aUnsafe)
return jarChannel->GetIsUnsafe(aUnsafe);
}
NS_IMETHODIMP
nsDocShell::GetHasMixedActiveContentLoaded(bool *aHasMixedActiveContentLoaded)
{
nsCOMPtr<nsIDocument> doc(do_GetInterface(GetAsSupports(this)));
*aHasMixedActiveContentLoaded = doc && doc->GetHasMixedActiveContentLoaded();
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetAllowPlugins(bool * aAllowPlugins)
{

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

@ -39,7 +39,7 @@ interface nsIWebBrowserPrint;
interface nsIVariant;
interface nsIPrivacyTransitionObserver;
[scriptable, builtinclass, uuid(a106db7f-6449-4a6b-914f-834ba308c3e2)]
[scriptable, builtinclass, uuid(ed04b29f-ae9a-460a-858e-960b523bb3a5)]
interface nsIDocShell : nsISupports
{
/**
@ -464,6 +464,18 @@ interface nsIDocShell : nsISupports
*/
readonly attribute boolean channelIsUnsafe;
/**
* This attribute determines whether Mixed Active Content is loaded on the
* document. When it is true, mixed active content was not blocked and has
* loaded on the page. When it is false, mixed active content has not loaded on
* the page, either because there was no mixed active content requests on the page
* or such requests were blocked by nsMixedContentBlocker.
* This boolean is set to true in nsMixedContentBlocker if Mixed Active Content
* is allowed (either explicitly on the page by the user or when the about:config
* setting security.mixed_content.block_active_content is set to false).
*/
readonly attribute boolean hasMixedActiveContentLoaded;
/**
* Disconnects this docshell's editor from its window, and stores the
* editor data in the open document's session history entry. This