Merge revision 845 changes:

- Add about:version, about:credits and about:license internal URLs (issue #731).
- Centralize retrieval of the CEF major version number from a new VERSION file.

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1271@846 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-10-08 17:48:20 +00:00
parent c5bb1d019a
commit 4c4206604d
25 changed files with 1377 additions and 633 deletions

1
cef3/VERSION Normal file
View File

@ -0,0 +1 @@
CEF_MAJOR=3

View File

@ -10,7 +10,7 @@
'revision': '<!(python tools/revision.py)', 'revision': '<!(python tools/revision.py)',
# Need to be creative to match dylib version formatting requirements. # Need to be creative to match dylib version formatting requirements.
'version_mac_dylib': 'version_mac_dylib':
'<!(python ../chrome/tools/build/version.py -f ../chrome/VERSION -t "3<(revision).@BUILD_HI@.@BUILD_LO@" -e "BUILD_HI=int(BUILD)/256" -e "BUILD_LO=int(BUILD)%256")', '<!(python ../chrome/tools/build/version.py -f VERSION -f ../chrome/VERSION -t "@CEF_MAJOR@<(revision).@BUILD_HI@.@BUILD_LO@" -e "BUILD_HI=int(BUILD)/256" -e "BUILD_LO=int(BUILD)%256")',
}, },
'includes': [ 'includes': [
# Bring in the source file lists. # Bring in the source file lists.
@ -792,6 +792,8 @@
'libcef/browser/browser_settings.h', 'libcef/browser/browser_settings.h',
'libcef/browser/browser_urlrequest_impl.cc', 'libcef/browser/browser_urlrequest_impl.cc',
'libcef/browser/browser_urlrequest_impl.h', 'libcef/browser/browser_urlrequest_impl.h',
'libcef/browser/chrome_scheme_handler.cc',
'libcef/browser/chrome_scheme_handler.h',
'libcef/browser/content_browser_client.cc', 'libcef/browser/content_browser_client.cc',
'libcef/browser/content_browser_client.h', 'libcef/browser/content_browser_client.h',
'libcef/browser/context.cc', 'libcef/browser/context.cc',
@ -810,6 +812,8 @@
'libcef/browser/download_manager_delegate.h', 'libcef/browser/download_manager_delegate.h',
'libcef/browser/frame_host_impl.cc', 'libcef/browser/frame_host_impl.cc',
'libcef/browser/frame_host_impl.h', 'libcef/browser/frame_host_impl.h',
'libcef/browser/internal_scheme_handler.cc',
'libcef/browser/internal_scheme_handler.h',
'libcef/browser/javascript_dialog.h', 'libcef/browser/javascript_dialog.h',
'libcef/browser/javascript_dialog_creator.cc', 'libcef/browser/javascript_dialog_creator.cc',
'libcef/browser/javascript_dialog_creator.h', 'libcef/browser/javascript_dialog_creator.h',
@ -830,6 +834,8 @@
'libcef/browser/resource_request_job.cc', 'libcef/browser/resource_request_job.cc',
'libcef/browser/resource_request_job.h', 'libcef/browser/resource_request_job.h',
'libcef/browser/scheme_impl.cc', 'libcef/browser/scheme_impl.cc',
'libcef/browser/scheme_registration.cc',
'libcef/browser/scheme_registration.h',
'libcef/browser/sqlite_diagnostics_stub.cc', 'libcef/browser/sqlite_diagnostics_stub.cc',
'libcef/browser/stream_impl.cc', 'libcef/browser/stream_impl.cc',
'libcef/browser/stream_impl.h', 'libcef/browser/stream_impl.h',

View File

@ -12,6 +12,7 @@
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/devtools_delegate.h" #include "libcef/browser/devtools_delegate.h"
#include "libcef/browser/navigate_params.h" #include "libcef/browser/navigate_params.h"
#include "libcef/browser/scheme_registration.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h" #include "libcef/browser/url_request_context_getter.h"
#include "libcef/browser/url_request_context_getter_proxy.h" #include "libcef/browser/url_request_context_getter_proxy.h"
@ -1223,6 +1224,10 @@ void CefBrowserHostImpl::DidFinishLoad(
CefRefPtr<CefFrame> frame = GetOrCreateFrame(frame_id, CefRefPtr<CefFrame> frame = GetOrCreateFrame(frame_id,
CefFrameHostImpl::kUnspecifiedFrameId, is_main_frame, string16(), CefFrameHostImpl::kUnspecifiedFrameId, is_main_frame, string16(),
validated_url); validated_url);
// Give internal scheme handlers an opportunity to update content.
scheme::DidFinishLoad(frame, validated_url);
OnLoadEnd(frame, validated_url); OnLoadEnd(frame, validated_url);
} }

View File

@ -0,0 +1,344 @@
// Copyright (c) 2012 The Chromium Embedded Framework 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/chrome_scheme_handler.h"
#include <map>
#include <string>
#include "include/cef_version.h"
#include "include/cef_web_plugin.h"
#include "libcef/browser/context.h"
#include "libcef/browser/internal_scheme_handler.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "content/public/common/content_client.h"
#include "grit/cef_resources.h"
#include "v8/include/v8.h"
#include "webkit/user_agent/user_agent_util.h"
namespace scheme {
const char kChromeScheme[] = "chrome";
const char kChromeURL[] = "chrome://";
namespace {
const char kChromeCreditsDomain[] = "credits";
const char kChromeLicenseDomain[] = "license";
const char kChromeVersionDomain[] = "version";
enum ChromeDomain {
CHROME_UNKNOWN = 0,
CHROME_CREDITS,
CHROME_LICENSE,
CHROME_VERSION,
};
ChromeDomain GetChromeDomain(const std::string& domain_name) {
static struct {
const char* name;
ChromeDomain domain;
} domains[] = {
{ kChromeCreditsDomain, CHROME_CREDITS },
{ kChromeLicenseDomain, CHROME_LICENSE },
{ kChromeVersionDomain, CHROME_VERSION },
};
for (size_t i = 0; i < sizeof(domains) / sizeof(domains[0]); ++i) {
if (base::strcasecmp(domains[i].name, domain_name.c_str()) == 0)
return domains[i].domain;
}
return CHROME_UNKNOWN;
}
std::string GetOSType() {
#if defined(OS_WIN)
return "Windows";
#elif defined(OS_MACOSX)
return "Mac OS X";
#elif defined(OS_CHROMEOS)
return "Chromium OS";
#elif defined(OS_ANDROID)
return "Android";
#elif defined(OS_LINUX)
return "Linux";
#elif defined(OS_FREEBSD)
return "FreeBSD";
#elif defined(OS_OPENBSD)
return "OpenBSD";
#elif defined(OS_SOLARIS)
return "Solaris";
#else
return "Unknown";
#endif
}
std::string GetCommandLine() {
#if defined(OS_WIN)
return WideToUTF8(CommandLine::ForCurrentProcess()->GetCommandLineString());
#elif defined(OS_POSIX)
std::string command_line = "";
typedef std::vector<std::string> ArgvList;
const ArgvList& argv = CommandLine::ForCurrentProcess()->argv();
for (ArgvList::const_iterator iter = argv.begin(); iter != argv.end(); iter++)
command_line += " " + *iter;
// TODO(viettrungluu): |command_line| could really have any encoding, whereas
// below we assumes it's UTF-8.
return command_line;
#endif
}
std::string GetModulePath() {
FilePath path;
if (PathService::Get(base::FILE_MODULE, &path))
return CefString(path.value());
return std::string();
}
class TemplateParser {
public:
TemplateParser()
: ident_start_("$$"),
ident_end_("$$") {
}
TemplateParser(const std::string& ident_start,
const std::string& ident_end)
: ident_start_(ident_start),
ident_end_(ident_end) {
}
void Add(const std::string& key, const std::string& value) {
values_.insert(std::make_pair(key, value));
}
void Parse(std::string* tmpl) {
int start_pos, end_pos = 0;
int ident_start_len = ident_start_.length();
int ident_end_len = ident_end_.length();
while(true) {
start_pos = tmpl->find(ident_start_, end_pos);
if (start_pos >= 0) {
end_pos = tmpl->find(ident_end_, start_pos + ident_start_len);
if (end_pos >= 0) {
// Found an identifier. Check if a substitution exists.
std::string key = tmpl->substr(start_pos + ident_start_len,
end_pos - start_pos - ident_start_len);
KeyMap::const_iterator it = values_.find(key);
if (it != values_.end()) {
// Peform the substitution.
tmpl->replace(start_pos, end_pos + ident_end_len - start_pos,
it->second);
end_pos = start_pos + it->second.length();
} else {
// Leave the unknown identifier in place.
end_pos += ident_end_len;
}
if (end_pos >= static_cast<int>(tmpl->length()) - ident_start_len -
ident_end_len) {
// Not enough room remaining for more identifiers.
break;
}
} else {
// No end identifier found.
break;
}
} else {
// No start identifier found.
break;
}
}
}
private:
typedef std::map<std::string, std::string> KeyMap;
KeyMap values_;
std::string ident_start_;
std::string ident_end_;
};
class Delegate : public InternalHandlerDelegate {
public:
Delegate() {}
virtual bool OnRequest(CefRefPtr<CefRequest> request,
Action* action) OVERRIDE {
GURL url = GURL(request->GetURL().ToString());
std::string path = url.path();
if (path.length() > 0)
path = path.substr(1);
bool handled = false;
ChromeDomain domain = GetChromeDomain(url.host());
switch (domain) {
case CHROME_CREDITS:
handled = OnCredits(path, action);
break;
case CHROME_LICENSE:
handled = OnLicense(action);
break;
case CHROME_VERSION:
handled = OnVersion(action);
break;
default:
break;
}
if (!handled && domain != CHROME_VERSION) {
action->redirect_url =
GURL(std::string(kChromeURL) + kChromeVersionDomain);
}
return true;
}
bool OnCredits(const std::string& path, Action* action) {
if (path == "credits.js") {
action->resource_id = IDR_CEF_CREDITS_JS;
} else if (path == "swiftshader.jpg") {
action->resource_id = IDR_CEF_CREDITS_SWIFTSHADER_JPG;
} else {
action->mime_type = "text/html";
action->resource_id = IDR_CEF_CREDITS_HTML;
}
return true;
}
bool OnLicense(Action* action) {
base::StringPiece piece = content::GetContentClient()->GetDataResource(
IDR_CEF_LICENSE_TXT, ui::SCALE_FACTOR_NONE);
if (piece.empty()) {
NOTREACHED() << "Failed to load license txt resource.";
return false;
}
std::string html = "<html><head><title>License</title></head><body><pre>" +
piece.as_string() + "</pre></body></html>";
action->mime_type = "text/html";
action->stream = CefStreamReader::CreateForData(
const_cast<char*>(html.c_str()), html.length());
action->stream_size = html.length();
return true;
}
bool OnVersion(Action* action) {
base::StringPiece piece = content::GetContentClient()->GetDataResource(
IDR_CEF_VERSION_HTML, ui::SCALE_FACTOR_NONE);
if (piece.empty()) {
NOTREACHED() << "Failed to load version html resource.";
return false;
}
TemplateParser parser;
parser.Add("YEAR", MAKE_STRING(COPYRIGHT_YEAR));
parser.Add("CEF",
base::StringPrintf("%d.%d.%d",
CEF_VERSION_MAJOR,
CHROME_VERSION_BUILD,
CEF_REVISION));
parser.Add("CHROMIUM",
base::StringPrintf("%d.%d.%d.%d",
CHROME_VERSION_MAJOR,
CHROME_VERSION_MINOR,
CHROME_VERSION_BUILD,
CHROME_VERSION_PATCH));
parser.Add("OS", GetOSType());
parser.Add("WEBKIT",
base::StringPrintf("%d.%d",
webkit_glue::GetWebKitMajorVersion(),
webkit_glue::GetWebKitMinorVersion()));
parser.Add("JAVASCRIPT", v8::V8::GetVersion());
parser.Add("FLASH", std::string()); // Value populated asynchronously.
parser.Add("USERAGENT", content::GetUserAgent(GURL()));
parser.Add("COMMANDLINE", GetCommandLine());
parser.Add("MODULEPATH", GetModulePath());
parser.Add("CACHEPATH", CefString(_Context->cache_path().value()));
std::string tmpl = piece.as_string();
parser.Parse(&tmpl);
action->mime_type = "text/html";
action->stream = CefStreamReader::CreateForData(
const_cast<char*>(tmpl.c_str()), tmpl.length());
action->stream_size = tmpl.length();
return true;
}
};
void DidFinishChromeVersionLoad(CefRefPtr<CefFrame> frame) {
// Retieve Flash version information and update asynchronously.
class Visitor : public CefWebPluginInfoVisitor {
public:
Visitor(CefRefPtr<CefFrame> frame)
: frame_(frame) {
}
virtual bool Visit(CefRefPtr<CefWebPluginInfo> info,
int count, int total) OVERRIDE {
std::string name = info->GetName();
if (name == "Shockwave Flash") {
if (frame_->IsValid()) {
std::string version = info->GetVersion();
frame_->ExecuteJavaScript(
"document.getElementById('flash').innerText = '" + version + "';",
std::string(), 0);
}
return false;
}
return true;
}
private:
CefRefPtr<CefFrame> frame_;
IMPLEMENT_REFCOUNTING(Visitor);
};
CefVisitWebPluginInfo(new Visitor(frame));
}
} // namespace
void RegisterChromeHandler() {
CefRegisterSchemeHandlerFactory(
kChromeScheme,
std::string(),
CreateInternalHandlerFactory(
make_scoped_ptr<InternalHandlerDelegate>(new Delegate())));
}
bool WillHandleBrowserAboutURL(GURL* url,
content::BrowserContext* browser_context) {
std::string text = url->possibly_invalid_spec();
if (text.find("about:") == 0 && text != "about:blank" && text.length() > 6) {
// Redirect about: URLs to chrome://
*url = GURL(kChromeURL + text.substr(6));
}
// Allow the redirection to proceed.
return false;
}
void DidFinishChromeLoad(CefRefPtr<CefFrame> frame,
const GURL& validated_url) {
ChromeDomain domain = GetChromeDomain(validated_url.host());
switch (domain) {
case CHROME_VERSION:
DidFinishChromeVersionLoad(frame);
default:
break;
}
}
} // namespace scheme

View File

@ -0,0 +1,35 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_CHROME_SCHEME_HANDLER_H_
#define CEF_LIBCEF_BROWSER_CHROME_SCHEME_HANDLER_H_
#pragma once
#include <string>
#include "include/cef_frame.h"
#include "googleurl/src/gurl.h"
namespace content {
class BrowserContext;
}
namespace scheme {
extern const char kChromeScheme[];
extern const char kChromeURL[];
// Register the chrome scheme handler.
void RegisterChromeHandler();
// Used to redirect about: URLs to chrome: URLs.
bool WillHandleBrowserAboutURL(GURL* url,
content::BrowserContext* browser_context);
// Used to fire any asynchronous content updates.
void DidFinishChromeLoad(CefRefPtr<CefFrame> frame,
const GURL& validated_url);
} // namespace scheme
#endif // CEF_LIBCEF_BROWSER_CHROME_SCHEME_HANDLER_H_

View File

@ -11,6 +11,7 @@
#include "libcef/browser/browser_main.h" #include "libcef/browser/browser_main.h"
#include "libcef/browser/browser_message_filter.h" #include "libcef/browser/browser_message_filter.h"
#include "libcef/browser/browser_settings.h" #include "libcef/browser/browser_settings.h"
#include "libcef/browser/chrome_scheme_handler.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/resource_dispatcher_host_delegate.h" #include "libcef/browser/resource_dispatcher_host_delegate.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
@ -23,6 +24,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "content/browser/plugin_service_impl.h" #include "content/browser/plugin_service_impl.h"
#include "content/public/browser/access_token_store.h" #include "content/public/browser/access_token_store.h"
#include "content/public/browser/browser_url_handler.h"
#include "content/public/browser/media_observer.h" #include "content/public/browser/media_observer.h"
#include "content/public/browser/plugin_service_filter.h" #include "content/public/browser/plugin_service_filter.h"
#include "content/public/browser/quota_permission_context.h" #include "content/public/browser/quota_permission_context.h"
@ -328,6 +330,13 @@ void CefContentBrowserClient::OverrideWebkitPrefs(
BrowserToWebSettings(browser->settings(), *prefs); BrowserToWebSettings(browser->settings(), *prefs);
} }
void CefContentBrowserClient::BrowserURLHandlerCreated(
content::BrowserURLHandler* handler) {
// Used to redirect about: URLs to chrome: URLs.
handler->AddHandlerPair(&scheme::WillHandleBrowserAboutURL,
content::BrowserURLHandler::null_handler());
}
std::string CefContentBrowserClient::GetDefaultDownloadName() { std::string CefContentBrowserClient::GetDefaultDownloadName() {
return "download"; return "download";
} }

