Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uplift Disable in-page translation in release channel to 0.65.x #2548

Merged
merged 1 commit into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "build/build_config.h"
#include "brave/app/brave_command_line_helper.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/common/brave_switches.h"
#include "brave/common/resource_bundle_helper.h"
#include "brave/components/brave_ads/browser/buildflags/buildflags.h"
Expand All @@ -27,6 +28,7 @@
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/translate/core/browser/translate_prefs.h"
#include "components/unified_consent/feature.h"
#include "content/public/common/content_features.h"
#include "extensions/common/extension_features.h"
Expand Down Expand Up @@ -148,11 +150,12 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
network::features::kNetworkService.name,
unified_consent::kUnifiedConsent.name,
features::kLookalikeUrlNavigationSuggestionsUI.name,
#if !BUILDFLAG(ENABLE_BRAVE_TRANSLATE)
translate::kTranslateUI.name,
#endif
};

command_line.AppendFeatures(enabled_features, disabled_features);


bool ret = ChromeMainDelegate::BasicStartupComplete(exit_code);

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
Expand Down
1 change: 1 addition & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ source_set("browser_process") {
":version_info",
"//base",
"//brave/browser/tor",
"//brave/browser/translate/buildflags",
"//brave/common",
"//brave/components/brave_ads/browser",
"//brave/components/brave_rewards/browser",
Expand Down
10 changes: 8 additions & 2 deletions browser/net/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import("//brave/browser/translate/buildflags/buildflags.gni")
import("//build/config/features.gni")

source_set("net") {
Expand Down Expand Up @@ -25,8 +26,6 @@ source_set("net") {
"brave_system_network_delegate.h",
"brave_tor_network_delegate_helper.cc",
"brave_tor_network_delegate_helper.h",
"brave_translate_redirect_network_delegate_helper.cc",
"brave_translate_redirect_network_delegate_helper.h",
"url_context.cc",
"url_context.h",
]
Expand All @@ -45,4 +44,11 @@ source_set("net") {
"//brave/app:brave_generated_resources_grit",
]
}

if (enable_brave_translate) {
sources += [
"brave_translate_redirect_network_delegate_helper.cc",
"brave_translate_redirect_network_delegate_helper.h",
]
}
}
8 changes: 7 additions & 1 deletion browser/net/brave_profile_network_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "brave/browser/net/brave_referrals_network_delegate_helper.h"
#include "brave/browser/net/brave_site_hacks_network_delegate_helper.h"
#include "brave/browser/net/brave_tor_network_delegate_helper.h"
#include "brave/browser/net/brave_translate_redirect_network_delegate_helper.h"
#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
Expand All @@ -22,6 +22,10 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "components/prefs/pref_service.h"

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE)
#include "brave/browser/net/brave_translate_redirect_network_delegate_helper.h"
#endif

