瀏覽代碼

add details for unmatch header, bug DOCUMENT_START not work, add a flag for logging

Carmelo Messina 4 年之前
父節點
當前提交
10a171ff5d
共有 1 個文件被更改,包括 156 次插入93 次删除
  1. 156 93
      build/patches/add-user-scripts.v5.patch

+ 156 - 93
build/patches/add-user-scripts.v5.patch

@@ -1,6 +1,6 @@
 From: uazo <uazo@users.noreply.github.com>
 From: uazo <uazo@users.noreply.github.com>
 Date: Fri, 18 Dec 2020 18:11:49 +0000
 Date: Fri, 18 Dec 2020 18:11:49 +0000
-Subject: Experimental user scripts support (preview
+Subject: Experimental user scripts support preview
 
 
 ---
 ---
  chrome/android/BUILD.gn                       |   2 +
  chrome/android/BUILD.gn                       |   2 +
@@ -10,9 +10,9 @@ Subject: Experimental user scripts support (preview
  chrome/android/java_sources.gni               |   3 +
  chrome/android/java_sources.gni               |   3 +
  chrome/android/proguard/main.flags            |   7 +
  chrome/android/proguard/main.flags            |   7 +
  chrome/browser/BUILD.gn                       |   5 +
  chrome/browser/BUILD.gn                       |   5 +
- chrome/browser/about_flags.cc                 |   5 +
- chrome/browser/flag_descriptions.cc           |   5 +
- chrome/browser/flag_descriptions.h            |   3 +
+ chrome/browser/about_flags.cc                 |   9 +
+ chrome/browser/flag_descriptions.cc           |  10 +
+ chrome/browser/flag_descriptions.h            |   5 +
  chrome/browser/prefs/browser_prefs.cc         |   2 +
  chrome/browser/prefs/browser_prefs.cc         |   2 +
  ...hrome_browser_main_extra_parts_profiles.cc |   4 +
  ...hrome_browser_main_extra_parts_profiles.cc |   4 +
  chrome/browser/profiles/profile_manager.cc    |   9 +
  chrome/browser/profiles/profile_manager.cc    |   9 +
@@ -42,8 +42,8 @@ Subject: Experimental user scripts support (preview
  components/user_scripts/browser/BUILD.gn      |  68 ++
  components/user_scripts/browser/BUILD.gn      |  68 ++
  .../user_scripts/browser/file_task_runner.cc  |  40 +
  .../user_scripts/browser/file_task_runner.cc  |  40 +
  .../user_scripts/browser/file_task_runner.h   |  34 +
  .../user_scripts/browser/file_task_runner.h   |  34 +
- .../browser/user_script_loader.cc             | 640 ++++++++++++++
- .../user_scripts/browser/user_script_loader.h | 172 ++++
+ .../browser/user_script_loader.cc             | 650 ++++++++++++++
+ .../user_scripts/browser/user_script_loader.h | 173 ++++
  .../browser/user_script_pref_info.cc          |  34 +
  .../browser/user_script_pref_info.cc          |  34 +
  .../browser/user_script_pref_info.h           |  58 ++
  .../browser/user_script_pref_info.h           |  58 ++
  .../user_scripts/browser/user_script_prefs.cc | 241 ++++++
  .../user_scripts/browser/user_script_prefs.cc | 241 ++++++
@@ -63,12 +63,12 @@ Subject: Experimental user scripts support (preview
  .../user_scripts/common/script_constants.h    |  33 +
  .../user_scripts/common/script_constants.h    |  33 +
  components/user_scripts/common/url_pattern.cc | 807 ++++++++++++++++++
  components/user_scripts/common/url_pattern.cc | 807 ++++++++++++++++++
  components/user_scripts/common/url_pattern.h  | 301 +++++++
  components/user_scripts/common/url_pattern.h  | 301 +++++++
- .../user_scripts/common/url_pattern_set.cc    | 327 +++++++
+ .../user_scripts/common/url_pattern_set.cc    | 330 +++++++
  .../user_scripts/common/url_pattern_set.h     | 161 ++++
  .../user_scripts/common/url_pattern_set.h     | 161 ++++
- components/user_scripts/common/user_script.cc | 339 ++++++++
+ components/user_scripts/common/user_script.cc | 351 ++++++++
  components/user_scripts/common/user_script.h  | 371 ++++++++
  components/user_scripts/common/user_script.h  | 371 ++++++++
- .../common/user_scripts_features.cc           |  31 +
- .../common/user_scripts_features.h            |  34 +
+ .../common/user_scripts_features.cc           |  34 +
+ .../common/user_scripts_features.h            |  35 +
  components/user_scripts/common/view_type.cc   |  39 +
  components/user_scripts/common/view_type.cc   |  39 +
  components/user_scripts/common/view_type.h    |  48 ++
  components/user_scripts/common/view_type.h    |  48 ++
  components/user_scripts/renderer/BUILD.gn     |  67 ++
  components/user_scripts/renderer/BUILD.gn     |  67 ++
@@ -84,27 +84,27 @@ Subject: Experimental user scripts support (preview
  .../user_scripts/renderer/script_injection.h  | 160 ++++
  .../user_scripts/renderer/script_injection.h  | 160 ++++
  .../renderer/script_injection_callback.cc     |  26 +
  .../renderer/script_injection_callback.cc     |  26 +
  .../renderer/script_injection_callback.h      |  38 +
  .../renderer/script_injection_callback.h      |  38 +
- .../renderer/script_injection_manager.cc      | 408 +++++++++
+ .../renderer/script_injection_manager.cc      | 407 +++++++++
  .../renderer/script_injection_manager.h       | 102 +++
  .../renderer/script_injection_manager.h       | 102 +++
  .../user_scripts/renderer/script_injector.h   |  96 +++
  .../user_scripts/renderer/script_injector.h   |  96 +++
  .../user_scripts/renderer/scripts_run_info.cc |  31 +
  .../user_scripts/renderer/scripts_run_info.cc |  31 +
  .../user_scripts/renderer/scripts_run_info.h  |  70 ++
  .../user_scripts/renderer/scripts_run_info.h  |  70 ++
  .../renderer/user_script_injector.cc          | 229 +++++
  .../renderer/user_script_injector.cc          | 229 +++++
  .../renderer/user_script_injector.h           |  86 ++
  .../renderer/user_script_injector.h           |  86 ++
- .../user_scripts/renderer/user_script_set.cc  | 240 ++++++
+ .../user_scripts/renderer/user_script_set.cc  | 260 ++++++
  .../user_scripts/renderer/user_script_set.h   | 102 +++
  .../user_scripts/renderer/user_script_set.h   | 102 +++
- .../renderer/user_script_set_manager.cc       |  75 ++
+ .../renderer/user_script_set_manager.cc       |  77 ++
  .../renderer/user_script_set_manager.h        |  62 ++
  .../renderer/user_script_set_manager.h        |  62 ++
  .../renderer/user_scripts_dispatcher.cc       |  36 +
  .../renderer/user_scripts_dispatcher.cc       |  36 +
  .../renderer/user_scripts_dispatcher.h        |  48 ++
  .../renderer/user_scripts_dispatcher.h        |  48 ++
- .../renderer/user_scripts_renderer_client.cc  |  75 ++
+ .../renderer/user_scripts_renderer_client.cc  |  76 ++
  .../renderer/user_scripts_renderer_client.h   |  33 +
  .../renderer/user_scripts_renderer_client.h   |  33 +
  .../renderer/web_ui_injection_host.cc         |  26 +
  .../renderer/web_ui_injection_host.cc         |  26 +
  .../renderer/web_ui_injection_host.h          |  28 +
  .../renderer/web_ui_injection_host.h          |  28 +
  .../strings/userscripts_strings.grdp          |  50 ++
  .../strings/userscripts_strings.grdp          |  50 ++
  tools/gritsettings/resource_ids.spec          |   3 +
  tools/gritsettings/resource_ids.spec          |   3 +
  .../chromium/ui/base/SelectFileDialog.java    |   3 +-
  .../chromium/ui/base/SelectFileDialog.java    |   3 +-
- 101 files changed, 8825 insertions(+), 4 deletions(-)
+ 101 files changed, 8888 insertions(+), 4 deletions(-)
  create mode 100755 components/user_scripts/android/BUILD.gn
  create mode 100755 components/user_scripts/android/BUILD.gn
  create mode 100755 components/user_scripts/android/java/res/drawable-hdpi/userscript_off.png
  create mode 100755 components/user_scripts/android/java/res/drawable-hdpi/userscript_off.png
  create mode 100755 components/user_scripts/android/java/res/drawable-hdpi/userscript_on.png
  create mode 100755 components/user_scripts/android/java/res/drawable-hdpi/userscript_on.png
@@ -329,13 +329,17 @@ diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
  #include "components/version_info/version_info.h"
  #include "components/version_info/version_info.h"
  #include "components/viz/common/features.h"
  #include "components/viz/common/features.h"
  #include "components/viz/common/switches.h"
  #include "components/viz/common/switches.h"
-@@ -6257,6 +6258,10 @@ const FeatureEntry kFeatureEntries[] = {
+@@ -6257,6 +6258,14 @@ const FeatureEntry kFeatureEntries[] = {
       FEATURE_VALUE_TYPE(features::kUserDataSnapshot)},
       FEATURE_VALUE_TYPE(features::kUserDataSnapshot)},
  #endif
  #endif
  
  
 +    {"enable-user-scripts", flag_descriptions::kEnableUserScriptsName,
 +    {"enable-user-scripts", flag_descriptions::kEnableUserScriptsName,
 +     flag_descriptions::kEnableUserScriptsDescription, kOsDesktop | kOsAndroid,
 +     flag_descriptions::kEnableUserScriptsDescription, kOsDesktop | kOsAndroid,
 +     FEATURE_VALUE_TYPE(user_scripts::features::kEnableUserScripts)},
 +     FEATURE_VALUE_TYPE(user_scripts::features::kEnableUserScripts)},
++
++    {"enable-user-scripts-log", flag_descriptions::kEnableLoggingUserScriptsName,
++     flag_descriptions::kEnableLoggingUserScriptsDescription, kOsDesktop | kOsAndroid,
++     FEATURE_VALUE_TYPE(user_scripts::features::kEnableLoggingUserScripts)},
 +
 +
  #if defined(OS_WIN)
  #if defined(OS_WIN)
      {"run-video-capture-service-in-browser",
      {"run-video-capture-service-in-browser",
@@ -343,7 +347,7 @@ diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
 diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
 diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
 --- a/chrome/browser/flag_descriptions.cc
 --- a/chrome/browser/flag_descriptions.cc
 +++ b/chrome/browser/flag_descriptions.cc
 +++ b/chrome/browser/flag_descriptions.cc
-@@ -4687,6 +4687,11 @@ const char kUserDataSnapshotDescription[] =
+@@ -4687,6 +4687,16 @@ const char kUserDataSnapshotDescription[] =
      "update and restoring them after a version rollback.";
      "update and restoring them after a version rollback.";
  #endif  // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
  #endif  // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
  
  
@@ -351,6 +355,11 @@ diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descripti
 +const char kEnableUserScriptsDescription[] =
 +const char kEnableUserScriptsDescription[] =
 +    "Enables experimental support on user scripts. "
 +    "Enables experimental support on user scripts. "
 +    "Please report back any bug.";
 +    "Please report back any bug.";
++
++const char kEnableLoggingUserScriptsName[] = "Enable logging user scripts component";
++const char kEnableLoggingUserScriptsDescription[] =
++    "Enables logging for troubleshooting feature. "
++    "Please report back any bug.";
 +
 +
  #if defined(OS_WIN) || defined(OS_CHROMEOS)
  #if defined(OS_WIN) || defined(OS_CHROMEOS)
  const char kWebShareName[] = "Web Share";
  const char kWebShareName[] = "Web Share";
@@ -358,12 +367,14 @@ diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descripti
 diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
 diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
 --- a/chrome/browser/flag_descriptions.h
 --- a/chrome/browser/flag_descriptions.h
 +++ b/chrome/browser/flag_descriptions.h
 +++ b/chrome/browser/flag_descriptions.h
-@@ -2735,6 +2735,9 @@ extern const char kUserDataSnapshotName[];
+@@ -2735,6 +2735,11 @@ extern const char kUserDataSnapshotName[];
  extern const char kUserDataSnapshotDescription[];
  extern const char kUserDataSnapshotDescription[];
  #endif  // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
  #endif  // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
  
  
 +extern const char kEnableUserScriptsName[];
 +extern const char kEnableUserScriptsName[];
 +extern const char kEnableUserScriptsDescription[];
 +extern const char kEnableUserScriptsDescription[];
++extern const char kEnableLoggingUserScriptsName[];
++extern const char kEnableLoggingUserScriptsDescription[];
 +
 +
  #if defined(OS_WIN) || defined(OS_CHROMEOS)
  #if defined(OS_WIN) || defined(OS_CHROMEOS)
  extern const char kWebShareName[];
  extern const char kWebShareName[];
@@ -2149,7 +2160,7 @@ diff --git a/components/user_scripts/browser/user_script_loader.cc b/components/
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/browser/user_script_loader.cc
 +++ b/components/user_scripts/browser/user_script_loader.cc
-@@ -0,0 +1,640 @@
+@@ -0,0 +1,650 @@
 +/*
 +/*
 +    This file is part of Bromite.
 +    This file is part of Bromite.
 +
 +
@@ -2250,7 +2261,8 @@ new file mode 100755
 +
 +
 +// static
 +// static
 +bool UserScriptLoader::ParseMetadataHeader(const base::StringPiece& script_text,
 +bool UserScriptLoader::ParseMetadataHeader(const base::StringPiece& script_text,
-+                                           std::unique_ptr<UserScript>& script) {
++                                           std::unique_ptr<UserScript>& script,
++                                           std::string& error_message) {
 +  // http://wiki.greasespot.net/Metadata_block
 +  // http://wiki.greasespot.net/Metadata_block
 +  base::StringPiece line;
 +  base::StringPiece line;
 +  size_t line_start = 0;
 +  size_t line_start = 0;
@@ -2311,13 +2323,17 @@ new file mode 100755
 +        script->set_description(value);
 +        script->set_description(value);
 +      } else if (GetDeclarationValue(line, kMatchDeclaration, &value)) {
 +      } else if (GetDeclarationValue(line, kMatchDeclaration, &value)) {
 +        URLPattern pattern(UserScript::ValidUserScriptSchemes());
 +        URLPattern pattern(UserScript::ValidUserScriptSchemes());
-+        if (URLPattern::ParseResult::kSuccess != pattern.Parse(value))
++        if (URLPattern::ParseResult::kSuccess != pattern.Parse(value)) {
++          error_message = "Invalid UserScript Schema " + value;
 +          return false;
 +          return false;
++        }
 +        script->add_url_pattern(pattern);
 +        script->add_url_pattern(pattern);
 +      } else if (GetDeclarationValue(line, kExcludeMatchDeclaration, &value)) {
 +      } else if (GetDeclarationValue(line, kExcludeMatchDeclaration, &value)) {
 +        URLPattern exclude(UserScript::ValidUserScriptSchemes());
 +        URLPattern exclude(UserScript::ValidUserScriptSchemes());
-+        if (URLPattern::ParseResult::kSuccess != exclude.Parse(value))
++        if (URLPattern::ParseResult::kSuccess != exclude.Parse(value)) {
++          error_message = "Invalid UserScript Schema " + value;
 +          return false;
 +          return false;
++        }
 +        script->add_exclude_url_pattern(exclude);
 +        script->add_exclude_url_pattern(exclude);
 +      } else if (GetDeclarationValue(line, kRunAtDeclaration, &value)) {
 +      } else if (GetDeclarationValue(line, kRunAtDeclaration, &value)) {
 +        if (value == kRunAtDocumentStartValue)
 +        if (value == kRunAtDocumentStartValue)
@@ -2326,8 +2342,10 @@ new file mode 100755
 +          script->set_run_location(UserScript::DOCUMENT_END);
 +          script->set_run_location(UserScript::DOCUMENT_END);
 +        else if (value == kRunAtDocumentIdleValue)
 +        else if (value == kRunAtDocumentIdleValue)
 +          script->set_run_location(UserScript::DOCUMENT_IDLE);
 +          script->set_run_location(UserScript::DOCUMENT_IDLE);
-+        else
++        else {
++          error_message = "Invalid RunAtDeclaration " + value;
 +          return false;
 +          return false;
++        }
 +      }
 +      }
 +
 +
 +      // TODO(aa): Handle more types of metadata.
 +      // TODO(aa): Handle more types of metadata.
@@ -2383,8 +2401,9 @@ new file mode 100755
 +      return false;
 +      return false;
 +    }
 +    }
 +
 +
-+    if (!UserScriptLoader::ParseMetadataHeader(content, script)) {
-+      *error = base::ASCIIToUTF16("Invalid script header.");
++    std::string detailed_error;
++    if (!UserScriptLoader::ParseMetadataHeader(content, script, detailed_error)) {
++      *error = base::ASCIIToUTF16("Invalid script header. " + detailed_error);
 +      return false;
 +      return false;
 +    }
 +    }
 +
 +
@@ -2392,11 +2411,13 @@ new file mode 100755
 +    // this value is used in ui to discriminate scripts
 +    // this value is used in ui to discriminate scripts
 +    script->set_key(script_key);
 +    script->set_key(script_key);
 +
 +
++    script->set_match_origin_as_fallback(MatchOriginAsFallbackBehavior::kNever);
++
 +    // remove unicode chars and set content into File
 +    // remove unicode chars and set content into File
 +    stripUnicode(content);
 +    stripUnicode(content);
 +    std::unique_ptr<UserScript::File> file(new UserScript::File());
 +    std::unique_ptr<UserScript::File> file(new UserScript::File());
 +    file->set_content(content);
 +    file->set_content(content);
-+    file->set_url(GURL("script.js")); // name doesn't matter
++    file->set_url(GURL(/*script_key*/ "script.js")); // name doesn't matter
 +
 +
 +    // create SHA256 of file
 +    // create SHA256 of file
 +    char raw[crypto::kSHA256Length] = {0};
 +    char raw[crypto::kSHA256Length] = {0};
@@ -2794,7 +2815,7 @@ diff --git a/components/user_scripts/browser/user_script_loader.h b/components/u
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/browser/user_script_loader.h
 +++ b/components/user_scripts/browser/user_script_loader.h
-@@ -0,0 +1,172 @@
+@@ -0,0 +1,173 @@
 +/*
 +/*
 +    This file is part of Bromite.
 +    This file is part of Bromite.
 +
 +
@@ -2873,7 +2894,8 @@ new file mode 100755
 +
 +
 +  // Parses the includes out of |script| and returns them in |includes|.
 +  // Parses the includes out of |script| and returns them in |includes|.
 +  static bool ParseMetadataHeader(const base::StringPiece& script_text,
 +  static bool ParseMetadataHeader(const base::StringPiece& script_text,
-+                                  std::unique_ptr<UserScript>& script);
++                                  std::unique_ptr<UserScript>& script,
++                                  std::string& error_message);
 +
 +
 +  UserScriptLoader(content::BrowserContext* browser_context,
 +  UserScriptLoader(content::BrowserContext* browser_context,
 +                   UserScriptsPrefs* prefs);
 +                   UserScriptsPrefs* prefs);
@@ -5107,7 +5129,7 @@ diff --git a/components/user_scripts/common/url_pattern_set.cc b/components/user
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/common/url_pattern_set.cc
 +++ b/components/user_scripts/common/url_pattern_set.cc
-@@ -0,0 +1,327 @@
+@@ -0,0 +1,330 @@
 +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 +// Use of this source code is governed by a BSD-style license that can be
 +// Use of this source code is governed by a BSD-style license that can be
 +// found in the LICENSE file.
 +// found in the LICENSE file.
@@ -5125,6 +5147,7 @@ new file mode 100755
 +#include "url/gurl.h"
 +#include "url/gurl.h"
 +#include "url/origin.h"
 +#include "url/origin.h"
 +#include "url/url_constants.h"
 +#include "url/url_constants.h"
++#include "user_scripts_features.h"
 +
 +
 +namespace user_scripts {
 +namespace user_scripts {
 +
 +
@@ -5332,17 +5355,19 @@ new file mode 100755
 +}
 +}
 +
 +
 +bool URLPatternSet::MatchesURL(const GURL& url) const {
 +bool URLPatternSet::MatchesURL(const GURL& url) const {
-+  // LOG(INFO) << "---URLPatternSet::MatchesURL  " << url.spec();
-+
 +  for (auto pattern = patterns_.cbegin(); pattern != patterns_.cend();
 +  for (auto pattern = patterns_.cbegin(); pattern != patterns_.cend();
 +       ++pattern) {
 +       ++pattern) {
 +    if (pattern->MatchesURL(url)) {
 +    if (pattern->MatchesURL(url)) {
-+      // LOG(INFO) << "---URLPatternSet::MatchesURL    true";
++      if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++        LOG(INFO) << "UserScripts: URLPatternSet::MatchesURL true " << url.spec();
++      
 +      return true;
 +      return true;
 +    }
 +    }
 +  }
 +  }
 +
 +
-+  // LOG(INFO) << "---URLPatternSet::MatchesURL    false";
++  if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++    LOG(INFO) << "UserScripts: URLPatternSet::MatchesURL false " << url.spec();
++
 +  return false;
 +  return false;
 +}
 +}
 +
 +
@@ -5605,7 +5630,7 @@ diff --git a/components/user_scripts/common/user_script.cc b/components/user_scr
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/common/user_script.cc
 +++ b/components/user_scripts/common/user_script.cc
-@@ -0,0 +1,339 @@
+@@ -0,0 +1,351 @@
 +// Copyright 2013 The Chromium Authors. All rights reserved.
 +// Copyright 2013 The Chromium Authors. All rights reserved.
 +// Use of this source code is governed by a BSD-style license that can be
 +// Use of this source code is governed by a BSD-style license that can be
 +// found in the LICENSE file.
 +// found in the LICENSE file.
@@ -5623,7 +5648,7 @@ new file mode 100755
 +#include "base/pickle.h"
 +#include "base/pickle.h"
 +#include "base/strings/pattern.h"
 +#include "base/strings/pattern.h"
 +#include "base/strings/string_util.h"
 +#include "base/strings/string_util.h"
-+//#include "switches.h"
++#include "user_scripts_features.h"
 +
 +
 +namespace {
 +namespace {
 +
 +
@@ -5705,38 +5730,38 @@ new file mode 100755
 +UserScript::~UserScript() = default;
 +UserScript::~UserScript() = default;
 +
 +
 +// static.
 +// static.
-+std::unique_ptr<UserScript> UserScript::CopyMetadataFrom(
-+    const UserScript& other) {
-+  std::unique_ptr<UserScript> script(new UserScript());
-+  script->run_location_ = other.run_location_;
-+  script->name_space_ = other.name_space_;
-+  script->name_ = other.name_;
-+  script->description_ = other.description_;
-+  script->version_ = other.version_;
-+  script->globs_ = other.globs_;
-+  script->exclude_globs_ = other.exclude_globs_;
-+  script->url_set_ = other.url_set_.Clone();
-+  script->exclude_url_set_ = other.exclude_url_set_.Clone();
-+
-+  // Note: File content is not copied.
-+  for (const std::unique_ptr<File>& file : other.js_scripts()) {
-+    std::unique_ptr<File> file_copy(new File(*file));
-+    script->js_scripts_.push_back(std::move(file_copy));
-+  }
-+  for (const std::unique_ptr<File>& file : other.css_scripts()) {
-+    std::unique_ptr<File> file_copy(new File(*file));
-+    script->css_scripts_.push_back(std::move(file_copy));
-+  }
-+  script->host_id_ = other.host_id_;
-+  script->consumer_instance_type_ = other.consumer_instance_type_;
-+  script->user_script_id_ = other.user_script_id_;
-+  script->emulate_greasemonkey_ = other.emulate_greasemonkey_;
-+  script->match_all_frames_ = other.match_all_frames_;
-+  script->match_origin_as_fallback_ = other.match_origin_as_fallback_;
-+  script->incognito_enabled_ = other.incognito_enabled_;
-+
-+  return script;
-+}
++// std::unique_ptr<UserScript> UserScript::CopyMetadataFrom(
++//     const UserScript& other) {
++//   std::unique_ptr<UserScript> script(new UserScript());
++//   script->run_location_ = other.run_location_;
++//   script->name_space_ = other.name_space_;
++//   script->name_ = other.name_;
++//   script->description_ = other.description_;
++//   script->version_ = other.version_;
++//   script->globs_ = other.globs_;
++//   script->exclude_globs_ = other.exclude_globs_;
++//   script->url_set_ = other.url_set_.Clone();
++//   script->exclude_url_set_ = other.exclude_url_set_.Clone();
++
++//   // Note: File content is not copied.
++//   for (const std::unique_ptr<File>& file : other.js_scripts()) {
++//     std::unique_ptr<File> file_copy(new File(*file));
++//     script->js_scripts_.push_back(std::move(file_copy));
++//   }
++//   for (const std::unique_ptr<File>& file : other.css_scripts()) {
++//     std::unique_ptr<File> file_copy(new File(*file));
++//     script->css_scripts_.push_back(std::move(file_copy));
++//   }
++//   script->host_id_ = other.host_id_;
++//   script->consumer_instance_type_ = other.consumer_instance_type_;
++//   script->user_script_id_ = other.user_script_id_;
++//   script->emulate_greasemonkey_ = other.emulate_greasemonkey_;
++//   script->match_all_frames_ = other.match_all_frames_;
++//   script->match_origin_as_fallback_ = other.match_origin_as_fallback_;
++//   script->incognito_enabled_ = other.incognito_enabled_;
++
++//   return script;
++// }
 +
 +
 +void UserScript::add_url_pattern(const URLPattern& pattern) {
 +void UserScript::add_url_pattern(const URLPattern& pattern) {
 +  url_set_.AddPattern(pattern);
 +  url_set_.AddPattern(pattern);
@@ -5748,23 +5773,35 @@ new file mode 100755
 +
 +
 +bool UserScript::MatchesURL(const GURL& url) const {
 +bool UserScript::MatchesURL(const GURL& url) const {
 +  if (!url_set_.is_empty()) {
 +  if (!url_set_.is_empty()) {
-+    if (!url_set_.MatchesURL(url))
++    if (!url_set_.MatchesURL(url)) {
++      if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++        LOG(INFO) << "UserScripts: No Match for url_set";
 +      return false;
 +      return false;
++    }
 +  }
 +  }
 +
 +
 +  if (!exclude_url_set_.is_empty()) {
 +  if (!exclude_url_set_.is_empty()) {
-+    if (exclude_url_set_.MatchesURL(url))
++    if (exclude_url_set_.MatchesURL(url)) {
++      if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++        LOG(INFO) << "UserScripts: No Match for exclude_url_set";
 +      return false;
 +      return false;
++    }
 +  }
 +  }
 +
 +
 +  if (!globs_.empty()) {
 +  if (!globs_.empty()) {
-+    if (!UrlMatchesGlobs(&globs_, url))
++    if (!UrlMatchesGlobs(&globs_, url)) {
++      if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++        LOG(INFO) << "UserScripts: No Match for globs";
 +      return false;
 +      return false;
++    }
 +  }
 +  }
 +
 +
 +  if (!exclude_globs_.empty()) {
 +  if (!exclude_globs_.empty()) {
-+    if (UrlMatchesGlobs(&exclude_globs_, url))
++    if (UrlMatchesGlobs(&exclude_globs_, url)) {
++      if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++        LOG(INFO) << "UserScripts: No Match for exclude_globs";
 +      return false;
 +      return false;
++    }
 +  }
 +  }
 +
 +
 +  return true;
 +  return true;
@@ -6098,7 +6135,7 @@ new file mode 100755
 +  ~UserScript();
 +  ~UserScript();
 +
 +
 +  // Performs a copy of all fields except file contents.
 +  // Performs a copy of all fields except file contents.
-+  static std::unique_ptr<UserScript> CopyMetadataFrom(const UserScript& other);
++  // static std::unique_ptr<UserScript> CopyMetadataFrom(const UserScript& other);
 +
 +
 +  const std::string& name_space() const { return name_space_; }
 +  const std::string& name_space() const { return name_space_; }
 +  void set_name_space(const std::string& name_space) {
 +  void set_name_space(const std::string& name_space) {
@@ -6325,7 +6362,7 @@ diff --git a/components/user_scripts/common/user_scripts_features.cc b/component
 new file mode 100644
 new file mode 100644
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/common/user_scripts_features.cc
 +++ b/components/user_scripts/common/user_scripts_features.cc
-@@ -0,0 +1,31 @@
+@@ -0,0 +1,34 @@
 +/*
 +/*
 +    This file is part of Bromite.
 +    This file is part of Bromite.
 +
 +
@@ -6353,6 +6390,9 @@ new file mode 100644
 +
 +
 +const base::Feature kEnableUserScripts = {"EnableUserScripts",
 +const base::Feature kEnableUserScripts = {"EnableUserScripts",
 +                                          base::FEATURE_DISABLED_BY_DEFAULT};
 +                                          base::FEATURE_DISABLED_BY_DEFAULT};
++const base::Feature kEnableLoggingUserScripts = 
++                                        {"EnableLoggingUserScripts",
++                                          base::FEATURE_DISABLED_BY_DEFAULT};
 +
 +
 +}
 +}
 +
 +
@@ -6362,7 +6402,7 @@ diff --git a/components/user_scripts/common/user_scripts_features.h b/components
 new file mode 100644
 new file mode 100644
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/common/user_scripts_features.h
 +++ b/components/user_scripts/common/user_scripts_features.h
-@@ -0,0 +1,34 @@
+@@ -0,0 +1,35 @@
 +/*
 +/*
 +    This file is part of Bromite.
 +    This file is part of Bromite.
 +
 +
@@ -6392,6 +6432,7 @@ new file mode 100644
 +
 +
 +namespace features {
 +namespace features {
 +    extern const base::Feature kEnableUserScripts;
 +    extern const base::Feature kEnableUserScripts;
++    extern const base::Feature kEnableLoggingUserScripts;
 +}
 +}
 +
 +
 +}
 +}
@@ -7478,11 +7519,11 @@ new file mode 100755
 +  complete_ = did_inject_js_ || !should_inject_js;
 +  complete_ = did_inject_js_ || !should_inject_js;
 +
 +
 +  if (complete_) {
 +  if (complete_) {
-+    // LOG(INFO) << "---ScriptInjection::Inject complete";
++    LOG(INFO) << "---ScriptInjection::Inject complete";
 +    injector_->OnInjectionComplete(std::move(execution_result_), run_location_,
 +    injector_->OnInjectionComplete(std::move(execution_result_), run_location_,
 +                                   render_frame_);
 +                                   render_frame_);
 +  } else {
 +  } else {
-+    // LOG(INFO) << "---ScriptInjection::Inject INcomplete";
++    LOG(INFO) << "---ScriptInjection::Inject INcomplete";
 +    ++scripts_run_info->num_blocking_js;
 +    ++scripts_run_info->num_blocking_js;
 +  }
 +  }
 +
 +
@@ -7826,7 +7867,7 @@ diff --git a/components/user_scripts/renderer/script_injection_manager.cc b/comp
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/renderer/script_injection_manager.cc
 +++ b/components/user_scripts/renderer/script_injection_manager.cc
-@@ -0,0 +1,408 @@
+@@ -0,0 +1,407 @@
 +// Copyright 2014 The Chromium Authors. All rights reserved.
 +// Copyright 2014 The Chromium Authors. All rights reserved.
 +// Use of this source code is governed by a BSD-style license that can be
 +// Use of this source code is governed by a BSD-style license that can be
 +// found in the LICENSE file.
 +// found in the LICENSE file.
@@ -7858,6 +7899,7 @@ new file mode 100755
 +#include "third_party/blink/public/web/web_local_frame.h"
 +#include "third_party/blink/public/web/web_local_frame.h"
 +#include "third_party/blink/public/web/web_view.h"
 +#include "third_party/blink/public/web/web_view.h"
 +#include "url/gurl.h"
 +#include "url/gurl.h"
++#include "../common/user_scripts_features.h"
 +
 +
 +namespace user_scripts {
 +namespace user_scripts {
 +
 +
@@ -7945,7 +7987,8 @@ new file mode 100755
 +}
 +}
 +
 +
 +void ScriptInjectionManager::RFOHelper::DidCreateDocumentElement() {
 +void ScriptInjectionManager::RFOHelper::DidCreateDocumentElement() {
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::DidCreateDocumentElement";
++  if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++    LOG(INFO) << "UserScripts: DidCreateDocumentElement -> DOCUMENT_START";
 +
 +
 +  ExtensionFrameHelper::Get(render_frame())
 +  ExtensionFrameHelper::Get(render_frame())
 +      ->ScheduleAtDocumentStart(
 +      ->ScheduleAtDocumentStart(
@@ -7979,7 +8022,9 @@ new file mode 100755
 +}
 +}
 +
 +
 +void ScriptInjectionManager::RFOHelper::DidFinishDocumentLoad() {
 +void ScriptInjectionManager::RFOHelper::DidFinishDocumentLoad() {
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::DidFinishDocumentLoad";
++  if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++    LOG(INFO) << "UserScripts: DidFinishDocumentLoad -> DOCUMENT_END";
++
 +  DCHECK(content::RenderThread::Get());
 +  DCHECK(content::RenderThread::Get());
 +  ExtensionFrameHelper::Get(render_frame())
 +  ExtensionFrameHelper::Get(render_frame())
 +      ->ScheduleAtDocumentEnd(
 +      ->ScheduleAtDocumentEnd(
@@ -8007,7 +8052,6 @@ new file mode 100755
 +      ->ScheduleAtDocumentIdle(
 +      ->ScheduleAtDocumentIdle(
 +          base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
 +          base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
 +                     weak_factory_.GetWeakPtr()));
 +                     weak_factory_.GetWeakPtr()));
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::DidFinishDocumentLoad exit";
 +}
 +}
 +
 +
 +void ScriptInjectionManager::RFOHelper::WillDetach() {
 +void ScriptInjectionManager::RFOHelper::WillDetach() {
@@ -8024,7 +8068,6 @@ new file mode 100755
 +}
 +}
 +
 +
 +void ScriptInjectionManager::RFOHelper::OnStop() {
 +void ScriptInjectionManager::RFOHelper::OnStop() {
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::OnStop";
 +  // If the navigation request fails (e.g. 204/205/downloads), notify the
 +  // If the navigation request fails (e.g. 204/205/downloads), notify the
 +  // extension to avoid keeping the frame in a START state indefinitely which
 +  // extension to avoid keeping the frame in a START state indefinitely which
 +  // leads to deadlocks.
 +  // leads to deadlocks.
@@ -8032,21 +8075,19 @@ new file mode 100755
 +}
 +}
 +
 +
 +void ScriptInjectionManager::RFOHelper::RunIdle() {
 +void ScriptInjectionManager::RFOHelper::RunIdle() {
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::RunIdle";
 +  // Only notify the manager if the frame hasn't already had idle run since the
 +  // Only notify the manager if the frame hasn't already had idle run since the
 +  // task to RunIdle() was posted.
 +  // task to RunIdle() was posted.
 +  if (should_run_idle_) {
 +  if (should_run_idle_) {
 +    should_run_idle_ = false;
 +    should_run_idle_ = false;
++    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++      LOG(INFO) << "UserScripts: RunIdle -> DOCUMENT_IDLE";
 +    manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_IDLE);
 +    manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_IDLE);
 +  }
 +  }
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::RunIdle exit";
 +}
 +}
 +
 +
 +void ScriptInjectionManager::RFOHelper::StartInjectScripts(
 +void ScriptInjectionManager::RFOHelper::StartInjectScripts(
 +    UserScript::RunLocation run_location) {
 +    UserScript::RunLocation run_location) {
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::StartInjectScripts";
 +  manager_->StartInjectScripts(render_frame(), run_location);
 +  manager_->StartInjectScripts(render_frame(), run_location);
-+  // LOG(INFO) << "---ScriptInjectionManager::RFOHelper::StartInjectScripts exit";
 +}
 +}
 +
 +
 +void ScriptInjectionManager::RFOHelper::InvalidateAndResetFrame(
 +void ScriptInjectionManager::RFOHelper::InvalidateAndResetFrame(
@@ -8069,7 +8110,6 @@ new file mode 100755
 +    : user_script_set_manager_(user_script_set_manager),
 +    : user_script_set_manager_(user_script_set_manager),
 +      user_script_set_manager_observer_(this) {
 +      user_script_set_manager_observer_(this) {
 +  user_script_set_manager_observer_.Add(user_script_set_manager_);
 +  user_script_set_manager_observer_.Add(user_script_set_manager_);
-+  // LOG(INFO) << "---ScriptInjectionManager::ScriptInjectionManager";
 +}
 +}
 +
 +
 +ScriptInjectionManager::~ScriptInjectionManager() {
 +ScriptInjectionManager::~ScriptInjectionManager() {
@@ -8883,7 +8923,7 @@ diff --git a/components/user_scripts/renderer/user_script_set.cc b/components/us
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/renderer/user_script_set.cc
 +++ b/components/user_scripts/renderer/user_script_set.cc
-@@ -0,0 +1,240 @@
+@@ -0,0 +1,260 @@
 +// Copyright 2014 The Chromium Authors. All rights reserved.
 +// Copyright 2014 The Chromium Authors. All rights reserved.
 +// Use of this source code is governed by a BSD-style license that can be
 +// Use of this source code is governed by a BSD-style license that can be
 +// found in the LICENSE file.
 +// found in the LICENSE file.
@@ -8909,6 +8949,7 @@ new file mode 100755
 +#include "third_party/blink/public/web/web_document.h"
 +#include "third_party/blink/public/web/web_document.h"
 +#include "third_party/blink/public/web/web_local_frame.h"
 +#include "third_party/blink/public/web/web_local_frame.h"
 +#include "url/gurl.h"
 +#include "url/gurl.h"
++#include "../common/user_scripts_features.h"
 +
 +
 +namespace user_scripts {
 +namespace user_scripts {
 +
 +
@@ -9063,8 +9104,12 @@ new file mode 100755
 +          web_frame, document_url, script->match_origin_as_fallback());
 +          web_frame, document_url, script->match_origin_as_fallback());
 +
 +
 +  bool is_subframe = web_frame->Parent();
 +  bool is_subframe = web_frame->Parent();
-+  if (!script->MatchesDocument(effective_document_url, is_subframe))
++  if (!script->MatchesDocument(effective_document_url, is_subframe)) {
++    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++      LOG(INFO) << "UserScripts: No Match name=" << script->name() << " " <<
++                                         "url=" << effective_document_url.spec();
 +    return injection;
 +    return injection;
++  }
 +
 +
 +  std::unique_ptr<ScriptInjector> injector(
 +  std::unique_ptr<ScriptInjector> injector(
 +      new UserScriptInjector(script, this));
 +      new UserScriptInjector(script, this));
@@ -9077,6 +9122,18 @@ new file mode 100755
 +    injection.reset(new ScriptInjection(std::move(injector), render_frame,
 +    injection.reset(new ScriptInjection(std::move(injector), render_frame,
 +                                        std::move(injection_host), run_location,
 +                                        std::move(injection_host), run_location,
 +                                        log_activity));
 +                                        log_activity));
++    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++      LOG(INFO) << "UserScripts: Match name=" << script->name() << " " <<
++                                         "url=" << effective_document_url.spec();
++  } else {
++    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts)) {
++      if (script->run_location() != run_location) 
++        LOG(INFO) << "UserScripts: wrong run location current " << run_location << " " <<
++                                                     "expeted " << script->run_location();
++      else
++        LOG(INFO) << "UserScripts: Match but no script name=" << script->name() << " " <<
++                                          "url=" << effective_document_url.spec();
++    }
 +  }
 +  }
 +  return injection;
 +  return injection;
 +}
 +}
@@ -9099,11 +9156,14 @@ new file mode 100755
 +    std::string content =
 +    std::string content =
 +        base::StrCat({kUserScriptHead, script_content, kUserScriptTail});
 +        base::StrCat({kUserScriptHead, script_content, kUserScriptTail});
 +    source = blink::WebString::FromUTF8(content);
 +    source = blink::WebString::FromUTF8(content);
++    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++      LOG(INFO) << "UserScripts: Injecting w/greasemonkey " << file.url();
 +    // LOG(INFO) << "---UserScriptSet::GetJsSource emu " << script_content;
 +    // LOG(INFO) << "---UserScriptSet::GetJsSource emu " << script_content;
 +  } else {
 +  } else {
 +    source = blink::WebString::FromUTF8(script_content.data(),
 +    source = blink::WebString::FromUTF8(script_content.data(),
 +                                        script_content.length());
 +                                        script_content.length());
-+    // LOG(INFO) << "Injecting user script " << file.Ascii();
++    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++      LOG(INFO) << "UserScripts: Injecting " << file.url();
 +  }
 +  }
 +  script_sources_[url] = source;
 +  script_sources_[url] = source;
 +  return source;
 +  return source;
@@ -9235,13 +9295,14 @@ diff --git a/components/user_scripts/renderer/user_script_set_manager.cc b/compo
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/renderer/user_script_set_manager.cc
 +++ b/components/user_scripts/renderer/user_script_set_manager.cc
-@@ -0,0 +1,75 @@
+@@ -0,0 +1,77 @@
 +#include "user_script_set_manager.h"
 +#include "user_script_set_manager.h"
 +
 +
 +#include "base/logging.h"
 +#include "base/logging.h"
 +#include "content/public/renderer/render_thread.h"
 +#include "content/public/renderer/render_thread.h"
 +#include "../common/host_id.h"
 +#include "../common/host_id.h"
 +#include "../common/extension_messages.h"
 +#include "../common/extension_messages.h"
++#include "../common/user_scripts_features.h"
 +#include "user_script_set.h"
 +#include "user_script_set.h"
 +
 +
 +namespace user_scripts {
 +namespace user_scripts {
@@ -9277,7 +9338,8 @@ new file mode 100755
 +    int tab_id,
 +    int tab_id,
 +    UserScript::RunLocation run_location) {
 +    UserScript::RunLocation run_location) {
 +
 +
-+  // LOG(INFO) << "---UserScriptSetManager::GetAllInjections";
++  if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++    LOG(INFO) << "UserScripts: GetAllInjections";
 +
 +
 +  // static_scripts_ is UserScriptSet
 +  // static_scripts_ is UserScriptSet
 +  static_scripts_.GetInjections(injections, render_frame, tab_id, run_location,
 +  static_scripts_.GetInjections(injections, render_frame, tab_id, run_location,
@@ -9480,7 +9542,7 @@ diff --git a/components/user_scripts/renderer/user_scripts_renderer_client.cc b/
 new file mode 100755
 new file mode 100755
 --- /dev/null
 --- /dev/null
 +++ b/components/user_scripts/renderer/user_scripts_renderer_client.cc
 +++ b/components/user_scripts/renderer/user_scripts_renderer_client.cc
-@@ -0,0 +1,75 @@
+@@ -0,0 +1,76 @@
 +#include "user_scripts_renderer_client.h"
 +#include "user_scripts_renderer_client.h"
 +
 +
 +#include <memory>
 +#include <memory>
@@ -9512,7 +9574,8 @@ new file mode 100755
 +}
 +}
 +
 +
 +void UserScriptsRendererClient::RenderThreadStarted() {
 +void UserScriptsRendererClient::RenderThreadStarted() {
-+  // LOG(INFO) << "---UserScriptsRendererClient::RenderThreadStarted";
++  if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
++    LOG(INFO) << "UserScripts: RenderThreadStarted";
 +  content::RenderThread* thread = content::RenderThread::Get();
 +  content::RenderThread* thread = content::RenderThread::Get();
 +
 +
 +  dispatcher_ = std::make_unique<UserScriptsDispatcher>();
 +  dispatcher_ = std::make_unique<UserScriptsDispatcher>();