mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
move pdf viewer behind feature flag
This commit is contained in:
committed by
Aleksei Kuzmin
parent
c1908147a9
commit
4b39d17e5f
@@ -7,7 +7,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/atom_version.h"
|
||||
#include "atom/common/chrome_version.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
@@ -20,7 +19,6 @@
|
||||
#include "content/public/common/pepper_plugin_info.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "media/media_features.h"
|
||||
#include "pdf/pdf.h"
|
||||
#include "ppapi/shared_impl/ppapi_permissions.h"
|
||||
#include "third_party/widevine/cdm/stub/widevine_cdm_version.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
@@ -30,6 +28,11 @@
|
||||
#include "chrome/common/widevine_cdm_constants.h"
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "pdf/pdf.h"
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
@@ -111,6 +114,7 @@ content::PepperPluginInfo CreateWidevineCdmInfo(const base::FilePath& path,
|
||||
}
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
|
||||
content::PepperPluginInfo pdf_info;
|
||||
pdf_info.is_internal = true;
|
||||
@@ -129,6 +133,7 @@ void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
|
||||
pdf_info.permissions = ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV;
|
||||
plugins->push_back(pdf_info);
|
||||
}
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
void ConvertStringWithSeparatorToVector(std::vector<std::string>* vec,
|
||||
const char* separator,
|
||||
@@ -220,7 +225,9 @@ void AtomContentClient::AddPepperPlugins(
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
AddWidevineCdmFromCommandLine(plugins);
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
ComputeBuiltInPlugins(plugins);
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "atom/browser/atom_access_token_store.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_web_ui_controller_factory.h"
|
||||
#include "atom/browser/bridge_task_runner.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/javascript_environment.h"
|
||||
@@ -33,6 +32,10 @@
|
||||
#include "ui/events/devices/x11/touch_factory_x11.h"
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
#include "atom/browser/atom_web_ui_controller_factory.h"
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
@@ -186,8 +189,10 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
||||
base::Bind(&v8::Isolate::LowMemoryNotification,
|
||||
base::Unretained(js_env_->isolate())));
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
content::WebUIControllerFactory::RegisterFactory(
|
||||
AtomWebUIControllerFactory::GetInstance());
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
brightray::BrowserMainParts::PreMainMessageLoopRun();
|
||||
bridge_task_runner_->MessageLoopIsReady();
|
||||
|
||||
@@ -8,17 +8,13 @@
|
||||
#include "atom/browser/login_handler.h"
|
||||
#include "atom/browser/web_contents_permission_helper.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/platform_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/download_manager.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/stream_info.h"
|
||||
#include "net/base/escape.h"
|
||||
#include "net/ssl/client_cert_store.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
#if defined(USE_NSS_CERTS)
|
||||
@@ -29,6 +25,14 @@
|
||||
#include "net/ssl/client_cert_store_mac.h"
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "content/public/browser/stream_info.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
@@ -65,6 +69,7 @@ void HandleExternalProtocolInUI(
|
||||
url);
|
||||
}
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
void OnPdfResourceIntercepted(
|
||||
const GURL& original_url,
|
||||
int render_process_host_id,
|
||||
@@ -102,6 +107,7 @@ void OnPdfResourceIntercepted(
|
||||
params.frame_tree_node_id = frame_host->GetFrameTreeNodeId();
|
||||
web_contents->GetController().LoadURLWithParams(params);
|
||||
}
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -145,6 +151,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
|
||||
const std::string& mime_type,
|
||||
GURL* origin,
|
||||
std::string* payload) {
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
const content::ResourceRequestInfo* info =
|
||||
content::ResourceRequestInfo::ForRequest(request);
|
||||
|
||||
@@ -164,6 +171,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
|
||||
info->GetWebContentsGetterForRequest()));
|
||||
return true;
|
||||
}
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
#include "atom/browser/ui/webui/pdf_viewer_ui.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "net/base/escape.h"
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -27,9 +29,11 @@ AtomWebUIControllerFactory::~AtomWebUIControllerFactory() {}
|
||||
content::WebUI::TypeID AtomWebUIControllerFactory::GetWebUIType(
|
||||
content::BrowserContext* browser_context,
|
||||
const GURL& url) const {
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
if (url.host() == kPdfViewerUIHost) {
|
||||
return const_cast<AtomWebUIControllerFactory*>(this);
|
||||
}
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
return content::WebUI::kNoWebUI;
|
||||
}
|
||||
@@ -49,6 +53,7 @@ bool AtomWebUIControllerFactory::UseWebUIBindingsForURL(
|
||||
content::WebUIController*
|
||||
AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
|
||||
const GURL& url) const {
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
if (url.host() == kPdfViewerUIHost) {
|
||||
base::StringPairs toplevel_params;
|
||||
base::SplitStringIntoKeyValuePairs(url.query(), '=', '&', &toplevel_params);
|
||||
@@ -70,6 +75,7 @@ AtomWebUIControllerFactory::CreateWebUIControllerForURL(content::WebUI* web_ui,
|
||||
auto browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
||||
return new PdfViewerUI(browser_context, web_ui, src);
|
||||
}
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ENABLE_PDF_VIEWER
|
||||
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
#include "atom/browser/ui/webui/pdf_viewer_handler.h"
|
||||
|
||||
#include "atom/common/atom_constants.h"
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ENABLE_PDF_VIEWER
|
||||
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
#ifndef ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_HANDLER_H_
|
||||
#define ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_HANDLER_H_
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ENABLE_PDF_VIEWER
|
||||
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
#include "atom/browser/ui/webui/pdf_viewer_ui.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ENABLE_PDF_VIEWER
|
||||
#error("This header can only be used when enable_pdf_viewer gyp flag is enabled")
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
#ifndef ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
|
||||
#define ATOM_BROWSER_UI_WEBUI_PDF_VIEWER_UI_H_
|
||||
|
||||
|
||||
@@ -24,11 +24,13 @@ const char kSecureProtocolDescription[] =
|
||||
"The connection to this site is using a strong protocol version "
|
||||
"and cipher suite.";
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
const char kPdfPluginMimeType[] = "application/x-google-chrome-pdf";
|
||||
const char kPdfPluginPath[] = "chrome://pdf-viewer/";
|
||||
const char kPdfPluginSrc[] = "src";
|
||||
|
||||
const char kPdfViewerUIOrigin[] = "chrome://pdf-viewer/";
|
||||
const char kPdfViewerUIHost[] = "pdf-viewer";
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -20,6 +20,7 @@ extern const char kValidCertificateDescription[];
|
||||
extern const char kSecureProtocol[];
|
||||
extern const char kSecureProtocolDescription[];
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
// The MIME type used for the PDF plugin.
|
||||
extern const char kPdfPluginMimeType[];
|
||||
extern const char kPdfPluginPath[];
|
||||
@@ -28,6 +29,7 @@ extern const char kPdfPluginSrc[];
|
||||
// Constants for PDF viewer webui.
|
||||
extern const char kPdfViewerUIOrigin[];
|
||||
extern const char kPdfViewerUIHost[];
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
} // namespace atom
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "atom/common/api/atom_bindings.h"
|
||||
#include "atom/common/api/event_emitter_caller.h"
|
||||
#include "atom/common/asar/asar_util.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/node_bindings.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "atom/renderer/api/atom_api_renderer_ipc.h"
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/color_util.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
@@ -44,6 +43,10 @@
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
#include "atom/common/atom_constants.h"
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
@@ -153,9 +156,11 @@ void RendererClientBase::RenderFrameCreated(
|
||||
// This is required for widevine plugin detection provided during runtime.
|
||||
blink::ResetPluginCache();
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
// Allow access to file scheme from pdf viewer.
|
||||
blink::WebSecurityPolicy::AddOriginAccessWhitelistEntry(
|
||||
GURL(kPdfViewerUIOrigin), "file", "", true);
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
}
|
||||
|
||||
void RendererClientBase::RenderViewCreated(content::RenderView* render_view) {
|
||||
@@ -192,7 +197,9 @@ bool RendererClientBase::OverrideCreatePlugin(
|
||||
blink::WebPlugin** plugin) {
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (params.mime_type.Utf8() == content::kBrowserPluginMimeType ||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
params.mime_type.Utf8() == kPdfPluginMimeType ||
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
command_line->HasSwitch(switches::kEnablePlugins))
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user