Browse Source

chore: force source code and markdown files to use LF line ending (#25174)

* chore: force source code and markdown files to use LF line ending

* chore: replace CRLF with LF

Co-authored-by: Cheng Zhao <[email protected]>
trop[bot] 4 years ago
parent
commit
12f0352abc

+ 10 - 0
.gitattributes

@@ -2,3 +2,13 @@
 # files to be checked out with LF endings even if core.autocrlf is true.
 *.patch text eol=lf
 patches/**/.patches merge=union
+
+# Source code and markdown files should always use LF as line ending.
+*.cc text eol=lf
+*.mm text eol=lf
+*.h text eol=lf
+*.js text eol=lf
+*.ts text eol=lf
+*.py text eol=lf
+*.ps1 text eol=lf
+*.md text eol=lf

+ 360 - 360
docs/fiddles/menus/customize-menus/main.js

@@ -1,360 +1,360 @@
-// Modules to control application life and create native browser window
-const {
-  BrowserWindow,
-  Menu,
-  MenuItem,
-  ipcMain,
-  app,
-  shell,
-  dialog
-} = require('electron')
-
-const menu = new Menu()
-menu.append(new MenuItem({ label: 'Hello' }))
-menu.append(new MenuItem({ type: 'separator' }))
-menu.append(
-  new MenuItem({ label: 'Electron', type: 'checkbox', checked: true })
-)
-
-const template = [
-  {
-    label: 'Edit',
-    submenu: [
-      {
-        label: 'Undo',
-        accelerator: 'CmdOrCtrl+Z',
-        role: 'undo'
-      },
-      {
-        label: 'Redo',
-        accelerator: 'Shift+CmdOrCtrl+Z',
-        role: 'redo'
-      },
-      {
-        type: 'separator'
-      },
-      {
-        label: 'Cut',
-        accelerator: 'CmdOrCtrl+X',
-        role: 'cut'
-      },
-      {
-        label: 'Copy',
-        accelerator: 'CmdOrCtrl+C',
-        role: 'copy'
-      },
-      {
-        label: 'Paste',
-        accelerator: 'CmdOrCtrl+V',
-        role: 'paste'
-      },
-      {
-        label: 'Select All',
-        accelerator: 'CmdOrCtrl+A',
-        role: 'selectall'
-      }
-    ]
-  },
-  {
-    label: 'View',
-    submenu: [
-      {
-        label: 'Reload',
-        accelerator: 'CmdOrCtrl+R',
-        click: (item, focusedWindow) => {
-          if (focusedWindow) {
-            // on reload, start fresh and close any old
-            // open secondary windows
-            if (focusedWindow.id === 1) {
-              BrowserWindow.getAllWindows().forEach(win => {
-                if (win.id > 1) win.close()
-              })
-            }
-            focusedWindow.reload()
-          }
-        }
-      },
-      {
-        label: 'Toggle Full Screen',
-        accelerator: (() => {
-          if (process.platform === 'darwin') {
-            return 'Ctrl+Command+F'
-          } else {
-            return 'F11'
-          }
-        })(),
-        click: (item, focusedWindow) => {
-          if (focusedWindow) {
-            focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
-          }
-        }
-      },
-      {
-        label: 'Toggle Developer Tools',
-        accelerator: (() => {
-          if (process.platform === 'darwin') {
-            return 'Alt+Command+I'
-          } else {
-            return 'Ctrl+Shift+I'
-          }
-        })(),
-        click: (item, focusedWindow) => {
-          if (focusedWindow) {
-            focusedWindow.toggleDevTools()
-          }
-        }
-      },
-      {
-        type: 'separator'
-      },
-      {
-        label: 'App Menu Demo',
-        click: function (item, focusedWindow) {
-          if (focusedWindow) {
-            const options = {
-              type: 'info',
-              title: 'Application Menu Demo',
-              buttons: ['Ok'],
-              message:
-                'This demo is for the Menu section, showing how to create a clickable menu item in the application menu.'
-            }
-            dialog.showMessageBox(focusedWindow, options, function () {})
-          }
-        }
-      }
-    ]
-  },
-  {
-    label: 'Window',
-    role: 'window',
-    submenu: [
-      {
-        label: 'Minimize',
-        accelerator: 'CmdOrCtrl+M',
-        role: 'minimize'
-      },
-      {
-        label: 'Close',
-        accelerator: 'CmdOrCtrl+W',
-        role: 'close'
-      },
-      {
-        type: 'separator'
-      },
-      {
-        label: 'Reopen Window',
-        accelerator: 'CmdOrCtrl+Shift+T',
-        enabled: false,
-        key: 'reopenMenuItem',
-        click: () => {
-          app.emit('activate')
-        }
-      }
-    ]
-  },
-  {
-    label: 'Help',
-    role: 'help',
-    submenu: [
-      {
-        label: 'Learn More',
-        click: () => {
-          shell.openExternal('http://electron.atom.io')
-        }
-      }
-    ]
-  }
-]
-
-function addUpdateMenuItems (items, position) {
-  if (process.mas) return
-
-  const version = app.getVersion()
-  const updateItems = [
-    {
-      label: `Version ${version}`,
-      enabled: false
-    },
-    {
-      label: 'Checking for Update',
-      enabled: false,
-      key: 'checkingForUpdate'
-    },
-    {
-      label: 'Check for Update',
-      visible: false,
-      key: 'checkForUpdate',
-      click: () => {
-        require('electron').autoUpdater.checkForUpdates()
-      }
-    },
-    {
-      label: 'Restart and Install Update',
-      enabled: true,
-      visible: false,
-      key: 'restartToUpdate',
-      click: () => {
-        require('electron').autoUpdater.quitAndInstall()
-      }
-    }
-  ]
-
-  items.splice.apply(items, [position, 0].concat(updateItems))
-}
-
-function findReopenMenuItem () {
-  const menu = Menu.getApplicationMenu()
-  if (!menu) return
-
-  let reopenMenuItem
-  menu.items.forEach(item => {
-    if (item.submenu) {
-      item.submenu.items.forEach(item => {
-        if (item.key === 'reopenMenuItem') {
-          reopenMenuItem = item
-        }
-      })
-    }
-  })
-  return reopenMenuItem
-}
-
-if (process.platform === 'darwin') {
-  const name = app.getName()
-  template.unshift({
-    label: name,
-    submenu: [
-      {
-        label: `About ${name}`,
-        role: 'about'
-      },
-      {
-        type: 'separator'
-      },
-      {
-        label: 'Services',
-        role: 'services',
-        submenu: []
-      },
-      {
-        type: 'separator'
-      },
-      {
-        label: `Hide ${name}`,
-        accelerator: 'Command+H',
-        role: 'hide'
-      },
-      {
-        label: 'Hide Others',
-        accelerator: 'Command+Alt+H',
-        role: 'hideothers'
-      },
-      {
-        label: 'Show All',
-        role: 'unhide'
-      },
-      {
-        type: 'separator'
-      },
-      {
-        label: 'Quit',
-        accelerator: 'Command+Q',
-        click: () => {
-          app.quit()
-        }
-      }
-    ]
-  })
-
-  // Window menu.
-  template[3].submenu.push(
-    {
-      type: 'separator'
-    },
-    {
-      label: 'Bring All to Front',
-      role: 'front'
-    }
-  )
-
-  addUpdateMenuItems(template[0].submenu, 1)
-}
-
-if (process.platform === 'win32') {
-  const helpMenu = template[template.length - 1].submenu
-  addUpdateMenuItems(helpMenu, 0)
-}
-// Keep a global reference of the window object, if you don't, the window will
-// be closed automatically when the JavaScript object is garbage collected.
-let mainWindow
-
-function createWindow () {
-  // Create the browser window.
-  mainWindow = new BrowserWindow({
-    width: 800,
-    height: 600,
-    webPreferences: {
-      nodeIntegration: true
-    }
-  })
-
-  // and load the index.html of the app.
-  mainWindow.loadFile('index.html')
-
-  // Open the DevTools.
-  // mainWindow.webContents.openDevTools()
-
-  // Emitted when the window is closed.
-  mainWindow.on('closed', function () {
-    // Dereference the window object, usually you would store windows
-    // in an array if your app supports multi windows, this is the time
-    // when you should delete the corresponding element.
-    mainWindow = null
-  })
-}
-
-// This method will be called when Electron has finished
-// initialization and is ready to create browser windows.
-// Some APIs can only be used after this event occurs.
-app.on('ready', () => {
-  createWindow()
-  const menu = Menu.buildFromTemplate(template)
-  Menu.setApplicationMenu(menu)
-})
-
-// Quit when all windows are closed.
-app.on('window-all-closed', function () {
-  // On OS X it is common for applications and their menu bar
-  // to stay active until the user quits explicitly with Cmd + Q
-  const reopenMenuItem = findReopenMenuItem()
-  if (reopenMenuItem) reopenMenuItem.enabled = true
-
-  if (process.platform !== 'darwin') {
-    app.quit()
-  }
-})
-
-app.on('activate', function () {
-  // On OS X it's common to re-create a window in the app when the
-  // dock icon is clicked and there are no other windows open.
-  if (mainWindow === null) {
-    createWindow()
-  }
-})
-
-app.on('browser-window-created', (event, win) => {
-  const reopenMenuItem = findReopenMenuItem()
-  if (reopenMenuItem) reopenMenuItem.enabled = false
-
-  win.webContents.on('context-menu', (e, params) => {
-    menu.popup(win, params.x, params.y)
-  })
-})
-
-ipcMain.on('show-context-menu', event => {
-  const win = BrowserWindow.fromWebContents(event.sender)
-  menu.popup(win)
-})
-
-// In this file you can include the rest of your app's specific main process
-// code. You can also put them in separate files and require them here.
+// Modules to control application life and create native browser window
+const {
+  BrowserWindow,
+  Menu,
+  MenuItem,
+  ipcMain,
+  app,
+  shell,
+  dialog
+} = require('electron')
+
+const menu = new Menu()
+menu.append(new MenuItem({ label: 'Hello' }))
+menu.append(new MenuItem({ type: 'separator' }))
+menu.append(
+  new MenuItem({ label: 'Electron', type: 'checkbox', checked: true })
+)
+
+const template = [
+  {
+    label: 'Edit',
+    submenu: [
+      {
+        label: 'Undo',
+        accelerator: 'CmdOrCtrl+Z',
+        role: 'undo'
+      },
+      {
+        label: 'Redo',
+        accelerator: 'Shift+CmdOrCtrl+Z',
+        role: 'redo'
+      },
+      {
+        type: 'separator'
+      },
+      {
+        label: 'Cut',
+        accelerator: 'CmdOrCtrl+X',
+        role: 'cut'
+      },
+      {
+        label: 'Copy',
+        accelerator: 'CmdOrCtrl+C',
+        role: 'copy'
+      },
+      {
+        label: 'Paste',
+        accelerator: 'CmdOrCtrl+V',
+        role: 'paste'
+      },
+      {
+        label: 'Select All',
+        accelerator: 'CmdOrCtrl+A',
+        role: 'selectall'
+      }
+    ]
+  },
+  {
+    label: 'View',
+    submenu: [
+      {
+        label: 'Reload',
+        accelerator: 'CmdOrCtrl+R',
+        click: (item, focusedWindow) => {
+          if (focusedWindow) {
+            // on reload, start fresh and close any old
+            // open secondary windows
+            if (focusedWindow.id === 1) {
+              BrowserWindow.getAllWindows().forEach(win => {
+                if (win.id > 1) win.close()
+              })
+            }
+            focusedWindow.reload()
+          }
+        }
+      },
+      {
+        label: 'Toggle Full Screen',
+        accelerator: (() => {
+          if (process.platform === 'darwin') {
+            return 'Ctrl+Command+F'
+          } else {
+            return 'F11'
+          }
+        })(),
+        click: (item, focusedWindow) => {
+          if (focusedWindow) {
+            focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
+          }
+        }
+      },
+      {
+        label: 'Toggle Developer Tools',
+        accelerator: (() => {
+          if (process.platform === 'darwin') {
+            return 'Alt+Command+I'
+          } else {
+            return 'Ctrl+Shift+I'
+          }
+        })(),
+        click: (item, focusedWindow) => {
+          if (focusedWindow) {
+            focusedWindow.toggleDevTools()
+          }
+        }
+      },
+      {
+        type: 'separator'
+      },
+      {
+        label: 'App Menu Demo',
+        click: function (item, focusedWindow) {
+          if (focusedWindow) {
+            const options = {
+              type: 'info',
+              title: 'Application Menu Demo',
+              buttons: ['Ok'],
+              message:
+                'This demo is for the Menu section, showing how to create a clickable menu item in the application menu.'
+            }
+            dialog.showMessageBox(focusedWindow, options, function () {})
+          }
+        }
+      }
+    ]
+  },
+  {
+    label: 'Window',
+    role: 'window',
+    submenu: [
+      {
+        label: 'Minimize',
+        accelerator: 'CmdOrCtrl+M',
+        role: 'minimize'
+      },
+      {
+        label: 'Close',
+        accelerator: 'CmdOrCtrl+W',
+        role: 'close'
+      },
+      {
+        type: 'separator'
+      },
+      {
+        label: 'Reopen Window',
+        accelerator: 'CmdOrCtrl+Shift+T',
+        enabled: false,
+        key: 'reopenMenuItem',
+        click: () => {
+          app.emit('activate')
+        }
+      }
+    ]
+  },
+  {
+    label: 'Help',
+    role: 'help',
+    submenu: [
+      {
+        label: 'Learn More',
+        click: () => {
+          shell.openExternal('http://electron.atom.io')
+        }
+      }
+    ]
+  }
+]
+
+function addUpdateMenuItems (items, position) {
+  if (process.mas) return
+
+  const version = app.getVersion()
+  const updateItems = [
+    {
+      label: `Version ${version}`,
+      enabled: false
+    },
+    {
+      label: 'Checking for Update',
+      enabled: false,
+      key: 'checkingForUpdate'
+    },
+    {
+      label: 'Check for Update',
+      visible: false,
+      key: 'checkForUpdate',
+      click: () => {
+        require('electron').autoUpdater.checkForUpdates()
+      }
+    },
+    {
+      label: 'Restart and Install Update',
+      enabled: true,
+      visible: false,
+      key: 'restartToUpdate',
+      click: () => {
+        require('electron').autoUpdater.quitAndInstall()
+      }
+    }
+  ]
+
+  items.splice.apply(items, [position, 0].concat(updateItems))
+}
+
+function findReopenMenuItem () {
+  const menu = Menu.getApplicationMenu()
+  if (!menu) return
+
+  let reopenMenuItem
+  menu.items.forEach(item => {
+    if (item.submenu) {
+      item.submenu.items.forEach(item => {
+        if (item.key === 'reopenMenuItem') {
+          reopenMenuItem = item
+        }
+      })
+    }
+  })
+  return reopenMenuItem
+}
+
+if (process.platform === 'darwin') {
+  const name = app.getName()
+  template.unshift({
+    label: name,
+    submenu: [
+      {
+        label: `About ${name}`,
+        role: 'about'
+      },
+      {
+        type: 'separator'
+      },
+      {
+        label: 'Services',
+        role: 'services',
+        submenu: []
+      },
+      {
+        type: 'separator'
+      },
+      {
+        label: `Hide ${name}`,
+        accelerator: 'Command+H',
+        role: 'hide'
+      },
+      {
+        label: 'Hide Others',
+        accelerator: 'Command+Alt+H',
+        role: 'hideothers'
+      },
+      {
+        label: 'Show All',
+        role: 'unhide'
+      },
+      {
+        type: 'separator'
+      },
+      {
+        label: 'Quit',
+        accelerator: 'Command+Q',
+        click: () => {
+          app.quit()
+        }
+      }
+    ]
+  })
+
+  // Window menu.
+  template[3].submenu.push(
+    {
+      type: 'separator'
+    },
+    {
+      label: 'Bring All to Front',
+      role: 'front'
+    }
+  )
+
+  addUpdateMenuItems(template[0].submenu, 1)
+}
+
+if (process.platform === 'win32') {
+  const helpMenu = template[template.length - 1].submenu
+  addUpdateMenuItems(helpMenu, 0)
+}
+// Keep a global reference of the window object, if you don't, the window will
+// be closed automatically when the JavaScript object is garbage collected.
+let mainWindow
+
+function createWindow () {
+  // Create the browser window.
+  mainWindow = new BrowserWindow({
+    width: 800,
+    height: 600,
+    webPreferences: {
+      nodeIntegration: true
+    }
+  })
+
+  // and load the index.html of the app.
+  mainWindow.loadFile('index.html')
+
+  // Open the DevTools.
+  // mainWindow.webContents.openDevTools()
+
+  // Emitted when the window is closed.
+  mainWindow.on('closed', function () {
+    // Dereference the window object, usually you would store windows
+    // in an array if your app supports multi windows, this is the time
+    // when you should delete the corresponding element.
+    mainWindow = null
+  })
+}
+
+// This method will be called when Electron has finished
+// initialization and is ready to create browser windows.
+// Some APIs can only be used after this event occurs.
+app.on('ready', () => {
+  createWindow()
+  const menu = Menu.buildFromTemplate(template)
+  Menu.setApplicationMenu(menu)
+})
+
+// Quit when all windows are closed.
+app.on('window-all-closed', function () {
+  // On OS X it is common for applications and their menu bar
+  // to stay active until the user quits explicitly with Cmd + Q
+  const reopenMenuItem = findReopenMenuItem()
+  if (reopenMenuItem) reopenMenuItem.enabled = true
+
+  if (process.platform !== 'darwin') {
+    app.quit()
+  }
+})
+
+app.on('activate', function () {
+  // On OS X it's common to re-create a window in the app when the
+  // dock icon is clicked and there are no other windows open.
+  if (mainWindow === null) {
+    createWindow()
+  }
+})
+
+app.on('browser-window-created', (event, win) => {
+  const reopenMenuItem = findReopenMenuItem()
+  if (reopenMenuItem) reopenMenuItem.enabled = false
+
+  win.webContents.on('context-menu', (e, params) => {
+    menu.popup(win, params.x, params.y)
+  })
+})
+
+ipcMain.on('show-context-menu', event => {
+  const win = BrowserWindow.fromWebContents(event.sender)
+  menu.popup(win)
+})
+
+// In this file you can include the rest of your app's specific main process
+// code. You can also put them in separate files and require them here.

+ 8 - 8
docs/fiddles/menus/customize-menus/renderer.js

@@ -1,8 +1,8 @@
-const { ipcRenderer } = require('electron')
-
-// Tell main process to show the menu when demo button is clicked
-const contextMenuBtn = document.getElementById('context-menu')
-
-contextMenuBtn.addEventListener('click', () => {
-  ipcRenderer.send('show-context-menu')
-})
+const { ipcRenderer } = require('electron')
+
+// Tell main process to show the menu when demo button is clicked
+const contextMenuBtn = document.getElementById('context-menu')
+
+contextMenuBtn.addEventListener('click', () => {
+  ipcRenderer.send('show-context-menu')
+})

File diff suppressed because it is too large
+ 0 - 54
docs/fiddles/native-ui/drag-and-drop/main.js


+ 21 - 21
docs/fiddles/native-ui/drag-and-drop/renderer.js

@@ -1,21 +1,21 @@
-const { ipcRenderer } = require('electron')
-const shell = require('electron').shell
-
-const links = document.querySelectorAll('a[href]')
-
-Array.prototype.forEach.call(links, (link) => {
-  const url = link.getAttribute('href')
-  if (url.indexOf('http') === 0) {
-    link.addEventListener('click', (e) => {
-      e.preventDefault()
-      shell.openExternal(url)
-    })
-  }
-})
-
-const dragFileLink = document.getElementById('drag-file-link')
-
-dragFileLink.addEventListener('dragstart', event => {
-  event.preventDefault()
-  ipcRenderer.send('ondragstart', __filename)
-})
+const { ipcRenderer } = require('electron')
+const shell = require('electron').shell
+
+const links = document.querySelectorAll('a[href]')
+
+Array.prototype.forEach.call(links, (link) => {
+  const url = link.getAttribute('href')
+  if (url.indexOf('http') === 0) {
+    link.addEventListener('click', (e) => {
+      e.preventDefault()
+      shell.openExternal(url)
+    })
+  }
+})
+
+const dragFileLink = document.getElementById('drag-file-link')
+
+dragFileLink.addEventListener('dragstart', event => {
+  event.preventDefault()
+  ipcRenderer.send('ondragstart', __filename)
+})

+ 10 - 10
script/start-goma.ps1

@@ -1,10 +1,10 @@
-param([string]$gomaDir=$PWD)
-$cmdPath = Join-Path -Path $gomaDir -ChildPath "goma_ctl.py" 
-Start-Process -FilePath cmd -ArgumentList "/C", "python", "$cmdPath", "ensure_start"
-$timedOut = $false; $waitTime = 0; $waitIncrement = 5; $timeout=120;
-Do { sleep $waitIncrement; $timedOut = (($waitTime+=$waitIncrement) -gt $timeout); iex "$gomaDir\gomacc.exe port 2" > $null; } Until(($LASTEXITCODE -eq 0) -or $timedOut) 
-if ($timedOut) { 
-    write-error 'Timed out waiting for goma to start'; exit 1; 
-} else {
-    Write-Output "Successfully started goma!"
-}
+param([string]$gomaDir=$PWD)
+$cmdPath = Join-Path -Path $gomaDir -ChildPath "goma_ctl.py" 
+Start-Process -FilePath cmd -ArgumentList "/C", "python", "$cmdPath", "ensure_start"
+$timedOut = $false; $waitTime = 0; $waitIncrement = 5; $timeout=120;
+Do { sleep $waitIncrement; $timedOut = (($waitTime+=$waitIncrement) -gt $timeout); iex "$gomaDir\gomacc.exe port 2" > $null; } Until(($LASTEXITCODE -eq 0) -or $timedOut) 
+if ($timedOut) { 
+    write-error 'Timed out waiting for goma to start'; exit 1; 
+} else {
+    Write-Output "Successfully started goma!"
+}

+ 65 - 65
shell/browser/electron_autofill_driver.cc

@@ -1,65 +1,65 @@
-// Copyright (c) 2019 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include "shell/browser/electron_autofill_driver.h"
-
-#include <memory>
-
-#include <utility>
-
-#include "content/public/browser/render_widget_host_view.h"
-#include "shell/browser/api/electron_api_web_contents.h"
-#include "shell/browser/native_window.h"
-
-namespace electron {
-
-AutofillDriver::AutofillDriver(
-    content::RenderFrameHost* render_frame_host,
-    mojom::ElectronAutofillDriverAssociatedRequest request)
-    : render_frame_host_(render_frame_host), binding_(this) {
-  autofill_popup_ = std::make_unique<AutofillPopup>();
-  binding_.Bind(std::move(request));
-}
-
-AutofillDriver::~AutofillDriver() = default;
-
-void AutofillDriver::ShowAutofillPopup(
-    const gfx::RectF& bounds,
-    const std::vector<base::string16>& values,
-    const std::vector<base::string16>& labels) {
-  auto* web_contents =
-      api::WebContents::From(
-          v8::Isolate::GetCurrent(),
-          content::WebContents::FromRenderFrameHost(render_frame_host_))
-          .get();
-  if (!web_contents || !web_contents->owner_window())
-    return;
-
-  auto* embedder = web_contents->embedder();
-
-  bool osr =
-      web_contents->IsOffScreen() || (embedder && embedder->IsOffScreen());
-  gfx::RectF popup_bounds(bounds);
-  content::RenderFrameHost* embedder_frame_host = nullptr;
-  if (embedder) {
-    auto* embedder_view = embedder->web_contents()->GetMainFrame()->GetView();
-    auto* view = web_contents->web_contents()->GetMainFrame()->GetView();
-    auto offset = view->GetViewBounds().origin() -
-                  embedder_view->GetViewBounds().origin();
-    popup_bounds.Offset(offset);
-    embedder_frame_host = embedder->web_contents()->GetMainFrame();
-  }
-
-  autofill_popup_->CreateView(render_frame_host_, embedder_frame_host, osr,
-                              web_contents->owner_window()->content_view(),
-                              popup_bounds);
-  autofill_popup_->SetItems(values, labels);
-}
-
-void AutofillDriver::HideAutofillPopup() {
-  if (autofill_popup_)
-    autofill_popup_->Hide();
-}
-
-}  // namespace electron
+// Copyright (c) 2019 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "shell/browser/electron_autofill_driver.h"
+
+#include <memory>
+
+#include <utility>
+
+#include "content/public/browser/render_widget_host_view.h"
+#include "shell/browser/api/electron_api_web_contents.h"
+#include "shell/browser/native_window.h"
+
+namespace electron {
+
+AutofillDriver::AutofillDriver(
+    content::RenderFrameHost* render_frame_host,
+    mojom::ElectronAutofillDriverAssociatedRequest request)
+    : render_frame_host_(render_frame_host), binding_(this) {
+  autofill_popup_ = std::make_unique<AutofillPopup>();
+  binding_.Bind(std::move(request));
+}
+
+AutofillDriver::~AutofillDriver() = default;
+
+void AutofillDriver::ShowAutofillPopup(
+    const gfx::RectF& bounds,
+    const std::vector<base::string16>& values,
+    const std::vector<base::string16>& labels) {
+  auto* web_contents =
+      api::WebContents::From(
+          v8::Isolate::GetCurrent(),
+          content::WebContents::FromRenderFrameHost(render_frame_host_))
+          .get();
+  if (!web_contents || !web_contents->owner_window())
+    return;
+
+  auto* embedder = web_contents->embedder();
+
+  bool osr =
+      web_contents->IsOffScreen() || (embedder && embedder->IsOffScreen());
+  gfx::RectF popup_bounds(bounds);
+  content::RenderFrameHost* embedder_frame_host = nullptr;
+  if (embedder) {
+    auto* embedder_view = embedder->web_contents()->GetMainFrame()->GetView();
+    auto* view = web_contents->web_contents()->GetMainFrame()->GetView();
+    auto offset = view->GetViewBounds().origin() -
+                  embedder_view->GetViewBounds().origin();
+    popup_bounds.Offset(offset);
+    embedder_frame_host = embedder->web_contents()->GetMainFrame();
+  }
+
+  autofill_popup_->CreateView(render_frame_host_, embedder_frame_host, osr,
+                              web_contents->owner_window()->content_view(),
+                              popup_bounds);
+  autofill_popup_->SetItems(values, labels);
+}
+
+void AutofillDriver::HideAutofillPopup() {
+  if (autofill_popup_)
+    autofill_popup_->Hide();
+}
+
+}  // namespace electron

+ 44 - 44
shell/browser/electron_autofill_driver.h

@@ -1,44 +1,44 @@
-// Copyright (c) 2019 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_H_
-#define SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_H_
-
-#include <memory>
-#include <vector>
-
-#if defined(TOOLKIT_VIEWS)
-#include "shell/browser/ui/autofill_popup.h"
-#endif
-
-#include "mojo/public/cpp/bindings/associated_binding.h"
-#include "shell/common/api/api.mojom.h"
-
-namespace electron {
-
-class AutofillDriver : public mojom::ElectronAutofillDriver {
- public:
-  AutofillDriver(content::RenderFrameHost* render_frame_host,
-                 mojom::ElectronAutofillDriverAssociatedRequest request);
-
-  ~AutofillDriver() override;
-
-  void ShowAutofillPopup(const gfx::RectF& bounds,
-                         const std::vector<base::string16>& values,
-                         const std::vector<base::string16>& labels) override;
-  void HideAutofillPopup() override;
-
- private:
-  content::RenderFrameHost* const render_frame_host_;
-
-#if defined(TOOLKIT_VIEWS)
-  std::unique_ptr<AutofillPopup> autofill_popup_;
-#endif
-
-  mojo::AssociatedBinding<mojom::ElectronAutofillDriver> binding_;
-};
-
-}  // namespace electron
-
-#endif  // SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_H_
+// Copyright (c) 2019 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_H_
+#define SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_H_
+
+#include <memory>
+#include <vector>
+
+#if defined(TOOLKIT_VIEWS)
+#include "shell/browser/ui/autofill_popup.h"
+#endif
+
+#include "mojo/public/cpp/bindings/associated_binding.h"
+#include "shell/common/api/api.mojom.h"
+
+namespace electron {
+
+class AutofillDriver : public mojom::ElectronAutofillDriver {
+ public:
+  AutofillDriver(content::RenderFrameHost* render_frame_host,
+                 mojom::ElectronAutofillDriverAssociatedRequest request);
+
+  ~AutofillDriver() override;
+
+  void ShowAutofillPopup(const gfx::RectF& bounds,
+                         const std::vector<base::string16>& values,
+                         const std::vector<base::string16>& labels) override;
+  void HideAutofillPopup() override;
+
+ private:
+  content::RenderFrameHost* const render_frame_host_;
+
+#if defined(TOOLKIT_VIEWS)
+  std::unique_ptr<AutofillPopup> autofill_popup_;
+#endif
+
+  mojo::AssociatedBinding<mojom::ElectronAutofillDriver> binding_;
+};
+
+}  // namespace electron
+
+#endif  // SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_H_

+ 111 - 111
shell/browser/electron_autofill_driver_factory.cc

@@ -1,111 +1,111 @@
-// Copyright (c) 2019 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include "shell/browser/electron_autofill_driver_factory.h"
-
-#include <memory>
-#include <utility>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/callback.h"
-#include "content/public/browser/navigation_handle.h"
-#include "content/public/browser/render_frame_host.h"
-#include "content/public/browser/web_contents.h"
-#include "shell/browser/electron_autofill_driver.h"
-
-namespace electron {
-
-namespace {
-
-std::unique_ptr<AutofillDriver> CreateDriver(
-    content::RenderFrameHost* render_frame_host,
-    mojom::ElectronAutofillDriverAssociatedRequest request) {
-  return std::make_unique<AutofillDriver>(render_frame_host,
-                                          std::move(request));
-}
-
-}  // namespace
-
-AutofillDriverFactory::~AutofillDriverFactory() = default;
-
-// static
-void AutofillDriverFactory::BindAutofillDriver(
-    mojom::ElectronAutofillDriverAssociatedRequest request,
-    content::RenderFrameHost* render_frame_host) {
-  content::WebContents* web_contents =
-      content::WebContents::FromRenderFrameHost(render_frame_host);
-  if (!web_contents)
-    return;
-
-  AutofillDriverFactory* factory =
-      AutofillDriverFactory::FromWebContents(web_contents);
-  if (!factory)
-    return;
-
-  AutofillDriver* driver = factory->DriverForFrame(render_frame_host);
-  if (!driver)
-    factory->AddDriverForFrame(
-        render_frame_host,
-        base::BindOnce(CreateDriver, render_frame_host, std::move(request)));
-}
-
-AutofillDriverFactory::AutofillDriverFactory(content::WebContents* web_contents)
-    : content::WebContentsObserver(web_contents) {
-  const std::vector<content::RenderFrameHost*> frames =
-      web_contents->GetAllFrames();
-  for (content::RenderFrameHost* frame : frames) {
-    if (frame->IsRenderFrameLive())
-      RenderFrameCreated(frame);
-  }
-}
-
-void AutofillDriverFactory::RenderFrameDeleted(
-    content::RenderFrameHost* render_frame_host) {
-  DeleteDriverForFrame(render_frame_host);
-}
-
-void AutofillDriverFactory::DidFinishNavigation(
-    content::NavigationHandle* navigation_handle) {
-  // For the purposes of this code, a navigation is not important if it has not
-  // committed yet or if it's in a subframe.
-  if (!navigation_handle->HasCommitted() ||
-      !navigation_handle->IsInMainFrame()) {
-    return;
-  }
-
-  CloseAllPopups();
-}
-
-AutofillDriver* AutofillDriverFactory::DriverForFrame(
-    content::RenderFrameHost* render_frame_host) {
-  auto mapping = driver_map_.find(render_frame_host);
-  return mapping == driver_map_.end() ? nullptr : mapping->second.get();
-}
-
-void AutofillDriverFactory::AddDriverForFrame(
-    content::RenderFrameHost* render_frame_host,
-    CreationCallback factory_method) {
-  auto insertion_result =
-      driver_map_.insert(std::make_pair(render_frame_host, nullptr));
-  // This can be called twice for the key representing the main frame.
-  if (insertion_result.second) {
-    insertion_result.first->second = std::move(factory_method).Run();
-  }
-}
-
-void AutofillDriverFactory::DeleteDriverForFrame(
-    content::RenderFrameHost* render_frame_host) {
-  driver_map_.erase(render_frame_host);
-}
-
-void AutofillDriverFactory::CloseAllPopups() {
-  for (auto& it : driver_map_) {
-    it.second->HideAutofillPopup();
-  }
-}
-
-WEB_CONTENTS_USER_DATA_KEY_IMPL(AutofillDriverFactory)
-
-}  // namespace electron
+// Copyright (c) 2019 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "shell/browser/electron_autofill_driver_factory.h"
+
+#include <memory>
+#include <utility>
+#include <vector>
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/web_contents.h"
+#include "shell/browser/electron_autofill_driver.h"
+
+namespace electron {
+
+namespace {
+
+std::unique_ptr<AutofillDriver> CreateDriver(
+    content::RenderFrameHost* render_frame_host,
+    mojom::ElectronAutofillDriverAssociatedRequest request) {
+  return std::make_unique<AutofillDriver>(render_frame_host,
+                                          std::move(request));
+}
+
+}  // namespace
+
+AutofillDriverFactory::~AutofillDriverFactory() = default;
+
+// static
+void AutofillDriverFactory::BindAutofillDriver(
+    mojom::ElectronAutofillDriverAssociatedRequest request,
+    content::RenderFrameHost* render_frame_host) {
+  content::WebContents* web_contents =
+      content::WebContents::FromRenderFrameHost(render_frame_host);
+  if (!web_contents)
+    return;
+
+  AutofillDriverFactory* factory =
+      AutofillDriverFactory::FromWebContents(web_contents);
+  if (!factory)
+    return;
+
+  AutofillDriver* driver = factory->DriverForFrame(render_frame_host);
+  if (!driver)
+    factory->AddDriverForFrame(
+        render_frame_host,
+        base::BindOnce(CreateDriver, render_frame_host, std::move(request)));
+}
+
+AutofillDriverFactory::AutofillDriverFactory(content::WebContents* web_contents)
+    : content::WebContentsObserver(web_contents) {
+  const std::vector<content::RenderFrameHost*> frames =
+      web_contents->GetAllFrames();
+  for (content::RenderFrameHost* frame : frames) {
+    if (frame->IsRenderFrameLive())
+      RenderFrameCreated(frame);
+  }
+}
+
+void AutofillDriverFactory::RenderFrameDeleted(
+    content::RenderFrameHost* render_frame_host) {
+  DeleteDriverForFrame(render_frame_host);
+}
+
+void AutofillDriverFactory::DidFinishNavigation(
+    content::NavigationHandle* navigation_handle) {
+  // For the purposes of this code, a navigation is not important if it has not
+  // committed yet or if it's in a subframe.
+  if (!navigation_handle->HasCommitted() ||
+      !navigation_handle->IsInMainFrame()) {
+    return;
+  }
+
+  CloseAllPopups();
+}
+
+AutofillDriver* AutofillDriverFactory::DriverForFrame(
+    content::RenderFrameHost* render_frame_host) {
+  auto mapping = driver_map_.find(render_frame_host);
+  return mapping == driver_map_.end() ? nullptr : mapping->second.get();
+}
+
+void AutofillDriverFactory::AddDriverForFrame(
+    content::RenderFrameHost* render_frame_host,
+    CreationCallback factory_method) {
+  auto insertion_result =
+      driver_map_.insert(std::make_pair(render_frame_host, nullptr));
+  // This can be called twice for the key representing the main frame.
+  if (insertion_result.second) {
+    insertion_result.first->second = std::move(factory_method).Run();
+  }
+}
+
+void AutofillDriverFactory::DeleteDriverForFrame(
+    content::RenderFrameHost* render_frame_host) {
+  driver_map_.erase(render_frame_host);
+}
+
+void AutofillDriverFactory::CloseAllPopups() {
+  for (auto& it : driver_map_) {
+    it.second->HideAutofillPopup();
+  }
+}
+
+WEB_CONTENTS_USER_DATA_KEY_IMPL(AutofillDriverFactory)
+
+}  // namespace electron

+ 57 - 57
shell/browser/electron_autofill_driver_factory.h

@@ -1,57 +1,57 @@
-// Copyright (c) 2019 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
-#define SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
-
-#include <memory>
-#include <unordered_map>
-
-#include "base/callback_forward.h"
-#include "content/public/browser/web_contents_observer.h"
-#include "content/public/browser/web_contents_user_data.h"
-#include "shell/common/api/api.mojom.h"
-
-namespace electron {
-
-class AutofillDriver;
-
-class AutofillDriverFactory
-    : public content::WebContentsObserver,
-      public content::WebContentsUserData<AutofillDriverFactory> {
- public:
-  typedef base::OnceCallback<std::unique_ptr<AutofillDriver>()>
-      CreationCallback;
-
-  ~AutofillDriverFactory() override;
-
-  static void BindAutofillDriver(
-      mojom::ElectronAutofillDriverAssociatedRequest request,
-      content::RenderFrameHost* render_frame_host);
-
-  // content::WebContentsObserver:
-  void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
-  void DidFinishNavigation(
-      content::NavigationHandle* navigation_handle) override;
-
-  AutofillDriver* DriverForFrame(content::RenderFrameHost* render_frame_host);
-  void AddDriverForFrame(content::RenderFrameHost* render_frame_host,
-                         CreationCallback factory_method);
-  void DeleteDriverForFrame(content::RenderFrameHost* render_frame_host);
-
-  void CloseAllPopups();
-
-  WEB_CONTENTS_USER_DATA_KEY_DECL();
-
- private:
-  explicit AutofillDriverFactory(content::WebContents* web_contents);
-  friend class content::WebContentsUserData<AutofillDriverFactory>;
-
-  std::unordered_map<content::RenderFrameHost*, std::unique_ptr<AutofillDriver>>
-      driver_map_;
-};
-
-}  // namespace electron
-
-#endif  // SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
+// Copyright (c) 2019 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
+#define SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
+
+#include <memory>
+#include <unordered_map>
+
+#include "base/callback_forward.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+#include "shell/common/api/api.mojom.h"
+
+namespace electron {
+
+class AutofillDriver;
+
+class AutofillDriverFactory
+    : public content::WebContentsObserver,
+      public content::WebContentsUserData<AutofillDriverFactory> {
+ public:
+  typedef base::OnceCallback<std::unique_ptr<AutofillDriver>()>
+      CreationCallback;
+
+  ~AutofillDriverFactory() override;
+
+  static void BindAutofillDriver(
+      mojom::ElectronAutofillDriverAssociatedRequest request,
+      content::RenderFrameHost* render_frame_host);
+
+  // content::WebContentsObserver:
+  void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
+  void DidFinishNavigation(
+      content::NavigationHandle* navigation_handle) override;
+
+  AutofillDriver* DriverForFrame(content::RenderFrameHost* render_frame_host);
+  void AddDriverForFrame(content::RenderFrameHost* render_frame_host,
+                         CreationCallback factory_method);
+  void DeleteDriverForFrame(content::RenderFrameHost* render_frame_host);
+
+  void CloseAllPopups();
+
+  WEB_CONTENTS_USER_DATA_KEY_DECL();
+
+ private:
+  explicit AutofillDriverFactory(content::WebContents* web_contents);
+  friend class content::WebContentsUserData<AutofillDriverFactory>;
+
+  std::unordered_map<content::RenderFrameHost*, std::unique_ptr<AutofillDriver>>
+      driver_map_;
+};
+
+}  // namespace electron
+
+#endif  // SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_

Some files were not shown because too many files changed in this diff