使用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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#ifndef _BROWSER_BROWSERHANDLER_H
#define _BROWSER_BROWSERHANDLER_H
 
#include "include/cef_client.h"
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "Cef3ClientApp.h"
#include "include/cef_drag_handler.h"
#include "include/wrapper/cef_resource_manager.h"
 
#include <list>
#include "souistd.h"
 
 
namespace browser
{  
 
const int POPUP_DEVTOOLS = WM_APP + 1;
 
class   CCef3WebviewHandler : public CefClient,
                       public CefRenderHandler,
                       public CefContextMenuHandler,
                       public CefDisplayHandler,
                       public CefDragHandler,
                       public CefKeyboardHandler,
                       public CefLifeSpanHandler,
                       public CefLoadHandler,
                       public CefRequestHandler
{
public: 
    // Implement this interface to receive notification of ClientHandlerOsr
    // events. The methods of this class will be called on the CEF UI thread.
    class OsrDelegate {
    public:
        // These methods match the CefLifeSpanHandler interface.
        virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) = 0;
        virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) = 0;
 
        // These methods match the CefRenderHandler interface.
        virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> browser,
            CefRect& rect) = 0;
        virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
            CefRect& rect) = 0;
        virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
            int viewX,
            int viewY,
            int& screenX,
            int& screenY) = 0;
        virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
            CefScreenInfo& screen_info) = 0;
        virtual void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) = 0;
        virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
            const CefRect& rect) = 0;
        virtual void OnPaint(CefRefPtr<CefBrowser> browser,
            PaintElementType type,
            const RectList& dirtyRects,
            const void* buffer,
            int width,
            int height) = 0;
        virtual void OnCursorChange(
            CefRefPtr<CefBrowser> browser,
            CefCursorHandle cursor,
            CefRenderHandler::CursorType type,
            const CefCursorInfo& custom_cursor_info) = 0;
        virtual void UpdateDragCursor(
            CefRefPtr<CefBrowser> browser,
            CefRenderHandler::DragOperation operation) = 0;
        virtual void OnImeCompositionRangeChanged(
            CefRefPtr<CefBrowser> browser,
            const CefRange& selection_range,
            const CefRenderHandler::RectList& character_bounds) = 0;
 
        virtual void OnBeforePopup(CefRefPtr<CefBrowser> browser,
                                   CefRefPtr<CefFrame> frame,
                                   const CefString& target_url,
                                   const CefString& target_frame_name,
                                   CefLifeSpanHandler::WindowOpenDisposition target_disposition,
                                   bool user_gesture,
                                   const CefPopupFeatures& popupFeatures,
                                   CefWindowInfo& windowInfo,
                                   CefRefPtr<CefClient>& client,
                                   CefBrowserSettings& settings,
                                   bool* no_javascript_access) = 0;
 
        virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
                                     CefRefPtr<CefFrame> frame,
                                     const CefString &url) = 0;
 
        virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
                               CefRefPtr<CefFrame> frame,
                               int httpStatusCode) = 0;
    protected:
        virtual ~OsrDelegate() {}
    };
 
 
    class MessageHandler
    {
    public:
        virtual bool OnBrowserMessage(CefRefPtr<CefBrowser> browser,
            CefProcessId source_process,
            CefRefPtr<CefProcessMessage> message) = 0;
    };
 
    CCef3WebviewHandler();
    ~CCef3WebviewHandler();
 
// ------------------------------------------------------------------------------
// 
// browser methods for user
//
// ------------------------------------------------------------------------------
 
    IMPLEMENT_REFCOUNTING(CCef3WebviewHandler);
 
public:
    void CloseDevTools(CefRefPtr<CefBrowser> browser); 
 
    bool CreatePopupWindow(
        CefRefPtr<CefBrowser> browser,
        bool is_devtools,
        const CefPopupFeatures& popupFeatures,
        CefWindowInfo& windowInfo,
        CefRefPtr<CefClient>& client,
        CefBrowserSettings& settings);
     
 
    BOOL Open(HWND hParent, SOUI::CRect rcView);
    void Close();
    void CloseAllBrowsers(bool force_close);
    void OpenDevTools();
    void SetRender(OsrDelegate * pHost);
    CefRefPtr<CefBrowser> GetBrowser();
    void RegisterMessageHandler(MessageHandler * handler);
    void UnRegisterMessgeHandler(MessageHandler * handler);
    bool IsAllowOsExce(const CefString& url);// Allow OS execution of Spotify URIs.
 
// ------------------------------------------------------------------------------
//
// impl cef handler callbacks
//
// ------------------------------------------------------------------------------
 
