From 6243e5a2a0470893daff4ba8d837dd1587f9f9ec Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Mon, 7 Aug 2006 18:46:24 +0000 Subject: [PATCH] Factor out subframe check and add it for window events (bug 347305) r=brettw --- extensions/metrics/src/nsLoadCollector.cpp | 24 +++++--------------- extensions/metrics/src/nsMetricsService.cpp | 22 ++++++++++++++++++ extensions/metrics/src/nsMetricsService.h | 4 ++++ extensions/metrics/src/nsWindowCollector.cpp | 13 +++++++++++ 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/extensions/metrics/src/nsLoadCollector.cpp b/extensions/metrics/src/nsLoadCollector.cpp index dcfe33a807b7..2ffee314b086 100644 --- a/extensions/metrics/src/nsLoadCollector.cpp +++ b/extensions/metrics/src/nsLoadCollector.cpp @@ -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 treeItem = do_QueryInterface(docShell); - if (treeItem) { - PRInt32 itemType; - treeItem->GetItemType(&itemType); - if (itemType == nsIDocShellTreeItem::typeContent) { - nsCOMPtr 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 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(); diff --git a/extensions/metrics/src/nsMetricsService.cpp b/extensions/metrics/src/nsMetricsService.cpp index c2aeef7a6e7a..0a521731343d 100644 --- a/extensions/metrics/src/nsMetricsService.cpp +++ b/extensions/metrics/src/nsMetricsService.cpp @@ -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 parent; + docShell->GetSameTypeParent(getter_AddRefs(parent)); + return (parent != nsnull); +} diff --git a/extensions/metrics/src/nsMetricsService.h b/extensions/metrics/src/nsMetricsService.h index 965f66463ff8..55369f939d2e 100644 --- a/extensions/metrics/src/nsMetricsService.h +++ b/extensions/metrics/src/nsMetricsService.h @@ -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__ diff --git a/extensions/metrics/src/nsWindowCollector.cpp b/extensions/metrics/src/nsWindowCollector.cpp index f9e5ff98b6dc..25ef15aa5e2b 100644 --- a/extensions/metrics/src/nsWindowCollector.cpp +++ b/extensions/metrics/src/nsWindowCollector.cpp @@ -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 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) {