• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_
6 #define CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_
7 
8 #include "include/cef_client.h"
9 
10 #include <list>
11 
12 class SimpleHandler : public CefClient,
13                       public CefDisplayHandler,
14                       public CefLifeSpanHandler,
15                       public CefLoadHandler {
16  public:
17   explicit SimpleHandler(bool use_views);
18   ~SimpleHandler();
19 
20   // Provide access to the single global instance of this object.
21   static SimpleHandler* GetInstance();
22 
23   // CefClient methods:
GetDisplayHandler()24   virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() override {
25     return this;
26   }
GetLifeSpanHandler()27   virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override {
28     return this;
29   }
GetLoadHandler()30   virtual CefRefPtr<CefLoadHandler> GetLoadHandler() override { return this; }
31 
32   // CefDisplayHandler methods:
33   virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
34                              const CefString& title) override;
35 
36   // CefLifeSpanHandler methods:
37   virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
38   virtual bool DoClose(CefRefPtr<CefBrowser> browser) override;
39   virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;
40 
41   // CefLoadHandler methods:
42   virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
43                            CefRefPtr<CefFrame> frame,
44                            ErrorCode errorCode,
45                            const CefString& errorText,
46                            const CefString& failedUrl) override;
47 
48   // Request that all existing browser windows close.
49   void CloseAllBrowsers(bool force_close);
50 
IsClosing()51   bool IsClosing() const { return is_closing_; }
52 
53   // Returns true if the Chrome runtime is enabled.
54   static bool IsChromeRuntimeEnabled();
55 
56  private:
57   // Platform-specific implementation.
58   void PlatformTitleChange(CefRefPtr<CefBrowser> browser,
59                            const CefString& title);
60 
61   // True if the application is using the Views framework.
62   const bool use_views_;
63 
64   // List of existing browser windows. Only accessed on the CEF UI thread.
65   typedef std::list<CefRefPtr<CefBrowser>> BrowserList;
66   BrowserList browser_list_;
67 
68   bool is_closing_;
69 
70   // Include the default reference counting implementation.
71   IMPLEMENT_REFCOUNTING(SimpleHandler);
72 };
73 
74 #endif  // CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_
75