瀏覽代碼

fix "Experimental user scripts support" and "Show site settings for cookies, javascript and ads"

Carmelo Messina 3 年之前
父節點
當前提交
a116910f07

+ 31 - 27
build/patches/Experimental-user-scripts-support.patch

@@ -72,7 +72,7 @@ See also: components/user_scripts/README.md
  .../user-script-ui/user-scripts-ui.js         |   9 +
  .../user-script-ui/user-scripts-ui.js         |   9 +
  .../browser/ui/user_scripts_ui.cc             | 148 ++++
  .../browser/ui/user_scripts_ui.cc             | 148 ++++
  .../user_scripts/browser/ui/user_scripts_ui.h |  39 +
  .../user_scripts/browser/ui/user_scripts_ui.h |  39 +
- .../browser/user_script_loader.cc             | 721 ++++++++++++++++
+ .../browser/user_script_loader.cc             | 714 ++++++++++++++++
  .../user_scripts/browser/user_script_loader.h | 170 ++++
  .../user_scripts/browser/user_script_loader.h | 170 ++++
  .../browser/user_script_pref_info.cc          |  34 +
  .../browser/user_script_pref_info.cc          |  34 +
  .../browser/user_script_pref_info.h           |  72 ++
  .../browser/user_script_pref_info.h           |  72 ++
@@ -95,7 +95,7 @@ See also: components/user_scripts/README.md
  components/user_scripts/common/url_pattern.h  | 302 +++++++
  components/user_scripts/common/url_pattern.h  | 302 +++++++
  .../user_scripts/common/url_pattern_set.cc    | 335 ++++++++
  .../user_scripts/common/url_pattern_set.cc    | 335 ++++++++
  .../user_scripts/common/url_pattern_set.h     | 161 ++++
  .../user_scripts/common/url_pattern_set.h     | 161 ++++
- components/user_scripts/common/user_script.cc | 317 +++++++
+ components/user_scripts/common/user_script.cc | 325 +++++++
  components/user_scripts/common/user_script.h  | 403 +++++++++
  components/user_scripts/common/user_script.h  | 403 +++++++++
  .../common/user_scripts_features.cc           |  32 +
  .../common/user_scripts_features.cc           |  32 +
  .../common/user_scripts_features.h            |  34 +
  .../common/user_scripts_features.h            |  34 +
@@ -121,7 +121,7 @@ See also: components/user_scripts/README.md
  .../user_scripts/renderer/scripts_run_info.h  |  70 ++
  .../user_scripts/renderer/scripts_run_info.h  |  70 ++
  .../renderer/user_script_injector.cc          | 228 +++++
  .../renderer/user_script_injector.cc          | 228 +++++
  .../renderer/user_script_injector.h           |  87 ++
  .../renderer/user_script_injector.h           |  87 ++
- .../user_scripts/renderer/user_script_set.cc  | 259 ++++++
+ .../user_scripts/renderer/user_script_set.cc  | 262 ++++++
  .../user_scripts/renderer/user_script_set.h   | 102 +++
  .../user_scripts/renderer/user_script_set.h   | 102 +++
  .../renderer/user_script_set_manager.cc       |  77 ++
  .../renderer/user_script_set_manager.cc       |  77 ++
  .../renderer/user_script_set_manager.h        |  62 ++
  .../renderer/user_script_set_manager.h        |  62 ++
@@ -133,7 +133,7 @@ See also: components/user_scripts/README.md
  .../renderer/web_ui_injection_host.h          |  28 +
  .../renderer/web_ui_injection_host.h          |  28 +
  .../strings/userscripts_strings.grdp          |  55 ++
  .../strings/userscripts_strings.grdp          |  55 ++
  tools/gritsettings/resource_ids.spec          |   6 +
  tools/gritsettings/resource_ids.spec          |   6 +
- 111 files changed, 9580 insertions(+), 2 deletions(-)
+ 111 files changed, 9584 insertions(+), 2 deletions(-)
  create mode 100644 components/user_scripts/README.md
  create mode 100644 components/user_scripts/README.md
  create mode 100755 components/user_scripts/android/BUILD.gn
  create mode 100755 components/user_scripts/android/BUILD.gn
  create mode 100644 components/user_scripts/android/java/res/layout/accept_script_item.xml
  create mode 100644 components/user_scripts/android/java/res/layout/accept_script_item.xml
