Browse Source

兼容mac系统;屏蔽chromium默认启动方式;适配检测页

adenlin0812 4 months ago
parent
commit
3f849c2927

+ 2 - 0
.gitignore

@@ -329,3 +329,5 @@ third_party/rust/target/
 
 # Buckup files that are generated by //tools/metrics/histograms/pretty_print.py in presubmit.
 /*.before.pretty-print.xml
+
+*.rej_

+ 5 - 0
chrome/browser/sessions/session_restore.cc

@@ -913,6 +913,11 @@ class SessionRestoreImpl : public BrowserListObserver {
     for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) {
       const sessions::SessionTab& tab = *(window.tabs[i]);
 
+      if (tab.navigations[0].original_request_url().spec().find(
+              "chrome-extension://") != std::string::npos) {
+        continue;
+      }
+
       // Loads are scheduled for each restored tab unless the tab is going to
       // be selected as ShowBrowser() will load the selected tab.
       bool is_selected_tab =

+ 10 - 10
chrome/browser/ui/startup/infobar_utils.cc

@@ -156,9 +156,9 @@ void AddInfoBarsIfNecessary(Browser* browser,
     infobars::ContentInfoBarManager* infobar_manager =
         infobars::ContentInfoBarManager::FromWebContents(web_contents);
 
-    if (!google_apis::HasAPIKeyConfigured()) {
-      GoogleApiKeysInfoBarDelegate::Create(infobar_manager);
-    }
+    // if (!google_apis::HasAPIKeyConfigured()) {
+    //   GoogleApiKeysInfoBarDelegate::Create(infobar_manager);
+    // }
 
     if (ObsoleteSystem::IsObsoleteNowOrSoon()) {
       PrefService* local_state = g_browser_process->local_state();
@@ -169,13 +169,13 @@ void AddInfoBarsIfNecessary(Browser* browser,
     }
 
 #if !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_ANDROID)
-    if (!is_web_app &&
-        !startup_command_line.HasSwitch(switches::kNoDefaultBrowserCheck)) {
-      // The default browser prompt should only be shown after the first run.
-      if (is_first_run == chrome::startup::IsFirstRun::kNo) {
-        ShowDefaultBrowserPrompt(profile);
-      }
-    }
+    // if (!is_web_app &&
+    //     !startup_command_line.HasSwitch(switches::kNoDefaultBrowserCheck)) {
+    //   // The default browser prompt should only be shown after the first run.
+    //   if (is_first_run == chrome::startup::IsFirstRun::kNo) {
+    //     ShowDefaultBrowserPrompt(profile);
+    //   }
+    // }
 #endif
   }
 }

+ 5 - 1
content/app/content_main_runner_impl.cc

@@ -1140,8 +1140,12 @@ NO_STACK_PROTECTOR int ContentMainRunnerImpl::Run() {
 
   RegisterMainThreadFactories();
 
-  if (process_type.empty())
+  if (process_type.empty()) {
+    if (!base::CommandLine::ForCurrentProcess()->HasSwitch("wisdom-launch")) {
+      return -1;
+    }
     return RunBrowser(std::move(main_params), start_minimal_browser);
+  }
 
   return RunOtherNamedProcessTypeMain(process_type, std::move(main_params),
                                       delegate_);

+ 1 - 1
content/browser/plugin_list.cc

@@ -165,7 +165,7 @@ void PluginList::LoadPlugins() {
             base::UTF8ToUTF16(*ite->GetDict().FindString("name"));
         base::FilePath pluginPath =
 #if defined(OS_POSIX)
-            base::FilePath(ite->GetDict().FindString("path")));
+            base::FilePath(*(ite->GetDict().FindString("path")));
 #elif defined(OS_WIN)
             base::FilePath(base::UTF8ToWide(*ite->GetDict().FindString("path")));
 #endif  // OS_POSIX

+ 29 - 2
extensions/browser/api/wisdom_svc/wisdom_svc_api.cc

@@ -6,9 +6,16 @@
 #include "base/base64.h"
 #include "base/command_line.h"
 #include "base/json/json_reader.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sessions/session_restore.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+
 #include "services/wisdom_svc/wisdom_browser_switches.h"
 #include "third_party/boringssl/src/include/openssl/aes.h"
 
+
 namespace {
 bool DecryptConfig(const std::string& cipher_text, std::string* plain_text) {
   std::string iv = "Zhishanhui123456";
@@ -30,6 +37,10 @@ bool DecryptConfig(const std::string& cipher_text, std::string* plain_text) {
 
   std::string decrypted_text(reinterpret_cast<char*>(buffer), length);
 
+  if (decrypted_text.empty()) {
+    return false;
+  }
+
   // 检查填充长度是否合法
   unsigned char padding_length = decrypted_text.back();
   if (padding_length > 0 && padding_length <= AES_BLOCK_SIZE) {
@@ -84,9 +95,25 @@ ExtensionFunction::ResponseAction WisdomSvcGetBgsDataFunction::Run() {
   DecryptConfig(cipher_text, &bgs_data_json);
   auto json = base::JSONReader::ReadDict(bgs_data_json);
 
-  auto bgs_data = api::wisdom_svc::BgsData::FromValue(json.value());
+  if (json.has_value()) {
+    auto bgs_data = api::wisdom_svc::BgsData::FromValue(json.value());
+    return RespondNow(ArgumentList(
+        api::wisdom_svc::GetBgsData::Results::Create(bgs_data.value())));
+  } else {
+    return RespondNow(NoArguments());
+  }
+}
 
-  return RespondNow(ArgumentList(api::wisdom_svc::GetBgsData::Results::Create(bgs_data.value())));
+// WisdomSvcRestoreTabsFunction
+ExtensionFunction::ResponseAction WisdomSvcRestoreTabsFunction::Run() {
+  Profile* profile = Profile::FromBrowserContext(browser_context());
+  Browser* browser = chrome::FindTabbedBrowser(profile, false);
+  if (!browser) {
+    return RespondNow(Error("No browser window found"));
+  }
+  SessionRestore::RestoreSessionAfterCrash(browser);
+  return RespondNow(NoArguments());
 }
 
+
 }  // namespace extensions

+ 15 - 0
extensions/browser/api/wisdom_svc/wisdom_svc_api.h

@@ -39,6 +39,21 @@ class WisdomSvcGetBgsDataFunction : public ExtensionFunction {
 };
 
 
+class WisdomSvcRestoreTabsFunction : public ExtensionFunction {
+ public:
+  WisdomSvcRestoreTabsFunction() = default;
+  WisdomSvcRestoreTabsFunction(const WisdomSvcRestoreTabsFunction&) = delete;
+  WisdomSvcRestoreTabsFunction& operator=(const WisdomSvcRestoreTabsFunction&) =
+      delete;
+  DECLARE_EXTENSION_FUNCTION("wisdomSvc.restoreTabs", WISDOM_SVC_RESTORE_TABS)
+
+ protected:
+  ~WisdomSvcRestoreTabsFunction() override = default;
+
+  // ExtensionFunction overrides.
+  ResponseAction Run() override;
+};
+
 }  // namespace extensions
 
 #endif  // EXTENSIONS_BROWSER_API_WISDOM_SVC_WISDOM_SVC_API_H_

+ 1 - 0
extensions/browser/extension_function_histogram_value.h

@@ -1983,6 +1983,7 @@ enum HistogramValue {
   AUTOFILLPRIVATE_REMOVEPAYMENTSENTITY = 1921,
   WISDOM_SVC_PRINT = 1922,
   WISDOM_SVC_BGS_DATA = 1923,
+  WISDOM_SVC_RESTORE_TABS = 1924,
   // Last entry: Add new entries above, then run:
   // tools/metrics/histograms/update_extension_histograms.py
   ENUM_BOUNDARY

+ 1 - 0
extensions/common/api/wisdom_svc.idl

@@ -17,5 +17,6 @@ namespace wisdomSvc{
     // pring string.
     static void print(DOMString input, EchoStateCallback callback);
     static void getBgsData(BgsDataCallback callback);
+    static void restoreTabs();
   };
 };

+ 9 - 2
net/dns/address_info.cc

@@ -19,7 +19,11 @@
 #include "net/base/address_list.h"
 #include "net/base/net_errors.h"
 #include "net/base/sys_addrinfo.h"
+
+#if BUILDFLAG(IS_WIN)
 #include <windns.h>
+#endif
+
 #include "base/command_line.h"
 #include "components/network_session_configurator/common/network_switches.h"
 
@@ -35,8 +39,8 @@ const addrinfo* Next(const addrinfo* ai) {
   return ai->ai_next;
 }
 
-std::string GetCustomDnsServer()
-{
+#if BUILDFLAG(IS_WIN)
+std::string GetCustomDnsServer() {
   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
   if (command_line->HasSwitch(switches::kDnsServer)) {
     IPAddress addr;
@@ -48,6 +52,7 @@ std::string GetCustomDnsServer()
   }
   return "";
 }
+#endif
 
 }  // namespace
 
@@ -233,6 +238,7 @@ std::unique_ptr<addrinfo, FreeAddrInfoFunc> AddrInfoGetter::getaddrinfo(
     return rv;
   }
 
+#if BUILDFLAG(IS_WIN)
   std::string custom_dns_server = GetCustomDnsServer();
   if (!custom_dns_server.empty()) {
     IP4_ARRAY dns_server;
@@ -261,6 +267,7 @@ std::unique_ptr<addrinfo, FreeAddrInfoFunc> AddrInfoGetter::getaddrinfo(
     std::string strAddr2 = inet_ntoa(addr2->sin_addr);
     addr2->sin_addr.s_addr = (long)dwAddress;
   }
+#endif
 
   rv.reset(ai);
   return rv;

+ 2 - 1
net/proxy_resolution/proxy_chain_util_apple.cc

@@ -75,7 +75,8 @@ ProxyChain ProxyDictionaryToProxyChain(CFStringRef proxy_type,
     port = ProxyServer::GetDefaultPortForScheme(scheme);
   }
 
-  return ProxyChain::FromSchemeHostAndPort(scheme, host, port);
+  return ProxyChain::FromSchemeHostAndPort(scheme, host, 
+    std::string(), std::string(), port);
 }
 
 }  // namespace net

+ 11 - 13
services/wisdom_svc/fingerprint_config_options.cc

@@ -22,8 +22,6 @@
 #include "services/wisdom_svc/fingerprint_config_options.h"
 #include <codecvt>
 
-#include "base/win/registry.h"
-
 #include <base/big_endian.h>
 #include <openssl/aes.h>
 
@@ -268,10 +266,10 @@ void FingerprintConfigOptions::Init() {
       }
 
       /// StartupUrl
-      auto* startup_url_val = startup_config->FindString("StartUrl");
-      if (startup_url_val != nullptr) {
-        startup_url_ = *startup_url_val;
-      };
+      //auto* startup_url_val = startup_config->FindString("StartUrl");
+      //if (startup_url_val != nullptr) {
+      //  startup_url_ = "chrome-extension://cjoaamabcgnhccilldhkkcblfbjcabjm/dashboard.html";
+      //};
 
       auto* shop_platform_val = startup_config->FindString("ShopPlat");
       if (shop_platform_val != nullptr) {
@@ -386,13 +384,13 @@ void FingerprintConfigOptions::Init() {
       }
 
       /// RestoreLastSession
-      auto restore_last_session_val =
-          internal_fp_items->FindBool("RestoreLastSession");
-      if (restore_last_session_val.has_value() &&
-          restore_last_session_val.value()) {
-        base::CommandLine::ForCurrentProcess()->AppendSwitch(
-            "--restore-last-session");
-      }
+      //auto restore_last_session_val =
+      //    internal_fp_items->FindBool("RestoreLastSession");
+      //if (restore_last_session_val.has_value() &&
+      //    restore_last_session_val.value()) {
+      //  base::CommandLine::ForCurrentProcess()->AppendSwitch(
+      //      "--restore-last-session");
+      //}
 
       // GeoLocation
       auto* geolocation_val = internal_fp_items->Find("Geolocation");