refactor: remove references to non-existent webui (#20867)

This commit is contained in:
Jeremy Apthorp 2019-11-04 09:50:31 -08:00 committed by GitHub
parent f645ca015f
commit 85647dfced
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 395 additions and 174 deletions

View file

@ -32,9 +32,10 @@
#endif // defined(WIDEVINE_CDM_AVAILABLE)
#if BUILDFLAG(ENABLE_PDF_VIEWER)
#include "pdf/pdf.h"
#include "shell/common/atom_constants.h"
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
#include "pdf/pdf.h" // nogncheck
#include "pdf/pdf_ppapi.h" // nogncheck
#include "shell/common/atom_constants.h" // nogncheck
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
#if BUILDFLAG(ENABLE_PLUGINS)
#include "content/public/common/pepper_plugin_info.h"
@ -153,7 +154,7 @@ void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
pdf_info.is_out_of_process = true;
pdf_info.name = "Chromium PDF Viewer";
pdf_info.description = "Portable Document Format";
pdf_info.path = base::FilePath::FromUTF8Unsafe(kPdfPluginPath);
pdf_info.path = base::FilePath(FILE_PATH_LITERAL("internal-pdf-viewer"));
content::WebPluginMimeType pdf_mime_type(kPdfPluginMimeType, "pdf",
"Portable Document Format");
pdf_info.mime_types.push_back(pdf_mime_type);
@ -162,7 +163,7 @@ void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
chrome_pdf::PPP_InitializeModule;
pdf_info.internal_entry_points.shutdown_module =
chrome_pdf::PPP_ShutdownModule;
pdf_info.permissions = ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV;
pdf_info.permissions = ppapi::PERMISSION_PDF | ppapi::PERMISSION_DEV;
plugins->push_back(pdf_info);
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
}

View file

