chrome: Add support for PdfViewerTest ceftests (see issue #3047)
We need to override ChromeMimeHandlerViewGuestDelegate to handle OnGuestAttached/Detached callbacks in order to account for the guest renderer process hosting the PDF extension. Additional work will be required to account for the renderer process hosting the PDF viewer when using `--enable-features=PdfUnseasoned` (see issue #2969).
This commit is contained in:
parent
f3cea7e7df
commit
6eff48e9ff
2
BUILD.gn
2
BUILD.gn
|
@ -466,6 +466,8 @@ static_library("libcef_static") {
|
|||
"libcef/browser/chrome/chrome_context_menu_handler.cc",
|
||||
"libcef/browser/chrome/chrome_context_menu_handler.h",
|
||||
"libcef/browser/chrome_crash_reporter_client_stub.cc",
|
||||
"libcef/browser/chrome/extensions/chrome_mime_handler_view_guest_delegate_cef.cc",
|
||||
"libcef/browser/chrome/extensions/chrome_mime_handler_view_guest_delegate_cef.h",
|
||||
"libcef/browser/context.cc",
|
||||
"libcef/browser/context.h",
|
||||
"libcef/browser/context_menu_params_impl.cc",
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2015 The Chromium Embedded Framework Authors.
|
||||
// Portions 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 "libcef/browser/chrome/extensions/chrome_mime_handler_view_guest_delegate_cef.h"
|
||||
|
||||
#include "libcef/browser/browser_host_base.h"
|
||||
#include "libcef/browser/browser_info.h"
|
||||
|
||||
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
ChromeMimeHandlerViewGuestDelegateCef::ChromeMimeHandlerViewGuestDelegateCef(
|
||||
MimeHandlerViewGuest* guest)
|
||||
: guest_(guest), owner_web_contents_(guest_->owner_web_contents()) {}
|
||||
|
||||
ChromeMimeHandlerViewGuestDelegateCef::
|
||||
~ChromeMimeHandlerViewGuestDelegateCef() = default;
|
||||
|
||||
void ChromeMimeHandlerViewGuestDelegateCef::OnGuestAttached() {
|
||||
content::WebContents* web_contents = guest_->web_contents();
|
||||
DCHECK(web_contents);
|
||||
|
||||
auto owner_browser =
|
||||
CefBrowserHostBase::GetBrowserForContents(owner_web_contents_);
|
||||
DCHECK(owner_browser);
|
||||
|
||||
// Associate guest state information with the owner browser.
|
||||
owner_browser->browser_info()->MaybeCreateFrame(web_contents->GetMainFrame(),
|
||||
true /* is_guest_view */);
|
||||
}
|
||||
|
||||
void ChromeMimeHandlerViewGuestDelegateCef::OnGuestDetached() {
|
||||
content::WebContents* web_contents = guest_->web_contents();
|
||||
DCHECK(web_contents);
|
||||
|
||||
auto owner_browser =
|
||||
CefBrowserHostBase::GetBrowserForContents(owner_web_contents_);
|
||||
DCHECK(owner_browser);
|
||||
|
||||
// Disassociate guest state information with the owner browser.
|
||||
owner_browser->browser_info()->RemoveFrame(web_contents->GetMainFrame());
|
||||
}
|
||||
|
||||
} // namespace extensions
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2015 The Chromium Embedded Framework Authors.
|
||||
// Portions 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.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_CHROME_EXTENSIONS_CHROME_MIME_HANDLER_VIEW_GUEST_DELEGATE_CEF_H_
|
||||
#define CEF_LIBCEF_BROWSER_CHROME_EXTENSIONS_CHROME_MIME_HANDLER_VIEW_GUEST_DELEGATE_CEF_H_
|
||||
|
||||
#include "chrome/browser/guest_view/mime_handler_view/chrome_mime_handler_view_guest_delegate.h"
|
||||
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
class ChromeMimeHandlerViewGuestDelegateCef
|
||||
: public ChromeMimeHandlerViewGuestDelegate {
|
||||
public:
|
||||
explicit ChromeMimeHandlerViewGuestDelegateCef(MimeHandlerViewGuest* guest);
|
||||
|
||||
ChromeMimeHandlerViewGuestDelegateCef(
|
||||
const ChromeMimeHandlerViewGuestDelegateCef&) = delete;
|
||||
ChromeMimeHandlerViewGuestDelegateCef& operator=(
|
||||
const ChromeMimeHandlerViewGuestDelegateCef&) = delete;
|
||||
|
||||
~ChromeMimeHandlerViewGuestDelegateCef() override;
|
||||
|
||||
// MimeHandlerViewGuestDelegate methods.
|
||||
void OnGuestAttached() override;
|
||||
void OnGuestDetached() override;
|
||||
|
||||
private:
|
||||
MimeHandlerViewGuest* guest_; // Owns us.
|
||||
content::WebContents* owner_web_contents_;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_CHROME_EXTENSIONS_CHROME_MIME_HANDLER_VIEW_GUEST_DELEGATE_CEF_H_
|
|
@ -219,6 +219,11 @@ patches = [
|
|||
# https://bitbucket.org/chromiumembedded/cef/issues/2969
|
||||
'name': 'chrome_browser_context_menus',
|
||||
},
|
||||
{
|
||||
# chrome: Support override of ChromeMimeHandlerViewGuestDelegate.
|
||||
# https://bitbucket.org/chromiumembedded/cef/issues/2969
|
||||
'name': 'chrome_browser_extensions',
|
||||
},
|
||||
{
|
||||
# Don't initialize ExtensionSystemFactory when extensions are disabled.
|
||||
# https://bitbucket.org/chromiumembedded/cef/issues/2852
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
diff --git chrome/browser/extensions/api/chrome_extensions_api_client.cc chrome/browser/extensions/api/chrome_extensions_api_client.cc
|
||||
index e3c5941a4ac67..6ae2b8fc39a0b 100644
|
||||
--- chrome/browser/extensions/api/chrome_extensions_api_client.cc
|
||||
+++ chrome/browser/extensions/api/chrome_extensions_api_client.cc
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "base/task/post_task.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
+#include "cef/libcef/features/runtime.h"
|
||||
#include "chrome/browser/extensions/api/automation_internal/chrome_automation_internal_api_delegate.h"
|
||||
#include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h"
|
||||
#include "chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.h"
|
||||
@@ -76,6 +77,10 @@
|
||||
#include "chrome/browser/extensions/clipboard_extension_helper_chromeos.h"
|
||||
#endif
|
||||
|
||||
+#if BUILDFLAG(ENABLE_CEF)
|
||||
+#include "cef/libcef/browser/chrome/extensions/chrome_mime_handler_view_guest_delegate_cef.h"
|
||||
+#endif
|
||||
+
|
||||
#if BUILDFLAG(ENABLE_PDF)
|
||||
#include "chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.h"
|
||||
#include "components/pdf/browser/pdf_web_contents_helper.h"
|
||||
@@ -300,6 +305,9 @@ ChromeExtensionsAPIClient::CreateGuestViewManagerDelegate(
|
||||
std::unique_ptr<MimeHandlerViewGuestDelegate>
|
||||
ChromeExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
|
||||
MimeHandlerViewGuest* guest) const {
|
||||
+ if (cef::IsChromeRuntimeEnabled()) {
|
||||
+ return std::make_unique<ChromeMimeHandlerViewGuestDelegateCef>(guest);
|
||||
+ }
|
||||
return std::make_unique<ChromeMimeHandlerViewGuestDelegate>();
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
#include "include/wrapper/cef_closure_task.h"
|
||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||
#include "tests/ceftests/test_handler.h"
|
||||
#include "tests/ceftests/test_util.h"
|
||||
#include "tests/gtest/include/gtest/gtest.h"
|
||||
#include "tests/shared/browser/client_app_browser.h"
|
||||
#include "tests/shared/browser/resource_util.h"
|
||||
|
@ -40,6 +41,15 @@ const int64 kPdfLoadDelayMs = 7000;
|
|||
const int64 kPdfLoadDelayMs = 5000;
|
||||
#endif
|
||||
|
||||
int64 PdfLoadDelayMs() {
|
||||
// TODO(chrome): The PDF renderer process created when using
|
||||
// `--enable-features=PdfUnseasoned` is currently causing a
|
||||
// "Timeout of new browser info response for frame" error which necessitates
|
||||
// a longer delay. Reduce this delay once we can properly account for that
|
||||
// new renderer process (see issue #3047).
|
||||
return IsChromeRuntimeEnabled() ? kPdfLoadDelayMs * 2 : kPdfLoadDelayMs;
|
||||
}
|
||||
|
||||
// Browser-side test handler.
|
||||
class PdfViewerTestHandler : public TestHandler, public CefContextMenuHandler {
|
||||
public:
|
||||
|
@ -81,7 +91,7 @@ class PdfViewerTestHandler : public TestHandler, public CefContextMenuHandler {
|
|||
CreateBrowser(url_, request_context);
|
||||
|
||||
// Time out the test after a reasonable period of time.
|
||||
SetTestTimeout(5000 + kPdfLoadDelayMs);
|
||||
SetTestTimeout(5000 + PdfLoadDelayMs());
|
||||
}
|
||||
|
||||
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
||||
|
@ -127,18 +137,19 @@ class PdfViewerTestHandler : public TestHandler, public CefContextMenuHandler {
|
|||
|
||||
if (is_pdf1) {
|
||||
// The first PDF document has loaded.
|
||||
if (got_context_menu_dismissed_) {
|
||||
// TODO(chrome): Add support for custom context menus.
|
||||
if (IsChromeRuntimeEnabled() || got_context_menu_dismissed_) {
|
||||
// After context menu display. Destroy the test.
|
||||
CefPostDelayedTask(
|
||||
TID_UI, base::BindOnce(&PdfViewerTestHandler::DestroyTest, this),
|
||||
kPdfLoadDelayMs);
|
||||
PdfLoadDelayMs());
|
||||
} else {
|
||||
// Trigger the context menu.
|
||||
CefPostDelayedTask(
|
||||
TID_UI,
|
||||
base::BindOnce(&PdfViewerTestHandler::TriggerContextMenu, this,
|
||||
frame->GetBrowser()),
|
||||
kPdfLoadDelayMs);
|
||||
PdfLoadDelayMs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,8 +196,14 @@ class PdfViewerTestHandler : public TestHandler, public CefContextMenuHandler {
|
|||
}
|
||||
|
||||
void DestroyTest() override {
|
||||
// TODO(chrome): Add support for custom context menus.
|
||||
if (!IsChromeRuntimeEnabled()) {
|
||||
EXPECT_TRUE(got_run_context_menu_);
|
||||
EXPECT_TRUE(got_context_menu_dismissed_);
|
||||
} else {
|
||||
EXPECT_FALSE(got_run_context_menu_);
|
||||
EXPECT_FALSE(got_context_menu_dismissed_);
|
||||
}
|
||||
|
||||
if (url_ == kPdfHtmlUrl) {
|
||||
// The HTML file will load the PDF twice in iframes.
|
||||
|
|
Loading…
Reference in New Issue