Index: chrome/browser/instant/instant_page.cc |
diff --git a/chrome/browser/instant/instant_page.cc b/chrome/browser/instant/instant_page.cc |
index ba79353ed5b8867e72e8b5452025a50f7f94e4cf..657a9509c80add1f189ff415ba43210bb3632f1a 100644 |
--- a/chrome/browser/instant/instant_page.cc |
+++ b/chrome/browser/instant/instant_page.cc |
@@ -4,261 +4,234 @@ |
#include "chrome/browser/instant/instant_page.h" |
-#include "base/utf_string_conversions.h" |
-#include "chrome/common/render_messages.h" |
+#include "chrome/browser/instant/instant_service.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/common/instant_messages.h" |
+#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/web_contents.h" |
-#include "ui/base/resource/resource_bundle.h" |
-#include "ui/gfx/font.h" |
InstantPage::Delegate::~Delegate() { |
} |
-InstantPage::~InstantPage() { |
-} |
- |
-void InstantPage::Update(const string16& text, |
- size_t selection_start, |
- size_t selection_end, |
- bool verbatim) { |
- Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim, |
- selection_start, selection_end)); |
-} |
- |
-void InstantPage::Submit(const string16& text) { |
- Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); |
+InstantPage::InstantPage(Delegate* delegate, InstantService* service) |
+ : delegate_(delegate), |
+ service_(service), |
+ routing_id_(MSG_ROUTING_NONE), |
+ supports_instant_(false), |
+ navigated_after_change_(false) { |
} |
-void InstantPage::Cancel(const string16& text) { |
- Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text)); |
+InstantPage::~InstantPage() { |
} |
-void InstantPage::SetPopupBounds(const gfx::Rect& bounds) { |
- Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds)); |
+void InstantPage::SetContents(content::WebContents* contents) { |
+ Observe(contents); |
} |
-void InstantPage::SetOmniboxBounds(const gfx::Rect& bounds) { |
- Send(new ChromeViewMsg_SearchBoxMarginChange( |
- routing_id(), bounds.x(), bounds.width())); |
+void InstantPage::DetermineInstantSupport() { |
+ SendMessage(scoped_ptr<IPC::Message>( |
+ new ChromeViewMsg_SearchBoxDetermineInstantSupport(routing_id()))); |
} |
-void InstantPage::InitializeFonts() { |
- // TODO(sail) Remove this once the Mac omnibox font size is updated. |
-#if defined(OS_MACOSX) |
- ui::ResourceBundle::FontStyle font_style = ui::ResourceBundle::BaseFont; |
-#else |
- ui::ResourceBundle::FontStyle font_style = ui::ResourceBundle::MediumFont; |
-#endif |
- const gfx::Font& omnibox_font = |
- ui::ResourceBundle::GetSharedInstance().GetFont(font_style); |
- string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName()); |
- size_t omnibox_font_size = omnibox_font.GetFontSize(); |
- Send(new ChromeViewMsg_SearchBoxFontInformation( |
- routing_id(), omnibox_font_name, omnibox_font_size)); |
+void InstantPage::Change(const string16& query, |
+ bool verbatim, |
+ size_t selection_start, |
+ size_t selection_end) { |
+ navigated_after_change_ = false; |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxChange( |
+ routing_id(), query, verbatim, selection_start, selection_end))); |
} |
-void InstantPage::DetermineIfPageSupportsInstant() { |
- Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
+void InstantPage::Submit(const string16& query) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxSubmit( |
+ routing_id(), query))); |
} |
-void InstantPage::SendAutocompleteResults( |
+void InstantPage::AutocompleteResults( |
const std::vector<InstantAutocompleteResult>& results) { |
- Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); |
-} |
- |
-void InstantPage::UpOrDownKeyPressed(int count) { |
- Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); |
+ SendMessage(scoped_ptr<IPC::Message>( |
+ new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results))); |
} |
-void InstantPage::CancelSelection(const string16& user_text) { |
- Send(new ChromeViewMsg_SearchBoxCancelSelection(routing_id(), user_text)); |
+void InstantPage::Select(int count) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxSelect( |
+ routing_id(), count))); |
} |
-void InstantPage::SendThemeBackgroundInfo( |
- const ThemeBackgroundInfo& theme_info) { |
- Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); |
+void InstantPage::Cancel(const string16& query) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxCancel( |
+ routing_id(), query))); |
} |
-void InstantPage::SetDisplayInstantResults(bool display_instant_results) { |
- Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults( |
- routing_id(), display_instant_results)); |
+void InstantPage::Blur(const string16& query) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxBlur( |
+ routing_id(), query))); |
} |
-void InstantPage::KeyCaptureChanged(bool is_key_capture_enabled) { |
- Send(new ChromeViewMsg_SearchBoxKeyCaptureChanged( |
- routing_id(), is_key_capture_enabled)); |
-} |
- |
-void InstantPage::SendMostVisitedItems( |
- const std::vector<MostVisitedItem>& items) { |
- Send(new ChromeViewMsg_InstantMostVisitedItemsChanged(routing_id(), items)); |
+void InstantPage::PopupBounds(const gfx::Rect& bounds) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxPopupBounds( |
+ routing_id(), bounds))); |
} |
-InstantPage::InstantPage(Delegate* delegate) |
- : delegate_(delegate), |
- supports_instant_(false) { |
+void InstantPage::OmniboxBounds(const gfx::Rect& bounds) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxOmniboxBounds( |
+ routing_id(), bounds))); |
} |
-void InstantPage::SetContents(content::WebContents* contents) { |
- Observe(contents); |
-} |
- |
-bool InstantPage::ShouldProcessRenderViewCreated() { |
- return false; |
-} |
- |
-bool InstantPage::ShouldProcessRenderViewGone() { |
- return false; |
-} |
- |
-bool InstantPage::ShouldProcessAboutToNavigateMainFrame() { |
- return false; |
+void InstantPage::KeyCaptureChanged(bool is_key_capture_enabled) { |
+ SendMessage(scoped_ptr<IPC::Message>( |
+ new ChromeViewMsg_SearchBoxKeyCaptureChanged(routing_id(), |
+ is_key_capture_enabled))); |
} |
-bool InstantPage::ShouldProcessSetSuggestions() { |
- return false; |
+void InstantPage::DisplayInstantResults(bool display_instant_results) { |
+ SendMessage(scoped_ptr<IPC::Message>( |
+ new ChromeViewMsg_SearchBoxDisplayInstantResults( |
+ routing_id(), display_instant_results))); |
} |
-bool InstantPage::ShouldProcessShowInstantOverlay() { |
- return false; |
+void InstantPage::ThemeChanged(const ThemeBackgroundInfo& theme_info) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxThemeChanged( |
+ routing_id(), theme_info))); |
} |
-bool InstantPage::ShouldProcessStartCapturingKeyStrokes() { |
- return false; |
+void InstantPage::FontChanged(const string16& font, size_t font_size) { |
+ SendMessage(scoped_ptr<IPC::Message>(new ChromeViewMsg_SearchBoxFontChanged( |
+ routing_id(), font, font_size))); |
} |
-bool InstantPage::ShouldProcessStopCapturingKeyStrokes() { |
- return false; |
+void InstantPage::MostVisitedItems(const std::vector<MostVisitedItem>& items) { |
+ SendMessage(scoped_ptr<IPC::Message>( |
+ new ChromeViewMsg_SearchBoxMostVisitedItems(routing_id(), items))); |
} |
-bool InstantPage::ShouldProcessNavigateToURL() { |
- return false; |
+void InstantPage::RenderViewGone(base::TerminationStatus /* status */) { |
+ delegate_->RenderViewGone(contents()); |
} |
-void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) { |
- if (ShouldProcessRenderViewCreated()) |
- delegate_->InstantPageRenderViewCreated(contents()); |
+void InstantPage::DidNavigateMainFrame( |
+ const content::LoadCommittedDetails& /* details */, |
+ const content::FrameNavigateParams& /* params */) { |
+ navigated_after_change_ = true; |
+ if (routing_id_ != routing_id()) { |
+ routing_id_ = routing_id(); |
+ delegate_->InitSearchBox(contents()); |
+ } |
} |
void InstantPage::DidFinishLoad( |
- int64 /* frame_id */, |
- const GURL& /* validated_url */, |
- bool is_main_frame, |
- content::RenderViewHost* /* render_view_host */) { |
+ int64 /* frame_id */, |
+ const GURL& /* validated_url */, |
+ bool is_main_frame, |
+ content::RenderViewHost* /* render_view_host */) { |
if (is_main_frame && !supports_instant_) |
- DetermineIfPageSupportsInstant(); |
+ DetermineInstantSupport(); |
} |
bool InstantPage::OnMessageReceived(const IPC::Message& message) { |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(InstantPage, message) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxInstantSupportDetermined, |
OnInstantSupportDetermined) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay, |
- OnShowInstantOverlay) |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StartCapturingKeyStrokes, |
- OnStartCapturingKeyStrokes); |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StopCapturingKeyStrokes, |
- OnStopCapturingKeyStrokes); |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, |
- OnSearchBoxNavigate); |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantDeleteMostVisitedItem, |
- OnDeleteMostVisitedItem); |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantUndoMostVisitedDeletion, |
- OnUndoMostVisitedDeletion); |
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions, |
- OnUndoAllMostVisitedDeletions); |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxSetSuggestion, |
+ OnSetSuggestion) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigateToURL, |
+ OnNavigateToURL) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowOverlay, OnShowOverlay) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxStartKeyCapture, |
+ OnStartKeyCapture) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxStopKeyCapture, |
+ OnStopKeyCapture) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, |
+ OnDeleteMostVisitedItem) |
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedItemDeletion, |
+ OnUndoMostVisitedItemDeletion) |
+ IPC_MESSAGE_HANDLER( |
+ ChromeViewHostMsg_SearchBoxUndoAllMostVisitedItemDeletions, |
+ OnUndoAllMostVisitedItemDeletions) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
} |
-void InstantPage::RenderViewGone(base::TerminationStatus /* status */) { |
- if (ShouldProcessRenderViewGone()) |
- delegate_->InstantPageRenderViewGone(contents()); |
-} |
+void InstantPage::SendMessage(scoped_ptr<IPC::Message> message) { |
+ if (!contents()) |
+ return; |
-void InstantPage::DidCommitProvisionalLoadForFrame( |
- int64 /* frame_id */, |
- bool is_main_frame, |
- const GURL& url, |
- content::PageTransition /* transition_type */, |
- content::RenderViewHost* /* render_view_host */) { |
- if (is_main_frame && ShouldProcessAboutToNavigateMainFrame()) |
- delegate_->InstantPageAboutToNavigateMainFrame(contents(), url); |
-} |
+ content::RenderProcessHost* process = contents()->GetRenderProcessHost(); |
+ if (!process) |
+ return; |
-void InstantPage::OnSetSuggestions( |
- int page_id, |
- const std::vector<InstantSuggestion>& suggestions) { |
- if (contents()->IsActiveEntry(page_id)) { |
- OnInstantSupportDetermined(page_id, true); |
- if (ShouldProcessSetSuggestions()) |
- delegate_->SetSuggestions(contents(), suggestions); |
- } |
+ if (service_->IsInstantProcess(process->GetID())) |
+ Send(message.release()); |
} |
void InstantPage::OnInstantSupportDetermined(int page_id, |
bool supports_instant) { |
- if (!contents()->IsActiveEntry(page_id) || supports_instant_) { |
- // Nothing to do if the page already supports Instant. |
- return; |
+ if (contents()->IsActiveEntry(page_id) && !supports_instant_) { |
+ supports_instant_ = supports_instant; |
+ delegate_->InstantSupportDetermined(contents()); |
} |
+} |
- supports_instant_ = supports_instant; |
- delegate_->InstantSupportDetermined(contents(), supports_instant); |
- |
- // If the page doesn't support Instant, stop listening to it. |
- if (!supports_instant) |
- Observe(NULL); |
+void InstantPage::OnSetSuggestion(int page_id, |
+ const InstantSuggestion& suggestion) { |
+ if (contents()->IsActiveEntry(page_id)) { |
+ OnInstantSupportDetermined(page_id, true); |
+ delegate_->SetSuggestion(contents(), suggestion); |
+ } |
} |
-void InstantPage::OnShowInstantOverlay(int page_id, |
- InstantShownReason reason, |
- int height, |
- InstantSizeUnits units) { |
+void InstantPage::OnNavigateToURL(int page_id, |
+ const GURL& url, |
+ content::PageTransition transition, |
+ WindowOpenDisposition disposition) { |
if (contents()->IsActiveEntry(page_id)) { |
OnInstantSupportDetermined(page_id, true); |
- if (ShouldProcessShowInstantOverlay()) |
- delegate_->ShowInstantOverlay(contents(), reason, height, units); |
+ delegate_->NavigateToURL(contents(), url, transition, disposition); |
} |
} |
-void InstantPage::OnStartCapturingKeyStrokes(int page_id) { |
+void InstantPage::OnShowOverlay(int page_id, |
+ int height, |
+ bool is_height_in_pixels) { |
if (contents()->IsActiveEntry(page_id)) { |
OnInstantSupportDetermined(page_id, true); |
- if (ShouldProcessStartCapturingKeyStrokes()) |
- delegate_->StartCapturingKeyStrokes(contents()); |
+ delegate_->ShowOverlay(contents(), height, is_height_in_pixels); |
} |
} |
-void InstantPage::OnStopCapturingKeyStrokes(int page_id) { |
+void InstantPage::OnStartKeyCapture(int page_id) { |
if (contents()->IsActiveEntry(page_id)) { |
OnInstantSupportDetermined(page_id, true); |
- if (ShouldProcessStopCapturingKeyStrokes()) |
- delegate_->StopCapturingKeyStrokes(contents()); |
+ delegate_->StartKeyCapture(contents()); |
} |
} |
-void InstantPage::OnSearchBoxNavigate(int page_id, |
- const GURL& url, |
- content::PageTransition transition, |
- WindowOpenDisposition disposition) { |
+void InstantPage::OnStopKeyCapture(int page_id) { |
if (contents()->IsActiveEntry(page_id)) { |
OnInstantSupportDetermined(page_id, true); |
- if (ShouldProcessNavigateToURL()) |
- delegate_->NavigateToURL(contents(), url, transition, disposition); |
+ delegate_->StopKeyCapture(contents()); |
} |
} |
-void InstantPage::OnDeleteMostVisitedItem(const GURL& url) { |
- delegate_->DeleteMostVisitedItem(url); |
+void InstantPage::OnDeleteMostVisitedItem(int page_id, const GURL& url) { |
+ if (contents()->IsActiveEntry(page_id)) { |
+ OnInstantSupportDetermined(page_id, true); |
+ delegate_->DeleteMostVisitedItem(contents(), url); |
+ } |
} |
-void InstantPage::OnUndoMostVisitedDeletion(const GURL& url) { |
- delegate_->UndoMostVisitedDeletion(url); |
+void InstantPage::OnUndoMostVisitedItemDeletion(int page_id, const GURL& url) { |
+ if (contents()->IsActiveEntry(page_id)) { |
+ OnInstantSupportDetermined(page_id, true); |
+ delegate_->UndoMostVisitedItemDeletion(contents(), url); |
+ } |
} |
-void InstantPage::OnUndoAllMostVisitedDeletions() { |
- delegate_->UndoAllMostVisitedDeletions(); |
+void InstantPage::OnUndoAllMostVisitedItemDeletions(int page_id) { |
+ if (contents()->IsActiveEntry(page_id)) { |
+ OnInstantSupportDetermined(page_id, true); |
+ delegate_->UndoAllMostVisitedItemDeletions(contents()); |
+ } |
} |