| Index: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc
|
| diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc b/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc
|
| index fe3361f9d8345324e2912850446377ec51ab4143..6bd6523f002123aa06d9af90da2c12fda7578b1a 100644
|
| --- a/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc
|
| +++ b/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc
|
| @@ -15,6 +15,7 @@
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/run_loop.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| @@ -31,6 +32,7 @@
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/common/render_messages.h"
|
| +#include "chrome/common/thumbnail_capturer.mojom.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| #include "chrome/test/base/search_test_utils.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| @@ -42,6 +44,7 @@
|
| #include "content/public/browser/navigation_controller.h"
|
| #include "content/public/browser/navigation_entry.h"
|
| #include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/render_frame_host.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/render_view_host.h"
|
| #include "content/public/browser/render_widget_host.h"
|
| @@ -53,6 +56,7 @@
|
| #include "net/url_request/url_request.h"
|
| #include "net/url_request/url_request_filter.h"
|
| #include "net/url_request/url_request_interceptor.h"
|
| +#include "services/service_manager/public/cpp/interface_provider.h"
|
| #include "third_party/WebKit/public/platform/WebInputEvent.h"
|
| #include "third_party/WebKit/public/web/WebContextMenuData.h"
|
| #include "ui/base/models/menu_model.h"
|
| @@ -556,55 +560,23 @@ class ThumbnailResponseWatcher : public content::NotificationObserver {
|
| RENDER_PROCESS_GONE,
|
| };
|
|
|
| - class MessageFilter : public content::BrowserMessageFilter {
|
| - public:
|
| - explicit MessageFilter(ThumbnailResponseWatcher* owner)
|
| - : content::BrowserMessageFilter(ChromeMsgStart), owner_(owner) {}
|
| -
|
| - bool OnMessageReceived(const IPC::Message& message) override {
|
| - if (message.type() ==
|
| - ChromeViewHostMsg_RequestThumbnailForContextNode_ACK::ID) {
|
| - content::BrowserThread::PostTask(
|
| - content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&MessageFilter::OnRequestThumbnailForContextNodeACK,
|
| - this));
|
| - }
|
| - return false;
|
| - }
|
| -
|
| - void OnRequestThumbnailForContextNodeACK() {
|
| - if (owner_)
|
| - owner_->OnRequestThumbnailForContextNodeACK();
|
| - }
|
| -
|
| - void Disown() { owner_ = nullptr; }
|
| -
|
| - private:
|
| - ~MessageFilter() override {}
|
| -
|
| - ThumbnailResponseWatcher* owner_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(MessageFilter);
|
| - };
|
| -
|
| - explicit ThumbnailResponseWatcher(
|
| - content::RenderProcessHost* render_process_host)
|
| - : message_loop_runner_(new content::MessageLoopRunner),
|
| - filter_(new MessageFilter(this)),
|
| - quit_reason_(STILL_RUNNING) {
|
| + explicit ThumbnailResponseWatcher(content::WebContents* tab)
|
| + : tab_(tab), quit_reason_(STILL_RUNNING) {
|
| + content::RenderProcessHost* render_process_host =
|
| + tab->GetRenderProcessHost();
|
| notification_registrar_.Add(
|
| this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
|
| content::Source<content::RenderProcessHost>(render_process_host));
|
| notification_registrar_.Add(
|
| this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
|
| content::Source<content::RenderProcessHost>(render_process_host));
|
| - render_process_host->AddFilter(filter_.get());
|
| + notification_registrar_.Add(
|
| + this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
|
| + content::NotificationService::AllSources());
|
| }
|
|
|
| - ~ThumbnailResponseWatcher() override { filter_->Disown(); }
|
| -
|
| QuitReason Wait() WARN_UNUSED_RESULT {
|
| - message_loop_runner_->Run();
|
| + run_loop_.Run();
|
| DCHECK_NE(STILL_RUNNING, quit_reason_);
|
| return quit_reason_;
|
| }
|
| @@ -612,21 +584,36 @@ class ThumbnailResponseWatcher : public content::NotificationObserver {
|
| void Observe(int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) override {
|
| - DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED ||
|
| - type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
|
| - quit_reason_ = RENDER_PROCESS_GONE;
|
| - message_loop_runner_->Quit();
|
| + if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED ||
|
| + type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED) {
|
| + quit_reason_ = RENDER_PROCESS_GONE;
|
| + run_loop_.Quit();
|
| + } else {
|
| + DCHECK_EQ(type, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN);
|
| + RequestThumbnail();
|
| + }
|
| }
|
|
|
| - void OnRequestThumbnailForContextNodeACK() {
|
| + void RequestThumbnail() {
|
| + tab_->GetMainFrame()->GetRemoteInterfaces()->GetInterface(
|
| + &thumbnail_capturer_);
|
| + thumbnail_capturer_->RequestThumbnailForContextNode(
|
| + 0, gfx::Size(2048, 2048),
|
| + base::Bind(&ThumbnailResponseWatcher::OnRequestThumbnailResponse,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + void OnRequestThumbnailResponse(const std::string& thumbnail_data,
|
| + const gfx::Size& original_size) {
|
| quit_reason_ = THUMBNAIL_RECEIVED;
|
| - message_loop_runner_->Quit();
|
| + run_loop_.Quit();
|
| }
|
|
|
| private:
|
| - scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
|
| - scoped_refptr<MessageFilter> filter_;
|
| + base::RunLoop run_loop_;
|
| content::NotificationRegistrar notification_registrar_;
|
| + content::WebContents* tab_;
|
| + chrome::mojom::ThumbnailCapturerPtr thumbnail_capturer_;
|
| QuitReason quit_reason_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ThumbnailResponseWatcher);
|
| @@ -650,10 +637,14 @@ class SearchByImageBrowserTest : public InProcessBrowserTest {
|
| }
|
|
|
| void AttemptImageSearch() {
|
| - // Right-click where the image should be.
|
| // |menu_observer_| will cause the search-by-image menu item to be clicked.
|
| menu_observer_.reset(new ContextMenuNotificationObserver(
|
| IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE));
|
| + RightClickImage();
|
| + }
|
| +
|
| + // Right-click where the image should be.
|
| + void RightClickImage() {
|
| content::WebContents* tab =
|
| browser()->tab_strip_model()->GetActiveWebContents();
|
| content::SimulateMouseClickAt(tab, 0, blink::WebMouseEvent::Button::Right,
|
| @@ -718,8 +709,9 @@ IN_PROC_BROWSER_TEST_F(SearchByImageBrowserTest, ImageSearchWithCorruptImage) {
|
|
|
| content::WebContents* tab =
|
| browser()->tab_strip_model()->GetActiveWebContents();
|
| - ThumbnailResponseWatcher watcher(tab->GetRenderProcessHost());
|
| - AttemptImageSearch();
|
| + // Create the watcher first because it observes the context menu creation.
|
| + ThumbnailResponseWatcher watcher(tab);
|
| + RightClickImage();
|
|
|
| // The browser should receive a response from the renderer, because the
|
| // renderer should not crash.
|
|
|