Skip to content

Commit

Permalink
Makes it so that loads originating from instant never show auth
Browse files Browse the repository at this point in the history
dialogs. This restriction is imposed by not being able to merge tab
contents with a pending navigation (auth dialogs result in a pending
navigation until the user authenticates).

BUG=89439
TEST=with instant enabled try a page that loads an auth dialog, make
sure you only see the dialog when you press enter.
R=cbentzel@chromium.org,jam@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100142 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed Sep 8, 2011
1 parent 9336ac3 commit b6ea339
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 6 additions & 5 deletions chrome/browser/instant/instant_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ const int kUpdateBoundsDelayMS = 1000;
// If this status code is seen instant is disabled for the specified host.
const int kHostBlacklistStatusCode = 403;

// Header and value set for all loads.
const char kPreviewHeader[] = "X-Purpose";
const char kPreviewHeaderValue[] = "instant";

} // namespace

// static
const char* const InstantLoader::kInstantHeader = "X-Purpose";
// static
const char* const InstantLoader::kInstantHeaderValue = "instant";

// FrameLoadObserver is responsible for determining if the page supports
// instant after it has loaded.
class InstantLoader::FrameLoadObserver : public NotificationObserver {
Expand Down Expand Up @@ -416,7 +417,7 @@ void InstantLoader::TabContentsDelegateImpl::NavigationStateChanged(
void InstantLoader::TabContentsDelegateImpl::AddNavigationHeaders(
const GURL& url,
std::string* headers) {
net::HttpUtil::AppendHeaderIfMissing(kPreviewHeader, kPreviewHeaderValue,
net::HttpUtil::AppendHeaderIfMissing(kInstantHeader, kInstantHeaderValue,
headers);
}

Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/instant/instant_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class TemplateURL;
// loaded as is.
class InstantLoader : public NotificationObserver {
public:
// Header and value set on loads that originate from instant.
static const char* const kInstantHeader;
static const char* const kInstantHeaderValue;

InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id);
virtual ~InstantLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "chrome/browser/download/download_throttling_resource_handler.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/instant/instant_loader.h"
#include "chrome/browser/net/load_timing_observer.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_tracker.h"
Expand Down Expand Up @@ -40,6 +41,22 @@

namespace {

// Empty ResourceDispatcherHostLoginDelegate implementation used for instant.
// Auth navigations don't commit the load (the load remains pending) until the
// user cancels or succeeds in authorizing. Since we don't allow merging of
// TabContents with pending loads we disallow auth dialogs from showing during
// instant. This empty ResourceDispatcherHostLoginDelegate implementation does
// that.
// TODO: see if we can handle this case more robustly.
class InstantResourceDispatcherHostLoginDelegate :
public ResourceDispatcherHostLoginDelegate {
public:
InstantResourceDispatcherHostLoginDelegate() {}

private:
DISALLOW_COPY_AND_ASSIGN(InstantResourceDispatcherHostLoginDelegate);
};

void AddPrerenderOnUI(
const base::Callback<prerender::PrerenderManager*(void)>&
prerender_manager_getter,
Expand Down Expand Up @@ -257,6 +274,11 @@ bool ChromeResourceDispatcherHostDelegate::AcceptAuthRequest(
ResourceDispatcherHostLoginDelegate*
ChromeResourceDispatcherHostDelegate::CreateLoginDelegate(
net::AuthChallengeInfo* auth_info, net::URLRequest* request) {
std::string instant_header_value;
if (request->extra_request_headers().GetHeader(
InstantLoader::kInstantHeader, &instant_header_value) &&
instant_header_value == InstantLoader::kInstantHeaderValue)
return new InstantResourceDispatcherHostLoginDelegate;
return CreateLoginPrompt(auth_info, request);
}

Expand Down

0 comments on commit b6ea339

Please sign in to comment.