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 "content/public/browser/web_contents.h" 14 #include "ui/gfx/geometry/size.h" 15 16 // Implementation of Alloy-based browser functionality. 17 class CefBrowserPlatformDelegateAlloy : public CefBrowserPlatformDelegate { 18 public: 19 content::WebContents* CreateWebContents(CefBrowserCreateParams& create_params, 20 bool& own_web_contents) override; 21 void WebContentsCreated(content::WebContents* web_contents, 22 bool owned) override; 23 void AddNewContents(content::WebContents* source, 24 std::unique_ptr<content::WebContents> new_contents, 25 const GURL& target_url, 26 WindowOpenDisposition disposition, 27 const gfx::Rect& initial_rect, 28 bool user_gesture, 29 bool* was_blocked) override; 30 bool ShouldTransferNavigation(bool is_main_frame_navigation) override; 31 void RenderViewCreated(content::RenderViewHost* render_view_host) override; 32 void RenderViewReady() override; 33 void BrowserCreated(CefBrowserHostBase* browser) override; 34 void CreateExtensionHost(const extensions::Extension* extension, 35 const GURL& url, 36 extensions::mojom::ViewType host_type) override; 37 extensions::ExtensionHost* GetExtensionHost() const override; 38 void BrowserDestroyed(CefBrowserHostBase* browser) override; 39 void SendCaptureLostEvent() override; 40 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MAC)) 41 void NotifyMoveOrResizeStarted() override; 42 #endif 43 bool PreHandleGestureEvent(content::WebContents* source, 44 const blink::WebGestureEvent& event) override; 45 bool IsNeverComposited(content::WebContents* web_contents) override; 46 void SetAutoResizeEnabled(bool enabled, 47 const CefSize& min_size, 48 const CefSize& max_size) override; 49 void SetAccessibilityState(cef_state_t accessibility_state) override; 50 bool IsPrintPreviewSupported() const override; 51 void Print() override; 52 void PrintToPDF(const CefString& path, 53 const CefPdfPrintSettings& settings, 54 CefRefPtr<CefPdfPrintCallback> callback) override; 55 void Find(int identifier, 56 const CefString& searchText, 57 bool forward, 58 bool matchCase, 59 bool findNext) override; 60 void StopFinding(bool clearSelection) override; 61 62 protected: 63 CefBrowserPlatformDelegateAlloy(); 64 65 base::RepeatingClosure GetBoundsChangedCallback(); 66 67 // Returns the WebContents most likely to handle an action. If extensions are 68 // enabled and this browser has a full-page guest (for example, a full-page 69 // PDF viewer extension) then the guest's WebContents will be returned. 70 // Otherwise, the browser's WebContents will be returned. 71 content::WebContents* GetActionableWebContents() const; 72 73 // Called from BrowserPlatformDelegateNative::set_windowless_handler(). set_as_secondary()74 void set_as_secondary() { primary_ = false; } 75 76 private: 77 void SetOwnedWebContents(content::WebContents* owned_contents); 78 79 void DestroyExtensionHost(); 80 void OnExtensionHostDeleted(); 81 82 void ConfigureAutoResize(); 83 84 // Non-nullptr if this object owns the WebContents. Will be nullptr for popup 85 // browsers between the calls to WebContentsCreated() and AddNewContents(), 86 // and may never be set if the parent browser is destroyed during popup 87 // creation. 88 std::unique_ptr<content::WebContents> owned_web_contents_; 89 90 // Used for the print preview dialog. 91 std::unique_ptr<CefWebContentsDialogHelper> web_contents_dialog_helper_; 92 93 // Used to provide unique incremental IDs for each find request. 94 int find_request_id_counter_ = 0; 95 96 // Used when the browser is hosting an extension. 97 extensions::ExtensionHost* extension_host_ = nullptr; 98 bool is_background_host_ = false; 99 100 // Used with auto-resize. 101 bool auto_resize_enabled_ = false; 102 gfx::Size auto_resize_min_; 103 gfx::Size auto_resize_max_; 104 105 // True if this is the primary platform delegate, in which case it will 106 // register WebContents delegate/observers. 107 bool primary_ = true; 108 109 base::WeakPtrFactory<CefBrowserPlatformDelegateAlloy> weak_ptr_factory_; 110 111 DISALLOW_COPY_AND_ASSIGN(CefBrowserPlatformDelegateAlloy); 112 }; 113 114 #endif // CEF_LIBCEF_BROWSER_ALLOY_BROWSER_PLATFORM_DELEGATE_ALLOY_H_ 115