mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add support for loading extensions (issue #1947)
- Add CefRequestContext::LoadExtension, CefExtension, CefExtensionHandler and related methods/interfaces. - Add chrome://extensions-support that lists supported Chrome APIs. - Add CefBrowserHost::SetAutoResizeEnabled and CefDisplayHandler::OnAutoResize to support browser resize based on preferred web contents size. - views: Add support for custom CefMenuButton popups. - cefclient: Run with `--load-extension=set_page_color` command-line flag for an extension loading example. Add `--use-views` on Windows and Linux for an even better example.
This commit is contained in:
@ -6,15 +6,58 @@
|
||||
#define CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_H_
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "include/base/cef_callback_forward.h"
|
||||
#include "include/base/cef_ref_counted.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/views/cef_window.h"
|
||||
#include "tests/cefclient/browser/client_types.h"
|
||||
#include "tests/cefclient/browser/image_cache.h"
|
||||
#include "tests/shared/browser/main_message_loop.h"
|
||||
|
||||
namespace client {
|
||||
|
||||
// Used to configure how a RootWindow is created.
|
||||
struct RootWindowConfig {
|
||||
RootWindowConfig();
|
||||
|
||||
// If true the window will show controls.
|
||||
bool with_controls;
|
||||
|
||||
// If true the window will use off-screen rendering.
|
||||
bool with_osr;
|
||||
|
||||
// If true the window is hosting an extension app.
|
||||
bool with_extension;
|
||||
|
||||
// If true the window will be created initially hidden.
|
||||
bool initially_hidden;
|
||||
|
||||
// Requested window position. If |bounds| and |source_bounds| are empty the
|
||||
// default window size and location will be used.
|
||||
CefRect bounds;
|
||||
|
||||
// Position of the UI element that triggered the window creation. If |bounds|
|
||||
// is empty and |source_bounds| is non-empty the new window will be positioned
|
||||
// relative to |source_bounds|. This is currently only implemented for Views-
|
||||
// based windows when |initially_hidden| is also true.
|
||||
CefRect source_bounds;
|
||||
|
||||
// Parent window. Only used for Views-based windows.
|
||||
CefRefPtr<CefWindow> parent_window;
|
||||
|
||||
// Callback to be executed when the window is closed. Will be executed on the
|
||||
// main thread. This is currently only implemented for Views-based windows.
|
||||
base::Closure close_callback;
|
||||
|
||||
// Initial URL to load.
|
||||
std::string url;
|
||||
};
|
||||
|
||||
typedef std::set<CefRefPtr<CefExtension>> ExtensionSet;
|
||||
|
||||
// Represents a top-level native window in the browser process. While references
|
||||
// to this object are thread-safe the methods must be called on the main thread
|
||||
// unless otherwise indicated.
|
||||
@ -30,8 +73,8 @@ class RootWindow
|
||||
virtual CefRefPtr<CefRequestContext> GetRequestContext(
|
||||
RootWindow* root_window) = 0;
|
||||
|
||||
// Returns the default window icon.
|
||||
virtual CefRefPtr<CefImage> GetDefaultWindowIcon() = 0;
|
||||
// Returns the ImageCache.
|
||||
virtual scoped_refptr<ImageCache> GetImageCache() = 0;
|
||||
|
||||
// Called to execute a test. See resource.h for |test_id| values.
|
||||
virtual void OnTest(RootWindow* root_window, int test_id) = 0;
|
||||
@ -42,6 +85,21 @@ class RootWindow
|
||||
// Called when the RootWindow has been destroyed.
|
||||
virtual void OnRootWindowDestroyed(RootWindow* root_window) = 0;
|
||||
|
||||
// Called when the RootWindow is activated (becomes the foreground window).
|
||||
virtual void OnRootWindowActivated(RootWindow* root_window) = 0;
|
||||
|
||||
// Called when the browser is created for the RootWindow.
|
||||
virtual void OnBrowserCreated(RootWindow* root_window,
|
||||
CefRefPtr<CefBrowser> browser) = 0;
|
||||
|
||||
// Create a window for |extension|. |source_bounds| are the bounds of the
|
||||
// UI element, like a button, that triggered the extension.
|
||||
virtual void CreateExtensionWindow(CefRefPtr<CefExtension> extension,
|
||||
const CefRect& source_bounds,
|
||||
CefRefPtr<CefWindow> parent_window,
|
||||
const base::Closure& close_callback,
|
||||
bool with_osr) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~Delegate() {}
|
||||
};
|
||||
@ -68,11 +126,8 @@ class RootWindow
|
||||
// Use RootWindowManager::CreateRootWindow() instead of calling this method
|
||||
// directly.
|
||||
virtual void Init(RootWindow::Delegate* delegate,
|
||||
bool with_controls,
|
||||
bool with_osr,
|
||||
const CefRect& bounds,
|
||||
const CefBrowserSettings& settings,
|
||||
const std::string& url) = 0;
|
||||
const RootWindowConfig& config,
|
||||
const CefBrowserSettings& settings) = 0;
|
||||
|
||||
// Initialize as a popup window. This is used to attach a new native window to
|
||||
// a single browser instance that will be created later. The native window
|
||||
@ -121,12 +176,25 @@ class RootWindow
|
||||
// Returns the native handle for this window, if any.
|
||||
virtual ClientWindowHandle GetWindowHandle() const = 0;
|
||||
|
||||
// Returns true if this window is using windowless rendering (osr).
|
||||
virtual bool WithWindowlessRendering() const = 0;
|
||||
|
||||
// Returns true if this window is hosting an extension app.
|
||||
virtual bool WithExtension() const = 0;
|
||||
|
||||
// Called when the set of loaded extensions changes. The default
|
||||
// implementation will create a single window instance for each extension.
|
||||
virtual void OnExtensionsChanged(const ExtensionSet& extensions);
|
||||
|
||||
protected:
|
||||
// Allow deletion via scoped_refptr only.
|
||||
friend struct DeleteOnMainThread;
|
||||
friend class base::RefCountedThreadSafe<RootWindow, DeleteOnMainThread>;
|
||||
|
||||
virtual ~RootWindow() {}
|
||||
RootWindow();
|
||||
virtual ~RootWindow();
|
||||
|
||||
Delegate* delegate_;
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
|
Reference in New Issue
Block a user