|
|
@@ -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
|