fix: build when pdf component is disabled (#33513)
This commit is contained in:
parent
b711860d21
commit
afe0116d59
9 changed files with 58 additions and 60 deletions
|
@ -12,9 +12,7 @@
|
|||
#include "base/command_line.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "chrome/common/pdf_util.h"
|
||||
#include "components/network_hints/renderer/web_prescient_networking_impl.h"
|
||||
#include "components/pdf/renderer/pdf_internal_plugin_delegate.h"
|
||||
#include "content/common/buildflags.h"
|
||||
#include "content/public/common/content_constants.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
|
@ -68,6 +66,9 @@
|
|||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
#include "chrome/common/pdf_util.h"
|
||||
#include "components/pdf/common/internal_plugin_helpers.h"
|
||||
#include "components/pdf/renderer/pdf_internal_plugin_delegate.h"
|
||||
#include "shell/common/electron_constants.h"
|
||||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
|
||||
|
@ -111,6 +112,25 @@ std::vector<std::string> ParseSchemesCLISwitch(base::CommandLine* command_line,
|
|||
base::SPLIT_WANT_NONEMPTY);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
class ChromePdfInternalPluginDelegate final
|
||||
: public pdf::PdfInternalPluginDelegate {
|
||||
public:
|
||||
ChromePdfInternalPluginDelegate() = default;
|
||||
ChromePdfInternalPluginDelegate(const ChromePdfInternalPluginDelegate&) =
|
||||
delete;
|
||||
ChromePdfInternalPluginDelegate& operator=(
|
||||
const ChromePdfInternalPluginDelegate&) = delete;
|
||||
~ChromePdfInternalPluginDelegate() override = default;
|
||||
|
||||
// `pdf::PdfInternalPluginDelegate`:
|
||||
bool IsAllowedOrigin(const url::Origin& origin) const override {
|
||||
return origin.scheme() == extensions::kExtensionScheme &&
|
||||
origin.host() == extension_misc::kPdfExtensionId;
|
||||
}
|
||||
};
|
||||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
|
||||
// static
|
||||
RendererClientBase* g_renderer_client_base = nullptr;
|
||||
|
||||
|
@ -311,29 +331,12 @@ void RendererClientBase::DidClearWindowObject(
|
|||
render_frame->GetWebFrame()->ExecuteScript(blink::WebScriptSource("void 0"));
|
||||
}
|
||||
|
||||
class ChromePdfInternalPluginDelegate final
|
||||
: public pdf::PdfInternalPluginDelegate {
|
||||
public:
|
||||
ChromePdfInternalPluginDelegate() = default;
|
||||
ChromePdfInternalPluginDelegate(const ChromePdfInternalPluginDelegate&) =
|
||||
delete;
|
||||
ChromePdfInternalPluginDelegate& operator=(
|
||||
const ChromePdfInternalPluginDelegate&) = delete;
|
||||
~ChromePdfInternalPluginDelegate() override = default;
|
||||
|
||||
// `pdf::PdfInternalPluginDelegate`:
|
||||
bool IsAllowedOrigin(const url::Origin& origin) const override {
|
||||
return origin.scheme() == extensions::kExtensionScheme &&
|
||||
origin.host() == extension_misc::kPdfExtensionId;
|
||||
}
|
||||
};
|
||||
|
||||
bool RendererClientBase::OverrideCreatePlugin(
|
||||
content::RenderFrame* render_frame,
|
||||
const blink::WebPluginParams& params,
|
||||
blink::WebPlugin** plugin) {
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
if (params.mime_type.Utf8() == kPdfPluginMimeType) {
|
||||
if (params.mime_type.Utf8() == pdf::kInternalPluginMimeType) {
|
||||
*plugin = pdf::CreateInternalPlugin(
|
||||
std::move(params), render_frame,
|
||||
std::make_unique<ChromePdfInternalPluginDelegate>());
|
||||
|
@ -342,7 +345,6 @@ bool RendererClientBase::OverrideCreatePlugin(
|
|||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
|
||||
if (params.mime_type.Utf8() == content::kBrowserPluginMimeType ||
|
||||
params.mime_type.Utf8() == kPdfPluginMimeType ||
|
||||
render_frame->GetBlinkPreferences().enable_plugins)
|
||||
return false;
|
||||
|
||||
|
@ -371,7 +373,7 @@ bool RendererClientBase::IsPluginHandledExternally(
|
|||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
DCHECK(plugin_element.HasHTMLTagName("object") ||
|
||||
plugin_element.HasHTMLTagName("embed"));
|
||||
if (mime_type == "application/x-google-chrome-pdf") {
|
||||
if (mime_type == pdf::kInternalPluginMimeType) {
|
||||
if (IsPdfInternalPluginAllowedOrigin(
|
||||
render_frame->GetWebFrame()->GetSecurityOrigin())) {
|
||||
return true;
|
||||
|
@ -379,11 +381,10 @@ bool RendererClientBase::IsPluginHandledExternally(
|
|||
|
||||
content::WebPluginInfo info;
|
||||
info.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS;
|
||||
const char16_t kPDFExtensionPluginName[] = u"Chromium PDF Viewer";
|
||||
info.name = kPDFExtensionPluginName;
|
||||
info.path = base::FilePath::FromUTF8Unsafe("internal-pdf-viewer");
|
||||
info.name = base::ASCIIToUTF16(kPDFInternalPluginName);
|
||||
info.path = base::FilePath(kPdfPluginPath);
|
||||
info.background_color = content::WebPluginInfo::kDefaultBackgroundColor;
|
||||
info.mime_types.emplace_back("application/x-google-chrome-pdf", "pdf",
|
||||
info.mime_types.emplace_back(pdf::kInternalPluginMimeType, "pdf",
|
||||
"Portable Document Format");
|
||||
return extensions::MimeHandlerViewContainerManager::Get(
|
||||
content::RenderFrame::FromWebFrame(
|
||||
|
@ -396,12 +397,10 @@ bool RendererClientBase::IsPluginHandledExternally(
|
|||
// electron_content_client.cc / ComputeBuiltInPlugins.
|
||||
content::WebPluginInfo info;
|
||||
info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN;
|
||||
const char16_t kPDFExtensionPluginName[] = u"Chromium PDF Viewer";
|
||||
info.name = kPDFExtensionPluginName;
|
||||
info.name = base::ASCIIToUTF16(kPDFExtensionPluginName);
|
||||
info.path = base::FilePath::FromUTF8Unsafe(extension_misc::kPdfExtensionId);
|
||||
info.background_color = content::WebPluginInfo::kDefaultBackgroundColor;
|
||||
info.mime_types.emplace_back("application/pdf", "pdf",
|
||||
"Portable Document Format");
|
||||
info.mime_types.emplace_back(kPDFMimeType, "pdf", "Portable Document Format");
|
||||
return extensions::MimeHandlerViewContainerManager::Get(
|
||||
content::RenderFrame::FromWebFrame(
|
||||
plugin_element.GetDocument().GetFrame()),
|
||||
|
@ -415,6 +414,7 @@ bool RendererClientBase::IsPluginHandledExternally(
|
|||
v8::Local<v8::Object> RendererClientBase::GetScriptableObject(
|
||||
const blink::WebElement& plugin_element,
|
||||
v8::Isolate* isolate) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
// If there is a MimeHandlerView that can provide the scriptable object then
|
||||
// MaybeCreateMimeHandlerView must have been called before and a container
|
||||
// manager should exist.
|
||||
|
@ -424,6 +424,7 @@ v8::Local<v8::Object> RendererClientBase::GetScriptableObject(
|
|||
false /* create_if_does_not_exist */);
|
||||
if (container_manager)
|
||||
return container_manager->GetScriptableObject(plugin_element, isolate);
|
||||
#endif
|
||||
return v8::Local<v8::Object>();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue