| Index: chrome/browser/instant/instant_overlay.cc
|
| diff --git a/chrome/browser/instant/instant_overlay.cc b/chrome/browser/instant/instant_overlay.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0b7cf3658cf1b3da39fa420702905bd83a427ad1
|
| --- /dev/null
|
| +++ b/chrome/browser/instant/instant_overlay.cc
|
| @@ -0,0 +1,145 @@
|
| +// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/instant/instant_overlay.h"
|
| +
|
| +#include "base/supports_user_data.h"
|
| +#include "chrome/browser/instant/instant_controller.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +
|
| +namespace {
|
| +
|
| +const int kStalePageTimeoutMS = 3 * 3600 * 1000; // 3 hours
|
| +
|
| +int kUserDataKey;
|
| +
|
| +class InstantOverlayUserData : public base::SupportsUserData::Data {
|
| + public:
|
| + explicit InstantOverlayUserData(InstantOverlay* overlay)
|
| + : overlay_(overlay) {}
|
| +
|
| + InstantOverlay* overlay() const { return overlay_; }
|
| +
|
| + private:
|
| + ~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_(new InstantLoader(ALLOW_THIS_IN_INITIALIZER_LIST(this))),
|
| + instant_url_(instant_url),
|
| + is_stale_(false),
|
| + is_pointer_down_from_activate_(false) {
|
| +}
|
| +
|
| +InstantOverlay::~InstantOverlay() {
|
| +}
|
| +
|
| +void InstantOverlay::InitContents(Profile* profile,
|
| + const content::WebContents* active_tab) {
|
| + loader_->Load(GURL(instant_url_), profile, active_tab, kStalePageTimeoutMS);
|
| + api()->SetContents(contents());
|
| + contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
|
| +}
|
| +
|
| +content::WebContents* InstantOverlay::ReleaseContents() {
|
| + api()->SetContents(NULL);
|
| + contents()->RemoveUserData(&kUserDataKey);
|
| + return loader_->ReleaseContents();
|
| +}
|
| +
|
| +void InstantOverlay::DidNavigate(
|
| + const history::HistoryAddPageArgs& add_page_args) {
|
| + last_navigation_ = add_page_args;
|
| +}
|
| +
|
| +bool InstantOverlay::IsUsingLocalPreview() const {
|
| + return instant_url_ == InstantController::kLocalOmniboxPopupURL;
|
| +}
|
| +
|
| +content::WebContents* InstantOverlay::ReplaceAndReleaseContents(
|
| + content::WebContents* new_contents) {
|
| + content::WebContents* old_contents = ReleaseContents();
|
| + loader_->SetContents(new_contents);
|
| + api()->SetContents(new_contents);
|
| + contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this));
|
| + controller_->SwappedOverlayWebContents();
|
| + return old_contents;
|
| +}
|
| +
|
| +void InstantOverlay::OnFocus() {
|
| + // The preview is getting focus. Equivalent to it being clicked.
|
| + bool tmp = is_pointer_down_from_activate_;
|
| + is_pointer_down_from_activate_ = true;
|
| + controller_->InstantOverlayContentsFocused();
|
| + is_pointer_down_from_activate_ = tmp;
|
| +}
|
| +
|
| +bool InstantOverlay::OnOpenURL() {
|
| + // Allow navigation to continue if we can commit the overlay.
|
| + return controller_->CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
|
| +}
|
| +
|
| +void InstantOverlay::SetPointerDown() {
|
| + is_pointer_down_from_activate_ = true;
|
| +}
|
| +
|
| +void InstantOverlay::MaybeCommitFromPointerRelease() {
|
| + if (is_pointer_down_from_activate_) {
|
| + is_pointer_down_from_activate_ = false;
|
| + controller_->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
|
| + }
|
| +}
|
| +
|
| +void InstantOverlay::OnStalePage() {
|
| + is_stale_ = true;
|
| + controller_->OnStaleOverlay();
|
| +}
|
| +
|
| +void InstantOverlay::OnUpdate() {
|
| + last_navigation_ = history::HistoryAddPageArgs();
|
| +}
|
| +
|
| +bool InstantOverlay::OnRenderViewGone() const {
|
| + return true;
|
| +}
|
| +
|
| +bool InstantOverlay::OnAboutToNavigateMainFrame() const {
|
| + return true;
|
| +}
|
| +
|
| +bool InstantOverlay::OnSetSuggestions() const {
|
| + return true;
|
| +}
|
| +
|
| +bool InstantOverlay::OnShowInstantPreview() const {
|
| + return true;
|
| +}
|
| +
|
| +bool InstantOverlay::OnStartCapturingKeyStrokes() const {
|
| + return true;
|
| +}
|
| +
|
| +bool InstantOverlay::OnStopCapturingKeyStrokes() const {
|
| + return true;
|
| +}
|
| +
|
| +bool InstantOverlay::OnNavigateToURL() const {
|
| + return true;
|
| +}
|
|
|