@@ -2833,7 +2833,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,721 @@
+@@ -0,0 +1,714 @@
 +/*
 +/*
 +    This file is part of Bromite.
 +    This file is part of Bromite.
 +
 +
@@ -2895,6 +2895,7 @@ new file mode 100755
 +#include "file_task_runner.h"
 +#include "file_task_runner.h"
 +#include "user_script_prefs.h"
 +#include "user_script_prefs.h"
 +#include "user_script_pref_info.h"
 +#include "user_script_pref_info.h"
++#include "../common/host_id.h"
 +
 +
 +using content::BrowserThread;
 +using content::BrowserThread;
 +using content::BrowserContext;
 +using content::BrowserContext;
@@ -2924,16 +2925,6 @@ new file mode 100755
 +static const base::StringPiece kParserError("// @error");
 +static const base::StringPiece kParserError("// @error");
 +static const base::StringPiece kForceDisabled("// @disabled");
 +static const base::StringPiece kForceDisabled("// @disabled");
 +
 +
-+bool invalidChar(unsigned char c)
-+{
-+  return !(c>=0 && c <128);
-+}
-+
-+void stripUnicode(std::string& str)
-+{
-+  str.erase(remove_if(str.begin(),str.end(), invalidChar), str.end());
-+}
-+
 +// Helper function to parse greasesmonkey headers
 +// Helper function to parse greasesmonkey headers
 +bool GetDeclarationValue(const base::StringPiece& line,
 +bool GetDeclarationValue(const base::StringPiece& line,
 +                         const base::StringPiece& prefix,
 +                         const base::StringPiece& prefix,
@@ -3101,13 +3092,12 @@ new file mode 100755
 +      return false;
 +      return false;
 +    }
 +    }
 +
 +
++    script->set_name(user_script_path.BaseName().value());
 +    script->set_match_origin_as_fallback(MatchOriginAsFallbackBehavior::kNever);
 +    script->set_match_origin_as_fallback(MatchOriginAsFallbackBehavior::kNever);
 +
 +
-+    // remove unicode chars and set content into File
-+    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_key*/ "script.js")); // name doesn't matter
++    file->set_url(GURL(base::StrCat({"https://userscripts/file/", script->name(), ".js"})));
 +
 +
 +    // create SHA256 of file
 +    // create SHA256 of file
 +    char raw[crypto::kSHA256Length] = {0};
 +    char raw[crypto::kSHA256Length] = {0};
@@ -3157,6 +3147,9 @@ new file mode 100755
 +  base::FilePath full_name;
 +  base::FilePath full_name;
 +  while (full_name = dir_enum.Next(), !full_name.empty()) {
 +  while (full_name = dir_enum.Next(), !full_name.empty()) {
 +    std::unique_ptr<UserScript> userscript(new UserScript());
 +    std::unique_ptr<UserScript> userscript(new UserScript());
++    userscript->set_id(UserScript::GenerateUserScriptID());
++    userscript->set_host_id(HostID(HostID::HostType::EXTENSIONS,
++      "_" + base::NumberToString(userscript->id())));
 +
 +
 +    std::u16string error;
 +    std::u16string error;
 +    bool found_metadata;
 +    bool found_metadata;
@@ -6425,7 +6418,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,317 @@
+@@ -0,0 +1,325 @@
 +// 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.
@@ -6533,6 +6526,12 @@ new file mode 100755
 +}
 +}
 +
 +
 +bool UserScript::MatchesURL(const GURL& url) const {
 +bool UserScript::MatchesURL(const GURL& url) const {
++  // exclude schemas not valid
++  URLPattern pattern(kValidUserScriptSchemes);
++  pattern.Parse(url.spec());
++  if (!pattern.IsValidScheme(pattern.scheme()))
++    return false;
++
 +  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))
 +      if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
@@ -6594,6 +6593,7 @@ new file mode 100755
 +  // Write the simple types to the pickle.
 +  // Write the simple types to the pickle.
 +  pickle->WriteInt(run_location());
 +  pickle->WriteInt(run_location());
 +  pickle->WriteInt(user_script_id_);
 +  pickle->WriteInt(user_script_id_);
++  pickle->WriteString(name_);
 +  pickle->WriteBool(emulate_greasemonkey());
 +  pickle->WriteBool(emulate_greasemonkey());
 +  pickle->WriteBool(match_all_frames());
 +  pickle->WriteBool(match_all_frames());
 +  pickle->WriteInt(static_cast<int>(match_origin_as_fallback()));
 +  pickle->WriteInt(static_cast<int>(match_origin_as_fallback()));
