Chromium Code Reviews| Index: chrome/browser/instant/instant_overlay.cc |
| diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_overlay.cc |
| similarity index 67% |
| rename from chrome/browser/instant/instant_loader.cc |
| rename to chrome/browser/instant/instant_overlay.cc |
| index c6e6874e5473509f431f41f34e479e93a1524e95..71986b413a6907e7cf8515f0f80f6942a3f00b5b 100644 |
| --- a/chrome/browser/instant/instant_loader.cc |
| +++ b/chrome/browser/instant/instant_overlay.cc |
| @@ -2,7 +2,7 @@ |
| // 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_loader.h" |
| +#include "chrome/browser/instant/instant_overlay.h" |
| #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
| @@ -10,47 +10,49 @@ |
| #include "chrome/browser/history/history_tab_helper.h" |
| #include "chrome/browser/instant/instant_controller.h" |
| #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
| +#include "chrome/browser/tab_contents/tab_util.h" |
| #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
| #include "chrome/browser/ui/search/search_tab_helper.h" |
| #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" |
| #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| #include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h" |
| +#include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents_delegate.h" |
| #include "content/public/browser/web_contents_view.h" |
| -#include "ipc/ipc_message.h" |
| namespace { |
| int kUserDataKey; |
| -class InstantLoaderUserData : public base::SupportsUserData::Data { |
| +class InstantOverlayUserData : public base::SupportsUserData::Data { |
| public: |
| - explicit InstantLoaderUserData(InstantLoader* loader) : loader_(loader) {} |
| + explicit InstantOverlayUserData(InstantOverlay* overlay) |
| + : overlay_(overlay) {} |
| - InstantLoader* loader() const { return loader_; } |
| + InstantOverlay* overlay() const { return overlay_; } |
| private: |
| - ~InstantLoaderUserData() {} |
| + ~InstantOverlayUserData() {} |
| - InstantLoader* const loader_; |
| + InstantOverlay* const overlay_; |
| - DISALLOW_COPY_AND_ASSIGN(InstantLoaderUserData); |
| + DISALLOW_COPY_AND_ASSIGN(InstantOverlayUserData); |
| }; |
| -} |
| +} // namespace |
| // WebContentsDelegateImpl ----------------------------------------------------- |
| -class InstantLoader::WebContentsDelegateImpl |
| +class InstantOverlay::WebContentsDelegateImpl |
| : public WebContentsModalDialogManagerDelegate, |
| public CoreTabHelperDelegate, |
| public content::WebContentsDelegate { |
| public: |
| - explicit WebContentsDelegateImpl(InstantLoader* loader); |
| + explicit WebContentsDelegateImpl(InstantOverlay* overlay); |
| private: |
| // Overridden from WebContentsModalDialogManagerDelegate: |
| @@ -80,17 +82,17 @@ class InstantLoader::WebContentsDelegateImpl |
| void MaybeCommitFromPointerRelease(); |
| - InstantLoader* const loader_; |
| + InstantOverlay* const overlay_; |
| DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl); |
| }; |
| -InstantLoader::WebContentsDelegateImpl::WebContentsDelegateImpl( |
| - InstantLoader* loader) |
| - : loader_(loader) { |
| +InstantOverlay::WebContentsDelegateImpl::WebContentsDelegateImpl( |
| + InstantOverlay* overlay) |
| + : overlay_(overlay) { |
| } |
| -bool InstantLoader::WebContentsDelegateImpl::ShouldFocusWebContentsModalDialog( |
| +bool InstantOverlay::WebContentsDelegateImpl::ShouldFocusWebContentsModalDialog( |
| ) { |
| // Return false so that web contents modal dialogs are not initially |
| // focused. If we did otherwise the preview would prematurely get committed |
| @@ -98,37 +100,37 @@ bool InstantLoader::WebContentsDelegateImpl::ShouldFocusWebContentsModalDialog( |
| return false; |
| } |
| -void InstantLoader::WebContentsDelegateImpl::SwapTabContents( |
| +void InstantOverlay::WebContentsDelegateImpl::SwapTabContents( |
| content::WebContents* old_contents, |
| content::WebContents* new_contents) { |
| - // If this is being called, something is swapping in to loader's |contents_| |
| + // If this is being called, something is swapping in to overlay's |contents_| |
| // before we've added it to the tab strip. |
| - loader_->ReplacePreviewContents(old_contents, new_contents); |
| + overlay_->ReplacePreviewContents(old_contents, new_contents); |
| } |
| -bool InstantLoader::WebContentsDelegateImpl::ShouldSuppressDialogs() { |
| +bool InstantOverlay::WebContentsDelegateImpl::ShouldSuppressDialogs() { |
| // Any message shown during Instant cancels Instant, so we suppress them. |
| return true; |
| } |
| -bool InstantLoader::WebContentsDelegateImpl::ShouldFocusPageAfterCrash() { |
| +bool InstantOverlay::WebContentsDelegateImpl::ShouldFocusPageAfterCrash() { |
| return false; |
| } |
| -void InstantLoader::WebContentsDelegateImpl::LostCapture() { |
| +void InstantOverlay::WebContentsDelegateImpl::LostCapture() { |
| MaybeCommitFromPointerRelease(); |
| } |
| -void InstantLoader::WebContentsDelegateImpl::WebContentsFocused( |
| +void InstantOverlay::WebContentsDelegateImpl::WebContentsFocused( |
| content::WebContents* /* contents */) { |
| // The preview is getting focus. Equivalent to it being clicked. |
| - bool tmp = loader_->is_pointer_down_from_activate_; |
| - loader_->is_pointer_down_from_activate_ = true; |
| - loader_->controller_->InstantLoaderContentsFocused(); |
| - loader_->is_pointer_down_from_activate_ = tmp; |
| + bool tmp = overlay_->is_pointer_down_from_activate_; |
| + overlay_->is_pointer_down_from_activate_ = true; |
| + overlay_->controller_->InstantOverlayContentsFocused(); |
| + overlay_->is_pointer_down_from_activate_ = tmp; |
| } |
| -bool InstantLoader::WebContentsDelegateImpl::CanDownload( |
| +bool InstantOverlay::WebContentsDelegateImpl::CanDownload( |
| content::RenderViewHost* /* render_view_host */, |
| int /* request_id */, |
| const std::string& /* request_method */) { |
| @@ -136,60 +138,60 @@ bool InstantLoader::WebContentsDelegateImpl::CanDownload( |
| return false; |
| } |
| -void InstantLoader::WebContentsDelegateImpl::HandleMouseDown() { |
| - loader_->is_pointer_down_from_activate_ = true; |
| +void InstantOverlay::WebContentsDelegateImpl::HandleMouseDown() { |
| + overlay_->is_pointer_down_from_activate_ = true; |
| } |
| -void InstantLoader::WebContentsDelegateImpl::HandleMouseUp() { |
| +void InstantOverlay::WebContentsDelegateImpl::HandleMouseUp() { |
| MaybeCommitFromPointerRelease(); |
| } |
| -void InstantLoader::WebContentsDelegateImpl::HandlePointerActivate() { |
| - loader_->is_pointer_down_from_activate_ = true; |
| +void InstantOverlay::WebContentsDelegateImpl::HandlePointerActivate() { |
| + overlay_->is_pointer_down_from_activate_ = true; |
| } |
| -void InstantLoader::WebContentsDelegateImpl::HandleGestureEnd() { |
| +void InstantOverlay::WebContentsDelegateImpl::HandleGestureEnd() { |
| MaybeCommitFromPointerRelease(); |
| } |
| -void InstantLoader::WebContentsDelegateImpl::DragEnded() { |
| +void InstantOverlay::WebContentsDelegateImpl::DragEnded() { |
| // If the user drags, we won't get a mouse up (at least on Linux). Commit the |
| // Instant result when the drag ends, so that during the drag the page won't |
| // move around. |
| MaybeCommitFromPointerRelease(); |
| } |
| -bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) { |
| +bool InstantOverlay::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) { |
| return false; |
| } |
| -content::WebContents* InstantLoader::WebContentsDelegateImpl::OpenURLFromTab( |
| +content::WebContents* InstantOverlay::WebContentsDelegateImpl::OpenURLFromTab( |
| content::WebContents* source, |
| const content::OpenURLParams& params) { |
| - content::WebContents* preview = loader_->contents_.get(); |
| - if (loader_->controller_->CommitIfPossible(INSTANT_COMMIT_NAVIGATED)) |
| + content::WebContents* preview = overlay_->contents_.get(); |
| + if (overlay_->controller_->CommitIfPossible(INSTANT_COMMIT_NAVIGATED)) |
| return preview->GetDelegate()->OpenURLFromTab(source, params); |
| return NULL; |
| } |
| -void InstantLoader::WebContentsDelegateImpl::MaybeCommitFromPointerRelease() { |
| - if (loader_->is_pointer_down_from_activate_) { |
| - loader_->is_pointer_down_from_activate_ = false; |
| - loader_->controller_->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| +void InstantOverlay::WebContentsDelegateImpl::MaybeCommitFromPointerRelease() { |
| + if (overlay_->is_pointer_down_from_activate_) { |
| + overlay_->is_pointer_down_from_activate_ = false; |
| + overlay_->controller_->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| } |
| } |
| -// InstantLoader --------------------------------------------------------------- |
| +// InstantOverlay ------------------------------------------------------------- |
| // static |
| -InstantLoader* InstantLoader::FromWebContents( |
| +InstantOverlay* InstantOverlay::FromWebContents( |
| const content::WebContents* web_contents) { |
| - InstantLoaderUserData* data = static_cast<InstantLoaderUserData*>( |
| + InstantOverlayUserData* data = static_cast<InstantOverlayUserData*>( |
| web_contents->GetUserData(&kUserDataKey)); |
| - return data ? data->loader() : NULL; |
| + return data ? data->overlay() : NULL; |
| } |
| -InstantLoader::InstantLoader(InstantController* controller, |
| +InstantOverlay::InstantOverlay(InstantController* controller, |
| const std::string& instant_url) |
| : client_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| controller_(controller), |
| @@ -200,17 +202,18 @@ InstantLoader::InstantLoader(InstantController* controller, |
| is_pointer_down_from_activate_(false) { |
| } |
| -InstantLoader::~InstantLoader() { |
| +InstantOverlay::~InstantOverlay() { |
| } |
| -void InstantLoader::InitContents(const content::WebContents* active_tab) { |
| +void InstantOverlay::InitContents(Profile* profile, |
| + const content::WebContents* active_tab) { |
|
Jered
2013/01/10 15:53:54
reindent
samarth
2013/01/11 19:43:05
Done.
|
| content::WebContents::CreateParams create_params( |
| - active_tab->GetBrowserContext()); |
| + profile, |
| + tab_util::GetSiteInstanceForNewTab(profile, GURL(instant_url_))); |
| if (active_tab) |
| create_params.initial_size = active_tab->GetView()->GetContainerSize(); |
| - contents_.reset(content::WebContents::CreateWithSessionStorage( |
| - create_params, |
| - active_tab->GetController().GetSessionStorageNamespaceMap())); |
| + |
| + contents_.reset(content::WebContents::Create(create_params)); |
| SetupPreviewContents(); |
| // This HTTP header and value are set on loads that originate from Instant. |
| @@ -221,21 +224,21 @@ void InstantLoader::InitContents(const content::WebContents* active_tab) { |
| contents_->WasHidden(); |
| } |
| -content::WebContents* InstantLoader::ReleaseContents() { |
| +content::WebContents* InstantOverlay::ReleaseContents() { |
| CleanupPreviewContents(); |
| return contents_.release(); |
| } |
| -void InstantLoader::DidNavigate( |
| +void InstantOverlay::DidNavigate( |
| const history::HistoryAddPageArgs& add_page_args) { |
| last_navigation_ = add_page_args; |
| } |
| -bool InstantLoader::IsUsingLocalPreview() const { |
| +bool InstantOverlay::IsUsingLocalPreview() const { |
| return instant_url_ == InstantController::kLocalOmniboxPopupURL; |
| } |
| -void InstantLoader::Update(const string16& text, |
| +void InstantOverlay::Update(const string16& text, |
| size_t selection_start, |
| size_t selection_end, |
| bool verbatim) { |
| @@ -243,59 +246,59 @@ void InstantLoader::Update(const string16& text, |
| client_.Update(text, selection_start, selection_end, verbatim); |
| } |
| -void InstantLoader::Submit(const string16& text) { |
| +void InstantOverlay::Submit(const string16& text) { |
| client_.Submit(text); |
| } |
| -void InstantLoader::Cancel(const string16& text) { |
| +void InstantOverlay::Cancel(const string16& text) { |
| client_.Cancel(text); |
| } |
| -void InstantLoader::SetPopupBounds(const gfx::Rect& bounds) { |
| +void InstantOverlay::SetPopupBounds(const gfx::Rect& bounds) { |
| client_.SetPopupBounds(bounds); |
| } |
| -void InstantLoader::SetMarginSize(int start, int end) { |
| +void InstantOverlay::SetMarginSize(int start, int end) { |
| client_.SetMarginSize(start, end); |
| } |
| -void InstantLoader::SendAutocompleteResults( |
| +void InstantOverlay::SendAutocompleteResults( |
| const std::vector<InstantAutocompleteResult>& results) { |
| client_.SendAutocompleteResults(results); |
| } |
| -void InstantLoader::UpOrDownKeyPressed(int count) { |
| +void InstantOverlay::UpOrDownKeyPressed(int count) { |
| client_.UpOrDownKeyPressed(count); |
| } |
| -void InstantLoader::SearchModeChanged(const chrome::search::Mode& mode) { |
| +void InstantOverlay::SearchModeChanged(const chrome::search::Mode& mode) { |
| client_.SearchModeChanged(mode); |
| } |
| -void InstantLoader::SendThemeBackgroundInfo( |
| +void InstantOverlay::SendThemeBackgroundInfo( |
| const ThemeBackgroundInfo& theme_info) { |
| client_.SendThemeBackgroundInfo(theme_info); |
| } |
| -void InstantLoader::SendThemeAreaHeight(int height) { |
| +void InstantOverlay::SendThemeAreaHeight(int height) { |
| client_.SendThemeAreaHeight(height); |
| } |
| -void InstantLoader::SetDisplayInstantResults(bool display_instant_results) { |
| +void InstantOverlay::SetDisplayInstantResults(bool display_instant_results) { |
| client_.SetDisplayInstantResults(display_instant_results); |
| } |
| -void InstantLoader::KeyCaptureChanged(bool is_key_capture_enabled) { |
| +void InstantOverlay::KeyCaptureChanged(bool is_key_capture_enabled) { |
| client_.KeyCaptureChanged(is_key_capture_enabled); |
| } |
| -void InstantLoader::SetSuggestions( |
| +void InstantOverlay::SetSuggestions( |
| const std::vector<InstantSuggestion>& suggestions) { |
| InstantSupportDetermined(true); |
| controller_->SetSuggestions(contents(), suggestions); |
| } |
| -void InstantLoader::InstantSupportDetermined(bool supports_instant) { |
| +void InstantOverlay::InstantSupportDetermined(bool supports_instant) { |
| // If we had already determined that the page supports Instant, nothing to do. |
| if (supports_instant_) |
| return; |
| @@ -304,38 +307,38 @@ void InstantLoader::InstantSupportDetermined(bool supports_instant) { |
| controller_->InstantSupportDetermined(contents(), supports_instant); |
| } |
| -void InstantLoader::ShowInstantPreview(InstantShownReason reason, |
| +void InstantOverlay::ShowInstantPreview(InstantShownReason reason, |
| int height, |
| InstantSizeUnits units) { |
| InstantSupportDetermined(true); |
| controller_->ShowInstantPreview(reason, height, units); |
| } |
| -void InstantLoader::StartCapturingKeyStrokes() { |
| +void InstantOverlay::StartCapturingKeyStrokes() { |
| InstantSupportDetermined(true); |
| - controller_->StartCapturingKeyStrokes(); |
| + controller_->StartCapturingKeyStrokes(contents()); |
| } |
| -void InstantLoader::StopCapturingKeyStrokes() { |
| +void InstantOverlay::StopCapturingKeyStrokes() { |
| InstantSupportDetermined(true); |
| - controller_->StopCapturingKeyStrokes(); |
| + controller_->StopCapturingKeyStrokes(contents()); |
| } |
| -void InstantLoader::RenderViewGone() { |
| - controller_->InstantLoaderRenderViewGone(); |
| +void InstantOverlay::RenderViewGone() { |
| + controller_->InstantOverlayRenderViewGone(); |
| } |
| -void InstantLoader::AboutToNavigateMainFrame(const GURL& url) { |
| - controller_->InstantLoaderAboutToNavigateMainFrame(url); |
| +void InstantOverlay::AboutToNavigateMainFrame(const GURL& url) { |
| + controller_->InstantOverlayAboutToNavigateMainFrame(url); |
| } |
| -void InstantLoader::NavigateToURL(const GURL& url, |
| +void InstantOverlay::NavigateToURL(const GURL& url, |
| content::PageTransition transition) { |
| InstantSupportDetermined(true); |
| controller_->NavigateToURL(url, transition); |
| } |
| -void InstantLoader::Observe(int type, |
| +void InstantOverlay::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| #if defined(OS_MACOSX) |
| @@ -349,9 +352,9 @@ void InstantLoader::Observe(int type, |
| #endif |
| } |
| -void InstantLoader::SetupPreviewContents() { |
| +void InstantOverlay::SetupPreviewContents() { |
| client_.SetContents(contents()); |
| - contents_->SetUserData(&kUserDataKey, new InstantLoaderUserData(this)); |
| + contents_->SetUserData(&kUserDataKey, new InstantOverlayUserData(this)); |
| contents_->SetDelegate(delegate_.get()); |
| // Set up various tab helpers. The rest will get attached when (if) the |
| @@ -399,7 +402,7 @@ void InstantLoader::SetupPreviewContents() { |
| #endif |
| } |
| -void InstantLoader::CleanupPreviewContents() { |
| +void InstantOverlay::CleanupPreviewContents() { |
| client_.SetContents(NULL); |
| contents_->RemoveUserData(&kUserDataKey); |
| contents_->SetDelegate(NULL); |
| @@ -426,7 +429,7 @@ void InstantLoader::CleanupPreviewContents() { |
| #endif |
| } |
| -void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents, |
| +void InstantOverlay::ReplacePreviewContents(content::WebContents* old_contents, |
| content::WebContents* new_contents) { |
| DCHECK_EQ(old_contents, contents()); |
| CleanupPreviewContents(); |
| @@ -435,5 +438,5 @@ void InstantLoader::ReplacePreviewContents(content::WebContents* old_contents, |
| ignore_result(contents_.release()); |
| contents_.reset(new_contents); |
| SetupPreviewContents(); |
| - controller_->SwappedWebContents(); |
| + controller_->SwappedOverlayWebContents(); |
| } |