Commit 54427cb3 authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

PDF Viewer: Disable "Rotate" context menu options in Presentation mode.

Bug: 1148478,1155076
Change-Id: I45421d6e0673d4d56b783f843bb12470c7a47202
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570992Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Commit-Queue: Raymes Khoury <raymes@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834377}
parent d4ca35de
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "pdf/buildflags.h"
#include "ppapi/buildflags/buildflags.h" #include "ppapi/buildflags/buildflags.h"
#include "printing/buildflags/buildflags.h" #include "printing/buildflags/buildflags.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
...@@ -186,6 +187,10 @@ ...@@ -186,6 +187,10 @@
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#endif #endif
#if BUILDFLAG(ENABLE_PDF)
#include "extensions/common/constants.h"
#endif
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
#include "chrome/browser/plugins/chrome_plugin_service_filter.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#endif #endif
...@@ -563,6 +568,13 @@ bool DoesInputFieldTypeSupportEmoji( ...@@ -563,6 +568,13 @@ bool DoesInputFieldTypeSupportEmoji(
} }
} }
#if BUILDFLAG(ENABLE_PDF)
bool IsPdfPluginURL(const GURL& url) {
return url.SchemeIs(extensions::kExtensionScheme) &&
url.host_piece() == extension_misc::kPdfExtensionId;
}
#endif
} // namespace } // namespace
// static // static
...@@ -1059,7 +1071,7 @@ void RenderViewContextMenu::RecordShownItem(int id) { ...@@ -1059,7 +1071,7 @@ void RenderViewContextMenu::RecordShownItem(int id) {
} }
bool RenderViewContextMenu::IsHTML5Fullscreen() const { bool RenderViewContextMenu::IsHTML5Fullscreen() const {
Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_); Browser* browser = chrome::FindBrowserWithWebContents(embedder_web_contents_);
if (!browser) if (!browser)
return false; return false;
...@@ -2014,8 +2026,17 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { ...@@ -2014,8 +2026,17 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
WebContextMenuData::kMediaCanToggleControls) != 0; WebContextMenuData::kMediaCanToggleControls) != 0;
case IDC_CONTENT_CONTEXT_ROTATECW: case IDC_CONTENT_CONTEXT_ROTATECW:
case IDC_CONTENT_CONTEXT_ROTATECCW: case IDC_CONTENT_CONTEXT_ROTATECCW: {
return (params_.media_flags & WebContextMenuData::kMediaCanRotate) != 0; bool is_pdf_viewer_fullscreen = false;
#if BUILDFLAG(ENABLE_PDF)
// Rotate commands should be disabled when in PDF Viewer's Presentation
// mode.
is_pdf_viewer_fullscreen =
IsPdfPluginURL(GetDocumentURL(params_)) && IsHTML5Fullscreen();
#endif
return !is_pdf_viewer_fullscreen &&
(params_.media_flags & WebContextMenuData::kMediaCanRotate) != 0;
}
case IDC_CONTENT_CONTEXT_COPYAVLOCATION: case IDC_CONTENT_CONTEXT_COPYAVLOCATION:
case IDC_CONTENT_CONTEXT_COPYIMAGELOCATION: case IDC_CONTENT_CONTEXT_COPYIMAGELOCATION:
......
...@@ -313,6 +313,36 @@ class PdfPluginContextMenuBrowserTest : public InProcessBrowserTest { ...@@ -313,6 +313,36 @@ class PdfPluginContextMenuBrowserTest : public InProcessBrowserTest {
return test_guest_view_manager_; return test_guest_view_manager_;
} }
std::unique_ptr<TestRenderViewContextMenu> SetupAndCreateMenu() {
// Load a pdf page.
GURL page_url = ui_test_utils::GetTestUrl(
base::FilePath(FILE_PATH_LITERAL("pdf")),
base::FilePath(FILE_PATH_LITERAL("test.pdf")));
ui_test_utils::NavigateToURL(browser(), page_url);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
// Wait for the PDF plugin to load.
EXPECT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
content::BrowserPluginGuestManager* guest_manager =
web_contents->GetBrowserContext()->GetGuestManager();
WebContents* guest_contents = guest_manager->GetFullPageGuest(web_contents);
EXPECT_TRUE(guest_contents);
// Get the pdf plugin's main frame.
content::RenderFrameHost* frame = guest_contents->GetMainFrame();
EXPECT_TRUE(frame);
EXPECT_NE(frame, web_contents->GetMainFrame());
content::ContextMenuParams params;
params.page_url = page_url;
params.frame_url = frame->GetLastCommittedURL();
params.media_type = blink::ContextMenuDataMediaType::kPlugin;
params.media_flags |= blink::WebContextMenuData::kMediaCanRotate;
auto menu = std::make_unique<TestRenderViewContextMenu>(frame, params);
menu->Init();
return menu;
}
// Helper function for testing context menu of a pdf plugin inside a web page. // Helper function for testing context menu of a pdf plugin inside a web page.
void TestContextMenuOfPdfInsideWebPage( void TestContextMenuOfPdfInsideWebPage(
const base::FilePath::CharType* file_name) { const base::FilePath::CharType* file_name) {
...@@ -1406,34 +1436,29 @@ IN_PROC_BROWSER_TEST_F(SearchByImageBrowserTest, ImageSearchWithCorruptImage) { ...@@ -1406,34 +1436,29 @@ IN_PROC_BROWSER_TEST_F(SearchByImageBrowserTest, ImageSearchWithCorruptImage) {
IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest,
FullPagePdfHasPageItems) { FullPagePdfHasPageItems) {
// Load a pdf page. std::unique_ptr<TestRenderViewContextMenu> menu = SetupAndCreateMenu();
GURL page_url =
ui_test_utils::GetTestUrl(base::FilePath(FILE_PATH_LITERAL("pdf")),
base::FilePath(FILE_PATH_LITERAL("test.pdf")));
ui_test_utils::NavigateToURL(browser(), page_url);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
// Wait for the PDF plugin to load.
ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
content::BrowserPluginGuestManager* guest_manager =
web_contents->GetBrowserContext()->GetGuestManager();
WebContents* guest_contents = guest_manager->GetFullPageGuest(web_contents);
ASSERT_TRUE(guest_contents);
// Get the pdf plugin's main frame.
content::RenderFrameHost* frame = guest_contents->GetMainFrame();
ASSERT_TRUE(frame);
ASSERT_NE(frame, web_contents->GetMainFrame());
content::ContextMenuParams params;
params.page_url = page_url;
params.frame_url = frame->GetLastCommittedURL();
params.media_type = blink::ContextMenuDataMediaType::kPlugin;
TestRenderViewContextMenu menu(frame, params);
menu.Init();
// The full page related items such as 'reload' should be there. // The full page related items such as 'reload' should be there.
ASSERT_TRUE(menu.IsItemPresent(IDC_RELOAD)); ASSERT_TRUE(menu->IsItemPresent(IDC_RELOAD));
}
IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest,
FullPagePdfFullscreenItems) {
std::unique_ptr<TestRenderViewContextMenu> menu = SetupAndCreateMenu();
// Test that the 'Rotate' items exist and are enabled.
ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_ROTATECW));
ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_ROTATECCW));
ASSERT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_ROTATECW));
ASSERT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_ROTATECCW));
// Set to tab fullscreen, and test that 'Rotate' items are disabled.
FullscreenController* fullscreen_controller =
browser()->exclusive_access_manager()->fullscreen_controller();
fullscreen_controller->set_is_tab_fullscreen_for_testing(true);
ASSERT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_ROTATECW));
ASSERT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_ROTATECCW));
} }
IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest,
......
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