├── .clog.toml ├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── CMakeLists.txt ├── ChangeLog.txt ├── Doxyfile ├── LICENSE ├── README.md ├── browser_demo ├── CMakeLists.txt ├── browser_address_edit.cpp ├── browser_address_edit.h ├── browser_event_delegate.cpp ├── browser_event_delegate.h ├── browser_tab_bar.cpp ├── browser_tab_bar.h ├── browser_tab_widget.cpp ├── browser_tab_widget.h ├── browser_window.cpp ├── browser_window.h ├── channel.cpp ├── channel.h ├── images │ ├── document-new-symbolic.svg │ ├── document-print-symbolic.svg │ ├── firefox.png │ ├── go-next-symbolic.svg │ ├── go-previous-symbolic.svg │ ├── images.qrc │ ├── system-lock-screen-symbolic.svg │ ├── user-home-symbolic.svg │ ├── view-more-symbolic.svg │ ├── view-refresh-symbolic.svg │ ├── window-close-symbolic.svg │ ├── zoom-in-symbolic.svg │ ├── zoom-original-symbolic.svg │ └── zoom-out-symbolic.svg ├── main.cpp ├── resources │ ├── iframe.html │ ├── index.html │ ├── redirect.html │ ├── resources.qrc │ ├── script.js │ ├── style.css │ └── user_script.js ├── sync_methods.cpp └── sync_methods.h ├── debian ├── changelog ├── compat ├── control ├── copyright ├── docs ├── libqcef-dev.install ├── libqcef1.install ├── libqcef1.lintian-overrides ├── rules └── source │ └── format ├── docs ├── cef.md └── proxy.md └── src ├── CMakeLists.txt ├── base ├── file_util.cpp ├── file_util.h └── macros.h ├── core ├── qcef_app.cpp ├── qcef_app.h ├── qcef_browser_transport.cpp ├── qcef_browser_transport.h ├── qcef_client_handler.cpp ├── qcef_client_handler.h ├── qcef_context.cpp ├── qcef_context.h ├── qcef_cookie_store.cpp ├── qcef_cookie_store.h ├── qcef_core_export.h ├── qcef_dialog_handler.cpp ├── qcef_dialog_handler.h ├── qcef_global_settings.cpp ├── qcef_global_settings.h ├── qcef_key_event_map.cpp ├── qcef_key_event_map.h ├── qcef_message_pump_handler.cpp ├── qcef_message_pump_handler.h ├── qcef_notification_constructor.cpp ├── qcef_notification_constructor.h ├── qcef_print_handler.cpp ├── qcef_print_handler.h ├── qcef_renderer_handler.cpp ├── qcef_renderer_handler.h ├── qcef_renderer_transport_handler.cpp ├── qcef_renderer_transport_handler.h ├── qcef_scheme_handler.h ├── qcef_scheme_handler_factory.cpp ├── qcef_scheme_handler_factory.h ├── qcef_string_visitor.cpp ├── qcef_string_visitor.h ├── qcef_sync_method.h ├── qcef_sync_method_handler.cpp ├── qcef_sync_method_handler.h ├── qcef_util.cpp ├── qcef_util.h ├── qcef_web_channel_consts.h ├── qcef_x11_util.cpp └── qcef_x11_util.h ├── data └── libqcef.pc.in ├── tests ├── notification_test.cpp ├── notification_window.cpp ├── notification_window.h ├── qt_version_test.cpp ├── web_demo.cpp └── xevent-tracer.c └── widgets ├── qcef_browser_event_delegate.cpp ├── qcef_browser_event_delegate.h ├── qcef_browser_event_delegate_p.h ├── qcef_client_handler_delegate.cpp ├── qcef_client_handler_delegate.h ├── qcef_native_event_filter.cpp ├── qcef_native_event_filter.h ├── qcef_notification_service.cpp ├── qcef_notification_service.h ├── qcef_ssl_status.h ├── qcef_web_page.cpp ├── qcef_web_page.h ├── qcef_web_settings.cpp ├── qcef_web_settings.h ├── qcef_web_view.cpp ├── qcef_web_view.h └── qcef_widgets_export.h /.clog.toml: -------------------------------------------------------------------------------- 1 | [clog] 2 | repository = "https://github.com/linuxdeepin/qcef" 3 | from-latest-tag = true 4 | 5 | changelog = "CHANGELOG.md" 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cmake-build-debug/ 2 | cmake-build-release/ 3 | debian/debhelper-build-stamp 4 | debian/files 5 | debian/libqcef-dev.debhelper.log 6 | debian/libqcef-dev.substvars 7 | debian/libqcef-dev/ 8 | debian/libqcef1.debhelper.log 9 | debian/libqcef1.substvars 10 | debian/libqcef1/ 11 | obj-x86-linux-gnu/ 12 | obj-x86_64-linux-gnu/ 13 | obj-mips64el-linux-gnuabi64/ 14 | debian/tmp/ 15 | debian/.debhelper/ 16 | build/ 17 | *.user 18 | .idea/ 19 | docs/qcef/ 20 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cef"] 2 | path = cef 3 | url = ../cef-binary 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## 1.1.6 (2019-04-24) 3 | 4 | 5 | #### Bug Fixes 6 | 7 | * crash on window close ([5bec3536](https://github.com/linuxdeepin/qcef/commit/5bec3536539a20cc3e353c15d5a11aa772fdd085)) 8 | 9 | 10 | 11 | 12 | ## 1.1.5.1 (2019-04-22) 13 | 14 | 15 | #### Bug Fixes 16 | 17 | * d'not setting zoom factor if the window is not mapped ([61b09442](https://github.com/linuxdeepin/qcef/commit/61b094424d492691ac3a72bdac030ff3cfbba386)) 18 | 19 | 20 | 21 | 22 | ## 1.1.4.7 (2019-04-22) 23 | 24 | 25 | #### Features 26 | 27 | * web zoom follow the QWidget::devicePixelRatioF ([0603275f](https://github.com/linuxdeepin/qcef/commit/0603275f5424c62a3e50d7aefd24410eaa3ea10e)) 28 | 29 | 30 | 31 | 32 | ## 1.1.4.6 (2019-01-02) 33 | 34 | 35 | #### Bug Fixes 36 | 37 | * destory qobject with deleteLater ([9e55466a](https://github.com/linuxdeepin/qcef/commit/9e55466afdcd12d33a323507b6436f48b05ae76b)) 38 | 39 | #### Features 40 | 41 | * support add custom header ([dc4890c2](https://github.com/linuxdeepin/qcef/commit/dc4890c279c80b09ae3db0f714b882cdb4b59448)) 42 | 43 | 44 | 45 | 46 | ## 1.1.4.5 (2018-10-18) 47 | 48 | 49 | #### Bug Fixes 50 | 51 | * can not found a qrc file if the file url not only path(eg: has query) ([747ec62b](https://github.com/linuxdeepin/qcef/commit/747ec62b563b6fbcdccaecd970da64facf18c587)) 52 | * the web content window position is wrong ([cdd18dbf](https://github.com/linuxdeepin/qcef/commit/cdd18dbfbb64757f57c60abfd3533627ebcf219f)) 53 | 54 | #### Features 55 | 56 | * support set background color ([d1e36167](https://github.com/linuxdeepin/qcef/commit/d1e3616765e2e4f0b49f0c57f3b910413a6bdc5c)) 57 | * auto mvoe the keyboard focus to the web window ([12892f70](https://github.com/linuxdeepin/qcef/commit/12892f7016fa62450130899964d1671fee731a76)) 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 2018-03-29 1.1.4.4 LiuLang 2 | * Move cef to submodule 3 | * Update cef binary package 4 | 5 | 2018-03-21 1.1.4.3 LiuLang 6 | * Add _NET_WM_PID flag to chrome wrapper window 7 | 8 | 2018-03-21 1.1.4.2 LiuLang 9 | * Add NativeEventFilter to handle mouse press event 10 | * Add window flag to chrome windows 11 | * Remove QCEF_EXTERNAL_MESSAGE_PUMP flag 12 | 13 | 2018-03-16 1.1.4.1 LiuLang 14 | * Update cef x86-64 tarball 15 | 16 | 2018-03-15 1.1.4 LiuLang 17 | * Update cef to 60.0.3112.113 18 | * Auto update cef window position on move event 19 | * Implement OnClipboardUpdated() methods in CefClientHandler 20 | * Support QShortcut 21 | * Replace QWindow with XWindow 22 | * Support updating browser locale 23 | * Support HiDPI screen 24 | 25 | 2017-11-17 1.1.3 LiuLang 26 | * Fix libqcef library path error 27 | * Update package dependency 28 | * Support specifying override-path at runtime 29 | 30 | 2017-11-10 1.1.2 LiuLang 31 | * WebView: set update-geometry-timer as single shot 32 | * Add QCEF_EXTERNAL_MESSAGE_PUMP option 33 | * Remove EMBED_WEBCHANNEL option 34 | * Remove QCEF_OVERRIDE_PATH option 35 | 36 | 2017-11-09 1.1.1 LiuLang 37 | * Update so version 38 | 39 | 2017-11-09 1.1.0 LiuLang 40 | 41 | * Add event filter to web view 42 | * Add iframe demo 43 | * Add internal MessagePumpHandler 44 | * Add localstorage demo 45 | * Add redirect page demo 46 | * Add web notification API 47 | * Support appending command line arguments 48 | * Support embed qwebchannel library 49 | * Support filetype filter in file-chooser-dialog 50 | * Support network proxy 51 | * Support refreshing web page 52 | * Support zoom-in / zoom-out web page 53 | * Fix double free pointer in debug mode 54 | * Fix iconChanged() signal 55 | * Fix segfault in updateBrowserGeometry() 56 | * Fix WindowOpenDisposition invalid in GCC5 57 | 58 | 2017-09-05 1.0.0 LiuLang 59 | 60 | * Initial release 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | Qt5 binding of [CEF](https://bitbucket.org/chromiumembedded/cef) 3 | 4 | # Build 5 | First fetch submodules: 6 | ```shell 7 | git submodule update --init --recursive 8 | git submodule update --remote 9 | ``` 10 | 11 | # LICENSE 12 | This project is released under GNU Lesser General Public License which 13 | can be found in LICENSE file. 14 | -------------------------------------------------------------------------------- /browser_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(browser-demo) 3 | 4 | set(CMAKE_CXX_STANDARD 11) 5 | 6 | if (CMAKE_BUILD_TYPE MATCHES Debug) 7 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Werror -Wextra") 8 | # -fno-rtti, Disable real-time type information 9 | # -fno-exceptions Disable exceptions 10 | # -fsanitize=address Enable memory sanitize plugin 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Werror -Wextra") 12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -fno-rtti -fno-exceptions") 13 | # -fsanitize=address, Enable memory address sanitizer. 14 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") 15 | # -fsanitize=leak, Enable memory leak sanitizer. 16 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak") 17 | # -fsanitize=memory, Enable detecting uninitited memory sanitizer. 18 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory " 19 | # "-fsanitize-memory-track-origins -fPIC -pie -fno-omit-frame-pointer") 20 | 21 | # Enable Qt builtin debug mode 22 | add_definitions("-DQT_MESSAGELOGCONTEXT") 23 | else() 24 | # -Wl, -O2 Enable linker optimizations 25 | #-Wl, --gc-sections Remove unused code resulting from -fdsta-sections and -ffunction-sections 26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2 -Wl,-O1 -Wl,--gc-sections") 27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -Wl,-O1 -Wl,--gc-sections -fno-rtti -Wno-unused-result") 28 | endif() 29 | 30 | 31 | find_package(PkgConfig REQUIRED) 32 | find_package(Qt5Core REQUIRED) 33 | find_package(Qt5Gui REQUIRED) 34 | find_package(Qt5WebChannel REQUIRED) 35 | find_package(Qt5Widgets REQUIRED) 36 | 37 | set(CMAKE_AUTOMOC ON) 38 | set(CMAKE_AUTORCC ON) 39 | 40 | pkg_search_module(LIBQCEF REQUIRED libqcef) 41 | include_directories(AFTER ${LIBQCEF_INCLUDE_DIRS}) 42 | 43 | set(LINK_LIBS 44 | Qt5::Gui 45 | Qt5::WebChannel 46 | Qt5::Widgets 47 | # ${LIBQCEF_LDFLAGS} 48 | ${LIBQCEF_LIBRARIES} 49 | ) 50 | 51 | set(BROWSER_DEMO_FILES 52 | main.cpp 53 | browser_address_edit.cpp 54 | browser_address_edit.h 55 | browser_event_delegate.cpp 56 | browser_event_delegate.h 57 | browser_tab_bar.cpp 58 | browser_tab_bar.h 59 | browser_tab_widget.cpp 60 | browser_tab_widget.h 61 | browser_window.cpp 62 | browser_window.h 63 | channel.cpp 64 | channel.h 65 | sync_methods.cpp 66 | sync_methods.h 67 | 68 | images/images.qrc 69 | resources/resources.qrc 70 | ) 71 | 72 | add_executable(browser-demo 73 | ${BROWSER_DEMO_FILES}) 74 | target_link_libraries(browser-demo ${LINK_LIBS}) -------------------------------------------------------------------------------- /browser_demo/browser_address_edit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "browser_address_edit.h" 19 | 20 | namespace { 21 | 22 | const char kLockIcon[] = ":/images/system-lock-screen-symbolic.svg"; 23 | 24 | } // namespace 25 | 26 | BrowserAddressEdit::BrowserAddressEdit(QWidget* parent) : QLineEdit(parent) { 27 | this->setStyleSheet("QLineEdit {padding-left: 26px; margin: 0px}"); 28 | ssl_button_ = new QPushButton(this); 29 | ssl_button_->setIcon(QIcon(kLockIcon)); 30 | ssl_button_->move(2, 0); 31 | ssl_button_->setFixedSize(24, 24); 32 | ssl_button_->setFlat(true); 33 | ssl_button_->hide(); 34 | } 35 | 36 | void BrowserAddressEdit::updateCertificatesInfo(bool secure) { 37 | if (secure) { 38 | ssl_button_->show(); 39 | } else { 40 | ssl_button_->hide(); 41 | } 42 | } -------------------------------------------------------------------------------- /browser_demo/browser_address_edit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_BROWSER_ADDRESS_EDIT_H 19 | #define QCEF_BROWSER_ADDRESS_EDIT_H 20 | 21 | #include 22 | #include 23 | 24 | class BrowserAddressEdit : public QLineEdit { 25 | Q_OBJECT 26 | public: 27 | explicit BrowserAddressEdit(QWidget* parent = nullptr); 28 | 29 | void updateCertificatesInfo(bool secure); 30 | 31 | private: 32 | QPushButton* ssl_button_ = nullptr; 33 | }; 34 | 35 | #endif // QCEF_BROWSER_ADDRESS_EDIT_H 36 | -------------------------------------------------------------------------------- /browser_demo/browser_event_delegate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "browser_event_delegate.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace { 26 | 27 | const int kF11Code = 95; 28 | const int kF5Code = 71; 29 | 30 | enum MenuIds { 31 | // Normal navigation. 32 | MenuBack = QCefContextMenu::MENU_ID_USER_FIRST, 33 | MenuForward, 34 | MenuReload, 35 | MenuStop, 36 | 37 | // Editable. 38 | MenuUndo, 39 | MenuRedo, 40 | MenuCut, 41 | MenuCopy, 42 | MenuPaste, 43 | MenuDelete, 44 | MenuSelectAll, 45 | 46 | // Link. 47 | MenuOpenLinkInNewTab, 48 | MenuCopyLinkAddress, 49 | }; 50 | 51 | } // namespace 52 | 53 | struct BrowserEventDelegatePrivate { 54 | QMenu* context_menu = nullptr; 55 | }; 56 | 57 | BrowserEventDelegate::BrowserEventDelegate(QObject* parent) 58 | : QObject(parent), 59 | p_(new BrowserEventDelegatePrivate()) { 60 | p_->context_menu = new QMenu(); 61 | } 62 | 63 | BrowserEventDelegate::~BrowserEventDelegate() { 64 | if (p_ != nullptr) { 65 | delete p_->context_menu; 66 | 67 | delete p_; 68 | p_ = nullptr; 69 | } 70 | } 71 | 72 | bool BrowserEventDelegate::onBeforePopup( 73 | const QUrl& url, 74 | QCefWindowOpenDisposition disposition) { 75 | emit this->popupRequested(url, disposition); 76 | return true; 77 | } 78 | 79 | bool BrowserEventDelegate::onBeforeBrowse(const QUrl& url, bool is_redirect) { 80 | if (url.host() == "bing.com") { 81 | qDebug() << "Prevent browser from navigating to bing.com, " << is_redirect; 82 | return true; 83 | } 84 | return false; 85 | } 86 | 87 | void BrowserEventDelegate::onBeforeContextMenu( 88 | QCefWebPage* web_page, 89 | QCefContextMenu* menu, 90 | const QCefContextMenuParams& params) { 91 | 92 | if (params.isEditable()) { 93 | // Editable menu. 94 | auto state = params.getEditStateFlags(); 95 | menu->addItem(MenuIds::MenuUndo, "Undo", 96 | state & QCEF_CM_EDITFLAG_CAN_UNDO, 97 | [](QCefWebPage* page) { 98 | page->undo(); 99 | }); 100 | menu->addItem(MenuIds::MenuRedo, "Redo", 101 | state & QCEF_CM_EDITFLAG_CAN_REDO, 102 | [](QCefWebPage* page) { 103 | page->redo(); 104 | }); 105 | menu->addSeparator(); 106 | menu->addItem(MenuIds::MenuCut, "Cut", 107 | state & QCEF_CM_EDITFLAG_CAN_CUT, 108 | [](QCefWebPage* page) { 109 | page->cut(); 110 | }); 111 | menu->addItem(MenuIds::MenuCopy, "Copy", 112 | state & QCEF_CM_EDITFLAG_CAN_COPY, 113 | [](QCefWebPage* page) { 114 | page->copy(); 115 | }); 116 | menu->addItem(MenuIds::MenuPaste, "Paste", 117 | state & QCEF_CM_EDITFLAG_CAN_PASTE, 118 | [](QCefWebPage* page) { 119 | page->paste(); 120 | }); 121 | menu->addItem(MenuIds::MenuDelete, "Delete", 122 | state & QCEF_CM_EDITFLAG_CAN_DELETE, 123 | [](QCefWebPage* page) { 124 | page->doDelete(); 125 | }); 126 | menu->addSeparator(); 127 | menu->addItem(MenuIds::MenuSelectAll, "Select all", 128 | state & QCEF_CM_EDITFLAG_CAN_SELECT_ALL, 129 | [](QCefWebPage* page) { 130 | page->selectAll(); 131 | }); 132 | return; 133 | } 134 | 135 | const QCefContextMenuFlags flags = params.getTypeFlags(); 136 | if (flags & QCEF_CM_FLAG_LINK) { 137 | // Link is selected. 138 | const QUrl url(params.getLinkUrl()); 139 | menu->addItem(MenuIds::MenuOpenLinkInNewTab, "Open link in new tab", true, 140 | [this, url](QCefWebPage* page) { 141 | emit this->popupRequested( 142 | url, 143 | QCEF_WOD_NEW_FOREGROUND_TAB); 144 | 145 | }); 146 | menu->addItem(MenuIds::MenuCopyLinkAddress, "Copy link address", true, 147 | [this, url](QCefWebPage* page) { 148 | emit this->copyLinkToClipboard(url); 149 | }); 150 | return; 151 | } 152 | 153 | // Normal menu. 154 | menu->addItem(MenuIds::MenuBack, "Back", web_page->canGoBack(), 155 | [](QCefWebPage* page) { 156 | page->back(); 157 | }); 158 | menu->addItem(MenuIds::MenuForward, "Forward", web_page->canGoForward(), 159 | [](QCefWebPage* page) { 160 | page->forward(); 161 | }); 162 | if (web_page->isLoading()) { 163 | menu->addItem(MenuIds::MenuStop, "Stop", true, 164 | [](QCefWebPage* page) { 165 | page->stop(); 166 | }); 167 | } else { 168 | menu->addItem(MenuIds::MenuReload, "Reload", true, 169 | [](QCefWebPage* page) { 170 | page->reload(); 171 | }); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /browser_demo/browser_event_delegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_BROWSER_EVENT_DELEGATE_H 19 | #define QCEF_BROWSER_EVENT_DELEGATE_H 20 | 21 | #include 22 | #include 23 | 24 | struct BrowserEventDelegatePrivate; 25 | 26 | class BrowserEventDelegate : public QObject, 27 | public QCefBrowserEventDelegate { 28 | Q_OBJECT 29 | 30 | public: 31 | explicit BrowserEventDelegate(QObject* parent = nullptr); 32 | 33 | ~BrowserEventDelegate() override; 34 | 35 | bool onBeforeBrowse(const QUrl& url, bool is_redirect) override; 36 | 37 | void onBeforeContextMenu(QCefWebPage* web_page, 38 | QCefContextMenu* menu, 39 | const QCefContextMenuParams& params) override; 40 | 41 | bool onBeforePopup(const QUrl& url, 42 | QCefWindowOpenDisposition disposition) override; 43 | 44 | signals: 45 | void popupRequested(const QUrl& url, QCefWindowOpenDisposition disposition); 46 | void copyLinkToClipboard(const QUrl& url); 47 | 48 | private: 49 | BrowserEventDelegatePrivate* p_ = nullptr; 50 | }; 51 | 52 | #endif // QCEF_BROWSER_EVENT_DELEGATE_H 53 | -------------------------------------------------------------------------------- /browser_demo/browser_tab_bar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "browser_tab_bar.h" 19 | 20 | #include 21 | #include 22 | 23 | BrowserTabBar::BrowserTabBar(QWidget* parent) : QTabBar(parent) { 24 | this->setStyleSheet("QTabBar::tab { max-width: 200px; }"); 25 | this->setUsesScrollButtons(true); 26 | } 27 | 28 | void BrowserTabBar::contextMenuEvent(QContextMenuEvent* event) { 29 | QWidget::contextMenuEvent(event); 30 | // TODO(LiuLang): show context menu. 31 | } -------------------------------------------------------------------------------- /browser_demo/browser_tab_bar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_BROWSER_TAB_BAR_H 19 | #define QCEF_BROWSER_TAB_BAR_H 20 | 21 | #include 22 | 23 | class BrowserTabBar : public QTabBar { 24 | Q_OBJECT 25 | public: 26 | explicit BrowserTabBar(QWidget* parent = nullptr); 27 | 28 | protected: 29 | void contextMenuEvent(QContextMenuEvent* event) override; 30 | }; 31 | 32 | 33 | #endif //CEF_BROWSER_TAB_BAR_H 34 | -------------------------------------------------------------------------------- /browser_demo/browser_tab_widget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_BROWSER_TAB_WIDGET_H 19 | #define QCEF_BROWSER_TAB_WIDGET_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | struct BrowserTabWidgetPrivate; 27 | 28 | class BrowserTabWidget : public QTabWidget { 29 | Q_OBJECT 30 | 31 | public: 32 | explicit BrowserTabWidget(QWidget* parent = nullptr); 33 | ~BrowserTabWidget() override; 34 | 35 | // Get loading state of current web view. 36 | bool isLoading() const; 37 | 38 | QCefSSLStatus getSSlStatus() const; 39 | 40 | signals: 41 | void fullscreenRequested(bool fullscreen); 42 | void urlChanged(const QUrl& url); 43 | 44 | void loadingStateChanged(bool is_loading, 45 | bool can_go_back, 46 | bool can_go_forward); 47 | 48 | public slots: 49 | void createNewBrowser(bool in_background, const QUrl& url = QUrl()); 50 | 51 | // Control navigation of current web page. 52 | void back(); 53 | void forward(); 54 | void reload(); 55 | void stop(); 56 | 57 | // Load |url| in current web view. 58 | void load(const QUrl& url); 59 | 60 | void zoomIn(); 61 | void zoomOut(); 62 | void zoomReset(); 63 | 64 | protected: 65 | void mouseDoubleClickEvent(QMouseEvent* event) override; 66 | 67 | private: 68 | void initConnections(); 69 | 70 | BrowserTabWidgetPrivate* p_ = nullptr; 71 | 72 | private slots: 73 | void onCurrentChanged(int index); 74 | 75 | // Hide tab bar in fullscreen mode. 76 | void onFullscreenRequested(bool fullscreen); 77 | 78 | void onNotificationReceived(const QString& summary, const QString& body); 79 | 80 | // Close web view at |index|. 81 | void onTabCloseRequested(int index); 82 | 83 | void onRefreshRequested(); 84 | void onPopupRequested(const QUrl& url, 85 | QCefWindowOpenDisposition disposition); 86 | void onToggleFullscreen(); 87 | 88 | void setClipboardUrl(const QUrl& url); 89 | }; 90 | 91 | 92 | #endif //CEF_BROWSER_TAB_WIDGET_H 93 | -------------------------------------------------------------------------------- /browser_demo/browser_window.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_BROWSER_DEMO_BROWSER_WINDOW_H 19 | #define QCEF_BROWSER_DEMO_BROWSER_WINDOW_H 20 | 21 | #include 22 | 23 | class QCefWebView; 24 | struct BrowserWindowPrivate; 25 | 26 | class BrowserWindow : public QFrame { 27 | Q_OBJECT 28 | 29 | public: 30 | explicit BrowserWindow(QWidget* parent = nullptr); 31 | ~BrowserWindow() override; 32 | 33 | private: 34 | void initConnections(); 35 | void initUI(); 36 | 37 | BrowserWindowPrivate* p_ = nullptr; 38 | 39 | private slots: 40 | void onAddressEditActivated(); 41 | void onReloadButtonClicked(); 42 | 43 | void onFullscreenRequested(bool fullscreen); 44 | void onLoadingStateChanged(bool is_loading, 45 | bool can_go_back, 46 | bool can_go_forward); 47 | void onUrlChanged(const QUrl& url); 48 | 49 | void showHomePage(); 50 | }; 51 | 52 | #endif // QCEF_BROWSER_DEMO_BROWSER_WINDOW_H 53 | -------------------------------------------------------------------------------- /browser_demo/channel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "channel.h" 19 | 20 | #include 21 | 22 | Channel::Channel(QObject* parent) : QObject(parent) { 23 | this->setObjectName("channel"); 24 | } 25 | 26 | void Channel::printMessage(const QString& msg) { 27 | qDebug() << "Channel::printMessage()" << msg; 28 | } 29 | 30 | int Channel::count() { 31 | count_ ++; 32 | return count_; 33 | } 34 | 35 | void Channel::execSql(const QString& id, const QString& statement) { 36 | qDebug() << "execSql()" << id << statement; 37 | emit this->onExecSqlDone(id, 0, QVariantList({"hello", "world"})); 38 | } 39 | -------------------------------------------------------------------------------- /browser_demo/channel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_BROWSWER_DEMO_CHANNEL_H 19 | #define QCEF_BROWSWER_DEMO_CHANNEL_H 20 | 21 | #include 22 | 23 | class Channel : public QObject { 24 | Q_OBJECT 25 | public: 26 | explicit Channel(QObject* parent = nullptr); 27 | 28 | public slots: 29 | void printMessage(const QString& msg); 30 | int count(); 31 | 32 | void execSql(const QString& id, const QString& statement); 33 | 34 | signals: 35 | void onExecSqlDone(const QString& id, int state, const QVariantList& result); 36 | 37 | private: 38 | int count_ = 0; 39 | }; 40 | 41 | 42 | #endif // QCEF_BROWSWER_DEMO_CHANNEL_H 43 | -------------------------------------------------------------------------------- /browser_demo/images/document-print-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 23 | 24 | 26 | image/svg+xml 27 | 29 | Gnome Symbolic Icon Theme 30 | 31 | 32 | 33 | 67 | 79 | 80 | Gnome Symbolic Icon Theme 82 | 84 | 90 | 96 | 101 | 107 | 112 | 118 | 124 | 130 | 136 | 142 | 148 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /browser_demo/images/firefox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martyr-deepin/qcef/ff3448cb3f86f42946d4c9eb01ccaa994f174fe0/browser_demo/images/firefox.png -------------------------------------------------------------------------------- /browser_demo/images/go-next-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 23 | 24 | 26 | image/svg+xml 27 | 29 | Gnome Symbolic Icon Theme 30 | 31 | 32 | 33 | 67 | 79 | 80 | Gnome Symbolic Icon Theme 82 | 84 | 90 | 96 | 101 | 107 | 112 | 118 | 124 | 130 | 136 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /browser_demo/images/go-previous-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 23 | 24 | 26 | image/svg+xml 27 | 29 | Gnome Symbolic Icon Theme 30 | 31 | 32 | 33 | 67 | 79 | 80 | Gnome Symbolic Icon Theme 82 | 84 | 90 | 96 | 101 | 107 | 112 | 118 | 124 | 130 | 136 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /browser_demo/images/images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | document-new-symbolic.svg 4 | document-print-symbolic.svg 5 | firefox.png 6 | go-next-symbolic.svg 7 | go-previous-symbolic.svg 8 | system-lock-screen-symbolic.svg 9 | user-home-symbolic.svg 10 | view-more-symbolic.svg 11 | view-refresh-symbolic.svg 12 | window-close-symbolic.svg 13 | zoom-in-symbolic.svg 14 | zoom-original-symbolic.svg 15 | zoom-out-symbolic.svg 16 | 17 | 18 | -------------------------------------------------------------------------------- /browser_demo/images/system-lock-screen-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 23 | 24 | 26 | image/svg+xml 27 | 29 | Gnome Symbolic Icon Theme 30 | 31 | 32 | 33 | 67 | 79 | 80 | Gnome Symbolic Icon Theme 82 | 84 | 90 | 95 | 96 | 102 | 107 | 113 | 118 | 124 | 130 | 136 | 142 | 143 | -------------------------------------------------------------------------------- /browser_demo/images/view-more-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 21 | 23 | image/svg+xml 24 | 26 | Gnome Symbolic Icon Theme 27 | 28 | 29 | 30 | 64 | 75 | 90 | 91 | Gnome Symbolic Icon Theme 93 | 95 | 101 | 106 | 111 | 116 | 121 | 127 | 133 | 139 | 145 | 154 | 163 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /browser_demo/images/view-refresh-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 23 | 24 | 26 | image/svg+xml 27 | 29 | Gnome Symbolic Icon Theme 30 | 31 | 32 | 33 | 67 | 79 | 80 | Gnome Symbolic Icon Theme 82 | 84 | 90 | 96 | 101 | 107 | 112 | 118 | 124 | 130 | 136 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /browser_demo/images/window-close-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 38 | Gnome Symbolic Icon Theme 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | Gnome Symbolic Icon Theme 49 | 50 | 51 | 52 | 54 | 58 | 61 | 64 | 67 | 71 | 76 | 77 | 78 | 81 | 84 | 87 | 88 | -------------------------------------------------------------------------------- /browser_demo/images/zoom-in-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 21 | 23 | image/svg+xml 24 | 26 | Gnome Symbolic Icon Theme 27 | 28 | 29 | 30 | 63 | 74 | 75 | Gnome Symbolic Icon Theme 77 | 79 | 85 | 90 | 95 | 100 | 105 | 111 | 117 | 123 | 129 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /browser_demo/images/zoom-original-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 21 | 23 | image/svg+xml 24 | 26 | Gnome Symbolic Icon Theme 27 | 28 | 29 | 30 | 63 | 74 | 75 | Gnome Symbolic Icon Theme 77 | 79 | 85 | 90 | 95 | 100 | 105 | 111 | 117 | 123 | 129 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /browser_demo/images/zoom-out-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 21 | 23 | image/svg+xml 24 | 26 | Gnome Symbolic Icon Theme 27 | 28 | 29 | 30 | 63 | 74 | 75 | Gnome Symbolic Icon Theme 77 | 79 | 85 | 90 | 95 | 100 | 105 | 111 | 117 | 123 | 129 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /browser_demo/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "browser_window.h" 26 | #include "sync_methods.h" 27 | 28 | #ifndef N_DEBUG 29 | // operation overloading is missing in debug mode. 30 | std::ostream& operator<<(std::ostream& os, wchar_t const* c) { 31 | os << c; 32 | return os; 33 | } 34 | #endif 35 | 36 | namespace { 37 | 38 | const char kPlatformThemeName[] = "QT_QPA_PLATFORMTHEME"; 39 | const char kGtk2Theme[] = "gtk2"; 40 | 41 | } // namespace 42 | 43 | int main(int argc, char* argv[]) { 44 | // If platform theme name is empty, fallback to gtk2. 45 | // gtk2 theme is included in libqt5libqgtk2 package. 46 | if (qgetenv(kPlatformThemeName) != kGtk2Theme) { 47 | qputenv(kPlatformThemeName, kGtk2Theme); 48 | } 49 | 50 | QCefGlobalSettings settings; 51 | // Do not use sandbox. 52 | settings.setNoSandbox(true); 53 | 54 | // Flash plugin only works on x86 platform. 55 | if (IsX86Architecture()) { 56 | // Pepper flash plugin crashes on chromium 60 57 | // settings.setPepperFlash(true); 58 | } 59 | 60 | // Use socks5 proxy. 61 | // settings.setProxyServer("socks5://127.0.0.1:1080"); 62 | 63 | // Open http://localhost:9222 in chromium browser to see dev tools. 64 | settings.setRemoteDebug(true); 65 | settings.setLogSeverity(QCefGlobalSettings::LogSeverity::Info); 66 | 67 | QDir cache_dir(QDir::home().filePath(".cache/qcef/browser-demo")); 68 | cache_dir.mkpath("."); 69 | settings.setUserDataPath(cache_dir.filePath("data")); 70 | settings.setCachePath(cache_dir.filePath("cache")); 71 | settings.setLogFile(cache_dir.filePath("web-console.log")); 72 | 73 | // Register echoMessage in web page. 74 | settings.registerSyncMethod("echoMessage", EchoMessage); 75 | 76 | // Register user script. 77 | settings.registerUserScript(":/resources/user_script.js", 78 | QUrl("qrc://resources/user_script.js")); 79 | 80 | // Disable GPU process. 81 | settings.addCommandLineSwitch("--disable-gpu", ""); 82 | 83 | // Enable aggressive storage commit to minimize data loss. 84 | // See public/common/content_switches.cc. 85 | settings.addCommandLineSwitch("--enable-aggressive-domstorage-flushing", ""); 86 | 87 | const int exit_code = QCefInit(argc, argv, settings); 88 | if (exit_code >= 0) { 89 | return exit_code; 90 | } 91 | 92 | QApplication app(argc, argv); 93 | app.setWindowIcon(QIcon(":/images/firefox.png")); 94 | 95 | qCritical() << "Qt:" << QT_VERSION << QT_VERSION_MAJOR << QT_VERSION_MINOR; 96 | 97 | BrowserWindow browser_window; 98 | browser_window.resize(860, 640); 99 | browser_window.show(); 100 | 101 | QCefBindApp(&app); 102 | return app.exec(); 103 | } 104 | -------------------------------------------------------------------------------- /browser_demo/resources/iframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | iframe 6 | 7 | 8 | 9 |
10 |

