使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 0408576e9da10015ffa9da0079b8c985113ce4b3
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
#ifndef __CEF3WEBVWNDHANDLER_H_
#define __CEF3WEBVWNDHANDLER_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_WND = WM_APP + 2;
 
#define  WM_OPENFILEDIALOG   WM_USER+1880 
#define  WM_WEBURLDIALOG     WM_USER+1881
 
class   CCef3WebVWndHandler : public CefClient,
                       public CefRenderHandler,
                       public CefContextMenuHandler,
                       public CefDisplayHandler,
                       public CefDownloadHandler,
                       public CefDragHandler,
                       public CefKeyboardHandler,
                       public CefLifeSpanHandler,
                       public CefLoadHandler,
                       public CefDialogHandler,
                       public CefRequestHandler
{
public: 
    
    CCef3WebVWndHandler();
    ~CCef3WebVWndHandler();
 
// ------------------------------------------------------------------------------
// 
// browser methods for user
//
// ------------------------------------------------------------------------------
 
    IMPLEMENT_REFCOUNTING(CCef3WebVWndHandler);
 
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,const CefString& url,SOUI::CRect rcView);
    void Close();
    void CloseAllBrowsers(bool force_close);
    void OpenDevTools();      
    CefRefPtr<CefBrowser> GetBrowser(); 
 
// ------------------------------------------------------------------------------
//
// 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 
    {
       
 
        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;
 
  /////////////////////////////////////CefDownloadHandler//////////////////////////////
  virtual void OnBeforeDownload(
      CefRefPtr<CefBrowser> browser,
      CefRefPtr<CefDownloadItem> download_item,
      const CefString& suggested_name,
      CefRefPtr<CefBeforeDownloadCallback> callback);
 
  
  virtual void OnDownloadUpdated(
      CefRefPtr<CefBrowser> browser,
      CefRefPtr<CefDownloadItem> download_item,
      CefRefPtr<CefDownloadItemCallback> callback); 
 
  virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler() override;  
  /////////////////////////////////////end CefDownloadHandler//////////////////////////////
 
    //
    // 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;
     
    }
 
    virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        ErrorCode errorCode,
        const CefString& errorText,
        const CefString& failedUrl)
    {
         CEF_REQUIRE_UI_THREAD();
 
        // Don't display an error for downloaded files.
        if (errorCode == ERR_ABORTED)
            return;
 
        // Display a load error message.
        std::stringstream ss;
        ss << "<html><body bgcolor=\"white\">"
            "<h2>Failed to load URL " << std::string(failedUrl) <<
            " with error " << std::string(errorText) << " (" << errorCode <<
            ").</h2></body></html>";
        frame->LoadString(ss.str(), failedUrl);
    }
 
protected: 
          ///
  // Return the handler for dialogs. If no handler is provided the default
  // implementation will be used.
  ///
  /*--cef()--*/
  virtual CefRefPtr<CefDialogHandler> GetDialogHandler() {
        return this;
  }
 
   virtual bool OnFileDialog(CefRefPtr<CefBrowser> browser,
                            FileDialogMode mode,
                            const CefString& title,
                            const CefString& default_file_path,
                            const std::vector<CefString>& accept_filters,
                            int selected_accept_filter,
                            CefRefPtr<CefFileDialogCallback> callback) {
      
    m_pFileDialogCallback  = callback; 
    
    ::SetFocus(m_hOwnerWnd); 
     
    ::SendMessage(m_hOwnerWnd,WM_OPENFILEDIALOG,NULL,NULL);
     
    CefRefPtr<CefBrowserHost> host = browser->GetHost();
    host->SetFocus(true); 
 
    return true;
  }
public:
    CefRefPtr<CefFileDialogCallback> m_pFileDialogCallback;
private:
    mutable base::Lock lock_;    
    HWND    m_hOwnerWnd;
    CefRefPtr<CefBrowser>   m_refBrowser;
    BOOL                    m_bPageLoaded;
  
    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_;
 
    std::wstring           m_PopupUrl; // µ¯³öµØÖ·
    std::wstring           m_strHtml; // ÒªÏÔʾµÄhtmlÄÚÈÝ
public:
    std::wstring          GetPopupUrl();
    bool                IsAllowOsExce(const CefString& url);// Allow OS execution of Spotify URIs.
    void                LoadHtml( std::wstring strValue);
};
 
 
} //namespace browser
 
#endif  // __CEF3WEBVWNDHANDLER_H_