@ -6,17 +6,8 @@
#include <string>
#include "electron/buildflags/buildflags.h"
#if BUILDFLAG(ENABLE_PDF_VIEWER)
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "net/base/escape.h"
#include "shell/browser/ui/webui/pdf_viewer_ui.h"
#include "shell/common/atom_constants.h"
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
#include "content/public/browser/web_contents.h"
#include "electron/buildflags/buildflags.h"
#include "shell/browser/ui/devtools_ui.h"
namespace electron {
@ -39,11 +30,6 @@ AtomWebUIControllerFactory::~AtomWebUIControllerFactory() = default;
content::WebUI::TypeID AtomWebUIControllerFactory::GetWebUIType(
content::BrowserContext* browser_context,
const GURL& url) {
#if BUILDFLAG(ENABLE_PDF_VIEWER)
if (url.host() == kPdfViewerUIHost) {
return const_cast<AtomWebUIControllerFactory*>(this);
}
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
if (url.host() == kChromeUIDevToolsBundledHost) {
return const_cast<AtomWebUIControllerFactory*>(this);
}
@ -66,29 +52,6 @@ bool AtomWebUIControllerFactory::UseWebUIBindingsForURL(
std::unique_ptr<content::WebUIController>
AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
const GURL& url) {
#if BUILDFLAG(ENABLE_PDF_VIEWER)
if (url.host() == kPdfViewerUIHost) {
base::StringPairs toplevel_params;
base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params);
std::string src;
const net::UnescapeRule::Type unescape_rules =
net::UnescapeRule::SPACES | net::UnescapeRule::PATH_SEPARATORS |
net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
net::UnescapeRule::REPLACE_PLUS_WITH_SPACE;
for (const auto& param : toplevel_params) {
if (param.first == kPdfPluginSrc) {
src = net::UnescapeURLComponent(param.second, unescape_rules);
}
}
if (url.has_ref()) {
src = src + '#' + url.ref();
}
auto browser_context = web_ui->GetWebContents()->GetBrowserContext();
return new PdfViewerUI(browser_context, web_ui, src);
}
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
if (url.host() == kChromeUIDevToolsBundledHost) {
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
return std::make_unique<DevToolsUI>(browser_context, web_ui);

View file

@ -59,6 +59,11 @@
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
#endif
#if BUILDFLAG(ENABLE_PDF_VIEWER)
#include "components/pdf/browser/pdf_web_contents_helper.h" // nogncheck
#include "shell/browser/electron_pdf_web_contents_helper_client.h"
#endif
using content::BrowserThread;
namespace electron {
@ -198,6 +203,11 @@ void CommonWebContentsDelegate::InitWithWebContents(
browser_context->GetUserAgent());
#endif
#if BUILDFLAG(ENABLE_PDF_VIEWER)
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>());
#endif
// Determien whether the WebContents is offscreen.
auto* web_preferences = WebContentsPreferences::From(web_contents);
offscreen_ =

View file

@ -0,0 +1,20 @@
// Copyright (c) 2015 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/electron_pdf_web_contents_helper_client.h"
ElectronPDFWebContentsHelperClient::ElectronPDFWebContentsHelperClient() {}
ElectronPDFWebContentsHelperClient::~ElectronPDFWebContentsHelperClient() =
default;
void ElectronPDFWebContentsHelperClient::UpdateContentRestrictions(
content::WebContents* contents,
int content_restrictions) {}
void ElectronPDFWebContentsHelperClient::OnPDFHasUnsupportedFeature(
content::WebContents* contents) {}
void ElectronPDFWebContentsHelperClient::OnSaveURL(
content::WebContents* contents) {}
void ElectronPDFWebContentsHelperClient::SetPluginCanSave(
content::WebContents* contents,
bool can_save) {}

View file

@ -0,0 +1,28 @@
// Copyright (c) 2015 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_ELECTRON_PDF_WEB_CONTENTS_HELPER_CLIENT_H_
#define SHELL_BROWSER_ELECTRON_PDF_WEB_CONTENTS_HELPER_CLIENT_H_
#include "components/pdf/browser/pdf_web_contents_helper_client.h"
namespace content {
class WebContents;
}
class ElectronPDFWebContentsHelperClient
: public pdf::PDFWebContentsHelperClient {
public:
ElectronPDFWebContentsHelperClient();
~ElectronPDFWebContentsHelperClient() override;
private:
// pdf::PDFWebContentsHelperClient
void UpdateContentRestrictions(content::WebContents* contents,
int content_restrictions) override;
void OnPDFHasUnsupportedFeature(content::WebContents* contents) override;
void OnSaveURL(content::WebContents* contents) override;
void SetPluginCanSave(content::WebContents* contents, bool can_save) override;
};
#endif // SHELL_BROWSER_ELECTRON_PDF_WEB_CONTENTS_HELPER_CLIENT_H_

View file

@ -0,0 +1,107 @@
// Copyright (c) 2012 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 "shell/renderer/electron_renderer_pepper_host_factory.h"
#include <memory>
#include <string>
#include "base/logging.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/ppapi_message_utils.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
using ppapi::host::ResourceHost;
// Stub class which ignores all messages
class PepperUMAHost : public ppapi::host::ResourceHost {
public:
PepperUMAHost(content::RendererPpapiHost* host,
PP_Instance instance,
PP_Resource resource)
: ResourceHost(host->GetPpapiHost(), instance, resource) {}
~PepperUMAHost() override = default;
// ppapi::host::ResourceMessageHandler implementation.
int32_t OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) override {
PPAPI_BEGIN_MESSAGE_MAP(PepperUMAHost, msg)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomTimes,
OnHistogramCustomTimes)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramCustomCounts,
OnHistogramCustomCounts)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramEnumeration,
OnHistogramEnumeration)
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
PpapiHostMsg_UMA_IsCrashReportingEnabled, OnIsCrashReportingEnabled)
PPAPI_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
private:
int32_t OnHistogramCustomTimes(ppapi::host::HostMessageContext* context,
const std::string& name,
int64_t sample,
int64_t min,
int64_t max,
uint32_t bucket_count) {
return PP_OK;
}
int32_t OnHistogramCustomCounts(ppapi::host::HostMessageContext* context,
const std::string& name,
int32_t sample,
int32_t min,
int32_t max,
uint32_t bucket_count) {
return PP_OK;
}
int32_t OnHistogramEnumeration(ppapi::host::HostMessageContext* context,
const std::string& name,
int32_t sample,
int32_t boundary_value) {
return PP_OK;
}
int32_t OnIsCrashReportingEnabled(ppapi::host::HostMessageContext* context) {
return PP_OK;
}
};
ElectronRendererPepperHostFactory::ElectronRendererPepperHostFactory(
content::RendererPpapiHost* host)
: host_(host) {}
ElectronRendererPepperHostFactory::~ElectronRendererPepperHostFactory() {}
std::unique_ptr<ResourceHost>
ElectronRendererPepperHostFactory::CreateResourceHost(
ppapi::host::PpapiHost* host,
PP_Resource resource,
PP_Instance instance,
const IPC::Message& message) {
DCHECK_EQ(host_->GetPpapiHost(), host);
// Make sure the plugin is giving us a valid instance for this resource.
if (!host_->IsValidInstance(instance))
return nullptr;
// Permissions for the following interfaces will be checked at the
// time of the corresponding instance's method calls. Currently these
// interfaces are available only for whitelisted apps which may not have
// access to the other private interfaces.
switch (message.type()) {
case PpapiHostMsg_UMA_Create::ID: {
return std::make_unique<PepperUMAHost>(host_, instance, resource);
}
}
return nullptr;
}

View file

