Commit 143099e3 authored by jzfeng's avatar jzfeng Committed by Commit bot

make headless lib complie when enable_basic_printing is set to false

There is a bug that headless lib doesn't complie when users set
enable_basic_printing to false in their args.gn file.

The patch ensure that the printing support is only avaliable when
enable_basic_printing is true.
When it is false, the PrintToPDF devtools command would return an error instead.

BUG=603559

Review-Url: https://codereview.chromium.org/2808653002
Cr-Commit-Position: refs/heads/master@{#463381}
parent 244727d0
......@@ -6,6 +6,7 @@ import("//build/config/chrome_build.gni")
import("//headless/headless.gni")
import("//build/util/process_version.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//printing/features/features.gni")
import("//testing/test.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")
......@@ -217,8 +218,6 @@ static_library("headless_lib") {
"lib/browser/headless_permission_manager.h",
"lib/browser/headless_platform_event_source.cc",
"lib/browser/headless_platform_event_source.h",
"lib/browser/headless_print_manager.cc",
"lib/browser/headless_print_manager.h",
"lib/browser/headless_shell_application_mac.mm",
"lib/browser/headless_shell_application_mac.h",
"lib/browser/headless_url_request_context_getter.cc",
......@@ -234,8 +233,6 @@ static_library("headless_lib") {
"lib/headless_content_main_delegate.h",
"lib/renderer/headless_content_renderer_client.cc",
"lib/renderer/headless_content_renderer_client.h",
"lib/renderer/headless_print_web_view_helper_delegate.cc",
"lib/renderer/headless_print_web_view_helper_delegate.h",
"public/headless_browser.cc",
"public/headless_browser.h",
"public/headless_browser_context.h",
......@@ -295,13 +292,20 @@ static_library("headless_lib") {
]
}
if (enable_basic_printing) {
sources += [
"lib/browser/headless_print_manager.cc",
"lib/browser/headless_print_manager.h",
"lib/renderer/headless_print_web_view_helper_delegate.cc",
"lib/renderer/headless_print_web_view_helper_delegate.h",
]
}
deps = [
":gen_devtools_client_api",
":version_header",
"//base",
"//components/crash/content/browser",
"//components/printing/browser",
"//components/printing/renderer",
"//components/security_state/content",
"//components/security_state/core",
"//content/public/app:both",
......@@ -323,6 +327,13 @@ static_library("headless_lib") {
deps += [ "//ui/aura" ]
}
if (enable_basic_printing) {
deps += [
"//components/printing/browser",
"//components/printing/renderer",
]
}
if (headless_use_embedded_resources) {
deps += [ ":embed_resources" ]
sources += [
......
......@@ -14,11 +14,15 @@
#include "headless/grit/headless_lib_resources.h"
#include "headless/lib/browser/headless_browser_context_impl.h"
#include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/browser/headless_print_manager.h"
#include "headless/lib/browser/headless_web_contents_impl.h"
#include "headless/public/devtools/domains/target.h"
#include "printing/features/features.h"
#include "ui/base/resource/resource_bundle.h"
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
#include "headless/lib/browser/headless_print_manager.h"
#endif
namespace headless {
namespace {
......@@ -68,6 +72,7 @@ std::unique_ptr<base::DictionaryValue> CreateInvalidParamResponse(
base::StringPrintf("Missing or invalid '%s' parameter", param.c_str()));
}
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
void PDFCreated(
const content::DevToolsManagerDelegate::CommandCallback& callback,
int command_id,
......@@ -85,6 +90,7 @@ void PDFCreated(
}
callback.Run(std::move(response));
}
#endif
} // namespace
......@@ -183,11 +189,17 @@ void HeadlessDevToolsManagerDelegate::PrintToPDF(
int command_id,
const base::DictionaryValue* params,
const CommandCallback& callback) {
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
content::WebContents* web_contents = agent_host->GetWebContents();
content::RenderFrameHost* rfh = web_contents->GetMainFrame();
printing::HeadlessPrintManager::FromWebContents(web_contents)
->GetPDFContents(rfh, base::Bind(&PDFCreated, callback, command_id));
#else
DCHECK(callback);
callback.Run(CreateErrorResponse(command_id, kErrorServerError,
"Printing is not enabled"));
#endif
}
std::unique_ptr<base::DictionaryValue>
......
......@@ -31,9 +31,13 @@
#include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/browser/headless_browser_main_parts.h"
#include "headless/lib/browser/headless_devtools_client_impl.h"
#include "headless/lib/browser/headless_print_manager.h"
#include "printing/features/features.h"
#include "services/service_manager/public/cpp/interface_registry.h"
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
#include "headless/lib/browser/headless_print_manager.h"
#endif
namespace headless {
// static
......@@ -174,7 +178,9 @@ HeadlessWebContentsImpl::HeadlessWebContentsImpl(
agent_host_(content::DevToolsAgentHost::GetOrCreateFor(web_contents)),
browser_context_(browser_context),
render_process_host_(web_contents->GetRenderProcessHost()) {
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
printing::HeadlessPrintManager::CreateForWebContents(web_contents);
#endif
web_contents_->SetDelegate(web_contents_delegate_.get());
render_process_host_->AddObserver(this);
}
......
include_rules = [
"+components/printing/renderer",
"+content/public/renderer",
"+printing",
"+third_party/WebKit/public",
]
\ No newline at end of file
]
......@@ -5,8 +5,12 @@
#include "headless/lib/renderer/headless_content_renderer_client.h"
#include "base/memory/ptr_util.h"
#include "printing/features/features.h"
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
#include "components/printing/renderer/print_web_view_helper.h"
#include "headless/lib/renderer/headless_print_web_view_helper_delegate.h"
#endif
namespace headless {
......@@ -16,8 +20,10 @@ HeadlessContentRendererClient::~HeadlessContentRendererClient() {}
void HeadlessContentRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
new printing::PrintWebViewHelper(
render_frame, base::MakeUnique<HeadlessPrintWebViewHelperDelegate>());
#endif
}
} // namespace headless
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment