| 
									
										
										
										
											2014-10-31 11:17:05 -07:00
										 |  |  | // Copyright (c) 2013 GitHub, Inc.
 | 
					
						
							| 
									
										
										
										
											2014-04-25 17:49:37 +08:00
										 |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							| 
									
										
										
										
											2013-05-03 00:05:09 +08:00
										 |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/api/atom_api_app.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-03 00:05:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-16 18:12:00 -04:00
										 |  |  | #include <memory>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 09:13:06 +08:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2014-08-13 14:24:35 +02:00
										 |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2014-03-16 09:13:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 15:39:44 +08:00
										 |  |  | #include "base/command_line.h"
 | 
					
						
							| 
									
										
										
										
											2014-08-12 17:01:56 +02:00
										 |  |  | #include "base/environment.h"
 | 
					
						
							|  |  |  | #include "base/files/file_path.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  | #include "base/files/file_util.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  | #include "base/optional.h"
 | 
					
						
							| 
									
										
										
										
											2014-08-12 17:01:56 +02:00
										 |  |  | #include "base/path_service.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-09 12:14:47 -08:00
										 |  |  | #include "base/system/sys_info.h"
 | 
					
						
							| 
									
										
										
										
											2017-02-17 14:03:46 +05:30
										 |  |  | #include "chrome/browser/browser_process.h"
 | 
					
						
							| 
									
										
										
										
											2016-11-03 00:27:16 +05:30
										 |  |  | #include "chrome/browser/icon_manager.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-13 13:05:16 +08:00
										 |  |  | #include "chrome/common/chrome_paths.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-05 10:38:55 +05:30
										 |  |  | #include "content/browser/gpu/compositor_util.h"        // nogncheck
 | 
					
						
							|  |  |  | #include "content/browser/gpu/gpu_data_manager_impl.h"  // nogncheck
 | 
					
						
							| 
									
										
										
										
											2016-07-11 14:04:56 -07:00
										 |  |  | #include "content/public/browser/browser_accessibility_state.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-27 11:09:27 -07:00
										 |  |  | #include "content/public/browser/browser_child_process_host.h"
 | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | #include "content/public/browser/child_process_data.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-11 20:52:07 +05:30
										 |  |  | #include "content/public/browser/client_certificate_delegate.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-25 20:28:07 +08:00
										 |  |  | #include "content/public/browser/gpu_data_manager.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-18 10:39:25 +08:00
										 |  |  | #include "content/public/browser/render_frame_host.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-07 12:15:48 +08:00
										 |  |  | #include "content/public/common/content_switches.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-07 16:15:30 +05:30
										 |  |  | #include "media/audio/audio_manager.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  | #include "net/ssl/client_cert_identity.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-11 20:52:07 +05:30
										 |  |  | #include "net/ssl/ssl_cert_request_info.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-14 17:07:49 -07:00
										 |  |  | #include "services/service_manager/sandbox/switches.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/api/atom_api_menu.h"
 | 
					
						
							|  |  |  | #include "shell/browser/api/atom_api_session.h"
 | 
					
						
							|  |  |  | #include "shell/browser/api/atom_api_web_contents.h"
 | 
					
						
							|  |  |  | #include "shell/browser/api/gpuinfo_manager.h"
 | 
					
						
							|  |  |  | #include "shell/browser/atom_browser_context.h"
 | 
					
						
							|  |  |  | #include "shell/browser/atom_browser_main_parts.h"
 | 
					
						
							|  |  |  | #include "shell/browser/atom_paths.h"
 | 
					
						
							|  |  |  | #include "shell/browser/login_handler.h"
 | 
					
						
							|  |  |  | #include "shell/browser/relauncher.h"
 | 
					
						
							|  |  |  | #include "shell/common/application_info.h"
 | 
					
						
							|  |  |  | #include "shell/common/atom_command_line.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | #include "shell/common/gin_converters/callback_converter.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_converters/file_path_converter.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_converters/gurl_converter.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_converters/image_converter.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_converters/net_converter.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-31 16:56:00 +09:00
										 |  |  | #include "shell/common/gin_converters/value_converter.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-09 00:10:18 +09:00
										 |  |  | #include "shell/common/gin_helper/dictionary.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | #include "shell/common/gin_helper/object_template_builder.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/common/node_includes.h"
 | 
					
						
							|  |  |  | #include "shell/common/options_switches.h"
 | 
					
						
							| 
									
										
										
										
											2016-01-24 08:30:14 +09:00
										 |  |  | #include "ui/gfx/image/image.h"
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-29 15:13:46 +08:00
										 |  |  | #if defined(OS_WIN)
 | 
					
						
							|  |  |  | #include "base/strings/utf_string_conversions.h"
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/ui/win/jump_list.h"
 | 
					
						
							| 
									
										
										
										
											2015-04-29 15:13:46 +08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-01 00:37:12 +10:00
										 |  |  | #if defined(OS_MACOSX)
 | 
					
						
							| 
									
										
										
										
											2018-11-20 21:33:23 +01:00
										 |  |  | #include <CoreFoundation/CoreFoundation.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/ui/cocoa/atom_bundle_mover.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-01 00:37:12 +10:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | using electron::Browser; | 
					
						
							| 
									
										
										
										
											2014-04-17 17:13:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | namespace gin { | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 17:35:51 +08:00
										 |  |  | #if defined(OS_WIN)
 | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | struct Converter<electron::ProcessIntegrityLevel> { | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |   static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |                                    electron::ProcessIntegrityLevel value) { | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |     switch (value) { | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |       case electron::ProcessIntegrityLevel::Untrusted: | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |         return StringToV8(isolate, "untrusted"); | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |       case electron::ProcessIntegrityLevel::Low: | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |         return StringToV8(isolate, "low"); | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |       case electron::ProcessIntegrityLevel::Medium: | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |         return StringToV8(isolate, "medium"); | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |       case electron::ProcessIntegrityLevel::High: | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |         return StringToV8(isolate, "high"); | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |       default: | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |         return StringToV8(isolate, "unknown"); | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | struct Converter<Browser::UserTask> { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  |                      Browser::UserTask* out) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary dict; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  |     if (!ConvertFromV8(isolate, val, &dict)) | 
					
						
							|  |  |  |       return false; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:26:44 +08:00
										 |  |  |     if (!dict.Get("program", &(out->program)) || | 
					
						
							|  |  |  |         !dict.Get("title", &(out->title))) | 
					
						
							|  |  |  |       return false; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:35:51 +08:00
										 |  |  |     if (dict.Get("iconPath", &(out->icon_path)) && | 
					
						
							|  |  |  |         !dict.Get("iconIndex", &(out->icon_index))) | 
					
						
							|  |  |  |       return false; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:26:44 +08:00
										 |  |  |     dict.Get("arguments", &(out->arguments)); | 
					
						
							|  |  |  |     dict.Get("description", &(out->description)); | 
					
						
							| 
									
										
										
										
											2019-05-13 18:17:12 +02:00
										 |  |  |     dict.Get("workingDirectory", &(out->working_dir)); | 
					
						
							| 
									
										
										
										
											2014-11-17 17:26:44 +08:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | using electron::JumpListCategory; | 
					
						
							|  |  |  | using electron::JumpListItem; | 
					
						
							|  |  |  | using electron::JumpListResult; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | struct Converter<JumpListItem::Type> { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |                      JumpListItem::Type* out) { | 
					
						
							|  |  |  |     std::string item_type; | 
					
						
							|  |  |  |     if (!ConvertFromV8(isolate, val, &item_type)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (item_type == "task") | 
					
						
							|  |  |  |       *out = JumpListItem::Type::TASK; | 
					
						
							|  |  |  |     else if (item_type == "separator") | 
					
						
							|  |  |  |       *out = JumpListItem::Type::SEPARATOR; | 
					
						
							|  |  |  |     else if (item_type == "file") | 
					
						
							|  |  |  |       *out = JumpListItem::Type::FILE; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                                    JumpListItem::Type val) { | 
					
						
							|  |  |  |     std::string item_type; | 
					
						
							|  |  |  |     switch (val) { | 
					
						
							|  |  |  |       case JumpListItem::Type::TASK: | 
					
						
							|  |  |  |         item_type = "task"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListItem::Type::SEPARATOR: | 
					
						
							|  |  |  |         item_type = "separator"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListItem::Type::FILE: | 
					
						
							|  |  |  |         item_type = "file"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     return gin::ConvertToV8(isolate, item_type); | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | struct Converter<JumpListItem> { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |                      JumpListItem* out) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary dict; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |     if (!ConvertFromV8(isolate, val, &dict)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!dict.Get("type", &(out->type))) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (out->type) { | 
					
						
							|  |  |  |       case JumpListItem::Type::TASK: | 
					
						
							|  |  |  |         if (!dict.Get("program", &(out->path)) || | 
					
						
							|  |  |  |             !dict.Get("title", &(out->title))) | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (dict.Get("iconPath", &(out->icon_path)) && | 
					
						
							|  |  |  |             !dict.Get("iconIndex", &(out->icon_index))) | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dict.Get("args", &(out->arguments)); | 
					
						
							|  |  |  |         dict.Get("description", &(out->description)); | 
					
						
							| 
									
										
										
										
											2019-05-13 18:17:12 +02:00
										 |  |  |         dict.Get("workingDirectory", &(out->working_dir)); | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListItem::Type::SEPARATOR: | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListItem::Type::FILE: | 
					
						
							|  |  |  |         return dict.Get("path", &(out->path)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert(false); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                                    const JumpListItem& val) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |     dict.Set("type", val.type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (val.type) { | 
					
						
							|  |  |  |       case JumpListItem::Type::TASK: | 
					
						
							|  |  |  |         dict.Set("program", val.path); | 
					
						
							|  |  |  |         dict.Set("args", val.arguments); | 
					
						
							|  |  |  |         dict.Set("title", val.title); | 
					
						
							|  |  |  |         dict.Set("iconPath", val.icon_path); | 
					
						
							|  |  |  |         dict.Set("iconIndex", val.icon_index); | 
					
						
							|  |  |  |         dict.Set("description", val.description); | 
					
						
							| 
									
										
										
										
											2019-05-13 18:17:12 +02:00
										 |  |  |         dict.Set("workingDirectory", val.working_dir); | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListItem::Type::SEPARATOR: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListItem::Type::FILE: | 
					
						
							|  |  |  |         dict.Set("path", val.path); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return dict.GetHandle(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | struct Converter<JumpListCategory::Type> { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |                      JumpListCategory::Type* out) { | 
					
						
							|  |  |  |     std::string category_type; | 
					
						
							|  |  |  |     if (!ConvertFromV8(isolate, val, &category_type)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (category_type == "tasks") | 
					
						
							|  |  |  |       *out = JumpListCategory::Type::TASKS; | 
					
						
							|  |  |  |     else if (category_type == "frequent") | 
					
						
							|  |  |  |       *out = JumpListCategory::Type::FREQUENT; | 
					
						
							|  |  |  |     else if (category_type == "recent") | 
					
						
							|  |  |  |       *out = JumpListCategory::Type::RECENT; | 
					
						
							|  |  |  |     else if (category_type == "custom") | 
					
						
							|  |  |  |       *out = JumpListCategory::Type::CUSTOM; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                                    JumpListCategory::Type val) { | 
					
						
							|  |  |  |     std::string category_type; | 
					
						
							|  |  |  |     switch (val) { | 
					
						
							|  |  |  |       case JumpListCategory::Type::TASKS: | 
					
						
							|  |  |  |         category_type = "tasks"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListCategory::Type::FREQUENT: | 
					
						
							|  |  |  |         category_type = "frequent"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListCategory::Type::RECENT: | 
					
						
							|  |  |  |         category_type = "recent"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListCategory::Type::CUSTOM: | 
					
						
							|  |  |  |         category_type = "custom"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     return gin::ConvertToV8(isolate, category_type); | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | struct Converter<JumpListCategory> { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |                      JumpListCategory* out) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary dict; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |     if (!ConvertFromV8(isolate, val, &dict)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (dict.Get("name", &(out->name)) && out->name.empty()) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!dict.Get("type", &(out->type))) { | 
					
						
							|  |  |  |       if (out->name.empty()) | 
					
						
							|  |  |  |         out->type = JumpListCategory::Type::TASKS; | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         out->type = JumpListCategory::Type::CUSTOM; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((out->type == JumpListCategory::Type::TASKS) || | 
					
						
							|  |  |  |         (out->type == JumpListCategory::Type::CUSTOM)) { | 
					
						
							|  |  |  |       if (!dict.Get("items", &(out->items))) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | struct Converter<JumpListResult> { | 
					
						
							|  |  |  |   static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) { | 
					
						
							|  |  |  |     std::string result_code; | 
					
						
							|  |  |  |     switch (val) { | 
					
						
							|  |  |  |       case JumpListResult::SUCCESS: | 
					
						
							|  |  |  |         result_code = "ok"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListResult::ARGUMENT_ERROR: | 
					
						
							|  |  |  |         result_code = "argumentError"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListResult::GENERIC_ERROR: | 
					
						
							|  |  |  |         result_code = "error"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR: | 
					
						
							|  |  |  |         result_code = "invalidSeparatorError"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR: | 
					
						
							|  |  |  |         result_code = "fileTypeRegistrationError"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR: | 
					
						
							|  |  |  |         result_code = "customCategoryAccessDeniedError"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ConvertToV8(isolate, result_code); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:35:51 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2016-07-07 16:29:09 -07:00
										 |  |  | struct Converter<Browser::LoginItemSettings> { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2016-07-07 16:29:09 -07:00
										 |  |  |                      Browser::LoginItemSettings* out) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary dict; | 
					
						
							| 
									
										
										
										
											2016-07-07 16:29:09 -07:00
										 |  |  |     if (!ConvertFromV8(isolate, val, &dict)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dict.Get("openAtLogin", &(out->open_at_login)); | 
					
						
							|  |  |  |     dict.Get("openAsHidden", &(out->open_as_hidden)); | 
					
						
							| 
									
										
										
										
											2017-01-30 14:01:40 -08:00
										 |  |  |     dict.Get("path", &(out->path)); | 
					
						
							|  |  |  |     dict.Get("args", &(out->args)); | 
					
						
							| 
									
										
										
										
											2016-07-07 16:29:09 -07:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                                    Browser::LoginItemSettings val) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); | 
					
						
							| 
									
										
										
										
											2016-07-07 16:29:09 -07:00
										 |  |  |     dict.Set("openAtLogin", val.open_at_login); | 
					
						
							|  |  |  |     dict.Set("openAsHidden", val.open_as_hidden); | 
					
						
							|  |  |  |     dict.Set("restoreState", val.restore_state); | 
					
						
							| 
									
										
										
										
											2016-07-07 16:29:58 -07:00
										 |  |  |     dict.Set("wasOpenedAtLogin", val.opened_at_login); | 
					
						
							|  |  |  |     dict.Set("wasOpenedAsHidden", val.opened_as_hidden); | 
					
						
							| 
									
										
										
										
											2016-07-07 16:29:09 -07:00
										 |  |  |     return dict.GetHandle(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | template <> | 
					
						
							| 
									
										
										
										
											2016-11-30 16:30:03 +09:00
										 |  |  | struct Converter<content::CertificateRequestResultType> { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static bool FromV8(v8::Isolate* isolate, | 
					
						
							|  |  |  |                      v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2016-11-30 16:30:03 +09:00
										 |  |  |                      content::CertificateRequestResultType* out) { | 
					
						
							|  |  |  |     bool b; | 
					
						
							|  |  |  |     if (!ConvertFromV8(isolate, val, &b)) | 
					
						
							|  |  |  |       return false; | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |     *out = b ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE | 
					
						
							|  |  |  |              : content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; | 
					
						
							| 
									
										
										
										
											2016-11-30 16:30:03 +09:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | }  // namespace gin
 | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | namespace electron { | 
					
						
							| 
									
										
										
										
											2013-05-03 00:05:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace api { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 21:26:45 +08:00
										 |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 12:29:18 +05:30
										 |  |  | IconLoader::IconSize GetIconSizeByString(const std::string& size) { | 
					
						
							| 
									
										
										
										
											2016-11-03 21:23:40 +03:00
										 |  |  |   if (size == "small") { | 
					
						
							|  |  |  |     return IconLoader::IconSize::SMALL; | 
					
						
							|  |  |  |   } else if (size == "large") { | 
					
						
							|  |  |  |     return IconLoader::IconSize::LARGE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return IconLoader::IconSize::NORMAL; | 
					
						
							| 
									
										
										
										
											2016-11-03 21:43:53 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-11-03 21:23:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-18 17:52:15 -08:00
										 |  |  | // Return the path constant from string.
 | 
					
						
							|  |  |  | int GetPathConstant(const std::string& name) { | 
					
						
							|  |  |  |   if (name == "appData") | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |     return DIR_APP_DATA; | 
					
						
							| 
									
										
										
										
											2015-01-18 17:52:15 -08:00
										 |  |  |   else if (name == "userData") | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |     return DIR_USER_DATA; | 
					
						
							| 
									
										
										
										
											2015-01-18 21:09:42 -08:00
										 |  |  |   else if (name == "cache") | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |     return DIR_CACHE; | 
					
						
							| 
									
										
										
										
											2015-01-18 21:09:42 -08:00
										 |  |  |   else if (name == "userCache") | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |     return DIR_USER_CACHE; | 
					
						
							| 
									
										
										
										
											2017-08-03 15:50:56 -07:00
										 |  |  |   else if (name == "logs") | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |     return DIR_APP_LOGS; | 
					
						
							| 
									
										
										
										
											2015-01-18 18:01:58 -08:00
										 |  |  |   else if (name == "home") | 
					
						
							|  |  |  |     return base::DIR_HOME; | 
					
						
							| 
									
										
										
										
											2015-01-18 21:31:09 -08:00
										 |  |  |   else if (name == "temp") | 
					
						
							|  |  |  |     return base::DIR_TEMP; | 
					
						
							| 
									
										
										
										
											2015-11-13 13:05:16 +08:00
										 |  |  |   else if (name == "userDesktop" || name == "desktop") | 
					
						
							| 
									
										
										
										
											2015-01-18 21:31:09 -08:00
										 |  |  |     return base::DIR_USER_DESKTOP; | 
					
						
							|  |  |  |   else if (name == "exe") | 
					
						
							|  |  |  |     return base::FILE_EXE; | 
					
						
							|  |  |  |   else if (name == "module") | 
					
						
							|  |  |  |     return base::FILE_MODULE; | 
					
						
							| 
									
										
										
										
											2015-11-13 13:05:16 +08:00
										 |  |  |   else if (name == "documents") | 
					
						
							|  |  |  |     return chrome::DIR_USER_DOCUMENTS; | 
					
						
							|  |  |  |   else if (name == "downloads") | 
					
						
							|  |  |  |     return chrome::DIR_DEFAULT_DOWNLOADS; | 
					
						
							|  |  |  |   else if (name == "music") | 
					
						
							|  |  |  |     return chrome::DIR_USER_MUSIC; | 
					
						
							|  |  |  |   else if (name == "pictures") | 
					
						
							|  |  |  |     return chrome::DIR_USER_PICTURES; | 
					
						
							|  |  |  |   else if (name == "videos") | 
					
						
							|  |  |  |     return chrome::DIR_USER_VIDEOS; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:37:27 -04:00
										 |  |  |   else if (name == "pepperFlashSystemPlugin") | 
					
						
							|  |  |  |     return chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN; | 
					
						
							| 
									
										
										
										
											2015-01-18 17:52:15 -08:00
										 |  |  |   else | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 16:24:35 +08:00
										 |  |  | bool NotificationCallbackWrapper( | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |     const base::RepeatingCallback< | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  |         void(const base::CommandLine::StringVector& command_line, | 
					
						
							|  |  |  |              const base::FilePath& current_directory)>& callback, | 
					
						
							| 
									
										
										
										
											2015-10-22 19:02:21 +08:00
										 |  |  |     const base::CommandLine::StringVector& cmd, | 
					
						
							| 
									
										
										
										
											2015-10-22 17:12:09 +08:00
										 |  |  |     const base::FilePath& cwd) { | 
					
						
							|  |  |  |   // Make sure the callback is called after app gets ready.
 | 
					
						
							|  |  |  |   if (Browser::Get()->is_ready()) { | 
					
						
							| 
									
										
										
										
											2017-09-20 11:40:49 +09:00
										 |  |  |     callback.Run(cmd, cwd); | 
					
						
							| 
									
										
										
										
											2015-10-22 17:12:09 +08:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     scoped_refptr<base::SingleThreadTaskRunner> task_runner( | 
					
						
							|  |  |  |         base::ThreadTaskRunnerHandle::Get()); | 
					
						
							| 
									
										
										
										
											2018-04-20 16:25:05 +05:30
										 |  |  |     task_runner->PostTask( | 
					
						
							|  |  |  |         FROM_HERE, base::BindOnce(base::IgnoreResult(callback), cmd, cwd)); | 
					
						
							| 
									
										
										
										
											2015-10-22 17:12:09 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   // ProcessSingleton needs to know whether current process is quiting.
 | 
					
						
							| 
									
										
										
										
											2015-10-22 16:24:35 +08:00
										 |  |  |   return !Browser::Get()->is_shutting_down(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  | void GotPrivateKey(std::shared_ptr<content::ClientCertificateDelegate> delegate, | 
					
						
							|  |  |  |                    scoped_refptr<net::X509Certificate> cert, | 
					
						
							|  |  |  |                    scoped_refptr<net::SSLPrivateKey> private_key) { | 
					
						
							|  |  |  |   delegate->ContinueWithCertificate(cert, private_key); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-11 20:52:07 +05:30
										 |  |  | void OnClientCertificateSelected( | 
					
						
							|  |  |  |     v8::Isolate* isolate, | 
					
						
							|  |  |  |     std::shared_ptr<content::ClientCertificateDelegate> delegate, | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  |     std::shared_ptr<net::ClientCertIdentityList> identities, | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2016-12-07 15:33:56 +05:30
										 |  |  |   if (args->Length() == 2) { | 
					
						
							| 
									
										
										
										
											2017-08-31 23:18:09 +03:00
										 |  |  |     delegate->ContinueWithCertificate(nullptr, nullptr); | 
					
						
							| 
									
										
										
										
											2016-12-07 15:33:56 +05:30
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   v8::Local<v8::Value> val; | 
					
						
							|  |  |  |   args->GetNext(&val); | 
					
						
							|  |  |  |   if (val->IsNull()) { | 
					
						
							| 
									
										
										
										
											2017-08-31 23:18:09 +03:00
										 |  |  |     delegate->ContinueWithCertificate(nullptr, nullptr); | 
					
						
							| 
									
										
										
										
											2015-06-11 20:52:07 +05:30
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   gin_helper::Dictionary cert_data; | 
					
						
							|  |  |  |   if (!gin::ConvertFromV8(isolate, val, &cert_data)) { | 
					
						
							| 
									
										
										
										
											2016-12-07 15:33:56 +05:30
										 |  |  |     args->ThrowError("Must pass valid certificate object."); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-17 20:48:09 +09:00
										 |  |  |   std::string data; | 
					
						
							| 
									
										
										
										
											2016-03-05 18:57:46 +09:00
										 |  |  |   if (!cert_data.Get("data", &data)) | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2015-06-11 20:52:07 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 18:57:46 +09:00
										 |  |  |   auto certs = net::X509Certificate::CreateCertificateListFromBytes( | 
					
						
							| 
									
										
										
										
											2016-08-17 20:48:09 +09:00
										 |  |  |       data.c_str(), data.length(), net::X509Certificate::FORMAT_AUTO); | 
					
						
							| 
									
										
										
										
											2017-08-31 23:18:09 +03:00
										 |  |  |   if (!certs.empty()) { | 
					
						
							|  |  |  |     scoped_refptr<net::X509Certificate> cert(certs[0].get()); | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  |     for (size_t i = 0; i < identities->size(); ++i) { | 
					
						
							| 
									
										
										
										
											2018-09-14 17:10:19 -07:00
										 |  |  |       if (cert->EqualsExcludingChain((*identities)[i]->certificate())) { | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  |         net::ClientCertIdentity::SelfOwningAcquirePrivateKey( | 
					
						
							|  |  |  |             std::move((*identities)[i]), | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |             base::BindRepeating(&GotPrivateKey, delegate, std::move(cert))); | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-31 23:18:09 +03:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-06-11 20:52:07 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-19 10:47:28 +05:30
										 |  |  | #if defined(USE_NSS_CERTS)
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | int ImportIntoCertStore(CertificateManagerModel* model, | 
					
						
							|  |  |  |                         const base::DictionaryValue& options) { | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  |   std::string file_data, cert_path; | 
					
						
							|  |  |  |   base::string16 password; | 
					
						
							| 
									
										
										
										
											2018-03-12 15:28:55 +09:00
										 |  |  |   net::ScopedCERTCertificateList imported_certs; | 
					
						
							| 
									
										
										
										
											2016-04-19 10:47:28 +05:30
										 |  |  |   int rv = -1; | 
					
						
							| 
									
										
										
										
											2016-04-20 08:45:49 +05:30
										 |  |  |   options.GetString("certificate", &cert_path); | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  |   options.GetString("password", &password); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!cert_path.empty()) { | 
					
						
							|  |  |  |     if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) { | 
					
						
							| 
									
										
										
										
											2017-04-17 17:17:02 +09:00
										 |  |  |       auto module = model->cert_db()->GetPrivateSlot(); | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |       rv = model->ImportFromPKCS12(module.get(), file_data, password, true, | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  |                                    &imported_certs); | 
					
						
							|  |  |  |       if (imported_certs.size() > 1) { | 
					
						
							|  |  |  |         auto it = imported_certs.begin(); | 
					
						
							| 
									
										
										
										
											2016-04-18 22:26:37 +05:30
										 |  |  |         ++it;  // skip first which would  be the client certificate.
 | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  |         for (; it != imported_certs.end(); ++it) | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |           rv &= model->SetCertTrust(it->get(), net::CA_CERT, | 
					
						
							| 
									
										
										
										
											2016-04-18 22:26:37 +05:30
										 |  |  |                                     net::NSSCertDatabase::TRUSTED_SSL); | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  |   return rv; | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-04-19 10:47:28 +05:30
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 15:10:32 +09:00
										 |  |  | void OnIconDataAvailable(gin_helper::Promise<gfx::Image> promise, | 
					
						
							|  |  |  |                          gfx::Image icon) { | 
					
						
							| 
									
										
										
										
											2019-04-30 20:18:22 -04:00
										 |  |  |   if (!icon.IsEmpty()) { | 
					
						
							| 
									
										
										
										
											2019-11-01 15:10:32 +09:00
										 |  |  |     promise.Resolve(icon); | 
					
						
							| 
									
										
										
										
											2016-11-05 21:23:49 +03:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     promise.RejectWithErrorMessage("Failed to get file icon."); | 
					
						
							| 
									
										
										
										
											2016-11-05 21:23:49 +03:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-11-03 00:27:16 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 21:26:45 +08:00
										 |  |  | }  // namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  | App::App(v8::Isolate* isolate) { | 
					
						
							| 
									
										
										
										
											2015-11-18 10:07:03 +08:00
										 |  |  |   static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(this); | 
					
						
							| 
									
										
										
										
											2013-05-03 10:53:54 +08:00
										 |  |  |   Browser::Get()->AddObserver(this); | 
					
						
							| 
									
										
										
										
											2015-06-25 20:28:07 +08:00
										 |  |  |   content::GpuDataManager::GetInstance()->AddObserver(this); | 
					
						
							| 
									
										
										
										
											2018-09-27 07:59:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 21:15:34 -07:00
										 |  |  |   base::ProcessId pid = base::GetCurrentProcId(); | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |   auto process_metric = std::make_unique<electron::ProcessMetric>( | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |       content::PROCESS_TYPE_BROWSER, base::GetCurrentProcessHandle(), | 
					
						
							| 
									
										
										
										
											2018-06-18 09:32:55 +02:00
										 |  |  |       base::ProcessMetrics::CreateCurrentProcessMetrics()); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  |   app_metrics_[pid] = std::move(process_metric); | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  |   Init(isolate); | 
					
						
							| 
									
										
										
										
											2013-05-03 10:53:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | App::~App() { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   static_cast<AtomBrowserClient*>(AtomBrowserClient::Get()) | 
					
						
							|  |  |  |       ->set_delegate(nullptr); | 
					
						
							| 
									
										
										
										
											2013-05-03 10:53:54 +08:00
										 |  |  |   Browser::Get()->RemoveObserver(this); | 
					
						
							| 
									
										
										
										
											2015-06-25 20:28:07 +08:00
										 |  |  |   content::GpuDataManager::GetInstance()->RemoveObserver(this); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  |   content::BrowserChildProcessObserver::Remove(this); | 
					
						
							| 
									
										
										
										
											2013-05-03 10:53:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-25 19:33:42 -08:00
										 |  |  | void App::OnBeforeQuit(bool* prevent_default) { | 
					
						
							| 
									
										
										
										
											2018-04-19 12:39:17 +02:00
										 |  |  |   if (Emit("before-quit")) { | 
					
						
							|  |  |  |     *prevent_default = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-02-25 19:33:42 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 10:53:54 +08:00
										 |  |  | void App::OnWillQuit(bool* prevent_default) { | 
					
						
							| 
									
										
										
										
											2018-04-19 12:39:17 +02:00
										 |  |  |   if (Emit("will-quit")) { | 
					
						
							|  |  |  |     *prevent_default = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-05-03 10:53:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void App::OnWindowAllClosed() { | 
					
						
							|  |  |  |   Emit("window-all-closed"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-09 18:19:51 -08:00
										 |  |  | void App::OnQuit() { | 
					
						
							|  |  |  |   int exitCode = AtomBrowserMainParts::Get()->GetExitCode(); | 
					
						
							|  |  |  |   Emit("quit", exitCode); | 
					
						
							| 
									
										
										
										
											2018-01-03 18:59:12 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (process_singleton_) { | 
					
						
							|  |  |  |     process_singleton_->Cleanup(); | 
					
						
							|  |  |  |     process_singleton_.reset(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-25 21:47:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 16:03:10 +08:00
										 |  |  | void App::OnOpenFile(bool* prevent_default, const std::string& file_path) { | 
					
						
							| 
									
										
										
										
											2018-04-19 12:39:17 +02:00
										 |  |  |   if (Emit("open-file", file_path)) { | 
					
						
							|  |  |  |     *prevent_default = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-05-30 16:03:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-10 16:10:38 +08:00
										 |  |  | void App::OnOpenURL(const std::string& url) { | 
					
						
							| 
									
										
										
										
											2015-01-14 17:51:54 -08:00
										 |  |  |   Emit("open-url", url); | 
					
						
							| 
									
										
										
										
											2013-07-10 16:10:38 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 19:05:53 -07:00
										 |  |  | void App::OnActivate(bool has_visible_windows) { | 
					
						
							|  |  |  |   Emit("activate", has_visible_windows); | 
					
						
							| 
									
										
										
										
											2015-09-14 19:28:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-03 15:31:46 +08:00
										 |  |  | void App::OnWillFinishLaunching() { | 
					
						
							|  |  |  |   Emit("will-finish-launching"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:17:44 -07:00
										 |  |  | void App::OnFinishLaunching(const base::DictionaryValue& launch_info) { | 
					
						
							| 
									
										
										
										
											2016-10-07 13:44:31 -07:00
										 |  |  | #if defined(OS_LINUX)
 | 
					
						
							| 
									
										
										
										
											2016-10-07 16:15:30 +05:30
										 |  |  |   // Set the application name for audio streams shown in external
 | 
					
						
							|  |  |  |   // applications. Only affects pulseaudio currently.
 | 
					
						
							|  |  |  |   media::AudioManager::SetGlobalAppName(Browser::Get()->GetName()); | 
					
						
							| 
									
										
										
										
											2016-10-07 13:44:31 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:17:44 -07:00
										 |  |  |   Emit("ready", launch_info); | 
					
						
							| 
									
										
										
										
											2017-09-14 23:08:18 +10:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-14 22:33:13 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-22 21:25:57 +05:30
										 |  |  | void App::OnPreMainMessageLoopRun() { | 
					
						
							|  |  |  |   content::BrowserChildProcessObserver::Add(this); | 
					
						
							| 
									
										
										
										
											2018-01-03 18:59:12 +09:00
										 |  |  |   if (process_singleton_) { | 
					
						
							|  |  |  |     process_singleton_->OnBrowserReady(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void App::OnAccessibilitySupportChanged() { | 
					
						
							|  |  |  |   Emit("accessibility-support-changed", IsAccessibilitySupportEnabled()); | 
					
						
							| 
									
										
										
										
											2017-12-22 21:25:57 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-05 12:26:23 +09:00
										 |  |  | #if defined(OS_MACOSX)
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void App::OnWillContinueUserActivity(bool* prevent_default, | 
					
						
							|  |  |  |                                      const std::string& type) { | 
					
						
							| 
									
										
										
										
											2018-04-19 12:39:17 +02:00
										 |  |  |   if (Emit("will-continue-activity", type)) { | 
					
						
							|  |  |  |     *prevent_default = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-06-26 16:14:44 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-14 16:12:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void App::OnDidFailToContinueUserActivity(const std::string& type, | 
					
						
							|  |  |  |                                           const std::string& error) { | 
					
						
							| 
									
										
										
										
											2017-06-26 16:14:44 -03:00
										 |  |  |   Emit("continue-activity-error", type, error); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-14 16:12:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void App::OnContinueUserActivity(bool* prevent_default, | 
					
						
							|  |  |  |                                  const std::string& type, | 
					
						
							|  |  |  |                                  const base::DictionaryValue& user_info) { | 
					
						
							| 
									
										
										
										
											2018-04-19 12:39:17 +02:00
										 |  |  |   if (Emit("continue-activity", type, user_info)) { | 
					
						
							|  |  |  |     *prevent_default = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-29 17:36:04 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-14 16:12:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void App::OnUserActivityWasContinued(const std::string& type, | 
					
						
							|  |  |  |                                      const base::DictionaryValue& user_info) { | 
					
						
							| 
									
										
										
										
											2017-06-26 16:14:44 -03:00
										 |  |  |   Emit("activity-was-continued", type, user_info); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-14 16:12:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void App::OnUpdateUserActivityState(bool* prevent_default, | 
					
						
							|  |  |  |                                     const std::string& type, | 
					
						
							|  |  |  |                                     const base::DictionaryValue& user_info) { | 
					
						
							| 
									
										
										
										
											2018-04-19 12:39:17 +02:00
										 |  |  |   if (Emit("update-activity-state", type, user_info)) { | 
					
						
							|  |  |  |     *prevent_default = true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-06-26 16:14:44 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-14 16:12:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-11 01:19:01 -07:00
										 |  |  | void App::OnNewWindowForTab() { | 
					
						
							|  |  |  |   Emit("new-window-for-tab"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-05-05 12:26:23 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-04-29 17:36:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 09:42:38 +05:30
										 |  |  | bool App::CanCreateWindow( | 
					
						
							|  |  |  |     content::RenderFrameHost* opener, | 
					
						
							|  |  |  |     const GURL& opener_url, | 
					
						
							|  |  |  |     const GURL& opener_top_level_frame_url, | 
					
						
							| 
									
										
										
										
											2019-01-21 23:44:57 +05:30
										 |  |  |     const url::Origin& source_origin, | 
					
						
							| 
									
										
										
										
											2017-12-07 09:42:38 +05:30
										 |  |  |     content::mojom::WindowContainerType container_type, | 
					
						
							| 
									
										
										
										
											2016-10-10 05:00:38 +05:30
										 |  |  |     const GURL& target_url, | 
					
						
							| 
									
										
										
										
											2017-12-07 09:42:38 +05:30
										 |  |  |     const content::Referrer& referrer, | 
					
						
							| 
									
										
										
										
											2016-10-10 05:00:38 +05:30
										 |  |  |     const std::string& frame_name, | 
					
						
							|  |  |  |     WindowOpenDisposition disposition, | 
					
						
							| 
									
										
										
										
											2017-12-07 09:42:38 +05:30
										 |  |  |     const blink::mojom::WindowFeatures& features, | 
					
						
							|  |  |  |     const std::vector<std::string>& additional_features, | 
					
						
							| 
									
										
										
										
											2018-04-11 10:42:14 +02:00
										 |  |  |     const scoped_refptr<network::ResourceRequestBody>& body, | 
					
						
							| 
									
										
										
										
											2017-12-07 09:42:38 +05:30
										 |  |  |     bool user_gesture, | 
					
						
							|  |  |  |     bool opener_suppressed, | 
					
						
							|  |  |  |     bool* no_javascript_access) { | 
					
						
							| 
									
										
										
										
											2016-03-31 19:51:18 +05:30
										 |  |  |   v8::Locker locker(isolate()); | 
					
						
							|  |  |  |   v8::HandleScope handle_scope(isolate()); | 
					
						
							|  |  |  |   content::WebContents* web_contents = | 
					
						
							| 
									
										
										
										
											2017-08-05 00:38:06 +03:00
										 |  |  |       content::WebContents::FromRenderFrameHost(opener); | 
					
						
							| 
									
										
										
										
											2016-03-31 19:51:18 +05:30
										 |  |  |   if (web_contents) { | 
					
						
							| 
									
										
										
										
											2018-10-19 17:52:07 +09:00
										 |  |  |     auto api_web_contents = WebContents::From(isolate(), web_contents); | 
					
						
							|  |  |  |     // No need to emit any event if the WebContents is not available in JS.
 | 
					
						
							|  |  |  |     if (!api_web_contents.IsEmpty()) { | 
					
						
							|  |  |  |       api_web_contents->OnCreateWindow(target_url, referrer, frame_name, | 
					
						
							|  |  |  |                                        disposition, additional_features, body); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-31 19:51:18 +05:30
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-12-07 09:42:38 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2016-03-31 19:51:18 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 10:39:25 +08:00
										 |  |  | void App::AllowCertificateError( | 
					
						
							| 
									
										
										
										
											2016-03-08 23:28:53 +09:00
										 |  |  |     content::WebContents* web_contents, | 
					
						
							| 
									
										
										
										
											2015-11-18 10:39:25 +08:00
										 |  |  |     int cert_error, | 
					
						
							|  |  |  |     const net::SSLInfo& ssl_info, | 
					
						
							|  |  |  |     const GURL& request_url, | 
					
						
							| 
									
										
										
										
											2019-05-13 14:24:39 -07:00
										 |  |  |     bool is_main_frame_request, | 
					
						
							| 
									
										
										
										
											2015-11-18 10:39:25 +08:00
										 |  |  |     bool strict_enforcement, | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |     const base::RepeatingCallback<void(content::CertificateRequestResultType)>& | 
					
						
							| 
									
										
										
										
											2016-11-30 16:30:03 +09:00
										 |  |  |         callback) { | 
					
						
							| 
									
										
										
										
											2015-11-18 10:39:25 +08:00
										 |  |  |   v8::Locker locker(isolate()); | 
					
						
							|  |  |  |   v8::HandleScope handle_scope(isolate()); | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   bool prevent_default = Emit( | 
					
						
							| 
									
										
										
										
											2018-10-19 17:52:07 +09:00
										 |  |  |       "certificate-error", WebContents::FromOrCreate(isolate(), web_contents), | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |       request_url, net::ErrorToString(cert_error), ssl_info.cert, callback); | 
					
						
							| 
									
										
										
										
											2015-11-18 10:39:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Deny the certificate by default.
 | 
					
						
							|  |  |  |   if (!prevent_default) | 
					
						
							| 
									
										
										
										
											2016-11-30 16:30:03 +09:00
										 |  |  |     callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); | 
					
						
							| 
									
										
										
										
											2015-11-18 10:39:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-02 18:22:09 -07:00
										 |  |  | base::OnceClosure App::SelectClientCertificate( | 
					
						
							| 
									
										
										
										
											2015-11-18 10:07:03 +08:00
										 |  |  |     content::WebContents* web_contents, | 
					
						
							|  |  |  |     net::SSLCertRequestInfo* cert_request_info, | 
					
						
							| 
									
										
										
										
											2017-08-21 00:35:04 +03:00
										 |  |  |     net::ClientCertIdentityList identities, | 
					
						
							| 
									
										
										
										
											2016-05-23 10:59:39 +09:00
										 |  |  |     std::unique_ptr<content::ClientCertificateDelegate> delegate) { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   std::shared_ptr<content::ClientCertificateDelegate> shared_delegate( | 
					
						
							|  |  |  |       delegate.release()); | 
					
						
							| 
									
										
										
										
											2017-08-21 00:35:04 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Convert the ClientCertIdentityList to a CertificateList
 | 
					
						
							|  |  |  |   // to avoid changes in the API.
 | 
					
						
							|  |  |  |   auto client_certs = net::CertificateList(); | 
					
						
							|  |  |  |   for (const std::unique_ptr<net::ClientCertIdentity>& identity : identities) | 
					
						
							| 
									
										
										
										
											2019-09-13 10:26:59 -04:00
										 |  |  |     client_certs.emplace_back(identity->certificate()); | 
					
						
							| 
									
										
										
										
											2017-08-21 00:35:04 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  |   auto shared_identities = | 
					
						
							|  |  |  |       std::make_shared<net::ClientCertIdentityList>(std::move(identities)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 10:07:03 +08:00
										 |  |  |   bool prevent_default = | 
					
						
							| 
									
										
										
										
											2015-11-18 10:10:21 +08:00
										 |  |  |       Emit("select-client-certificate", | 
					
						
							| 
									
										
										
										
											2018-10-19 17:52:07 +09:00
										 |  |  |            WebContents::FromOrCreate(isolate(), web_contents), | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  |            cert_request_info->host_and_port.ToString(), std::move(client_certs), | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |            base::BindOnce(&OnClientCertificateSelected, isolate(), | 
					
						
							|  |  |  |                           shared_delegate, shared_identities)); | 
					
						
							| 
									
										
										
										
											2015-11-18 10:07:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Default to first certificate from the platform store.
 | 
					
						
							| 
									
										
										
										
											2017-08-31 23:18:09 +03:00
										 |  |  |   if (!prevent_default) { | 
					
						
							| 
									
										
										
										
											2017-10-23 13:24:17 +05:30
										 |  |  |     scoped_refptr<net::X509Certificate> cert = | 
					
						
							|  |  |  |         (*shared_identities)[0]->certificate(); | 
					
						
							|  |  |  |     net::ClientCertIdentity::SelfOwningAcquirePrivateKey( | 
					
						
							|  |  |  |         std::move((*shared_identities)[0]), | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |         base::BindRepeating(&GotPrivateKey, shared_delegate, std::move(cert))); | 
					
						
							| 
									
										
										
										
											2017-08-31 23:18:09 +03:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-07-02 18:22:09 -07:00
										 |  |  |   return base::OnceClosure(); | 
					
						
							| 
									
										
										
										
											2015-11-18 10:07:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-18 03:06:48 +02:00
										 |  |  | void App::OnGpuInfoUpdate() { | 
					
						
							|  |  |  |   Emit("gpu-info-update"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 17:00:45 -07:00
										 |  |  | void App::OnGpuProcessCrashed(base::TerminationStatus status) { | 
					
						
							|  |  |  |   Emit("gpu-process-crashed", | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |        status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); | 
					
						
							| 
									
										
										
										
											2015-06-25 20:28:07 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | void App::BrowserChildProcessLaunchedAndConnected( | 
					
						
							|  |  |  |     const content::ChildProcessData& data) { | 
					
						
							| 
									
										
										
										
											2019-01-09 15:21:51 -08:00
										 |  |  |   ChildProcessLaunched(data.process_type, data.GetProcess().Handle()); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void App::BrowserChildProcessHostDisconnected( | 
					
						
							|  |  |  |     const content::ChildProcessData& data) { | 
					
						
							| 
									
										
										
										
											2019-01-09 15:21:51 -08:00
										 |  |  |   ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle())); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 17:11:49 -07:00
										 |  |  | void App::BrowserChildProcessCrashed( | 
					
						
							|  |  |  |     const content::ChildProcessData& data, | 
					
						
							|  |  |  |     const content::ChildProcessTerminationInfo& info) { | 
					
						
							| 
									
										
										
										
											2019-01-09 15:21:51 -08:00
										 |  |  |   ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle())); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:32:08 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 17:11:49 -07:00
										 |  |  | void App::BrowserChildProcessKilled( | 
					
						
							|  |  |  |     const content::ChildProcessData& data, | 
					
						
							|  |  |  |     const content::ChildProcessTerminationInfo& info) { | 
					
						
							| 
									
										
										
										
											2019-01-09 15:21:51 -08:00
										 |  |  |   ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle())); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:32:08 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 07:51:17 -07:00
										 |  |  | void App::RenderProcessReady(content::RenderProcessHost* host) { | 
					
						
							| 
									
										
										
										
											2018-09-14 17:13:02 -07:00
										 |  |  |   ChildProcessLaunched(content::PROCESS_TYPE_RENDERER, | 
					
						
							|  |  |  |                        host->GetProcess().Handle()); | 
					
						
							| 
									
										
										
										
											2019-06-04 16:07:34 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // TODO(jeremy): this isn't really the right place to be creating
 | 
					
						
							|  |  |  |   // `WebContents` instances, but this was implicitly happening before in
 | 
					
						
							|  |  |  |   // `RenderProcessPreferences`, so this is at least more explicit...
 | 
					
						
							|  |  |  |   content::WebContents* web_contents = | 
					
						
							|  |  |  |       AtomBrowserClient::Get()->GetWebContentsFromProcessID(host->GetID()); | 
					
						
							|  |  |  |   if (web_contents) | 
					
						
							|  |  |  |     WebContents::FromOrCreate(v8::Isolate::GetCurrent(), web_contents); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:32:08 -07:00
										 |  |  | void App::RenderProcessDisconnected(base::ProcessId host_pid) { | 
					
						
							|  |  |  |   ChildProcessDisconnected(host_pid); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:32:08 -07:00
										 |  |  | void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) { | 
					
						
							| 
									
										
										
										
											2017-05-19 21:28:52 -07:00
										 |  |  |   auto pid = base::GetProcId(handle); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined(OS_MACOSX)
 | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |   auto metrics = base::ProcessMetrics::CreateProcessMetrics( | 
					
						
							|  |  |  |       handle, content::BrowserChildProcessHost::GetPortProvider()); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |   auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |   app_metrics_[pid] = std::make_unique<electron::ProcessMetric>( | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |       process_type, handle, std::move(metrics)); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 07:51:17 -07:00
										 |  |  | void App::ChildProcessDisconnected(base::ProcessId pid) { | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  |   app_metrics_.erase(pid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 23:26:42 +09:00
										 |  |  | base::FilePath App::GetAppPath() const { | 
					
						
							| 
									
										
										
										
											2017-04-04 09:36:01 +09:00
										 |  |  |   return app_path_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 10:59:12 +09:00
										 |  |  | void App::SetAppPath(const base::FilePath& app_path) { | 
					
						
							| 
									
										
										
										
											2017-04-04 09:36:01 +09:00
										 |  |  |   app_path_ = app_path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 22:04:58 -07:00
										 |  |  | #if !defined(OS_MACOSX)
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | void App::SetAppLogsPath(gin_helper::ErrorThrower thrower, | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |                          base::Optional<base::FilePath> custom_path) { | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  |   if (custom_path.has_value()) { | 
					
						
							|  |  |  |     if (!custom_path->IsAbsolute()) { | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |       thrower.ThrowError("Path must be absolute"); | 
					
						
							| 
									
										
										
										
											2019-04-18 22:04:58 -07:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  |     base::PathService::Override(DIR_APP_LOGS, custom_path.value()); | 
					
						
							| 
									
										
										
										
											2019-04-18 22:04:58 -07:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     base::FilePath path; | 
					
						
							|  |  |  |     if (base::PathService::Get(DIR_USER_DATA, &path)) { | 
					
						
							|  |  |  |       path = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); | 
					
						
							|  |  |  |       path = path.Append(base::FilePath::FromUTF8Unsafe("logs")); | 
					
						
							|  |  |  |       base::PathService::Override(DIR_APP_LOGS, path); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | base::FilePath App::GetPath(gin_helper::ErrorThrower thrower, | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |                             const std::string& name) { | 
					
						
							| 
									
										
										
										
											2015-01-18 20:24:58 -08:00
										 |  |  |   bool succeed = false; | 
					
						
							| 
									
										
										
										
											2014-08-12 17:01:56 +02:00
										 |  |  |   base::FilePath path; | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-18 17:52:15 -08:00
										 |  |  |   int key = GetPathConstant(name); | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  |   if (key >= 0) { | 
					
						
							| 
									
										
										
										
											2018-09-14 17:09:42 -07:00
										 |  |  |     succeed = base::PathService::Get(key, &path); | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  |     // If users try to get the logs path before setting a logs path,
 | 
					
						
							|  |  |  |     // set the path to a sensible default and then try to get it again
 | 
					
						
							|  |  |  |     if (!succeed && name == "logs") { | 
					
						
							|  |  |  |       base::ThreadRestrictions::ScopedAllowIO allow_io; | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |       SetAppLogsPath(thrower, base::Optional<base::FilePath>()); | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  |       succeed = base::PathService::Get(key, &path); | 
					
						
							| 
									
										
										
										
											2019-07-30 13:55:04 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  |   if (!succeed) | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |     thrower.ThrowError("Failed to get '" + name + "' path"); | 
					
						
							| 
									
										
										
										
											2019-08-19 15:16:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-18 17:11:27 -08:00
										 |  |  |   return path; | 
					
						
							| 
									
										
										
										
											2014-08-12 17:01:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | void App::SetPath(gin_helper::ErrorThrower thrower, | 
					
						
							| 
									
										
										
										
											2015-01-18 20:24:58 -08:00
										 |  |  |                   const std::string& name, | 
					
						
							|  |  |  |                   const base::FilePath& path) { | 
					
						
							| 
									
										
										
										
											2016-04-21 14:37:29 +09:00
										 |  |  |   if (!path.IsAbsolute()) { | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |     thrower.ThrowError("Path must be absolute"); | 
					
						
							| 
									
										
										
										
											2016-04-21 14:37:29 +09:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-18 20:24:58 -08:00
										 |  |  |   bool succeed = false; | 
					
						
							| 
									
										
										
										
											2015-01-18 17:52:15 -08:00
										 |  |  |   int key = GetPathConstant(name); | 
					
						
							| 
									
										
										
										
											2019-10-31 13:11:51 -07:00
										 |  |  |   if (key >= 0) { | 
					
						
							| 
									
										
										
										
											2018-09-14 17:09:42 -07:00
										 |  |  |     succeed = | 
					
						
							|  |  |  |         base::PathService::OverrideAndCreateIfNeeded(key, path, true, false); | 
					
						
							| 
									
										
										
										
											2019-10-31 13:11:51 -07:00
										 |  |  |     if (key == DIR_USER_DATA) { | 
					
						
							|  |  |  |       succeed |= base::PathService::OverrideAndCreateIfNeeded( | 
					
						
							|  |  |  |           chrome::DIR_USER_DATA, path, true, false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-01-18 20:24:58 -08:00
										 |  |  |   if (!succeed) | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |     thrower.ThrowError("Failed to set path"); | 
					
						
							| 
									
										
										
										
											2015-01-18 17:52:15 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-18 04:12:24 -07:00
										 |  |  | void App::SetDesktopName(const std::string& desktop_name) { | 
					
						
							|  |  |  | #if defined(OS_LINUX)
 | 
					
						
							| 
									
										
										
										
											2016-05-23 10:59:39 +09:00
										 |  |  |   std::unique_ptr<base::Environment> env(base::Environment::Create()); | 
					
						
							| 
									
										
										
										
											2014-09-18 04:12:24 -07:00
										 |  |  |   env->SetVar("CHROME_DESKTOP", desktop_name); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-16 17:16:21 +09:00
										 |  |  | std::string App::GetLocale() { | 
					
						
							| 
									
										
										
										
											2017-12-16 14:51:29 +05:30
										 |  |  |   return g_browser_process->GetApplicationLocale(); | 
					
						
							| 
									
										
										
										
											2015-09-16 17:16:21 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 21:33:23 +01:00
										 |  |  | std::string App::GetLocaleCountryCode() { | 
					
						
							|  |  |  |   std::string region; | 
					
						
							|  |  |  | #if defined(OS_WIN)
 | 
					
						
							|  |  |  |   WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, | 
					
						
							|  |  |  |                       (LPWSTR)&locale_name, | 
					
						
							|  |  |  |                       sizeof(locale_name) / sizeof(WCHAR)) || | 
					
						
							|  |  |  |       GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, | 
					
						
							|  |  |  |                       (LPWSTR)&locale_name, | 
					
						
							|  |  |  |                       sizeof(locale_name) / sizeof(WCHAR))) { | 
					
						
							|  |  |  |     base::WideToUTF8(locale_name, wcslen(locale_name), ®ion); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | #elif defined(OS_MACOSX)
 | 
					
						
							|  |  |  |   CFLocaleRef locale = CFLocaleCopyCurrent(); | 
					
						
							|  |  |  |   CFStringRef value = CFStringRef( | 
					
						
							|  |  |  |       static_cast<CFTypeRef>(CFLocaleGetValue(locale, kCFLocaleCountryCode))); | 
					
						
							|  |  |  |   const CFIndex kCStringSize = 128; | 
					
						
							|  |  |  |   char temporaryCString[kCStringSize] = {0}; | 
					
						
							|  |  |  |   CFStringGetCString(value, temporaryCString, kCStringSize, | 
					
						
							|  |  |  |                      kCFStringEncodingUTF8); | 
					
						
							|  |  |  |   region = temporaryCString; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-09-16 18:12:00 -04:00
										 |  |  |   const char* locale_ptr = setlocale(LC_TIME, nullptr); | 
					
						
							| 
									
										
										
										
											2018-11-20 21:33:23 +01:00
										 |  |  |   if (!locale_ptr) | 
					
						
							| 
									
										
										
										
											2019-09-16 18:12:00 -04:00
										 |  |  |     locale_ptr = setlocale(LC_NUMERIC, nullptr); | 
					
						
							| 
									
										
										
										
											2018-11-20 21:33:23 +01:00
										 |  |  |   if (locale_ptr) { | 
					
						
							|  |  |  |     std::string locale = locale_ptr; | 
					
						
							|  |  |  |     std::string::size_type rpos = locale.find('.'); | 
					
						
							|  |  |  |     if (rpos != std::string::npos) | 
					
						
							|  |  |  |       locale = locale.substr(0, rpos); | 
					
						
							|  |  |  |     rpos = locale.find('_'); | 
					
						
							|  |  |  |     if (rpos != std::string::npos && rpos + 1 < locale.size()) | 
					
						
							|  |  |  |       region = locale.substr(rpos + 1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   return region.size() == 2 ? region : std::string(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  | void App::OnSecondInstance(const base::CommandLine::StringVector& cmd, | 
					
						
							|  |  |  |                            const base::FilePath& cwd) { | 
					
						
							|  |  |  |   Emit("second-instance", cmd, cwd); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool App::HasSingleInstanceLock() const { | 
					
						
							| 
									
										
										
										
											2018-01-03 18:59:12 +09:00
										 |  |  |   if (process_singleton_) | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool App::RequestSingleInstanceLock() { | 
					
						
							|  |  |  |   if (HasSingleInstanceLock()) | 
					
						
							|  |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2015-10-21 13:17:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 18:59:12 +09:00
										 |  |  |   base::FilePath user_dir; | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  |   base::PathService::Get(DIR_USER_DATA, &user_dir); | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |   auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this)); | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-16 18:12:00 -04:00
										 |  |  |   process_singleton_ = std::make_unique<ProcessSingleton>( | 
					
						
							|  |  |  |       user_dir, base::BindRepeating(NotificationCallbackWrapper, cb)); | 
					
						
							| 
									
										
										
										
											2015-10-19 18:02:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 18:59:12 +09:00
										 |  |  |   switch (process_singleton_->NotifyOtherProcessOrCreate()) { | 
					
						
							| 
									
										
										
										
											2015-10-19 16:21:03 -07:00
										 |  |  |     case ProcessSingleton::NotifyResult::LOCK_ERROR: | 
					
						
							|  |  |  |     case ProcessSingleton::NotifyResult::PROFILE_IN_USE: | 
					
						
							| 
									
										
										
										
											2017-12-11 13:25:49 +05:30
										 |  |  |     case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED: { | 
					
						
							| 
									
										
										
										
											2018-01-03 18:59:12 +09:00
										 |  |  |       process_singleton_.reset(); | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  |       return false; | 
					
						
							| 
									
										
										
										
											2017-12-11 13:25:49 +05:30
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-10-22 16:55:54 +08:00
										 |  |  |     case ProcessSingleton::NotifyResult::PROCESS_NONE: | 
					
						
							|  |  |  |     default:  // Shouldn't be needed, but VS warns if it is not there.
 | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  |       return true; | 
					
						
							| 
									
										
										
										
											2015-10-19 16:21:03 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-19 14:43:04 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  | void App::ReleaseSingleInstanceLock() { | 
					
						
							| 
									
										
										
										
											2018-01-03 18:59:12 +09:00
										 |  |  |   if (process_singleton_) { | 
					
						
							|  |  |  |     process_singleton_->Cleanup(); | 
					
						
							|  |  |  |     process_singleton_.reset(); | 
					
						
							| 
									
										
										
										
											2016-05-26 14:07:19 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | bool App::Relaunch(gin_helper::Arguments* js_args) { | 
					
						
							| 
									
										
										
										
											2016-06-02 21:49:29 +09:00
										 |  |  |   // Parse parameters.
 | 
					
						
							|  |  |  |   bool override_argv = false; | 
					
						
							|  |  |  |   base::FilePath exec_path; | 
					
						
							|  |  |  |   relauncher::StringVector args; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   gin_helper::Dictionary options; | 
					
						
							| 
									
										
										
										
											2016-06-02 21:49:29 +09:00
										 |  |  |   if (js_args->GetNext(&options)) { | 
					
						
							| 
									
										
										
										
											2016-06-03 12:08:45 +09:00
										 |  |  |     if (options.Get("execPath", &exec_path) | options.Get("args", &args)) | 
					
						
							| 
									
										
										
										
											2016-06-02 21:49:29 +09:00
										 |  |  |       override_argv = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!override_argv) { | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |     const relauncher::StringVector& argv = electron::AtomCommandLine::argv(); | 
					
						
							| 
									
										
										
										
											2016-06-02 21:49:29 +09:00
										 |  |  |     return relauncher::RelaunchApp(argv); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   relauncher::StringVector argv; | 
					
						
							|  |  |  |   argv.reserve(1 + args.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (exec_path.empty()) { | 
					
						
							|  |  |  |     base::FilePath current_exe_path; | 
					
						
							| 
									
										
										
										
											2018-09-14 17:09:42 -07:00
										 |  |  |     base::PathService::Get(base::FILE_EXE, ¤t_exe_path); | 
					
						
							| 
									
										
										
										
											2016-06-02 21:49:29 +09:00
										 |  |  |     argv.push_back(current_exe_path.value()); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     argv.push_back(exec_path.value()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   argv.insert(argv.end(), args.begin(), args.end()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return relauncher::RelaunchApp(argv); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) { | 
					
						
							| 
									
										
										
										
											2016-06-06 20:19:55 +09:00
										 |  |  |   if (Browser::Get()->is_ready()) { | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |     thrower.ThrowError( | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |         "app.disableHardwareAcceleration() can only be called " | 
					
						
							|  |  |  |         "before app is ready"); | 
					
						
							| 
									
										
										
										
											2016-06-06 20:19:55 +09:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   content::GpuDataManager::GetInstance()->DisableHardwareAcceleration(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) { | 
					
						
							| 
									
										
										
										
											2017-07-14 01:27:03 +03:00
										 |  |  |   if (Browser::Get()->is_ready()) { | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |     thrower.ThrowError( | 
					
						
							| 
									
										
										
										
											2017-07-14 01:27:03 +03:00
										 |  |  |         "app.disableDomainBlockingFor3DAPIs() can only be called " | 
					
						
							|  |  |  |         "before app is ready"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   content::GpuDataManagerImpl::GetInstance() | 
					
						
							|  |  |  |       ->DisableDomainBlockingFor3DAPIsForTesting(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 14:32:14 -07:00
										 |  |  | bool App::IsAccessibilitySupportEnabled() { | 
					
						
							| 
									
										
										
										
											2018-04-17 15:41:47 -07:00
										 |  |  |   auto* ax_state = content::BrowserAccessibilityState::GetInstance(); | 
					
						
							| 
									
										
										
										
											2016-07-11 14:04:56 -07:00
										 |  |  |   return ax_state->IsAccessibleBrowser(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | void App::SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower, | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |                                          bool enabled) { | 
					
						
							| 
									
										
										
										
											2019-01-04 07:20:06 -08:00
										 |  |  |   if (!Browser::Get()->is_ready()) { | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |     thrower.ThrowError( | 
					
						
							| 
									
										
										
										
											2019-01-04 07:20:06 -08:00
										 |  |  |         "app.setAccessibilitySupportEnabled() can only be called " | 
					
						
							|  |  |  |         "after app is ready"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 15:41:47 -07:00
										 |  |  |   auto* ax_state = content::BrowserAccessibilityState::GetInstance(); | 
					
						
							| 
									
										
										
										
											2017-08-27 11:53:25 -03:00
										 |  |  |   if (enabled) { | 
					
						
							| 
									
										
										
										
											2017-08-24 11:22:28 -03:00
										 |  |  |     ax_state->OnScreenReaderDetected(); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     ax_state->DisableAccessibility(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   Browser::Get()->OnAccessibilitySupportChanged(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | Browser::LoginItemSettings App::GetLoginItemSettings( | 
					
						
							|  |  |  |     gin_helper::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2017-01-30 14:01:40 -08:00
										 |  |  |   Browser::LoginItemSettings options; | 
					
						
							|  |  |  |   args->GetNext(&options); | 
					
						
							|  |  |  |   return Browser::Get()->GetLoginItemSettings(options); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-19 10:47:28 +05:30
										 |  |  | #if defined(USE_NSS_CERTS)
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void App::ImportCertificate(const base::DictionaryValue& options, | 
					
						
							| 
									
										
										
										
											2019-04-20 13:20:37 -04:00
										 |  |  |                             net::CompletionRepeatingCallback callback) { | 
					
						
							| 
									
										
										
										
											2016-07-12 22:45:15 +09:00
										 |  |  |   auto browser_context = AtomBrowserContext::From("", false); | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  |   if (!certificate_manager_model_) { | 
					
						
							| 
									
										
										
										
											2018-08-03 14:23:07 -07:00
										 |  |  |     auto copy = base::DictionaryValue::From( | 
					
						
							|  |  |  |         base::Value::ToUniquePtrValue(options.Clone())); | 
					
						
							| 
									
										
										
										
											2016-06-22 16:10:36 +09:00
										 |  |  |     CertificateManagerModel::Create( | 
					
						
							|  |  |  |         browser_context.get(), | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |         base::BindRepeating(&App::OnCertificateManagerModelCreated, | 
					
						
							|  |  |  |                             base::Unretained(this), base::Passed(©), | 
					
						
							|  |  |  |                             callback)); | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  |   int rv = ImportIntoCertStore(certificate_manager_model_.get(), options); | 
					
						
							| 
									
										
										
										
											2019-04-20 13:20:37 -04:00
										 |  |  |   std::move(callback).Run(rv); | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void App::OnCertificateManagerModelCreated( | 
					
						
							| 
									
										
										
										
											2016-05-23 10:59:39 +09:00
										 |  |  |     std::unique_ptr<base::DictionaryValue> options, | 
					
						
							| 
									
										
										
										
											2019-04-20 13:20:37 -04:00
										 |  |  |     net::CompletionOnceCallback callback, | 
					
						
							| 
									
										
										
										
											2016-05-23 10:59:39 +09:00
										 |  |  |     std::unique_ptr<CertificateManagerModel> model) { | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  |   certificate_manager_model_ = std::move(model); | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |   int rv = | 
					
						
							|  |  |  |       ImportIntoCertStore(certificate_manager_model_.get(), *(options.get())); | 
					
						
							| 
									
										
										
										
											2019-04-20 13:20:37 -04:00
										 |  |  |   std::move(callback).Run(rv); | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-04-19 10:47:28 +05:30
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-04-18 10:41:31 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  | #if defined(OS_WIN)
 | 
					
						
							|  |  |  | v8::Local<v8::Value> App::GetJumpListSettings() { | 
					
						
							|  |  |  |   JumpList jump_list(Browser::Get()->GetAppUserModelID()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   int min_items = 10; | 
					
						
							|  |  |  |   std::vector<JumpListItem> removed_items; | 
					
						
							|  |  |  |   if (jump_list.Begin(&min_items, &removed_items)) { | 
					
						
							|  |  |  |     // We don't actually want to change anything, so abort the transaction.
 | 
					
						
							|  |  |  |     jump_list.Abort(); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     LOG(ERROR) << "Failed to begin Jump List transaction."; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate()); | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   dict.Set("minItems", min_items); | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   dict.Set("removedItems", gin::ConvertToV8(isolate(), removed_items)); | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   return dict.GetHandle(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | JumpListResult App::SetJumpList(v8::Local<v8::Value> val, | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |                                 gin_helper::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   std::vector<JumpListCategory> categories; | 
					
						
							|  |  |  |   bool delete_jump_list = val->IsNull(); | 
					
						
							|  |  |  |   if (!delete_jump_list && | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |       !gin::ConvertFromV8(args->isolate(), val, &categories)) { | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |     args->ThrowError("Argument must be null or an array of categories"); | 
					
						
							|  |  |  |     return JumpListResult::ARGUMENT_ERROR; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   JumpList jump_list(Browser::Get()->GetAppUserModelID()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (delete_jump_list) { | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |     return jump_list.Delete() ? JumpListResult::SUCCESS | 
					
						
							|  |  |  |                               : JumpListResult::GENERIC_ERROR; | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Start a transaction that updates the JumpList of this application.
 | 
					
						
							|  |  |  |   if (!jump_list.Begin()) | 
					
						
							|  |  |  |     return JumpListResult::GENERIC_ERROR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   JumpListResult result = jump_list.AppendCategories(categories); | 
					
						
							|  |  |  |   // AppendCategories may have failed to add some categories, but it's better
 | 
					
						
							|  |  |  |   // to have something than nothing so try to commit the changes anyway.
 | 
					
						
							|  |  |  |   if (!jump_list.Commit()) { | 
					
						
							|  |  |  |     LOG(ERROR) << "Failed to commit changes to custom Jump List."; | 
					
						
							|  |  |  |     // It's more useful to return the earlier error code that might give
 | 
					
						
							|  |  |  |     // some indication as to why the transaction actually failed, so don't
 | 
					
						
							|  |  |  |     // overwrite it with a "generic error" code here.
 | 
					
						
							|  |  |  |     if (result == JumpListResult::SUCCESS) | 
					
						
							|  |  |  |       result = JumpListResult::GENERIC_ERROR; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif  // defined(OS_WIN)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 08:50:12 -08:00
										 |  |  | v8::Local<v8::Promise> App::GetFileIcon(const base::FilePath& path, | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |                                         gin_helper::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2019-11-01 15:10:32 +09:00
										 |  |  |   gin_helper::Promise<gfx::Image> promise(isolate()); | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |   v8::Local<v8::Promise> handle = promise.GetHandle(); | 
					
						
							| 
									
										
										
										
											2016-11-05 21:55:23 +03:00
										 |  |  |   base::FilePath normalized_path = path.NormalizePathSeparators(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 08:50:12 -08:00
										 |  |  |   IconLoader::IconSize icon_size; | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   gin_helper::Dictionary options; | 
					
						
							| 
									
										
										
										
											2016-11-03 21:23:40 +03:00
										 |  |  |   if (!args->GetNext(&options)) { | 
					
						
							| 
									
										
										
										
											2016-11-03 21:04:56 +03:00
										 |  |  |     icon_size = IconLoader::IconSize::NORMAL; | 
					
						
							| 
									
										
										
										
											2016-11-03 21:23:40 +03:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     std::string icon_size_string; | 
					
						
							| 
									
										
										
										
											2016-11-04 12:29:18 +05:30
										 |  |  |     options.Get("size", &icon_size_string); | 
					
						
							| 
									
										
										
										
											2016-11-03 21:23:40 +03:00
										 |  |  |     icon_size = GetIconSizeByString(icon_size_string); | 
					
						
							| 
									
										
										
										
											2016-11-03 21:04:56 +03:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-06 00:42:53 +05:30
										 |  |  |   auto* icon_manager = AtomBrowserMainParts::Get()->GetIconManager(); | 
					
						
							| 
									
										
										
										
											2017-02-17 14:03:46 +05:30
										 |  |  |   gfx::Image* icon = | 
					
						
							|  |  |  |       icon_manager->LookupIconFromFilepath(normalized_path, icon_size); | 
					
						
							| 
									
										
										
										
											2016-11-03 00:27:16 +05:30
										 |  |  |   if (icon) { | 
					
						
							| 
									
										
										
										
											2019-11-01 15:10:32 +09:00
										 |  |  |     promise.Resolve(*icon); | 
					
						
							| 
									
										
										
										
											2016-11-03 00:27:16 +05:30
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     icon_manager->LoadIcon( | 
					
						
							|  |  |  |         normalized_path, icon_size, | 
					
						
							|  |  |  |         base::BindOnce(&OnIconDataAvailable, std::move(promise)), | 
					
						
							|  |  |  |         &cancelable_task_tracker_); | 
					
						
							| 
									
										
										
										
											2016-11-03 00:27:16 +05:30
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |   return handle; | 
					
						
							| 
									
										
										
										
											2016-11-03 00:27:16 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | std::vector<gin_helper::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) { | 
					
						
							|  |  |  |   std::vector<gin_helper::Dictionary> result; | 
					
						
							| 
									
										
										
										
											2019-01-25 09:39:32 -05:00
										 |  |  |   result.reserve(app_metrics_.size()); | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  |   int processor_count = base::SysInfo::NumberOfProcessors(); | 
					
						
							| 
									
										
										
										
											2017-04-17 04:59:16 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  |   for (const auto& process_metric : app_metrics_) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary pid_dict = gin::Dictionary::CreateEmpty(isolate); | 
					
						
							|  |  |  |     gin_helper::Dictionary cpu_dict = gin::Dictionary::CreateEmpty(isolate); | 
					
						
							| 
									
										
										
										
											2017-04-26 21:04:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-09 00:10:18 +09:00
										 |  |  |     // TODO(zcbenz): Just call SetHidden when this file is converted to gin.
 | 
					
						
							|  |  |  |     gin_helper::Dictionary(isolate, pid_dict.GetHandle()) | 
					
						
							|  |  |  |         .SetHidden("simple", true); | 
					
						
							|  |  |  |     gin_helper::Dictionary(isolate, cpu_dict.GetHandle()) | 
					
						
							|  |  |  |         .SetHidden("simple", true); | 
					
						
							| 
									
										
										
										
											2018-08-03 21:07:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |     cpu_dict.Set( | 
					
						
							|  |  |  |         "percentCPUUsage", | 
					
						
							|  |  |  |         process_metric.second->metrics->GetPlatformIndependentCPUUsage() / | 
					
						
							|  |  |  |             processor_count); | 
					
						
							| 
									
										
										
										
											2017-10-27 14:21:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if !defined(OS_WIN)
 | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  |     cpu_dict.Set("idleWakeupsPerSecond", | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |                  process_metric.second->metrics->GetIdleWakeupsPerSecond()); | 
					
						
							| 
									
										
										
										
											2017-10-27 14:21:46 -07:00
										 |  |  | #else
 | 
					
						
							|  |  |  |     // Chrome's underlying process_metrics.cc will throw a non-fatal warning
 | 
					
						
							|  |  |  |     // that this method isn't implemented on Windows, so set it to 0 instead
 | 
					
						
							|  |  |  |     // of calling it
 | 
					
						
							|  |  |  |     cpu_dict.Set("idleWakeupsPerSecond", 0); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-15 17:41:45 -07:00
										 |  |  |     pid_dict.Set("cpu", cpu_dict); | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |     pid_dict.Set("pid", process_metric.second->process.Pid()); | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  |     pid_dict.Set("type", content::GetProcessTypeNameInEnglish( | 
					
						
							|  |  |  |                              process_metric.second->type)); | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  |     pid_dict.Set("creationTime", | 
					
						
							|  |  |  |                  process_metric.second->process.CreationTime().ToJsTime()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 22:41:59 +02:00
										 |  |  | #if !defined(OS_LINUX)
 | 
					
						
							|  |  |  |     auto memory_info = process_metric.second->GetMemoryInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary memory_dict = gin::Dictionary::CreateEmpty(isolate); | 
					
						
							| 
									
										
										
										
											2019-09-09 00:10:18 +09:00
										 |  |  |     // TODO(zcbenz): Just call SetHidden when this file is converted to gin.
 | 
					
						
							|  |  |  |     gin_helper::Dictionary(isolate, memory_dict.GetHandle()) | 
					
						
							|  |  |  |         .SetHidden("simple", true); | 
					
						
							| 
									
										
										
										
											2019-07-23 22:41:59 +02:00
										 |  |  |     memory_dict.Set("workingSetSize", | 
					
						
							|  |  |  |                     static_cast<double>(memory_info.working_set_size >> 10)); | 
					
						
							|  |  |  |     memory_dict.Set( | 
					
						
							|  |  |  |         "peakWorkingSetSize", | 
					
						
							|  |  |  |         static_cast<double>(memory_info.peak_working_set_size >> 10)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(OS_WIN)
 | 
					
						
							|  |  |  |     memory_dict.Set("privateBytes", | 
					
						
							|  |  |  |                     static_cast<double>(memory_info.private_bytes >> 10)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pid_dict.Set("memory", memory_dict); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-14 21:39:55 +02:00
										 |  |  | #if defined(OS_MACOSX)
 | 
					
						
							|  |  |  |     pid_dict.Set("sandboxed", process_metric.second->IsSandboxed()); | 
					
						
							|  |  |  | #elif defined(OS_WIN)
 | 
					
						
							|  |  |  |     auto integrity_level = process_metric.second->GetIntegrityLevel(); | 
					
						
							|  |  |  |     auto sandboxed = ProcessMetric::IsSandboxed(integrity_level); | 
					
						
							|  |  |  |     pid_dict.Set("integrityLevel", integrity_level); | 
					
						
							|  |  |  |     pid_dict.Set("sandboxed", sandboxed); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-04 13:27:35 -07:00
										 |  |  |     result.push_back(pid_dict); | 
					
						
							| 
									
										
										
										
											2017-04-17 04:59:16 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-27 21:07:35 -07:00
										 |  |  |   return result; | 
					
						
							| 
									
										
										
										
											2017-04-17 04:59:16 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-30 13:00:55 -07:00
										 |  |  | v8::Local<v8::Value> App::GetGPUFeatureStatus(v8::Isolate* isolate) { | 
					
						
							|  |  |  |   auto status = content::GetFeatureStatus(); | 
					
						
							| 
									
										
										
										
											2017-11-23 13:43:11 +01:00
										 |  |  |   base::DictionaryValue temp; | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   return gin::ConvertToV8(isolate, status ? *status : temp); | 
					
						
							| 
									
										
										
										
											2017-05-30 19:06:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 07:59:23 -07:00
										 |  |  | v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate, | 
					
						
							|  |  |  |                                        const std::string& info_type) { | 
					
						
							|  |  |  |   auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance(); | 
					
						
							| 
									
										
										
										
											2019-11-01 15:10:32 +09:00
										 |  |  |   gin_helper::Promise<base::DictionaryValue> promise(isolate); | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |   v8::Local<v8::Promise> handle = promise.GetHandle(); | 
					
						
							| 
									
										
										
										
											2018-10-02 03:34:52 +02:00
										 |  |  |   if (info_type != "basic" && info_type != "complete") { | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     promise.RejectWithErrorMessage( | 
					
						
							| 
									
										
										
										
											2018-10-02 03:34:52 +02:00
										 |  |  |         "Invalid info type. Use 'basic' or 'complete'"); | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     return handle; | 
					
						
							| 
									
										
										
										
											2018-10-02 03:34:52 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   std::string reason; | 
					
						
							|  |  |  |   if (!gpu_data_manager->GpuAccessAllowed(&reason)) { | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     promise.RejectWithErrorMessage("GPU access not allowed. Reason: " + reason); | 
					
						
							|  |  |  |     return handle; | 
					
						
							| 
									
										
										
										
											2018-09-27 07:59:23 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   auto* const info_mgr = GPUInfoManager::GetInstance(); | 
					
						
							|  |  |  |   if (info_type == "complete") { | 
					
						
							| 
									
										
										
										
											2018-10-15 08:26:47 -07:00
										 |  |  | #if defined(OS_WIN) || defined(OS_MACOSX)
 | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     info_mgr->FetchCompleteInfo(std::move(promise)); | 
					
						
							| 
									
										
										
										
											2018-10-02 03:34:52 +02:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     info_mgr->FetchBasicInfo(std::move(promise)); | 
					
						
							| 
									
										
										
										
											2018-10-02 03:34:52 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-09-27 07:59:23 -07:00
										 |  |  |   } else /* (info_type == "basic") */ { | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |     info_mgr->FetchBasicInfo(std::move(promise)); | 
					
						
							| 
									
										
										
										
											2018-09-27 07:59:23 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-02-21 12:32:44 +00:00
										 |  |  |   return handle; | 
					
						
							| 
									
										
										
										
											2018-09-27 07:59:23 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 06:32:09 +02:00
										 |  |  | static void RemoveNoSandboxSwitch(base::CommandLine* command_line) { | 
					
						
							| 
									
										
										
										
											2018-09-14 17:07:49 -07:00
										 |  |  |   if (command_line->HasSwitch(service_manager::switches::kNoSandbox)) { | 
					
						
							| 
									
										
										
										
											2018-10-10 06:32:09 +02:00
										 |  |  |     const base::CommandLine::CharType* noSandboxArg = | 
					
						
							|  |  |  |         FILE_PATH_LITERAL("--no-sandbox"); | 
					
						
							| 
									
										
										
										
											2017-06-28 08:33:06 -07:00
										 |  |  |     base::CommandLine::StringVector modified_command_line; | 
					
						
							|  |  |  |     for (auto& arg : command_line->argv()) { | 
					
						
							|  |  |  |       if (arg.compare(noSandboxArg) != 0) { | 
					
						
							|  |  |  |         modified_command_line.push_back(arg); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-06-26 14:13:41 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |     command_line->InitFromArgv(modified_command_line); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-10-10 06:32:09 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | void App::EnableSandbox(gin_helper::ErrorThrower thrower) { | 
					
						
							| 
									
										
										
										
											2018-10-10 06:32:09 +02:00
										 |  |  |   if (Browser::Get()->is_ready()) { | 
					
						
							| 
									
										
										
										
											2019-08-23 15:49:54 -07:00
										 |  |  |     thrower.ThrowError( | 
					
						
							| 
									
										
										
										
											2018-10-10 06:32:09 +02:00
										 |  |  |         "app.enableSandbox() can only be called " | 
					
						
							|  |  |  |         "before app is ready"); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   auto* command_line = base::CommandLine::ForCurrentProcess(); | 
					
						
							|  |  |  |   RemoveNoSandboxSwitch(command_line); | 
					
						
							|  |  |  |   command_line->AppendSwitch(switches::kEnableSandbox); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 16:34:42 -07:00
										 |  |  | void App::SetUserAgentFallback(const std::string& user_agent) { | 
					
						
							|  |  |  |   AtomBrowserClient::Get()->SetUserAgent(user_agent); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::string App::GetUserAgentFallback() { | 
					
						
							|  |  |  |   return AtomBrowserClient::Get()->GetUserAgent(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 15:47:18 -07:00
										 |  |  | void App::SetBrowserClientCanUseCustomSiteInstance(bool should_disable) { | 
					
						
							|  |  |  |   AtomBrowserClient::Get()->SetCanUseCustomSiteInstance(should_disable); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | bool App::CanBrowserClientUseCustomSiteInstance() { | 
					
						
							|  |  |  |   return AtomBrowserClient::Get()->CanUseCustomSiteInstance(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-01 00:37:12 +10:00
										 |  |  | #if defined(OS_MACOSX)
 | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  | bool App::MoveToApplicationsFolder(gin_helper::ErrorThrower thrower, | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |                                    gin::Arguments* args) { | 
					
						
							|  |  |  |   return AtomBundleMover::Move(thrower, args); | 
					
						
							| 
									
										
										
										
											2017-09-01 00:37:12 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool App::IsInApplicationsFolder() { | 
					
						
							| 
									
										
										
										
											2019-09-06 14:52:54 +09:00
										 |  |  |   return AtomBundleMover::IsCurrentAppInApplicationsFolder(); | 
					
						
							| 
									
										
										
										
											2017-09-01 00:37:12 +10:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | int DockBounce(gin_helper::Arguments* args) { | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |   int request_id = -1; | 
					
						
							| 
									
										
										
										
											2019-07-31 08:20:45 -07:00
										 |  |  |   std::string type = "informational"; | 
					
						
							|  |  |  |   args->GetNext(&type); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |   if (type == "critical") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:11:41 +02:00
										 |  |  |     request_id = Browser::Get()->DockBounce(Browser::BounceType::CRITICAL); | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |   else if (type == "informational") | 
					
						
							| 
									
										
										
										
											2019-05-03 20:11:41 +02:00
										 |  |  |     request_id = Browser::Get()->DockBounce(Browser::BounceType::INFORMATIONAL); | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |   return request_id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | void DockSetMenu(electron::api::Menu* menu) { | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |   Browser::Get()->DockSetMenu(menu->model()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | v8::Local<v8::Value> App::GetDockAPI(v8::Isolate* isolate) { | 
					
						
							|  |  |  |   if (dock_.IsEmpty()) { | 
					
						
							|  |  |  |     // Initialize the Dock API, the methods are bound to "dock" which exists
 | 
					
						
							|  |  |  |     // for the lifetime of "app"
 | 
					
						
							|  |  |  |     auto browser = base::Unretained(Browser::Get()); | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |     gin_helper::Dictionary dock_obj = gin::Dictionary::CreateEmpty(isolate); | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |     dock_obj.SetMethod("bounce", &DockBounce); | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |     dock_obj.SetMethod( | 
					
						
							|  |  |  |         "cancelBounce", | 
					
						
							|  |  |  |         base::BindRepeating(&Browser::DockCancelBounce, browser)); | 
					
						
							|  |  |  |     dock_obj.SetMethod( | 
					
						
							|  |  |  |         "downloadFinished", | 
					
						
							|  |  |  |         base::BindRepeating(&Browser::DockDownloadFinished, browser)); | 
					
						
							|  |  |  |     dock_obj.SetMethod( | 
					
						
							|  |  |  |         "setBadge", base::BindRepeating(&Browser::DockSetBadgeText, browser)); | 
					
						
							|  |  |  |     dock_obj.SetMethod( | 
					
						
							|  |  |  |         "getBadge", base::BindRepeating(&Browser::DockGetBadgeText, browser)); | 
					
						
							|  |  |  |     dock_obj.SetMethod("hide", | 
					
						
							|  |  |  |                        base::BindRepeating(&Browser::DockHide, browser)); | 
					
						
							|  |  |  |     dock_obj.SetMethod("show", | 
					
						
							|  |  |  |                        base::BindRepeating(&Browser::DockShow, browser)); | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |     dock_obj.SetMethod("isVisible", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                        base::BindRepeating(&Browser::DockIsVisible, browser)); | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  |     dock_obj.SetMethod("setMenu", &DockSetMenu); | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |     dock_obj.SetMethod("setIcon", | 
					
						
							|  |  |  |                        base::BindRepeating(&Browser::DockSetIcon, browser)); | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dock_.Reset(isolate, dock_obj.GetHandle()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return v8::Local<v8::Value>::New(isolate, dock_); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-01 00:37:12 +10:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  | gin::Handle<App> App::Create(v8::Isolate* isolate) { | 
					
						
							|  |  |  |   return gin::CreateHandle(isolate, new App(isolate)); | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void App::BuildPrototype(v8::Isolate* isolate, | 
					
						
							|  |  |  |                          v8::Local<v8::FunctionTemplate> prototype) { | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   prototype->SetClassName(gin::StringToV8(isolate, "App")); | 
					
						
							| 
									
										
										
										
											2014-10-30 22:27:29 +08:00
										 |  |  |   auto browser = base::Unretained(Browser::Get()); | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |       .SetMethod("quit", base::BindRepeating(&Browser::Quit, browser)) | 
					
						
							|  |  |  |       .SetMethod("exit", base::BindRepeating(&Browser::Exit, browser)) | 
					
						
							|  |  |  |       .SetMethod("focus", base::BindRepeating(&Browser::Focus, browser)) | 
					
						
							|  |  |  |       .SetMethod("getVersion", | 
					
						
							|  |  |  |                  base::BindRepeating(&Browser::GetVersion, browser)) | 
					
						
							|  |  |  |       .SetMethod("setVersion", | 
					
						
							|  |  |  |                  base::BindRepeating(&Browser::SetVersion, browser)) | 
					
						
							| 
									
										
										
										
											2019-04-30 13:55:33 -07:00
										 |  |  |       .SetMethod("_getName", base::BindRepeating(&Browser::GetName, browser)) | 
					
						
							|  |  |  |       .SetMethod("_setName", base::BindRepeating(&Browser::SetName, browser)) | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |       .SetMethod("isReady", base::BindRepeating(&Browser::is_ready, browser)) | 
					
						
							|  |  |  |       .SetMethod("whenReady", base::BindRepeating(&Browser::WhenReady, browser)) | 
					
						
							| 
									
										
										
										
											2014-11-17 13:05:06 +08:00
										 |  |  |       .SetMethod("addRecentDocument", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::AddRecentDocument, browser)) | 
					
						
							| 
									
										
										
										
											2014-11-17 16:13:47 +08:00
										 |  |  |       .SetMethod("clearRecentDocuments", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::ClearRecentDocuments, browser)) | 
					
						
							| 
									
										
										
										
											2015-11-03 15:09:31 +08:00
										 |  |  |       .SetMethod("setAppUserModelId", | 
					
						
							| 
									
										
										
										
											2019-04-29 17:40:39 -07:00
										 |  |  |                  base::BindRepeating(&Browser::SetAppUserModelID, browser)) | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |       .SetMethod( | 
					
						
							|  |  |  |           "isDefaultProtocolClient", | 
					
						
							|  |  |  |           base::BindRepeating(&Browser::IsDefaultProtocolClient, browser)) | 
					
						
							|  |  |  |       .SetMethod( | 
					
						
							|  |  |  |           "setAsDefaultProtocolClient", | 
					
						
							|  |  |  |           base::BindRepeating(&Browser::SetAsDefaultProtocolClient, browser)) | 
					
						
							|  |  |  |       .SetMethod( | 
					
						
							|  |  |  |           "removeAsDefaultProtocolClient", | 
					
						
							|  |  |  |           base::BindRepeating(&Browser::RemoveAsDefaultProtocolClient, browser)) | 
					
						
							| 
									
										
										
										
											2019-11-06 17:50:33 -08:00
										 |  |  |       .SetMethod( | 
					
						
							|  |  |  |           "getApplicationNameForProtocol", | 
					
						
							|  |  |  |           base::BindRepeating(&Browser::GetApplicationNameForProtocol, browser)) | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |       .SetMethod("_setBadgeCount", | 
					
						
							|  |  |  |                  base::BindRepeating(&Browser::SetBadgeCount, browser)) | 
					
						
							|  |  |  |       .SetMethod("_getBadgeCount", | 
					
						
							|  |  |  |                  base::BindRepeating(&Browser::GetBadgeCount, browser)) | 
					
						
							| 
									
										
										
										
											2017-01-30 14:01:40 -08:00
										 |  |  |       .SetMethod("getLoginItemSettings", &App::GetLoginItemSettings) | 
					
						
							| 
									
										
										
										
											2016-07-11 10:57:53 -07:00
										 |  |  |       .SetMethod("setLoginItemSettings", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::SetLoginItemSettings, browser)) | 
					
						
							| 
									
										
										
										
											2019-03-14 13:39:52 -07:00
										 |  |  |       .SetMethod("isEmojiPanelSupported", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::IsEmojiPanelSupported, browser)) | 
					
						
							|  |  |  |       .SetProperty("badgeCount", | 
					
						
							|  |  |  |                    base::BindRepeating(&Browser::GetBadgeCount, browser), | 
					
						
							|  |  |  |                    base::BindRepeating(&Browser::SetBadgeCount, browser)) | 
					
						
							| 
									
										
										
										
											2019-04-30 13:55:33 -07:00
										 |  |  |       .SetProperty("name", base::BindRepeating(&Browser::GetName, browser), | 
					
						
							|  |  |  |                    base::BindRepeating(&Browser::SetName, browser)) | 
					
						
							| 
									
										
										
										
											2016-01-29 22:51:06 +01:00
										 |  |  | #if defined(OS_MACOSX)
 | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |       .SetMethod("hide", base::BindRepeating(&Browser::Hide, browser)) | 
					
						
							|  |  |  |       .SetMethod("show", base::BindRepeating(&Browser::Show, browser)) | 
					
						
							| 
									
										
										
										
											2016-04-29 22:05:36 -07:00
										 |  |  |       .SetMethod("setUserActivity", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::SetUserActivity, browser)) | 
					
						
							| 
									
										
										
										
											2016-07-07 14:29:43 -07:00
										 |  |  |       .SetMethod("getCurrentActivityType", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::GetCurrentActivityType, browser)) | 
					
						
							|  |  |  |       .SetMethod( | 
					
						
							|  |  |  |           "invalidateCurrentActivity", | 
					
						
							|  |  |  |           base::BindRepeating(&Browser::InvalidateCurrentActivity, browser)) | 
					
						
							| 
									
										
										
										
											2019-06-06 22:16:03 -07:00
										 |  |  |       .SetMethod("resignCurrentActivity", | 
					
						
							|  |  |  |                  base::BindRepeating(&Browser::ResignCurrentActivity, browser)) | 
					
						
							| 
									
										
										
										
											2017-06-26 16:14:44 -03:00
										 |  |  |       .SetMethod("updateCurrentActivity", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::UpdateCurrentActivity, browser)) | 
					
						
							| 
									
										
										
										
											2018-11-13 17:12:24 -05:00
										 |  |  |       .SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder) | 
					
						
							|  |  |  |       .SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder) | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-10-10 13:30:58 -07:00
										 |  |  |       .SetMethod("setAboutPanelOptions", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::SetAboutPanelOptions, browser)) | 
					
						
							| 
									
										
										
										
											2018-11-11 22:52:27 -05:00
										 |  |  |       .SetMethod("showAboutPanel", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::ShowAboutPanel, browser)) | 
					
						
							| 
									
										
										
										
											2019-03-14 13:39:52 -07:00
										 |  |  | #if defined(OS_MACOSX) || defined(OS_WIN)
 | 
					
						
							|  |  |  |       .SetMethod("showEmojiPanel", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::ShowEmojiPanel, browser)) | 
					
						
							| 
									
										
										
										
											2019-04-04 19:49:04 -07:00
										 |  |  |       .SetProperty("accessibilitySupportEnabled", | 
					
						
							|  |  |  |                    &App::IsAccessibilitySupportEnabled, | 
					
						
							|  |  |  |                    &App::SetAccessibilitySupportEnabled) | 
					
						
							| 
									
										
										
										
											2019-03-14 13:39:52 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | #if defined(OS_WIN)
 | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |       .SetMethod("setUserTasks", | 
					
						
							|  |  |  |                  base::BindRepeating(&Browser::SetUserTasks, browser)) | 
					
						
							| 
									
										
										
										
											2016-08-12 16:31:17 +07:00
										 |  |  |       .SetMethod("getJumpListSettings", &App::GetJumpListSettings) | 
					
						
							|  |  |  |       .SetMethod("setJumpList", &App::SetJumpList) | 
					
						
							| 
									
										
										
										
											2016-07-01 17:39:01 +09:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #if defined(OS_LINUX)
 | 
					
						
							|  |  |  |       .SetMethod("isUnityRunning", | 
					
						
							| 
									
										
										
										
											2019-04-26 21:42:56 -07:00
										 |  |  |                  base::BindRepeating(&Browser::IsUnityRunning, browser)) | 
					
						
							| 
									
										
										
										
											2014-11-17 17:19:41 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-04-04 09:36:01 +09:00
										 |  |  |       .SetMethod("setAppPath", &App::SetAppPath) | 
					
						
							|  |  |  |       .SetMethod("getAppPath", &App::GetAppPath) | 
					
						
							| 
									
										
										
										
											2015-01-18 17:52:15 -08:00
										 |  |  |       .SetMethod("setPath", &App::SetPath) | 
					
						
							|  |  |  |       .SetMethod("getPath", &App::GetPath) | 
					
						
							| 
									
										
										
										
											2019-04-18 22:04:58 -07:00
										 |  |  |       .SetMethod("setAppLogsPath", &App::SetAppLogsPath) | 
					
						
							| 
									
										
										
										
											2015-04-28 15:49:16 -07:00
										 |  |  |       .SetMethod("setDesktopName", &App::SetDesktopName) | 
					
						
							| 
									
										
										
										
											2015-09-16 17:16:21 +09:00
										 |  |  |       .SetMethod("getLocale", &App::GetLocale) | 
					
						
							| 
									
										
										
										
											2018-11-20 21:33:23 +01:00
										 |  |  |       .SetMethod("getLocaleCountryCode", &App::GetLocaleCountryCode) | 
					
						
							| 
									
										
										
										
											2016-04-19 10:47:28 +05:30
										 |  |  | #if defined(USE_NSS_CERTS)
 | 
					
						
							| 
									
										
										
										
											2016-04-20 08:45:49 +05:30
										 |  |  |       .SetMethod("importCertificate", &App::ImportCertificate) | 
					
						
							| 
									
										
										
										
											2016-04-18 21:05:33 +05:30
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-05-08 01:29:18 +10:00
										 |  |  |       .SetMethod("hasSingleInstanceLock", &App::HasSingleInstanceLock) | 
					
						
							|  |  |  |       .SetMethod("requestSingleInstanceLock", &App::RequestSingleInstanceLock) | 
					
						
							|  |  |  |       .SetMethod("releaseSingleInstanceLock", &App::ReleaseSingleInstanceLock) | 
					
						
							| 
									
										
										
										
											2016-06-06 20:19:55 +09:00
										 |  |  |       .SetMethod("relaunch", &App::Relaunch) | 
					
						
							| 
									
										
										
										
											2019-04-04 19:49:04 -07:00
										 |  |  |       .SetMethod("_isAccessibilitySupportEnabled", | 
					
						
							| 
									
										
										
										
											2016-07-11 14:32:14 -07:00
										 |  |  |                  &App::IsAccessibilitySupportEnabled) | 
					
						
							| 
									
										
										
										
											2019-04-04 19:49:04 -07:00
										 |  |  |       .SetMethod("_setAccessibilitySupportEnabled", | 
					
						
							| 
									
										
										
										
											2017-08-24 11:22:28 -03:00
										 |  |  |                  &App::SetAccessibilitySupportEnabled) | 
					
						
							| 
									
										
										
										
											2016-06-06 20:19:55 +09:00
										 |  |  |       .SetMethod("disableHardwareAcceleration", | 
					
						
							| 
									
										
										
										
											2016-11-03 00:27:16 +05:30
										 |  |  |                  &App::DisableHardwareAcceleration) | 
					
						
							| 
									
										
										
										
											2017-07-14 01:27:03 +03:00
										 |  |  |       .SetMethod("disableDomainBlockingFor3DAPIs", | 
					
						
							|  |  |  |                  &App::DisableDomainBlockingFor3DAPIs) | 
					
						
							| 
									
										
										
										
											2017-04-17 04:59:16 -07:00
										 |  |  |       .SetMethod("getFileIcon", &App::GetFileIcon) | 
					
						
							| 
									
										
										
										
											2017-05-26 07:51:17 -07:00
										 |  |  |       .SetMethod("getAppMetrics", &App::GetAppMetrics) | 
					
						
							| 
									
										
										
										
											2017-05-30 19:06:08 +02:00
										 |  |  |       .SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus) | 
					
						
							| 
									
										
										
										
											2018-09-27 07:59:23 -07:00
										 |  |  |       .SetMethod("getGPUInfo", &App::GetGPUInfo) | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | #if defined(MAS_BUILD)
 | 
					
						
							| 
									
										
										
										
											2018-02-13 05:25:06 +11:00
										 |  |  |       .SetMethod("startAccessingSecurityScopedResource", | 
					
						
							|  |  |  |                  &App::StartAccessingSecurityScopedResource) | 
					
						
							| 
									
										
										
										
											2019-02-14 14:29:20 -08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #if defined(OS_MACOSX)
 | 
					
						
							|  |  |  |       .SetProperty("dock", &App::GetDockAPI) | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-05-01 16:34:42 -07:00
										 |  |  |       .SetProperty("userAgentFallback", &App::GetUserAgentFallback, | 
					
						
							|  |  |  |                    &App::SetUserAgentFallback) | 
					
						
							| 
									
										
										
										
											2019-05-31 15:47:18 -07:00
										 |  |  |       .SetMethod("enableSandbox", &App::EnableSandbox) | 
					
						
							|  |  |  |       .SetProperty("allowRendererProcessReuse", | 
					
						
							|  |  |  |                    &App::CanBrowserClientUseCustomSiteInstance, | 
					
						
							|  |  |  |                    &App::SetBrowserClientCanUseCustomSiteInstance); | 
					
						
							| 
									
										
										
										
											2013-05-30 19:24:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 17:13:46 +08:00
										 |  |  | }  // namespace api
 | 
					
						
							| 
									
										
										
										
											2013-12-05 10:32:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | }  // namespace electron
 | 
					
						
							| 
									
										
										
										
											2013-12-05 10:32:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 17:13:46 +08:00
										 |  |  | namespace { | 
					
						
							| 
									
										
										
										
											2013-05-17 15:39:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:55:30 -04:00
										 |  |  | void Initialize(v8::Local<v8::Object> exports, | 
					
						
							|  |  |  |                 v8::Local<v8::Value> unused, | 
					
						
							|  |  |  |                 v8::Local<v8::Context> context, | 
					
						
							|  |  |  |                 void* priv) { | 
					
						
							| 
									
										
										
										
											2014-06-29 20:48:44 +08:00
										 |  |  |   v8::Isolate* isolate = context->GetIsolate(); | 
					
						
							| 
									
										
										
										
											2019-10-24 14:47:58 +09:00
										 |  |  |   gin_helper::Dictionary dict(isolate, exports); | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |   dict.Set("App", electron::api::App::GetConstructor(isolate) | 
					
						
							| 
									
										
										
										
											2019-01-09 11:17:05 -08:00
										 |  |  |                       ->GetFunction(context) | 
					
						
							|  |  |  |                       .ToLocalChecked()); | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  |   dict.Set("app", electron::api::App::Create(isolate)); | 
					
						
							| 
									
										
										
										
											2014-04-17 17:13:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-08 23:59:52 +05:30
										 |  |  | NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_app, Initialize) |