• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2020 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_DEVTOOLS_MESSAGE_OBSERVER_H_
38 #define CEF_INCLUDE_CEF_DEVTOOLS_MESSAGE_OBSERVER_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 
43 class CefBrowser;
44 
45 ///
46 // Callback interface for CefBrowserHost::AddDevToolsMessageObserver. The
47 // methods of this class will be called on the browser process UI thread.
48 ///
49 /*--cef(source=client)--*/
50 class CefDevToolsMessageObserver : public virtual CefBaseRefCounted {
51  public:
52   ///
53   // Method that will be called on receipt of a DevTools protocol message.
54   // |browser| is the originating browser instance. |message| is a UTF8-encoded
55   // JSON dictionary representing either a method result or an event. |message|
56   // is only valid for the scope of this callback and should be copied if
57   // necessary. Return true if the message was handled or false if the message
58   // should be further processed and passed to the OnDevToolsMethodResult or
59   // OnDevToolsEvent methods as appropriate.
60   //
61   // Method result dictionaries include an "id" (int) value that identifies the
62   // orginating method call sent from CefBrowserHost::SendDevToolsMessage, and
63   // optionally either a "result" (dictionary) or "error" (dictionary) value.
64   // The "error" dictionary will contain "code" (int) and "message" (string)
65   // values. Event dictionaries include a "method" (string) value and optionally
66   // a "params" (dictionary) value. See the DevTools protocol documentation at
67   // https://chromedevtools.github.io/devtools-protocol/ for details of
68   // supported method calls and the expected "result" or "params" dictionary
69   // contents. JSON dictionaries can be parsed using the CefParseJSON function
70   // if desired, however be aware of performance considerations when parsing
71   // large messages (some of which may exceed 1MB in size).
72   ///
73   /*--cef()--*/
OnDevToolsMessage(CefRefPtr<CefBrowser> browser,const void * message,size_t message_size)74   virtual bool OnDevToolsMessage(CefRefPtr<CefBrowser> browser,
75                                  const void* message,
76                                  size_t message_size) {
77     return false;
78   }
79 
80   ///
81   // Method that will be called after attempted execution of a DevTools protocol
82   // method. |browser| is the originating browser instance. |message_id| is the
83   // "id" value that identifies the originating method call message. If the
84   // method succeeded |success| will be true and |result| will be the
85   // UTF8-encoded JSON "result" dictionary value (which may be empty). If the
86   // method failed |success| will be false and |result| will be the UTF8-encoded
87   // JSON "error" dictionary value. |result| is only valid for the scope of this
88   // callback and should be copied if necessary. See the OnDevToolsMessage
89   // documentation for additional details on |result| contents.
90   ///
91   /*--cef(optional_param=result)--*/
OnDevToolsMethodResult(CefRefPtr<CefBrowser> browser,int message_id,bool success,const void * result,size_t result_size)92   virtual void OnDevToolsMethodResult(CefRefPtr<CefBrowser> browser,
93                                       int message_id,
94                                       bool success,
95                                       const void* result,
96                                       size_t result_size) {}
97 
98   ///
99   // Method that will be called on receipt of a DevTools protocol event.
100   // |browser| is the originating browser instance. |method| is the "method"
101   // value. |params| is the UTF8-encoded JSON "params" dictionary value (which
102   // may be empty). |params| is only valid for the scope of this callback and
103   // should be copied if necessary. See the OnDevToolsMessage documentation for
104   // additional details on |params| contents.
105   ///
106   /*--cef(optional_param=params)--*/
OnDevToolsEvent(CefRefPtr<CefBrowser> browser,const CefString & method,const void * params,size_t params_size)107   virtual void OnDevToolsEvent(CefRefPtr<CefBrowser> browser,
108                                const CefString& method,
109                                const void* params,
110                                size_t params_size) {}
111 
112   ///
113   // Method that will be called when the DevTools agent has attached. |browser|
114   // is the originating browser instance. This will generally occur in response
115   // to the first message sent while the agent is detached.
116   ///
117   /*--cef()--*/
OnDevToolsAgentAttached(CefRefPtr<CefBrowser> browser)118   virtual void OnDevToolsAgentAttached(CefRefPtr<CefBrowser> browser) {}
119 
120   ///
121   // Method that will be called when the DevTools agent has detached. |browser|
122   // is the originating browser instance. Any method results that were pending
123   // before the agent became detached will not be delivered, and any active
124   // event subscriptions will be canceled.
125   ///
126   /*--cef()--*/
OnDevToolsAgentDetached(CefRefPtr<CefBrowser> browser)127   virtual void OnDevToolsAgentDetached(CefRefPtr<CefBrowser> browser) {}
128 };
129 
130 #endif  // CEF_INCLUDE_CEF_DEVTOOLS_MESSAGE_OBSERVER_H_
131