Commit 07c1a090 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[SSL] Componentize launching of date and time settings

This CL componentizes the implementation of launching of date and time
settings found in //chrome's SSLErrorControllerClient in order to reuse
this functionality in WebLayer (that reuse will happen in a followup).
The code has no //chrome dependencies. We placed it in the
security_interstitials component as that is the only consumer of this
functionality at this time; if need be it can be moved into a more
generalized location (e.g., a standalone component) in the future.

Tested manually that visiting the bad clock interstitial and clicking
"update date and time" still works as expected on Android (note that on
Linux, the other platform where I can locally test, this already
doesn't work as expected; filed as crbug.com/1051427).

Change-Id: I062dbf61392c329f11d9a3f8af748a4ec2086d05
Bug: 1030692
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1988353
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740629}
parent bb0bfa07
......@@ -76,20 +76,4 @@ public abstract class IntentHelper {
// If no app handles it, do nothing.
}
}
/**
* Opens date and time in Android settings.
*
*/
@CalledByNative
static void openDateAndTimeSettings() {
Intent intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
try {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ContextUtils.getApplicationContext().startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
// If it doesn't work, avoid crashing.
}
}
}
......@@ -36,10 +36,5 @@ void SendEmail(const base::string16& d_email,
j_file_to_attach);
}
void OpenDateAndTimeSettings() {
JNIEnv* env = AttachCurrentThread();
Java_IntentHelper_openDateAndTimeSettings(env);
}
} // namespace android
} // namespace chrome
......@@ -19,9 +19,6 @@ void SendEmail(const base::string16& data_email,
const base::string16& data_chooser_title,
const base::string16& data_file_to_attach);
// Triggers an intent to open the date and time settings.
void OpenDateAndTimeSettings();
} // namespace android
} // namespace chrome
......
......@@ -23,13 +23,10 @@
#include "chrome/common/url_constants.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/security_interstitials/content/content_metrics_helper.h"
#include "components/security_interstitials/content/utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/intent_helper.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
......@@ -72,81 +69,6 @@ bool HasSeenRecurrentErrorInternal(content::WebContents* web_contents,
return state->HasSeenRecurrentErrors(cert_error);
}
#if !defined(OS_CHROMEOS)
void LaunchDateAndTimeSettingsImpl() {
// The code for each OS is completely separate, in order to avoid bugs like
// https://crbug.com/430877 . ChromeOS is handled on the UI thread.
#if defined(OS_ANDROID)
chrome::android::OpenDateAndTimeSettings();
#elif defined(OS_LINUX)
struct ClockCommand {
const char* const pathname;
const char* const argument;
};
static const ClockCommand kClockCommands[] = {
// Unity
{"/usr/bin/unity-control-center", "datetime"},
// GNOME
//
// NOTE: On old Ubuntu, naming control panels doesn't work, so it
// opens the overview. This will have to be good enough.
{"/usr/bin/gnome-control-center", "datetime"},
{"/usr/local/bin/gnome-control-center", "datetime"},
{"/opt/bin/gnome-control-center", "datetime"},
// KDE
{"/usr/bin/kcmshell4", "clock"},
{"/usr/local/bin/kcmshell4", "clock"},
{"/opt/bin/kcmshell4", "clock"},
};
base::CommandLine command(base::FilePath(""));
for (const ClockCommand& cmd : kClockCommands) {
base::FilePath pathname(cmd.pathname);
if (base::PathExists(pathname)) {
command.SetProgram(pathname);
command.AppendArg(cmd.argument);
break;
}
}
if (command.GetProgram().empty()) {
// Alas, there is nothing we can do.
return;
}
base::LaunchOptions options;
options.wait = false;
options.allow_new_privs = true;
base::LaunchProcess(command, options);
#elif defined(OS_MACOSX)
base::CommandLine command(base::FilePath("/usr/bin/open"));
command.AppendArg("/System/Library/PreferencePanes/DateAndTime.prefPane");
base::LaunchOptions options;
options.wait = false;
base::LaunchProcess(command, options);
#elif defined(OS_WIN)
base::FilePath path;
base::PathService::Get(base::DIR_SYSTEM, &path);
static const base::char16 kControlPanelExe[] = L"control.exe";
path = path.Append(base::string16(kControlPanelExe));
base::CommandLine command(path);
command.AppendArg(std::string("/name"));
command.AppendArg(std::string("Microsoft.DateAndTime"));
base::LaunchOptions options;
options.wait = false;
base::LaunchProcess(command, options);
#else
#error Unsupported target architecture.
#endif
// Don't add code here! (See the comment at the beginning of the function.)
}
#endif
} // namespace
SSLErrorControllerClient::SSLErrorControllerClient(
......@@ -223,7 +145,7 @@ void SSLErrorControllerClient::LaunchDateAndTimeSettings() {
base::PostTask(
FROM_HERE,
{base::ThreadPool(), base::TaskPriority::USER_VISIBLE, base::MayBlock()},
base::BindOnce(&LaunchDateAndTimeSettingsImpl));
base::BindOnce(&security_interstitials::LaunchDateAndTimeSettings));
#endif
}
......
......@@ -58,6 +58,8 @@ static_library("security_interstitial_page") {
"unsafe_resource_util.h",
"urls.cc",
"urls.h",
"utils.cc",
"utils.h",
]
public_deps = [
......
......@@ -6,12 +6,18 @@ import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
generate_jni("jni_headers") {
sources = [ "java/src/org/chromium/components/security_interstitials/CaptivePortalHelper.java" ]
sources = [
"java/src/org/chromium/components/security_interstitials/CaptivePortalHelper.java",
"java/src/org/chromium/components/security_interstitials/DateAndTimeSettingsHelper.java",
]
}
android_library("java") {
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
sources = [ "java/src/org/chromium/components/security_interstitials/CaptivePortalHelper.java" ]
sources = [
"java/src/org/chromium/components/security_interstitials/CaptivePortalHelper.java",
"java/src/org/chromium/components/security_interstitials/DateAndTimeSettingsHelper.java",
]
deps = [
"//base:base_java",
"//base:jni_java",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.security_interstitials;
import android.content.Intent;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
/**
* Helper for opening date and time settings.
*/
@JNINamespace("security_interstitials")
public abstract class DateAndTimeSettingsHelper {
private DateAndTimeSettingsHelper() {}
/**
* Opens date and time in Android settings.
*
*/
@CalledByNative
static void openDateAndTimeSettings() {
Intent intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
try {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ContextUtils.getApplicationContext().startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
// If it doesn't work, avoid crashing.
}
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/security_interstitials/content/utils.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/process/launch.h"
#include "build/build_config.h"
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "components/security_interstitials/content/android/jni_headers/DateAndTimeSettingsHelper_jni.h"
#endif
#if defined(OS_WIN)
#include "base/base_paths_win.h"
#include "base/path_service.h"
#include "base/strings/string16.h"
#endif
namespace security_interstitials {
#if !defined(OS_CHROMEOS) && !defined(OS_FUCHSIA)
void LaunchDateAndTimeSettings() {
// The code for each OS is completely separate, in order to avoid bugs like
// https://crbug.com/430877 .
#if defined(OS_ANDROID)
JNIEnv* env = base::android::AttachCurrentThread();
Java_DateAndTimeSettingsHelper_openDateAndTimeSettings(env);
#elif defined(OS_LINUX)
struct ClockCommand {
const char* const pathname;
const char* const argument;
};
static const ClockCommand kClockCommands[] = {
// Unity
{"/usr/bin/unity-control-center", "datetime"},
// GNOME
//
// NOTE: On old Ubuntu, naming control panels doesn't work, so it
// opens the overview. This will have to be good enough.
{"/usr/bin/gnome-control-center", "datetime"},
{"/usr/local/bin/gnome-control-center", "datetime"},
{"/opt/bin/gnome-control-center", "datetime"},
// KDE
{"/usr/bin/kcmshell4", "clock"},
{"/usr/local/bin/kcmshell4", "clock"},
{"/opt/bin/kcmshell4", "clock"},
};
base::CommandLine command(base::FilePath(""));
for (const ClockCommand& cmd : kClockCommands) {
base::FilePath pathname(cmd.pathname);
if (base::PathExists(pathname)) {
command.SetProgram(pathname);
command.AppendArg(cmd.argument);
break;
}
}
if (command.GetProgram().empty()) {
// Alas, there is nothing we can do.
return;
}
base::LaunchOptions options;
options.wait = false;
options.allow_new_privs = true;
base::LaunchProcess(command, options);
#elif defined(OS_MACOSX)
base::CommandLine command(base::FilePath("/usr/bin/open"));
command.AppendArg("/System/Library/PreferencePanes/DateAndTime.prefPane");
base::LaunchOptions options;
options.wait = false;
base::LaunchProcess(command, options);
#elif defined(OS_WIN)
base::FilePath path;
base::PathService::Get(base::DIR_SYSTEM, &path);
static const base::char16 kControlPanelExe[] = L"control.exe";
path = path.Append(base::string16(kControlPanelExe));
base::CommandLine command(path);
command.AppendArg(std::string("/name"));
command.AppendArg(std::string("Microsoft.DateAndTime"));
base::LaunchOptions options;
options.wait = false;
base::LaunchProcess(command, options);
#else
#error Unsupported target architecture.
#endif
// Don't add code here! (See the comment at the beginning of the function.)
}
#endif
} // namespace security_interstitials
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_UTILS_H_
#define COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_UTILS_H_
#include "build/build_config.h"
namespace security_interstitials {
// Provides utilities for security interstitials on //content-based platforms.
#if !defined(OS_CHROMEOS) && !defined(OS_FUCHSIA)
// Launches date and time settings as appropriate based on the platform (not
// supported on ChromeOS, where taking this action requires embedder-level
// machinery, or Fuchsia, which simply doesn't require this functionality).
void LaunchDateAndTimeSettings();
#endif
} // namespace security_interstitials
#endif // COMPONENTS_SECURITY_INTERSTITIALS_CONTENT_UTILS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment