Chromium Code Reviews| Index: chrome/browser/instant/instant_loader.cc |
| =================================================================== |
| --- chrome/browser/instant/instant_loader.cc (revision 158566) |
| +++ chrome/browser/instant/instant_loader.cc (working copy) |
| @@ -5,7 +5,6 @@ |
| #include "chrome/browser/instant/instant_loader.h" |
| #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| -#include "chrome/browser/history/history_types.h" |
| #include "chrome/browser/instant/instant_loader_delegate.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| @@ -24,6 +23,24 @@ |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_delegate.h" |
| +namespace { |
| + |
| +static int kUserDataKey; |
|
sreeram
2012/09/25 22:51:48
I don't think static adds any value, since this is
|
| + |
| +class InstantLoaderUserData : public base::SupportsUserData::Data { |
| + public: |
| + explicit InstantLoaderUserData(InstantLoader* loader) : loader_(loader) {} |
| + virtual ~InstantLoaderUserData() {} |
| + |
| + InstantLoader* loader() const { return loader_; } |
| + |
| + private: |
| + InstantLoader* loader_; |
| + DISALLOW_COPY_AND_ASSIGN(InstantLoaderUserData); |
|
sreeram
2012/09/25 22:51:48
This (and line 109) could instead be DISALLOW_IMPL
|
| +}; |
| + |
| +} |
| + |
| // WebContentsDelegateImpl ----------------------------------------------------- |
| class InstantLoader::WebContentsDelegateImpl |
| @@ -59,9 +76,6 @@ |
| virtual void HandleGestureEnd() OVERRIDE; |
| virtual void DragEnded() OVERRIDE; |
| virtual bool OnGoToEntryOffset(int offset) OVERRIDE; |
| - virtual bool ShouldAddNavigationToHistory( |
| - const history::HistoryAddPageArgs& add_page_args, |
| - content::NavigationType navigation_type) OVERRIDE; |
| // content::WebContentsObserver: |
| virtual void DidFinishLoad( |
| @@ -169,13 +183,6 @@ |
| return false; |
| } |
| -bool InstantLoader::WebContentsDelegateImpl::ShouldAddNavigationToHistory( |
| - const history::HistoryAddPageArgs& add_page_args, |
| - content::NavigationType navigation_type) { |
| - loader_->last_navigation_ = add_page_args; |
| - return false; |
| -} |
| - |
| void InstantLoader::WebContentsDelegateImpl::DidFinishLoad( |
| int64 frame_id, |
| const GURL& validated_url, |
| @@ -281,6 +288,14 @@ |
| // InstantLoader --------------------------------------------------------------- |
| +// static |
| +InstantLoader* InstantLoader::FromWebContents( |
| + content::WebContents* web_contents) { |
| + InstantLoaderUserData* data = static_cast<InstantLoaderUserData*>( |
| + web_contents->GetUserData(&kUserDataKey)); |
| + return data ? data->loader() : NULL; |
| +} |
| + |
| InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, |
| const std::string& instant_url, |
| const TabContents* tab_contents) |
| @@ -340,6 +355,11 @@ |
| count)); |
| } |
| +void InstantLoader::DidNavigate( |
| + const history::HistoryAddPageArgs& add_page_args) { |
| + last_navigation_ = add_page_args; |
| +} |
| + |
| TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type, |
| const string16& text) { |
| content::RenderViewHost* rvh = |
| @@ -349,6 +369,7 @@ |
| else |
| rvh->Send(new ChromeViewMsg_SearchBoxCancel(rvh->GetRoutingID(), text)); |
| CleanupPreviewContents(); |
| + preview_contents_->web_contents()->RemoveUserData(&kUserDataKey); |
| return preview_contents_.release(); |
| } |
| @@ -372,6 +393,7 @@ |
| void InstantLoader::SetupPreviewContents() { |
| content::WebContents* new_contents = preview_contents_->web_contents(); |
| + new_contents->SetUserData(&kUserDataKey, new InstantLoaderUserData(this)); |
| preview_delegate_.reset(new WebContentsDelegateImpl(this)); |
| WebContentsDelegateImpl* new_delegate = preview_delegate_.get(); |
| new_contents->SetDelegate(new_delegate); |