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..8e326a94b17f80b963de953f1bccbcbdddaa656c |
--- /dev/null |
+++ b/chrome/browser/instant/instant_overlay.cc |
@@ -0,0 +1,121 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
dhollowa
2013/01/22 22:34:58
nit: 2013
|
+// 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 |
dhollowa
2013/01/22 22:34:58
DRY violation. Move to instant_page.h?
samarth
2013/01/25 21:08:40
I was leaving open the possibility that ntp and ov
|
+ |
+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(InstantPage::Delegate* delegate, |
+ const std::string& instant_url) |
+ : InstantPage(delegate), |
+ 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); |
+ SetContents(loader_->contents()); |
+ contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this)); |
+} |
+ |
+content::WebContents* InstantOverlay::ReleaseContents() { |
+ 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; |
+} |
+ |
+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); |
+} |
+ |
+content::WebContents* InstantOverlay::ReplaceAndReleaseContents( |
+ content::WebContents* new_contents) { |
+ content::WebContents* old_contents = ReleaseContents(); |
+ loader_->SetContents(new_contents); |
+ SetContents(new_contents); |
+ contents()->SetUserData(&kUserDataKey, new InstantOverlayUserData(this)); |
+ delegate()->InstantPageSwappedContents(new_contents); |
+ 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; |
+ delegate()->InstantPageFocused(contents()); |
+ is_pointer_down_from_activate_ = tmp; |
+} |
+ |
+bool InstantOverlay::OnOpenURL() { |
+ // The delegate determines if this navigation can continue. |
+ return delegate()->InstantPageAboutToOpenURL(contents()); |
+} |
+ |
+void InstantOverlay::OnPointerDown() { |
+ is_pointer_down_from_activate_ = true; |
+} |
+ |
+void InstantOverlay::OnPointerRelease() { |
+ if (is_pointer_down_from_activate_) { |
+ is_pointer_down_from_activate_ = false; |
+ delegate()->InstantPageClicked(contents()); |
+ } |
+} |
+ |
+void InstantOverlay::OnStalePage() { |
+ is_stale_ = true; |
+ delegate()->OnStalePage(contents()); |
+} |