1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_MAIN_FRAME_OBSERVER_H_
6 #define CONTENT_BROWSER_WEBUI_WEB_UI_MAIN_FRAME_OBSERVER_H_
7 
8 #include <stdint.h>
9 
10 #include "base/gtest_prod_util.h"  // FRIEND_TEST_ALL_PREFIXES
11 #include "base/strings/string16.h"
12 #include "build/build_config.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/web_contents_observer.h"
15 
16 namespace blink {
17 namespace mojom {
18 enum class ConsoleMessageLevel;
19 }
20 }  // namespace blink
21 
22 namespace content {
23 class NavigationHandle;
24 class RenderFrameHost;
25 class WebContents;
26 class WebUIImpl;
27 
28 class CONTENT_EXPORT WebUIMainFrameObserver : public WebContentsObserver {
29  public:
30   WebUIMainFrameObserver(WebUIImpl* web_ui, WebContents* contents);
31   ~WebUIMainFrameObserver() override;
32   WebUIMainFrameObserver(const WebUIMainFrameObserver& rhs) = delete;
33   WebUIMainFrameObserver& operator=(const WebUIMainFrameObserver& rhs) = delete;
34 
35  protected:
36   friend class WebUIMainFrameObserverTest;
37 
38   // Override from WebContentsObserver
39   void DidFinishNavigation(NavigationHandle* navigation_handle) override;
40 
41 // TODO(crbug.com/1129544) This is currently disabled due to Windows DLL
42 // thunking issues. Fix & re-enable.
43 #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_BSD)
44   // On official Google builds, capture and report JavaScript error messages on
45   // WebUI surfaces back to Google. This allows us to fix JavaScript errors and
46   // exceptions.
47   void OnDidAddMessageToConsole(RenderFrameHost* source_frame,
48                                 blink::mojom::ConsoleMessageLevel log_level,
49                                 const base::string16& message,
50                                 int32_t line_no,
51                                 const base::string16& source_id) override;
52 #endif  // defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_BSD)
53 
54  private:
55   WebUIImpl* web_ui_;
56 };
57 
58 }  // namespace content
59 
60 #endif  // CONTENT_BROWSER_WEBUI_WEB_UI_MAIN_FRAME_OBSERVER_H_
61