BraveProfileNetworkDelegate::BraveProfileNetworkDelegate(
extensions::EventRouterForwarder* event_router) :
BraveNetworkDelegateBase(event_router) {
Expand Down Expand Up @@ -50,9 +54,11 @@ BraveProfileNetworkDelegate::BraveProfileNetworkDelegate(
callback = base::Bind(brave::OnBeforeURLRequest_TorWork);
before_url_request_callbacks_.push_back(callback);

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE)
callback = base::BindRepeating(
brave::OnBeforeURLRequest_TranslateRedirectWork);
before_url_request_callbacks_.push_back(callback);
#endif

brave::OnBeforeStartTransactionCallback start_transaction_callback =
base::Bind(brave::OnBeforeStartTransaction_SiteHacksWork);
Expand Down
7 changes: 5 additions & 2 deletions browser/net/brave_static_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <vector>

#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/common/network_constants.h"
#include "brave/common/translate_network_constants.h"
#include "extensions/common/url_pattern.h"
Expand All @@ -33,11 +34,12 @@ int OnBeforeURLRequest_StaticRedirectWork(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kCRLSetPrefix4);
static URLPattern crxDownload_pattern(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kCRXDownloadPrefix);
#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE)
static URLPattern translate_pattern(URLPattern::SCHEME_HTTPS,
kTranslateElementJSPattern);
static URLPattern translate_language_pattern(URLPattern::SCHEME_HTTPS,
kTranslateLanguagePattern);

#endif
if (geo_pattern.MatchesURL(ctx->request_url)) {
ctx->new_url_spec = GURL(GOOGLEAPIS_ENDPOINT GOOGLEAPIS_API_KEY).spec();
return net::OK;
Expand Down Expand Up @@ -89,7 +91,7 @@ int OnBeforeURLRequest_StaticRedirectWork(
ctx->new_url_spec = ctx->request_url.ReplaceComponents(replacements).spec();
return net::OK;
}

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE)
if (translate_pattern.MatchesURL(ctx->request_url)) {
replacements.SetQueryStr(ctx->request_url.query_piece());
replacements.SetPathStr(ctx->request_url.path_piece());
Expand All @@ -102,6 +104,7 @@ int OnBeforeURLRequest_StaticRedirectWork(
ctx->new_url_spec = GURL(kBraveTranslateLanguageEndpoint).spec();
return net::OK;
}
#endif

#if !defined(NDEBUG)
GURL gurl = ctx->request_url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "brave/browser/net/url_context.h"
#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/common/network_constants.h"
#include "brave/common/translate_network_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
Expand Down Expand Up @@ -304,6 +305,7 @@ TEST_F(BraveStaticRedirectNetworkDelegateHelperTest,
EXPECT_EQ(ret, net::OK);
}

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE)
TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, RedirectTranslate) {
net::TestDelegate test_delegate;
std::string query_string(
Expand Down Expand Up @@ -350,5 +352,6 @@ TEST_F(BraveStaticRedirectNetworkDelegateHelperTest,
EXPECT_EQ(before_url_context->new_url_spec, expected_url);
EXPECT_EQ(ret, net::OK);
}
#endif

} // namespace
5 changes: 4 additions & 1 deletion browser/resources/settings/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import("//brave/build/config.gni")
import("//chrome/browser/resources/optimize_webui.gni")
import("//chrome/common/features.gni")
import("//tools/grit/grit_rule.gni")

grit("resources") {
source = "settings_resources.grd"

defines = ["is_release_channel=$is_release_channel"]

source_is_generated = optimize_webui

outputs = [
Expand Down Expand Up @@ -50,4 +53,4 @@ if (optimize_webui) {
rebase_path("$target_gen_dir/${pak_file}", root_build_dir),
]
}
}
}
9 changes: 9 additions & 0 deletions browser/resources/settings/brave_settings_overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,16 @@ BravePatching.RegisterPolymerTemplateModifications({
console.error('[Brave Settings Overrides] Could not find manage payments link')
}
manageLink.remove()
},
// <if expr="is_release_channel">
'settings-languages-page': (templateContent) => {
const offerTranslateToggle = templateContent.querySelector('#offerTranslateOtherLanguages')
if (!offerTranslateToggle) {
console.error('[Brave Settings Overrides] Could not find offer translate toggle')
}
offerTranslateToggle.remove()
}
// </if>
})

// Icons
Expand Down
2 changes: 1 addition & 1 deletion browser/resources/settings/settings_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<release seq="1">
<structures>
<structure name="IDR_SETTINGS_BRAVE_SETTINGS_OVERRIDES_HTML" file="brave_settings_overrides.html" type="chrome_html" />
<structure name="IDR_SETTINGS_BRAVE_SETTINGS_OVERRIDES_JS" file="brave_settings_overrides.js" type="chrome_html" />
<structure name="IDR_SETTINGS_BRAVE_SETTINGS_OVERRIDES_JS" file="brave_settings_overrides.js" type="chrome_html" preprocess="true" />
<structure name="IDR_SETTINGS_BRAVE_ICONS_HTML" file="brave_icons.html" type="chrome_html" />
<structure name="IDR_SETTINGS_DEFAULT_BRAVE_SHIELDS_BROWSER_PROXY_HTML" file="default_brave_shields_page/default_brave_shields_browser_proxy.html" type="chrome_html" />
<structure name="IDR_SETTINGS_DEFAULT_BRAVE_SHIELDS_BROWSER_PROXY_JS" file="default_brave_shields_page/default_brave_shields_browser_proxy.js" type="chrome_html" preprocess="true" />
Expand Down
9 changes: 9 additions & 0 deletions browser/translate/buildflags/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import("//build/buildflag_header.gni")
import("//brave/browser/translate/buildflags/buildflags.gni")