iframe-test

11 |
12 | 13 |
14 |
15 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /browser_demo/resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello, CEF 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 |
14 |

Channel test

15 |
16 |

Send message to channel object

17 | 18 | 19 |
20 |
21 | 22 |
23 | 24 |
25 | 26 |
27 |
28 | 29 | 32 | 33 |
34 |

Tooltip position

35 | Amazon China 36 |
37 | 38 |
39 |

Cross Domain

40 | 41 |
42 | 43 |
44 |

Dialog test

45 |
46 | 47 | 49 | 51 |
52 |
53 | 54 |
55 | 56 |
57 | 58 |
59 |

Download Handler

60 | qcef.zip 61 |
62 | 63 |
64 |

PDF files

65 | The GNU 66 | C Reference Manual 67 |
68 | 69 |
70 |

Web Notification

71 | 74 |
75 | 76 |
77 |

onBeforeBrowse() test

78 | Bing.com 79 |
80 | 81 |
82 |

Javascript close window

83 | 84 |
85 | 86 |
87 |

Javascript popup window

88 | 89 |
90 | 91 |
92 |

Check redirect

93 | 94 |
95 | 96 |
97 |

Dispatch Event

98 |
99 | 100 |
101 | 102 |
103 | 104 |
105 |

LocalStorage

