2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2012-09-11 00:19:19 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_context.h"
|
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
|
|
|
#include "libcef/browser/browser_main.h"
|
|
|
|
#include "libcef/browser/browser_message_filter.h"
|
|
|
|
#include "libcef/browser/browser_settings.h"
|
|
|
|
#include "libcef/browser/context.h"
|
2012-06-25 23:21:27 +02:00
|
|
|
#include "libcef/browser/resource_dispatcher_host_delegate.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "libcef/common/cef_switches.h"
|
|
|
|
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/file_path.h"
|
2012-09-11 00:19:19 +02:00
|
|
|
#include "base/path_service.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/access_token_store.h"
|
|
|
|
#include "content/public/browser/media_observer.h"
|
2012-04-04 20:18:09 +02:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2012-06-25 23:21:27 +02:00
|
|
|
#include "content/public/browser/resource_dispatcher_host.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
|
|
|
#include "googleurl/src/gurl.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// In-memory store for access tokens used by geolocation.
|
|
|
|
class CefAccessTokenStore : public content::AccessTokenStore {
|
|
|
|
public:
|
|
|
|
CefAccessTokenStore() {}
|
|
|
|
|
|
|
|
virtual void LoadAccessTokens(
|
|
|
|
const LoadAccessTokensCallbackType& callback) OVERRIDE {
|
|
|
|
callback.Run(access_token_set_,
|
|
|
|
_Context->browser_context()->GetRequestContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SaveAccessToken(
|
|
|
|
const GURL& server_url, const string16& access_token) OVERRIDE {
|
|
|
|
access_token_set_[server_url] = access_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AccessTokenSet access_token_set_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
class CefMediaObserver : public content::MediaObserver {
|
|
|
|
public:
|
|
|
|
CefMediaObserver() {}
|
|
|
|
virtual ~CefMediaObserver() {}
|
|
|
|
|
|
|
|
virtual void OnDeleteAudioStream(void* host, int stream_id) OVERRIDE {}
|
|
|
|
|
|
|
|
virtual void OnSetAudioStreamPlaying(void* host, int stream_id,
|
|
|
|
bool playing) OVERRIDE {}
|
|
|
|
virtual void OnSetAudioStreamStatus(void* host, int stream_id,
|
|
|
|
const std::string& status) OVERRIDE {}
|
|
|
|
virtual void OnSetAudioStreamVolume(void* host, int stream_id,
|
|
|
|
double volume) OVERRIDE {}
|
|
|
|
virtual void OnMediaEvent(int render_process_id,
|
|
|
|
const media::MediaLogEvent& event) OVERRIDE {}
|
2012-05-18 17:04:56 +02:00
|
|
|
virtual void OnCaptureDevicesOpened(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const content::MediaStreamDevices& devices) OVERRIDE {}
|
|
|
|
virtual void OnCaptureDevicesClosed(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
|
|
|
const content::MediaStreamDevices& devices) OVERRIDE {}
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CefContentBrowserClient::CefContentBrowserClient()
|
|
|
|
: browser_main_parts_(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CefContentBrowserClient::~CefContentBrowserClient() {
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BrowserMainParts* CefContentBrowserClient::CreateBrowserMainParts(
|
|
|
|
const content::MainFunctionParams& parameters) {
|
2012-04-11 20:00:55 +02:00
|
|
|
browser_main_parts_ = new CefBrowserMainParts(parameters);
|
|
|
|
return browser_main_parts_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentBrowserClient::RenderProcessHostCreated(
|
|
|
|
content::RenderProcessHost* host) {
|
|
|
|
host->GetChannel()->AddFilter(new CefBrowserMessageFilter(host));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefContentBrowserClient::AppendExtraCommandLineSwitches(
|
|
|
|
CommandLine* command_line, int child_process_id) {
|
2012-09-10 18:13:51 +02:00
|
|
|
const CommandLine& browser_cmd = *CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
{
|
|
|
|
// Propagate the following switches to all command lines (along with any
|
|
|
|
// associated values) if present in the browser command line.
|
|
|
|
static const char* const kSwitchNames[] = {
|
|
|
|
switches::kLogFile,
|
|
|
|
switches::kLogSeverity,
|
|
|
|
};
|
|
|
|
command_line->CopySwitchesFrom(browser_cmd, kSwitchNames,
|
|
|
|
arraysize(kSwitchNames));
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string process_type =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
if (process_type == switches::kRendererProcess) {
|
2012-09-10 18:13:51 +02:00
|
|
|
// Propagate the following switches to the renderer command line (along with
|
|
|
|
// any associated values) if present in the browser command line.
|
|
|
|
static const char* const kSwitchNames[] = {
|
|
|
|
switches::kProductVersion,
|
|
|
|
switches::kLocale,
|
|
|
|
switches::kResourcesDirPath,
|
|
|
|
switches::kLocalesDirPath,
|
|
|
|
switches::kPackLoadingDisabled,
|
|
|
|
};
|
|
|
|
command_line->CopySwitchesFrom(browser_cmd, kSwitchNames,
|
|
|
|
arraysize(kSwitchNames));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
content::MediaObserver* CefContentBrowserClient::GetMediaObserver() {
|
|
|
|
// TODO(cef): Return NULL once it's supported. See crbug.com/116113.
|
|
|
|
if (!media_observer_.get())
|
|
|
|
media_observer_.reset(new CefMediaObserver());
|
|
|
|
return media_observer_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::AccessTokenStore* CefContentBrowserClient::CreateAccessTokenStore() {
|
|
|
|
return new CefAccessTokenStore;
|
|
|
|
}
|
|
|
|
|
2012-06-25 23:21:27 +02:00
|
|
|
void CefContentBrowserClient::ResourceDispatcherHostCreated() {
|
|
|
|
resource_dispatcher_host_delegate_.reset(
|
|
|
|
new CefResourceDispatcherHostDelegate());
|
|
|
|
content::ResourceDispatcherHost::Get()->SetDelegate(
|
|
|
|
resource_dispatcher_host_delegate_.get());
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContentBrowserClient::OverrideWebkitPrefs(
|
|
|
|
content::RenderViewHost* rvh,
|
|
|
|
const GURL& url,
|
2012-05-18 17:04:56 +02:00
|
|
|
webkit_glue::WebPreferences* prefs) {
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForHost(rvh);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(browser.get());
|
|
|
|
|
|
|
|
// Populate WebPreferences based on CefBrowserSettings.
|
|
|
|
BrowserToWebSettings(browser->settings(), *prefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CefContentBrowserClient::GetDefaultDownloadName() {
|
|
|
|
return "download";
|
|
|
|
}
|
2012-09-11 00:19:19 +02:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
const wchar_t* CefContentBrowserClient::GetResourceDllName() {
|
|
|
|
static wchar_t file_path[MAX_PATH+1] = {0};
|
|
|
|
|
|
|
|
if (file_path[0] == 0) {
|
|
|
|
// Retrieve the module path (usually libcef.dll).
|
|
|
|
FilePath module;
|
|
|
|
PathService::Get(base::FILE_MODULE, &module);
|
|
|
|
const std::wstring wstr = module.value();
|
|
|
|
size_t count = std::min(static_cast<size_t>(MAX_PATH), wstr.size());
|
|
|
|
wcsncpy(file_path, wstr.c_str(), count);
|
|
|
|
file_path[count] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file_path;
|
|
|
|
}
|
|
|
|
#endif // defined(OS_WIN)
|