Commit b4adc139 authored by lazyboy's avatar lazyboy Committed by Commit bot

Fix context menu positioning in MimeHandlerViewGuest.

BUG=422641
Test=Load chrome with the following flags:
--out-of-process-pdf, --enable-mime-handler-view
Load a PDF in a <webview>, e.g. use the webview-sample/browser app:
https://chrome.google.com/webstore/detail/edggnmnajhcbhlnpjnogkjpghaikidaa
and navigate to a PDF.
Right clicking the PDF should bring context menu to correct
position relative to the cursor.

Review URL: https://codereview.chromium.org/667273002

Cr-Commit-Position: refs/heads/master@{#300639}
parent f6495730
......@@ -5,8 +5,10 @@
#include "chrome/browser/guest_view/mime_handler_view/chrome_mime_handler_view_guest_delegate.h"
#include "chrome/browser/chrome_page_zoom.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
#include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
#include "components/pdf/browser/pdf_web_contents_helper.h"
#include "components/renderer_context_menu/context_menu_delegate.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
#if defined(ENABLE_PRINTING)
......@@ -53,4 +55,17 @@ void ChromeMimeHandlerViewGuestDelegate::ChangeZoom(bool zoom_in) {
zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT);
}
bool ChromeMimeHandlerViewGuestDelegate::HandleContextMenu(
content::WebContents* web_contents,
const content::ContextMenuParams& params) {
ContextMenuDelegate* menu_delegate =
ContextMenuDelegate::FromWebContents(web_contents);
DCHECK(menu_delegate);
scoped_ptr<RenderViewContextMenu> menu =
menu_delegate->BuildMenu(web_contents, params);
menu_delegate->ShowMenu(menu.Pass());
return true;
}
} // namespace extensions
......@@ -9,6 +9,7 @@
namespace content {
class WebContents;
struct ContextMenuParams;
} // namespace content
namespace extensions {
......@@ -20,6 +21,8 @@ class ChromeMimeHandlerViewGuestDelegate : public MimeHandlerViewGuestDelegate {
// MimeHandlerViewGuestDelegate.
void AttachHelpers() override;
bool HandleContextMenu(content::WebContents* web_contents,
const content::ContextMenuParams& params) override;
void ChangeZoom(bool zoom_in) override;
private:
......
......@@ -370,6 +370,7 @@ source_set("browser") {
"guest_view/mime_handler_view/mime_handler_view_constants.h",
"guest_view/mime_handler_view/mime_handler_view_guest.h",
"guest_view/mime_handler_view/mime_handler_view_guest.cc",
"guest_view/mime_handler_view/mime_handler_view_guest_delegate.cc",
"guest_view/mime_handler_view/mime_handler_view_guest_delegate.h",
"guest_view/web_view/javascript_dialog_helper.cc",
"guest_view/web_view/javascript_dialog_helper.h",
......
......@@ -147,6 +147,14 @@ void MimeHandlerViewGuest::ContentsZoomChange(bool zoom_in) {
delegate_->ChangeZoom(zoom_in);
}
bool MimeHandlerViewGuest::HandleContextMenu(
const content::ContextMenuParams& params) {
if (delegate_)
return delegate_->HandleContextMenu(web_contents(), params);
return false;
}
void MimeHandlerViewGuest::HandleKeyboardEvent(
WebContents* source,
const content::NativeWebKeyboardEvent& event) {
......
......@@ -10,6 +10,7 @@
namespace content {
class WebContents;
struct ContextMenuParams;
} // namespace content
namespace extensions {
......@@ -47,6 +48,7 @@ class MimeHandlerViewGuest : public GuestView<MimeHandlerViewGuest>,
// WebContentsDelegate implementation.
void ContentsZoomChange(bool zoom_in) override;
bool HandleContextMenu(const content::ContextMenuParams& params) override;
void HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h"
namespace extensions {
bool MimeHandlerViewGuestDelegate::HandleContextMenu(
content::WebContents* web_contents,
const content::ContextMenuParams& params) {
return false;
}
} // namespace extensions
......@@ -9,6 +9,7 @@
namespace content {
class WebContents;
struct ContextMenuParams;
} // namespace content
namespace extensions {
......@@ -24,6 +25,10 @@ class MimeHandlerViewGuestDelegate {
// Attaches helpers upon initializing the WebContents.
virtual void AttachHelpers() {}
// Handles context menu, or returns false if unhandled.
virtual bool HandleContextMenu(content::WebContents* web_contents,
const content::ContextMenuParams& params);
// Request to change the zoom level of the top level page containing
// this view.
virtual void ChangeZoom(bool zoom_in) {}
......
......@@ -668,6 +668,7 @@
'browser/guest_view/guest_view.h',
'browser/guest_view/mime_handler_view/mime_handler_view_constants.cc',
'browser/guest_view/mime_handler_view/mime_handler_view_constants.h',
'browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.cc',
'browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h',
'browser/guest_view/mime_handler_view/mime_handler_view_guest.cc',
'browser/guest_view/mime_handler_view/mime_handler_view_guest.h',
......
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