]> khamidou — GitHub mirrors - electron.git/commitdiff
Add API to override browser version.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 5 Dec 2013 02:26:01 +0000 (10:26 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 5 Dec 2013 02:26:01 +0000 (10:26 +0800)
browser/api/atom_api_app.cc
browser/api/atom_api_app.h
browser/browser.cc
browser/browser.h
browser/browser_mac.mm
browser/browser_win.cc

index 909bff3950c74c03b19c998e8cfc0bd86f3602af..23c84a5b303814e67c44aba9ab5d27eae2c33a24 100644 (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());
 
index 04b70eb78f91d4c1b8aac22971a4dd4f60c076c6..f5685a77fc5528e1bc810f1ace7976e71f2c82bf 100644 (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);
 
index c4a2d50cdf8faaefe65e18880b4394c1b379c2c7..1bb7e66e3dd8afa96f71bae7db02be67cb970313 100644 (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,
index c715dfe1c6182c828655d66a1c40ea5dfcfb1012..e66076b227c38f0968c52b18d156cbb4b9da4c36 100644 (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);
 };
 
index 95ce57e1d1bd2af71fecd47c5f757d2f3a839978..3d01c94d5db8b0bd80a727a93c0bdc6e3ac24851 100644 (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);
index 1948abff5cb4c4183ee8b60a45d07a6b5eea968f..7256f7e4666a43ea59d721c743ad6e05ef66a798 100644 (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(