1 // Copyright 2017 the Chromium Embedded Framework Authors. Portions copyright 2 // 2013 The Chromium Authors. All rights reserved. Use of this source code is 3 // governed by a BSD-style license that can be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ 6 #define CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ 7 8 #include <memory> 9 10 #include "base/scoped_observation.h" 11 #include "extensions/browser/extension_host.h" 12 #include "extensions/browser/extension_host_registry.h" 13 14 class AlloyBrowserHostImpl; 15 16 namespace content { 17 class WebContents; 18 } // namespace content 19 20 namespace extensions { 21 22 // The ExtensionHost for an extension that backs a view in the browser UI. For 23 // example, this could be an extension popup or dialog, but not a background 24 // page. Object lifespan is managed by AlloyBrowserHostImpl. Based on 25 // chrome/browser/extensions/extension_view_host.h. 26 class CefExtensionViewHost : public ExtensionHost, 27 public ExtensionHostRegistry::Observer { 28 public: 29 CefExtensionViewHost(AlloyBrowserHostImpl* browser, 30 const Extension* extension, 31 content::WebContents* host_contents, 32 const GURL& url, 33 mojom::ViewType host_type); 34 35 CefExtensionViewHost(const CefExtensionViewHost&) = delete; 36 CefExtensionViewHost& operator=(const CefExtensionViewHost&) = delete; 37 38 ~CefExtensionViewHost() override; 39 40 // ExtensionHost methods: 41 void OnDidStopFirstLoad() override; 42 void LoadInitialURL() override; 43 bool IsBackgroundPage() const override; 44 45 // content::WebContentsDelegate methods: 46 bool ShouldAllowRendererInitiatedCrossProcessNavigation( 47 bool is_main_frame_navigation) override; 48 bool PreHandleGestureEvent(content::WebContents* source, 49 const blink::WebGestureEvent& event) override; 50 51 // extensions::ExtensionFunctionDispatcher::Delegate methods: 52 content::WebContents* GetVisibleWebContents() const override; 53 54 // ExtensionHostRegistry::Observer methods: 55 void OnExtensionHostDocumentElementAvailable( 56 content::BrowserContext* browser_context, 57 ExtensionHost* extension_host) override; 58 59 private: 60 base::ScopedObservation<ExtensionHostRegistry, 61 ExtensionHostRegistry::Observer> 62 host_registry_observation_{this}; 63 }; 64 65 } // namespace extensions 66 67 #endif // CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ 68