diff --git a/.gitignore b/.gitignore index 5c30efe..9c89ef7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ cef/ +.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index 62c9844..4874eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,36 +1,38 @@ Changelog === +### 0.3.0 (2017-06-18) +* Building with CEF 3.3071.1640.g1ebbf3c / Chromium 59.0.3071.82 (Windows, Linux & OS X, 64bit) +* Now possible to build on Mac OS X. Tested on 10.11.6 with XCode ver. 8.2.0. Experimental +* Bug fixes. Code cleanup and better formatting + ### 0.2.1 (2016-12-20) -* Allow only specified schemes when in server mode (ie. block file:// access) -* Added option to enable JavaScript --javascript -* Added --file option to load file from command line -* Disabled standard input (use --file instead) -* Added --background option to print html backgrounds -* Bulding with CEF 3.2883.1540.gedbfb20 / Chromium 55.0.2883.59 version (Windows & Linux, 64bit) +* Bulding with CEF 3.2883.1540.gedbfb20 / Chromium 55.0.2883.59 (Windows & Linux, 64bit) +* Allow only specified schemes when in server mode (ie. block `file://` access) +* Added option to enable JavaScript `--javascript` +* Added `--file` option to load file from command line +* Disabled standard input (use `--file` instead) +* Added `--background` option to print html backgrounds -=== ### 0.2.0 (2016-11-29) -* Added HTTP server mode (use with --server flag) -* Added configurable --host and --port when running in server mode +* Bulding with CEF 3.2883.1539.gd7f087e / Chromium 55.0.2883.59 (Windows & Linux, 64bit) +* Added HTTP server mode (use with `--server` flag) +* Added configurable `--host` and `--port` options when running in server mode * Various fixes and improvements -* Bulding with CEF 3.2883.1539.gd7f087e / Chromium 55.0.2883.59 version (Windows & Linux, 64bit) -=== ### 0.1.6 (2016-09-21) -* Fix: small improvements to allow building on Linux (tested on Debian 8.5.0 x64) * Small changes to build using CEF 3.2743.1449.g90ba67d build +* Small improvements to allow building on Linux (tested on Debian 8.5.0 x64) -=== ### 0.1.5 (2016-09-15) -* Add: option to set page margin --margin -* Add: option to list available page sizes --list-sizes -* Change: url is now specified with --url option +* Added option to set page margin `--margin` +* Added option to list available page sizes `--list-sizes` +* Changed url to be specified with `--url` option * Heavy code refractoring ### 0.1.1 (2016-08-06) -* Add: some paper sizes: US, ANSI and photo -* Add: help message -* Fix: url load error handling +* Added some more paper sizes: US, ANSI and photo +* Added help message +* Fixed url load error handling ### 0.1.0 (2016-08-03) * Initial release. Working version :) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5622eb..9be9132 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,9 @@ cmake_minimum_required(VERSION 2.8.12.1) -set(USE_SANDBOX OFF) -set(USE_ATL OFF) +if(APPLE) + set(PROJECT_ARCH x86_64) +endif() # Only generate Debug and Release configuration types. set(CMAKE_CONFIGURATION_TYPES Debug Release) @@ -156,7 +157,7 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON) # files as an example. # D. Comment in these lines: # -set(CEF_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/cef") +set(CEF_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/cef" CACHE STRING "Directory where CEF release is located") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake") # Example 3: The binary distribution is in a separate directory from your @@ -200,14 +201,15 @@ find_package(CEF REQUIRED) # directory. add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper) +set(USE_SANDBOX OFF) +set(USE_ATL OFF) + include_directories("asio") add_definitions(-DASIO_STANDALONE -DASIO_NO_TYPEID) # Include application targets. # Comes from the /CMakeLists.txt file in the current directory. # TODO: Change these lines to match your project target when you copy this file. -#add_subdirectory(cefclient) -#add_subdirectory(cefsimple) add_subdirectory(src) # Display configuration settings. diff --git a/README.md b/README.md index ad74326..990b57b 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,7 @@ In addition to POSTing content inside the request body, special HTTP header `Con ### Building -In order to build, [CEF build distribution files](http://opensource.spotify.com/cefbuilds/index.html) must be placed in cef/ subdirectory. `cef-pdf` should compile without problems with cmake/ninja on Windows 7+ and Linux (tested on Debian 8.5.0 x64), using decent C++11 compiler. Mac OS X needs some work (contributors welcome). - -### TODO - - - Mac OS X versions - - Improve performance +In order to build, [CEF build distribution files](http://opensource.spotify.com/cefbuilds/index.html) must be placed in cef/ subdirectory. `cef-pdf` should compile without problems with cmake/ninja on Windows (7, x64), Linux (tested on Debian 8.5.0, x64) and Mac OS X (10.11.6) using decent C++11 compiler. ### License diff --git a/resource/Info.plist b/resource/Info.plist new file mode 100644 index 0000000..508e80f --- /dev/null +++ b/resource/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${PRODUCT_NAME} + CFBundleIdentifier + org.cef.cef-pdf.helper + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0.0 + CFBundleVersion + 1.0.0 + LSMinimumSystemVersion + 10.9.0 + LSUIElement + 1 + NSSupportsAutomaticGraphicsSwitching + + NSHumanReadableCopyright + © 2017, cef-pdf + + diff --git a/src/cef-pdf.exe.manifest b/resource/cef-pdf.exe.manifest similarity index 100% rename from src/cef-pdf.exe.manifest rename to resource/cef-pdf.exe.manifest diff --git a/src/compatibility.manifest b/resource/compatibility.manifest similarity index 100% rename from src/compatibility.manifest rename to resource/compatibility.manifest diff --git a/resource/helper-Info.plist b/resource/helper-Info.plist new file mode 100644 index 0000000..82fdb11 --- /dev/null +++ b/resource/helper-Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${PRODUCT_NAME} + CFBundleIdentifier + org.cef.cefsimple.helper + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0.0 + CFBundleVersion + 1.0.0 + LSFileQuarantineEnabled + + LSMinimumSystemVersion + 10.9.0 + LSUIElement + 1 + NSSupportsAutomaticGraphicsSwitching + + NSHumanReadableCopyright + © 2017, cef-pdf + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba28b0a..7719d01 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,23 +3,24 @@ # can be found in the LICENSE file. # -# Source files. +# Targets and source files. # -# cef-pdf sources. +set(CEF_TARGET "cef-pdf") +set(CEF_HELPER_TARGET "cef-pdf Helper") + file(GLOB_RECURSE CEFPDF_SRCS "*.cpp") -source_group(cef-pdf FILES ${CEFPDF_SRCS}) +set(CEFPDF_HELPER_SRCS ${CEFPDF_SRCS}) +list(FILTER CEFPDF_SRCS EXCLUDE REGEX "subprocess\\.cpp$") +list(FILTER CEFPDF_HELPER_SRCS EXCLUDE REGEX "main\\.cpp$") + +source_group("${CEF_TARGET}" FILES ${CEFPDF_SRCS}) +#source_group("${CEF_HELPER_TARGET}" FILES ${CEFPDF_HELPER_SRCS}) # # Shared configuration. # -# Target executable names. -set(CEF_TARGET "cef-pdf") -if(OS_MACOSX) - set(CEF_HELPER_TARGET "cef-pdf Helper") -endif() - # Logical target used to link the libcef library. ADD_LOGICAL_TARGET("libcef_lib" "${CEF_LIB_DEBUG}" "${CEF_LIB_RELEASE}") @@ -36,8 +37,8 @@ if(OS_LINUX) add_executable(${CEF_TARGET} ${CEFPDF_SRCS}) SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) add_dependencies(${CEF_TARGET} libcef_dll_wrapper) - target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS} -Wl,--no-fatal-warnings) - target_compile_options(${CEF_TARGET} PRIVATE -fexceptions) + target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}) + target_compile_options(${CEF_TARGET} PUBLIC -fexceptions) # Set rpath so that libraries can be placed next to the executable. set_target_properties(${CEF_TARGET} PROPERTIES INSTALL_RPATH "$ORIGIN") @@ -71,8 +72,9 @@ if(OS_MACOSX) add_dependencies(${CEF_HELPER_TARGET} libcef_dll_wrapper) target_link_libraries(${CEF_HELPER_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}) set_target_properties(${CEF_HELPER_TARGET} PROPERTIES - MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/mac/helper-Info.plist - ) + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/resource/helper-Info.plist + ) + target_compile_options(${CEF_HELPER_TARGET} PUBLIC -fexceptions -Wno-unused-local-typedef) # Fix the framework rpath in the helper executable. FIX_MACOSX_HELPER_FRAMEWORK_RPATH(${CEF_HELPER_TARGET}) @@ -84,8 +86,9 @@ if(OS_MACOSX) target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}) set_target_properties(${CEF_TARGET} PROPERTIES RESOURCE "${CEFPDF_RESOURCES_SRCS}" - MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/mac/Info.plist - ) + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/resource/Info.plist + ) + target_compile_options(${CEF_TARGET} PUBLIC -fexceptions -Wno-unused-local-typedef) # Copy files into the main app bundle. add_custom_command( @@ -95,12 +98,15 @@ if(OS_MACOSX) COMMAND ${CMAKE_COMMAND} -E copy_directory "${CEF_HELPER_APP}" "${CEF_APP}/Contents/Frameworks/${CEF_HELPER_TARGET}.app" + # Remove helper bundle + COMMAND ${CMAKE_COMMAND} -E remove_directory + "${CEF_HELPER_APP}" # Copy the CEF framework into the Frameworks directory. COMMAND ${CMAKE_COMMAND} -E copy_directory "${CEF_BINARY_DIR}/Chromium Embedded Framework.framework" "${CEF_APP}/Contents/Frameworks/Chromium Embedded Framework.framework" VERBATIM - ) + ) # Fix the framework rpath in the main executable. FIX_MACOSX_MAIN_FRAMEWORK_RPATH(${CEF_TARGET}) @@ -122,9 +128,22 @@ if(OS_WINDOWS) # Executable target. add_executable(${CEF_TARGET} WIN32 ${CEFPDF_SRCS}) add_dependencies(${CEF_TARGET} libcef_dll_wrapper) + + list(APPEND CEF_COMPILER_DEFINES + _HAS_EXCEPTIONS=1 + ) + + list(APPEND CEF_CXX_COMPILER_FLAGS + /EHsc + ) + + list(APPEND CEF_EXE_LINKER_FLAGS + /entry:mainCRTStartup + /subsystem:console + ) + SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}) - target_compile_definitions(${CEF_TARGET} PRIVATE _HAS_EXCEPTIONS=1) if(USE_SANDBOX) # Logical target used to link the cef_sandbox library. @@ -133,7 +152,7 @@ if(OS_WINDOWS) endif() # Add the custom manifest files to the executable. - ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}" "${CEF_TARGET}" "exe") + ADD_WINDOWS_MANIFEST("${CMAKE_SOURCE_DIR}/resource" "${CEF_TARGET}" "exe") # Copy binary and resource files to the target output directory. COPY_FILES("${CEF_TARGET}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}") diff --git a/src/Client.cpp b/src/Client.cpp index e485c73..4afc3bb 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -27,11 +27,9 @@ Client::Client() : m_settings.command_line_args_disabled = true; m_windowInfo.windowless_rendering_enabled = true; - m_windowInfo.transparent_painting_enabled = false; m_browserSettings.windowless_frame_rate = 1; CefString(&m_browserSettings.default_encoding).FromString(constants::encoding); - m_browserSettings.caret_browsing = STATE_DISABLED; m_browserSettings.plugins = STATE_DISABLED; m_browserSettings.javascript_open_windows = STATE_DISABLED; m_browserSettings.javascript_close_windows = STATE_DISABLED; @@ -105,9 +103,9 @@ CefRefPtr Client::GetBrowserProcessHandler() return this; } -void Client::OnRegisterCustomSchemes(CefRefPtr registrar) +void Client::OnRegisterCustomSchemes(CefRawPtr registrar) { - registrar->AddCustomScheme(constants::scheme, true, false, false); + registrar->AddCustomScheme(constants::scheme, true, false, false, false, true, false); } void Client::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr command_line) diff --git a/src/Client.h b/src/Client.h index 3b16297..a6d8202 100644 --- a/src/Client.h +++ b/src/Client.h @@ -46,29 +46,29 @@ class Client : public CefApp, // Get the number of running job processes unsigned int GetProcessCount() { return m_processCount; - }; + } void SetStopAfterLastJob(bool flag) { m_stopAfterLastJob = flag; - }; + } void SetDisableJavaScript(bool flag) { m_browserSettings.javascript = flag ? STATE_DISABLED : STATE_ENABLED; - }; + } void SetAllowedSchemes(const std::set& schemes) { for (auto s: schemes) { m_requestHandler->AddAllowedScheme(s); } - }; + } void ClearAllowedSchemes() { m_requestHandler->ClearAllowedSchemes(); - }; + } // CefApp methods: virtual CefRefPtr GetBrowserProcessHandler() override; - virtual void OnRegisterCustomSchemes(CefRefPtr registrar) override; + virtual void OnRegisterCustomSchemes(CefRawPtr registrar) override; virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr command_line) override; // CefBrowserProcessHandler methods: @@ -124,7 +124,7 @@ class Client : public CefApp, CefRefPtr m_requestHandler; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Client); + IMPLEMENT_REFCOUNTING(Client) }; } // namespace cefpdf diff --git a/src/Common.cpp b/src/Common.cpp index 71c5839..6c3df72 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -257,8 +257,7 @@ std::string getCurrentWorkingDirectory() return result; #else char result[2*4096]; - getcwd(result, 2*4096); - return result; + return getcwd(result, 2*4096); #endif // OS_WIN } @@ -323,4 +322,4 @@ bool deleteTempFile(const std::string& path) return 0 == std::remove(path.c_str()); } -} // namespace cefpdf \ No newline at end of file +} // namespace cefpdf diff --git a/src/Common.h b/src/Common.h index 1178771..efdb0e8 100644 --- a/src/Common.h +++ b/src/Common.h @@ -15,7 +15,7 @@ std::string getTempDirectory(); namespace constants { // cef-pdf version number - const std::string version = "0.2.1"; + const std::string version = "0.3.0"; // Internal scheme const std::string scheme = "cefpdf"; // Default page size diff --git a/src/Job/ContentProvider.h b/src/Job/ContentProvider.h index 373ce10..6c1fd15 100644 --- a/src/Job/ContentProvider.h +++ b/src/Job/ContentProvider.h @@ -1,48 +1,48 @@ -#ifndef JOB_CONTENT_PROVIDER_H_ -#define JOB_CONTENT_PROVIDER_H_ - -#include "Visitor.h" -#include "Local.h" -#include "Remote.h" -#include "StdInput.h" -#include "StdInputStreamReader.h" - -namespace cefpdf { -namespace job { - -class ContentProvider : public Visitor -{ - -public: - ContentProvider() {}; - - CefRefPtr GetStreamReader() const { - return m_reader; - }; - - virtual void visit(CefRefPtr job) { - m_reader = CefStreamReader::CreateForData( - static_cast(const_cast(job->GetContent().c_str())), - job->GetContent().size() - ); - }; - - virtual void visit(CefRefPtr job) { - // no implementation - }; - - virtual void visit(CefRefPtr job) { - m_reader = CefStreamReader::CreateForHandler(new StdInputStreamReader); - }; - -private: - CefRefPtr m_reader; - - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(ContentProvider); -}; - -} // namespace job -} // namespace cefpdf - -#endif // JOB_CONTENT_PROVIDER_H_ \ No newline at end of file +#ifndef JOB_CONTENT_PROVIDER_H_ +#define JOB_CONTENT_PROVIDER_H_ + +#include "Visitor.h" +#include "Local.h" +#include "Remote.h" +#include "StdInput.h" +#include "StdInputStreamReader.h" + +namespace cefpdf { +namespace job { + +class ContentProvider : public Visitor +{ + +public: + ContentProvider() {} + + CefRefPtr GetStreamReader() const { + return m_reader; + } + + virtual void visit(CefRefPtr job) override { + m_reader = CefStreamReader::CreateForData( + static_cast(const_cast(job->GetContent().c_str())), + job->GetContent().size() + ); + } + + virtual void visit(CefRefPtr job) override { + // no implementation + } + + virtual void visit(CefRefPtr job) override { + m_reader = CefStreamReader::CreateForHandler(new StdInputStreamReader); + } + +private: + CefRefPtr m_reader; + + // Include the default reference counting implementation. + IMPLEMENT_REFCOUNTING(ContentProvider) +}; + +} // namespace job +} // namespace cefpdf + +#endif // JOB_CONTENT_PROVIDER_H_ diff --git a/src/Job/Job.h b/src/Job/Job.h index d988f2c..9f9a940 100644 --- a/src/Job/Job.h +++ b/src/Job/Job.h @@ -12,28 +12,29 @@ namespace cefpdf { namespace job { -class Job : public CefBase +class Job : public CefBaseRefCounted { + public: Job(); std::future GetFuture() { return m_promise.get_future(); - }; + } void Resolve(std::string value) { m_promise.set_value(value); - }; + } virtual void accept(CefRefPtr visitor) = 0; const CefString& GetOutputPath() const { return m_outputPath; - }; + } void SetOutputPath(const CefString& outputPath) { m_outputPath = outputPath; - }; + } void SetPageSize(const CefString& pageSize); @@ -55,7 +56,7 @@ class Job : public CefBase std::promise m_promise; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Job); + IMPLEMENT_REFCOUNTING(Job) }; } // namespace job diff --git a/src/Job/Loader.h b/src/Job/Loader.h index 10bec0f..4590098 100644 --- a/src/Job/Loader.h +++ b/src/Job/Loader.h @@ -1,44 +1,44 @@ -#ifndef JOB_LOADER_H_ -#define JOB_LOADER_H_ - -#include "../Common.h" -#include "Visitor.h" -#include "Local.h" -#include "Remote.h" -#include "StdInput.h" - -#include "include/cef_frame.h" - -namespace cefpdf { -namespace job { - -class Loader : public Visitor -{ - -public: - Loader(CefRefPtr frame) : - m_frame(frame) {}; - - virtual void visit(CefRefPtr job) { - m_frame->LoadURL(cefpdf::constants::scheme + "://local"); - }; - - virtual void visit(CefRefPtr job) { - m_frame->LoadURL(job->GetUrl()); - }; - - virtual void visit(CefRefPtr job) { - m_frame->LoadURL(cefpdf::constants::scheme + "://stdin"); - }; - -private: - CefRefPtr m_frame; - - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Loader); -}; - -} // namespace job -} // namespace cefpdf - -#endif // JOB_LOADER_H_ \ No newline at end of file +#ifndef JOB_LOADER_H_ +#define JOB_LOADER_H_ + +#include "../Common.h" +#include "Visitor.h" +#include "Local.h" +#include "Remote.h" +#include "StdInput.h" + +#include "include/cef_frame.h" + +namespace cefpdf { +namespace job { + +class Loader : public Visitor +{ + +public: + Loader(CefRefPtr frame) : + m_frame(frame) {} + + virtual void visit(CefRefPtr job) override { + m_frame->LoadURL(cefpdf::constants::scheme + "://local"); + } + + virtual void visit(CefRefPtr job) override { + m_frame->LoadURL(job->GetUrl()); + } + + virtual void visit(CefRefPtr job) override { + m_frame->LoadURL(cefpdf::constants::scheme + "://stdin"); + } + +private: + CefRefPtr m_frame; + + // Include the default reference counting implementation. + IMPLEMENT_REFCOUNTING(Loader) +}; + +} // namespace job +} // namespace cefpdf + +#endif // JOB_LOADER_H_ diff --git a/src/Job/Local.h b/src/Job/Local.h index 34f2253..8c084a3 100644 --- a/src/Job/Local.h +++ b/src/Job/Local.h @@ -1,37 +1,37 @@ -#ifndef JOB_LOCAL_H_ -#define JOB_LOCAL_H_ - -#include "Job.h" - -namespace cefpdf { -namespace job { - -class Local : public Job -{ - -public: - Local(const std::string& content) : Job(), m_content(content) {}; - - virtual const std::string& GetContent() const { - return m_content; - }; - - void SetContent(const std::string& content) { - m_content = content; - }; - - virtual void accept(CefRefPtr visitor) { - visitor->visit(this); - }; - -private: - std::string m_content; - - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Local); -}; - -} // namespace job -} // namespace cefpdf - -#endif // JOB_LOCAL_H_ \ No newline at end of file +#ifndef JOB_LOCAL_H_ +#define JOB_LOCAL_H_ + +#include "Job.h" + +namespace cefpdf { +namespace job { + +class Local : public Job +{ + +public: + Local(const std::string& content) : Job(), m_content(content) {} + + virtual const std::string& GetContent() const { + return m_content; + } + + void SetContent(const std::string& content) { + m_content = content; + } + + virtual void accept(CefRefPtr visitor) override { + visitor->visit(this); + } + +private: + std::string m_content; + + // Include the default reference counting implementation. + IMPLEMENT_REFCOUNTING(Local) +}; + +} // namespace job +} // namespace cefpdf + +#endif // JOB_LOCAL_H_ diff --git a/src/Job/Manager.h b/src/Job/Manager.h index 20eedef..a0bde9e 100644 --- a/src/Job/Manager.h +++ b/src/Job/Manager.h @@ -12,13 +12,13 @@ namespace cefpdf { namespace job { -class Manager : public CefBase +class Manager : public CefBaseRefCounted { public: typedef CefLoadHandler::ErrorCode ErrorCode; - Manager() {}; + Manager() {} std::size_t Queue(CefRefPtr job); @@ -49,10 +49,8 @@ class Manager : public CefBase void Resolve(Manager::Iterator it, const std::string&); - unsigned int m_counter = 0; - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Manager); + IMPLEMENT_REFCOUNTING(Manager) }; } // namespace job diff --git a/src/Job/Printer.h b/src/Job/Printer.h index 172f708..d7f89d5 100644 --- a/src/Job/Printer.h +++ b/src/Job/Printer.h @@ -1,58 +1,58 @@ -#ifndef JOB_PRINTER_H_ -#define JOB_PRINTER_H_ - -#include "Manager.h" -#include "Visitor.h" -#include "Local.h" -#include "Remote.h" -#include "StdInput.h" - -namespace cefpdf { -namespace job { - -class Printer : public Visitor, - public CefPdfPrintCallback -{ - -public: - Printer(CefRefPtr manager, CefRefPtr browser) : - m_manager(manager), - m_browser(browser) {}; - - void Print(CefRefPtr job) { - m_browser->GetHost()->PrintToPDF( - job->GetOutputPath(), - job->GetCefPdfPrintSettings(), - this - ); - }; - - virtual void visit(CefRefPtr job) { - Print(job.get()); - }; - - virtual void visit(CefRefPtr job) { - Print(job.get()); - }; - - virtual void visit(CefRefPtr job) { - Print(job.get()); - } - - // CefPdfPrintCallback methods: - void OnPdfPrintFinished(const CefString& path, bool ok) override { - m_manager->Finish(m_browser, path, ok); - }; - -private: - CefRefPtr m_manager; - CefRefPtr m_browser; - - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Printer); -}; - -} // namespace job -} // namespace cefpdf - -#endif // JOB_PRINTER_H_ \ No newline at end of file +#ifndef JOB_PRINTER_H_ +#define JOB_PRINTER_H_ + +#include "Manager.h" +#include "Visitor.h" +#include "Local.h" +#include "Remote.h" +#include "StdInput.h" + +namespace cefpdf { +namespace job { + +class Printer : public Visitor, + public CefPdfPrintCallback +{ + +public: + Printer(CefRefPtr manager, CefRefPtr browser) : + m_manager(manager), + m_browser(browser) {} + + void Print(CefRefPtr job) { + m_browser->GetHost()->PrintToPDF( + job->GetOutputPath(), + job->GetCefPdfPrintSettings(), + this + ); + } + + virtual void visit(CefRefPtr job) override { + Print(job.get()); + } + + virtual void visit(CefRefPtr job) override { + Print(job.get()); + } + + virtual void visit(CefRefPtr job) override { + Print(job.get()); + } + + // CefPdfPrintCallback methods: + void OnPdfPrintFinished(const CefString& path, bool ok) override { + m_manager->Finish(m_browser, path, ok); + } + +private: + CefRefPtr m_manager; + CefRefPtr m_browser; + + // Include the default reference counting implementation. + IMPLEMENT_REFCOUNTING(Printer) +}; + +} // namespace job +} // namespace cefpdf + +#endif // JOB_PRINTER_H_ diff --git a/src/Job/Remote.h b/src/Job/Remote.h index b0329da..1cb72ba 100644 --- a/src/Job/Remote.h +++ b/src/Job/Remote.h @@ -1,34 +1,34 @@ -#ifndef JOB_REMOTE_H_ -#define JOB_REMOTE_H_ - -#include "Job.h" - -namespace cefpdf { -namespace job { - -class Remote : public Job -{ - -public: - Remote(const CefString& url) : - Job(), m_url(url) {}; - - const CefString& GetUrl() const { - return m_url; - }; - - virtual void accept(CefRefPtr visitor) { - visitor->visit(this); - }; - -private: - CefString m_url; - - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Remote); -}; - -} // namespace job -} // namespace cefpdf - -#endif // JOB_REMOTE_H_ \ No newline at end of file +#ifndef JOB_REMOTE_H_ +#define JOB_REMOTE_H_ + +#include "Job.h" + +namespace cefpdf { +namespace job { + +class Remote : public Job +{ + +public: + Remote(const CefString& url) : + Job(), m_url(url) {} + + const CefString& GetUrl() const { + return m_url; + } + + virtual void accept(CefRefPtr visitor) override { + visitor->visit(this); + } + +private: + CefString m_url; + + // Include the default reference counting implementation. + IMPLEMENT_REFCOUNTING(Remote) +}; + +} // namespace job +} // namespace cefpdf + +#endif // JOB_REMOTE_H_ diff --git a/src/Job/StdInput.h b/src/Job/StdInput.h index f66f6ef..40cebb5 100644 --- a/src/Job/StdInput.h +++ b/src/Job/StdInput.h @@ -1,26 +1,25 @@ -#ifndef JOB_STDINPUT_H_ -#define JOB_STDINPUT_H_ - -#include "Job.h" - -namespace cefpdf { -namespace job { - -class StdInput : public Job -{ - -public: - virtual void accept(CefRefPtr visitor) { - visitor->visit(this); - }; - -private: - - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(StdInput); -}; - -} // namespace job -} // namespace cefpdf - -#endif // JOB_STDINPUT_H_ \ No newline at end of file +#ifndef JOB_STDINPUT_H_ +#define JOB_STDINPUT_H_ + +#include "Job.h" + +namespace cefpdf { +namespace job { + +class StdInput : public Job +{ + +public: + virtual void accept(CefRefPtr visitor) override { + visitor->visit(this); + } + +private: + // Include the default reference counting implementation. + IMPLEMENT_REFCOUNTING(StdInput) +}; + +} // namespace job +} // namespace cefpdf + +#endif // JOB_STDINPUT_H_ diff --git a/src/Job/StdInputStreamReader.cpp b/src/Job/StdInputStreamReader.cpp index 7a5f6da..fff89a6 100644 --- a/src/Job/StdInputStreamReader.cpp +++ b/src/Job/StdInputStreamReader.cpp @@ -39,4 +39,4 @@ int StdInputStreamReader::Seek(int64 offset, int whence) } } // namespace job -} // namespace cefpdf \ No newline at end of file +} // namespace cefpdf diff --git a/src/Job/StdInputStreamReader.h b/src/Job/StdInputStreamReader.h index 6c79aad..9d2c5d0 100644 --- a/src/Job/StdInputStreamReader.h +++ b/src/Job/StdInputStreamReader.h @@ -7,44 +7,42 @@ #include #include #include -#include namespace cefpdf { namespace job { class StdInputStreamReader : public CefReadHandler { - public: - StdInputStreamReader() : m_initialized(false) {}; +public: + StdInputStreamReader() : m_initialized(false) {} void Initialize(); - virtual int Eof() { + virtual int Eof() override { return std::cin.eof() ? 1 : 0; - }; + } - virtual bool MayBlock() { + virtual bool MayBlock() override { return true; - }; + } - virtual std::size_t Read(void* ptr, std::size_t size, std::size_t n); + virtual std::size_t Read(void* ptr, std::size_t size, std::size_t n) override; - virtual int Seek(int64 offset, int whence); + virtual int Seek(int64 offset, int whence) override; - virtual int64 Tell() { + virtual int64 Tell() override { return std::cin.tellg(); - }; - - private: + } +private: bool m_initialized; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(StdInputStreamReader); + IMPLEMENT_REFCOUNTING(StdInputStreamReader) }; } // namespace job } // namespace cefpdf -#endif // JOB_STDINPUT_STREAM_READER_H_ \ No newline at end of file +#endif // JOB_STDINPUT_STREAM_READER_H_ diff --git a/src/Job/Visitor.h b/src/Job/Visitor.h index 9513b45..1590c81 100644 --- a/src/Job/Visitor.h +++ b/src/Job/Visitor.h @@ -1,31 +1,31 @@ -#ifndef JOB_VISITOR_H_ -#define JOB_VISITOR_H_ - -#include "include/cef_base.h" - -namespace cefpdf { -namespace job { - -class Local; -class Remote; -class StdInput; - -class Visitor : public CefBase -{ - -public: - Visitor() {}; - - virtual void visit(CefRefPtr) = 0; - virtual void visit(CefRefPtr) = 0; - virtual void visit(CefRefPtr) = 0; - -private: - // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Visitor); -}; - -} // namespace job -} // namespace cefpdf - -#endif // JOB_VISITOR_H_ \ No newline at end of file +#ifndef JOB_VISITOR_H_ +#define JOB_VISITOR_H_ + +#include "include/cef_base.h" + +namespace cefpdf { +namespace job { + +class Local; +class Remote; +class StdInput; + +class Visitor : public CefBaseRefCounted +{ + +public: + Visitor() {} + + virtual void visit(CefRefPtr) = 0; + virtual void visit(CefRefPtr) = 0; + virtual void visit(CefRefPtr) = 0; + +private: + // Include the default reference counting implementation. + IMPLEMENT_REFCOUNTING(Visitor) +}; + +} // namespace job +} // namespace cefpdf + +#endif // JOB_VISITOR_H_ diff --git a/src/PrintHandler.cpp b/src/PrintHandler.cpp index 5c69550..b519033 100644 --- a/src/PrintHandler.cpp +++ b/src/PrintHandler.cpp @@ -8,30 +8,40 @@ PrintHandler::PrintHandler() {} // CefPrintHandler methods: // ------------------------------------------------------------------------- -CefSize PrintHandler::GetPdfPaperSize(int device_units_per_inch) +CefSize PrintHandler::GetPdfPaperSize(CefRefPtr browser, int device_units_per_inch) { DLOG(INFO) << "PrintHandler::GetPdfPaperSize: " << device_units_per_inch; return CefSize(device_units_per_inch*100, device_units_per_inch*100*2); } -bool PrintHandler::OnPrintDialog(bool has_selection, CefRefPtr callback) -{ +bool PrintHandler::OnPrintDialog( + CefRefPtr browser, + bool has_selection, + CefRefPtr callback +) { return true; } -bool PrintHandler::OnPrintJob(const CefString& document_name, const CefString& pdf_file_path, CefRefPtr callback) -{ +bool PrintHandler::OnPrintJob( + CefRefPtr browser, + const CefString& document_name, + const CefString& pdf_file_path, + CefRefPtr callback +) { return true; } -void PrintHandler::OnPrintReset() +void PrintHandler::OnPrintReset(CefRefPtr browser) { } -void PrintHandler::OnPrintSettings(CefRefPtr settings, bool get_defaults) -{ +void PrintHandler::OnPrintSettings( + CefRefPtr browser, + CefRefPtr settings, + bool get_defaults +) { } @@ -40,4 +50,4 @@ void PrintHandler::OnPrintStart(CefRefPtr browser) } -} // namespace cefpdf \ No newline at end of file +} // namespace cefpdf diff --git a/src/PrintHandler.h b/src/PrintHandler.h index 2e46b9c..6784eaa 100644 --- a/src/PrintHandler.h +++ b/src/PrintHandler.h @@ -7,27 +7,39 @@ namespace cefpdf { class PrintHandler : public CefPrintHandler { - public: +public: PrintHandler(); // CefPrintHandler methods: - virtual CefSize GetPdfPaperSize(int device_units_per_inch) override; + virtual CefSize GetPdfPaperSize(CefRefPtr browser, int device_units_per_inch) override; - virtual bool OnPrintDialog(bool has_selection, CefRefPtr callback) override; + virtual bool OnPrintDialog( + CefRefPtr browser, + bool has_selection, + CefRefPtr callback + ) override; - virtual bool OnPrintJob(const CefString& document_name, const CefString& pdf_file_path, CefRefPtr callback) override; + virtual bool OnPrintJob( + CefRefPtr browser, + const CefString& document_name, + const CefString& pdf_file_path, + CefRefPtr callback + ) override; - virtual void OnPrintReset() override; + virtual void OnPrintReset(CefRefPtr browser) override; - virtual void OnPrintSettings(CefRefPtr settings, bool get_defaults) override; + virtual void OnPrintSettings( + CefRefPtr browser, + CefRefPtr settings, + bool get_defaults + ) override; virtual void OnPrintStart(CefRefPtr browser) override; - private: - +private: // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(PrintHandler); + IMPLEMENT_REFCOUNTING(PrintHandler) }; } // namespace cefpdf diff --git a/src/RenderHandler.cpp b/src/RenderHandler.cpp index e71f8a3..433f2cb 100644 --- a/src/RenderHandler.cpp +++ b/src/RenderHandler.cpp @@ -24,4 +24,4 @@ void RenderHandler::OnPaint( } -} // namespace cefpdf \ No newline at end of file +} // namespace cefpdf diff --git a/src/RenderHandler.h b/src/RenderHandler.h index 96f6c6d..23ee1a6 100644 --- a/src/RenderHandler.h +++ b/src/RenderHandler.h @@ -7,8 +7,8 @@ namespace cefpdf { class RenderHandler : public CefRenderHandler { - public: +public: RenderHandler(); // CefRenderHandler methods: @@ -21,10 +21,9 @@ class RenderHandler : public CefRenderHandler const void* buffer, int width, int height ) override; - private: - +private: // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(RenderHandler); + IMPLEMENT_REFCOUNTING(RenderHandler) }; } // namespace cefpdf diff --git a/src/RequestHandler.cpp b/src/RequestHandler.cpp index 18bfaa7..021f878 100644 --- a/src/RequestHandler.cpp +++ b/src/RequestHandler.cpp @@ -34,4 +34,4 @@ bool RequestHandler::OnBeforeBrowse( return !std::regex_search(url, re, std::regex_constants::match_continuous); } -} // namespace cefpdf \ No newline at end of file +} // namespace cefpdf diff --git a/src/RequestHandler.h b/src/RequestHandler.h index d4b0d63..eed0f9d 100644 --- a/src/RequestHandler.h +++ b/src/RequestHandler.h @@ -10,24 +10,24 @@ namespace cefpdf { class RequestHandler : public CefRequestHandler { - public: - RequestHandler() {}; +public: + RequestHandler() {} void AddAllowedScheme(const std::string& scheme) { m_schemes.insert(scheme); - }; + } void ClearAllowedSchemes() { m_schemes.clear(); - }; + } void RemoveAllowedScheme(const std::string& scheme) { auto i = m_schemes.find(scheme); if (i != m_schemes.end()) { m_schemes.erase(i); } - }; + } // CefRequestHandler methods: virtual bool OnBeforeBrowse( @@ -35,14 +35,13 @@ class RequestHandler : public CefRequestHandler CefRefPtr frame, CefRefPtr request, bool is_redirect - ); - - private: + ) override; +private: std::set m_schemes; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(RequestHandler); + IMPLEMENT_REFCOUNTING(RequestHandler) }; } // namespace cefpdf diff --git a/src/SchemeHandlerFactory.h b/src/SchemeHandlerFactory.h index 1e28f8a..c0a8fc6 100644 --- a/src/SchemeHandlerFactory.h +++ b/src/SchemeHandlerFactory.h @@ -25,7 +25,7 @@ class SchemeHandlerFactory : public CefSchemeHandlerFactory CefRefPtr m_jobsManager; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(SchemeHandlerFactory); + IMPLEMENT_REFCOUNTING(SchemeHandlerFactory) }; } // namespace cefpdf diff --git a/src/Server/Connection.h b/src/Server/Connection.h index 9073f8b..55152e0 100644 --- a/src/Server/Connection.h +++ b/src/Server/Connection.h @@ -16,40 +16,41 @@ namespace server { class ConnectionManager; -class Connection : public CefBase +class Connection : public CefBaseRefCounted { + public: Connection( CefRefPtr connectionManager, asio::ip::tcp::socket socket ) : m_connectionManager(connectionManager), - m_socket(std::move(socket)) {}; + m_socket(std::move(socket)) {} Connection(const Connection&) = delete; Connection& operator=(const Connection&) = delete; void Start() { ReadSome(); - }; + } void Write(); bool isOpen() { return m_socket.is_open(); - }; + } void Close() { m_socket.close(); - }; + } const http::Request& GetRequest() const { return m_request; - }; + } http::Response& GetResponse() { return m_response; - }; + } private: void ReadSome(); @@ -67,10 +68,10 @@ class Connection : public CefBase std::string m_requestData; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Connection); + IMPLEMENT_REFCOUNTING(Connection) }; } // namespace server } // namespace cefpdf -#endif // SERVER_CONNECTION_H_ \ No newline at end of file +#endif // SERVER_CONNECTION_H_ diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h index 4007f19..43e225a 100644 --- a/src/Server/ConnectionManager.h +++ b/src/Server/ConnectionManager.h @@ -11,12 +11,12 @@ namespace cefpdf { namespace server { -class ConnectionManager : public CefBase +class ConnectionManager : public CefBaseRefCounted { public: ConnectionManager(CefRefPtr requestHandler) : - m_requestHandler(requestHandler) {}; + m_requestHandler(requestHandler) {} ConnectionManager(const ConnectionManager&) = delete; ConnectionManager& operator=(const ConnectionManager&) = delete; @@ -32,7 +32,7 @@ class ConnectionManager : public CefBase CefRefPtr m_requestHandler; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(ConnectionManager); + IMPLEMENT_REFCOUNTING(ConnectionManager) }; } // namespace server diff --git a/src/Server/Http.h b/src/Server/Http.h index 5efa522..8180ed7 100644 --- a/src/Server/Http.h +++ b/src/Server/Http.h @@ -34,4 +34,4 @@ struct Response { } // namespace server } // namespace cefpdf -#endif // SERVER_HTTP_H_ \ No newline at end of file +#endif // SERVER_HTTP_H_ diff --git a/src/Server/RequestHandler.h b/src/Server/RequestHandler.h index 9bb2a9c..8d48103 100644 --- a/src/Server/RequestHandler.h +++ b/src/Server/RequestHandler.h @@ -9,11 +9,12 @@ namespace cefpdf { namespace server { -class RequestHandler : public CefBase +class RequestHandler : public CefBaseRefCounted { + public: RequestHandler(CefRefPtr client) : - m_client(client) {}; + m_client(client) {} RequestHandler(const RequestHandler&) = delete; RequestHandler& operator=(const RequestHandler&) = delete; @@ -27,10 +28,10 @@ class RequestHandler : public CefBase void SetContentLength(http::Response&); // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(RequestHandler); + IMPLEMENT_REFCOUNTING(RequestHandler) }; } // namespace server } // namespace cefpdf -#endif // SERVER_REQUEST_HANDLER_H_ \ No newline at end of file +#endif // SERVER_REQUEST_HANDLER_H_ diff --git a/src/Server/Server.h b/src/Server/Server.h index 07dbb3a..ae670fe 100644 --- a/src/Server/Server.h +++ b/src/Server/Server.h @@ -15,7 +15,7 @@ namespace cefpdf { namespace server { -class Server : public CefBase +class Server : public CefBaseRefCounted { public: @@ -38,7 +38,7 @@ class Server : public CefBase int m_counter; // Include the default reference counting implementation. - IMPLEMENT_REFCOUNTING(Server); + IMPLEMENT_REFCOUNTING(Server) }; } // namespace server diff --git a/src/main.cpp b/src/main.cpp index b7958c7..40bcd6c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,10 +7,6 @@ #include #include -#if defined(OS_WIN) -#pragma comment(linker, "/entry:mainCRTStartup /subsystem:console") -#endif // OS_WIN - void printSizes() { cefpdf::PageSizesMap::const_iterator it; diff --git a/src/subprocess.cpp b/src/subprocess.cpp new file mode 100644 index 0000000..924594e --- /dev/null +++ b/src/subprocess.cpp @@ -0,0 +1,9 @@ +#include "Client.h" + +// This entry point is for Mac OS X only +int main(int argc, char* argv[]) +{ + CefRefPtr app = new cefpdf::Client(); + CefMainArgs mainArgs(argc, argv); + return app->ExecuteSubProcess(mainArgs); +}