WebClient.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. //
  2. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <include/cef_app.h>
  23. #include <include/cef_client.h>
  24. #include <include/cef_browser.h>
  25. #include <include/wrapper/cef_helpers.h>
  26. #include <include/base/cef_bind.h>
  27. #include <include/wrapper/cef_closure_task.h>
  28. #include "include/wrapper/cef_message_router.h"
  29. #include <Atomic/Core/ProcessUtils.h>
  30. #include <Atomic/Core/CoreEvents.h>
  31. #include <Atomic/IO/Log.h>
  32. #include <Atomic/Input/Input.h>
  33. #include <Atomic/Graphics/Graphics.h>
  34. #include "WebBrowserHost.h"
  35. #include "WebMessageHandler.h"
  36. #include "WebClient.h"
  37. #include "WebKeyboard.h"
  38. #include "WebViewEvents.h"
  39. #include "WebString.h"
  40. #include <SDL/include/SDL.h>
  41. #include <ThirdParty/SDL/include/SDL_syswm.h>
  42. namespace Atomic
  43. {
  44. #ifdef ATOMIC_PLATFORM_OSX
  45. void* GetNSWindowContentView(void* window);
  46. #endif
  47. class WebClientPrivate : public CefClient,
  48. public CefLifeSpanHandler,
  49. public CefLoadHandler,
  50. public CefDisplayHandler,
  51. public CefRequestHandler,
  52. public CefKeyboardHandler
  53. {
  54. friend class WebClient;
  55. public:
  56. WebClientPrivate(WebClient* client)
  57. {
  58. webClient_ = client;
  59. webBrowserHost_ = webClient_->GetSubsystem<WebBrowserHost>();
  60. CefMessageRouterConfig config;
  61. config.js_query_function = "atomicQuery";
  62. config.js_cancel_function = "atomicQueryCancel";
  63. browserSideRouter_ = CefMessageRouterBrowserSide::Create(config);
  64. }
  65. virtual ~WebClientPrivate()
  66. {
  67. }
  68. CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE
  69. {
  70. if (webClient_->renderHandler_.Null())
  71. return nullptr;
  72. return webClient_->renderHandler_->GetCEFRenderHandler();
  73. }
  74. CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
  75. {
  76. return this;
  77. }
  78. CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
  79. {
  80. return this;
  81. }
  82. CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
  83. {
  84. return this;
  85. }
  86. CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
  87. {
  88. return this;
  89. }
  90. CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE
  91. {
  92. return this;
  93. }
  94. // CefKeyboardHandler
  95. virtual bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
  96. const CefKeyEvent& event,
  97. CefEventHandle os_event,
  98. bool* is_keyboard_shortcut) OVERRIDE
  99. {
  100. return false;
  101. }
  102. // CefRequestHandler methods
  103. bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
  104. CefRefPtr<CefFrame> frame,
  105. CefRefPtr<CefRequest> request,
  106. bool is_redirect) OVERRIDE
  107. {
  108. CEF_REQUIRE_UI_THREAD();
  109. browserSideRouter_->OnBeforeBrowse(browser, frame);
  110. return false;
  111. }
  112. bool OnProcessMessageReceived(
  113. CefRefPtr<CefBrowser> browser,
  114. CefProcessId source_process,
  115. CefRefPtr<CefProcessMessage> message) OVERRIDE
  116. {
  117. CEF_REQUIRE_UI_THREAD();
  118. if (browserSideRouter_->OnProcessMessageReceived(browser, source_process, message))
  119. {
  120. return true;
  121. }
  122. return false;
  123. }
  124. void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
  125. TerminationStatus status) OVERRIDE
  126. {
  127. CEF_REQUIRE_UI_THREAD();
  128. browserSideRouter_->OnRenderProcessTerminated(browser);
  129. }
  130. // CefLoadHandler
  131. void OnLoadStart(CefRefPtr<CefBrowser> browser,
  132. CefRefPtr<CefFrame> frame) OVERRIDE
  133. {
  134. if (webClient_.Null() || !frame->IsMain())
  135. return;
  136. VariantMap eventData;
  137. eventData[WebViewLoadStart::P_CLIENT] = webClient_;
  138. CefString cefURL = frame->GetURL();
  139. String url;
  140. ConvertCEFString(cefURL, url);
  141. eventData[WebViewLoadStart::P_URL] = url;
  142. webClient_->SendEvent(E_WEBVIEWLOADSTART, eventData);
  143. }
  144. void OnLoadEnd(CefRefPtr<CefBrowser> browser,
  145. CefRefPtr<CefFrame> frame,
  146. int httpStatusCode) OVERRIDE
  147. {
  148. if (webClient_.Null() || !frame->IsMain())
  149. return;
  150. VariantMap eventData;
  151. eventData[WebViewLoadEnd::P_CLIENT] = webClient_;
  152. CefString cefURL = frame->GetURL();
  153. String url;
  154. ConvertCEFString(cefURL, url);
  155. eventData[WebViewLoadEnd::P_URL] = url;
  156. webClient_->SendEvent(E_WEBVIEWLOADEND, eventData);
  157. }
  158. void OnLoadError(CefRefPtr<CefBrowser> browser,
  159. CefRefPtr<CefFrame> frame,
  160. ErrorCode errorCode,
  161. const CefString& errorText,
  162. const CefString& failedUrl) OVERRIDE
  163. {
  164. if (webClient_.Null())
  165. return;
  166. }
  167. void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
  168. bool isLoading,
  169. bool canGoBack,
  170. bool canGoForward) OVERRIDE
  171. {
  172. if (webClient_.Null())
  173. return;
  174. VariantMap eventData;
  175. eventData[WebViewLoadStateChange::P_CLIENT] = webClient_;
  176. eventData[WebViewLoadStateChange::P_LOADING] = isLoading;
  177. eventData[WebViewLoadStateChange::P_CANGOBACK] = canGoBack;
  178. eventData[WebViewLoadStateChange::P_CANGOFORWARD] = canGoForward;
  179. webClient_->SendEvent(E_WEBVIEWLOADSTATECHANGE, eventData);
  180. }
  181. // CefDisplayHandler
  182. void OnAddressChange(CefRefPtr<CefBrowser> browser,
  183. CefRefPtr<CefFrame> frame,
  184. const CefString& url) OVERRIDE
  185. {
  186. if (webClient_.Null() || !frame->IsMain())
  187. return;
  188. VariantMap eventData;
  189. eventData[WebViewAddressChange::P_CLIENT] = webClient_;
  190. String _url;
  191. ConvertCEFString(url, _url);
  192. eventData[WebViewAddressChange::P_URL] = _url;
  193. webClient_->SendEvent(E_WEBVIEWADDRESSCHANGE, eventData);
  194. }
  195. void OnTitleChange(CefRefPtr<CefBrowser> browser,
  196. const CefString& title) OVERRIDE
  197. {
  198. if (webClient_.Null())
  199. return;
  200. VariantMap eventData;
  201. eventData[WebViewTitleChange::P_CLIENT] = webClient_;
  202. String _title;
  203. ConvertCEFString(title, _title);
  204. eventData[WebViewTitleChange::P_TITLE] = _title;
  205. webClient_->SendEvent(E_WEBVIEWTITLECHANGE, eventData);
  206. }
  207. ///
  208. // Called to display a console message. Return true to stop the message from
  209. // being output to the console.
  210. ///
  211. /*--cef(optional_param=message,optional_param=source)--*/
  212. virtual bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
  213. const CefString& message,
  214. const CefString& source,
  215. int line) OVERRIDE
  216. {
  217. if (webClient_.Null())
  218. return false;
  219. String _message;
  220. ConvertCEFString(message, _message);
  221. String _source;
  222. ConvertCEFString(source, _source);
  223. LOGINFOF("WebViewJS: %s (%s:%i)", _message.CString(), _source.CString(), line);
  224. return false;
  225. }
  226. bool CreateBrowser(const String& initialURL, int width, int height)
  227. {
  228. if (webClient_->renderHandler_.Null())
  229. {
  230. LOGERROR("WebClient::CreateBrowser - No render handler specified");
  231. return false;
  232. }
  233. CefWindowInfo windowInfo;
  234. CefBrowserSettings browserSettings;
  235. browserSettings.webgl = STATE_ENABLED;
  236. browserSettings.file_access_from_file_urls = STATE_ENABLED;
  237. browserSettings.universal_access_from_file_urls = STATE_ENABLED;
  238. windowInfo.width = width;
  239. windowInfo.height = height;
  240. Graphics* graphics = webClient_->GetSubsystem<Graphics>();
  241. SDL_Window* sdlWindow = static_cast<SDL_Window*>(graphics->GetSDLWindow());
  242. SDL_SysWMinfo info;
  243. SDL_VERSION(&info.version);
  244. if(SDL_GetWindowWMInfo(sdlWindow, &info))
  245. {
  246. #ifdef ATOMIC_PLATFORM_OSX
  247. NSView* view = (NSView*) GetNSWindowContentView(info.info.cocoa.window);
  248. windowInfo.SetAsWindowless(view, false);
  249. #endif
  250. #ifdef ATOMIC_PLATFORM_WINDOWS
  251. windowInfo.SetAsWindowless(info.info.win.window, false);
  252. #endif
  253. webClient_->renderHandler_->SetSize(width, height);
  254. CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync(windowInfo, this,
  255. initialURL.CString(), browserSettings, nullptr);
  256. if (!browser.get())
  257. return false;
  258. browser_ = browser;
  259. return true;
  260. }
  261. return false;
  262. }
  263. // CefLifeSpanHandler methods:
  264. virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE
  265. {
  266. CEF_REQUIRE_UI_THREAD();
  267. }
  268. virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE
  269. {
  270. return false;
  271. }
  272. virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE
  273. {
  274. CEF_REQUIRE_UI_THREAD();
  275. browser_ = nullptr;
  276. }
  277. void CloseBrowser(bool force_close)
  278. {
  279. if (!CefCurrentlyOn(TID_UI))
  280. {
  281. // Execute on the UI thread.
  282. CefPostTask(TID_UI,
  283. base::Bind(&WebClientPrivate::CloseBrowser, this, force_close));
  284. return;
  285. }
  286. if (!browser_.get())
  287. return;
  288. browser_->GetHost()->CloseBrowser(force_close);
  289. }
  290. IMPLEMENT_REFCOUNTING(WebClientPrivate);
  291. private:
  292. CefRefPtr<CefBrowser> browser_;
  293. WeakPtr<WebBrowserHost> webBrowserHost_;
  294. WeakPtr<WebClient> webClient_;
  295. CefRefPtr<CefMessageRouterBrowserSide> browserSideRouter_;
  296. };
  297. WebClient::WebClient(Context* context) : Object(context)
  298. {
  299. d_ = new WebClientPrivate(this);
  300. }
  301. WebClient::~WebClient()
  302. {
  303. if (d_)
  304. {
  305. List<SharedPtr<WebMessageHandler>>::Iterator itr = messageHandlers_.Begin();
  306. while (itr != messageHandlers_.End())
  307. {
  308. CefMessageRouterBrowserSide::Handler* handler = static_cast<CefMessageRouterBrowserSide::Handler*>((*itr)->GetCefHandler());
  309. d_->browserSideRouter_->RemoveHandler(handler);
  310. itr++;
  311. }
  312. d_->CloseBrowser(true);
  313. }
  314. renderHandler_ = 0;
  315. //d_->Release();
  316. }
  317. void WebClient::SendMouseClickEvent(int x, int y, unsigned button, bool mouseUp, unsigned modifier, int clickCount) const
  318. {
  319. if (!d_->browser_.get())
  320. return;
  321. CefRefPtr<CefBrowserHost> host = d_->browser_->GetHost();
  322. CefMouseEvent mevent;
  323. mevent.x = x;
  324. mevent.y = y;
  325. mevent.modifiers = 0;
  326. //MBT_LEFT = 0,
  327. //MBT_MIDDLE,
  328. //MBT_RIGHT,
  329. host->SendMouseClickEvent(mevent, (CefBrowserHost::MouseButtonType) button, mouseUp, clickCount);
  330. }
  331. void WebClient::SendMousePressEvent(int x, int y, unsigned button, unsigned modifier, int clickCount) const
  332. {
  333. SendMouseClickEvent(x, y, button, false, modifier, clickCount);
  334. SendMouseClickEvent(x, y, button, true, modifier, clickCount);
  335. }
  336. void WebClient::SendMouseMoveEvent(int x, int y, unsigned modifier, bool mouseLeave) const
  337. {
  338. if (!d_->browser_.get())
  339. return;
  340. CefRefPtr<CefBrowserHost> host = d_->browser_->GetHost();
  341. CefMouseEvent mevent;
  342. mevent.x = x;
  343. mevent.y = y;
  344. mevent.modifiers = 0;
  345. Input* input = GetSubsystem<Input>();
  346. if (input->GetMouseButtonDown(MOUSEB_LEFT))
  347. mevent.modifiers |= EVENTFLAG_LEFT_MOUSE_BUTTON;
  348. if (input->GetMouseButtonDown(MOUSEB_MIDDLE))
  349. mevent.modifiers |= EVENTFLAG_MIDDLE_MOUSE_BUTTON;
  350. if (input->GetMouseButtonDown(MOUSEB_RIGHT))
  351. mevent.modifiers |= EVENTFLAG_RIGHT_MOUSE_BUTTON;
  352. host->SendMouseMoveEvent(mevent, mouseLeave);
  353. }
  354. void WebClient::SendMouseWheelEvent(int x, int y, unsigned modifier,int deltaX, int deltaY) const
  355. {
  356. if (!d_->browser_.get())
  357. return;
  358. CefRefPtr<CefBrowserHost> host = d_->browser_->GetHost();
  359. CefMouseEvent mevent;
  360. mevent.x = x;
  361. mevent.y = y;
  362. mevent.modifiers = 0;
  363. deltaY = -deltaY * 5;
  364. #ifndef ATOMIC_PLATFORM_OSX
  365. deltaY *= 5;
  366. #endif
  367. host->SendMouseWheelEvent(mevent, deltaX, deltaY);
  368. }
  369. /*
  370. EVENTFLAG_CAPS_LOCK_ON = 1 << 0,
  371. EVENTFLAG_SHIFT_DOWN = 1 << 1,
  372. EVENTFLAG_CONTROL_DOWN = 1 << 2,
  373. EVENTFLAG_ALT_DOWN = 1 << 3,
  374. EVENTFLAG_LEFT_MOUSE_BUTTON = 1 << 4,
  375. EVENTFLAG_MIDDLE_MOUSE_BUTTON = 1 << 5,
  376. EVENTFLAG_RIGHT_MOUSE_BUTTON = 1 << 6,
  377. // Mac OS-X command key.
  378. EVENTFLAG_COMMAND_DOWN = 1 << 7,
  379. EVENTFLAG_NUM_LOCK_ON = 1 << 8,
  380. EVENTFLAG_IS_KEY_PAD = 1 << 9,
  381. EVENTFLAG_IS_LEFT = 1 << 10,
  382. EVENTFLAG_IS_RIGHT = 1 << 11,
  383. } cef_event_flags_t;
  384. */
  385. void WebClient::SendKeyEvent(const StringHash eventType, VariantMap& eventData)
  386. {
  387. if (!d_->browser_.get())
  388. return;
  389. CefRefPtr<CefBrowserHost> host = d_->browser_->GetHost();
  390. CefKeyEvent keyEvent;
  391. if (!ConvertKeyEvent(GetSubsystem<Input>(), eventType, eventData, keyEvent))
  392. return;
  393. host->SendKeyEvent(keyEvent);
  394. #ifdef ATOMIC_PLATFORM_WINDOWS
  395. // RETURN KEY: We need to send both keydown and char for return key
  396. // this allows it to be used both to confirm entry on popups,
  397. // while also being used for text input
  398. if (keyEvent.windows_key_code == 13)
  399. {
  400. keyEvent.type = KEYEVENT_CHAR;
  401. host->SendKeyEvent(keyEvent);
  402. }
  403. #endif
  404. #ifdef ATOMIC_PLATFORM_OSX
  405. // RETURN KEY: We need to send both keydown and char for return key
  406. // this allows it to be used both to confirm entry on popups,
  407. // while also being used for text input
  408. if (keyEvent.native_key_code == 36)
  409. {
  410. keyEvent.type = KEYEVENT_CHAR;
  411. host->SendKeyEvent(keyEvent);
  412. }
  413. // Send an empty key event on OSX, which seems to fix
  414. // keyboard problems on OSX with cefclient
  415. // ./cefclient --off-screen-rendering-enabled
  416. // return does not work at all on cef client with offscreen
  417. // bad interaction with arrow keys (for example here, after
  418. // hitting arrow keys, return/text takes a couple presses to register
  419. memset((void*)&keyEvent, 0, sizeof(keyEvent));
  420. keyEvent.type = KEYEVENT_KEYDOWN;
  421. keyEvent.modifiers = 0;
  422. keyEvent.native_key_code = 0;
  423. host->SendKeyEvent(keyEvent);
  424. #endif
  425. }
  426. void WebClient::SendTextInputEvent(const StringHash eventType, VariantMap& eventData)
  427. {
  428. if (!d_->browser_.get())
  429. return;
  430. CefRefPtr<CefBrowserHost> host = d_->browser_->GetHost();
  431. CefKeyEvent keyEvent;
  432. if (!ConvertTextInputEvent(eventType, eventData, keyEvent))
  433. return;
  434. host->SendKeyEvent(keyEvent);
  435. }
  436. void WebClient::SendFocusEvent(bool focus)
  437. {
  438. if (!d_->browser_.get())
  439. return;
  440. CefRefPtr<CefBrowserHost> host = d_->browser_->GetHost();
  441. host->SendFocusEvent(focus);
  442. }
  443. // Javascript
  444. void WebClient::ExecuteJavaScript(const String& script)
  445. {
  446. if (!d_->browser_.get())
  447. return;
  448. d_->browser_->GetMainFrame()->ExecuteJavaScript(CefString(script.CString()), "", 0);
  449. }
  450. void WebClient::AddMessageHandler(WebMessageHandler* handler, bool first)
  451. {
  452. SharedPtr<WebMessageHandler> _handler(handler);
  453. if (handler->GetWebClient())
  454. {
  455. LOGWARNING("WebClient::AddMessageHandler - message handler already added to another client");
  456. return;
  457. }
  458. if (messageHandlers_.Contains(_handler))
  459. {
  460. LOGWARNING("WebClient::AddMessageHandler - message handler already added to this client");
  461. return;
  462. }
  463. _handler->SetWebClient(this);
  464. messageHandlers_.Push(_handler);
  465. d_->browserSideRouter_->AddHandler(static_cast<CefMessageRouterBrowserSide::Handler*>(handler->GetCefHandler()), first);
  466. }
  467. void WebClient::RemoveMessageHandler(WebMessageHandler* handler)
  468. {
  469. SharedPtr<WebMessageHandler> _handler(handler);
  470. List<SharedPtr<WebMessageHandler>>::Iterator itr = messageHandlers_.Find(_handler);
  471. if (itr == messageHandlers_.End())
  472. {
  473. LOGWARNING("WebClient::RemoveMessageHandler - message handler not found");
  474. return;
  475. }
  476. d_->browserSideRouter_->RemoveHandler(static_cast<CefMessageRouterBrowserSide::Handler*>(handler->GetCefHandler()));
  477. messageHandlers_.Erase(itr);
  478. }
  479. // Navigation
  480. void WebClient::LoadURL(const String& url)
  481. {
  482. if (!d_->browser_.get())
  483. {
  484. return;
  485. }
  486. CefString _url(url.CString());
  487. d_->browser_->GetMainFrame()->LoadURL(_url);
  488. }
  489. void WebClient::GoBack()
  490. {
  491. if (!d_->browser_.get())
  492. return;
  493. d_->browser_->GoBack();
  494. }
  495. void WebClient::GoForward()
  496. {
  497. if (!d_->browser_.get())
  498. return;
  499. d_->browser_->GoForward();
  500. }
  501. bool WebClient::IsLoading()
  502. {
  503. if (!d_->browser_.get())
  504. return false;
  505. return d_->browser_->IsLoading();
  506. }
  507. void WebClient::Reload()
  508. {
  509. if (!d_->browser_.get())
  510. return;
  511. d_->browser_->Reload();
  512. }
  513. void WebClient::ShortcutCut()
  514. {
  515. if (!d_->browser_.get())
  516. return;
  517. d_->browser_->GetFocusedFrame()->Cut();
  518. }
  519. void WebClient::ShortcutCopy()
  520. {
  521. if (!d_->browser_.get())
  522. return;
  523. d_->browser_->GetFocusedFrame()->Copy();
  524. }
  525. void WebClient::ShortcutPaste()
  526. {
  527. if (!d_->browser_.get())
  528. return;
  529. d_->browser_->GetFocusedFrame()->Paste();
  530. }
  531. void WebClient::ShortcutSelectAll()
  532. {
  533. if (!d_->browser_.get())
  534. return;
  535. d_->browser_->GetFocusedFrame()->SelectAll();
  536. }
  537. void WebClient::ShortcutUndo()
  538. {
  539. if (!d_->browser_.get())
  540. return;
  541. d_->browser_->GetFocusedFrame()->Undo();
  542. }
  543. void WebClient::ShortcutRedo()
  544. {
  545. if (!d_->browser_.get())
  546. return;
  547. d_->browser_->GetFocusedFrame()->Redo();
  548. }
  549. void WebClient::ShortcutDelete()
  550. {
  551. if (!d_->browser_.get())
  552. return;
  553. d_->browser_->GetFocusedFrame()->Delete();
  554. }
  555. void WebClient::WasResized()
  556. {
  557. if (!d_->browser_.get())
  558. return;
  559. CefRefPtr<CefBrowserHost> host = d_->browser_->GetHost();
  560. host->WasResized();;
  561. }
  562. bool WebClient::CreateBrowser(const String& initialURL, int width, int height)
  563. {
  564. bool result = d_->CreateBrowser(initialURL, width, height);
  565. return result;
  566. }
  567. void WebClient::SetSize(int width, int height)
  568. {
  569. if (renderHandler_.Null())
  570. return;
  571. if (renderHandler_->GetWidth() == width && renderHandler_->GetHeight() == height)
  572. return;
  573. renderHandler_->SetSize(width, height);
  574. WasResized();
  575. }
  576. void WebClient::SetWebRenderHandler(WebRenderHandler* handler)
  577. {
  578. handler->SetWebClient(this);
  579. renderHandler_ = handler;
  580. }
  581. CefClient* WebClient::GetCefClient()
  582. {
  583. return d_;
  584. }
  585. }