View File

@ -46,6 +46,8 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh, virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh,
const GURL& url, const GURL& url,
webkit_glue::WebPreferences* prefs) OVERRIDE; webkit_glue::WebPreferences* prefs) OVERRIDE;
virtual void BrowserURLHandlerCreated(
content::BrowserURLHandler* handler) OVERRIDE;
virtual std::string GetDefaultDownloadName() OVERRIDE; virtual std::string GetDefaultDownloadName() OVERRIDE;
#if defined(OS_WIN) #if defined(OS_WIN)
const wchar_t* GetResourceDllName() OVERRIDE; const wchar_t* GetResourceDllName() OVERRIDE;

View File

@ -8,7 +8,7 @@
#include "libcef/browser/browser_main.h" #include "libcef/browser/browser_main.h"
#include "libcef/browser/browser_message_loop.h" #include "libcef/browser/browser_message_loop.h"
#include "libcef/browser/content_browser_client.h" #include "libcef/browser/content_browser_client.h"
#include "libcef/browser/devtools_scheme_handler.h" #include "libcef/browser/scheme_registration.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/main_delegate.h" #include "libcef/common/main_delegate.h"
@ -359,8 +359,8 @@ CefDevToolsDelegate* CefContext::devtools_delegate() const {
void CefContext::OnContextInitialized() { void CefContext::OnContextInitialized() {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
// Perform DevTools scheme registration. // Register internal scheme handlers.
RegisterDevToolsSchemeHandler(); scheme::RegisterInternalHandlers();
// Notify the handler. // Notify the handler.
CefRefPtr<CefApp> app = application(); CefRefPtr<CefApp> app = application();

View File

@ -124,7 +124,7 @@ bool CefDevToolsDelegate::BundlesFrontendResources() {
} }
std::string CefDevToolsDelegate::GetFrontendResourcesBaseURL() { std::string CefDevToolsDelegate::GetFrontendResourcesBaseURL() {
return kChromeDevToolsURL; return scheme::kChromeDevToolsURL;
} }
std::string CefDevToolsDelegate::GetDevToolsURL(content::RenderViewHost* rvh, std::string CefDevToolsDelegate::GetDevToolsURL(content::RenderViewHost* rvh,
@ -140,7 +140,7 @@ std::string CefDevToolsDelegate::GetDevToolsURL(content::RenderViewHost* rvh,
std::string page_id = binding_->GetIdentifier(rvh); std::string page_id = binding_->GetIdentifier(rvh);
std::string host = http_scheme ? std::string host = http_scheme ?
base::StringPrintf("http://localhost:%d/devtools/", port) : base::StringPrintf("http://localhost:%d/devtools/", port) :
kChromeDevToolsURL; scheme::kChromeDevToolsURL;
return base::StringPrintf( return base::StringPrintf(
"%sdevtools.html?ws=localhost:%d/devtools/page/%s", "%sdevtools.html?ws=localhost:%d/devtools/page/%s",

View File

@ -1,25 +1,14 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved. // reserved. Use of this source code is governed by a BSD-style license that can
// Use of this source code is governed by a BSD-style license that can be // be found in the LICENSE file.
// found in the LICENSE file.
#include "libcef/browser/devtools_scheme_handler.h" #include "libcef/browser/devtools_scheme_handler.h"
#include <string> #include <string>
#include "libcef/browser/internal_scheme_handler.h"
#include "include/cef_browser.h"
#include "include/cef_request.h"
#include "include/cef_resource_handler.h"
#include "include/cef_response.h"
#include "include/cef_scheme.h"
#include "include/cef_stream.h"
#include "include/cef_url.h"
#include "base/file_util.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "content/public/common/content_client.h"
#include "grit/devtools_resources_map.h" #include "grit/devtools_resources_map.h"
#include "ui/base/resource/resource_bundle.h"
namespace scheme {
const char kChromeDevToolsScheme[] = "chrome-devtools"; const char kChromeDevToolsScheme[] = "chrome-devtools";
const char kChromeDevToolsHost[] = "devtools"; const char kChromeDevToolsHost[] = "devtools";
@ -27,119 +16,37 @@ const char kChromeDevToolsURL[] = "chrome-devtools://devtools/";
namespace { namespace {
static std::string PathWithoutParams(const std::string& path) { class Delegate : public InternalHandlerDelegate {
size_t query_position = path.find("?");
if (query_position != std::string::npos)
return path.substr(0, query_position);
return path;
}
static std::string GetMimeType(const std::string& filename) {
if (EndsWith(filename, ".html", false)) {
return "text/html";
} else if (EndsWith(filename, ".css", false)) {
return "text/css";
} else if (EndsWith(filename, ".js", false)) {
return "application/javascript";
} else if (EndsWith(filename, ".png", false)) {
return "image/png";
} else if (EndsWith(filename, ".gif", false)) {
return "image/gif";
}
NOTREACHED();
return "text/plain";
}
class DevToolsSchemeHandler : public CefResourceHandler {
public: public:
DevToolsSchemeHandler(const std::string& path, Delegate() {}
CefRefPtr<CefStreamReader> reader,
int size)
: path_(path), reader_(reader), size_(size) {
}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request, virtual bool OnRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback) Action* action) OVERRIDE {
OVERRIDE { GURL url = GURL(request->GetURL().ToString());
callback->Continue(); std::string path = url.path();
if (path.length() > 0)
path = path.substr(1);
for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) {
if (base::strcasecmp(kDevtoolsResources[i].name,
path.c_str()) == 0) {
action->resource_id = kDevtoolsResources[i].value;
return true; return true;
} }
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE {
response_length = size_;
response->SetMimeType(GetMimeType(path_));
response->SetStatus(200);
} }
virtual bool ReadResponse(void* data_out, return false;
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefCallback> callback)
OVERRIDE {
bytes_read = reader_->Read(data_out, 1, bytes_to_read);
return (bytes_read > 0);
} }
virtual void Cancel() OVERRIDE {
}
private:
std::string path_;
CefRefPtr<CefStreamReader> reader_;
int size_;
IMPLEMENT_REFCOUNTING(DevToolSSchemeHandler);
};
class DevToolsSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
DevToolsSchemeHandlerFactory() {}
virtual CefRefPtr<CefResourceHandler> Create(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request) OVERRIDE {
std::string url = PathWithoutParams(request->GetURL());
const char* path = &url.c_str()[strlen(kChromeDevToolsURL)];
int size = -1;
CefRefPtr<CefStreamReader> reader = GetStreamReader(path, size);
if (!reader.get())
return NULL;
return new DevToolsSchemeHandler(path, reader, size);
}
CefRefPtr<CefStreamReader> GetStreamReader(const char* path, int& size) {
// Create a stream for the grit resource.
for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) {
if (base::strcasecmp(kDevtoolsResources[i].name, path) == 0) {
base::StringPiece piece =
content::GetContentClient()->GetDataResource(
kDevtoolsResources[i].value, ui::SCALE_FACTOR_NONE);
if (!piece.empty()) {
size = piece.size();
return CefStreamReader::CreateForData(const_cast<char*>(piece.data()),
size);
}
}
}
NOTREACHED() << "Missing DevTools resource: " << path;
return NULL;
}
IMPLEMENT_REFCOUNTING(DevToolSSchemeHandlerFactory);
}; };
} // namespace } // namespace
// Register the DevTools scheme handler. void RegisterChromeDevToolsHandler() {
void RegisterDevToolsSchemeHandler() { CefRegisterSchemeHandlerFactory(
CefRegisterSchemeHandlerFactory(kChromeDevToolsScheme, kChromeDevToolsHost, kChromeDevToolsScheme,
new DevToolsSchemeHandlerFactory()); kChromeDevToolsHost,
CreateInternalHandlerFactory(
make_scoped_ptr<InternalHandlerDelegate>(new Delegate())));
} }
} // namespace scheme

View File

@ -6,11 +6,15 @@
#define CEF_LIBCEF_BROWSER_DEVTOOLS_SCHEME_HANDLER_H_ #define CEF_LIBCEF_BROWSER_DEVTOOLS_SCHEME_HANDLER_H_
#pragma once #pragma once
namespace scheme {
extern const char kChromeDevToolsScheme[]; extern const char kChromeDevToolsScheme[];
extern const char kChromeDevToolsHost[]; extern const char kChromeDevToolsHost[];
extern const char kChromeDevToolsURL[]; extern const char kChromeDevToolsURL[];
// Register the DevTools scheme handler. // Register the chrome-devtools scheme handler.
void RegisterDevToolsSchemeHandler(); void RegisterChromeDevToolsHandler();
} // namespace scheme
#endif // CEF_LIBCEF_BROWSER_DEVTOOLS_SCHEME_HANDLER_H_ #endif // CEF_LIBCEF_BROWSER_DEVTOOLS_SCHEME_HANDLER_H_

View File

@ -0,0 +1,178 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
// Portions 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/internal_scheme_handler.h"
#include <string>
#include "base/string_util.h"
#include "content/public/common/content_client.h"
#include "ui/base/resource/resource_bundle.h"
namespace scheme {
namespace {
static std::string GetMimeType(const std::string& filename) {
if (EndsWith(filename, ".html", false)) {
return "text/html";
} else if (EndsWith(filename, ".css", false)) {
return "text/css";
} else if (EndsWith(filename, ".jpg", false)) {
return "image/jpeg";
} else if (EndsWith(filename, ".js", false)) {
return "application/javascript";
} else if (EndsWith(filename, ".png", false)) {
return "image/png";
} else if (EndsWith(filename, ".gif", false)) {
return "image/gif";
}
NOTREACHED() << "No known mime type for file: " << filename.c_str();
return "text/plain";
}
class RedirectHandler : public CefResourceHandler {
public:
explicit RedirectHandler(const GURL& url)
: url_(url) {
}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback) OVERRIDE {
callback->Continue();
return true;
}
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE {
response_length = 0;
redirectUrl = url_.spec();
}
virtual bool ReadResponse(void* data_out,
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefCallback> callback) OVERRIDE {
return false;
}
virtual void Cancel() OVERRIDE {
}
private:
GURL url_;
IMPLEMENT_REFCOUNTING(RedirectHandler);
};
class InternalHandler : public CefResourceHandler {
public:
InternalHandler(const std::string& mime_type,
CefRefPtr<CefStreamReader> reader,
int size)
: mime_type_(mime_type),
reader_(reader),
size_(size) {
}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback) OVERRIDE {
callback->Continue();
return true;
}
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE {
response_length = size_;
response->SetMimeType(mime_type_);
response->SetStatus(200);
}
virtual bool ReadResponse(void* data_out,
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefCallback> callback) OVERRIDE {
bytes_read = reader_->Read(data_out, 1, bytes_to_read);
return (bytes_read > 0);
}
virtual void Cancel() OVERRIDE {
}
private:
std::string mime_type_;
CefRefPtr<CefStreamReader> reader_;
int size_;
IMPLEMENT_REFCOUNTING(InternalHandler);
};
class InternalHandlerFactory : public CefSchemeHandlerFactory {
public:
explicit InternalHandlerFactory(
scoped_ptr<InternalHandlerDelegate> delegate)
: delegate_(delegate.Pass()) {
}
virtual CefRefPtr<CefResourceHandler> Create(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request) OVERRIDE {
GURL url = GURL(request->GetURL().ToString());
InternalHandlerDelegate::Action action;
if (delegate_->OnRequest(request, &action)) {
if (!action.redirect_url.is_empty() && action.redirect_url.is_valid())
return new RedirectHandler(action.redirect_url);
if (action.mime_type.empty())
action.mime_type = GetMimeType(url.path());
if (action.resource_id >= 0) {
base::StringPiece piece = content::GetContentClient()->GetDataResource(
action.resource_id, ui::SCALE_FACTOR_NONE);
if (!piece.empty()) {
action.stream =
CefStreamReader::CreateForData(const_cast<char*>(piece.data()),
piece.size());
action.stream_size = piece.size();
} else {
NOTREACHED() << "Failed to load internal resource for id: " <<
action.resource_id << " URL: " << url.spec().c_str();
return NULL;
}
}
if (action.stream.get()) {
return new InternalHandler(action.mime_type, action.stream,
action.stream_size);
}
}
return NULL;
}
private:
scoped_ptr<InternalHandlerDelegate> delegate_;
IMPLEMENT_REFCOUNTING(InternalHandlerFactory);
};
} // namespace
InternalHandlerDelegate::Action::Action()
: stream_size(-1),
resource_id(-1) {
}
CefRefPtr<CefSchemeHandlerFactory> CreateInternalHandlerFactory(
scoped_ptr<InternalHandlerDelegate> delegate) {
DCHECK(delegate.get());
return new InternalHandlerFactory(delegate.Pass());
}
} // namespace scheme

