refactor: remove references to non-existent webui (#20867)
This commit is contained in:
parent
f645ca015f
commit
85647dfced
17 changed files with 395 additions and 174 deletions
|
@ -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);
|
||||
|
|
|
@ -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_ =
|
||||
|
|
20
shell/browser/electron_pdf_web_contents_helper_client.cc
Normal file
20
shell/browser/electron_pdf_web_contents_helper_client.cc
Normal 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) {}
|
28
shell/browser/electron_pdf_web_contents_helper_client.h
Normal file
28
shell/browser/electron_pdf_web_contents_helper_client.h
Normal 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_
|
Loading…
Add table
Add a link
Reference in a new issue