Hello
james.su,
I'd like you to do a code review. Please review the following patch:
----------------------------------------------------------------------
r1285: (no author) | 2009-12-03 15:54:22 +0800
Support 301/302 redirections for ongotourl.
----------------------------------------------------------------------
r1286: (no author) | 2009-12-03 15:56:50 +0800
----------------------------------------------------------------------
=== extensions/gtkmoz_browser_element/browser_child.cc
==================================================================
--- extensions/gtkmoz_browser_element/browser_child.cc (revision 1284)
+++ extensions/gtkmoz_browser_element/browser_child.cc (revision 1286)
@@ -53,6 +53,8 @@
#endif
#include <nsEvent.h>
#include <nsICategoryManager.h>
+#include <nsIChannel.h>
+#include <nsIChannelEventSink.h>
#include <nsIComponentRegistrar.h>
#include <nsIContentPolicy.h>
#include <nsIDOMAbstractView.h>
@@ -581,10 +583,12 @@
return NULL;
}
-class ContentPolicy : public nsIContentPolicy {
+class ContentPolicy : public nsIContentPolicy, public nsIChannelEventSink {
public:
NS_DECL_ISUPPORTS
+ static const PRUint32 kTypeRedirect = 999;
+
NS_IMETHOD ShouldLoad(PRUint32 content_type, nsIURI *content_location,
nsIURI *request_origin, nsISupports *context,
const nsACString &mime_type_guess, nsISupports *extra,
@@ -627,8 +631,10 @@
return NS_OK;
}
- if (content_type == TYPE_DOCUMENT || content_type == TYPE_SUBDOCUMENT) {
- if (!browser_info->always_open_new_window) {
+ if (content_type == TYPE_DOCUMENT || content_type == TYPE_SUBDOCUMENT ||
+ content_type == kTypeRedirect) {
+ if (content_type == kTypeRedirect ||
+ !browser_info->always_open_new_window) {
std::string r = SendFeedback(browser_info->browser_id,
kGoToURLFeedback, url_spec.get(),
NULL);
@@ -693,9 +699,28 @@
return ShouldLoad(content_type, content_location, request_origin,
context, mime_type, extra, retval);
}
+
+ NS_IMETHOD OnChannelRedirect(nsIChannel *old_channel, nsIChannel *new_channel,
+ PRUint32 flags) {
+ nsCOMPtr<nsIURI> uri;
+ nsresult rv = new_channel->GetURI(getter_AddRefs(uri));
+ NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsIInterfaceRequestor> callbacks;
+ rv = new_channel->GetNotificationCallbacks(getter_AddRefs(callbacks));
+ NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsIDOMWindow> window(do_GetInterface(callbacks));
+ if (window) {
+ PRInt16 should_load;
+ rv = ShouldLoad(kTypeRedirect, uri, nsnull, window,
+ NS_LITERAL_CSTRING(""), nsnull, &should_load);
+ NS_ENSURE_SUCCESS(rv, rv);
+ return should_load == ACCEPT ? NS_OK : NS_ERROR_FAILURE;
+ }
+ return NS_OK;
+ }
};
-NS_IMPL_ISUPPORTS1(ContentPolicy, nsIContentPolicy)
+NS_IMPL_ISUPPORTS2(ContentPolicy, nsIContentPolicy, nsIChannelEventSink)
static ContentPolicy g_content_policy;
static ContentPolicy *GetContentPolicy() {
@@ -1231,6 +1256,10 @@
CONTENT_POLICY_CONTRACTID,
PR_FALSE, PR_TRUE, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
+ rv = category_manager->AddCategoryEntry("net-channel-event-sinks",
+ CONTENT_POLICY_CONTRACTID,
+ CONTENT_POLICY_CONTRACTID,
+ PR_FALSE, PR_TRUE, nsnull);
return rv;
}
This is a semiautomated message from "svkmail". Complaints or suggestions?
Mail
edy...@gmail.com.