View File

@ -0,0 +1,53 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_INTERNAL_SCHEME_HANDLER_H_
#define CEF_LIBCEF_BROWSER_INTERNAL_SCHEME_HANDLER_H_
#pragma once
#include <string>
#include "include/cef_scheme.h"
#include "base/memory/scoped_ptr.h"
#include "googleurl/src/gurl.h"
namespace scheme {
// All methods will be called on the browser process IO thread.
class InternalHandlerDelegate {
public:
class Action {
public:
Action();
// Set to the appropriate value or leave empty to have it determined based
// on the file extension.
std::string mime_type;
// Option 1: Provide a stream for the resource contents. Set |stream_size|
// to the stream size or to -1 if unknown.
CefRefPtr<CefStreamReader> stream;
int stream_size;
// Option 2: Specify a resource id to load static content.
int resource_id;
// Option 3: Redirect to the specified URL.
GURL redirect_url;
};
virtual ~InternalHandlerDelegate() {}
// Populate |action| and return true if the request was handled.
virtual bool OnRequest(CefRefPtr<CefRequest> request,
Action* action) = 0;
};
// Create an internal scheme handler factory. The factory will take ownership of
// |delegate|.
CefRefPtr<CefSchemeHandlerFactory> CreateInternalHandlerFactory(
scoped_ptr<InternalHandlerDelegate> delegate);
} // namespace scheme
#endif // CEF_LIBCEF_BROWSER_INTERNAL_SCHEME_HANDLER_H_

