Add API to override browser version.

This commit is contained in:
Cheng Zhao 2013-12-05 10:26:01 +08:00
parent 02bbf07d3a
commit 420ae1a2cc
6 changed files with 40 additions and 3 deletions

View file

@ -108,6 +108,19 @@ v8::Handle<v8::Value> App::GetVersion(const v8::Arguments &args) {
return v8::String::New(version.data(), version.size());
}
// static
v8::Handle<v8::Value> App::SetVersion(const v8::Arguments &args) {
v8::HandleScope scope;
std::string version;
if (!FromV8Arguments(args, &version))
return node::ThrowError("Bad argument");
Browser::Get()->SetVersion(version);
return v8::Undefined();
}
// static
v8::Handle<v8::Value> App::AppendSwitch(const v8::Arguments &args) {
v8::HandleScope scope;
@ -190,6 +203,7 @@ void App::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "terminate", Terminate);
NODE_SET_PROTOTYPE_METHOD(t, "focus", Focus);
NODE_SET_PROTOTYPE_METHOD(t, "getVersion", GetVersion);
NODE_SET_PROTOTYPE_METHOD(t, "setVersion", SetVersion);
target->Set(v8::String::NewSymbol("Application"), t->GetFunction());

View file

@ -40,6 +40,7 @@ class App : public EventEmitter,
static v8::Handle<v8::Value> Terminate(const v8::Arguments &args);
static v8::Handle<v8::Value> Focus(const v8::Arguments &args);
static v8::Handle<v8::Value> GetVersion(const v8::Arguments &args);
static v8::Handle<v8::Value> SetVersion(const v8::Arguments &args);
static v8::Handle<v8::Value> AppendSwitch(const v8::Arguments &args);
static v8::Handle<v8::Value> AppendArgument(const v8::Arguments &args);

View file

@ -33,6 +33,20 @@ void Browser::Quit() {
window_list->CloseAllWindows();
}
std::string Browser::GetVersion() const {
if (version_override_.empty()) {
std::string version = GetExecutableFileVersion();
if (!version.empty())
return version;
}
return version_override_;
}
void Browser::SetVersion(const std::string& version) {
version_override_ = version;
}
bool Browser::OpenFile(const std::string& file_path) {
bool prevent_default = false;
FOR_EACH_OBSERVER(BrowserObserver,

View file

@ -31,7 +31,10 @@ class Browser : public WindowListObserver {
void Focus();
// Returns the version of the executable (or bundle).
std::string GetVersion();
std::string GetVersion() const;
// Overrides the application version.
void SetVersion(const std::string& version);
#if defined(OS_MACOSX)
// Bounce the dock icon.
@ -68,6 +71,9 @@ class Browser : public WindowListObserver {
bool is_quiting() const { return is_quiting_; }
protected:
// Returns the version of application bundle or executable file.
std::string GetExecutableFileVersion() const;
// Send the will-quit message and then terminate the application.
void NotifyAndTerminate();
@ -84,6 +90,8 @@ class Browser : public WindowListObserver {
// Observers of the browser.
ObserverList<BrowserObserver> observers_;
std::string version_override_;
DISALLOW_COPY_AND_ASSIGN(Browser);
};

View file

@ -19,7 +19,7 @@ void Browser::Focus() {
[[AtomApplication sharedApplication] activateIgnoringOtherApps:YES];
}
std::string Browser::GetVersion() {
std::string Browser::GetExecutableFileVersion() const {
NSDictionary* infoDictionary = base::mac::OuterBundle().infoDictionary;
NSString *version = [infoDictionary objectForKey:@"CFBundleVersion"];
return base::SysNSStringToUTF8(version);

View file

@ -43,7 +43,7 @@ void Browser::Focus() {
EnumWindows(&WindowsEnumerationHandler, reinterpret_cast<LPARAM>(&pid));
}
std::string Browser::GetVersion() {
std::string Browser::GetExecutableFileVersion() const {
base::FilePath path;
if (PathService::Get(base::FILE_EXE, &path)) {
scoped_ptr<FileVersionInfo> version_info(