| Index: chrome/browser/instant/instant_overlay.cc
|
| diff --git a/chrome/browser/instant/instant_overlay.cc b/chrome/browser/instant/instant_overlay.cc
|
| index 33b803e1a98746ff4b70cf8bf9bd518e84989218..d7492ef9e532ec1cc1119f56ec78ee1cc7c24f0c 100644
|
| --- a/chrome/browser/instant/instant_overlay.cc
|
| +++ b/chrome/browser/instant/instant_overlay.cc
|
| @@ -5,167 +5,88 @@
|
| #include "chrome/browser/instant/instant_overlay.h"
|
|
|
| #include "base/auto_reset.h"
|
| -#include "base/supports_user_data.h"
|
| -#include "chrome/browser/instant/search.h"
|
| +#include "chrome/browser/instant/instant_controller.h"
|
| #include "content/public/browser/web_contents.h"
|
|
|
| -namespace {
|
| -
|
| -int kUserDataKey;
|
| -
|
| -class InstantOverlayUserData : public base::SupportsUserData::Data {
|
| - public:
|
| - explicit InstantOverlayUserData(InstantOverlay* overlay)
|
| - : overlay_(overlay) {}
|
| -
|
| - virtual InstantOverlay* overlay() const { return overlay_; }
|
| -
|
| - private:
|
| - virtual ~InstantOverlayUserData() {}
|
| -
|
| - InstantOverlay* const overlay_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(InstantOverlayUserData);
|
| -};
|
| -
|
| -} // namespace
|
| -
|
| -// static
|
| -InstantOverlay* InstantOverlay::FromWebContents(
|
| - const content::WebContents* web_contents) {
|
| - InstantOverlayUserData* data = static_cast<InstantOverlayUserData*>(
|
| - web_contents->GetUserData(&kUserDataKey));
|
| - return data ? data->overlay() : NULL;
|
| -}
|
| -
|
| InstantOverlay::InstantOverlay(InstantController* controller,
|
| - const std::string& instant_url)
|
| - : InstantPage(controller),
|
| - loader_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| - instant_url_(instant_url),
|
| - is_stale_(false),
|
| + InstantService* service,
|
| + scoped_ptr<content::WebContents> contents)
|
| + : InstantWebContentsContainer(controller, service),
|
| + controller_(controller),
|
| is_pointer_down_from_activate_(false) {
|
| + contents_ = contents.Pass();
|
| + SetUpContents();
|
| + page_.set_supports_instant(true);
|
| }
|
|
|
| InstantOverlay::~InstantOverlay() {
|
| }
|
|
|
| -void InstantOverlay::InitContents(Profile* profile,
|
| - const content::WebContents* active_tab) {
|
| - loader_.Init(GURL(instant_url_), profile, active_tab,
|
| - base::Bind(&InstantOverlay::HandleStalePage,
|
| - base::Unretained(this)));
|
| - SetContents(loader_.contents());
|
| - contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
|
| - loader_.Load();
|
| -}
|
| -
|
| scoped_ptr<content::WebContents> InstantOverlay::ReleaseContents() {
|
| - contents()->RemoveUserData(&kUserDataKey);
|
| - SetContents(NULL);
|
| - return loader_.ReleaseContents();
|
| -}
|
| -
|
| -void InstantOverlay::DidNavigate(
|
| - const history::HistoryAddPageArgs& add_page_args) {
|
| - last_navigation_ = add_page_args;
|
| + TearDownContents();
|
| + return contents_.Pass();
|
| }
|
|
|
| -bool InstantOverlay::IsUsingLocalOverlay() const {
|
| - return instant_url_ == chrome::search::kLocalOmniboxPopupURL;
|
| +void InstantOverlay::SwapTabContents(content::WebContents* old_contents,
|
| + content::WebContents* new_contents) {
|
| + InstantWebContentsContainer::SwapTabContents(old_contents, new_contents);
|
| + controller_->SwappedOverlayContents();
|
| }
|
|
|
| -void InstantOverlay::Update(const string16& text,
|
| - size_t selection_start,
|
| - size_t selection_end,
|
| - bool verbatim) {
|
| - last_navigation_ = history::HistoryAddPageArgs();
|
| - InstantPage::Update(text, selection_start, selection_end, verbatim);
|
| -}
|
| -
|
| -bool InstantOverlay::ShouldProcessRenderViewCreated() {
|
| - return true;
|
| -}
|
| -
|
| -bool InstantOverlay::ShouldProcessRenderViewGone() {
|
| - return true;
|
| -}
|
| -
|
| -bool InstantOverlay::ShouldProcessAboutToNavigateMainFrame() {
|
| - return true;
|
| -}
|
| +content::WebContents* InstantOverlay::OpenURLFromTab(
|
| + content::WebContents* source,
|
| + const content::OpenURLParams& params) {
|
| + if (!page_.supports_instant())
|
| + return InstantWebContentsContainer::OpenURLFromTab(source, params);
|
|
|
| -bool InstantOverlay::ShouldProcessSetSuggestions() {
|
| - return true;
|
| -}
|
| + // Allow the navigation to continue if we are able to commit the overlay.
|
| + //
|
| + // Cache the overlay contents since committing it will cause the contents
|
| + // to be released (and be set to NULL).
|
| + content::WebContents* overlay = contents();
|
| + if (controller_->CommitIfPossible(INSTANT_COMMIT_NAVIGATED)) {
|
| + // If the commit was successful, the overlay's delegate should be the tab
|
| + // strip, which will be able to handle the navigation.
|
| + DCHECK_NE(this, overlay->GetDelegate());
|
| + return overlay->GetDelegate()->OpenURLFromTab(source, params);
|
| + }
|
|
|
| -bool InstantOverlay::ShouldProcessShowInstantOverlay() {
|
| - return true;
|
| + return NULL;
|
| }
|
|
|
| -bool InstantOverlay::ShouldProcessNavigateToURL() {
|
| - return true;
|
| +void InstantOverlay::CloseContents(content::WebContents* /* source */) {
|
| + controller_->RenderViewGone(contents());
|
| }
|
|
|
| -void InstantOverlay::OnSwappedContents() {
|
| - contents()->RemoveUserData(&kUserDataKey);
|
| - SetContents(loader_.contents());
|
| - contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
|
| - instant_controller()->SwappedOverlayContents();
|
| +void InstantOverlay::LostCapture() {
|
| + HandleMouseUp();
|
| }
|
|
|
| -void InstantOverlay::OnFocus() {
|
| +void InstantOverlay::WebContentsFocused(content::WebContents* /* contents */) {
|
| // The overlay is getting focus. Equivalent to it being clicked.
|
| base::AutoReset<bool> reset(&is_pointer_down_from_activate_, true);
|
| - instant_controller()->FocusedOverlayContents();
|
| + controller_->FocusedOverlayContents();
|
| }
|
|
|
| -void InstantOverlay::OnMouseDown() {
|
| +void InstantOverlay::HandleMouseDown() {
|
| is_pointer_down_from_activate_ = true;
|
| }
|
|
|
| -void InstantOverlay::OnMouseUp() {
|
| +void InstantOverlay::HandleMouseUp() {
|
| if (is_pointer_down_from_activate_) {
|
| is_pointer_down_from_activate_ = false;
|
| - instant_controller()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
|
| + controller_->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
|
| }
|
| }
|
|
|
| -content::WebContents* InstantOverlay::OpenURLFromTab(
|
| - content::WebContents* source,
|
| - const content::OpenURLParams& params) {
|
| - if (!supports_instant()) {
|
| - // If the page doesn't yet support Instant, it hasn't fully loaded.
|
| - // This is a redirect that we should allow. http://crbug.com/177948
|
| - content::NavigationController::LoadURLParams load_params(params.url);
|
| - load_params.transition_type = params.transition;
|
| - load_params.referrer = params.referrer;
|
| - load_params.extra_headers = params.extra_headers;
|
| - load_params.is_renderer_initiated = params.is_renderer_initiated;
|
| - load_params.transferred_global_request_id =
|
| - params.transferred_global_request_id;
|
| - load_params.is_cross_site_redirect = params.is_cross_site_redirect;
|
| -
|
| - contents()->GetController().LoadURLWithParams(load_params);
|
| - return contents();
|
| - }
|
| +void InstantOverlay::HandlePointerActivate() {
|
| + HandleMouseDown();
|
| +}
|
|
|
| - // We will allow the navigate to continue if we are able to commit the
|
| - // overlay.
|
| - //
|
| - // First, cache the overlay contents since committing it will cause the
|
| - // contents to be released (and be set to NULL).
|
| - content::WebContents* overlay = contents();
|
| - if (instant_controller()->CommitIfPossible(INSTANT_COMMIT_NAVIGATED)) {
|
| - // If the commit was successful, the overlay's delegate should be the tab
|
| - // strip, which will be able to handle the navigation.
|
| - DCHECK_NE(&loader_, overlay->GetDelegate());
|
| - return overlay->GetDelegate()->OpenURLFromTab(source, params);
|
| - }
|
| - return NULL;
|
| +void InstantOverlay::HandleGestureEnd() {
|
| + HandleMouseUp();
|
| }
|
|
|
| -void InstantOverlay::HandleStalePage() {
|
| - is_stale_ = true;
|
| - instant_controller()->ReloadOverlayIfStale();
|
| +void InstantOverlay::DragEnded() {
|
| + HandleMouseUp();
|
| }
|
|
|