Browse Source

refactor: eliminate duplicate code (#40088)

Milan Burda 1 year ago
parent
commit
6a99c7b840
2 changed files with 14 additions and 19 deletions
  1. 1 8
      shell/browser/file_select_helper.cc
  2. 13 11
      shell/browser/native_window_mac.mm

+ 1 - 8
shell/browser/file_select_helper.cc

@@ -101,14 +101,7 @@ void FileSelectHelper::FileSelectedWithExtraInfo(
   std::vector<ui::SelectedFileInfo> files;
   files.push_back(file);
 
-#if BUILDFLAG(IS_MAC)
-  base::ThreadPool::PostTask(
-      FROM_HERE,
-      {base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
-      base::BindOnce(&FileSelectHelper::ProcessSelectedFilesMac, this, files));
-#else
-  ConvertToFileChooserFileInfoList(files);
-#endif  // BUILDFLAG(IS_MAC)
+  MultiFilesSelectedWithExtraInfo(files, params);
 }
 
 void FileSelectHelper::MultiFilesSelected(

+ 13 - 11
shell/browser/native_window_mac.mm

@@ -202,6 +202,14 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) {
   }
 }
 
+NSView* GetNativeNSView(NativeBrowserView* view) {
+  if (auto* inspectable = view->GetInspectableWebContentsView()) {
+    return inspectable->GetNativeView().GetNativeNSView();
+  } else {
+    return nullptr;
+  }
+}
+
 }  // namespace
 
 NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
@@ -1256,10 +1264,7 @@ void NativeWindowMac::AddBrowserView(NativeBrowserView* view) {
   }
 
   add_browser_view(view);
-  if (view->GetInspectableWebContentsView()) {
-    auto* native_view = view->GetInspectableWebContentsView()
-                            ->GetNativeView()
-                            .GetNativeNSView();
+  if (auto* native_view = GetNativeNSView(view)) {
     [[window_ contentView] addSubview:native_view
                            positioned:NSWindowAbove
                            relativeTo:nil];
@@ -1278,9 +1283,9 @@ void NativeWindowMac::RemoveBrowserView(NativeBrowserView* view) {
     return;
   }
 
-  if (view->GetInspectableWebContentsView())
-    [view->GetInspectableWebContentsView()->GetNativeView().GetNativeNSView()
-        removeFromSuperview];
+  if (auto* native_view = GetNativeNSView(view)) {
+    [native_view removeFromSuperview];
+  }
   remove_browser_view(view);
 
   [CATransaction commit];
@@ -1297,10 +1302,7 @@ void NativeWindowMac::SetTopBrowserView(NativeBrowserView* view) {
 
   remove_browser_view(view);
   add_browser_view(view);
-  if (view->GetInspectableWebContentsView()) {
-    auto* native_view = view->GetInspectableWebContentsView()
-                            ->GetNativeView()
-                            .GetNativeNSView();
+  if (auto* native_view = GetNativeNSView(view)) {
     [[window_ contentView] addSubview:native_view
                            positioned:NSWindowAbove
                            relativeTo:nil];