Chromium Code Reviews| Index: chrome/browser/ui/search/search_ipc_router.cc |
| diff --git a/chrome/browser/ui/search/search_ipc_router.cc b/chrome/browser/ui/search/search_ipc_router.cc |
| index 593aed70406ba9844a826d7f5a6f1915531539d4..5cc609b5b2bee8f615d2ea191cf6da35ba514fe1 100644 |
| --- a/chrome/browser/ui/search/search_ipc_router.cc |
| +++ b/chrome/browser/ui/search/search_ipc_router.cc |
| @@ -11,7 +11,34 @@ |
| #include "chrome/common/render_messages.h" |
| #include "components/search/search.h" |
| #include "content/public/browser/navigation_details.h" |
| +#include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/common/associated_interface_provider.h" |
| + |
| +namespace { |
| + |
| +class SearchBoxClientFactoryImpl |
| + : public SearchIPCRouter::SearchBoxClientFactory { |
| + public: |
| + // The |web_contents| must outlive this object. |
| + SearchBoxClientFactoryImpl(content::WebContents* web_contents) |
| + : web_contents_(web_contents) {} |
| + chrome::mojom::SearchBox* GetSearchBox() override; |
| + |
| + private: |
| + content::WebContents* web_contents_; |
| + chrome::mojom::SearchBoxAssociatedPtr search_box_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SearchBoxClientFactoryImpl); |
| +}; |
| + |
| +chrome::mojom::SearchBox* SearchBoxClientFactoryImpl::GetSearchBox() { |
| + web_contents_->GetMainFrame()->GetRemoteAssociatedInterfaces()->GetInterface( |
| + &search_box_); |
|
Marc Treib
2016/10/13 09:04:50
Does this need to happen on every GetSearchBox cal
tibell
2016/10/13 23:29:44
Done.
|
| + return search_box_.get(); |
| +} |
| + |
| +} // namespace |
| SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, |
| Delegate* delegate, |
| @@ -20,7 +47,9 @@ SearchIPCRouter::SearchIPCRouter(content::WebContents* web_contents, |
| delegate_(delegate), |
| policy_(std::move(policy)), |
| commit_counter_(0), |
| - is_active_tab_(false) { |
| + is_active_tab_(false), |
| + bindings_(web_contents, this), |
| + search_box_client_factory_(new SearchBoxClientFactoryImpl(web_contents)) { |
| DCHECK(web_contents); |
| DCHECK(delegate); |
| DCHECK(policy_.get()); |
| @@ -30,11 +59,11 @@ SearchIPCRouter::~SearchIPCRouter() {} |
| void SearchIPCRouter::OnNavigationEntryCommitted() { |
| ++commit_counter_; |
| - Send(new ChromeViewMsg_SetPageSequenceNumber(routing_id(), commit_counter_)); |
| + search_box()->SetPageSequenceNumber(commit_counter_); |
| } |
| void SearchIPCRouter::DetermineIfPageSupportsInstant() { |
| - Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
| + search_box()->DetermineIfPageSupportsInstant(); |
| } |
| void SearchIPCRouter::SendChromeIdentityCheckResult( |
| @@ -43,15 +72,14 @@ void SearchIPCRouter::SendChromeIdentityCheckResult( |
| if (!policy_->ShouldProcessChromeIdentityCheck()) |
| return; |
| - Send(new ChromeViewMsg_ChromeIdentityCheckResult(routing_id(), identity, |
| - identity_match)); |
| + search_box()->ChromeIdentityCheckResult(identity, identity_match); |
| } |
| void SearchIPCRouter::SendHistorySyncCheckResult(bool sync_history) { |
| if (!policy_->ShouldProcessHistorySyncCheck()) |
| return; |
| - Send(new ChromeViewMsg_HistorySyncCheckResult(routing_id(), sync_history)); |
| + search_box()->HistorySyncCheckResult(sync_history); |
| } |
| void SearchIPCRouter::SetSuggestionToPrefetch( |
| @@ -59,16 +87,14 @@ void SearchIPCRouter::SetSuggestionToPrefetch( |
| if (!policy_->ShouldSendSetSuggestionToPrefetch()) |
| return; |
| - Send(new ChromeViewMsg_SearchBoxSetSuggestionToPrefetch(routing_id(), |
| - suggestion)); |
| + search_box()->SetSuggestionToPrefetch(suggestion); |
| } |
| void SearchIPCRouter::SetInputInProgress(bool input_in_progress) { |
| if (!policy_->ShouldSendSetInputInProgress(is_active_tab_)) |
| return; |
| - Send(new ChromeViewMsg_SearchBoxSetInputInProgress(routing_id(), |
| - input_in_progress)); |
| + search_box()->SetInputInProgress(input_in_progress); |
| } |
| void SearchIPCRouter::OmniboxFocusChanged(OmniboxFocusState state, |
| @@ -76,7 +102,7 @@ void SearchIPCRouter::OmniboxFocusChanged(OmniboxFocusState state, |
| if (!policy_->ShouldSendOmniboxFocusChanged()) |
| return; |
| - Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason)); |
| + search_box()->FocusChanged(state, reason); |
| } |
| void SearchIPCRouter::SendMostVisitedItems( |
| @@ -84,7 +110,7 @@ void SearchIPCRouter::SendMostVisitedItems( |
| if (!policy_->ShouldSendMostVisitedItems()) |
| return; |
| - Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items)); |
| + search_box()->MostVisitedChanged(items); |
| } |
| void SearchIPCRouter::SendThemeBackgroundInfo( |
| @@ -92,7 +118,7 @@ void SearchIPCRouter::SendThemeBackgroundInfo( |
| if (!policy_->ShouldSendThemeBackgroundInfo()) |
| return; |
| - Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); |
| + search_box()->ThemeChanged(theme_info); |
| } |
| void SearchIPCRouter::Submit(const base::string16& text, |
| @@ -100,7 +126,7 @@ void SearchIPCRouter::Submit(const base::string16& text, |
| if (!policy_->ShouldSubmitQuery()) |
| return; |
| - Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text, params)); |
| + search_box()->Submit(text, params); |
| } |
| void SearchIPCRouter::OnTabActivated() { |
| @@ -111,52 +137,19 @@ void SearchIPCRouter::OnTabDeactivated() { |
| is_active_tab_ = false; |
| } |
| -bool SearchIPCRouter::OnMessageReceived(const IPC::Message& message) { |
| - if (IPC_MESSAGE_CLASS(message) != ChromeMsgStart) |
| - return false; |
| - |
| - Profile* profile = |
| - Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| - if (!search::IsRenderedInInstantProcess(web_contents(), profile)) |
| - return false; |
| - |
| - bool handled = true; |
| - IPC_BEGIN_MESSAGE_MAP(SearchIPCRouter, message) |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
| - OnInstantSupportDetermined) |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, |
| - OnDeleteMostVisitedItem); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion, |
| - OnUndoMostVisitedDeletion); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions, |
| - OnUndoAllMostVisitedDeletions); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogEvent, OnLogEvent); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogMostVisitedImpression, |
| - OnLogMostVisitedImpression); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LogMostVisitedNavigation, |
| - OnLogMostVisitedNavigation); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PasteAndOpenDropdown, |
| - OnPasteAndOpenDropDown); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_HistorySyncCheck, |
| - OnHistorySyncCheck); |
| - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ChromeIdentityCheck, |
| - OnChromeIdentityCheck); |
| - IPC_MESSAGE_UNHANDLED(handled = false) |
| - IPC_END_MESSAGE_MAP() |
| - return handled; |
| -} |
| - |
| -void SearchIPCRouter::OnInstantSupportDetermined(int page_seq_no, |
| - bool instant_support) const { |
| +void SearchIPCRouter::InstantSupportDetermined(int page_seq_no, |
| + bool instant_support) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| delegate_->OnInstantSupportDetermined(instant_support); |
| } |
| -void SearchIPCRouter::OnFocusOmnibox(int page_seq_no, |
| - OmniboxFocusState state) const { |
| +void SearchIPCRouter::FocusOmnibox(int page_seq_no, OmniboxFocusState state) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -167,8 +160,10 @@ void SearchIPCRouter::OnFocusOmnibox(int page_seq_no, |
| delegate_->FocusOmnibox(state); |
| } |
| -void SearchIPCRouter::OnDeleteMostVisitedItem(int page_seq_no, |
| - const GURL& url) const { |
| +void SearchIPCRouter::SearchBoxDeleteMostVisitedItem(int page_seq_no, |
| + const GURL& url) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -179,8 +174,10 @@ void SearchIPCRouter::OnDeleteMostVisitedItem(int page_seq_no, |
| delegate_->OnDeleteMostVisitedItem(url); |
| } |
| -void SearchIPCRouter::OnUndoMostVisitedDeletion(int page_seq_no, |
| - const GURL& url) const { |
| +void SearchIPCRouter::SearchBoxUndoMostVisitedDeletion(int page_seq_no, |
| + const GURL& url) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -191,7 +188,9 @@ void SearchIPCRouter::OnUndoMostVisitedDeletion(int page_seq_no, |
| delegate_->OnUndoMostVisitedDeletion(url); |
| } |
| -void SearchIPCRouter::OnUndoAllMostVisitedDeletions(int page_seq_no) const { |
| +void SearchIPCRouter::SearchBoxUndoAllMostVisitedDeletions(int page_seq_no) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -202,9 +201,11 @@ void SearchIPCRouter::OnUndoAllMostVisitedDeletions(int page_seq_no) const { |
| delegate_->OnUndoAllMostVisitedDeletions(); |
| } |
| -void SearchIPCRouter::OnLogEvent(int page_seq_no, |
| - NTPLoggingEventType event, |
| - base::TimeDelta time) const { |
| +void SearchIPCRouter::LogEvent(int page_seq_no, |
| + NTPLoggingEventType event, |
| + base::TimeDelta time) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -215,8 +216,12 @@ void SearchIPCRouter::OnLogEvent(int page_seq_no, |
| delegate_->OnLogEvent(event, time); |
| } |
| -void SearchIPCRouter::OnLogMostVisitedImpression( |
| - int page_seq_no, int position, NTPLoggingTileSource tile_source) const { |
| +void SearchIPCRouter::LogMostVisitedImpression( |
| + int page_seq_no, |
| + int position, |
| + NTPLoggingTileSource tile_source) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -228,8 +233,12 @@ void SearchIPCRouter::OnLogMostVisitedImpression( |
| delegate_->OnLogMostVisitedImpression(position, tile_source); |
| } |
| -void SearchIPCRouter::OnLogMostVisitedNavigation( |
| - int page_seq_no, int position, NTPLoggingTileSource tile_source) const { |
| +void SearchIPCRouter::LogMostVisitedNavigation( |
| + int page_seq_no, |
| + int position, |
| + NTPLoggingTileSource tile_source) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -241,8 +250,10 @@ void SearchIPCRouter::OnLogMostVisitedNavigation( |
| delegate_->OnLogMostVisitedNavigation(position, tile_source); |
| } |
| -void SearchIPCRouter::OnPasteAndOpenDropDown(int page_seq_no, |
| - const base::string16& text) const { |
| +void SearchIPCRouter::PasteAndOpenDropdown(int page_seq_no, |
| + const base::string16& text) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -253,9 +264,10 @@ void SearchIPCRouter::OnPasteAndOpenDropDown(int page_seq_no, |
| delegate_->PasteIntoOmnibox(text); |
| } |
| -void SearchIPCRouter::OnChromeIdentityCheck( |
| - int page_seq_no, |
| - const base::string16& identity) const { |
| +void SearchIPCRouter::ChromeIdentityCheck(int page_seq_no, |
| + const base::string16& identity) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -266,7 +278,9 @@ void SearchIPCRouter::OnChromeIdentityCheck( |
| delegate_->OnChromeIdentityCheck(identity); |
| } |
| -void SearchIPCRouter::OnHistorySyncCheck(int page_seq_no) const { |
| +void SearchIPCRouter::HistorySyncCheck(int page_seq_no) { |
| + if (!IsRenderedInInstantProcess()) |
| + return; |
| if (page_seq_no != commit_counter_) |
| return; |
| @@ -277,6 +291,16 @@ void SearchIPCRouter::OnHistorySyncCheck(int page_seq_no) const { |
| delegate_->OnHistorySyncCheck(); |
| } |
| +bool SearchIPCRouter::IsRenderedInInstantProcess() const { |
| + // TODO(tibell): Instead of rejecting messages check at connection time if we |
| + // want to talk to the render frame or not. Later, in an out-of-process iframe |
| + // world, the IsRenderedInInstantProcess check will have to be done, as it's |
| + // based on the RenderView. |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| + return search::IsRenderedInInstantProcess(web_contents(), profile); |
| +} |
| + |
| void SearchIPCRouter::set_delegate_for_testing(Delegate* delegate) { |
| DCHECK(delegate); |
| delegate_ = delegate; |