mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Move browser runtime-specific logic to CefBrowserPlatformDelegate (see issue #2969)
This change moves the runtime-specific implementations of CefBrowserHostImpl methods to CefBrowserPlatformDelegate. Some WebContentsDelegate methods implemented by CefBrowserHostImpl set state or trigger client callbacks. Those implementations will likely stay with CefBrowserHostImpl and will need to be called from the Browser equivalents when using the Chrome runtime.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
|
||||
#include "base/callback_forward.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace blink {
|
||||
@@ -32,6 +33,10 @@ class RenderViewHostDelegateView;
|
||||
class WebContentsView;
|
||||
} // namespace content
|
||||
|
||||
namespace extensions {
|
||||
class ExtensionHost;
|
||||
}
|
||||
|
||||
#if defined(USE_AURA)
|
||||
namespace views {
|
||||
class Widget;
|
||||
@@ -54,6 +59,13 @@ class CefBrowserPlatformDelegate {
|
||||
static std::unique_ptr<CefBrowserPlatformDelegate> Create(
|
||||
CefBrowserHostImpl::CreateParams& create_params);
|
||||
|
||||
// Called from CefBrowserHostImpl::Create.
|
||||
// Wait for the call to WebContentsCreated(owned=true) before taking ownership
|
||||
// of the resulting WebContents object.
|
||||
virtual content::WebContents* CreateWebContents(
|
||||
CefBrowserHostImpl::CreateParams& create_params,
|
||||
bool& own_web_contents);
|
||||
|
||||
// Called to create the view objects for a new WebContents. Will only be
|
||||
// called a single time per instance. May be called on multiple threads. Only
|
||||
// used with windowless rendering.
|
||||
@@ -61,9 +73,28 @@ class CefBrowserPlatformDelegate {
|
||||
content::WebContentsView** view,
|
||||
content::RenderViewHostDelegateView** delegate_view);
|
||||
|
||||
// Called after the WebContents for the browser is created. Will only be
|
||||
// called a single time per instance.
|
||||
virtual void WebContentsCreated(content::WebContents* web_contents);
|
||||
// Called after the WebContents for a browser has been created. |owned| will
|
||||
// be true if |web_contents| was created via CreateWebContents() and we should
|
||||
// take ownership. This will also be called for popup WebContents created
|
||||
// indirectly by Chromium. Will only be called a single time per instance.
|
||||
virtual void WebContentsCreated(content::WebContents* web_contents,
|
||||
bool owned);
|
||||
|
||||
// Called when Chromium is ready to hand over ownership of a popup
|
||||
// WebContents. WebContentsCreated(owned=false) will be called first for
|
||||
// |new_contents|. Will only be called a single time per instance. See also
|
||||
// the WebContentsDelegate documentation.
|
||||
virtual void AddNewContents(
|
||||
content::WebContents* source,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
const GURL& target_url,
|
||||
WindowOpenDisposition disposition,
|
||||
const gfx::Rect& initial_rect,
|
||||
bool user_gesture,
|
||||
bool* was_blocked);
|
||||
|
||||
// See WebContentsDelegate documentation.
|
||||
virtual bool ShouldTransferNavigation(bool is_main_frame_navigation);
|
||||
|
||||
// Called after the RenderViewHost is created.
|
||||
virtual void RenderViewCreated(content::RenderViewHost* render_view_host);
|
||||
@@ -73,6 +104,11 @@ class CefBrowserPlatformDelegate {
|
||||
// method.
|
||||
virtual void BrowserCreated(CefBrowserHostImpl* browser);
|
||||
|
||||
// Called from CefBrowserHostImpl::Create.
|
||||
void CreateExtensionHost(const extensions::Extension* extension,
|
||||
const GURL& url,
|
||||
extensions::ViewType host_type);
|
||||
|
||||
// Send any notifications related to browser creation. Called after
|
||||
// BrowserCreated().
|
||||
virtual void NotifyBrowserCreated();
|
||||
@@ -189,6 +225,13 @@ class CefBrowserPlatformDelegate {
|
||||
virtual bool HandleKeyboardEvent(
|
||||
const content::NativeWebKeyboardEvent& event) = 0;
|
||||
|
||||
// See WebContentsDelegate documentation.
|
||||
virtual bool PreHandleGestureEvent(content::WebContents* source,
|
||||
const blink::WebGestureEvent& event);
|
||||
|
||||
// See WebContentsDelegate documentation.
|
||||
virtual bool IsNeverComposited(content::WebContents* web_contents);
|
||||
|
||||
// Invoke platform specific handling for the external protocol.
|
||||
static void HandleExternalProtocol(const GURL& url);
|
||||
|
||||
@@ -267,6 +310,26 @@ class CefBrowserPlatformDelegate {
|
||||
virtual gfx::Point GetDialogPosition(const gfx::Size& size);
|
||||
virtual gfx::Size GetMaximumDialogSize();
|
||||
|
||||
// See CefBrowserHost documentation.
|
||||
void SetAutoResizeEnabled(bool enabled,
|
||||
const CefSize& min_size,
|
||||
const CefSize& max_size);
|
||||
virtual void ConfigureAutoResize();
|
||||
virtual void SetAccessibilityState(cef_state_t accessibility_state);
|
||||
virtual bool IsPrintPreviewSupported() const;
|
||||
virtual void Print();
|
||||
virtual void PrintToPDF(const CefString& path,
|
||||
const CefPdfPrintSettings& settings,
|
||||
CefRefPtr<CefPdfPrintCallback> callback);
|
||||
virtual void Find(int identifier,
|
||||
const CefString& searchText,
|
||||
bool forward,
|
||||
bool matchCase,
|
||||
bool findNext);
|
||||
virtual void StopFinding(bool clearSelection);
|
||||
|
||||
extensions::ExtensionHost* extension_host() const { return extension_host_; }
|
||||
|
||||
protected:
|
||||
// Allow deletion via scoped_ptr only.
|
||||
friend std::default_delete<CefBrowserPlatformDelegate>;
|
||||
@@ -278,12 +341,45 @@ class CefBrowserPlatformDelegate {
|
||||
|
||||
static int TranslateWebEventModifiers(uint32 cef_modifiers);
|
||||
|
||||
CefBrowserHostImpl* browser_ = nullptr; // Not owned by this object.
|
||||
// Returns the WebContents most likely to handle an action. If extensions are
|
||||
// enabled and this browser has a full-page guest (for example, a full-page
|
||||
// PDF viewer extension) then the guest's WebContents will be returned.
|
||||
// Otherwise, the browser's WebContents will be returned.
|
||||
content::WebContents* GetActionableWebContents() const;
|
||||
|
||||
// Not owned by this object.
|
||||
content::WebContents* web_contents_ = nullptr;
|
||||
CefBrowserHostImpl* browser_ = nullptr;
|
||||
|
||||
private:
|
||||
void SetOwnedWebContents(content::WebContents* owned_contents);
|
||||
|
||||
void DestroyExtensionHost();
|
||||
void OnExtensionHostDeleted();
|
||||
|
||||
// Non-nullptr if this object owns the WebContents. Will be nullptr for popup
|
||||
// browsers between the calls to WebContentsCreated() and AddNewContents(),
|
||||
// and may never be set if the parent browser is destroyed during popup
|
||||
// creation.
|
||||
std::unique_ptr<content::WebContents> owned_web_contents_;
|
||||
|
||||
// Used for the print preview dialog.
|
||||
std::unique_ptr<CefWebContentsDialogHelper> web_contents_dialog_helper_;
|
||||
|
||||
// Used to provide unique incremental IDs for each find request.
|
||||
int find_request_id_counter_ = 0;
|
||||
|
||||
// Used when the browser is hosting an extension.
|
||||
extensions::ExtensionHost* extension_host_ = nullptr;
|
||||
bool is_background_host_ = false;
|
||||
|
||||
// Used with auto-resize.
|
||||
bool auto_resize_enabled_ = false;
|
||||
gfx::Size auto_resize_min_;
|
||||
gfx::Size auto_resize_max_;
|
||||
|
||||
base::WeakPtrFactory<CefBrowserPlatformDelegate> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefBrowserPlatformDelegate);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user