View File

@ -10,8 +10,8 @@
#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h" #include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/devtools_scheme_handler.h"
#include "libcef/browser/resource_request_job.h" #include "libcef/browser/resource_request_job.h"
#include "libcef/browser/scheme_registration.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_context_getter.h" #include "libcef/browser/url_request_context_getter.h"
#include "libcef/common/request_impl.h" #include "libcef/common/request_impl.h"
@ -310,8 +310,8 @@ bool CefClearSchemeHandlerFactories() {
if (CEF_CURRENTLY_ON(CEF_IOT)) { if (CEF_CURRENTLY_ON(CEF_IOT)) {
CefUrlRequestManager::GetInstance()->ClearFactories(); CefUrlRequestManager::GetInstance()->ClearFactories();
// Re-register the DevTools scheme handler. // Register internal scheme handlers.
RegisterDevToolsSchemeHandler(); scheme::RegisterInternalHandlers();
} else { } else {
CEF_POST_TASK(CEF_IOT, CEF_POST_TASK(CEF_IOT,
base::Bind(base::IgnoreResult(&CefClearSchemeHandlerFactories))); base::Bind(base::IgnoreResult(&CefClearSchemeHandlerFactories)));

View File

@ -0,0 +1,44 @@
// Copyright (c) 2012 The Chromium Embedded Framework 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/scheme_registration.h"
#include "libcef/browser/chrome_scheme_handler.h"
#include "libcef/browser/devtools_scheme_handler.h"
#include "libcef/renderer/content_renderer_client.h"
namespace scheme {
void AddStandardSchemes(std::vector<std::string>* standard_schemes) {
static struct {
const char* name;
bool is_local;
bool is_display_isolated;
} schemes[] = {
{ scheme::kChromeScheme, true, true },
{ scheme::kChromeDevToolsScheme, true, false }
};
for (size_t i = 0; i < sizeof(schemes) / sizeof(schemes[0]); ++i)
standard_schemes->push_back(schemes[i].name);
if (CefContentRendererClient::Get()) {
// Running in single-process mode. Register the schemes with WebKit.
for (size_t i = 0; i < sizeof(schemes) / sizeof(schemes[0]); ++i) {
CefContentRendererClient::Get()->AddCustomScheme(
schemes[i].name, schemes[i].is_local, schemes[i].is_display_isolated);
}
}
}
void RegisterInternalHandlers() {
scheme::RegisterChromeHandler();
scheme::RegisterChromeDevToolsHandler();
}
void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url) {
if (validated_url.scheme() == scheme::kChromeScheme)
scheme::DidFinishChromeLoad(frame, validated_url);
}
} // namespace scheme

View File

@ -0,0 +1,27 @@
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_SCHEME_IMPL_H_
#define CEF_LIBCEF_BROWSER_SCHEME_IMPL_H_
#pragma once
#include <string>
#include <vector>
#include "include/cef_frame.h"
#include "googleurl/src/gurl.h"
namespace scheme {
// Add all standard schemes.
void AddStandardSchemes(std::vector<std::string>* standard_schemes);
// Register all internal scheme handlers.
void RegisterInternalHandlers();
// Used to fire any asynchronous content updates.
void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url);
} // namespace scheme
#endif // CEF_LIBCEF_BROWSER_SCHEME_IMPL_H_

View File

@ -5,10 +5,9 @@
#include "libcef/common/content_client.h" #include "libcef/common/content_client.h"
#include "include/cef_stream.h" #include "include/cef_stream.h"
#include "include/cef_version.h" #include "include/cef_version.h"
#include "libcef/browser/devtools_scheme_handler.h" #include "libcef/browser/scheme_registration.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
#include "libcef/common/scheme_registrar_impl.h" #include "libcef/common/scheme_registrar_impl.h"
#include "libcef/renderer/content_renderer_client.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
@ -54,12 +53,7 @@ void CefContentClient::AddAdditionalSchemes(
DCHECK(schemeRegistrar->VerifyRefCount()); DCHECK(schemeRegistrar->VerifyRefCount());
} }
standard_schemes->push_back(kChromeDevToolsScheme); scheme::AddStandardSchemes(standard_schemes);
if (CefContentRendererClient::Get()) {
// Register the DevTools scheme with WebKit.
CefContentRendererClient::Get()->AddCustomScheme(kChromeDevToolsScheme,
true, false);
}
} }
std::string CefContentClient::GetUserAgent() const { std::string CefContentClient::GetUserAgent() const {

View File

@ -0,0 +1,123 @@
<!DOCTYPE HTML>
<!--
about:version template page
-->
<html id="t" i18n-values="dir:textdirection;">
<head>
<title>About Version</title>
<style>/* 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. */
body {
background-color: white;
color: black;
font-family: Helvetica,Arial,sans-serif;
margin: 0;
}
#outer {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
width: 820px;
}
#inner {
padding-top: 10px;
width: 550px;
}
.label {
-webkit-padding-end: 5px;
font-size: 0.9em;
font-weight: bold;
text-align: end;
white-space: nowrap;
}
.label:after {
content: ':';
}
#logo {
float: right;
margin-left: 40px;
text-align: right;
width: 200px;
}
#company {
font-size: 0.7em;
text-align: right;
}
#copyright {
font-size: 0.7em;
text-align: right;
}
.value {
font-family: monospace;
max-width: 430px;
padding-left: 5px;
}
</style>
</head>
<body>
<div id="outer">
<div id="logo">
<div id="company">Chromium Embedded Framework (CEF)</div>
<div id="copyright">Copyright &copy; $$YEAR$$ The Chromium Embedded Framework Authors.<br/>All rights reserved.<br/><a href="chrome://license">license</a> | <a href="chrome://credits">credits</a></div>
</div>
<table id="inner" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="label" valign="top">CEF</td>
<td class="value">$$CEF$$</td>
</tr>
<tr>
<td class="label" valign="top">Chromium</td>
<td class="value">$$CHROMIUM$$</td>
</tr>
<tr>
<td class="label" valign="top">OS</td>
<td class="value">$$OS$$</td>
</tr>
<tr>
<td class="label" valign="top">WebKit</td>
<td class="value">$$WEBKIT$$</td>
</tr>
<tr>
<td class="label" valign="top">JavaScript</td>
<td class="value">$$JAVASCRIPT$$</td>
</tr>
<tr><td class="label" valign="top">Flash</td>
<td class="value" id="flash">$$FLASH$$</td>
</tr>
<tr>
<td class="label" valign="top">User Agent</td>
<td class="value">$$USERAGENT$$</td>
</tr>
<tr>
<td class="label" valign="top">Command Line</td>
<td class="value">$$COMMANDLINE$$</td>
</tr>
<tr>
<td class="label" valign="top">Module Path</td>
<td class="value">$$MODULEPATH$$</td>
</tr>
<tr>
<td class="label" valign="top">Cache Path</td>
<td class="value">$$CACHEPATH$$</td>
</tr>
</table>
</div>
</body>
</html>

