Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request permissions page #2569

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
browser: true,
},
globals: {
chrome: false,
basicContext: false,
require: false,
requireModule: false,
Expand Down
41 changes: 41 additions & 0 deletions app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class ApplicationController extends Controller {
@tracked _navWidthExpanded = 180;
@tracked _navWidthCollapsed = 48;
@tracked navIsCollapsed = false;
@tracked inspectingTabOrigin = null;

get navWidth() {
return this.navIsCollapsed
Expand All @@ -53,6 +54,25 @@ export default class ApplicationController extends Controller {
this.mixinDetails = [];
}

get targetTabOrigin() {
if (!this.inspectingTabOrigin) {
void this.requestTargetTabOrigin();
return null;
}
return `${window.location.origin}/request.html?tabOrigin=${this.inspectingTabOrigin}`;
}

requestTargetTabOrigin() {
// during tests
if (typeof chrome === 'undefined') {
return;
}
chrome.devtools.inspectedWindow.eval('window.location', (resp) => {
const origin = resp.origin;
this.inspectingTabOrigin = origin;
});
}

/*
* Called when digging deeper into object stack
* from within the ObjectInspector
Expand Down Expand Up @@ -190,4 +210,25 @@ export default class ApplicationController extends Controller {
this.set('mixinDetails', null);
}
}

@action
requestPermissionForAll() {
function onResponse(response) {
if (response) {
console.log('Permission was granted');
} else {
console.log('Permission was refused');
}
return chrome.permissions.getAll();
}

const permissionsToRequest = {
origins: ['<all_urls>'],
};

chrome.permissions.request(permissionsToRequest).then(async (response) => {
const currentPermissions = await onResponse(response);
console.log(`Current permissions:`, currentPermissions);
});
}
}
1 change: 0 additions & 1 deletion app/services/adapters/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default class Chrome extends WebExtension {
@tracked canOpenResource = true;

openResource(file, line) {
/*global chrome */
// For some reason it opens the line after the one specified
chrome.devtools.panels.openResource(file, line - 1);
}
Expand Down
1 change: 0 additions & 1 deletion app/services/adapters/web-extension.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* globals chrome */
import { computed } from '@ember/object';
import { tracked } from '@glimmer/tracking';

Expand Down
3 changes: 3 additions & 0 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<ul>
<li>This is not an Ember application.</li>
<li>You are using an old version of Ember (&lt; rc5).</li>
<li>You did not have set up the addons permissions.
<a target='_blank' rel="noopener noreferrer" href={{this.targetTabOrigin}}>request permissions</a>
</li>
{{#if this.isChrome}}
<li>
You are using the file:// protocol (instead of http://), in which case:
Expand Down
31 changes: 31 additions & 0 deletions skeletons/web-extension/request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<head>
<link rel="stylesheet" href="./panes-3-16-0/assets/ember-inspector.css">
<link rel="stylesheet" href="./panes-3-16-0/assets/vendor.css">
</head>
<body class='theme--light'>
<div class="error-page box-border overflow-auto absolute inset-0 flex text-base13 text-md bg-base02">
<div class="error-page__content box-border relative m-auto px-6 pb-6 rounded bg-base00" style='border: 1px solid orangered'>
<div class="error-page__header overflow-hidden relative flex items-center font-bold text-4xl">
<div class="flex-grow pt-6">
<br />
Request permission to enable ember inspector
<img style='position: absolute; right: 0; top: 0' src='./panes-3-16-0/assets/images/icon48.png'/>
<br />
<br />
</div>
</div>

<div class="error-page__body pb-2">
<button style='padding: 5px' id='request-all'>request permission for all sites</button>
<br />
<br />
<button style='padding: 5px' id='request-one'>request permission for </button>
<br />
<br />
</div>
</div>
</div>
</body>
<script src='./request.js'></script>
</html>
13 changes: 13 additions & 0 deletions skeletons/web-extension/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
document.getElementById('request-all').addEventListener('click', async () => {
await chrome.permissions.request({origins: ['<all_urls>']});
window.close()
})

const url = new URL(window.location);
const tabOrigin = url.searchParams.get('tabOrigin');
document.getElementById('request-one').innerText += ' ' + tabOrigin;

document.getElementById('request-one').addEventListener('click', async () => {
await chrome.permissions.request({origins: [tabOrigin + '/*']});
window.close()
})
Loading