WebClient.cpp 19 KB

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