View File

@ -10,6 +10,11 @@
<release seq="1"> <release seq="1">
<includes> <includes>
<include name="IDR_CEF_DEVTOOLS_DISCOVERY_PAGE" file="devtools_discovery_page.html" type="BINDATA" /> <include name="IDR_CEF_DEVTOOLS_DISCOVERY_PAGE" file="devtools_discovery_page.html" type="BINDATA" />
<include name="IDR_CEF_CREDITS_HTML" file="..\..\..\chrome\browser\resources\about_credits.html" type="BINDATA" />
<include name="IDR_CEF_CREDITS_JS" file="..\..\..\chrome\browser\resources\about_credits.js" type="BINDATA" />
<include name="IDR_CEF_CREDITS_SWIFTSHADER_JPG" file="..\..\..\chrome\browser\resources\swiftshader.jpg" type="BINDATA" />
<include name="IDR_CEF_LICENSE_TXT" file="..\..\LICENSE.txt" type="BINDATA" />
<include name="IDR_CEF_VERSION_HTML" file="about_version.html" type="BINDATA" />
</includes> </includes>
</release> </release>
</grit> </grit>

View File

@ -95,8 +95,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,CHROME_VERSION_BUILD,CEF_REVISION,0 FILEVERSION CEF_VERSION_MAJOR,CHROME_VERSION_BUILD,CEF_REVISION,0
PRODUCTVERSION 3,CHROME_VERSION_BUILD,CEF_REVISION,0 PRODUCTVERSION CEF_VERSION_MAJOR,CHROME_VERSION_BUILD,CEF_REVISION,0
FILEFLAGSMASK 0x17L FILEFLAGSMASK 0x17L
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -112,12 +112,12 @@ BEGIN
BLOCK "040904b0" BLOCK "040904b0"
BEGIN BEGIN
VALUE "FileDescription", "Chromium Embedded Framework (CEF) Dynamic Link Library" VALUE "FileDescription", "Chromium Embedded Framework (CEF) Dynamic Link Library"
VALUE "FileVersion", "3." MAKE_STRING(CHROME_VERSION_BUILD) "." MAKE_STRING(CEF_REVISION) VALUE "FileVersion", MAKE_STRING(CEF_VERSION_MAJOR) "." MAKE_STRING(CHROME_VERSION_BUILD) "." MAKE_STRING(CEF_REVISION)
VALUE "InternalName", "libcef" VALUE "InternalName", "libcef"
VALUE "LegalCopyright", "Copyright (C) " MAKE_STRING(COPYRIGHT_YEAR) " The Chromium Embedded Framework Authors" VALUE "LegalCopyright", "Copyright (C) " MAKE_STRING(COPYRIGHT_YEAR) " The Chromium Embedded Framework Authors"
VALUE "OriginalFilename", "libcef.dll" VALUE "OriginalFilename", "libcef.dll"
VALUE "ProductName", "Chromium Embedded Framework (CEF) Dynamic Link Library" VALUE "ProductName", "Chromium Embedded Framework (CEF) Dynamic Link Library"
VALUE "ProductVersion", "3." MAKE_STRING(CHROME_VERSION_BUILD) "." MAKE_STRING(CEF_REVISION) VALUE "ProductVersion", MAKE_STRING(CEF_VERSION_MAJOR) "." MAKE_STRING(CHROME_VERSION_BUILD) "." MAKE_STRING(CEF_REVISION)
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -109,3 +109,11 @@ def make_dir(name, quiet = True):
def get_files(search_glob): def get_files(search_glob):
""" Returns all files matching the search glob. """ """ Returns all files matching the search glob. """
return iglob(search_glob) return iglob(search_glob)
def read_version_file(file, args):
""" Read and parse a version file (key=value pairs, one per line). """
lines = read_file(file).split("\n")
for line in lines:
parts = line.split('=', 1)
if len(parts) == 2:
args[parts[0]] = parts[1]

