2019-02-25 19:25:17 +01:00
|
|
|
diff --git chrome/browser/ui/BUILD.gn chrome/browser/ui/BUILD.gn
|
2019-10-01 15:55:16 +02:00
|
|
|
index 3b387d754736..2c537f9c15c1 100644
|
2019-02-25 19:25:17 +01:00
|
|
|
--- chrome/browser/ui/BUILD.gn
|
|
|
|
+++ chrome/browser/ui/BUILD.gn
|
2019-07-16 19:59:21 +02:00
|
|
|
@@ -10,6 +10,7 @@ import("//build/config/jumbo.gni")
|
|
|
|
import("//build/config/linux/gtk/gtk.gni")
|
2019-02-25 19:25:17 +01:00
|
|
|
import("//build/config/ui.gni")
|
|
|
|
import("//build/split_static_library.gni")
|
|
|
|
+import("//cef/libcef/features/features.gni")
|
|
|
|
import("//chrome/common/features.gni")
|
|
|
|
import("//chromeos/assistant/assistant.gni")
|
|
|
|
import("//components/feature_engagement/features.gni")
|
2019-10-01 15:55:16 +02:00
|
|
|
@@ -370,6 +371,10 @@ jumbo_split_static_library("ui") {
|
2019-02-25 19:25:17 +01:00
|
|
|
"//build/config/compiler:wexit_time_destructors",
|
|
|
|
]
|
|
|
|
|
|
|
|
+ if (enable_cef) {
|
|
|
|
+ configs += [ "//cef/libcef/features:config" ]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
# Since browser and browser_ui actually depend on each other,
|
|
|
|
# we must omit the dependency from browser_ui to browser.
|
|
|
|
# However, this means browser_ui and browser should more or less
|
2019-10-01 15:55:16 +02:00
|
|
|
@@ -388,6 +393,7 @@ jumbo_split_static_library("ui") {
|
2019-02-25 19:25:17 +01:00
|
|
|
"//base:i18n",
|
|
|
|
"//base/allocator:buildflags",
|
|
|
|
"//cc/paint",
|
|
|
|
+ "//cef/libcef/features",
|
|
|
|
"//chrome:extra_resources",
|
|
|
|
"//chrome:resources",
|
|
|
|
"//chrome:strings",
|
2018-10-24 22:37:39 +02:00
|
|
|
diff --git chrome/browser/ui/webui/net_export_ui.cc chrome/browser/ui/webui/net_export_ui.cc
|
2019-10-01 15:55:16 +02:00
|
|
|
index 081ef17bf0d9..46b1d1af2baa 100644
|
2018-10-24 22:37:39 +02:00
|
|
|
--- chrome/browser/ui/webui/net_export_ui.cc
|
|
|
|
+++ chrome/browser/ui/webui/net_export_ui.cc
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -20,13 +20,12 @@
|
2019-02-25 19:25:17 +01:00
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "base/values.h"
|
|
|
|
+#include "cef/libcef/features/features.h"
|
|
|
|
#include "chrome/browser/browser_process.h"
|
|
|
|
-#include "chrome/browser/download/download_prefs.h"
|
|
|
|
#include "chrome/browser/net/net_export_helper.h"
|
|
|
|
#include "chrome/browser/net/system_network_context_manager.h"
|
|
|
|
#include "chrome/browser/platform_util.h"
|
|
|
|
#include "chrome/browser/profiles/profile.h"
|
|
|
|
-#include "chrome/browser/ui/chrome_select_file_policy.h"
|
|
|
|
#include "chrome/common/channel_info.h"
|
|
|
|
#include "chrome/common/url_constants.h"
|
|
|
|
#include "components/grit/components_resources.h"
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -41,7 +40,14 @@
|
2019-02-25 19:25:17 +01:00
|
|
|
#include "content/public/browser/web_ui_message_handler.h"
|
|
|
|
#include "extensions/buildflags/buildflags.h"
|
|
|
|
#include "net/log/net_log_capture_mode.h"
|
|
|
|
+
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
+#include "chrome/browser/download/download_prefs.h"
|
|
|
|
+#include "chrome/browser/ui/chrome_select_file_policy.h"
|
|
|
|
#include "ui/shell_dialogs/select_file_dialog.h"
|
|
|
|
+#else
|
|
|
|
+#include "cef/libcef/browser/browser_host_impl.h"
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
#if defined(OS_ANDROID)
|
|
|
|
#include "chrome/browser/android/intent_helper.h"
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -67,6 +73,7 @@ content::WebUIDataSource* CreateNetExportHTMLSource() {
|
2019-02-25 19:25:17 +01:00
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
void SetIfNotNull(base::DictionaryValue* dict,
|
|
|
|
const base::StringPiece& path,
|
|
|
|
std::unique_ptr<base::Value> in_value) {
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -74,6 +81,7 @@ void SetIfNotNull(base::DictionaryValue* dict,
|
2019-02-25 19:25:17 +01:00
|
|
|
dict->Set(path, std::move(in_value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+#endif // !BUILDFLAG(ENABLE_CEF)
|
|
|
|
|
|
|
|
// This class receives javascript messages from the renderer.
|
|
|
|
// Note that the WebUI infrastructure runs on the UI thread, therefore all of
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -81,7 +89,9 @@ void SetIfNotNull(base::DictionaryValue* dict,
|
2019-02-25 19:25:17 +01:00
|
|
|
class NetExportMessageHandler
|
|
|
|
: public WebUIMessageHandler,
|
|
|
|
public base::SupportsWeakPtr<NetExportMessageHandler>,
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
public ui::SelectFileDialog::Listener,
|
|
|
|
+#endif
|
|
|
|
public net_log::NetExportFileWriter::StateObserver {
|
|
|
|
public:
|
|
|
|
NetExportMessageHandler();
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -97,11 +107,13 @@ class NetExportMessageHandler
|
2019-02-25 19:25:17 +01:00
|
|
|
void OnSendNetLog(const base::ListValue* list);
|
|
|
|
void OnShowFile(const base::ListValue* list);
|
|
|
|
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
// ui::SelectFileDialog::Listener implementation.
|
|
|
|
void FileSelected(const base::FilePath& path,
|
|
|
|
int index,
|
|
|
|
void* params) override;
|
|
|
|
void FileSelectionCanceled(void* params) override;
|
|
|
|
+#endif // !BUILDFLAG(ENABLE_CEF)
|
|
|
|
|
|
|
|
// net_log::NetExportFileWriter::StateObserver implementation.
|
|
|
|
void OnNewState(const base::DictionaryValue& state) override;
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -131,9 +143,16 @@ class NetExportMessageHandler
|
2019-02-25 19:25:17 +01:00
|
|
|
// renderer.
|
|
|
|
void NotifyUIWithState(std::unique_ptr<base::DictionaryValue> state);
|
|
|
|
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
// Opens the SelectFileDialog UI with the default path to save a
|
|
|
|
// NetLog file.
|
|
|
|
void ShowSelectFileDialog(const base::FilePath& default_path);
|
|
|
|
+#else
|
|
|
|
+ void ShowCefSaveAsDialog(content::WebContents* web_contents);
|
|
|
|
+ void SaveAsDialogDismissed(
|
|
|
|
+ int selected_accept_filter,
|
|
|
|
+ const std::vector<base::FilePath>& file_paths);
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
// Cached pointer to SystemNetworkContextManager's NetExportFileWriter.
|
|
|
|
net_log::NetExportFileWriter* file_writer_;
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -149,7 +168,9 @@ class NetExportMessageHandler
|
2019-02-25 19:25:17 +01:00
|
|
|
net::NetLogCaptureMode capture_mode_;
|
|
|
|
uint64_t max_log_file_size_;
|
|
|
|
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
|
|
|
|
+#endif
|
|
|
|
|
2019-09-04 17:13:32 +02:00
|
|
|
base::WeakPtrFactory<NetExportMessageHandler> weak_ptr_factory_{this};
|
2019-02-25 19:25:17 +01:00
|
|
|
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -166,8 +187,10 @@ NetExportMessageHandler::NetExportMessageHandler()
|
2019-02-25 19:25:17 +01:00
|
|
|
NetExportMessageHandler::~NetExportMessageHandler() {
|
|
|
|
// There may be a pending file dialog, it needs to be told that the user
|
|
|
|
// has gone away so that it doesn't try to call back.
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
if (select_file_dialog_)
|
|
|
|
select_file_dialog_->ListenerDestroyed();
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
file_writer_->StopNetLog(nullptr);
|
|
|
|
}
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -230,6 +253,7 @@ void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
|
2019-02-25 19:25:17 +01:00
|
|
|
if (UsingMobileUI()) {
|
|
|
|
StartNetLog(base::FilePath());
|
|
|
|
} else {
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
base::FilePath initial_dir = last_save_dir.Pointer()->empty() ?
|
|
|
|
DownloadPrefs::FromBrowserContext(
|
|
|
|
web_ui()->GetWebContents()->GetBrowserContext())->DownloadPath() :
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -237,6 +261,9 @@ void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
|
2019-02-25 19:25:17 +01:00
|
|
|
base::FilePath initial_path =
|
|
|
|
initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json"));
|
|
|
|
ShowSelectFileDialog(initial_path);
|
|
|
|
+#else // BUILDFLAG(ENABLE_CEF)
|
|
|
|
+ ShowCefSaveAsDialog(web_ui()->GetWebContents());
|
|
|
|
+#endif // BUILDFLAG(ENABLE_CEF)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -246,6 +273,7 @@ void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) {
|
2019-02-25 19:25:17 +01:00
|
|
|
std::unique_ptr<base::DictionaryValue> ui_thread_polled_data(
|
|
|
|
new base::DictionaryValue());
|
|
|
|
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
Profile* profile = Profile::FromWebUI(web_ui());
|
|
|
|
SetIfNotNull(ui_thread_polled_data.get(), "prerenderInfo",
|
|
|
|
chrome_browser_net::GetPrerenderInfo(profile));
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -255,6 +283,7 @@ void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) {
|
2019-02-25 19:25:17 +01:00
|
|
|
SetIfNotNull(ui_thread_polled_data.get(), "serviceProviders",
|
|
|
|
chrome_browser_net::GetWindowsServiceProviders());
|
|
|
|
#endif
|
|
|
|
+#endif // !BUILDFLAG(ENABLE_CEF)
|
|
|
|
|
|
|
|
file_writer_->StopNetLog(std::move(ui_thread_polled_data));
|
|
|
|
}
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -271,6 +300,7 @@ void NetExportMessageHandler::OnShowFile(const base::ListValue* list) {
|
2019-02-25 19:25:17 +01:00
|
|
|
base::Bind(&NetExportMessageHandler::ShowFileInShell, AsWeakPtr()));
|
|
|
|
}
|
|
|
|
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
void NetExportMessageHandler::FileSelected(const base::FilePath& path,
|
|
|
|
int index,
|
|
|
|
void* params) {
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -289,6 +319,7 @@ void NetExportMessageHandler::FileSelectionCanceled(void* params) {
|
2019-02-25 19:25:17 +01:00
|
|
|
DCHECK(select_file_dialog_);
|
|
|
|
select_file_dialog_ = nullptr;
|
|
|
|
}
|
|
|
|
+#endif // !BUILDFLAG(ENABLE_CEF)
|
|
|
|
|
|
|
|
void NetExportMessageHandler::OnNewState(const base::DictionaryValue& state) {
|
|
|
|
NotifyUIWithState(state.CreateDeepCopy());
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -353,6 +384,7 @@ void NetExportMessageHandler::NotifyUIWithState(
|
2019-02-25 19:25:17 +01:00
|
|
|
*state);
|
|
|
|
}
|
|
|
|
|
|
|
|
+#if !BUILDFLAG(ENABLE_CEF)
|
|
|
|
void NetExportMessageHandler::ShowSelectFileDialog(
|
|
|
|
const base::FilePath& default_path) {
|
|
|
|
// User may have clicked more than once before the save dialog appears.
|
2019-09-04 17:13:32 +02:00
|
|
|
@@ -371,6 +403,43 @@ void NetExportMessageHandler::ShowSelectFileDialog(
|
2019-02-25 19:25:17 +01:00
|
|
|
ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), default_path,
|
|
|
|
&file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr);
|
|
|
|
}
|
|
|
|
+#endif // !BUILDFLAG(ENABLE_CEF)
|
|
|
|
+
|
|
|
|
+#if BUILDFLAG(ENABLE_CEF)
|
|
|
|
+
|
|
|
|
+void NetExportMessageHandler::ShowCefSaveAsDialog(
|
|
|
|
+ content::WebContents* web_contents) {
|
|
|
|
+ CefRefPtr<CefBrowserHostImpl> cef_browser =
|
|
|
|
+ CefBrowserHostImpl::GetBrowserForContents(web_contents);
|
|
|
|
+ if (!cef_browser)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ base::FilePath initial_dir;
|
|
|
|
+ if (!last_save_dir.Pointer()->empty())
|
|
|
|
+ initial_dir = *last_save_dir.Pointer();
|
|
|
|
+ base::FilePath initial_path =
|
|
|
|
+ initial_dir.Append(FILE_PATH_LITERAL("chrome-net-export-log.json"));
|
|
|
|
+
|
|
|
|
+ CefFileDialogRunner::FileChooserParams params;
|
|
|
|
+ params.mode = blink::mojom::FileChooserParams::Mode::kSave;
|
|
|
|
+ params.default_file_name = initial_path;
|
|
|
|
+ params.accept_types.push_back(CefString(initial_path.Extension()));
|
|
|
|
+
|
|
|
|
+ cef_browser->RunFileChooser(
|
|
|
|
+ params, base::Bind(&NetExportMessageHandler::SaveAsDialogDismissed,
|
|
|
|
+ weak_ptr_factory_.GetWeakPtr()));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void NetExportMessageHandler::SaveAsDialogDismissed(
|
|
|
|
+ int selected_accept_filter,
|
|
|
|
+ const std::vector<base::FilePath>& file_paths) {
|
|
|
|
+ if (file_paths.size() == 1) {
|
|
|
|
+ *last_save_dir.Pointer() = file_paths[0].DirName();
|
|
|
|
+ StartNetLog(file_paths[0]);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#endif // BUILDFLAG(ENABLE_CEF)
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|