Commit bff3df1e authored by ananta@chromium.org's avatar ananta@chromium.org

Implement poor man's redirect handling in ChromeFrame for browsers which don't implement

the NPAPI redirect notification spec.

We compare the URL received in the NewStream notification with the requested URL and if they
differ we cancel the current request and inform Chrome that this was a redirect. The sideeffect
would be that there would be two GET requests sent out.

BUG=69419
TEST=none.

Review URL: http://codereview.chromium.org/6381005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72029 0039d316-1c4b-4281-b951-d872f2087c98
parent c5b8b374
...@@ -527,3 +527,7 @@ void AllocateStringVariant(const std::string& str, NPVariant* var) { ...@@ -527,3 +527,7 @@ void AllocateStringVariant(const std::string& str, NPVariant* var) {
NULL_TO_NPVARIANT(*var); NULL_TO_NPVARIANT(*var);
} }
} }
bool BrowserSupportsRedirectNotification() {
return npapi::g_urlredirectresponse != NULL;
}
...@@ -276,4 +276,8 @@ class ScopedNpObject { ...@@ -276,4 +276,8 @@ class ScopedNpObject {
// The memory allocation is done via the npapi browser functions. // The memory allocation is done via the npapi browser functions.
void AllocateStringVariant(const std::string& str, NPVariant* var); void AllocateStringVariant(const std::string& str, NPVariant* var);
// Returns true if the host browser supports the NPAPI redirect notification
// spec. https://wiki.mozilla.org/NPAPI:HTTPRedirectHandling
bool BrowserSupportsRedirectNotification();
#endif // CHROME_FRAME_NP_BROWSER_FUNCTIONS_H_ #endif // CHROME_FRAME_NP_BROWSER_FUNCTIONS_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "chrome_frame/chrome_frame_npapi.h"
#include "chrome_frame/np_browser_functions.h" #include "chrome_frame/np_browser_functions.h"
#include "chrome_frame/np_utils.h" #include "chrome_frame/np_utils.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
...@@ -370,6 +371,24 @@ NPError NPAPIUrlRequestManager::NewStream(NPMIMEType type, ...@@ -370,6 +371,24 @@ NPError NPAPIUrlRequestManager::NewStream(NPMIMEType type,
} }
DCHECK(request_map_.find(request->id()) != request_map_.end()); DCHECK(request_map_.find(request->id()) != request_map_.end());
// If the host browser does not support the NPAPI redirect notification
// spec, and if the request URL is implicitly redirected, we need to
// inform Chrome about the redirect and allow it to follow the redirect.
// We achieve this by comparing the URL requested with the URL received in
// the response and if they don't match we assume a redirect. This would have
// a sideffect that two GET requests would be sent out in this case.
if (!BrowserSupportsRedirectNotification()) {
if (GURL(request->url().c_str()) != GURL(stream->url)) {
DVLOG(1) << "Request URL:"
<< request->url()
<< " was redirected to:"
<< stream->url;
delegate_->OnResponseStarted(request->id(), "", "", 0, base::Time(),
stream->url, 302);
return NPERR_GENERIC_ERROR;
}
}
// We need to return the requested stream mode if we are returning a success // We need to return the requested stream mode if we are returning a success
// code. If we don't do this it causes Opera to blow up. // code. If we don't do this it causes Opera to blow up.
*stream_type = NP_NORMAL; *stream_type = NP_NORMAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment