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