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:
@ -20,6 +20,7 @@
|
||||
#include "tests/cefclient/browser/main_context.h"
|
||||
#include "tests/cefclient/browser/root_window_manager.h"
|
||||
#include "tests/cefclient/browser/test_runner.h"
|
||||
#include "tests/shared/browser/extension_util.h"
|
||||
#include "tests/shared/browser/resource_util.h"
|
||||
#include "tests/shared/common/client_switches.h"
|
||||
|
||||
@ -417,6 +418,14 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClientHandler::OnAutoResize(CefRefPtr<CefBrowser> browser,
|
||||
const CefSize& new_size) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
NotifyAutoResize(new_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClientHandler::OnBeforeDownload(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefDownloadItem> download_item,
|
||||
@ -541,6 +550,19 @@ void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
||||
if (mouse_cursor_change_disabled_)
|
||||
browser->GetHost()->SetMouseCursorChangeDisabled(true);
|
||||
|
||||
if (browser->GetHost()->GetExtension()) {
|
||||
// Browsers hosting extension apps should auto-resize.
|
||||
browser->GetHost()->SetAutoResizeEnabled(true, CefSize(20, 20),
|
||||
CefSize(1000, 1000));
|
||||
|
||||
CefRefPtr<CefExtension> extension = browser->GetHost()->GetExtension();
|
||||
if (extension_util::IsInternalExtension(extension->GetPath())) {
|
||||
// Register the internal handler for extension resources.
|
||||
extension_util::AddInternalExtensionToResourceManager(extension,
|
||||
resource_manager_);
|
||||
}
|
||||
}
|
||||
|
||||
NotifyBrowserCreated(browser);
|
||||
}
|
||||
|
||||
@ -623,8 +645,11 @@ bool ClientHandler::OnOpenURLFromTab(
|
||||
target_disposition == WOD_NEW_FOREGROUND_TAB) {
|
||||
// Handle middle-click and ctrl + left-click by opening the URL in a new
|
||||
// browser window.
|
||||
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
|
||||
true, is_osr(), CefRect(), target_url);
|
||||
RootWindowConfig config;
|
||||
config.with_controls = true;
|
||||
config.with_osr = is_osr();
|
||||
config.url = target_url;
|
||||
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -867,9 +892,11 @@ void ClientHandler::ShowSSLInformation(CefRefPtr<CefBrowser> browser) {
|
||||
|
||||
ss << "</body></html>";
|
||||
|
||||
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
|
||||
false, is_osr(), CefRect(),
|
||||
test_runner::GetDataURI(ss.str(), "text/html"));
|
||||
RootWindowConfig config;
|
||||
config.with_controls = false;
|
||||
config.with_osr = is_osr();
|
||||
config.url = test_runner::GetDataURI(ss.str(), "text/html");
|
||||
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
|
||||
}
|
||||
|
||||
bool ClientHandler::CreatePopupWindow(CefRefPtr<CefBrowser> browser,
|
||||
@ -969,6 +996,18 @@ void ClientHandler::NotifyFullscreen(bool fullscreen) {
|
||||
delegate_->OnSetFullscreen(fullscreen);
|
||||
}
|
||||
|
||||
void ClientHandler::NotifyAutoResize(const CefSize& new_size) {
|
||||
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
||||
// Execute this method on the main thread.
|
||||
MAIN_POST_CLOSURE(
|
||||
base::Bind(&ClientHandler::NotifyAutoResize, this, new_size));
|
||||
return;
|
||||
}
|
||||
|
||||
if (delegate_)
|
||||
delegate_->OnAutoResize(new_size);
|
||||
}
|
||||
|
||||
void ClientHandler::NotifyLoadingState(bool isLoading,
|
||||
bool canGoBack,
|
||||
bool canGoForward) {
|
||||
|
Reference in New Issue
Block a user