使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 479b1995ef435713c2cf4f0da8de3a6af6c30922
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "../stdafx.h"
#include "Cef3MainContextImpl.h"
#include "include/cef_parser.h"
#include <direct.h>
#include <shlobj.h>
#include "Cef3ClientAppBrowser.h"
#include "Cef3ResourceUtil.h"
#include "Cef3CustomerScheme.h"
#include "include/wrapper/cef_resource_manager.h"
#include "include/wrapper/cef_stream_resource_handler.h"
 
namespace browser {
 
namespace {
const char kDefaultUrl[] = "http://www.baidu.com";
const char kTestOrigin[] = "http://tests/";
 
 
// Add a file extension to |url| if none is currently specified.
std::string RequestUrlFilter(const std::string& url) {
    if (url.find(kTestOrigin) != 0U) {
        // Don't filter anything outside of the test origin.
        return url;
    }
 
    // Identify where the query or fragment component, if any, begins.
    size_t suffix_pos = url.find('?');
    if (suffix_pos == std::string::npos)
        suffix_pos = url.find('#');
 
    std::string url_base, url_suffix;
    if (suffix_pos == std::string::npos) {
        url_base = url;
    } else {
        url_base = url.substr(0, suffix_pos);
        url_suffix = url.substr(suffix_pos);
    }
 
    // Identify the last path component.
    size_t path_pos = url_base.rfind('/');
    if (path_pos == std::string::npos)
        return url;
 
    const std::string& path_component = url_base.substr(path_pos);
 
    // Identify if a file extension is currently specified.
    size_t ext_pos = path_component.rfind(".");
    if (ext_pos != std::string::npos)
        return url;
 
    // Rebuild the URL with a file extension.
    return url_base + ".html" + url_suffix;
}
}  // namespace
 
CCef3MainContextImpl::CCef3MainContextImpl(bool terminate_when_all_windows_closed)
    : terminate_when_all_windows_closed_(terminate_when_all_windows_closed),
    initialized_(false),
    shutdown_(false) {
    // Set the main URL.
    main_url_ = kDefaultUrl;
}
 
CCef3MainContextImpl::~CCef3MainContextImpl() {
    // The context must either not have been initialized, or it must have also
    // been shut down.
    DCHECK(!initialized_ || shutdown_);
}
 
// Returns dev tools client
IBrowserClient *CCef3MainContextImpl::GetDevToolsClient() {
    return dev_tools_client_;
}
 
void CCef3MainContextImpl::SetDevToolsClient(IBrowserClient *pBrowserClient) {
    dev_tools_client_ = pBrowserClient;
}
 
std::string CCef3MainContextImpl::GetConsoleLogPath() {
    return GetAppWorkingDirectory() + "console.log";
}
 
std::string CCef3MainContextImpl::GetMainURL() {
    return main_url_;
}
 
// Provider that dumps the request contents.
class RequestDumpResourceProvider : public CefResourceManager::Provider {
public:
    explicit RequestDumpResourceProvider(const std::string& url)
        : url_(url) {
        DCHECK(!url.empty());
    }
 
    bool OnRequest(scoped_refptr<CefResourceManager::Request> request) OVERRIDE {
        CEF_REQUIRE_IO_THREAD();
 
        const std::string& url = request->url();
        if (url != url_) {
            // Not handled by this provider.
            return false;
        }
 
        const std::string& dump = browser::DumpRequestContents(request->request());
        std::string str = "<html><body bgcolor=\"white\"><pre>" + dump +
            "</pre></body></html>";
        CefRefPtr<CefStreamReader> stream =
            CefStreamReader::CreateForData(
                static_cast<void*>(const_cast<char*>(str.c_str())),
                str.size());
        DCHECK(stream.get());
        request->Continue(new CefStreamResourceHandler("text/html", stream));
        return true;
    }
 
private:
    std::string url_;
 
