Skip to content

Commit

Permalink
Add support for chrome://net-export in WebLayer to debug network prob…
Browse files Browse the repository at this point in the history
…lems.

Also fix chrome:// URLs not working in weblayer_shell.

Bug: 1254558
Change-Id: I3cc841afa0a7db5378bbf6c3f9dc173770ad34a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3195531
Auto-Submit: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#927258}
  • Loading branch information
John Abd-El-Malek authored and Chromium LUCI CQ committed Oct 1, 2021
1 parent 6e965a0 commit 3b560b7
Show file tree
Hide file tree
Showing 20 changed files with 278 additions and 27 deletions.
1 change: 0 additions & 1 deletion chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,6 @@ generate_jni("chrome_jni_headers") {
"java/src/org/chromium/chrome/browser/ChromePowerModeVoter.java",
"java/src/org/chromium/chrome/browser/DevToolsServer.java",
"java/src/org/chromium/chrome/browser/IntentHandler.java",
"java/src/org/chromium/chrome/browser/IntentHelper.java",
"java/src/org/chromium/chrome/browser/NearOomMonitor.java",
"java/src/org/chromium/chrome/browser/PlayServicesVersionInfo.java",
"java/src/org/chromium/chrome/browser/SearchGeolocationDisclosureTabHelper.java",
Expand Down
1 change: 0 additions & 1 deletion chrome/android/chrome_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/DevToolsServer.java",
"java/src/org/chromium/chrome/browser/FileProviderHelper.java",
"java/src/org/chromium/chrome/browser/IntentHandler.java",
"java/src/org/chromium/chrome/browser/IntentHelper.java",
"java/src/org/chromium/chrome/browser/KeyboardShortcuts.java",
"java/src/org/chromium/chrome/browser/LaunchIntentDispatcher.java",
"java/src/org/chromium/chrome/browser/LauncherShortcutActivity.java",
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2813,8 +2813,6 @@ static_library("browser") {
"android/instantapps/instant_apps_settings.cc",
"android/instantapps/instant_apps_settings.h",
"android/intent_handler.cc",
"android/intent_helper.cc",
"android/intent_helper.h",
"android/javascript/web_context_fetcher.cc",
"android/locale/locale_manager.cc",
"android/locale/locale_manager.h",
Expand Down Expand Up @@ -3370,6 +3368,7 @@ static_library("browser") {
"//components/bookmarks/common/android",
"//components/browser_ui/contacts_picker/android",
"//components/browser_ui/photo_picker/android",
"//components/browser_ui/share/android",
"//components/browser_ui/site_settings/android",
"//components/browser_ui/sms/android",
"//components/browser_ui/util/android",
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ static_library("ui") {
"//chrome/browser/ui/webui/explore_sites_internals:mojo_bindings",
"//chrome/browser/ui/webui/feed_internals:mojo_bindings",
"//components/browser_ui/client_certificate/android",
"//components/browser_ui/share/android",
"//components/browser_ui/util/android",
"//components/embedder_support/android:context_menu",
"//components/embedder_support/android:web_contents_delegate",
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/webui/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_rules = [
"+ash/components/account_manager",
"+ash/components/audio",
"+ash/webui/os_feedback_ui",
"+components/browser_ui/share/android",
"+components/services/app_service/public",
"+device/bluetooth",
"+extensions/strings/grit/extensions_strings.h",
Expand Down
9 changes: 4 additions & 5 deletions chrome/browser/ui/webui/net_export_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "ui/shell_dialogs/select_file_dialog.h"

#if defined(OS_ANDROID)
#include "chrome/browser/android/intent_helper.h"
#include "components/browser_ui/share/android/intent_helper.h"
#endif

using content::BrowserThread;
Expand Down Expand Up @@ -311,10 +311,9 @@ void NetExportMessageHandler::SendEmail(const base::FilePath& file_to_send) {
std::string body =
"Please add some informative text about the network issues.";
base::FilePath::StringType file_to_attach(file_to_send.value());
chrome::android::SendEmail(
base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject),
base::UTF8ToUTF16(body), base::UTF8ToUTF16(title),
base::UTF8ToUTF16(file_to_attach));
browser_ui::SendEmail(base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject),
base::UTF8ToUTF16(body), base::UTF8ToUTF16(title),
base::UTF8ToUTF16(file_to_attach));
#endif
}

Expand Down
17 changes: 17 additions & 0 deletions components/browser_ui/share/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

import("//build/config/android/rules.gni")

source_set("android") {
sources = [
"intent_helper.cc",
"intent_helper.h",
]
deps = [
":jni_headers",
"//base",
]
}

generate_jni("jni_headers") {
sources =
[ "java/src/org/chromium/components/browser_ui/share/IntentHelper.java" ]
}

# Constants only target without dependencies to allow embedders to only include relevant code.
android_library("constants_java") {
sources = [
Expand All @@ -14,6 +30,7 @@ android_library("constants_java") {
android_library("java") {
sources = [
"java/src/org/chromium/components/browser_ui/share/ClipboardImageFileProvider.java",
"java/src/org/chromium/components/browser_ui/share/IntentHelper.java",
"java/src/org/chromium/components/browser_ui/share/ShareDialogAdapter.java",
"java/src/org/chromium/components/browser_ui/share/ShareHelper.java",
"java/src/org/chromium/components/browser_ui/share/ShareImageFileUtils.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/android/intent_helper.h"
#include "components/browser_ui/share/android/intent_helper.h"

#include <jni.h>

#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "chrome/android/chrome_jni_headers/IntentHelper_jni.h"
#include "components/browser_ui/share/android/jni_headers/IntentHelper_jni.h"

using base::android::AttachCurrentThread;
using base::android::ConvertUTF16ToJavaString;
using base::android::ScopedJavaLocalRef;

namespace chrome {
namespace android {
namespace browser_ui {

void SendEmail(const std::u16string& d_email,
const std::u16string& d_subject,
Expand All @@ -36,5 +35,4 @@ void SendEmail(const std::u16string& d_email,
j_file_to_attach);
}

} // namespace android
} // namespace chrome
} // namespace browser_ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ANDROID_INTENT_HELPER_H_
#define CHROME_BROWSER_ANDROID_INTENT_HELPER_H_
#ifndef COMPONENTS_BROWSER_UI_SHARE_ANDROID_INTENT_HELPER_H_
#define COMPONENTS_BROWSER_UI_SHARE_ANDROID_INTENT_HELPER_H_

#include <jni.h>

#include <string>


namespace chrome {
namespace android {
namespace browser_ui {

// Triggers a send email intent.
void SendEmail(const std::u16string& data_email,
Expand All @@ -20,7 +18,6 @@ void SendEmail(const std::u16string& data_email,
const std::u16string& data_chooser_title,
const std::u16string& data_file_to_attach);

} // namespace android
} // namespace chrome
} // namespace browser_ui

#endif // CHROME_BROWSER_ANDROID_INTENT_HELPER_H_
#endif // COMPONENTS_BROWSER_UI_SHARE_ANDROID_INTENT_HELPER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser;
package org.chromium.components.browser_ui.share;

import android.content.Intent;
import android.net.Uri;
Expand All @@ -19,7 +19,6 @@
* Helper for issuing intents to the android framework.
*/
public abstract class IntentHelper {

private IntentHelper() {}

/**
Expand All @@ -37,7 +36,7 @@ static void sendEmail(
String email, String subject, String body, String chooserTitle, String fileToAttach) {
Intent send = new Intent(Intent.ACTION_SEND);
send.setType("message/rfc822");
if (!TextUtils.isEmpty(email)) send.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
if (!TextUtils.isEmpty(email)) send.putExtra(Intent.EXTRA_EMAIL, new String[] {email});
send.putExtra(Intent.EXTRA_SUBJECT, subject);
send.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
if (!TextUtils.isEmpty(fileToAttach)) {
Expand Down
4 changes: 4 additions & 0 deletions weblayer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ source_set("weblayer_lib_base") {
"browser/weblayer_speech_recognition_manager_delegate.h",
"browser/weblayer_variations_service_client.cc",
"browser/weblayer_variations_service_client.h",
"browser/webui/net_export_ui.cc",
"browser/webui/net_export_ui.h",
"browser/webui/web_ui_controller_factory.cc",
"browser/webui/web_ui_controller_factory.h",
"browser/webui/weblayer_internals_ui.cc",
Expand Down Expand Up @@ -440,6 +442,7 @@ source_set("weblayer_lib_base") {
"//components/language/core/browser",
"//components/leveldb_proto",
"//components/metrics",
"//components/net_log",
"//components/network_time",
"//components/no_state_prefetch/browser",
"//components/no_state_prefetch/common",
Expand Down Expand Up @@ -704,6 +707,7 @@ source_set("weblayer_lib_base") {
"//components/browser_ui/client_certificate/android",
"//components/browser_ui/contacts_picker/android",
"//components/browser_ui/photo_picker/android",
"//components/browser_ui/share/android",
"//components/browser_ui/site_settings/android",
"//components/browser_ui/sms/android",
"//components/cdm/browser",
Expand Down
1 change: 1 addition & 0 deletions weblayer/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ include_rules = [
"+components/media_router",
"+components/metrics",
"+components/navigation_interception",
"+components/net_log",
"+components/network_session_configurator",
"+components/network_time",
"+components/page_load_metrics/browser",
Expand Down
9 changes: 9 additions & 0 deletions weblayer/browser/system_network_context_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/net_log/net_export_file_writer.h"
#include "components/variations/net/variations_http_headers.h"
#include "content/public/browser/network_service_instance.h"
#include "services/cert_verifier/public/mojom/cert_verifier_service_factory.mojom.h"
Expand Down Expand Up @@ -129,4 +130,12 @@ SystemNetworkContextManager::GetSharedURLLoaderFactory() {
return shared_url_loader_factory_;
}

net_log::NetExportFileWriter*
SystemNetworkContextManager::GetNetExportFileWriter() {
if (!net_export_file_writer_) {
net_export_file_writer_ = std::make_unique<net_log::NetExportFileWriter>();
}
return net_export_file_writer_.get();
}

} // namespace weblayer
12 changes: 12 additions & 0 deletions weblayer/browser/system_network_context_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace network {
class SharedURLLoaderFactory;
} // namespace network

namespace net_log {
class NetExportFileWriter;
}

namespace weblayer {

// Manages a system-wide network context that's not tied to a profile.
Expand Down Expand Up @@ -63,6 +67,11 @@ class SystemNetworkContextManager {
// network service crashes.
scoped_refptr<network::SharedURLLoaderFactory> GetSharedURLLoaderFactory();

// Returns a shared global NetExportFileWriter instance, used by net-export.
// It lives here so it can outlive chrome://net-export/ if the tab is closed
// or destroyed, and so that it's destroyed before Mojo is shut down.
net_log::NetExportFileWriter* GetNetExportFileWriter();

private:
explicit SystemNetworkContextManager(const std::string& user_agent);

Expand All @@ -76,6 +85,9 @@ class SystemNetworkContextManager {
shared_url_loader_factory_;

mojo::Remote<network::mojom::NetworkContext> system_network_context_;

// Initialized on first access.
std::unique_ptr<net_log::NetExportFileWriter> net_export_file_writer_;
};

} // namespace weblayer
Expand Down
Loading

0 comments on commit 3b560b7

Please sign in to comment.