refactor: remove private webContents.getId() API (#13674)
This commit is contained in:
parent
a88cdf2d1f
commit
305e3aad40
12 changed files with 14 additions and 45 deletions
|
@ -1103,17 +1103,6 @@ void WebContents::NavigationEntryCommitted(
|
||||||
details.is_same_document, details.did_replace_entry);
|
details.is_same_document, details.did_replace_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t WebContents::GetIDForContents(content::WebContents* web_contents) {
|
|
||||||
int64_t process_id = web_contents->GetMainFrame()->GetProcess()->GetID();
|
|
||||||
int64_t routing_id = web_contents->GetMainFrame()->GetRoutingID();
|
|
||||||
int64_t rv = (process_id << 32) + routing_id;
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t WebContents::GetID() const {
|
|
||||||
return WebContents::GetIDForContents(web_contents());
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebContents::GetProcessID() const {
|
int WebContents::GetProcessID() const {
|
||||||
return web_contents()->GetMainFrame()->GetProcess()->GetID();
|
return web_contents()->GetMainFrame()->GetProcess()->GetID();
|
||||||
}
|
}
|
||||||
|
@ -1129,7 +1118,7 @@ WebContents::Type WebContents::GetType() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::Equal(const WebContents* web_contents) const {
|
bool WebContents::Equal(const WebContents* web_contents) const {
|
||||||
return GetID() == web_contents->GetID();
|
return ID() == web_contents->ID();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||||
|
@ -1992,7 +1981,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "WebContents"));
|
prototype->SetClassName(mate::StringToV8(isolate, "WebContents"));
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.MakeDestroyable()
|
.MakeDestroyable()
|
||||||
.SetMethod("getId", &WebContents::GetID)
|
|
||||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
||||||
.SetMethod("getOSProcessId", &WebContents::GetOSProcessID)
|
.SetMethod("getOSProcessId", &WebContents::GetOSProcessID)
|
||||||
.SetMethod("equal", &WebContents::Equal)
|
.SetMethod("equal", &WebContents::Equal)
|
||||||
|
|
|
@ -98,12 +98,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
static void BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
v8::Local<v8::FunctionTemplate> prototype);
|
||||||
|
|
||||||
static int64_t GetIDForContents(content::WebContents* web_contents);
|
|
||||||
|
|
||||||
// Notifies to destroy any guest web contents before destroying self.
|
// Notifies to destroy any guest web contents before destroying self.
|
||||||
void DestroyWebContents(bool async);
|
void DestroyWebContents(bool async);
|
||||||
|
|
||||||
int64_t GetID() const;
|
|
||||||
int GetProcessID() const;
|
int GetProcessID() const;
|
||||||
base::ProcessId GetOSProcessID() const;
|
base::ProcessId GetOSProcessID() const;
|
||||||
Type GetType() const;
|
Type GetType() const;
|
||||||
|
|
|
@ -344,10 +344,6 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
web_preferences->AppendCommandLineSwitches(command_line);
|
web_preferences->AppendCommandLineSwitches(command_line);
|
||||||
SessionPreferences::AppendExtraCommandLineSwitches(
|
SessionPreferences::AppendExtraCommandLineSwitches(
|
||||||
web_contents->GetBrowserContext(), command_line);
|
web_contents->GetBrowserContext(), command_line);
|
||||||
|
|
||||||
auto context_id = atom::api::WebContents::GetIDForContents(web_contents);
|
|
||||||
command_line->AppendSwitchASCII(switches::kContextId,
|
|
||||||
base::IntToString(context_id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,9 +188,6 @@ const char kAppUserModelId[] = "app-user-model-id";
|
||||||
// The application path
|
// The application path
|
||||||
const char kAppPath[] = "app-path";
|
const char kAppPath[] = "app-path";
|
||||||
|
|
||||||
// The context ID for this process
|
|
||||||
const char kContextId[] = "context-id";
|
|
||||||
|
|
||||||
// The command line switch versions of the options.
|
// The command line switch versions of the options.
|
||||||
const char kBackgroundColor[] = "background-color";
|
const char kBackgroundColor[] = "background-color";
|
||||||
const char kPreloadScript[] = "preload";
|
const char kPreloadScript[] = "preload";
|
||||||
|
|
|
@ -92,7 +92,6 @@ extern const char kRegisterServiceWorkerSchemes[];
|
||||||
extern const char kSecureSchemes[];
|
extern const char kSecureSchemes[];
|
||||||
extern const char kAppUserModelId[];
|
extern const char kAppUserModelId[];
|
||||||
extern const char kAppPath[];
|
extern const char kAppPath[];
|
||||||
extern const char kContextId[];
|
|
||||||
|
|
||||||
extern const char kBackgroundColor[];
|
extern const char kBackgroundColor[];
|
||||||
extern const char kPreloadScript[];
|
extern const char kPreloadScript[];
|
||||||
|
|
|
@ -179,7 +179,7 @@ const createGuest = function (embedder, params) {
|
||||||
const attachGuest = function (event, elementInstanceId, guestInstanceId, params) {
|
const attachGuest = function (event, elementInstanceId, guestInstanceId, params) {
|
||||||
const embedder = event.sender
|
const embedder = event.sender
|
||||||
// Destroy the old guest when attaching.
|
// Destroy the old guest when attaching.
|
||||||
const key = `${embedder.getId()}-${elementInstanceId}`
|
const key = `${embedder.id}-${elementInstanceId}`
|
||||||
const oldGuestInstanceId = embedderElementsMap[key]
|
const oldGuestInstanceId = embedderElementsMap[key]
|
||||||
if (oldGuestInstanceId != null) {
|
if (oldGuestInstanceId != null) {
|
||||||
// Reattachment to the same guest is just a no-op.
|
// Reattachment to the same guest is just a no-op.
|
||||||
|
@ -199,7 +199,7 @@ const attachGuest = function (event, elementInstanceId, guestInstanceId, params)
|
||||||
|
|
||||||
// If this guest is already attached to an element then remove it
|
// If this guest is already attached to an element then remove it
|
||||||
if (guestInstance.elementInstanceId) {
|
if (guestInstance.elementInstanceId) {
|
||||||
const oldKey = `${guestInstance.embedder.getId()}-${guestInstance.elementInstanceId}`
|
const oldKey = `${guestInstance.embedder.id}-${guestInstance.elementInstanceId}`
|
||||||
delete embedderElementsMap[oldKey]
|
delete embedderElementsMap[oldKey]
|
||||||
|
|
||||||
// Remove guest from embedder if moving across web views
|
// Remove guest from embedder if moving across web views
|
||||||
|
@ -290,7 +290,7 @@ const destroyGuest = function (embedder, guestInstanceId) {
|
||||||
guestInstance.guest.destroy()
|
guestInstance.guest.destroy()
|
||||||
delete guestInstances[guestInstanceId]
|
delete guestInstances[guestInstanceId]
|
||||||
|
|
||||||
const key = `${embedder.getId()}-${guestInstance.elementInstanceId}`
|
const key = `${embedder.id}-${guestInstance.elementInstanceId}`
|
||||||
delete embedderElementsMap[key]
|
delete embedderElementsMap[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,9 +210,9 @@ const unwrapArgs = function (sender, contextId, args) {
|
||||||
return rendererFunctions.get(objectId)
|
return rendererFunctions.get(objectId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const webContentsId = sender.getId()
|
const processId = sender.getProcessId()
|
||||||
let callIntoRenderer = function (...args) {
|
let callIntoRenderer = function (...args) {
|
||||||
if (!sender.isDestroyed() && webContentsId === sender.getId()) {
|
if (!sender.isDestroyed() && processId === sender.getProcessId()) {
|
||||||
sender.send('ELECTRON_RENDERER_CALLBACK', contextId, meta.id, valueToMeta(sender, contextId, args))
|
sender.send('ELECTRON_RENDERER_CALLBACK', contextId, meta.id, valueToMeta(sender, contextId, args))
|
||||||
} else {
|
} else {
|
||||||
removeRemoteListenersAndLogWarning(this, meta, callIntoRenderer)
|
removeRemoteListenersAndLogWarning(this, meta, callIntoRenderer)
|
||||||
|
@ -453,7 +453,6 @@ ipcMain.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event, preloadPath) {
|
||||||
event.returnValue = {
|
event.returnValue = {
|
||||||
preloadSrc: preloadSrc,
|
preloadSrc: preloadSrc,
|
||||||
preloadError: preloadError,
|
preloadError: preloadError,
|
||||||
webContentsId: event.sender.getId(),
|
|
||||||
platform: process.platform,
|
platform: process.platform,
|
||||||
execPath: process.execPath,
|
execPath: process.execPath,
|
||||||
env: process.env
|
env: process.env
|
||||||
|
|
|
@ -365,7 +365,6 @@ const registerWebViewElement = function () {
|
||||||
'replaceMisspelling',
|
'replaceMisspelling',
|
||||||
'findInPage',
|
'findInPage',
|
||||||
'stopFindInPage',
|
'stopFindInPage',
|
||||||
'getId',
|
|
||||||
'downloadURL',
|
'downloadURL',
|
||||||
'inspectServiceWorker',
|
'inspectServiceWorker',
|
||||||
'print',
|
'print',
|
||||||
|
|
|
@ -36,15 +36,9 @@ const loadedModules = new Map([
|
||||||
])
|
])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
preloadSrc, preloadError, webContentsId, platform, execPath, env
|
preloadSrc, preloadError, platform, execPath, env
|
||||||
} = electron.ipcRenderer.sendSync('ELECTRON_BROWSER_SANDBOX_LOAD', preloadPath)
|
} = electron.ipcRenderer.sendSync('ELECTRON_BROWSER_SANDBOX_LOAD', preloadPath)
|
||||||
|
|
||||||
Object.defineProperty(process, 'webContentsId', {
|
|
||||||
configurable: false,
|
|
||||||
writable: false,
|
|
||||||
value: webContentsId
|
|
||||||
})
|
|
||||||
|
|
||||||
require('../renderer/web-frame-init')()
|
require('../renderer/web-frame-init')()
|
||||||
|
|
||||||
// Pass different process object to the preload script(which should not have
|
// Pass different process object to the preload script(which should not have
|
||||||
|
|
|
@ -207,7 +207,7 @@ describe('BrowserWindow module', () => {
|
||||||
const contents = w.webContents
|
const contents = w.webContents
|
||||||
w.destroy()
|
w.destroy()
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
contents.getId()
|
contents.getProcessId()
|
||||||
}, /Object has been destroyed/)
|
}, /Object has been destroyed/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -40,7 +40,7 @@ describe('webContents module', () => {
|
||||||
it('returns an array of web contents', (done) => {
|
it('returns an array of web contents', (done) => {
|
||||||
w.webContents.on('devtools-opened', () => {
|
w.webContents.on('devtools-opened', () => {
|
||||||
const all = webContents.getAllWebContents().sort((a, b) => {
|
const all = webContents.getAllWebContents().sort((a, b) => {
|
||||||
return a.getId() - b.getId()
|
return a.id - b.id
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.ok(all.length >= 4)
|
assert.ok(all.length >= 4)
|
||||||
|
@ -61,15 +61,15 @@ describe('webContents module', () => {
|
||||||
if (isCi) return done()
|
if (isCi) return done()
|
||||||
|
|
||||||
const specWebContents = remote.getCurrentWebContents()
|
const specWebContents = remote.getCurrentWebContents()
|
||||||
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
assert.equal(specWebContents.id, webContents.getFocusedWebContents().id)
|
||||||
|
|
||||||
specWebContents.once('devtools-opened', () => {
|
specWebContents.once('devtools-opened', () => {
|
||||||
assert.equal(specWebContents.devToolsWebContents.getId(), webContents.getFocusedWebContents().getId())
|
assert.equal(specWebContents.devToolsWebContents.id, webContents.getFocusedWebContents().id)
|
||||||
specWebContents.closeDevTools()
|
specWebContents.closeDevTools()
|
||||||
})
|
})
|
||||||
|
|
||||||
specWebContents.once('devtools-closed', () => {
|
specWebContents.once('devtools-closed', () => {
|
||||||
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
assert.equal(specWebContents.id, webContents.getFocusedWebContents().id)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1035,7 +1035,7 @@ describe('<webview> tag', function () {
|
||||||
assert.ok(webview.partition)
|
assert.ok(webview.partition)
|
||||||
|
|
||||||
const listener = function (webContents, permission, callback) {
|
const listener = function (webContents, permission, callback) {
|
||||||
if (webContents.getId() === webview.getId()) {
|
if (webContents.id === webview.getWebContents().id) {
|
||||||
// requestMIDIAccess with sysex requests both midi and midiSysex so
|
// requestMIDIAccess with sysex requests both midi and midiSysex so
|
||||||
// grant the first midi one and then reject the midiSysex one
|
// grant the first midi one and then reject the midiSysex one
|
||||||
if (requestedPermission === 'midiSysex' && permission === 'midi') {
|
if (requestedPermission === 'midiSysex' && permission === 'midi') {
|
||||||
|
@ -1121,7 +1121,7 @@ describe('<webview> tag', function () {
|
||||||
webview.partition = 'permissionTest'
|
webview.partition = 'permissionTest'
|
||||||
webview.setAttribute('nodeintegration', 'on')
|
webview.setAttribute('nodeintegration', 'on')
|
||||||
session.fromPartition(webview.partition).setPermissionRequestHandler((webContents, permission, callback) => {
|
session.fromPartition(webview.partition).setPermissionRequestHandler((webContents, permission, callback) => {
|
||||||
if (webContents.getId() === webview.getId()) {
|
if (webContents.id === webview.getWebContents().id) {
|
||||||
assert.equal(permission, 'notifications')
|
assert.equal(permission, 'notifications')
|
||||||
setTimeout(() => { callback(true) }, 10)
|
setTimeout(() => { callback(true) }, 10)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue