<commit_before>#include "nw_chrome_browser_hooks.h"

// base
#include "base/command_line.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"

#if defined(OS_WIN)
#include "base/win/scoped_gdi_object.h"
#endif // OS_WIN

// chrome
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"

#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/crx_file/id_util.h"

// content
//#include "content/common/dom_storage/dom_storage_map.h"
//#include "content/browser/dom_storage/dom_storage_area.h"
#include "content/nw/src/common/shell_switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/result_codes.h"

// content/nw
#include "content/nw/src/nw_base.h"
#include "content/nw/src/nw_package.h"
#include "content/nw/src/policy_cert_verifier.h"

// extensions
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"

#include "net/cert/x509_certificate.h"
#include "net/cert/test_root_certs.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/transaction.h"
#include "storage/common/database/database_identifier.h"
#include "services/network/network_service.h"
#include "ui/gfx/image/image.h"

#if defined(OS_WIN)
#define _USE_MATH_DEFINES
#include <math.h>
#endif

using content::DevToolsAgentHost;
using content::RenderFrameHost;
using extensions::EventRouter;
using extensions::Extension;
using extensions::ExtensionPrefs;
using extensions::ExtensionRegistry;

namespace nw
{

namespace {

gfx::Image g_app_icon;
int g_cdt_process_id = -1;
std::string g_extension_id;
bool g_reloading_app = false;
net::CertificateList trust_anchors;

#if defined(OS_WIN)
base::win::ScopedHICON g_window_hicon;
base::win::ScopedHICON g_app_hicon;
#endif

}

void ReloadExtensionHook(const extensions::Extension* extension) {
  g_reloading_app = true;
  KeepAliveRegistry::GetInstance()->Register(KeepAliveOrigin::APP_CONTROLLER, KeepAliveRestartOption::ENABLED);
  //keep alive count is paired with
  //appwindow's lifetime, so it's
  //needed to keep alive during
  //reload
}

void CreateAppWindowHook(extensions::AppWindow* app_window) {
  if (g_reloading_app) {
    g_reloading_app = false;
    KeepAliveRegistry::GetInstance()->Unregister(KeepAliveOrigin::APP_CONTROLLER, KeepAliveRestartOption::ENABLED);
  }
}

bool IsReloadingApp() {
  return g_reloading_app;
}

typedef void (*SendEventToAppFn)(const std::string& event_name, std::unique_ptr<base::ListValue> event_args);
CONTENT_EXPORT extern SendEventToAppFn gSendEventToApp;

void SendEventToApp(const std::string& event_name, std::unique_ptr<base::ListValue> event_args) {
  Profile* profile = ProfileManager::GetActiveUserProfile();
  const extensions::ExtensionSet& extensions =
    ExtensionRegistry::Get(profile)->enabled_extensions();
  ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile);

  for (extensions::ExtensionSet::const_iterator it = extensions.begin();
       it != extensions.end(); ++it) {
    const Extension* extension = it->get();
    if (extension_prefs->IsExtensionRunning(extension->id()) &&
        extension->location() == extensions::Manifest::COMMAND_LINE) {
      std::unique_ptr<extensions::Event> event(new extensions::Event(extensions::events::UNKNOWN,
                                                                event_name,
                                                                std::move(event_args)));
      event->restrict_to_browser_context = profile;
      EventRouter::Get(profile)
        ->DispatchEventToExtension(extension->id(), std::move(event));
    }
  }
}

typedef bool (*CheckStoragePartitionMatchesFn)(int render_process_id, const GURL& url);
CONTENT_EXPORT extern CheckStoragePartitionMatchesFn gCheckStoragePartitionMatches;

bool CheckStoragePartitionMatches(int render_process_id, const GURL& url) {
  return render_process_id == g_cdt_process_id && url.SchemeIs(content_settings::kChromeDevToolsScheme);
}

bool InspectElement(content::WebContents* web_contents, int x, int y) {
  scoped_refptr<DevToolsAgentHost> agent_host(DevToolsAgentHost::GetOrCreateFor(web_contents));
  DevToolsWindow* window = DevToolsWindow::FindDevToolsWindow(agent_host.get());
  if (!window)
    return false;<commit_msg>Fix extensions::Manifest::COMMAND_LINE<commit_after>#include "nw_chrome_browser_hooks.h"

// base
#include "base/command_line.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"

#if defined(OS_WIN)
#include "base/win/scoped_gdi_object.h"
#endif // OS_WIN

// chrome
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"

#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/crx_file/id_util.h"

// content
//#include "content/common/dom_storage/dom_storage_map.h"
//#include "content/browser/dom_storage/dom_storage_area.h"
#include "content/nw/src/common/shell_switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/result_codes.h"

// content/nw
#include "content/nw/src/nw_base.h"
#include "content/nw/src/nw_package.h"
#include "content/nw/src/policy_cert_verifier.h"

// extensions
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"

#include "net/cert/x509_certificate.h"
#include "net/cert/test_root_certs.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/transaction.h"
#include "storage/common/database/database_identifier.h"
#include "services/network/network_service.h"
#include "ui/gfx/image/image.h"

#if defined(OS_WIN)
#define _USE_MATH_DEFINES
#include <math.h>
#endif

using content::DevToolsAgentHost;
using content::RenderFrameHost;
using extensions::EventRouter;
using extensions::Extension;
using extensions::ExtensionPrefs;
using extensions::ExtensionRegistry;

namespace nw
{

namespace {

gfx::Image g_app_icon;
int g_cdt_process_id = -1;
std::string g_extension_id;
bool g_reloading_app = false;
net::CertificateList trust_anchors;

#if defined(OS_WIN)
base::win::ScopedHICON g_window_hicon;
base::win::ScopedHICON g_app_hicon;
#endif

}

void ReloadExtensionHook(const extensions::Extension* extension) {
  g_reloading_app = true;
  KeepAliveRegistry::GetInstance()->Register(KeepAliveOrigin::APP_CONTROLLER, KeepAliveRestartOption::ENABLED);
  //keep alive count is paired with
  //appwindow's lifetime, so it's
  //needed to keep alive during
  //reload
}

void CreateAppWindowHook(extensions::AppWindow* app_window) {
  if (g_reloading_app) {
    g_reloading_app = false;
    KeepAliveRegistry::GetInstance()->Unregister(KeepAliveOrigin::APP_CONTROLLER, KeepAliveRestartOption::ENABLED);
  }
}

bool IsReloadingApp() {
  return g_reloading_app;
}

typedef void (*SendEventToAppFn)(const std::string& event_name, std::unique_ptr<base::ListValue> event_args);
CONTENT_EXPORT extern SendEventToAppFn gSendEventToApp;

void SendEventToApp(const std::string& event_name, std::unique_ptr<base::ListValue> event_args) {
  Profile* profile = ProfileManager::GetActiveUserProfile();
  const extensions::ExtensionSet& extensions =
    ExtensionRegistry::Get(profile)->enabled_extensions();
  ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile);

  for (extensions::ExtensionSet::const_iterator it = extensions.begin();
       it != extensions.end(); ++it) {
    const Extension* extension = it->get();
    if (extension_prefs->IsExtensionRunning(extension->id()) &&
        extension->location() == extensions::mojom::ManifestLocation::kCommandLine) {
      std::unique_ptr<extensions::Event> event(new extensions::Event(extensions::events::UNKNOWN,
                                                                event_name,
                                                                std::move(event_args)));
      event->restrict_to_browser_context = profile;
      EventRouter::Get(profile)
        ->DispatchEventToExtension(extension->id(), std::move(event));
    }
  }
}

typedef bool (*CheckStoragePartitionMatchesFn)(int render_process_id, const GURL& url);
CONTENT_EXPORT extern CheckStoragePartitionMatchesFn gCheckStoragePartitionMatches;

bool CheckStoragePartitionMatches(int render_process_id, const GURL& url) {
  return render_process_id == g_cdt_process_id && url.SchemeIs(content_settings::kChromeDevToolsScheme);
}

bool InspectElement(content::WebContents* web_contents, int x, int y) {
  scoped_refptr<DevToolsAgentHost> agent_host(DevToolsAgentHost::GetOrCreateFor(web_contents));
  DevToolsWindow* window = DevToolsWindow::FindDevToolsWindow(agent_host.get());
  if (!window)
    return false;
{'fraction_non_alphanumeric': 0.12253829321663019, 'fraction_numerical': 0.0007293946024799417, 'mean_word_length': 6.058558558558558, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3504711', 'n_tokens_mistral': 3543, 'n_tokens_neox': 3516, 'n_words': 548}