Commit 18763fde authored by Marshall Greenblatt's avatar Marshall Greenblatt
Browse files

Add initial WebUI support (issue #2037)

- Visit chrome://webui-hosts for the list of supported hosts.
parent 659e5af8
......@@ -946,6 +946,7 @@ template("cef_pak_scaled") {
repack("pak_${target_name}") {
# Each input pak file should also have a deps line for completeness.
# Add associated .h files in the make_pack_header("resources") target.
sources = [
"$root_gen_dir/blink/public/resources/blink_image_resources_${percent}_percent.pak",
"$root_gen_dir/chrome/renderer_resources_${percent}_percent.pak",
......@@ -993,6 +994,8 @@ cef_pak_scaled("200_percent") {
# Generate devtools_resources.pak.
repack("pak_devtools") {
# Each input pak file should also have a deps line for completeness.
# Add associated .h files in the make_pack_header("resources") target.
sources = [
"$root_gen_dir/blink/devtools_resources.pak",
]
......@@ -1010,6 +1013,7 @@ repack("pak_devtools") {
# Generate cef_extensions.pak.
repack("pak_extensions") {
# Each input pak file should also have a deps line for completeness.
# Add associated .h files in the make_pack_header("resources") target.
sources = [
"$root_gen_dir/chrome/component_extension_resources.pak",
"$root_gen_dir/extensions/extensions_renderer_resources.pak",
......@@ -1069,12 +1073,15 @@ grit("cef_resources") {
# Generate cef.pak.
repack("pak") {
# Each input pak file should also have a deps line for completeness.
# Add associated .h files in the make_pack_header("resources") target.
sources = [
"$root_gen_dir/blink/public/resources/blink_resources.pak",
"$root_gen_dir/chrome/browser_resources.pak",
"$root_gen_dir/chrome/net_internals_resources.pak",
"$root_gen_dir/chrome/common_resources.pak",
"$root_gen_dir/components/components_resources.pak",
"$root_gen_dir/cef/cef_resources.pak",
"$root_gen_dir/content/browser/tracing/tracing_resources.pak",
"$root_gen_dir/content/content_resources.pak",
"$root_gen_dir/net/net_resources.pak",
]
......@@ -1085,9 +1092,11 @@ repack("pak") {
public_deps = [
"//third_party/WebKit/public:resources_grit",
"//chrome/browser:resources",
"//chrome/browser/resources:net_internals_resources",
"//chrome/common:resources",
"//components/resources:components_resources",
":cef_resources",
"//content/browser/tracing:resources",
"//content:resources",
"//net:net_resources",
]
......@@ -1127,11 +1136,16 @@ make_pack_header("resources") {
header = "$root_out_dir/includes/include/cef_pack_resources.h"
inputs = [
"$root_gen_dir/blink/grit/devtools_resources.h",
"$root_gen_dir/blink/public/resources/grit/blink_image_resources.h",
"$root_gen_dir/blink/public/resources/grit/blink_resources.h",
"$root_gen_dir/cef/grit/cef_resources.h",
"$root_gen_dir/chrome/grit/browser_resources.h",
"$root_gen_dir/chrome/grit/common_resources.h",
"$root_gen_dir/chrome/grit/component_extension_resources.h",
"$root_gen_dir/chrome/grit/net_internals_resources.h",
"$root_gen_dir/chrome/grit/renderer_resources.h",
"$root_gen_dir/components/grit/components_resources.h",
"$root_gen_dir/content/browser/tracing/grit/tracing_resources.h",
"$root_gen_dir/content/grit/content_resources.h",
"$root_gen_dir/extensions/grit/extensions_browser_resources.h",
"$root_gen_dir/extensions/grit/extensions_renderer_resources.h",
......@@ -1148,6 +1162,7 @@ make_pack_header("strings") {
header = "$root_out_dir/includes/include/cef_pack_strings.h"
inputs = [
"$root_gen_dir/cef/grit/cef_strings.h",
"$root_gen_dir/chrome/grit/chromium_strings.h",
"$root_gen_dir/chrome/grit/generated_resources.h",
"$root_gen_dir/chrome/grit/locale_settings.h",
"$root_gen_dir/chrome/grit/platform_locale_settings.h",
......@@ -1396,6 +1411,7 @@ cef_unittests_sources = [
"tests/unittests/v8_unittest.cc",
"tests/unittests/values_unittest.cc",
"tests/unittests/version_unittest.cc",
"tests/unittests/webui_unittest.cc",
"tests/unittests/xml_reader_unittest.cc",
"tests/unittests/zip_reader_unittest.cc",
]
......
......@@ -27,8 +27,10 @@ template("_repack_one_locale") {
visibility = invoker.visibility
# Each input pak file should also have a deps line for completeness.
# Add associated .h files in the make_pack_header("strings") target.
sources = [
"${root_gen_dir}/cef/cef_strings_${locale}.pak",
"${root_gen_dir}/chrome/chromium_strings_${locale}.pak",
"${root_gen_dir}/chrome/generated_resources_${locale}.pak",
"${root_gen_dir}/chrome/locale_settings_${locale}.pak",
"${root_gen_dir}/chrome/platform_locale_settings_${locale}.pak",
......@@ -45,6 +47,7 @@ template("_repack_one_locale") {
# listed both here and in the libcef_static target.
public_deps = [
":cef_strings",
"//chrome/app:chromium_strings",
"//chrome/app:generated_resources",
"//chrome/app/resources:locale_settings",
"//chrome/app/resources:platform_locale_settings",
......
......@@ -17,6 +17,7 @@
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/resource_context_impl.h"
#include "content/browser/streams/stream_context.h"
#include "content/browser/webui/url_data_manager.h"
#include "content/public/browser/storage_partition.h"
namespace {
......@@ -47,6 +48,10 @@ bool ShouldProxyUserData(const void* key) {
if (key == kFontFamilyCacheKey)
return true;
// If this value is not proxied WebUI will fail to load.
if (key == content::URLDataManager::GetUserDataKey())
return true;
return false;
}
......@@ -69,6 +74,14 @@ CefBrowserContextProxy::~CefBrowserContextProxy() {
parent_->RemoveProxy(this);
}
void CefBrowserContextProxy::Initialize() {
CefBrowserContext::Initialize();
// This object's CefResourceContext needs to proxy some UserData requests to
// the parent object's CefResourceContext.
resource_context()->set_parent(parent_->resource_context());
}
base::SupportsUserData::Data*
CefBrowserContextProxy::GetUserData(const void* key) const {
if (ShouldProxyUserData(key))
......
......@@ -23,6 +23,9 @@ class CefBrowserContextProxy : public CefBrowserContext {
CefBrowserContextProxy(CefRefPtr<CefRequestContextHandler> handler,
scoped_refptr<CefBrowserContextImpl> parent);
// Must be called immediately after this object is created.
void Initialize() override;
// SupportsUserData methods.
Data* GetUserData(const void* key) const override;
void SetUserData(const void* key, Data* data) override;
......
......@@ -17,6 +17,7 @@
#include "libcef/browser/extensions/browser_context_keyed_service_factories.h"
#include "libcef/browser/extensions/extensions_browser_client.h"
#include "libcef/browser/extensions/extension_system_factory.h"
#include "libcef/browser/net/chrome_scheme_handler.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_client.h"
#include "libcef/common/extensions/extensions_util.h"
......@@ -27,10 +28,8 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "content/browser/webui/content_web_ui_controller_factory.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/web_ui_controller_factory.h"
#include "content/public/common/content_switches.h"
#include "device/geolocation/access_token_store.h"
#include "device/geolocation/geolocation_delegate.h"
......@@ -141,11 +140,6 @@ void CefBrowserMainParts::ToolkitInitialized() {
}
void CefBrowserMainParts::PostMainMessageLoopStart() {
// Don't use the default WebUI controller factory because is conflicts with
// CEF's internal handling of "chrome://tracing".
content::WebUIControllerFactory::UnregisterFactoryForTesting(
content::ContentWebUIControllerFactory::GetInstance());
#if defined(OS_LINUX)
printing::PrintingContextLinux::SetCreatePrintDialogFunction(
&CefPrintDialogLinux::CreatePrintDialog);
......@@ -202,6 +196,8 @@ void CefBrowserMainParts::PreMainMessageLoopRun() {
device::GeolocationProvider::SetGeolocationDelegate(
new CefGeolocationDelegate(
global_browser_context_->request_context().get()));
scheme::RegisterWebUIControllerFactory();
}
void CefBrowserMainParts::PostMainMessageLoopRun() {
......
......@@ -11,25 +11,46 @@
#include "libcef/common/cef_switches.h"
#include "base/command_line.h"
#include "chrome/browser/net/chrome_net_log_helper.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "components/net_log/chrome_net_log.h"
#include "content/public/common/content_switches.h"
#include "ui/message_center/message_center.h"
ChromeBrowserProcessStub::ChromeBrowserProcessStub()
: initialized_(false),
context_initialized_(false),
shutdown_(false),
locale_("en-US") {
chrome::SetBrowserContextIncognitoHelper(this);
}
ChromeBrowserProcessStub::~ChromeBrowserProcessStub() {
DCHECK(!initialized_ || shutdown_);
DCHECK((!initialized_ && !context_initialized_) || shutdown_);
g_browser_process = NULL;
chrome::SetBrowserContextIncognitoHelper(nullptr);
}
void ChromeBrowserProcessStub::Initialize() {
CEF_REQUIRE_UIT();
void ChromeBrowserProcessStub::Initialize(
const base::CommandLine& command_line) {
DCHECK(!initialized_);
DCHECK(!context_initialized_);
DCHECK(!shutdown_);
base::FilePath net_log_path;
if (command_line.HasSwitch(switches::kLogNetLog))
net_log_path = command_line.GetSwitchValuePath(switches::kLogNetLog);
net_log_.reset(new net_log::ChromeNetLog(
net_log_path, GetNetCaptureModeFromCommandLine(command_line),
command_line.GetCommandLineString(), std::string()));
initialized_ = true;
}
void ChromeBrowserProcessStub::OnContextInitialized() {
CEF_REQUIRE_UIT();
DCHECK(initialized_);
DCHECK(!context_initialized_);
DCHECK(!shutdown_);
// Must be created after the NotificationService.
......@@ -37,12 +58,13 @@ void ChromeBrowserProcessStub::Initialize() {
profile_manager_.reset(new ChromeProfileManagerStub());
event_router_forwarder_ = new extensions::EventRouterForwarder();
initialized_ = true;
context_initialized_ = true;
}
void ChromeBrowserProcessStub::Shutdown() {
CEF_REQUIRE_UIT();
DCHECK(initialized_);
DCHECK(context_initialized_);
DCHECK(!shutdown_);
// Wait for the pending print jobs to finish. Don't do this later, since
......@@ -58,146 +80,149 @@ void ChromeBrowserProcessStub::Shutdown() {
}
void ChromeBrowserProcessStub::ResourceDispatcherHostCreated() {
NOTIMPLEMENTED();
NOTREACHED();
};
void ChromeBrowserProcessStub::EndSession() {
NOTIMPLEMENTED();
NOTREACHED();
};
metrics_services_manager::MetricsServicesManager*
ChromeBrowserProcessStub::GetMetricsServicesManager() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
metrics::MetricsService* ChromeBrowserProcessStub::metrics_service() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
rappor::RapporService* ChromeBrowserProcessStub::rappor_service() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
IOThread* ChromeBrowserProcessStub::io_thread() {
NOTIMPLEMENTED();
return NULL;
}
WatchDogThread* ChromeBrowserProcessStub::watchdog_thread() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
ProfileManager* ChromeBrowserProcessStub::profile_manager() {
DCHECK(context_initialized_);
return profile_manager_.get();
}
PrefService* ChromeBrowserProcessStub::local_state() {
NOTIMPLEMENTED();
return NULL;
DCHECK(context_initialized_);
return profile_manager_->GetLastUsedProfile(
profile_manager_->user_data_dir())->GetPrefs();
}
net::URLRequestContextGetter*
ChromeBrowserProcessStub::system_request_context() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
variations::VariationsService*
ChromeBrowserProcessStub::variations_service() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
BrowserProcessPlatformPart* ChromeBrowserProcessStub::platform_part() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
extensions::EventRouterForwarder*
ChromeBrowserProcessStub::extension_event_router_forwarder() {
DCHECK(context_initialized_);
return event_router_forwarder_.get();
}
NotificationUIManager* ChromeBrowserProcessStub::notification_ui_manager() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
NotificationPlatformBridge*
ChromeBrowserProcessStub::notification_platform_bridge() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
message_center::MessageCenter* ChromeBrowserProcessStub::message_center() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
policy::BrowserPolicyConnector*
ChromeBrowserProcessStub::browser_policy_connector() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
policy::PolicyService* ChromeBrowserProcessStub::policy_service() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
IconManager* ChromeBrowserProcessStub::icon_manager() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
GpuModeManager* ChromeBrowserProcessStub::gpu_mode_manager() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
GpuProfileCache* ChromeBrowserProcessStub::gpu_profile_cache() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
void ChromeBrowserProcessStub::CreateDevToolsHttpProtocolHandler(
const std::string& ip,
uint16_t port) {
NOTIMPLEMENTED();
NOTREACHED();
}
void ChromeBrowserProcessStub::CreateDevToolsAutoOpener() {
NOTIMPLEMENTED();
NOTREACHED();
}
bool ChromeBrowserProcessStub::IsShuttingDown() {
NOTIMPLEMENTED();
NOTREACHED();
return false;
}
printing::PrintJobManager* ChromeBrowserProcessStub::print_job_manager() {
DCHECK(context_initialized_);
return print_job_manager_.get();
}
printing::PrintPreviewDialogController*
ChromeBrowserProcessStub::print_preview_dialog_controller() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
printing::BackgroundPrintingManager*
ChromeBrowserProcessStub::background_printing_manager() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
IntranetRedirectDetector*
ChromeBrowserProcessStub::intranet_redirect_detector() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
......@@ -211,45 +236,45 @@ void ChromeBrowserProcessStub::SetApplicationLocale(const std::string& locale) {
}
DownloadStatusUpdater* ChromeBrowserProcessStub::download_status_updater() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
DownloadRequestLimiter* ChromeBrowserProcessStub::download_request_limiter() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
BackgroundModeManager* ChromeBrowserProcessStub::background_mode_manager() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
void ChromeBrowserProcessStub::set_background_mode_manager_for_test(
std::unique_ptr<BackgroundModeManager> manager) {
NOTIMPLEMENTED();
NOTREACHED();
}
StatusTray* ChromeBrowserProcessStub::status_tray() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
safe_browsing::SafeBrowsingService*
ChromeBrowserProcessStub::safe_browsing_service() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
safe_browsing::ClientSideDetectionService*
ChromeBrowserProcessStub::safe_browsing_detection_service() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
subresource_filter::RulesetService*
ChromeBrowserProcessStub::subresource_filter_ruleset_service() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
......@@ -259,75 +284,75 @@ void ChromeBrowserProcessStub::StartAutoupdateTimer() {
#endif
net_log::ChromeNetLog* ChromeBrowserProcessStub::net_log() {
NOTIMPLEMENTED();
return NULL;
DCHECK(initialized_);
return net_log_.get();
}
component_updater::ComponentUpdateService*
ChromeBrowserProcessStub::component_updater() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
CRLSetFetcher* ChromeBrowserProcessStub::crl_set_fetcher() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
component_updater::PnaclComponentInstaller*
ChromeBrowserProcessStub::pnacl_component_installer() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
component_updater::SupervisedUserWhitelistInstaller*
ChromeBrowserProcessStub::supervised_user_whitelist_installer() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
MediaFileSystemRegistry*
ChromeBrowserProcessStub::media_file_system_registry() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
bool ChromeBrowserProcessStub::created_local_state() const {
NOTIMPLEMENTED();
NOTREACHED();
return false;
}
#if defined(ENABLE_WEBRTC)
WebRtcLogUploader* ChromeBrowserProcessStub::webrtc_log_uploader() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
#endif
network_time::NetworkTimeTracker*
ChromeBrowserProcessStub::network_time_tracker() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
gcm::GCMDriver* ChromeBrowserProcessStub::gcm_driver() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
shell_integration::DefaultWebClientState
ChromeBrowserProcessStub::CachedDefaultWebClientState() {
NOTIMPLEMENTED();
NOTREACHED();
return shell_integration::UNKNOWN_DEFAULT;
}
memory::TabManager* ChromeBrowserProcessStub::GetTabManager() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
PhysicalWebDataSource* ChromeBrowserProcessStub::GetPhysicalWebDataSource() {
NOTIMPLEMENTED();
NOTREACHED();
return NULL;
}
......
......@@ -33,7 +33,8 @@ class ChromeBrowserProcessStub : public BrowserProcess,
ChromeBrowserProcessStub();
~ChromeBrowserProcessStub() override;
void Initialize();
void Initialize(const base::CommandLine& command_line);
void OnContextInitialized();
void Shutdown();
// BrowserProcess implementation.
......@@ -117,12 +118,14 @@ class ChromeBrowserProcessStub : public BrowserProcess,
private:
bool initialized_;
bool context_initialized_;
bool shutdown_;
std::string locale_;
std::unique_ptr<printing::PrintJobManager> print_job_manager_;
std::unique_ptr<ChromeProfileManagerStub> profile_manager_;
scoped_refptr<extensions::EventRouterForwarder> event_router_forwarder_;
std::unique_ptr<net_log::ChromeNetLog> net_log_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProcessStub);
};
......
......@@ -6,6 +6,25 @@
#include "libcef/browser/chrome_profile_manager_stub.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/content_browser_client.h"
namespace {
// Return the active browser context. This is primarily called from Chrome code
// that handles WebUI views and wishes to associate the view's data with a
// particular context (profile). Chrome stores multiple profiles in sub-
// directories of |user_data_dir| and then uses ProfileManager to track which
// profile (sub-directory name) was last active.
//
// TODO(cef): To most closely match Chrome behavior this should return the
// context for the currently active browser (e.g. the browser with input focus).
// Return the main context for now since we don't currently have a good way to
// determine that.
CefBrowserContextImpl* GetActiveBrowserContext() {
return CefContentBrowserClient::Get()->browser_context().get();
}
} // namespace
ChromeProfileManagerStub::ChromeProfileManagerStub()
: ProfileManager(base::FilePath()) {
......@@ -18,7 +37,15 @@ Profile* ChromeProfileManagerStub::GetProfile(
const base::FilePath& profile_dir) {
scoped_refptr<CefBrowserContextImpl> browser_context =
CefBrowserContextImpl::GetForCachePath(profile_dir);
DCHECK(browser_context);
if (!browser_context) {
// ProfileManager makes assumptions about profile directory paths that do
// not match CEF usage. For example, the default Chrome profile name is
// "Default" so it will append that sub-directory name to an empty
// |user_data_dir| value and then call this method. Use the active context
// in cases such as this where we don't understand what ProfileManager is
// asking for.