buildflag_header("buildflags") {
header = "buildflags.h"
flags = [
"ENABLE_BRAVE_TRANSLATE=$enable_brave_translate",
]
}
6 changes: 6 additions & 0 deletions browser/translate/buildflags/buildflags.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import("//brave/build/config.gni")
import("//build/config/features.gni")

declare_args() {
enable_brave_translate = !is_release_channel
}
4 changes: 3 additions & 1 deletion build/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare_args() {
# "nightly" for nightly channel release.
# "" for stable channel release.
brave_channel = ""

is_release_channel = true
base_sparkle_update_url = ""

brave_dsa_file = "dsa_pub.pem"
Expand Down Expand Up @@ -104,3 +104,5 @@ if (is_win) {
} else if (is_linux) {
brave_platform = "linux"
}

is_release_channel = brave_channel == ""
17 changes: 17 additions & 0 deletions chromium_src/chrome/browser/translate/translate_service.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/translate/buildflags/buildflags.h"

namespace {
bool IsBraveTranslateEnabled() {
#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE)
return true;
#endif
return false;
}
} // namespace

#include "../../../../../../chrome/browser/translate/translate_service.cc" // NOLINT
13 changes: 13 additions & 0 deletions patches/chrome-browser-translate-translate_service.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/chrome/browser/translate/translate_service.cc b/chrome/browser/translate/translate_service.cc
index 06eacc6c808221f905aea64e33dd64a3e373bb62..22e589b8729d7f197aeac2b1c9a230b9344d24b0 100644
--- a/chrome/browser/translate/translate_service.cc
+++ b/chrome/browser/translate/translate_service.cc
@@ -136,7 +136,7 @@ bool TranslateService::IsTranslatableURL(const GURL& url) {
// - Chrome OS file manager extension
// - an FTP page (as FTP pages tend to have long lists of filenames that may
// confuse the CLD)
- return !url.is_empty() && !url.SchemeIs(content::kChromeUIScheme) &&
+ return IsBraveTranslateEnabled() && !url.is_empty() && !url.SchemeIs(content::kChromeUIScheme) &&
!url.SchemeIs(content::kChromeDevToolsScheme) &&
#if defined(OS_CHROMEOS)
!(url.SchemeIs(extensions::kExtensionScheme) &&
8 changes: 7 additions & 1 deletion test/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import("//brave/build/config.gni")
import("//brave/browser/translate/buildflags/buildflags.gni")
import("//brave/components/brave_ads/browser/buildflags/buildflags.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
import("//testing/test.gni")
Expand Down Expand Up @@ -56,7 +57,6 @@ test("brave_unit_tests") {
"//brave/browser/net/brave_site_hacks_network_delegate_helper_unittest.cc",
"//brave/browser/net/brave_static_redirect_network_delegate_helper_unittest.cc",
"//brave/browser/net/brave_tor_network_delegate_helper_unittest.cc",
"//brave/browser/net/brave_translate_redirect_network_delegate_helper_unittest.cc",
"//brave/browser/profiles/tor_unittest_profile_manager.cc",
"//brave/browser/profiles/tor_unittest_profile_manager.h",
"//brave/browser/profiles/brave_profile_manager_unittest.cc",
Expand Down Expand Up @@ -139,6 +139,12 @@ test("brave_unit_tests") {
]
}

if (enable_brave_translate) {
sources += [
"//brave/browser/net/brave_translate_redirect_network_delegate_helper_unittest.cc",
]
}

# On Windows, brave_install_static_unittests covers channel test.
if (is_mac || is_linux) {
sources += [
Expand Down