зеркало из https://github.com/electron/electron.git
test: add -pdf-ready-to-print event to WebContents for testing (#43652)
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
Родитель
4bc1221864
Коммит
0009a19ce6
1
BUILD.gn
1
BUILD.gn
|
@ -743,6 +743,7 @@ source_set("electron_lib") {
|
||||||
"//components/pdf/common:constants",
|
"//components/pdf/common:constants",
|
||||||
"//components/pdf/renderer",
|
"//components/pdf/renderer",
|
||||||
"//pdf",
|
"//pdf",
|
||||||
|
"//pdf:content_restriction",
|
||||||
]
|
]
|
||||||
sources += [
|
sources += [
|
||||||
"shell/browser/electron_pdf_document_helper_client.cc",
|
"shell/browser/electron_pdf_document_helper_client.cc",
|
||||||
|
|
|
@ -3726,6 +3726,10 @@ void WebContents::OnInputEvent(const blink::WebInputEvent& event) {
|
||||||
Emit("input-event", event);
|
Emit("input-event", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::PDFReadyToPrint() {
|
||||||
|
Emit("-pdf-ready-to-print");
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::RunJavaScriptDialog(content::WebContents* web_contents,
|
void WebContents::RunJavaScriptDialog(content::WebContents* web_contents,
|
||||||
content::RenderFrameHost* rfh,
|
content::RenderFrameHost* rfh,
|
||||||
content::JavaScriptDialogType dialog_type,
|
content::JavaScriptDialogType dialog_type,
|
||||||
|
|
|
@ -479,6 +479,8 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
|
|
||||||
void SetBackgroundColor(std::optional<SkColor> color);
|
void SetBackgroundColor(std::optional<SkColor> color);
|
||||||
|
|
||||||
|
void PDFReadyToPrint();
|
||||||
|
|
||||||
SkRegion* draggable_region() {
|
SkRegion* draggable_region() {
|
||||||
return force_non_draggable_ ? nullptr : draggable_region_.get();
|
return force_non_draggable_ ? nullptr : draggable_region_.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include "chrome/browser/pdf/pdf_frame_util.h"
|
#include "chrome/browser/pdf/pdf_frame_util.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
#include "pdf/content_restriction.h"
|
||||||
|
#include "shell/browser/api/electron_api_web_contents.h"
|
||||||
|
|
||||||
ElectronPDFDocumentHelperClient::ElectronPDFDocumentHelperClient() = default;
|
ElectronPDFDocumentHelperClient::ElectronPDFDocumentHelperClient() = default;
|
||||||
ElectronPDFDocumentHelperClient::~ElectronPDFDocumentHelperClient() = default;
|
ElectronPDFDocumentHelperClient::~ElectronPDFDocumentHelperClient() = default;
|
||||||
|
@ -20,11 +22,21 @@ content::RenderFrameHost* ElectronPDFDocumentHelperClient::FindPdfFrame(
|
||||||
|
|
||||||
void ElectronPDFDocumentHelperClient::UpdateContentRestrictions(
|
void ElectronPDFDocumentHelperClient::UpdateContentRestrictions(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
int content_restrictions) {}
|
int content_restrictions) {
|
||||||
void ElectronPDFDocumentHelperClient::OnPDFHasUnsupportedFeature(
|
// UpdateContentRestrictions potentially gets called twice from
|
||||||
content::WebContents* contents) {}
|
// pdf/pdf_view_web_plugin.cc. The first time it is potentially called is
|
||||||
void ElectronPDFDocumentHelperClient::OnSaveURL(
|
// when loading starts and it is called with a restriction on printing. The
|
||||||
content::WebContents* contents) {}
|
// second time it is called is when loading is finished and if printing is
|
||||||
void ElectronPDFDocumentHelperClient::SetPluginCanSave(
|
// allowed there won't be a printing restriction passed, so we can use this
|
||||||
content::RenderFrameHost* render_frame_host,
|
// second call to notify that the pdf document is ready to print.
|
||||||
bool can_save) {}
|
if (!(content_restrictions & chrome_pdf::kContentRestrictionPrint)) {
|
||||||
|
content::WebContents* web_contents =
|
||||||
|
content::WebContents::FromRenderFrameHost(render_frame_host);
|
||||||
|
electron::api::WebContents* api_web_contents =
|
||||||
|
electron::api::WebContents::From(
|
||||||
|
web_contents->GetOutermostWebContents());
|
||||||
|
if (api_web_contents) {
|
||||||
|
api_web_contents->PDFReadyToPrint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ class ElectronPDFDocumentHelperClient : public pdf::PDFDocumentHelperClient {
|
||||||
content::WebContents* contents) override;
|
content::WebContents* contents) override;
|
||||||
void UpdateContentRestrictions(content::RenderFrameHost* render_frame_host,
|
void UpdateContentRestrictions(content::RenderFrameHost* render_frame_host,
|
||||||
int content_restrictions) override;
|
int content_restrictions) override;
|
||||||
void OnPDFHasUnsupportedFeature(content::WebContents* contents) override;
|
void OnPDFHasUnsupportedFeature(content::WebContents* contents) override {}
|
||||||
void OnSaveURL(content::WebContents* contents) override;
|
void OnSaveURL(content::WebContents* contents) override {}
|
||||||
void SetPluginCanSave(content::RenderFrameHost* render_frame_host,
|
void SetPluginCanSave(content::RenderFrameHost* render_frame_host,
|
||||||
bool can_save) override;
|
bool can_save) override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_PDF_DOCUMENT_HELPER_CLIENT_H_
|
#endif // ELECTRON_SHELL_BROWSER_ELECTRON_PDF_DOCUMENT_HELPER_CLIENT_H_
|
||||||
|
|
Загрузка…
Ссылка в новой задаче