106 | 0 107 | 108 |
109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /browser_demo/resources/redirect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello, CEF 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 |
14 |

Channel test

15 |
16 |

Send message to channel object

17 | 18 | 19 |
20 |
21 | 22 |
23 | 24 |
25 | 26 |
27 |
28 | 29 | 32 | 33 |
34 |

Tooltip position

35 | Amazon China 36 |
37 | 38 |
39 |

Cross Domain

40 | 41 |
42 | 43 |
44 |

Dialog test

45 |
46 | 47 | 49 | 51 |
52 |
53 | 54 |
55 | 56 |
57 | 58 |
59 |

Download Handler

60 | qcef.zip 61 |
62 | 63 |
64 |

PDF files

65 | The GNU 66 | C Reference Manual 67 |
68 | 69 |
70 |

Web Notification

71 | 74 |
75 | 76 |
77 |

onBeforeBrowse() test

78 | Bing.com 79 |
80 | 81 |
82 |

Javascript close window

83 | 84 |
85 | 86 |
87 |

Javascript popup window

88 | 89 |
90 | 91 |
92 |

Check redirect

93 | 94 |
95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /browser_demo/resources/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | iframe.html 4 | index.html 5 | redirect.html 6 | script.js 7 | style.css 8 | user_script.js 9 | 10 | 11 | -------------------------------------------------------------------------------- /browser_demo/resources/script.js: -------------------------------------------------------------------------------- 1 | 2 | "use strict"; 3 | 4 | console.log("LOADING script.js"); 5 | 6 | function testCrossDomain() { 7 | var xhr = new XMLHttpRequest(); 8 | xhr.open('get', 'http://music.163.com'); 9 | xhr.send(); 10 | } 11 | 12 | function channelCount() { 13 | qWebChannel.objects.channel.count(function(id) { 14 | console.log("id: ", id); 15 | }); 16 | } 17 | 18 | function execSql() { 19 | var id = "query-1"; 20 | var statement = "statement-1"; 21 | qWebChannel.objects.channel.execSql(id, statement); 22 | } 23 | 24 | function printMessage(msg) { 25 | qWebChannel.objects.channel.printMessage(msg); 26 | } 27 | 28 | function onConfirmButtonClicked() { 29 | var ret = confirm("Confirm?"); 30 | console.log("confirm result: ", ret); 31 | } 32 | 33 | function onPromptButtonClicked() { 34 | var ret = prompt("Please input your name:"); 35 | console.log("prompt returns: ", ret); 36 | } 37 | 38 | function closeWindow() { 39 | window.close(); 40 | } 41 | 42 | function popupWindow() { 43 | window.open("http://www.z.cn"); 44 | } 45 | 46 | function onNotificationButtonClicked() { 47 | var msgTitle = "Message title"; 48 | var msgOption = { 49 | body: "Message body!", 50 | icon: "qrc://images/user-home-symbolic.svg", 51 | tag: "tag", 52 | } 53 | // Let's check if the browser supports notifications 54 | if (!("Notification" in window)) { 55 | alert("This browser does not support system notifications"); 56 | } else if (Notification.permission === "granted") { 57 | // Let's check whether notification permissions have already been granted 58 | // If it's okay let's create a notification 59 | var notification = new Notification(msgTitle, msgOption); 60 | } else if (Notification.permission !== 'denied') { 61 | // Otherwise, we need to ask the user for permission 62 | Notification.requestPermission(function (permission) { 63 | // If the user accepts, let's create a notification 64 | if (permission === "granted") { 65 | var notification = new Notification(msgTitle, msgOption); 66 | } 67 | }); 68 | } 69 | 70 | // Finally, if the user has denied notifications and you 71 | // want to be respectful there is no need to bother them any more. 72 | } 73 | 74 | function redirectPage() { 75 | window.location.href = "qrc://resources/redirect.html"; 76 | } 77 | 78 | function selectImageFiles() { 79 | const file = document.querySelector("input.avatar-file"); 80 | if (file) { 81 | const event = new MouseEvent("click", { 82 | bubbles: true, 83 | cancelable: true, 84 | view: window 85 | }); 86 | file.dispatchEvent(event); 87 | } 88 | } 89 | 90 | function updateButtonClickCount() { 91 | const key = "button-click"; 92 | const val = getButtonClickCount(); 93 | window.localStorage.setItem(key, val + 1); 94 | updateButtonClickLabel(); 95 | } 96 | 97 | function updateButtonClickLabel() { 98 | const span = document.querySelector(".local-storage-label"); 99 | span.innerHTML = getButtonClickCount(); 100 | } 101 | 102 | function getButtonClickCount() { 103 | const key = "button-click"; 104 | var val = window.localStorage.getItem(key); 105 | if (val !== null) { 106 | return parseInt(val); 107 | } else { 108 | return 0; 109 | } 110 | } 111 | 112 | function bootstrap() { 113 | qWebChannel.objects.titleBar.onBackButtonClicked.connect(function() { 114 | navigator.goBack(); 115 | }); 116 | qWebChannel.objects.channel.onExecSqlDone.connect(function(id, state, result) { 117 | console.log("id: ", id, ", state: ", state, ", result:", result); 118 | }); 119 | 120 | document.getElementById("send").onclick = function () { 121 | var msg = document.getElementById("msg").value; 122 | printMessage(msg); 123 | }; 124 | 125 | updateButtonClickLabel(); 126 | } 127 | 128 | new QWebChannel(qt.webChannelTransport, function (channel) { 129 | window.qWebChannel = channel; 130 | bootstrap(); 131 | }); 132 | -------------------------------------------------------------------------------- /browser_demo/resources/style.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: blue; 3 | font-size: 42px; 4 | } 5 | 6 | .avatar-file { 7 | visibility: hidden; 8 | } -------------------------------------------------------------------------------- /browser_demo/resources/user_script.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | console.log("LOADING user_script.js"); 4 | 5 | function user_script_function() { 6 | console.log("Hello user script"); 7 | } -------------------------------------------------------------------------------- /browser_demo/sync_methods.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "sync_methods.h" 19 | 20 | #include 21 | 22 | QString EchoMessage(const QString& msg) { 23 | qDebug() << __FUNCTION__ << msg; 24 | return msg; 25 | } -------------------------------------------------------------------------------- /browser_demo/sync_methods.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_BROWSER_DEMO_SYNC_METHODS_H 19 | #define QCEF_BROWSER_DEMO_SYNC_METHODS_H 20 | 21 | #include 22 | #include 23 | 24 | QString EchoMessage(const QString& msg); 25 | 26 | #endif // QCEF_BROWSER_DEMO_SYNC_METHODS_H 27 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | qcef (1.1.4.4) stable; urgency=medium 2 | 3 | * Move cef to submodule 4 | * Update cef binary package 5 | 6 | -- Liu Lang Thu, 29 Mar 2018 16:20:02 +0800 7 | 8 | qcef (1.1.4.3) stable; urgency=medium 9 | 10 | * Add _NET_WM_PID flag to chrome wrapper window 11 | 12 | -- Liu Lang Wed, 21 Mar 2018 15:13:01 +0800 13 | 14 | qcef (1.1.4.2) stable; urgency=medium 15 | 16 | * Add NativeEventFilter to handle mouse press event 17 | * Add window flag to chrome windows 18 | * Remove QCEF_EXTERNAL_MESSAGE_PUMP flag 19 | 20 | -- Liu Lang Wed, 21 Mar 2018 09:20:27 +0800 21 | 22 | qcef (1.1.4.1) stable; urgency=medium 23 | 24 | * Update cef x86-64 tarball 25 | 26 | -- Liu Lang Fri, 16 Mar 2018 11:48:58 +0800 27 | 28 | qcef (1.1.4) stable; urgency=medium 29 | 30 | * Update cef to 60.0.3112.113 31 | * Auto update cef window position on move event 32 | * Implement OnClipboardUpdated() methods in CefClientHandler 33 | * Support QShortcut 34 | * Replace QWindow with XWindow 35 | * Support updating browser locale 36 | * Support HiDPI screen 37 | 38 | -- Liu Lang Thu, 15 Mar 2018 15:53:21 +0800 39 | 40 | qcef (1.1.3) stable; urgency=medium 41 | 42 | * Fix libqcef library path error 43 | * Update package dependency 44 | * Support specifying override-path at runtime 45 | 46 | -- Liu Lang Fri, 17 Nov 2017 13:09:47 +0800 47 | 48 | qcef (1.1.2) stable; urgency=medium 49 | 50 | * WebView: set update-geometry-timer as single shot 51 | * Add QCEF_EXTERNAL_MESSAGE_PUMP option 52 | * Remove EMBED_WEBCHANNEL option 53 | * Remove QCEF_OVERRIDE_PATH option 54 | 55 | -- LiuLang Wed, 10 Nov 2017 17:01:31 +0800 56 | 57 | qcef (1.1.0) stable; urgency=medium 58 | 59 | * Add event filter to web view 60 | * Add iframe demo 61 | * Add internal MessagePumpHandler 62 | * Add localstorage demo 63 | * Add redirect page demo 64 | * Add web notification API 65 | * Support appending command line arguments 66 | * Support embed qwebchannel library 67 | * Support filetype filter in file-chooser-dialog 68 | * Support network proxy 69 | * Support refreshing web page 70 | * Support zoom-in / zoom-out web page 71 | * Fix double free pointer in debug mode 72 | * Fix iconChanged() signal 73 | * Fix segfault in updateBrowserGeometry() 74 | * Fix WindowOpenDisposition invalid in GCC5 75 | 76 | -- LiuLang Wed, 09 Nov 2017 16:55:31 +0800 77 | 78 | qcef (1.0.0) stable; urgency=medium 79 | 80 | * Initial release 81 | 82 | -- LiuLang Wed, 09 Aug 2017 09:55:36 +0800 83 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: qcef 2 | Section: libdevel 3 | Priority: optional 4 | Maintainer: LiuLang 5 | Build-Depends: debhelper (>= 9), 6 | ca-certificates, 7 | cmake, 8 | git, 9 | libasound2, 10 | libfl-dev, 11 | libfontconfig1-dev, 12 | libgconf-2-4, 13 | libgtk2.0-dev, 14 | libglib2.0-dev, 15 | libharfbuzz-dev, 16 | libnspr4, 17 | libnss3, 18 | libpulse0, 19 | libqt5webchannel5-dev, 20 | libqt5x11extras5-dev, 21 | libx11-dev, 22 | libxext-dev, 23 | libxss-dev, 24 | libxtst-dev, 25 | mesa-common-dev, 26 | pkg-config, 27 | qtbase5-private-dev, 28 | qttools5-dev-tools, 29 | Standards-Version: 3.9.8 30 | Homepage: https://www.deepin.org 31 | 32 | Package: libqcef1 33 | Architecture: any 34 | Multi-Arch: same 35 | Depends: ${shlibs:Depends}, ${misc:Depends}, 36 | Conflicts: libqcef 37 | Replaces: libqcef 38 | Description: Qt5 binding of CEF3. 39 | qcef provides a web browser engine that makes it easy to embed into other 40 | Qt widgets. 41 | 42 | Package: libqcef-dev 43 | Architecture: any 44 | Depends: ${misc:Depends}, 45 | libgconf-2-4, 46 | libpulse0, 47 | libqcef1 ( = ${binary:Version}) 48 | Description: Qt5 binding of CEF3. 49 | qcef provides a web browser engine that makes it easy to embed into other 50 | Qt widgets. 51 | . 52 | This package contains the header files of qcef. 53 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: qcef 3 | Upstream-Contact: xushaohua 4 | Source: https://github.com/linuxdeepin/qcef 5 | 6 | Files: * 7 | Copyright: 2017 Deepin Ltd. 8 | License: LGPL-3+ 9 | This package is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation; either version 3 of the License, or 12 | (at your option) any later version. 13 | . 14 | This package is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | . 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with this program. If not, see 21 | . 22 | On Debian systems, the complete text of the GNU General 23 | Public License version 3 can be found in "/usr/share/common-licenses/LGPL-3". 24 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /debian/libqcef-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/* 2 | usr/lib/*/pkgconfig/* 3 | usr/lib/*/libqcef.so 4 | -------------------------------------------------------------------------------- /debian/libqcef1.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/libqcef.so.* 2 | usr/lib/*/qcef 3 | -------------------------------------------------------------------------------- /debian/libqcef1.lintian-overrides: -------------------------------------------------------------------------------- 1 | libqcef1: embedded-library usr/lib/libcef.so: libavutil 2 | libqcef1: embedded-library usr/lib/libcef.so: lcms2 3 | libqcef1: embedded-library usr/lib/libcef.so: srtp 4 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | export QT_SELECT=qt5 3 | export DH_VERBOSE=1 4 | 5 | DH_AUTO_ARGS = --parallel --buildsystem=cmake 6 | 7 | %: 8 | dh $@ --parallel 9 | 10 | # Override qcef exe path to /usr/lib/qcef. 11 | override_dh_auto_configure: 12 | ifneq (,$(wildcard .git/config)) 13 | git submodule update --init --recursive 14 | git submodule update --remote 15 | else 16 | rm -rf cef 17 | git clone https://cr.deepin.io/cef-binary cef 18 | endif 19 | dh_auto_configure -- \ 20 | -DCMAKE_BUILD_TYPE=Release \ 21 | -DPROJECT_ARCH=${DEB_TARGET_GNU_CPU} \ 22 | -DCMAKE_INSTALL_PREFIX=/usr \ 23 | -DQCEF_INSTALL_PATH=/usr/lib/${DEB_HOST_MULTIARCH} 24 | 25 | override_dh_auto_build: 26 | dh_auto_build -- qcef 27 | 28 | # chrome-sandbox requires SUID attribute. 29 | override_dh_fixperms: 30 | dh_fixperms --exclude chrome-sandbox 31 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /docs/cef.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martyr-deepin/qcef/ff3448cb3f86f42946d4c9eb01ccaa994f174fe0/docs/cef.md -------------------------------------------------------------------------------- /docs/proxy.md: -------------------------------------------------------------------------------- 1 | ## Network Proxy 2 | -------------------------------------------------------------------------------- /src/base/file_util.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Deepin Ltd. All rights reserved. 2 | // Use of this source is governed by General Public License that can be found 3 | // in the LICENSE file. 4 | 5 | #include "base/file_util.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | QDir ConcateDir(const QDir& parent_dir, const QString& folder_name) { 17 | if (!parent_dir.exists(folder_name)) { 18 | // TODO(xushaohua): Handles permission error. 19 | parent_dir.mkpath(folder_name); 20 | } 21 | return QDir(parent_dir.filePath(folder_name)); 22 | } 23 | 24 | bool CopyFile(const QString& src_file, 25 | const QString& dest_file, 26 | bool overwrite) { 27 | QFile dest(dest_file); 28 | if (dest.exists()) { 29 | if (overwrite) { 30 | if (!dest.remove()) { 31 | qCritical() << "Failed to remove:" << dest_file; 32 | return false; 33 | } 34 | } else { 35 | qCritical() << dest_file << "exists but is not overwritten"; 36 | return false; 37 | } 38 | } 39 | return QFile::copy(src_file, dest_file); 40 | } 41 | 42 | bool CopyFolder(const QString src_dir, const QString& dest_dir, 43 | bool recursive) { 44 | QDirIterator::IteratorFlag iter_flag; 45 | if (recursive) { 46 | iter_flag = QDirIterator::Subdirectories; 47 | } else { 48 | iter_flag = QDirIterator::NoIteratorFlags; 49 | } 50 | QDirIterator iter(src_dir, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, 51 | iter_flag); 52 | QFileInfo src_info; 53 | QString dest_filepath; 54 | bool ok = true; 55 | if (!QDir(dest_dir).exists()) { 56 | ok = CreateDirs(dest_dir); 57 | } 58 | 59 | // Walk through source folder. 60 | while (ok && iter.hasNext()) { 61 | src_info = iter.next(); 62 | dest_filepath = iter.filePath().replace(src_dir, dest_dir); 63 | if (src_info.isDir()) { 64 | if (!QDir(dest_filepath).exists()) { 65 | ok = CreateDirs(dest_filepath); 66 | } 67 | if (ok) { 68 | ok = CopyMode(iter.filePath().toStdString().c_str(), 69 | dest_filepath.toStdString().c_str()); 70 | } 71 | } else if (src_info.isFile()) { 72 | if (QFile::exists(dest_filepath)) { 73 | // Remove old file first. 74 | QFile::remove(dest_filepath); 75 | } 76 | ok = QFile::copy(iter.filePath(), dest_filepath); 77 | if (ok) { 78 | ok = CopyMode(iter.filePath().toStdString().c_str(), 79 | dest_filepath.toStdString().c_str()); 80 | } 81 | } else if (src_info.isSymLink()) { 82 | if (QFile::exists(dest_filepath)) { 83 | QFile::remove(dest_filepath); 84 | } 85 | ok = QFile::link(src_info.canonicalFilePath(), dest_filepath); 86 | } else { 87 | // Ignores other type of files. 88 | } 89 | } 90 | return ok; 91 | } 92 | 93 | bool CopyMode(const char* src_file, const char* dest_file) { 94 | struct stat st; 95 | if (stat(src_file, &st) == -1) { 96 | return false; 97 | } 98 | 99 | const mode_t mode = st.st_mode & 0777; 100 | return (chmod(dest_file, mode) == 0); 101 | } 102 | 103 | bool CreateDirs(const QString& dirpath) { 104 | return QDir(dirpath).mkpath("."); 105 | } 106 | 107 | bool CreateParentDirs(const QString& filepath) { 108 | return QFileInfo(filepath).absoluteDir().mkpath("."); 109 | } 110 | 111 | QString GetFileBasename(const QString& filepath) { 112 | const QString filename = GetFileName(filepath); 113 | const int dot_index = filename.lastIndexOf(QChar('.')); 114 | if (dot_index > 0) { 115 | return filename.left(dot_index); 116 | } else { 117 | // Filename does not contain extension name. 118 | return filename; 119 | } 120 | } 121 | 122 | QString GetFileExtname(const QString& filepath) { 123 | const int dot_index = filepath.lastIndexOf(QChar('.')); 124 | if (dot_index > 0) { 125 | // Ignores hidden file. 126 | return filepath.mid(dot_index + 1).toLower(); 127 | } 128 | 129 | return ""; 130 | } 131 | 132 | QString GetFileName(const QString& filepath) { 133 | const int slash_index = filepath.lastIndexOf(QDir::separator()); 134 | if (slash_index > -1) { 135 | return filepath.mid(slash_index + 1); 136 | } else { 137 | // filepath is the filename. 138 | return filepath; 139 | } 140 | } 141 | 142 | qint64 GetFileSize(const QString& filepath) { 143 | QFileInfo info(filepath); 144 | if (info.exists()) { 145 | return info.size(); 146 | } else { 147 | return 0; 148 | } 149 | } 150 | 151 | QString ReadFile(const QString& path) { 152 | QFile file(path); 153 | if (file.exists()) { 154 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 155 | qWarning() << "ReadFile() failed to open" << path; 156 | return ""; 157 | } 158 | QTextStream text_stream(&file); 159 | QString str = text_stream.readAll(); 160 | file.close(); 161 | return str; 162 | } else { 163 | qWarning() << "ReadFileContent() file not found: " << path; 164 | return ""; 165 | } 166 | } 167 | 168 | QString ReadGBKFile(const QString& path) { 169 | QFile file(path); 170 | if (file.exists()) { 171 | if (!file.open(QIODevice::ReadOnly)) { 172 | qWarning() << "ReadGBKFile() failed to open" << path; 173 | return ""; 174 | } 175 | const QByteArray file_data = file.readAll(); 176 | QTextCodec* codec = QTextCodec::codecForName("GB18030"); 177 | file.close(); 178 | return codec->toUnicode(file_data); 179 | } else { 180 | qWarning() << "ReadGBKFile() file not found:" << path; 181 | return ""; 182 | } 183 | } 184 | 185 | bool ReadRawFile(const QString& path, QByteArray& content) { 186 | QFile file(path); 187 | if (file.exists()) { 188 | if (file.open(QIODevice::ReadOnly)) { 189 | content = file.readAll(); 190 | return true; 191 | } 192 | } 193 | qWarning() << "ReadRawFile() failed!" << path; 194 | return false; 195 | } 196 | 197 | bool ReadTextFile(const QString& path, QString& content) { 198 | QFile file(path); 199 | if (file.exists()) { 200 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { 201 | QTextStream text_stream(&file); 202 | content = text_stream.readAll(); 203 | file.close(); 204 | return true; 205 | } 206 | } 207 | qWarning() << "ReadTextFile() failed!" << path; 208 | return false; 209 | } 210 | 211 | bool WriteTextFile(const QString& path, const QString& content) { 212 | QFile file(path); 213 | if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { 214 | QTextStream text_stream(&file); 215 | text_stream << content; 216 | text_stream.flush(); 217 | file.close(); 218 | return true; 219 | }else { 220 | qCritical() << "WriteTextFile() failed!" << ", path:" << path; 221 | return false; 222 | } 223 | } -------------------------------------------------------------------------------- /src/base/file_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 Deepin Ltd. All rights reserved. 2 | // Use of this source is governed by General Public License that can be found 3 | // in the LICENSE file. 4 | 5 | #ifndef QCEF_BASE_FILE_UTIL_H 6 | #define QCEF_BASE_FILE_UTIL_H 7 | 8 | #include 9 | #include 10 | 11 | // Create a folder with |folder_name| in |parent_dir| directory and 12 | // returns a QDir object referencing to its absolute path. 13 | QDir ConcateDir(const QDir& parent_dir, const QString& folder_name); 14 | 15 | // Copy file from |src_file| to |dest_file|. 16 | // If |dest_file| exists, overwrite its content if |overwrite| is true, or 17 | // returns false if not overwrite. 18 | bool CopyFile(const QString& src_file, const QString& dest_file, bool overwrite); 19 | 20 | // Folder content in |src_dir| into |dest_dir|. 21 | // This method only copy normal files, folders and symbolic link file. 22 | // Other type of files and character device, FIFO and device file are ignored. 23 | // For advanced copy function, see misc/unsquashfs.cpp 24 | bool CopyFolder(const QString src_dir, const QString& dest_dir, 25 | bool recursive = true); 26 | 27 | // Copy file/folder mode from |src_file| to |dest_file| 28 | // Both |src_file| and |dest_file| should not be symbolic link. 29 | bool CopyMode(const char* src_file, const char* dest_file); 30 | 31 | // Create parent folders and itself. 32 | bool CreateDirs(const QString& dirpath); 33 | 34 | // Create parent folders. 35 | bool CreateParentDirs(const QString& filepath); 36 | 37 | // Returns basename of |filepath|. 38 | QString GetFileBasename(const QString& filepath); 39 | 40 | // Returns lower cased extension name of |filepath|, might be empty. 41 | QString GetFileExtname(const QString& filepath); 42 | 43 | // Returns filename of |filepath|. 44 | QString GetFileName(const QString& filepath); 45 | 46 | // Get size of file. If file not found or has no access, returns 0. 47 | qint64 GetFileSize(const QString& filepath); 48 | 49 | // Read contents of file, returns an empty string if failed. 50 | // DEPRECATED: call ReadTextFile() instead. 51 | QString ReadFile(const QString& path); 52 | 53 | // Read text file encoded in GB18030. 54 | QString ReadGBKFile(const QString& path); 55 | 56 | // Read content of file at |path|, and save its content into |content|. 57 | // Returns true if succeeded, or false otherwise. 58 | bool ReadRawFile(const QString& path, QByteArray& content); 59 | 60 | // Read contents of text file, returns true if succeeded, or false otherwise. 61 | // |content| holds the content of that file. 62 | bool ReadTextFile(const QString& path, QString& content); 63 | 64 | // Write content to file, returns true if succeeded, or false otherwise. 65 | bool WriteTextFile(const QString& path, const QString& content); 66 | 67 | #endif // QCEF_BASE_FILE_UTIL_H 68 | -------------------------------------------------------------------------------- /src/base/macros.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Deepin Ltd. All rights reserved. 2 | // Use of this source is governed by Commercial License that can be found 3 | // in the LICENSE file. 4 | 5 | #ifndef BASE_MACROS_H_ 6 | #define BASE_MACROS_H_ 7 | 8 | // These macros are copied from chromium/base. 9 | // Put this in the declarations for a class to be uncopyable. 10 | #define DISALLOW_COPY(TypeName) \ 11 | TypeName(const TypeName&) = delete 12 | 13 | // Put this in the declarations for a class to be unassignable. 14 | #define DISALLOW_ASSIGN(TypeName) \ 15 | void operator=(const TypeName&) = delete 16 | 17 | // A macro to disallow the copy constructor and operator= functions 18 | // This should be used in the private: declarations for a class 19 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 20 | TypeName(const TypeName&); \ 21 | void operator=(const TypeName&) 22 | 23 | #endif // BASE_MACROS_H_ 24 | -------------------------------------------------------------------------------- /src/core/qcef_app.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "core/qcef_app.h" 6 | 7 | #include "core/qcef_print_handler.h" 8 | #include "core/qcef_message_pump_handler.h" 9 | #include "core/qcef_renderer_handler.h" 10 | #include "core/qcef_scheme_handler_factory.h" 11 | #include "include/wrapper/cef_helpers.h" 12 | 13 | QCefApp::QCefApp() : message_handler_(new QCefMessagePumpHandler()) { 14 | } 15 | 16 | QCefApp::~QCefApp() { 17 | if (message_handler_ != nullptr) { 18 | message_handler_->deleteLater(); 19 | message_handler_ = nullptr; 20 | } 21 | } 22 | 23 | void QCefApp::OnContextInitialized() { 24 | CEF_REQUIRE_UI_THREAD(); 25 | 26 | // Register custom scheme handler factory. 27 | CefRefPtr factory = 28 | new QCefSchemeHandlerFactory(custom_scheme_handler_); 29 | CefRegisterSchemeHandlerFactory("qrc", "", factory); 30 | 31 | for (const QUrl& entry : custom_scheme_list_) { 32 | CefRegisterSchemeHandlerFactory(entry.scheme().toStdString(), 33 | entry.host().toStdString(), 34 | factory); 35 | } 36 | } 37 | 38 | void QCefApp::OnBeforeCommandLineProcessing( 39 | const CefString& process_type, 40 | CefRefPtr command_line) { 41 | (void)process_type; 42 | for (const QCefCommandLineSwitch& arg : appended_args_) { 43 | if (arg.value.isEmpty()) { 44 | command_line->AppendSwitch(arg.key.toStdString()); 45 | } else { 46 | command_line->AppendSwitchWithValue(arg.key.toStdString(), 47 | arg.value.toStdString()); 48 | } 49 | } 50 | } 51 | 52 | void QCefApp::OnRegisterCustomSchemes(CefRawPtr registrar) { 53 | // Register file:/ and qrc:/ schemes. 54 | registrar->AddCustomScheme("file", true, true, false, true, true, false); 55 | registrar->AddCustomScheme("qrc", false, true, false, true, true, false); 56 | 57 | // Register custom scheme names. 58 | if (!custom_scheme_list_.empty()) { 59 | for (const QUrl& entry : custom_scheme_list_) { 60 | registrar->AddCustomScheme(entry.scheme().toStdString(), 61 | true, true, false, true, true, false); 62 | } 63 | } 64 | } 65 | 66 | void QCefApp::appendCommandLineSwitches(const QCefCommandLineSwitchList& args) { 67 | appended_args_ = args; 68 | } 69 | 70 | CefRefPtr QCefApp::GetRenderProcessHandler() { 71 | return new QCefRendererHandler(sync_methods_, register_scripts_); 72 | } 73 | 74 | void QCefApp::addCustomSchemes(const QList& list) { 75 | custom_scheme_list_ = list; 76 | } 77 | 78 | void QCefApp::setCustomSchemeHandler(QCefSchemeHandler handler) { 79 | custom_scheme_handler_ = handler; 80 | } 81 | 82 | void QCefApp::setSyncMethods(const QCefSyncMethodMap& map) { 83 | sync_methods_ = map; 84 | } 85 | 86 | CefRefPtr QCefApp::GetPrintHandler() { 87 | return new QCefPrintHandler(); 88 | } 89 | 90 | void QCefApp::setRegisterScripts(const QCefUserScriptList& scripts) { 91 | register_scripts_ = scripts; 92 | } 93 | -------------------------------------------------------------------------------- /src/core/qcef_app.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef QCEF_CORE_QCEF_APP_H 6 | #define QCEF_CORE_QCEF_APP_H 7 | 8 | #include 9 | 10 | #include "core/qcef_global_settings.h" 11 | #include "core/qcef_scheme_handler.h" 12 | #include "core/qcef_sync_method.h" 13 | #include "include/cef_app.h" 14 | 15 | class QCefMessagePumpHandler; 16 | 17 | // Implement application-level callbacks for the browser process. 18 | class QCefApp : public CefApp, 19 | public CefBrowserProcessHandler { 20 | public: 21 | QCefApp(); 22 | ~QCefApp() override; 23 | 24 | // CefApp methods: 25 | CefRefPtr GetBrowserProcessHandler() override { 26 | return this; 27 | } 28 | CefRefPtr GetRenderProcessHandler() override; 29 | 30 | // CefBrowserProcessHandler methods: 31 | void OnContextInitialized() override; 32 | 33 | void OnBeforeCommandLineProcessing( 34 | const CefString& process_type, 35 | CefRefPtr command_line) override; 36 | 37 | void OnRegisterCustomSchemes( 38 | CefRawPtr registrar) override; 39 | 40 | CefRefPtr GetPrintHandler() override; 41 | 42 | // Open API used to customize cef app. 43 | void appendCommandLineSwitches(const QCefCommandLineSwitchList& args); 44 | 45 | void addCustomSchemes(const QList& list); 46 | 47 | void setCustomSchemeHandler(QCefSchemeHandler handler); 48 | 49 | void setSyncMethods(const QCefSyncMethodMap& map); 50 | 51 | void setRegisterScripts(const QCefUserScriptList& scripts); 52 | 53 | private: 54 | // Include the default reference counting implementation. 55 | IMPLEMENT_REFCOUNTING(QCefApp); 56 | DISALLOW_COPY_AND_ASSIGN(QCefApp); 57 | 58 | QCefCommandLineSwitchList appended_args_; 59 | QList custom_scheme_list_; 60 | QCefSchemeHandler custom_scheme_handler_ = nullptr; 61 | QCefSyncMethodMap sync_methods_; 62 | QCefUserScriptList register_scripts_; 63 | QCefMessagePumpHandler* message_handler_ = nullptr; 64 | }; 65 | 66 | #endif // QCEF_CORE_QCEF_APP_H 67 | -------------------------------------------------------------------------------- /src/core/qcef_browser_transport.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_browser_transport.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "core/qcef_web_channel_consts.h" 25 | 26 | QCefBrowserTransport::QCefBrowserTransport(CefRefPtr browser, 27 | QObject* parent) 28 | : QWebChannelAbstractTransport(parent), 29 | browser_(browser) { 30 | } 31 | 32 | void QCefBrowserTransport::sendMessage(const QJsonObject& message) { 33 | // Send message from browser process to renderer process. 34 | CefRefPtr msg = 35 | CefProcessMessage::Create(kQCefRenderQtMessage); 36 | CefRefPtr args = msg->GetArgumentList(); 37 | const std::string data = QJsonDocument(message).toJson().toStdString(); 38 | args->SetString(0, data); 39 | browser_->SendProcessMessage(PID_RENDERER, msg); 40 | } 41 | -------------------------------------------------------------------------------- /src/core/qcef_browser_transport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_WEB_CHANNEL_TRANSPORT_H 19 | #define QCEF_CORE_QCEF_WEB_CHANNEL_TRANSPORT_H 20 | 21 | #include 22 | 23 | #include "include/cef_browser.h" 24 | #include "include/internal/cef_ptr.h" 25 | 26 | // Communication channel between browser process and renderer process. 27 | class QCefBrowserTransport : public QWebChannelAbstractTransport { 28 | Q_OBJECT 29 | 30 | public: 31 | explicit QCefBrowserTransport(CefRefPtr browser, 32 | QObject* parent = nullptr); 33 | 34 | // Send messages from between browser process to render process. 35 | void sendMessage(const QJsonObject& message) override; 36 | 37 | private: 38 | CefRefPtr browser_ = nullptr; 39 | }; 40 | 41 | 42 | #endif // QCEF_CORE_QCEF_WEB_CHANNEL_TRANSPORT_H 43 | -------------------------------------------------------------------------------- /src/core/qcef_context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_CONTEXT_H 19 | #define QCEF_CORE_QCEF_CONTEXT_H 20 | 21 | #include "qcef_core_export.h" 22 | #include "qcef_global_settings.h" 23 | 24 | class QCoreApplication; 25 | 26 | /** 27 | * Initialize cef app with specific settings. 28 | * @param argc Number of arguments. 29 | * @param argv Pointer to argument list. 30 | * @param settings Reference to global settings. 31 | * @return 0 on success of browser process, > 0 on success of zygto processes, < 0 on error. 32 | */ 33 | QCEF_CORE_EXPORT int QCefInit(int argc, 34 | char** argv, 35 | const QCefGlobalSettings& settings); 36 | 37 | /** 38 | * Bind cef message loop to Qt main message loop. 39 | * @param app Initialized Qt QApplication instance. 40 | */ 41 | QCEF_CORE_EXPORT void QCefBindApp(QCoreApplication* app); 42 | 43 | /** 44 | * Stop internal timer explicitly. 45 | * Normally no need to call this method to stop cef worker. 46 | */ 47 | QCEF_CORE_EXPORT void QCefStopTimer(); 48 | 49 | /** 50 | * Stop renderer processes. 51 | * Normally no need to call this method to cleanup sub-processes. 52 | */ 53 | QCEF_CORE_EXPORT void QCefShutdown(); 54 | 55 | #endif // QCEF_CORE_QCEF_CONTEXT_H 56 | -------------------------------------------------------------------------------- /src/core/qcef_cookie_store.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_cookie_store.h" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "include/cef_cookie.h" 27 | 28 | namespace { 29 | 30 | const int kSleepInterval = 100; 31 | const int kMaximumAcquireCount = 300; 32 | 33 | // Used by getCookie(). 34 | class CookieVisitor : public CefCookieVisitor { 35 | public: 36 | CookieVisitor(const std::string& name) 37 | : CefCookieVisitor(), 38 | cookie_name(name), 39 | cookie_value(), 40 | semaphore(0) { } 41 | ~CookieVisitor() override { } 42 | 43 | bool Visit(const CefCookie& cookie, 44 | int count, 45 | int total, 46 | bool& deleteCookie) override; 47 | 48 | std::string cookie_name; 49 | std::string cookie_value; 50 | QSemaphore semaphore; 51 | 52 | private: 53 | IMPLEMENT_REFCOUNTING(CookieVisitor); 54 | }; 55 | 56 | // Used by getCookies(). 57 | class CookieTotalVisitor : public CefCookieVisitor { 58 | public: 59 | CookieTotalVisitor() : CefCookieVisitor(), cookies(), semaphore(0) { } 60 | ~CookieTotalVisitor() override { } 61 | 62 | bool Visit(const CefCookie& cookie, 63 | int count, 64 | int total, 65 | bool& deleteCookie) override; 66 | 67 | QMap cookies; 68 | QSemaphore semaphore; 69 | 70 | private: 71 | IMPLEMENT_REFCOUNTING(CookieTotalVisitor); 72 | }; 73 | 74 | bool CookieVisitor::Visit(const CefCookie& cookie, 75 | int count, 76 | int total, 77 | bool& deleteCookie) { 78 | Q_UNUSED(count); 79 | Q_UNUSED(total); 80 | 81 | if (cookie_name == std::string(CefString(&cookie.name))) { 82 | cookie_value = std::string(CefString(&cookie.value)); 83 | return false; 84 | } 85 | return true; 86 | } 87 | 88 | bool CookieTotalVisitor::Visit(const CefCookie& cookie, 89 | int count, 90 | int total, 91 | bool& deleteCookie) { 92 | cookies.insert(QString::fromStdString(std::string(CefString(&cookie.name))), 93 | QString::fromStdString(std::string(CefString(&cookie.value)))); 94 | 95 | if (count + 1 == total) { 96 | semaphore.release(); 97 | } 98 | 99 | return true; 100 | } 101 | 102 | } // namespace 103 | 104 | void QCefFlushCookies() { 105 | auto cookie_manager = CefCookieManager::GetGlobalManager(nullptr); 106 | cookie_manager->FlushStore(nullptr); 107 | } 108 | 109 | QString QCefGetCookie(const QString& domain, const QString& name) { 110 | CefRefPtr cookie_visitor = 111 | new CookieVisitor(name.toStdString()); 112 | 113 | auto cookie_manager = CefCookieManager::GetGlobalManager(nullptr); 114 | cookie_manager->VisitUrlCookies(domain.toStdString(), false, 115 | CefRefPtr(cookie_visitor)); 116 | 117 | // Wait until visitor release. 118 | int count = 0; 119 | while (!cookie_visitor->semaphore.tryAcquire() && 120 | count < kMaximumAcquireCount) { 121 | usleep(kSleepInterval); 122 | count++; 123 | } 124 | 125 | return QString::fromStdString(cookie_visitor->cookie_value); 126 | } 127 | 128 | QVariantMap QCefGetCookies(const QString& domain) { 129 | CefRefPtr cookie_visitor = new CookieTotalVisitor(); 130 | auto cookie_manager = CefCookieManager::GetGlobalManager(nullptr); 131 | cookie_manager->VisitUrlCookies(domain.toStdString(), false, 132 | CefRefPtr(cookie_visitor)); 133 | 134 | // Wait until visitor release. 135 | int count = 0; 136 | while (!cookie_visitor->semaphore.tryAcquire() && 137 | count < kMaximumAcquireCount) { 138 | usleep(kSleepInterval); 139 | count++; 140 | } 141 | 142 | QVariantMap map; 143 | 144 | for (auto iter = cookie_visitor->cookies.cbegin(); 145 | iter != cookie_visitor->cookies.cend(); ++iter) { 146 | map.insert(iter.key(), iter.value()); 147 | } 148 | 149 | return map; 150 | } 151 | 152 | void QCefMoveCookie(const QString& old_domain, 153 | const QString& new_domain, 154 | const QString& name) { 155 | Q_UNUSED(old_domain); 156 | Q_UNUSED(new_domain); 157 | Q_UNUSED(name); 158 | // TODO(LiuLang): 159 | } 160 | 161 | bool QCefRemoveCookie(const QString& domain, const QString& name) { 162 | auto cookie_manager = CefCookieManager::GetGlobalManager(nullptr); 163 | cookie_manager->DeleteCookies(domain.toStdString(), 164 | name.toStdString(), 165 | nullptr); 166 | cookie_manager->FlushStore(nullptr); 167 | return true; 168 | } 169 | 170 | void QCefSetCookie(const QString& domain, 171 | const QString& name, 172 | const QString& value) { 173 | auto cookie_manager = CefCookieManager::GetGlobalManager(nullptr); 174 | CefCookie cefCookie; 175 | CefString(&cefCookie.name) = name.toStdString(); 176 | CefString(&cefCookie.domain) = QUrl(domain).host().toStdString(); 177 | CefString(&cefCookie.value) = value.toStdString(); 178 | cookie_manager->SetCookie(domain.toStdString(), cefCookie, nullptr); 179 | cookie_manager->FlushStore(nullptr); 180 | } 181 | -------------------------------------------------------------------------------- /src/core/qcef_cookie_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_COOKIE_STORE_H 19 | #define QCEF_CORE_QCEF_COOKIE_STORE_H 20 | 21 | #include 22 | #include 23 | 24 | #include "qcef_core_export.h" 25 | 26 | /** 27 | * Flush the backing store (if any) to disk. 28 | */ 29 | void QCEF_CORE_EXPORT QCefFlushCookies(); 30 | 31 | /** 32 | * Get browser cookie with |name| as cookie name and |domain| as cookie path. 33 | * This method is used to bypass browser security restriction. 34 | * Returns cookie value on success, or "" on error. 35 | * @param domain Domain name of cookie. 36 | * @param name Cookie name. 37 | * @return Cookie value on success or an empty string on error. 38 | */ 39 | QString QCEF_CORE_EXPORT QCefGetCookie(const QString& domain, 40 | const QString& name); 41 | 42 | /** 43 | * Get all cookies associated with |domain|. 44 | * Returns a map of (cookie-name, cookie-value) pair. 45 | * @param domain Domain name of cookies. 46 | * @return A map of cookie-name => cookie-value pair. 47 | */ 48 | QVariantMap QCEF_CORE_EXPORT QCefGetCookies(const QString& domain); 49 | 50 | /** 51 | * Movie cookie with |name| from domain |old_domain| to domain |new_domain|. 52 | * @param old_domain Name of old cookie domain. 53 | * @param new_domain Name of new cookie domain. 54 | * @param name Cookie name. 55 | */ 56 | void QCEF_CORE_EXPORT QCefMoveCookie(const QString& old_domain, 57 | const QString& new_domain, 58 | const QString& name); 59 | 60 | /** 61 | * Remove cookie item. 62 | * @param domain Domain name of cookies. 63 | * @param name Cookie name to be removed. 64 | * @return true if this cookie exists and is removed, else false. 65 | */ 66 | 67 | bool QCEF_CORE_EXPORT QCefRemoveCookie(const QString& domain, 68 | const QString& name); 69 | 70 | /** 71 | * Set browser cookie at |domain| with |name| and cookie value |value|. 72 | * @param domain Domain name of cookies. 73 | * @param name Cookie name to be inserted. 74 | * @param value Value of cookie. 75 | */ 76 | void QCEF_CORE_EXPORT QCefSetCookie(const QString& domain, 77 | const QString& name, 78 | const QString& value); 79 | 80 | #endif // QCEF_CORE_QCEF_COOKIE_STORE_H 81 | -------------------------------------------------------------------------------- /src/core/qcef_core_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_CORE_EXPORT_H 19 | #define QCEF_CORE_QCEF_CORE_EXPORT_H 20 | 21 | #define QCEF_CORE_EXPORT __attribute__((visibility("default"))) 22 | 23 | #endif // QCEF_CORE_QCEF_CORE_EXPORT_H 24 | -------------------------------------------------------------------------------- /src/core/qcef_dialog_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_DIALOG_HANDLER_H 19 | #define QCEF_CORE_QCEF_DIALOG_HANDLER_H 20 | 21 | #include "include/cef_dialog_handler.h" 22 | #include "include/cef_jsdialog_handler.h" 23 | 24 | class QCefDialogHandler : public CefDialogHandler, 25 | public CefJSDialogHandler { 26 | public: 27 | QCefDialogHandler(); 28 | 29 | bool OnFileDialog(CefRefPtr browser, FileDialogMode mode, 30 | const CefString& title, const CefString& default_file_path, 31 | const std::vector& accept_filters, 32 | int selected_accept_filter, 33 | CefRefPtr callback) override; 34 | 35 | bool OnJSDialog(CefRefPtr browser, 36 | const CefString& origin_url, 37 | JSDialogType dialog_type, 38 | const CefString& message_text, 39 | const CefString& default_prompt_text, 40 | CefRefPtr callback, 41 | bool& suppress_message) override; 42 | 43 | bool OnBeforeUnloadDialog(CefRefPtr browser, 44 | const CefString& message_text, 45 | bool is_reload, 46 | CefRefPtr callback) override; 47 | 48 | void OnResetDialogState(CefRefPtr browser) override; 49 | 50 | void OnDialogClosed(CefRefPtr browser) override; 51 | 52 | private: 53 | IMPLEMENT_REFCOUNTING(QCefDialogHandler); 54 | }; 55 | 56 | 57 | #endif // QCEF_CORE_QCEF_DIALOG_HANDLER_H 58 | -------------------------------------------------------------------------------- /src/core/qcef_key_event_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_QCEF_KEY_EVENT_MAP_H 19 | #define QCEF_QCEF_KEY_EVENT_MAP_H 20 | 21 | #include 22 | 23 | #include "include/internal/cef_linux.h" 24 | 25 | // Map XEvent(XKeyEvent) to QKeyEvent 26 | QKeyEvent XEvent2QtKeyEvent(CefEventHandle event); 27 | 28 | #endif //QCEF_QCEF_KEY_EVENT_MAP_H 29 | -------------------------------------------------------------------------------- /src/core/qcef_message_pump_handler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_message_pump_handler.h" 19 | 20 | #include 21 | 22 | #include "include/cef_app.h" 23 | 24 | QCefMessagePumpHandler::QCefMessagePumpHandler(QObject* parent) 25 | : QObject(parent), timer_id_(0) { 26 | } 27 | 28 | void QCefMessagePumpHandler::scheduleWork(qint64 delayed_ms) { 29 | if (delayed_ms <= 0) { 30 | QCoreApplication::postEvent(this, new QEvent(QEvent::User)); 31 | } else { 32 | killTimer(timer_id_); 33 | // Limit delayed time to 50ms. 34 | const int delay = qMin(static_cast(delayed_ms), 50); 35 | timer_id_ = startTimer(delay); 36 | } 37 | } 38 | 39 | void QCefMessagePumpHandler::timerEvent(QTimerEvent* event) { 40 | Q_ASSERT(event->timerId() == timer_id_); 41 | QObject::timerEvent(event); 42 | CefDoMessageLoopWork(); 43 | } 44 | 45 | void QCefMessagePumpHandler::customEvent(QEvent* event) { 46 | QObject::customEvent(event); 47 | CefDoMessageLoopWork(); 48 | } 49 | -------------------------------------------------------------------------------- /src/core/qcef_message_pump_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_MESSAGE_PUMP_HANDLER_H 19 | #define QCEF_CORE_QCEF_MESSAGE_PUMP_HANDLER_H 20 | 21 | #include 22 | 23 | // Integrate CEF Message with Qt Message Loop. 24 | class QCefMessagePumpHandler : public QObject { 25 | Q_OBJECT 26 | public: 27 | explicit QCefMessagePumpHandler(QObject* parent = nullptr); 28 | 29 | void scheduleWork(qint64 delayed_ms); 30 | 31 | protected: 32 | void customEvent(QEvent* event) override; 33 | 34 | void timerEvent(QTimerEvent* event) override; 35 | 36 | private: 37 | int timer_id_; 38 | }; 39 | 40 | #endif // QCEF_CORE_QCEF_MESSAGE_PUMP_HANDLER_H 41 | -------------------------------------------------------------------------------- /src/core/qcef_notification_constructor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_notification_constructor.h" 19 | 20 | #include "core/qcef_web_channel_consts.h" 21 | 22 | QCefNotificationConstructor::QCefNotificationConstructor( 23 | CefRefPtr browser, CefRefPtr frame) 24 | : browser_(browser), 25 | frame_(frame) { 26 | } 27 | 28 | bool QCefNotificationConstructor::Execute(const CefString& name, 29 | CefRefPtr object, 30 | const CefV8ValueList& arguments, 31 | CefRefPtr& retval, 32 | CefString& exception) { 33 | (void)name; 34 | (void)object; 35 | (void)retval; 36 | 37 | if (arguments.empty()) { 38 | exception = "Argument mismatch!"; 39 | return true; 40 | } 41 | 42 | // Send notification message to UI thread. 43 | CefRefPtr message = CefProcessMessage::Create( 44 | kQCefWebNotificationBody); 45 | CefRefPtr args = message->GetArgumentList(); 46 | args->SetString(0, frame_->GetURL()); 47 | args->SetString(1, arguments.at(0)->GetStringValue()); 48 | if (arguments.size() > 1) { 49 | // Pass through notification option. 50 | CefRefPtr v8_value = arguments.at(1); 51 | std::vector v8_keys; 52 | CefRefPtr dict = CefDictionaryValue::Create(); 53 | if (v8_value->GetKeys(v8_keys)) { 54 | for (const CefString& key : v8_keys) { 55 | CefRefPtr v = v8_value->GetValue(key); 56 | dict->SetString(key, v->GetStringValue()); 57 | } 58 | args->SetDictionary(2, dict); 59 | } 60 | } 61 | browser_->SendProcessMessage(PID_BROWSER, message); 62 | 63 | return true; 64 | } 65 | 66 | QCefNotificationRequestPermission::QCefNotificationRequestPermission( 67 | CefRefPtr browser, CefRefPtr frame) 68 | : browser_(browser), 69 | frame_(frame) { 70 | } 71 | 72 | bool QCefNotificationRequestPermission::Execute(const CefString& name, 73 | CefRefPtr object, 74 | const CefV8ValueList& arguments, 75 | CefRefPtr& retval, 76 | CefString& exception) { 77 | (void)name; 78 | (void)object; 79 | (void)arguments; 80 | (void)retval; 81 | (void)exception; 82 | // TODO(LiuLang): Implement notification permission management. 83 | return true; 84 | } 85 | -------------------------------------------------------------------------------- /src/core/qcef_notification_constructor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_NOTIFICATION_CONSTRUCTOR_H 19 | #define QCEF_CORE_QCEF_NOTIFICATION_CONSTRUCTOR_H 20 | 21 | #include "include/cef_v8.h" 22 | 23 | // Implementation of Notification() prototype constructor. 24 | class QCefNotificationConstructor : public CefV8Handler { 25 | public: 26 | QCefNotificationConstructor(CefRefPtr browser, 27 | CefRefPtr frame); 28 | bool Execute(const CefString& name, 29 | CefRefPtr object, 30 | const CefV8ValueList& arguments, 31 | CefRefPtr& retval, 32 | CefString& exception) override; 33 | 34 | private: 35 | IMPLEMENT_REFCOUNTING(QCefNotificationConstructor); 36 | DISALLOW_COPY_AND_ASSIGN(QCefNotificationConstructor); 37 | 38 | CefRefPtr browser_ = nullptr; 39 | CefRefPtr frame_ = nullptr; 40 | }; 41 | 42 | // Implementation of Notification.requestPermission() method. 43 | class QCefNotificationRequestPermission : public CefV8Handler { 44 | public: 45 | QCefNotificationRequestPermission(CefRefPtr browser, 46 | CefRefPtr frame); 47 | bool Execute(const CefString& name, 48 | CefRefPtr object, 49 | const CefV8ValueList& arguments, 50 | CefRefPtr& retval, 51 | CefString& exception) override; 52 | 53 | private: 54 | IMPLEMENT_REFCOUNTING(QCefNotificationRequestPermission); 55 | DISALLOW_COPY_AND_ASSIGN(QCefNotificationRequestPermission); 56 | 57 | CefRefPtr browser_ = nullptr; 58 | CefRefPtr frame_ = nullptr; 59 | }; 60 | 61 | #endif // QCEF_CORE_QCEF_NOTIFICATION_CONSTRUCTOR_H 62 | -------------------------------------------------------------------------------- /src/core/qcef_print_handler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_print_handler.h" 19 | 20 | 21 | QCefPrintHandler::QCefPrintHandler() { 22 | 23 | } 24 | 25 | QCefPrintHandler::~QCefPrintHandler() { 26 | 27 | } 28 | 29 | void QCefPrintHandler::OnPrintStart(CefRefPtr browser) { 30 | (void)browser; 31 | } 32 | 33 | void QCefPrintHandler::OnPrintSettings(CefRefPtr browser, 34 | CefRefPtr settings, 35 | bool get_defaults) { 36 | (void)browser; 37 | (void)settings; 38 | (void)get_defaults; 39 | } 40 | 41 | bool QCefPrintHandler::OnPrintDialog( 42 | CefRefPtr browser, 43 | bool has_selection, 44 | CefRefPtr callback) { 45 | (void)browser; 46 | (void)has_selection; 47 | (void)callback; 48 | return false; 49 | } 50 | 51 | bool QCefPrintHandler::OnPrintJob(CefRefPtr browser, 52 | const CefString& document_name, 53 | const CefString& pdf_file_path, 54 | CefRefPtr callback) { 55 | (void)browser; 56 | (void)document_name; 57 | (void)pdf_file_path; 58 | (void)callback; 59 | return false; 60 | } 61 | 62 | void QCefPrintHandler::OnPrintReset(CefRefPtr browser) { 63 | (void)browser; 64 | } 65 | 66 | CefSize QCefPrintHandler::GetPdfPaperSize(int device_units_per_inch) { 67 | return CefPrintHandler::GetPdfPaperSize(device_units_per_inch); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/core/qcef_print_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_PRINT_HANDLER_H 19 | #define QCEF_CORE_QCEF_PRINT_HANDLER_H 20 | 21 | #include "include/cef_print_handler.h" 22 | 23 | class QCefPrintHandler : public CefPrintHandler { 24 | public: 25 | QCefPrintHandler(); 26 | ~QCefPrintHandler() override; 27 | void OnPrintStart(CefRefPtr browser) override; 28 | 29 | void OnPrintSettings(CefRefPtr browser, 30 | CefRefPtr settings, 31 | bool get_defaults) override; 32 | 33 | bool OnPrintDialog(CefRefPtr browser, bool has_selection, 34 | CefRefPtr callback) override; 35 | 36 | bool OnPrintJob(CefRefPtr browser, const CefString& document_name, 37 | const CefString& pdf_file_path, 38 | CefRefPtr callback) override; 39 | 40 | void OnPrintReset(CefRefPtr browser) override; 41 | 42 | CefSize GetPdfPaperSize(int device_units_per_inch) override; 43 | 44 | private: 45 | IMPLEMENT_REFCOUNTING(QCefPrintHandler); 46 | DISALLOW_COPY_AND_ASSIGN(QCefPrintHandler); 47 | }; 48 | 49 | 50 | #endif // QCEF_CORE_QCEF_PRINT_HANDLER_H 51 | -------------------------------------------------------------------------------- /src/core/qcef_renderer_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_RENDERER_HANDLER_H 19 | #define QCEF_CORE_QCEF_RENDERER_HANDLER_H 20 | 21 | #include "core/qcef_global_settings.h" 22 | #include "core/qcef_sync_method.h" 23 | #include "include/cef_render_process_handler.h" 24 | 25 | // Handle messages in renderer processes. 26 | class QCefRendererHandler : public CefRenderProcessHandler { 27 | public: 28 | QCefRendererHandler() { } 29 | explicit QCefRendererHandler(const QCefSyncMethodMap& map, 30 | const QCefUserScriptList& scripts); 31 | void OnContextCreated(CefRefPtr browser, 32 | CefRefPtr frame, 33 | CefRefPtr context) override; 34 | 35 | void OnContextReleased(CefRefPtr browser, 36 | CefRefPtr frame, 37 | CefRefPtr context) override; 38 | 39 | bool OnProcessMessageReceived(CefRefPtr browser, 40 | CefProcessId source_process, 41 | CefRefPtr message) override; 42 | 43 | void OnWebKitInitialized() override; 44 | 45 | private: 46 | IMPLEMENT_REFCOUNTING(QCefRendererHandler); 47 | DISALLOW_COPY_AND_ASSIGN(QCefRendererHandler); 48 | 49 | QCefSyncMethodMap sync_methods_; 50 | QList register_scripts_; 51 | }; 52 | 53 | #endif // QCEF_CORE_QCEF_RENDERER_HANDLER_H 54 | -------------------------------------------------------------------------------- /src/core/qcef_renderer_transport_handler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_renderer_transport_handler.h" 19 | 20 | #include 21 | 22 | #include "core/qcef_web_channel_consts.h" 23 | #include "include/wrapper/cef_helpers.h" 24 | 25 | QCefRendererTransportHandler::QCefRendererTransportHandler( 26 | CefRefPtr browser) 27 | : browser_(browser) { 28 | } 29 | 30 | bool QCefRendererTransportHandler::Execute(const CefString& name, 31 | CefRefPtr object, 32 | const CefV8ValueList& arguments, 33 | CefRefPtr& retval, 34 | CefString& exception) { 35 | CEF_REQUIRE_RENDERER_THREAD(); 36 | DCHECK_EQ(name, "send"); 37 | 38 | // Send message from renderer process to browser process. 39 | CefRefPtr msg = 40 | CefProcessMessage::Create(kQCefRenderQtMessage); 41 | 42 | CefRefPtr args = msg->GetArgumentList(); 43 | args->SetString(0, arguments[0]->GetStringValue()); 44 | 45 | browser_->SendProcessMessage(PID_BROWSER, msg); 46 | 47 | return true; 48 | } 49 | -------------------------------------------------------------------------------- /src/core/qcef_renderer_transport_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_RENDERER_TRANSPORT_HANDLER_H 19 | #define QCEF_CORE_QCEF_RENDERER_TRANSPORT_HANDLER_H 20 | 21 | #include "include/cef_v8.h" 22 | 23 | // Send message from renderer process to browser process. 24 | class QCefRendererTransportHandler : public CefV8Handler { 25 | public: 26 | explicit QCefRendererTransportHandler(CefRefPtr browser); 27 | 28 | bool Execute(const CefString& name, 29 | CefRefPtr object, 30 | const CefV8ValueList& arguments, 31 | CefRefPtr& retval, 32 | CefString& exception) override; 33 | 34 | IMPLEMENT_REFCOUNTING(QCefRendererTransportHandler); 35 | 36 | private: 37 | CefRefPtr browser_ = nullptr; 38 | }; 39 | 40 | #endif // QCEF_CORE_QCEF_RENDERER_TRANSPORT_HANDLER_H 41 | -------------------------------------------------------------------------------- /src/core/qcef_scheme_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_SCHEME_HANDLER_H 19 | #define QCEF_CORE_QCEF_SCHEME_HANDLER_H 20 | 21 | #include 22 | 23 | // User may implement this function to handle url requests with custom scheme 24 | // names. 25 | // Note that qrc: and file:/ have already been handled properly. 26 | typedef QString (*QCefSchemeHandler)(const QUrl& url); 27 | 28 | #endif // QCEF_CORE_QCEF_SCHEME_HANDLER_H 29 | -------------------------------------------------------------------------------- /src/core/qcef_scheme_handler_factory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_scheme_handler_factory.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace { 27 | 28 | QString Ext2Mime(const QString& fileName) { 29 | const auto pos = fileName.lastIndexOf('.'); 30 | const auto ext = fileName.mid(pos + 1).toLower(); 31 | 32 | if (ext == "css") { 33 | return "text/css"; 34 | } 35 | if (ext == "html") { 36 | return "text/html"; 37 | } 38 | if (ext == "js") { 39 | return "application/javascript"; 40 | } 41 | if (ext == "less") { 42 | return "text/less"; 43 | } 44 | if (ext == "svg") { 45 | return "image/svg+xml"; 46 | } 47 | if (ext == "png") { 48 | return "image/png"; 49 | } 50 | if (ext == "gif") { 51 | return "image/gif"; 52 | } 53 | if (ext == "jpg" || ext == "jpeg") { 54 | return "image/jpeg"; 55 | } 56 | return ""; 57 | } 58 | 59 | CefStreamResourceHandler* 60 | CreateQFileStreamResourceHandler(const QString& path) { 61 | if (!QFile::exists(path)) { 62 | qWarning() << __FUNCTION__ << "File not found:" << path; 63 | return nullptr; 64 | } 65 | QFile file(path); 66 | if (!file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { 67 | qWarning() << __FUNCTION__ << "Failed to open file: " << path; 68 | return nullptr; 69 | } 70 | 71 | const QByteArray content = file.readAll(); 72 | QString mime(Ext2Mime(path)); 73 | if (mime.isEmpty()) { 74 | QMimeDatabase mime_database; 75 | const QMimeType mime_type = mime_database.mimeTypeForData(content); 76 | mime = mime_type.name(); 77 | } 78 | const char* content_bytes = content.constData(); 79 | CefRefPtr stream = CefStreamReader::CreateForData( 80 | static_cast(const_cast(content_bytes)), 81 | (size_t)(file.size())); 82 | 83 | // Set mime type name to empty. 84 | return new CefStreamResourceHandler(mime.toStdString(), stream); 85 | }; 86 | 87 | } // namespace 88 | 89 | CefRefPtr QCefSchemeHandlerFactory::Create( 90 | CefRefPtr browser, 91 | CefRefPtr frame, 92 | const CefString& scheme_name, 93 | CefRefPtr request) { 94 | (void) browser; 95 | (void) frame; 96 | CEF_REQUIRE_IO_THREAD(); 97 | 98 | const QString url(QString::fromStdString(request->GetURL().ToString())); 99 | if (scheme_name == "qrc") { 100 | // Handle qrc protocol. 101 | const QString qrc_file("://" + QUrl(url).path()); 102 | return CreateQFileStreamResourceHandler(qrc_file); 103 | } 104 | if (custom_scheme_handler_ != nullptr) { 105 | const QString filepath = custom_scheme_handler_(QUrl(url)); 106 | return CreateQFileStreamResourceHandler(filepath); 107 | } 108 | return nullptr; 109 | } 110 | -------------------------------------------------------------------------------- /src/core/qcef_scheme_handler_factory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_SCHEME_HANDLER_FACTORY_H 19 | #define QCEF_CORE_QCEF_SCHEME_HANDLER_FACTORY_H 20 | 21 | #include "core/qcef_scheme_handler.h" 22 | #include "include/cef_scheme.h" 23 | #include "include/wrapper/cef_stream_resource_handler.h" 24 | 25 | // Handle custom scheme requests. 26 | class QCefSchemeHandlerFactory : public CefSchemeHandlerFactory { 27 | public: 28 | explicit QCefSchemeHandlerFactory(QCefSchemeHandler handler) 29 | : custom_scheme_handler_(handler) { } 30 | 31 | CefRefPtr Create(CefRefPtr browser, 32 | CefRefPtr frame, 33 | const CefString& scheme_name, 34 | CefRefPtr request) override; 35 | 36 | private: 37 | IMPLEMENT_REFCOUNTING(QCefSchemeHandlerFactory) 38 | 39 | QCefSchemeHandler custom_scheme_handler_ = nullptr; 40 | }; 41 | 42 | #endif // QCEF_CORE_QCEF_SCHEME_HANDLER_FACTORY_H 43 | -------------------------------------------------------------------------------- /src/core/qcef_string_visitor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_string_visitor.h" 19 | 20 | StringVisitor::StringVisitor(StringVisitorCallback callback) 21 | : callback_(std::move(callback)) { 22 | } 23 | 24 | void StringVisitor::Visit(const CefString& string) { 25 | if (callback_ != nullptr) { 26 | callback_(QString::fromStdString(string.ToString())); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/core/qcef_string_visitor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_STRING_VISITOR_H 19 | #define QCEF_CORE_QCEF_STRING_VISITOR_H 20 | 21 | #include "include/cef_string_visitor.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | typedef std::function StringVisitorCallback ; 28 | 29 | // Retrieve cef string asynchronously. 30 | class StringVisitor : public CefStringVisitor { 31 | public: 32 | explicit StringVisitor(StringVisitorCallback callback); 33 | 34 | void Visit(const CefString& string) override; 35 | 36 | private: 37 | IMPLEMENT_REFCOUNTING(StringVisitor); 38 | DISALLOW_COPY_AND_ASSIGN(StringVisitor); 39 | 40 | StringVisitorCallback callback_ = nullptr; 41 | }; 42 | 43 | #endif // QCEF_CORE_QCEF_STRING_VISITOR_H 44 | -------------------------------------------------------------------------------- /src/core/qcef_sync_method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_SYNC_METHOD_H 19 | #define QCEF_CORE_QCEF_SYNC_METHOD_H 20 | 21 | #include 22 | #include 23 | 24 | // Register sync methods in global context of V8 engine. 25 | // Note that this method is called in render process. 26 | // If multiple arguments or return values need to be handled, try to serialize 27 | // them. 28 | typedef QString (*QCefSyncMethod)(const QString& argument); 29 | typedef QMap QCefSyncMethodMap; 30 | 31 | #endif // QCEF_CORE_QCEF_SYNC_METHOD_H 32 | -------------------------------------------------------------------------------- /src/core/qcef_sync_method_handler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_sync_method_handler.h" 19 | 20 | QCefSyncMethodHandler::QCefSyncMethodHandler(const QCefSyncMethodMap& map) 21 | : sync_methods_(map) { 22 | } 23 | 24 | bool QCefSyncMethodHandler::Execute(const CefString& name, 25 | CefRefPtr object, 26 | const CefV8ValueList& arguments, 27 | CefRefPtr& retval, 28 | CefString& exception) { 29 | const QString func_name = QString::fromStdString(name.ToString()); 30 | if (sync_methods_.contains(func_name)) { 31 | if (arguments.size() != 1) { 32 | exception = "Arguments mismatch, expect 1 argument!"; 33 | return true; 34 | } 35 | const auto arg0 = arguments.at(0); 36 | if (!arg0->IsString()) { 37 | exception = "Argument 0 shall be a string!"; 38 | return true; 39 | } 40 | const QString input = QString::fromStdString(arg0->GetStringValue()); 41 | const QString result = sync_methods_[func_name](input); 42 | retval = CefV8Value::CreateString(result.toStdString()); 43 | return true; 44 | } 45 | 46 | return false; 47 | } 48 | -------------------------------------------------------------------------------- /src/core/qcef_sync_method_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_SYNC_METHOD_HANDLER_H 19 | #define QCEF_CORE_QCEF_SYNC_METHOD_HANDLER_H 20 | 21 | #include "core/qcef_sync_method.h" 22 | #include "include/cef_v8.h" 23 | 24 | class QCefSyncMethodHandler : public CefV8Handler { 25 | public: 26 | QCefSyncMethodHandler(const QCefSyncMethodMap& map); 27 | 28 | bool Execute(const CefString& name, CefRefPtr object, 29 | const CefV8ValueList& arguments, CefRefPtr& retval, 30 | CefString& exception) override; 31 | 32 | private: 33 | IMPLEMENT_REFCOUNTING(QCefSyncMethodHandler); 34 | QCefSyncMethodMap sync_methods_; 35 | }; 36 | 37 | 38 | #endif // QCEF_CORE_QCEF_SYNC_METHOD_HANDLER_H 39 | -------------------------------------------------------------------------------- /src/core/qcef_util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "core/qcef_util.h" 19 | 20 | #include 21 | #include 22 | 23 | bool IsX86Architecture() { 24 | struct utsname info; 25 | if (uname(&info) == 0) { 26 | const std::string machine(info.machine); 27 | if (machine == "i386" || machine == "i468" || machine == "i586" || 28 | machine == "i686" || machine == "x86" || 29 | machine == "amd64" || machine == "x86_64") { 30 | return true; 31 | } 32 | } 33 | return false; 34 | } -------------------------------------------------------------------------------- /src/core/qcef_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_UTIL_H 19 | #define QCEF_CORE_QCEF_UTIL_H 20 | 21 | #include "qcef_core_export.h" 22 | 23 | /** 24 | * Check whether current cpu architecture is x86 serials. 25 | * @return Returns true if current cpu type is x86 or x86_64. 26 | */ 27 | QCEF_CORE_EXPORT bool IsX86Architecture(); 28 | 29 | #endif // QCEF_CORE_QCEF_UTIL_H 30 | -------------------------------------------------------------------------------- /src/core/qcef_web_channel_consts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_WEB_CHANNEL_CONSTS_H 19 | #define QCEF_CORE_QCEF_WEB_CHANNEL_CONSTS_H 20 | 21 | // Message names used between browser process and renderer processes. 22 | const char kQCefRenderContextCreated[] = "QCefRenderContextCreated"; 23 | const char kQCefRenderContextReleased[] = "QCefRenderContextReleased"; 24 | const char kQCefRenderQtMessage[] = "QCefRenderQtMessage"; 25 | 26 | // Web Notification 27 | const char kQCefWebNotificationRequest[] = "QCefWebNotificationRequest"; 28 | const char kQCefWebNotificationBody[] = "QCefWebNotificationBody"; 29 | 30 | #endif // QCEF_CORE_QCEF_WEB_CHANNEL_CONSTS_H 31 | -------------------------------------------------------------------------------- /src/core/qcef_x11_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_CORE_QCEF_X11_UTIL_H 19 | #define QCEF_CORE_QCEF_X11_UTIL_H 20 | 21 | #include 22 | 23 | #include "include/internal/cef_linux.h" 24 | 25 | void SetXErrorHandler(); 26 | 27 | // Convert native keyboard event modifiers to Qt. 28 | Qt::KeyboardModifiers NativeToQtKeyboardModifiers(uint32 native); 29 | 30 | // Wraps XReparentWindow(). 31 | void ReparentWindow(CefWindowHandle parent, CefWindowHandle child, CefWindowHandle container); 32 | 33 | unsigned long InitCefBrowserWindow(int width, int height); 34 | 35 | void SetXWindowBounds(CefWindowHandle xwindow, 36 | int x, int y, 37 | int width, int height); 38 | 39 | //void SetXWindowTitle(CefWindowHandle window, const std::string& title); 40 | // 41 | //void SetXWindowVisible(CefWindowHandle xwindow, bool visible); 42 | 43 | #endif // QCEF_CORE_QCEF_X11_UTIL_H 44 | -------------------------------------------------------------------------------- /src/data/libqcef.pc.in: -------------------------------------------------------------------------------- 1 | prefix=${CMAKE_INSTALL_PREFIX} 2 | exec_prefix=${CMAKE_INSTALL_PREFIX} 3 | libdir=${QCEF_INSTALL_PATH} 4 | includedir=${CMAKE_INSTALL_PREFIX}/include 5 | 6 | Name: QCEF 7 | Description: Qt5 binding of CEF3 8 | Version: ${QCEF_VERSION_MAJOR}.${QCEF_VERSION_MINOR}.${QCEF_VERSION_MICRO} 9 | Libs: -L${QCEF_INSTALL_PATH} -lqcef 10 | Cflags: -I${CMAKE_INSTALL_PREFIX}/include/qcef -------------------------------------------------------------------------------- /src/tests/notification_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | #include "tests/notification_window.h" 21 | 22 | int main(int argc, char* argv[]) { 23 | QApplication app(argc, argv); 24 | 25 | NotificationWindow window; 26 | window.resize(640, 480); 27 | window.show(); 28 | 29 | return app.exec(); 30 | } -------------------------------------------------------------------------------- /src/tests/notification_window.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "tests/notification_window.h" 19 | 20 | #include 21 | 22 | #include "widgets/qcef_notification_service.h" 23 | 24 | struct NotificationWindowPrivate { 25 | QCefNotificationService* service = nullptr; 26 | QPushButton* show_button = nullptr; 27 | }; 28 | 29 | NotificationWindow::NotificationWindow(QWidget* parent) 30 | : QFrame(parent), 31 | p_(new NotificationWindowPrivate()) { 32 | p_->service = new QCefNotificationService(this); 33 | p_->show_button = new QPushButton("Show notification", this); 34 | connect(p_->show_button, &QPushButton::clicked, [=]() { 35 | p_->service->notify("Hello", "Body", QIcon()); 36 | }); 37 | } 38 | 39 | NotificationWindow::~NotificationWindow() { 40 | if (p_ != nullptr) { 41 | delete p_; 42 | p_ = nullptr; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/tests/notification_window.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_TESTS_NOTIFICATION_WINDOW_H 19 | #define QCEF_TESTS_NOTIFICATION_WINDOW_H 20 | 21 | #include 22 | 23 | struct NotificationWindowPrivate; 24 | 25 | class NotificationWindow : public QFrame { 26 | Q_OBJECT 27 | public: 28 | explicit NotificationWindow(QWidget* parent = nullptr); 29 | ~NotificationWindow() override; 30 | 31 | private: 32 | NotificationWindowPrivate* p_ = nullptr; 33 | }; 34 | 35 | 36 | #endif // QCEF_TESTS_NOTIFICATION_WINDOW_H 37 | -------------------------------------------------------------------------------- /src/tests/qt_version_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | int main(int argc, char** argv) { 22 | qDebug() << QT_VERSION_MAJOR << QT_VERSION_MINOR; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/tests/web_demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "core/qcef_context.h" 25 | #include "widgets/qcef_web_view.h" 26 | 27 | std::ostream& operator<<(std::ostream& ostream, wchar_t const* content) { 28 | ostream << content; 29 | return ostream; 30 | } 31 | 32 | int main(int argc, char** argv) { 33 | QCefGlobalSettings settings; 34 | // Do not use sandbox. 35 | settings.setNoSandbox(true); 36 | 37 | // Open http://localhost:9222 in chromium browser to see dev tools. 38 | settings.setRemoteDebug(true); 39 | settings.setLogSeverity(QCefGlobalSettings::LogSeverity::Info); 40 | 41 | const int exit_code = QCefInit(argc, argv, settings); 42 | if (exit_code >= 0) { 43 | return exit_code; 44 | } 45 | 46 | QApplication app(argc, argv); 47 | QCefBindApp(&app); 48 | 49 | QWidget window; 50 | QVBoxLayout* layout = new QVBoxLayout(); 51 | window.setLayout(layout); 52 | 53 | QLineEdit* edit = new QLineEdit(); 54 | layout->addWidget(edit); 55 | 56 | QCefWebView view; 57 | layout->addWidget(&view); 58 | view.show(); 59 | view.setUrl(QUrl("https://www.bing.com")); 60 | 61 | window.resize(860, 640); 62 | window.show(); 63 | 64 | return app.exec(); 65 | } -------------------------------------------------------------------------------- /src/tests/xevent-tracer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ $year Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | static Display* dpy; 24 | static Window focus_win = None; 25 | 26 | static void attach_to_focuswin(void) { 27 | int revert_to = 0; 28 | 29 | XGetInputFocus(dpy, &focus_win, &revert_to); 30 | XSetWindowAttributes attr; 31 | attr.event_mask = FocusChangeMask | KeyPressMask; 32 | XChangeWindowAttributes(dpy, focus_win, CWEventMask, &attr); 33 | 34 | if (focus_win != None) 35 | XSelectInput(dpy, focus_win, FocusChangeMask | KeyPressMask); 36 | else 37 | sleep(1); 38 | } 39 | 40 | static void handle_event(void) { 41 | XEvent ev; 42 | char buf[100]; 43 | int len; 44 | 45 | XNextEvent(dpy, &ev); 46 | switch (ev.xany.type) { 47 | case FocusIn: { 48 | fprintf(stdout, "FocusIn: %ld\n", focus_win); 49 | break; 50 | } 51 | case FocusOut: { 52 | fprintf(stdout, "FocusOut: %ld\n", focus_win); 53 | focus_win = None; 54 | break; 55 | } 56 | case KeyPress: { 57 | len = XLookupString(&ev.xkey, buf, 99, 0, 0); 58 | buf[len] = 0; 59 | printf("KeyPress: %s\n", buf); 60 | break; 61 | } 62 | case KeyRelease: { 63 | len = XLookupString(&ev.xkey, buf, 99, 0, 0); 64 | buf[len] = 0; 65 | printf("KeyRelease: %s\n", buf); 66 | break; 67 | } 68 | default: { 69 | fprintf(stdout, "type: %d\n", ev.type); 70 | } 71 | } 72 | } 73 | 74 | int main(void) { 75 | 76 | dpy = XOpenDisplay(getenv("DISPLAY")); 77 | 78 | if (dpy == NULL) { 79 | fprintf(stdout, "cannot init display\n"); 80 | exit(1); 81 | } 82 | 83 | while (1) { 84 | if (focus_win == None) 85 | attach_to_focuswin(); 86 | else 87 | handle_event(); 88 | } 89 | } -------------------------------------------------------------------------------- /src/widgets/qcef_browser_event_delegate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "widgets/qcef_browser_event_delegate.h" 19 | 20 | #include "widgets/qcef_browser_event_delegate_p.h" 21 | 22 | QCefContextMenuParams::QCefContextMenuParams() 23 | : p_(new QCefContextMenuParamsPrivate()) { 24 | } 25 | 26 | QCefContextMenuParams::~QCefContextMenuParams() { 27 | if (p_ != nullptr) { 28 | delete p_; 29 | p_ = nullptr; 30 | } 31 | } 32 | 33 | int QCefContextMenuParams::getXCoord() const { 34 | return p_->params->GetXCoord(); 35 | } 36 | 37 | int QCefContextMenuParams::getYCoord() const { 38 | return p_->params->GetYCoord(); 39 | } 40 | 41 | QCefContextMenuParams::TypeFlags QCefContextMenuParams::getTypeFlags() const { 42 | return static_cast(p_->params->GetTypeFlags()); 43 | } 44 | 45 | QString QCefContextMenuParams::getLinkUrl() const { 46 | return QString::fromStdString(p_->params->GetLinkUrl()); 47 | } 48 | 49 | QString QCefContextMenuParams::getUnfilteredLinkUrl() const { 50 | return QString::fromStdString(p_->params->GetUnfilteredLinkUrl()); 51 | } 52 | 53 | QString QCefContextMenuParams::getSourceUrl() const { 54 | return QString::fromStdString(p_->params->GetSourceUrl()); 55 | } 56 | 57 | bool QCefContextMenuParams::hasImageContents() const { 58 | return p_->params->HasImageContents(); 59 | } 60 | 61 | QString QCefContextMenuParams::getTitleText() const { 62 | return QString::fromStdString(p_->params->GetTitleText()); 63 | } 64 | 65 | QString QCefContextMenuParams::getPageUrl() const { 66 | return QString::fromStdString(p_->params->GetPageUrl()); 67 | } 68 | 69 | QString QCefContextMenuParams::getFrameUrl() const { 70 | return QString::fromStdString(p_->params->GetFrameUrl()); 71 | } 72 | 73 | QString QCefContextMenuParams::getFrameCharset() const { 74 | return QString::fromStdString(p_->params->GetFrameCharset()); 75 | } 76 | 77 | QCefContextMenuParams::MediaType QCefContextMenuParams::getMediaType() const { 78 | return static_cast(p_->params->GetMediaType()); 79 | } 80 | 81 | QCefContextMenuParams::MediaStateFlags 82 | QCefContextMenuParams::getMediaStateFlags() const { 83 | return static_cast( 84 | p_->params->GetMediaStateFlags()); 85 | } 86 | 87 | QString QCefContextMenuParams::getSelectionText() const { 88 | return QString::fromStdString(p_->params->GetSelectionText().ToString()); 89 | } 90 | 91 | bool QCefContextMenuParams::isEditable() const { 92 | return p_->params->IsEditable(); 93 | } 94 | 95 | QCefContextMenuParams::EditStateFlags 96 | QCefContextMenuParams::getEditStateFlags() const { 97 | return static_cast(p_->params->GetEditStateFlags()); 98 | } 99 | 100 | QCefContextMenu::QCefContextMenu() : items_(), callbacks_() { 101 | 102 | } 103 | 104 | void QCefContextMenu::addItem(int id, 105 | const QString& label, 106 | bool enabled, 107 | Callback callback) { 108 | items_.append(MenuItem{ItemType::Item, id, label, enabled}); 109 | callbacks_.insert(id, callback); 110 | } 111 | 112 | void QCefContextMenu::addSeparator() { 113 | items_.append(MenuItem{ItemType::Separator}); 114 | } 115 | 116 | void QCefContextMenu::clear() { 117 | items_.clear(); 118 | callbacks_.clear(); 119 | } 120 | 121 | const QVector QCefContextMenu::items() const { 122 | return items_; 123 | } 124 | 125 | const QMap QCefContextMenu::callbacks() const { 126 | return callbacks_; 127 | } 128 | -------------------------------------------------------------------------------- /src/widgets/qcef_browser_event_delegate_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_WIDGETS_QCEF_BROWSER_EVENT_DELEGATE_P_H 19 | #define QCEF_WIDGETS_QCEF_BROWSER_EVENT_DELEGATE_P_H 20 | 21 | #include "include/cef_context_menu_handler.h" 22 | 23 | struct QCefContextMenuParamsPrivate { 24 | CefRefPtr params = nullptr; 25 | }; 26 | 27 | #endif // QCEF_WIDGETS_QCEF_BROWSER_EVENT_DELEGATE_P_H -------------------------------------------------------------------------------- /src/widgets/qcef_client_handler_delegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_WIDGETS_QCEF_CLIENT_HANDLER_DELEGATE_H 19 | #define QCEF_WIDGETS_QCEF_CLIENT_HANDLER_DELEGATE_H 20 | 21 | #include "core/qcef_client_handler.h" 22 | 23 | #include "include/cef_app.h" 24 | #include "include/cef_life_span_handler.h" 25 | #include "widgets/qcef_web_page.h" 26 | 27 | class QCefContextMenu; 28 | 29 | // Implements delegate of QCefClientHandler, to let QCefWebPage be notified 30 | // about state change of cef browser. 31 | class QCefClientHandlerDelegate : public QCefClientHandler::Delegate 32 | { 33 | public: 34 | explicit QCefClientHandlerDelegate(QCefWebPage *web_page); 35 | 36 | ~QCefClientHandlerDelegate() override; 37 | 38 | bool OnBeforeBrowse(const CefString &url, bool is_redirect) override; 39 | 40 | void OnBeforeContextMenu(CefRefPtr browser, 41 | CefRefPtr frame, 42 | CefRefPtr params, 43 | CefRefPtr model) override; 44 | 45 | bool OnContextMenuCommand(CefRefPtr browser, 46 | CefRefPtr frame, 47 | CefRefPtr params, 48 | int command_id) override; 49 | 50 | bool OnBeforePopup( 51 | const CefString &target_url, 52 | CefLifeSpanHandler::WindowOpenDisposition target_disposition) override; 53 | 54 | void OnBrowserCreated(CefRefPtr browser) override; 55 | 56 | void DoClose(CefRefPtr browser) override; 57 | 58 | void OnFaviconURLChange(const CefString &icon_url, 59 | CefRefPtr icon) override; 60 | 61 | void OnLoadStarted(CefRefPtr browser, 62 | CefRefPtr frame) override; 63 | 64 | void OnLoadingStateChange(CefRefPtr browser, 65 | bool is_loading, 66 | bool can_go_back, 67 | bool can_go_forward) override; 68 | 69 | void OnLoadEnd(CefRefPtr browser, 70 | CefRefPtr frame, 71 | int httpStatusCode) override; 72 | 73 | QString OnLoadError(CefRefPtr browser, 74 | CefRefPtr frame, 75 | int errorCode) override; 76 | 77 | bool OnProcessMessageReceived(CefRefPtr browser, 78 | CefProcessId source_process, 79 | CefRefPtr message) override; 80 | 81 | void OnSetFullscreen(bool fullscreen) override; 82 | 83 | void OnTitleChanged(const CefString &title) override; 84 | 85 | void OnUrlChanged(const CefString &url) override; 86 | 87 | // Returns true if this key event is grabbed and handled by Qt Application. 88 | bool OnPreKeyEvent(QKeyEvent *event) override; 89 | 90 | // Update Qt clipboard when cef update its internal clipboard data. 91 | void OnClipboardChanged(const char *text_data, size_t text_len) override; 92 | 93 | void OnGotFocus(CefRefPtr browser) override; 94 | 95 | CefRequestHandler::ReturnValue OnBeforeResourceLoad( 96 | CefRefPtr browser, 97 | CefRefPtr frame, 98 | CefRefPtr request, 99 | CefRefPtr callback) override; 100 | 101 | private: 102 | CefRefPtr cef_browser_ = nullptr; 103 | QCefWebPage *web_page_ = nullptr; 104 | QCefContextMenu *context_menu_ = nullptr; 105 | }; 106 | 107 | #endif // QCEF_WIDGETS_QCEF_CLIENT_HANDLER_DELEGATE_H 108 | -------------------------------------------------------------------------------- /src/widgets/qcef_native_event_filter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ $year Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "qcef_native_event_filter.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace { 27 | 28 | QCefNativeEventFilter* g_filter = nullptr; 29 | 30 | // Get currently focused window, might be qt window or cef window. 31 | ::Window GetFocusWindow() { 32 | ::Display* display = QX11Info::display(); 33 | ::Window window; 34 | int revert_to; 35 | XGetInputFocus(display, &window, &revert_to); 36 | return window; 37 | } 38 | 39 | // Get top level qt window. 40 | ::Window GetTopLevelWindow() { 41 | if (qApp->focusWidget() != nullptr && 42 | qApp->focusWidget()->topLevelWidget() != nullptr) { 43 | return qApp->focusWidget()->topLevelWidget()->winId(); 44 | } else { 45 | return 0; 46 | } 47 | } 48 | 49 | void FocusToWindow(::Window window) { 50 | ::Display* display = QX11Info::display(); 51 | XSetInputFocus(display, window, RevertToParent, CurrentTime); 52 | } 53 | 54 | } // namespace 55 | 56 | // static 57 | void QCefNativeEventFilter::install() { 58 | if (g_filter == nullptr) { 59 | g_filter = new QCefNativeEventFilter(); 60 | Q_ASSERT(g_filter != nullptr); 61 | // 禁用,使用Qt本地事件实现鼠标按下后转移窗口焦点 62 | // qApp->installNativeEventFilter(g_filter); 63 | } 64 | } 65 | 66 | bool QCefNativeEventFilter::nativeEventFilter(const QByteArray& event_type, 67 | void* message, 68 | long* result) { 69 | Q_UNUSED(result); 70 | if ("xcb_generic_event_t" == event_type) { 71 | xcb_generic_event_t* event = static_cast(message); 72 | if ((event->response_type & ~0x80) == XCB_GE_GENERIC) { 73 | xcb_ge_generic_event_t* ge_event = 74 | reinterpret_cast(event); 75 | const ::Window top_level_win = GetTopLevelWindow(); 76 | if ((ge_event->event_type == XCB_BUTTON_PRESS) && 77 | (top_level_win != 0) && 78 | (top_level_win != GetFocusWindow())) { 79 | // Focus on qt top level window. 80 | FocusToWindow(top_level_win); 81 | } 82 | } 83 | } 84 | return false; 85 | } 86 | -------------------------------------------------------------------------------- /src/widgets/qcef_native_event_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ $year Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_WIDGETS_QCEF_NATIVE_EVENT_FILTER_H 19 | #define QCEF_WIDGETS_QCEF_NATIVE_EVENT_FILTER_H 20 | 21 | #include 22 | 23 | class QCefNativeEventFilter : public QAbstractNativeEventFilter { 24 | public: 25 | // Install global instance of event filter. 26 | static void install(); 27 | 28 | bool nativeEventFilter(const QByteArray& event_type, 29 | void* message, 30 | long* result) override; 31 | 32 | private: 33 | QCefNativeEventFilter() { } 34 | }; 35 | 36 | #endif // QCEF_WIDGETS_QCEF_NATIVE_EVENT_FILTER_H 37 | -------------------------------------------------------------------------------- /src/widgets/qcef_notification_service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "widgets/qcef_notification_service.h" 19 | 20 | #include 21 | #include 22 | 23 | namespace { 24 | 25 | const char kDBusService[] = "org.freedesktop.Notifications"; 26 | const char kDBusPath[] = "/org/freedesktop/Notifications"; 27 | const char kDBusInterface[] = "org.freedesktop.Notifications"; 28 | 29 | const char kNotify[] = "Notify"; 30 | 31 | // This is a raw data image format which describes the width, 32 | // height, rowstride, has alpha, bits per sample, channels and 33 | // image data respectively. 34 | //struct ImageData { 35 | // qint32 width; 36 | // qint32 height; 37 | // qint32 rowstride; 38 | // bool has_alpha; 39 | // qint32 bits_per_sample; 40 | // qint32 channels; 41 | // QByteArray data; 42 | //}; 43 | 44 | //Q_DECLARE_METATYPE(ImageData) 45 | 46 | } // namespace 47 | 48 | QCefNotificationService::QCefNotificationService(QObject* parent) 49 | : QDBusAbstractInterface(kDBusService, 50 | kDBusPath, 51 | kDBusInterface, 52 | QDBusConnection::sessionBus(), 53 | parent) { 54 | // qDBusRegisterMetaType(); 55 | } 56 | 57 | void QCefNotificationService::notify(const QString& title, 58 | const QString& body, 59 | const QIcon& icon) { 60 | // STRING app_name; 61 | // UINT32 replaces_id; 62 | // STRING app_icon; 63 | // STRING summary; 64 | // STRING body; 65 | // ARRAY actions; 66 | // DICT hints; 67 | // INT32 expire_timeout; 68 | const QString app_name("App name"); 69 | const quint32 replaced_id = 0; 70 | // const QString app_icon("/tmp/firefox.png"); 71 | const QString app_icon; 72 | const QStringList actions = {"default", "Activate"}; 73 | QVariantMap hints; 74 | // This is a raw data image format which describes the width, 75 | // height, rowstride, has alpha, bits per sample, channels and 76 | // image data respectively. 77 | QVariantList image_data; 78 | QImage image(icon.pixmap(QSize(32, 32)).toImage()); 79 | image_data.append(image.width()); 80 | image_data.append(image.height()); 81 | // rowstrike. 82 | image_data.append(256); 83 | image_data.append(image.hasAlphaChannel()); 84 | // Bits per sample. 85 | image_data.append(8); 86 | int channels = 3; 87 | if (image.isGrayscale()) { 88 | channels = 1; 89 | } else if (image.hasAlphaChannel()) { 90 | channels = 4; 91 | } 92 | image_data.append(channels); 93 | const QByteArray bytes((const char*)(image.constBits()), 94 | image.width() * image.height()); 95 | image_data.append(bytes); 96 | 97 | hints.insert("imdage-data", image_data); 98 | const qint32 expire_timeout = -1; 99 | this->asyncCall(kNotify, app_name, replaced_id, app_icon, 100 | title, body, 101 | actions, hints, expire_timeout); 102 | } -------------------------------------------------------------------------------- /src/widgets/qcef_notification_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_WIDGETS_QCEF_NOTIFICATION_SERVICE_H 19 | #define QCEF_WIDGETS_QCEF_NOTIFICATION_SERVICE_H 20 | 21 | #include 22 | 23 | #include "qcef_widgets_export.h" 24 | 25 | /** 26 | * Binding of freedesktop notifications dbus service. 27 | */ 28 | class QCEF_WIDGETS_EXPORT QCefNotificationService 29 | : public QDBusAbstractInterface { 30 | Q_OBJECT 31 | public: 32 | explicit QCefNotificationService(QObject* parent = nullptr); 33 | 34 | public slots: 35 | /** 36 | * Popup a new notification. 37 | * @param title Notification title. 38 | * @param body Notification content. 39 | * @param icon Notification icon. 40 | */ 41 | void notify(const QString& title, const QString& body, const QIcon& icon); 42 | }; 43 | 44 | #endif // QCEF_WIDGETS_QCEF_NOTIFICATION_SERVICE_H 45 | -------------------------------------------------------------------------------- /src/widgets/qcef_ssl_status.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_WIDGETS_QCEF_SSL_STATUS_H 19 | #define QCEF_WIDGETS_QCEF_SSL_STATUS_H 20 | 21 | #include "qcef_widgets_export.h" 22 | 23 | /** 24 | * Supported SSL content status flags. See content/public/common/ssl_status.h 25 | * for more information. 26 | */ 27 | enum QCEF_WIDGETS_EXPORT QCefSSLContentStatus { 28 | NORMAL_CONTENT = 0, 29 | DISPLAYED_INSECURE_CONTENT = 1 << 0, 30 | RAN_INSECURE_CONTENT = 1 << 1, 31 | }; 32 | 33 | struct QCEF_WIDGETS_EXPORT QCefSSLStatus { 34 | /** 35 | * Whether the status is related to a secure SSL/TLS connection. 36 | */ 37 | bool is_secure_connection = false; 38 | 39 | /** 40 | * A bit mask containing the page security content status. 41 | */ 42 | QCefSSLContentStatus content_status = QCefSSLContentStatus::NORMAL_CONTENT; 43 | }; 44 | 45 | #endif // QCEF_WIDGETS_QCEF_SSL_STATUS_H 46 | -------------------------------------------------------------------------------- /src/widgets/qcef_web_view.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "widgets/qcef_web_view.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "widgets/qcef_web_page.h" 29 | 30 | struct QCefWebViewPrivate { 31 | QCefWebPage* page = nullptr; 32 | bool window_mapped = false; 33 | bool auto_zoom = true; 34 | }; 35 | 36 | QCefWebView::QCefWebView(QWidget* parent) 37 | : QWidget(parent), 38 | p_(new QCefWebViewPrivate()) { 39 | this->setAttribute(Qt::WA_NativeWindow, true); 40 | this->setAttribute(Qt::WA_DontCreateNativeAncestors, true); 41 | 42 | connect(page(), &QCefWebPage::renderContextCreated, 43 | this, &QCefWebView::updateWebZoom, Qt::QueuedConnection); 44 | 45 | if (qApp->metaObject()->indexOfSignal("screenDevicePixelRatioChanged(QScreen*)") >= 0) { 46 | connect(qApp, SIGNAL(screenDevicePixelRatioChanged(QScreen*)), 47 | this, SLOT(onScreenScaleChanged(QScreen*)), Qt::QueuedConnection); 48 | } 49 | } 50 | 51 | QCefWebView::~QCefWebView() { 52 | if (p_ != nullptr) { 53 | 54 | if (p_->page != nullptr) { 55 | p_->page->deleteLater(); 56 | p_->page = nullptr; 57 | } 58 | 59 | delete p_; 60 | p_ = nullptr; 61 | } 62 | } 63 | 64 | void QCefWebView::load(const QUrl& url) { 65 | this->page()->load(url); 66 | } 67 | 68 | void QCefWebView::setUrl(const QUrl& url) { 69 | this->page()->setUrl(url); 70 | } 71 | 72 | QUrl QCefWebView::url() const { 73 | return this->page()->url(); 74 | } 75 | 76 | QCefWebPage* QCefWebView::page() const { 77 | if (p_->page == nullptr) { 78 | QCefWebView* that = const_cast(this); 79 | that->p_->page = new QCefWebPage(that); 80 | } 81 | return p_->page; 82 | } 83 | 84 | bool QCefWebView::autoZoom() const 85 | { 86 | return p_->auto_zoom; 87 | } 88 | 89 | void QCefWebView::setAutoZoom(bool autoZoom) 90 | { 91 | if (p_->auto_zoom == autoZoom) 92 | return; 93 | 94 | p_->auto_zoom = autoZoom; 95 | 96 | updateWebZoom(); 97 | } 98 | 99 | void QCefWebView::showEvent(QShowEvent* event) { 100 | QWidget::showEvent(event); 101 | if (!p_->window_mapped) { 102 | p_->window_mapped = true; 103 | QTimer::singleShot(1, this, [=]() { 104 | page()->remapBrowserWindow(this->winId(), 0); 105 | }); 106 | updateWebZoom(); 107 | } 108 | } 109 | 110 | void QCefWebView::resizeEvent(QResizeEvent* event) { 111 | QWidget::resizeEvent(event); 112 | page()->updateBrowserGeometry(event->size()); 113 | } 114 | 115 | void QCefWebView::focusInEvent(QFocusEvent *event) 116 | { 117 | if (p_->page) { 118 | p_->page->setFocus(true); 119 | } 120 | 121 | QWidget::focusInEvent(event); 122 | } 123 | 124 | bool QCefWebView::event(QEvent *event) 125 | { 126 | if (event->type() == QEvent::ScreenChangeInternal) { 127 | updateWebZoom(); 128 | } 129 | 130 | return QWidget::event(event); 131 | } 132 | 133 | void QCefWebView::updateWebZoom() 134 | { 135 | if (!p_->window_mapped) 136 | return; 137 | 138 | if (autoZoom()) { 139 | // chromium 中缩放比例以 20% 递增,因此,zoomLevel 的值实际上表示递增的倍数 140 | // 如,值为1时表示缩放为1.2倍,值为2时表示缩放为1.2*1.2倍 141 | page()->setZoomFactor(std::log(devicePixelRatioF()) / std::log(1.2)); 142 | } else { 143 | page()->resetZoomFactor(); 144 | } 145 | } 146 | 147 | void QCefWebView::onScreenScaleChanged(QScreen *screen) 148 | { 149 | if (window()->windowHandle() && window()->windowHandle()->screen() == screen) { 150 | updateWebZoom(); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/widgets/qcef_web_view.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_WIDGETS_QCEF_WEB_VIEW_H 19 | #define QCEF_WIDGETS_QCEF_WEB_VIEW_H 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "qcef_widgets_export.h" 26 | 27 | struct QCefWebViewPrivate; 28 | class QCefWebPage; 29 | class QCefWebSettings; 30 | 31 | /** 32 | * This widget class is used to view web document. 33 | * When inheriting from QCefWebView, remember to disable rtti feature 34 | * by appending -fno-rtti to compiler flag list, or else an error like 35 | * "undefined reference to `typeinfo for QCefWebView'" will occur. 36 | */ 37 | class QCEF_WIDGETS_EXPORT QCefWebView : public QWidget { 38 | Q_OBJECT 39 | Q_PROPERTY(QUrl url READ url WRITE setUrl) 40 | Q_PROPERTY(bool autoZoom READ autoZoom WRITE setAutoZoom) 41 | 42 | public: 43 | explicit QCefWebView(QWidget* parent = nullptr); 44 | ~QCefWebView() override; 45 | 46 | /** 47 | * Loads the specified |url| and displays it. 48 | * @param url 49 | */ 50 | void load(const QUrl& url); 51 | 52 | /** 53 | * Set url of web page. 54 | * @param url 55 | */ 56 | void setUrl(const QUrl& url); 57 | 58 | QUrl url() const; 59 | 60 | QCefWebPage* page() const; 61 | 62 | bool autoZoom() const; 63 | 64 | public Q_SLOTS: 65 | void setAutoZoom(bool autoZoom); 66 | 67 | protected: 68 | void showEvent(QShowEvent* event) override; 69 | 70 | void resizeEvent(QResizeEvent* event) override; 71 | void focusInEvent(QFocusEvent *event) override; 72 | bool event(QEvent *event) override; 73 | 74 | private: 75 | void updateWebZoom(); 76 | Q_SLOT void onScreenScaleChanged(QScreen *screen); 77 | 78 | QCefWebViewPrivate* p_ = nullptr; 79 | }; 80 | 81 | 82 | #endif // QCEF_WIDGETS_QCEF_WEB_VIEW_H 83 | -------------------------------------------------------------------------------- /src/widgets/qcef_widgets_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef QCEF_WIDGETS_QCEF_EXPORT_H 19 | #define QCEF_WIDGETS_QCEF_EXPORT_H 20 | 21 | #define QCEF_WIDGETS_EXPORT __attribute__((visibility("default"))) 22 | 23 | #endif // QCEF_WIDGETS_QCEF_EXPORT_H 24 | --------------------------------------------------------------------------------