    DISALLOW_COPY_AND_ASSIGN(RequestDumpResourceProvider);
};
 
void CCef3MainContext::DoMessageLoopWork() {
    CefDoMessageLoopWork();
}
 
CefRefPtr<CefApp> CCef3MainContext::InitCef3(const CefMainArgs& main_args, void* windows_sandbox_info) {
    // Enable High-DPI support on Windows 7 or newer.
    CefEnableHighDPISupport();
 
    // Parse command-line arguments.
    CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
    command_line->InitFromString(::GetCommandLineW());
 
    // Create a ClientApp of the correct type.
    CefRefPtr<CefApp> app;
    CCef3ClientApp::ProcessType process_type = CCef3ClientApp::GetProcessType(command_line);
    if (process_type == CCef3ClientApp::BrowserProcess)
        app = new CCef3ClientAppBrowser();
 
    return app;
}
 
bool CCef3MainContextImpl::Initialize(const CefMainArgs& main_args, CefRefPtr<CefApp> app, void* windows_sandbox_info) {
    DCHECK(thread_checker_.CalledOnValidThread());
    DCHECK(!initialized_);
    DCHECK(!shutdown_);
 
 
    CefSettings settings;
    CefSettingsTraits::init(&settings);
 
    settings.no_sandbox = true;
 
    const char* loc = "zh-CN";
    CefString(&settings.locale).FromASCII(loc);
    CefString(&settings.accept_language_list).FromASCII(loc);
    cef_string_from_ascii(loc, strlen(loc), &settings.locale);
    /*settings.Locale = "zh-CN";
    settings.AcceptLanguageList="zh-CN";*/
    settings.ignore_certificate_errors = true;      //ºöÂÔµôsslÖ¤ÊéÑéÖ¤´íÎó
    settings.log_severity = LOGSEVERITY_ERROR; 
    //multi_threaded_message_lo
    settings.single_process = false;
    settings.windowless_rendering_enabled = false;    // ²»ÓÃÀëÆÁäÖȾ
    settings.multi_threaded_message_loop = true;      // ¶àÏß³ÌäÖȾ
    CefString(&settings.log_file)  = SApplication::getSingleton().GetAppDir() + L"\\cef\\";
    CefString(&settings.cache_path) = SApplication::getSingleton().GetAppDir() + L"\\cef\\";
    CefString(&settings.resources_dir_path) = SApplication::getSingleton().GetAppDir() + L"\\cef\\Resources\\";
    CefString(&settings.locales_dir_path) = SApplication::getSingleton().GetAppDir() + L"\\cef\\Resources\\locales";
    //
    // CEF Initiaized
    //
    if (!CefInitialize(main_args, settings, app, windows_sandbox_info))
        return false;
 
    // Register scheme handlers.
    browser::scheme::RegisterSchemeHandlers();
 
    initialized_ = true;
 
    return true;
}
 
void CCef3MainContextImpl::Shutdown() {
    DCHECK(thread_checker_.CalledOnValidThread());
    DCHECK(initialized_);
    DCHECK(!shutdown_);
     
    CefShutdown();
 
    shutdown_ = true;
}
 
 
std::string CCef3MainContextImpl::GetDownloadPath(const std::string& file_name) {
    TCHAR szFolderPath[MAX_PATH];
    std::string path;
 
    // Save the file in the user's "My Documents" folder.
    if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE,
                                  NULL, 0, szFolderPath))) {
        path = CefString(szFolderPath);
        path += "\\" + file_name;
    }
 
    return path;
}
 
std::string CCef3MainContextImpl::GetAppWorkingDirectory() {
    char szWorkingDir[MAX_PATH + 1];
    if (_getcwd(szWorkingDir, MAX_PATH) == NULL) {
        szWorkingDir[0] = 0;
    } else {
        // Add trailing path separator.
        size_t len = strlen(szWorkingDir);
        szWorkingDir[len] = '\\';
        szWorkingDir[len + 1] = 0;
    }
    return szWorkingDir;
}
 
//return the opened browser count
int CCef3MainContextImpl::GetOpenedBrowserCount() {
    return browser_opened_;
}
 
int  CCef3MainContextImpl::AddOpenedBrowserCount() {
    return ++browser_opened_;
}
 
int  CCef3MainContextImpl::DelOpenedBrowserCount() {
    return --browser_opened_;
}
 
}  // namespace browser