@@ -6649,6 +6649,7 @@ new file mode 100755
 +  run_location_ = static_cast<RunLocation>(run_location);
 +  run_location_ = static_cast<RunLocation>(run_location);
 +
 +
 +  CHECK(iter->ReadInt(&user_script_id_));
 +  CHECK(iter->ReadInt(&user_script_id_));
++  CHECK(iter->ReadString(&name_));
 +  CHECK(iter->ReadBool(&emulate_greasemonkey_));
 +  CHECK(iter->ReadBool(&emulate_greasemonkey_));
 +  CHECK(iter->ReadBool(&match_all_frames_));
 +  CHECK(iter->ReadBool(&match_all_frames_));
 +  int match_origin_as_fallback_int = 0;
 +  int match_origin_as_fallback_int = 0;
@@ -9713,7 +9714,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,259 @@
+@@ -0,0 +1,262 @@
 +// 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.
@@ -9896,8 +9897,9 @@ new file mode 100755
 +  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))
 +    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts))
-+      LOG(INFO) << "UserScripts: No Match name=" << script->name() << " " <<
-+                                         "url=" << effective_document_url.spec();
++      LOG(INFO) << "UserScripts: Match name=" << script->name() <<
++                                      " id=" << script->host_id().id() <<
++                                      " url=" << effective_document_url.spec();
 +    return injection;
 +    return injection;
 +  }
 +  }
 +
 +
@@ -9919,11 +9921,13 @@ new file mode 100755
 +    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts)) {
 +    if (base::FeatureList::IsEnabled(features::kEnableLoggingUserScripts)) {
 +      if (script->run_location() != run_location)
 +      if (script->run_location() != run_location)
 +        LOG(INFO) << "UserScripts: run location for name=" << script->name() <<
 +        LOG(INFO) << "UserScripts: run location for name=" << script->name() <<
-+                                        "current " << run_location << " " <<
-+                                        "need " << script->run_location();
++                                      " id=" << script->host_id().id() <<
++                                      " current " << run_location <<
++                                      " need " << script->run_location();
 +      else
 +      else
-+        LOG(INFO) << "UserScripts: Match but no run name=" << script->name() << " " <<
-+                                        "url=" << effective_document_url.spec();
++        LOG(INFO) << "UserScripts: Match but no run name=" << script->name() <<
++                                      " id=" << script->host_id().id() <<
++                                      " url=" << effective_document_url.spec();
 +    }
 +    }
 +  }
 +  }
 +  return injection;
 +  return injection;
@@ -10495,8 +10499,8 @@ new file mode 100755
 +namespace {
 +namespace {
 +
 +
 +// The default secure CSP to be used in order to prevent remote scripts.
 +// The default secure CSP to be used in order to prevent remote scripts.
++// use "script-src 'self' 'unsafe-eval'; object-src 'self';" to enable eval
 +const char kDefaultSecureCSP[] = "script-src 'self'; object-src 'self';";
 +const char kDefaultSecureCSP[] = "script-src 'self'; object-src 'self';";
-+
 +}
 +}
 +
 +
 +WebUIInjectionHost::WebUIInjectionHost(const HostID& host_id)
 +WebUIInjectionHost::WebUIInjectionHost(const HostID& host_id)

+ 1 - 1
build/patches/Show-site-settings-for-cookies-javascript-and-ads.patch

@@ -66,7 +66,7 @@ diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/c
 +        Integer currentValue =
 +        Integer currentValue =
 +                mSite.getContentSetting(browserContextHandle, ContentSettingsType.COOKIES);
 +                mSite.getContentSetting(browserContextHandle, ContentSettingsType.COOKIES);
 +        // Always show the cookies permission
 +        // Always show the cookies permission
-+        if (currentValue == null) {
++        if (currentValue == null || currentValue == ContentSettingValues.DEFAULT) {
 +            currentValue = WebsitePreferenceBridge.isCategoryEnabled(
 +            currentValue = WebsitePreferenceBridge.isCategoryEnabled(
 +                                   browserContextHandle, ContentSettingsType.COOKIES)
 +                                   browserContextHandle, ContentSettingsType.COOKIES)
 +                    ? ContentSettingValues.ALLOW
 +                    ? ContentSettingValues.ALLOW