View File

@ -16,7 +16,8 @@ RunAction(cef_dir, gyper)
print "\nGenerating CEF version header file..." print "\nGenerating CEF version header file..."
gyper = [ 'python', 'tools/make_version_header.py', gyper = [ 'python', 'tools/make_version_header.py',
'--header', 'include/cef_version.h', '--header', 'include/cef_version.h',
'--version', '../chrome/VERSION' ] '--cef_version', 'VERSION',
'--chrome_version', '../chrome/VERSION' ]
RunAction(cef_dir, gyper) RunAction(cef_dir, gyper)
print "\nPatching build configuration and source files for CEF..." print "\nPatching build configuration and source files for CEF..."

View File

@ -175,15 +175,12 @@ chromium_rev = chromium_info['revision']
date = get_date() date = get_date()
# Read and parse the version file (key=value pairs, one per line) # Read and parse the version file (key=value pairs, one per line)
chrome = {} args = {}
lines = read_file(os.path.join(cef_dir, '../chrome/VERSION')).split("\n") read_version_file('VERSION', args)
for line in lines: read_version_file('../chrome/VERSION', args)
parts = line.split('=', 1)
if len(parts) == 2:
chrome[parts[0]] = parts[1]
cef_ver = '3.'+chrome['BUILD']+'.'+cef_rev cef_ver = args['CEF_MAJOR']+'.'+args['BUILD']+'.'+cef_rev
chromium_ver = chrome['MAJOR']+'.'+chrome['MINOR']+'.'+chrome['BUILD']+'.'+chrome['PATCH'] chromium_ver = args['MAJOR']+'.'+args['MINOR']+'.'+args['BUILD']+'.'+args['PATCH']
# Test the operating system. # Test the operating system.
platform = ''; platform = '';