protected:
 
    //
    // CefClient methods. Important to return |this| for the handler callbacks.
    // 
 
    virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE { return this; }
    virtual CefRefPtr<CefRenderHandler> GetRenderHandler()           OVERRIDE { return this; }
    virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler()         OVERRIDE { return this; }
    virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler()       OVERRIDE { return this; }
    virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler()       OVERRIDE { return this; }
    virtual CefRefPtr<CefLoadHandler> GetLoadHandler()               OVERRIDE { return this; }
    virtual CefRefPtr<CefDragHandler> GetDragHandler()               OVERRIDE { return this; }
    virtual CefRefPtr<CefRequestHandler> GetRequestHandler()         OVERRIDE { return this; }
 
    virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
        CefProcessId source_process,
        CefRefPtr<CefProcessMessage> message)  OVERRIDE 
    {
        if (m_pMsgHandler)
        {
            return m_pMsgHandler->OnBrowserMessage(browser, source_process, message);
        }
 
        return true;
    }
 
    // CefRequestHandler methods
    bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefRequest> request,
        bool is_redirect) OVERRIDE;
    bool OnOpenURLFromTab(
        CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        const CefString& target_url,
        CefRequestHandler::WindowOpenDisposition target_disposition,
        bool user_gesture) OVERRIDE;
    cef_return_value_t OnBeforeResourceLoad(
        CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefRequest> request,
        CefRefPtr<CefRequestCallback> callback) OVERRIDE;
    CefRefPtr<CefResourceHandler> GetResourceHandler(
        CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefRequest> request) OVERRIDE;
    CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
        CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefRequest> request,
        CefRefPtr<CefResponse> response) OVERRIDE;
    bool OnQuotaRequest(CefRefPtr<CefBrowser> browser,
        const CefString& origin_url,
        int64 new_size,
        CefRefPtr<CefRequestCallback> callback) OVERRIDE;
    void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
        const CefString& url,
        bool& allow_os_execution) OVERRIDE;
    bool OnCertificateError(
        CefRefPtr<CefBrowser> browser,
        ErrorCode cert_error,
        const CefString& request_url,
        CefRefPtr<CefSSLInfo> ssl_info,
        CefRefPtr<CefRequestCallback> callback) OVERRIDE;
    void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
        TerminationStatus status) OVERRIDE;
 
     
    // CefRenderHandler interfaces 
    virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> browser,
        CefRect& rect) OVERRIDE;
    virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
        CefRect& rect) OVERRIDE;
    virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
        int viewX,
        int viewY,
        int& screenX,
        int& screenY) OVERRIDE;
    virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
        CefScreenInfo& screen_info)  OVERRIDE;
    virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
        bool show) OVERRIDE; 
    virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
        const CefRect& rect)  OVERRIDE; 
    virtual void OnPaint(
        CefRefPtr<CefBrowser> browser,
        PaintElementType type,
        const RectList& dirtyRects,
        const void* buffer,
        int width,
        int height) OVERRIDE; 
    virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
        CefCursorHandle cursor,
        CursorType type,
        const CefCursorInfo& custom_cursor_info) OVERRIDE; 
    virtual bool StartDragging(
        CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefDragData> drag_data,
        CefRenderHandler::DragOperationsMask allowed_ops,
        int x, int y) OVERRIDE; 
    virtual void UpdateDragCursor(
        CefRefPtr<CefBrowser> browser,
        CefRenderHandler::DragOperation operation)
        OVERRIDE;
     void OnImeCompositionRangeChanged(
      CefRefPtr<CefBrowser> browser,
      const CefRange& selection_range,
      const CefRenderHandler::RectList& character_bounds) OVERRIDE;
 
    //
    // CefContextMenuHandler methods
    // 
    virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefContextMenuParams> params,
        CefRefPtr<CefMenuModel> model) OVERRIDE;
 
    // CefDisplayHandler methods
    void OnTitleChange(CefRefPtr<CefBrowser> browser,
                       const CefString& title) OVERRIDE;
 
    bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
                          const CefString& message,
                          const CefString& source, int line) OVERRIDE;
    void OnAddressChange(CefRefPtr<CefBrowser> browser,
                         CefRefPtr<CefFrame> frame,
                         const CefString& url) OVERRIDE;
 
 
    //
    // CefKeyboardHandler methods
    //
    virtual bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
        const CefKeyEvent& event,
        CefEventHandle os_event,
        bool* is_keyboard_shortcut) OVERRIDE;
 
    //
    // CefLifeSpanHandler methods
    //
    virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        const CefString& target_url,
        const CefString& target_frame_name,
        CefLifeSpanHandler::WindowOpenDisposition target_disposition,
        bool user_gesture,
        const CefPopupFeatures& popupFeatures,
        CefWindowInfo& windowInfo,
        CefRefPtr<CefClient>& client,
        CefBrowserSettings& settings,
        bool* no_javascript_access)OVERRIDE;
 
    virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE ;
    virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
    virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser)OVERRIDE;
 
    //
    // CefLoadHandler methods
    //
 
    virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
                             CefRefPtr<CefFrame> frame,
                             TransitionType transition_typ) OVERRIDE
    {
    }
 
    virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        int httpStatusCode) OVERRIDE
    {
        m_bPageLoaded = TRUE;
        if (m_posr) {
            m_posr->OnLoadEnd(browser, frame, httpStatusCode);
        }
    }
 
    virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        ErrorCode errorCode,
        const CefString& errorText,
        const CefString& failedUrl)
    {
    }
 
 
private:
    CefRefPtr<CefBrowser>   m_refBrowser;
    BOOL                    m_bPageLoaded;
    OsrDelegate       * m_posr;
    MessageHandler        * m_pMsgHandler;
 
    CefRefPtr<CefClient>    m_refDevToolsClient;
    // Manages the registration and delivery of resources.
    CefRefPtr<CefResourceManager> resource_manager_;
 
    // Console logging state.
    const std::string console_log_file_;
 
    bool first_console_message_;
};
 
 
} //namespace browser
 
#endif