Commit ec72f998 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

SearchBox: Hook up Mojo interfaces in DidCommitProvisionalLoad

SearchBox may execute JS in response to IPCs, but running JS in the
given frame is illegal before the provisional navigation has committed.

Bug: 765101
Change-Id: I7fc01989177b768667b5d64c2198b2da3ec0adb9
Reviewed-on: https://chromium-review.googlesource.com/723079Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509728}
parent 839ea8c6
...@@ -224,13 +224,12 @@ SearchBox::SearchBox(content::RenderFrame* render_frame) ...@@ -224,13 +224,12 @@ SearchBox::SearchBox(content::RenderFrame* render_frame)
most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize), most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize),
binding_(this), binding_(this),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
// Connect to the embedded search interface in the browser. // Note: This class may execute JS in |render_frame| in response to IPCs (via
chrome::mojom::EmbeddedSearchConnectorAssociatedPtr connector; // the SearchBoxExtension::Dispatch* methods). However, for cross-process
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(&connector); // navigations, a "provisional frame" is created at first, and it's illegal
chrome::mojom::EmbeddedSearchClientAssociatedPtrInfo embedded_search_client; // to execute any JS in it before it's actually swapped in, i.e.m before the
binding_.Bind(mojo::MakeRequest(&embedded_search_client)); // navigation has committed. So we only hook up the Mojo interfaces in
connector->Connect(mojo::MakeRequest(&embedded_search_service_), // RenderFrameObserver::DidCommitProvisionalLoad. See crbug.com/765101.
std::move(embedded_search_client));
} }
SearchBox::~SearchBox() = default; SearchBox::~SearchBox() = default;
...@@ -410,9 +409,18 @@ GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const { ...@@ -410,9 +409,18 @@ GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const {
return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL();
} }
void SearchBox::Bind( void SearchBox::DidCommitProvisionalLoad(bool is_new_navigation,
chrome::mojom::EmbeddedSearchClientAssociatedRequest request) { bool is_same_document_navigation) {
binding_.Bind(std::move(request)); if (binding_.is_bound())
return;
// Connect to the embedded search interface in the browser.
chrome::mojom::EmbeddedSearchConnectorAssociatedPtr connector;
render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(&connector);
chrome::mojom::EmbeddedSearchClientAssociatedPtrInfo embedded_search_client;
binding_.Bind(mojo::MakeRequest(&embedded_search_client));
connector->Connect(mojo::MakeRequest(&embedded_search_service_),
std::move(embedded_search_client));
} }
void SearchBox::OnDestruct() { void SearchBox::OnDestruct() {
......
...@@ -123,6 +123,8 @@ class SearchBox : public content::RenderFrameObserver, ...@@ -123,6 +123,8 @@ class SearchBox : public content::RenderFrameObserver,
private: private:
// Overridden from content::RenderFrameObserver: // Overridden from content::RenderFrameObserver:
void DidCommitProvisionalLoad(bool is_new_navigation,
bool is_same_document_navigation) override;
void OnDestruct() override; void OnDestruct() override;
// Overridden from chrome::mojom::EmbeddedSearchClient: // Overridden from chrome::mojom::EmbeddedSearchClient:
...@@ -141,8 +143,6 @@ class SearchBox : public content::RenderFrameObserver, ...@@ -141,8 +143,6 @@ class SearchBox : public content::RenderFrameObserver,
// Returns the URL of the Most Visited item specified by the |item_id|. // Returns the URL of the Most Visited item specified by the |item_id|.
GURL GetURLForMostVisitedItem(InstantRestrictedID item_id) const; GURL GetURLForMostVisitedItem(InstantRestrictedID item_id) const;
void Bind(chrome::mojom::EmbeddedSearchClientAssociatedRequest request);
int page_seq_no_; int page_seq_no_;
bool is_focused_; bool is_focused_;
bool is_input_in_progress_; bool is_input_in_progress_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment