mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 11:26:09 +00:00
Factor out subframe check and add it for window events (bug 347305) r=brettw
This commit is contained in:
parent
324976ffe2
commit
6243e5a2a0
@ -42,7 +42,6 @@
|
||||
#endif
|
||||
|
||||
#include "nsLoadCollector.h"
|
||||
#include "nsWindowCollector.h"
|
||||
#include "nsMetricsService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCURILoader.h"
|
||||
@ -359,23 +358,12 @@ nsLoadCollector::OnStateChange(nsIWebProgress *webProgress,
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Consider the load to be a subframe if the docshell is not chrome,
|
||||
// and has a sameTypeParent.
|
||||
PRBool subframe = PR_FALSE;
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(docShell);
|
||||
if (treeItem) {
|
||||
PRInt32 itemType;
|
||||
treeItem->GetItemType(&itemType);
|
||||
if (itemType == nsIDocShellTreeItem::typeContent) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> parent;
|
||||
treeItem->GetSameTypeParent(getter_AddRefs(parent));
|
||||
if (parent) {
|
||||
subframe = PR_TRUE;
|
||||
rv = props->SetPropertyAsBool(NS_LITERAL_STRING("subframe"),
|
||||
PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(docShell);
|
||||
NS_ENSURE_STATE(item);
|
||||
PRBool subframe = nsMetricsUtils::IsSubframe(item);
|
||||
if (subframe) {
|
||||
rv = props->SetPropertyAsBool(NS_LITERAL_STRING("subframe"), PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
nsMetricsService *ms = nsMetricsService::get();
|
||||
|
@ -83,6 +83,7 @@
|
||||
#ifndef MOZILLA_1_8_BRANCH
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#endif
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsDocShellCID.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsIBadCertListener.h"
|
||||
@ -1745,3 +1746,24 @@ nsMetricsUtils::CreateElement(nsIDOMDocument *ownerDoc,
|
||||
return ownerDoc->CreateElementNS(NS_LITERAL_STRING(NS_METRICS_NAMESPACE),
|
||||
tag, element);
|
||||
}
|
||||
|
||||
|
||||
/* static */ PRBool
|
||||
nsMetricsUtils::IsSubframe(nsIDocShellTreeItem* docShell)
|
||||
{
|
||||
// Consider the docshell to be a subframe if it's is content, not chrome,
|
||||
// and has a parent docshell which is also content.
|
||||
if (!docShell) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 itemType;
|
||||
docShell->GetItemType(&itemType);
|
||||
if (itemType != nsIDocShellTreeItem::typeContent) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> parent;
|
||||
docShell->GetSameTypeParent(getter_AddRefs(parent));
|
||||
return (parent != nsnull);
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ class nsIDOMWindow;
|
||||
class nsIDOMDocument;
|
||||
class nsIDOMNode;
|
||||
class nsIMetricsCollector;
|
||||
class nsIDocShellTreeItem;
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
// Shared log for the metrics service and collectors.
|
||||
@ -309,6 +310,9 @@ public:
|
||||
// ownerDocument and tag.
|
||||
static nsresult CreateElement(nsIDOMDocument *ownerDoc,
|
||||
const nsAString &tag, nsIDOMElement **element);
|
||||
|
||||
// Returns true if the docshell should be considered a subframe.
|
||||
static PRBool IsSubframe(nsIDocShellTreeItem *docShell);
|
||||
};
|
||||
|
||||
#endif // nsMetricsService_h__
|
||||
|
@ -205,6 +205,11 @@ nsWindowCollector::Observe(nsISupports *subject,
|
||||
rv = properties->SetPropertyAsBool(NS_LITERAL_STRING("chrome"), PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
if (nsMetricsUtils::IsSubframe(item)) {
|
||||
rv = properties->SetPropertyAsBool(NS_LITERAL_STRING("subframe"),
|
||||
PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
} else if (strcmp(topic, "domwindowopened") == 0) {
|
||||
// We'd like to log a window open event now, but the window opener
|
||||
// has not yet been set when we receive the domwindowopened notification.
|
||||
@ -229,6 +234,14 @@ nsWindowCollector::Observe(nsISupports *subject,
|
||||
// Log a window destroy event.
|
||||
action.Assign("destroy");
|
||||
window = do_GetInterface(subject);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(subject);
|
||||
NS_ENSURE_STATE(item);
|
||||
if (nsMetricsUtils::IsSubframe(item)) {
|
||||
rv = properties->SetPropertyAsBool(NS_LITERAL_STRING("subframe"),
|
||||
PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
|
||||
if (window) {
|
||||
|
Loading…
Reference in New Issue
Block a user