1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. 2 // Portions copyright (c) 2011 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #ifndef CEF_LIBCEF_BROWSER_ALLOY_BROWSER_PLATFORM_DELEGATE_ALLOY_H_ 7 #define CEF_LIBCEF_BROWSER_ALLOY_BROWSER_PLATFORM_DELEGATE_ALLOY_H_ 8 9 #include "libcef/browser/browser_platform_delegate.h" 10 #include "libcef/browser/web_contents_dialog_helper.h" 11 12 #include "base/memory/weak_ptr.h" 13 #include "components/find_in_page/find_notification_details.h" 14 #include "content/public/browser/web_contents.h" 15 #include "ui/gfx/geometry/size.h" 16 17 // Implementation of Alloy-based browser functionality. 18 class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate { 19 public: 20 CefBrowserPlatformDelegateAlloy(const CefBrowserPlatformDelegateAlloy&) = 21 delete; 22 CefBrowserPlatformDelegateAlloy& operator=( 23 const CefBrowserPlatformDelegateAlloy&) = delete; 24 25 content::WebContents* CreateWebContents(CefBrowserCreateParams& create_params, 26 bool& own_web_contents) override; 27 void WebContentsCreated(content::WebContents* web_contents, 28 bool owned) override; 29 void AddNewContents(content::WebContents* source, 30 std::unique_ptr<content::WebContents> new_contents, 31 const GURL& target_url, 32 WindowOpenDisposition disposition, 33 const gfx::Rect& initial_rect, 34 bool user_gesture, 35 bool* was_blocked) override; 36 bool ShouldAllowRendererInitiatedCrossProcessNavigation( 37 bool is_main_frame_navigation) override; 38 void RenderViewCreated(content::RenderViewHost* render_view_host) override; 39 void RenderViewReady() override; 40 void BrowserCreated(CefBrowserHostBase* browser) override; 41 void CreateExtensionHost(const extensions::Extension* extension, 42 const GURL& url, 43 extensions::mojom::ViewType host_type) override; 44 extensions::ExtensionHost* GetExtensionHost() const override; 45 void BrowserDestroyed(CefBrowserHostBase* browser) override; 46 void SendCaptureLostEvent() override; 47 #if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)) 48 void NotifyMoveOrResizeStarted() override; 49 #endif 50 bool PreHandleGestureEvent(content::WebContents* source, 51 const blink::WebGestureEvent& event) override; 52 bool IsNeverComposited(content::WebContents* web_contents) override; 53 void SetAutoResizeEnabled(bool enabled, 54 const CefSize& min_size, 55 const CefSize& max_size) override; 56 void SetAccessibilityState(cef_state_t accessibility_state) override; 57 bool IsPrintPreviewSupported() const override; 58 void Print() override; 59 void PrintToPDF(const CefString& path, 60 const CefPdfPrintSettings& settings, 61 CefRefPtr<CefPdfPrintCallback> callback) override; 62 void Find(const CefString& searchText, 63 bool forward, 64 bool matchCase, 65 bool findNext) override; 66 void StopFinding(bool clearSelection) override; 67 68 // Called from AlloyBrowserHostImpl::FindReply(). 69 bool HandleFindReply(int request_id, 70 int number_of_matches, 71 const gfx::Rect& selection_rect, 72 int active_match_ordinal, 73 bool final_update); 74 last_search_result()75 const find_in_page::FindNotificationDetails& last_search_result() const { 76 return last_search_result_; 77 } 78 79 protected: 80 CefBrowserPlatformDelegateAlloy(); 81 82 base::RepeatingClosure GetBoundsChangedCallback(); 83 84 // Called from BrowserPlatformDelegateNative::set_windowless_handler(). set_as_secondary()85 void set_as_secondary() { primary_ = false; } 86 87 private: 88 void SetOwnedWebContents(content::WebContents* owned_contents); 89 90 void DestroyExtensionHost(); 91 void OnExtensionHostDeleted(); 92 93 void ConfigureAutoResize(); 94 95 // Non-nullptr if this object owns the WebContents. Will be nullptr for popup 96 // browsers between the calls to WebContentsCreated() and AddNewContents(), 97 // and may never be set if the parent browser is destroyed during popup 98 // creation. 99 std::unique_ptr<content::WebContents> owned_web_contents_; 100 101 // Used for the print preview dialog. 102 std::unique_ptr<CefWebContentsDialogHelper> web_contents_dialog_helper_; 103 104 // The last find result. This object contains details about the number of 105 // matches, the find selection rectangle, etc. 106 find_in_page::FindNotificationDetails last_search_result_; 107 108 // Used when the browser is hosting an extension. 109 extensions::ExtensionHost* extension_host_ = nullptr; 110 bool is_background_host_ = false; 111 112 // Used with auto-resize. 113 bool auto_resize_enabled_ = false; 114 gfx::Size auto_resize_min_; 115 gfx::Size auto_resize_max_; 116 117 // True if this is the primary platform delegate, in which case it will 118 // register WebContents delegate/observers. 119 bool primary_ = true; 120 121 base::WeakPtrFactory<CefBrowserPlatformDelegateAlloy> weak_ptr_factory_; 122 }; 123 124 #endif // CEF_LIBCEF_BROWSER_ALLOY_BROWSER_PLATFORM_DELEGATE_ALLOY_H_ 125