@ -0,0 +1,37 @@
// Copyright (c) 2012 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 SHELL_RENDERER_ELECTRON_RENDERER_PEPPER_HOST_FACTORY_H_
#define SHELL_RENDERER_ELECTRON_RENDERER_PEPPER_HOST_FACTORY_H_
#include <memory>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "ppapi/host/host_factory.h"
namespace content {
class RendererPpapiHost;
}
class ElectronRendererPepperHostFactory : public ppapi::host::HostFactory {
public:
explicit ElectronRendererPepperHostFactory(content::RendererPpapiHost* host);
~ElectronRendererPepperHostFactory() override;
// HostFactory.
std::unique_ptr<ppapi::host::ResourceHost> CreateResourceHost(
ppapi::host::PpapiHost* host,
PP_Resource resource,
PP_Instance instance,
const IPC::Message& message) override;
private:
// Not owned by this object.
content::RendererPpapiHost* host_;
DISALLOW_COPY_AND_ASSIGN(ElectronRendererPepperHostFactory);
};
#endif // SHELL_RENDERER_ELECTRON_RENDERER_PEPPER_HOST_FACTORY_H_

View file

@ -0,0 +1,33 @@
// Copyright (c) 2012 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 "shell/renderer/pepper_helper.h"
#include <memory>
#include "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
#include "chrome/renderer/pepper/pepper_shared_memory_message_filter.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "electron/shell/renderer/electron_renderer_pepper_host_factory.h"
#include "ppapi/host/ppapi_host.h"
PepperHelper::PepperHelper(content::RenderFrame* render_frame)
: RenderFrameObserver(render_frame) {}
PepperHelper::~PepperHelper() {}
void PepperHelper::DidCreatePepperPlugin(content::RendererPpapiHost* host) {
// TODO(brettw) figure out how to hook up the host factory. It needs some
// kind of filter-like system to allow dynamic additions.
host->GetPpapiHost()->AddHostFactoryFilter(
std::make_unique<ChromeRendererPepperHostFactory>(host));
host->GetPpapiHost()->AddHostFactoryFilter(
std::make_unique<ElectronRendererPepperHostFactory>(host));
host->GetPpapiHost()->AddInstanceMessageFilter(
std::make_unique<PepperSharedMemoryMessageFilter>(host));
}
void PepperHelper::OnDestruct() {
delete this;
}

View file

@ -0,0 +1,28 @@
// Copyright (c) 2012 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 SHELL_RENDERER_PEPPER_HELPER_H_
#define SHELL_RENDERER_PEPPER_HELPER_H_
#include "base/compiler_specific.h"
#include "base/component_export.h"
#include "base/macros.h"
#include "content/public/renderer/render_frame_observer.h"
// This class listens for Pepper creation events from the RenderFrame and
// attaches the parts required for plugin support.
class PepperHelper : public content::RenderFrameObserver {
public:
explicit PepperHelper(content::RenderFrame* render_frame);
~PepperHelper() override;
// RenderFrameObserver.
void DidCreatePepperPlugin(content::RendererPpapiHost* host) override;
void OnDestruct() override;
private:
DISALLOW_COPY_AND_ASSIGN(PepperHelper);
};
#endif // SHELL_RENDERER_PEPPER_HELPER_H_

View file

@ -55,9 +55,9 @@
#include "shell/common/atom_constants.h"
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
#if BUILDFLAG(ENABLE_PEPPER_FLASH)
#include "chrome/renderer/pepper/pepper_helper.h"
#endif // BUILDFLAG(ENABLE_PEPPER_FLASH)
#if BUILDFLAG(ENABLE_PLUGINS)
#include "shell/renderer/pepper_helper.h"
#endif // BUILDFLAG(ENABLE_PLUGINS)
#if BUILDFLAG(ENABLE_PRINTING)
#include "components/printing/renderer/print_render_frame_helper.h"
@ -227,7 +227,7 @@ void RendererClientBase::RenderFrameCreated(
new AutofillAgent(render_frame,
render_frame->GetAssociatedInterfaceRegistry());
#endif
#if BUILDFLAG(ENABLE_PEPPER_FLASH)
#if BUILDFLAG(ENABLE_PLUGINS)
new PepperHelper(render_frame);
#endif
new ContentSettingsObserver(render_frame);
@ -244,12 +244,6 @@ void RendererClientBase::RenderFrameCreated(
base::BindRepeating(&ElectronApiServiceImpl::BindTo,
service->GetWeakPtr()));
#if BUILDFLAG(ENABLE_PDF_VIEWER)
// Allow access to file scheme from pdf viewer.
blink::WebSecurityPolicy::AddOriginAccessWhitelistEntry(
GURL(kPdfViewerUIOrigin), "file", "", true);
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
content::RenderView* render_view = render_frame->GetRenderView();
if (render_frame->IsMainFrame() && render_view) {
blink::WebView* webview = render_view->GetWebView();