simple_handler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
  2. // reserved. Use of this source code is governed by a BSD-style license that
  3. // can be found in the LICENSE file.
  4. #ifndef CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_
  5. #define CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_
  6. #include "include/cef_client.h"
  7. #include <list>
  8. class SimpleHandler : public CefClient,
  9. public CefDisplayHandler,
  10. public CefLifeSpanHandler,
  11. public CefLoadHandler {
  12. public:
  13. explicit SimpleHandler(bool use_views);
  14. ~SimpleHandler();
  15. // Provide access to the single global instance of this object.
  16. static SimpleHandler* GetInstance();
  17. // CefClient methods:
  18. virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
  19. return this;
  20. }
  21. virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
  22. return this;
  23. }
  24. virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE { return this; }
  25. // CefDisplayHandler methods:
  26. virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
  27. const CefString& title) OVERRIDE;
  28. // CefLifeSpanHandler methods:
  29. virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
  30. virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
  31. virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
  32. // CefLoadHandler methods:
  33. virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
  34. CefRefPtr<CefFrame> frame,
  35. ErrorCode errorCode,
  36. const CefString& errorText,
  37. const CefString& failedUrl) OVERRIDE;
  38. // Request that all existing browser windows close.
  39. void CloseAllBrowsers(bool force_close);
  40. bool IsClosing() const { return is_closing_; }
  41. private:
  42. // Platform-specific implementation.
  43. void PlatformTitleChange(CefRefPtr<CefBrowser> browser,
  44. const CefString& title);
  45. // True if the application is using the Views framework.
  46. const bool use_views_;
  47. // List of existing browser windows. Only accessed on the CEF UI thread.
  48. typedef std::list<CefRefPtr<CefBrowser>> BrowserList;
  49. BrowserList browser_list_;
  50. bool is_closing_;
  51. // Include the default reference counting implementation.
  52. IMPLEMENT_REFCOUNTING(SimpleHandler);
  53. };
  54. #endif // CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_