Skip to content

Commit

Permalink
In ChromeFrame with the IMoniker patch on, we should save away the re…
Browse files Browse the repository at this point in the history
…direct information received for the initial pending request. This

is to ensure that we inform Chrome about this redirect which can then be followed correctly from Chrome. 

The other change is to save away the URL being navigated to in the bind context context object. This is also updated if we receive a redirect
notification in our callback wrapper. The active document refers this URL if it is available and falls back to the old mechanism of retrieving
the URL from the moniker if not.

This ensures that optin urls continue to work correctly if the initial page is redirected.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45114 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ananta@chromium.org committed Apr 20, 2010
1 parent 735f05d commit 29c32f9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
9 changes: 9 additions & 0 deletions chrome_frame/bind_context_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@ class BindContextInfo : public IUnknown, public CComObjectRoot {
return cache_;
}

void set_url(const std::wstring& url) {
url_ = url;
}

const std::wstring url() const {
return url_;
}

private:
ScopedComPtr<IStream> cache_;
bool no_cache_;
bool chrome_request_;
bool is_switching_;
std::wstring url_;

DISALLOW_COPY_AND_ASSIGN(BindContextInfo);
};
Expand Down
20 changes: 15 additions & 5 deletions chrome_frame/chrome_active_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome_frame/bho.h"
#include "chrome_frame/bind_context_info.h"
#include "chrome_frame/utils.h"

const wchar_t kChromeAttachExternalTabPrefix[] = L"attach_external_tab";
Expand Down Expand Up @@ -233,11 +234,20 @@ STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable,
NavigationManager* mgr = NavigationManager::GetThreadInstance();
DCHECK(mgr);

// If the original URL contains an anchor, then the URL queried
// from the moniker does not contain the anchor. To workaround
// this we retrieve the URL from our BHO.
std::wstring url(GetActualUrlFromMoniker(
moniker_name, bind_context, mgr ? mgr->url(): std::wstring()));
std::wstring url;

scoped_refptr<BindContextInfo> info =
BindContextInfo::FromBindContext(bind_context);
DCHECK(info);
if (info && !info->url().empty()) {
url = info->url();
} else {
// If the original URL contains an anchor, then the URL queried
// from the moniker does not contain the anchor. To workaround
// this we retrieve the URL from our BHO.
url = GetActualUrlFromMoniker(moniker_name, bind_context,
mgr ? mgr->url(): std::wstring());
}

// The is_new_navigation variable indicates if this a navigation initiated
// by typing in a URL for e.g. in the IE address bar, or from Chrome by
Expand Down
7 changes: 6 additions & 1 deletion chrome_frame/urlmon_bind_status_callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ bool SniffData::InitializeCache(const std::wstring& url) {
NOTREACHED();
return false;
}

return true;
}

Expand Down Expand Up @@ -213,6 +212,12 @@ STDMETHODIMP BSCBStorageBind::OnProgress(ULONG progress, ULONG progress_max,
Progress new_progress = { progress, progress_max, status_code,
status_text ? status_text : std::wstring() };
saved_progress_.push_back(new_progress);
if (status_code == BINDSTATUS_REDIRECTING) {
scoped_refptr<BindContextInfo> info =
BindContextInfo::FromBindContext(bind_ctx_);
DCHECK(info);
info->set_url(status_text);
}
} else {
hr = CallbackImpl::OnProgress(progress, progress_max, status_code,
status_text);
Expand Down
38 changes: 25 additions & 13 deletions chrome_frame/urlmon_url_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,31 @@ STDMETHODIMP UrlmonUrlRequest::OnProgress(ULONG progress, ULONG max_progress,
return S_OK;
}

// Ignore any notifications received while we are in the pending state waiting
// for the request to be initiated by Chrome.
if (pending_)
// Ignore any notifications received while we are in the pending state
// waiting for the request to be initiated by Chrome.
if (pending_ && status_code != BINDSTATUS_REDIRECTING)
return S_OK;

switch (status_code) {
case BINDSTATUS_REDIRECTING: {
DLOG(INFO) << "URL: " << url() << " redirected to " << status_text;
// Fetch the redirect status as they aren't all equal (307 in particular
// retains the HTTP request verb).
int http_code = GetHttpResponseStatusFromBinding(binding_);
status_.SetRedirected(http_code, WideToUTF8(status_text));
// Abort. We will inform Chrome in OnStopBinding callback.
binding_->Abort();
return E_ABORT;
// If we receive a redirect for the initial pending request initiated
// when our document loads we should stash it away and inform Chrome
// accordingly when it requests data for the original URL.
scoped_refptr<BindContextInfo> info =
BindContextInfo::FromBindContext(bind_context_);
DCHECK(info);
GURL previously_redirected(info ? info->url() : std::wstring());
if (GURL(status_text) != previously_redirected) {
DLOG(INFO) << "URL: " << url() << " redirected to " << status_text;
// Fetch the redirect status as they aren't all equal (307 in particular
// retains the HTTP request verb).
int http_code = GetHttpResponseStatusFromBinding(binding_);
status_.SetRedirected(http_code, WideToUTF8(status_text));
// Abort. We will inform Chrome in OnStopBinding callback.
binding_->Abort();
return E_ABORT;
}
break;
}

case BINDSTATUS_COOKIE_SENT:
Expand Down Expand Up @@ -313,8 +323,10 @@ STDMETHODIMP UrlmonUrlRequest::OnStopBinding(HRESULT result, LPCWSTR error) {
if (status_.was_redirected()) {
// Just release bindings here. Chrome will issue EndRequest(request_id)
// after processing headers we had provided.
std::string headers = GetHttpHeadersFromBinding(binding_);
OnResponse(0, UTF8ToWide(headers).c_str(), NULL, NULL);
if (!pending_) {
std::string headers = GetHttpHeadersFromBinding(binding_);
OnResponse(0, UTF8ToWide(headers).c_str(), NULL, NULL);
}
ReleaseBindings();
return S_OK;
}
Expand Down

0 comments on commit 29c32f9

Please sign in to comment.