View File

@ -1,2 +1,2 @@
@echo off @echo off
..\third_party\python_26\python.exe tools\make_version_header.py --header include\cef_version.h --version ../chrome/VERSION ..\third_party\python_26\python.exe tools\make_version_header.py --header include\cef_version.h --cef_version VERSION --chrome_version ../chrome/VERSION

View File

@ -23,7 +23,9 @@ This utility creates the version header file.
parser = OptionParser(description=disc) parser = OptionParser(description=disc)
parser.add_option('--header', dest='header', metavar='FILE', parser.add_option('--header', dest='header', metavar='FILE',
help='output version header file [required]') help='output version header file [required]')
parser.add_option('--version', dest='version', metavar='FILE', parser.add_option('--cef_version', dest='cef_version', metavar='FILE',
help='input CEF version config file [required]')
parser.add_option('--chrome_version', dest='chrome_version', metavar='FILE',
help='input Chrome version config file [required]') help='input Chrome version config file [required]')
parser.add_option('-q', '--quiet', parser.add_option('-q', '--quiet',
action='store_true', dest='quiet', default=False, action='store_true', dest='quiet', default=False,
@ -31,24 +33,22 @@ parser.add_option('-q', '--quiet',
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
# the header option is required # the header option is required
if options.header is None or options.version is None: if options.header is None or options.cef_version is None or options.chrome_version is None:
parser.print_help(sys.stdout) parser.print_help(sys.stdout)
sys.exit() sys.exit()
def write_svn_header(header, version): def write_svn_header(header, chrome_version, cef_version):
""" Creates the header file for the current revision and Chrome version information """ Creates the header file for the current revision and Chrome version information
if the information has changed or if the file doesn't already exist. """ if the information has changed or if the file doesn't already exist. """
if not path_exists(version): if not path_exists(chrome_version):
raise Exception('Version file '+version+' does not exist.') raise Exception('Chrome version file '+chrome_version+' does not exist.')
if not path_exists(cef_version):
raise Exception('CEF version file '+cef_version+' does not exist.')
# Read and parse the version file (key=value pairs, one per line) args = {}
chrome = {} read_version_file(chrome_version, args)
lines = read_file(version).split("\n") read_version_file(cef_version, args)
for line in lines:
parts = line.split('=', 1)
if len(parts) == 2:
chrome[parts[0]] = parts[1]
if path_exists(header): if path_exists(header):
oldcontents = read_file(header) oldcontents = read_file(header)
@ -97,12 +97,13 @@ def write_svn_header(header, version):
'//\n\n'+\ '//\n\n'+\
'#ifndef CEF_INCLUDE_CEF_VERSION_H_\n'+\ '#ifndef CEF_INCLUDE_CEF_VERSION_H_\n'+\
'#define CEF_INCLUDE_CEF_VERSION_H_\n\n'+\ '#define CEF_INCLUDE_CEF_VERSION_H_\n\n'+\
'#define CEF_VERSION_MAJOR ' + args['CEF_MAJOR'] + '\n'+\
'#define CEF_REVISION ' + revision + '\n'+\ '#define CEF_REVISION ' + revision + '\n'+\
'#define COPYRIGHT_YEAR ' + year + '\n\n'+\ '#define COPYRIGHT_YEAR ' + year + '\n\n'+\
'#define CHROME_VERSION_MAJOR ' + chrome['MAJOR'] + '\n'+\ '#define CHROME_VERSION_MAJOR ' + args['MAJOR'] + '\n'+\
'#define CHROME_VERSION_MINOR ' + chrome['MINOR'] + '\n'+\ '#define CHROME_VERSION_MINOR ' + args['MINOR'] + '\n'+\
'#define CHROME_VERSION_BUILD ' + chrome['BUILD'] + '\n'+\ '#define CHROME_VERSION_BUILD ' + args['BUILD'] + '\n'+\
'#define CHROME_VERSION_PATCH ' + chrome['PATCH'] + '\n\n'+\ '#define CHROME_VERSION_PATCH ' + args['PATCH'] + '\n\n'+\
'#define DO_MAKE_STRING(p) #p\n'+\ '#define DO_MAKE_STRING(p) #p\n'+\
'#define MAKE_STRING(p) DO_MAKE_STRING(p)\n\n'+\ '#define MAKE_STRING(p) DO_MAKE_STRING(p)\n\n'+\
'#ifndef APSTUDIO_HIDDEN_SYMBOLS\n\n'\ '#ifndef APSTUDIO_HIDDEN_SYMBOLS\n\n'\
@ -125,7 +126,7 @@ def write_svn_header(header, version):
return False return False
written = write_svn_header(options.header, options.version) written = write_svn_header(options.header, options.chrome_version, options.cef_version)
if not options.quiet: if not options.quiet:
if written: if written:
sys.stdout.write('File '+options.header+' updated.\n') sys.stdout.write('File '+options.header+' updated.\n')