-
Notifications
You must be signed in to change notification settings - Fork 350
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
WIP of auto-container-origin #386
WIP of auto-container-origin #386
Conversation
webextension/background.js
Outdated
|
||
browser.contextMenus.onClicked.addListener((info, tab) => { | ||
const pageUrl = new window.URL(info.pageUrl); | ||
const userContextId = getUserContextIdFromCookieStore(tab.cookieStoreId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 tab.cookieStoreId
Yay Firefox 52 WebExtensions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to work for 51? Totally forgot about that :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I introduced cookieStoreId, but it's not in FF51.... we can still retrieve the userContextId from the tab as we do in index.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start. Some nits but overall it's coming along. Agree with the changes you already mention making.
webextension/background.js
Outdated
} | ||
}); | ||
|
||
browser.webRequest.onBeforeRequest.addListener((options) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add this check?
if (options.frameId !== 0) {
return {}
}
So we only do this logic for the requests that happen in the top frame?
I.e., we just want to check the first/top request in the tab - not all the requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the check anyway for paranoia sake.
webextension/background.js
Outdated
return false; | ||
} | ||
|
||
const storagePrefix = "originMap@@_"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: more descriptive name? originContainerMap@@_
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done... the @@_
is my paranoia about something merging with the key itself as it's just a boring key val store.
webextension/background.js
Outdated
return { | ||
cancel: true, | ||
}; | ||
return {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unreachable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup deleted.
webextension/background.js
Outdated
console.log('err', e); | ||
return {}; | ||
}); | ||
},{urls: ["<all_urls>"], types: ["main_frame"]}, ["blocking"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the main_frame
RequestFilter
here takes care of my concern about processing every request. 👍
Absolutely 👍
I would leave this out at first, until users tell us they're sick of the warning? Based on the experience in Blok, I imagine most users will get their origins and containers linked in the first couple weeks, and it seems we should err on the side of reminding them about the privacy & security concerns of auto-linking rather than err on the side of users easily falling back into insecure browsing.
👍 for the tab-bar context menu (is this possible in WebExtension?), the container icon in the Awesomebar (see #387 - possible in WebExtension?), and/or a new pageAction. |
webextension/background.js
Outdated
const storagePrefix = "originMap@@_"; | ||
const storageArea = browser.storage.local; | ||
|
||
browser.contextMenus.onClicked.addListener((info, tab) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add:
if (info.menuItemId !== "open-in-this-container") {
return;
}
To make sure that clicks on other context menus don't trigger the assignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if we add any certainly. There is a click handler per each menu item too, I just didn't test that out yet.
56a05d9
to
4bb53ef
Compare
I put in a rough warning when users are directed to a container, currently this opens in the container and I use history replace to move them into the same container. It might actually make more sense to use message passing to the background page to open in a selected container (this would allow the user flow of people who want to auto assign the container but also want to change it sometimes). To make the never ask checkbox work I had to use message passing anyway. I would have to put it a fair bit more work in to get any of these features:
I think we should show the full URL here however... I also think it looks ugly :( This really needs some of @johngruen's touch probably either way it's lower on the priorities I have on making pretty. |
👍 to some styling work on it. Some clearer copy may also be: "
|
hey @jonathanKingston @groovecoder work week this week has put me behind. Should be able to clean up by friday. |
webextension/background.js
Outdated
|
||
browser.contextMenus.onClicked.addListener((info, tab) => { | ||
const pageUrl = new window.URL(info.pageUrl); | ||
const userContextId = getUserContextIdFromCookieStore(tab.cookieStoreId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I introduced cookieStoreId, but it's not in FF51.... we can still retrieve the userContextId from the tab as we do in index.js.
webextension/background.js
Outdated
if (neverAsk) { | ||
browser.tabs.create({url, cookieStoreId: `firefox-container-${userContextId}`}); | ||
} else { | ||
browser.tabs.create({url: `${loadPage}?url=${url}`, cookieStoreId: `firefox-container-${userContextId}`}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the position? We should open the new tab in the same position where we are.
Plus, doing this we are breaks the Back-Forward feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another point would be: what about if the URL is loaded from a window.open() ? This breaks also 'the web' because you will open a tab, instead of a window, and the parent window will not have a reference to the new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would somewhat argue breaking window.opener is a feature. I'm not sure we can fix that through a web extension either right?
4bb53ef
to
c2d78c7
Compare
@groovecoder @bakulf @kjozwiak and @johngruen I pushed an update for the branch auto-container-origin This has the index mentioned by @bakulf and the new error layout as discussed with @groovecoder and demoed in the meeting. It is still missing the ability to unassign though. |
a2df62f
to
90beb31
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly naming and copy nits. But a big-ish question is if we want to set a global "never ask" preference, or I thought we should start with a "Never ask again for this site".
Should we start out with the more secure/private/annoying UX - i.e., confirm for each individual assignment - and only relax it when users complain?
webextension/background.js
Outdated
@@ -1,3 +1,174 @@ | |||
const assignManager = { | |||
closeableWindows: new Set([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: CLOSEABLE_WINDOWS
to denote it is a constant/hard-coded set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using uppercase here makes me cry a little (especially when it's not a const too), much like Hungarian notation does but I will not argue ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webextension/background.js
Outdated
"about:home", | ||
"about:blank" | ||
]), | ||
menuAssignId: "open-in-this-container", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MENU_ASSIGNED_ID
webextension/background.js
Outdated
"about:blank" | ||
]), | ||
menuAssignId: "open-in-this-container", | ||
menuRemoveId: "remove-open-in-this-container", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MENU_REMOVE_ID
webextension/background.js
Outdated
}); | ||
}); | ||
|
||
browser.runtime.onMessage.addListener((request) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change request
to something more accurate like neverAskMessage
? When I first read this, I thought request
was an HTTP request of some kind.
webextension/background.js
Outdated
}, | ||
|
||
getOriginStoreKey(url) { | ||
const storagePrefix = "originContainerMap@@_"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: STORAGE_PREFIX
to denote hard-coded constant string.
webextension/background.js
Outdated
if (store[originStoreKey]) { | ||
browser.contextMenus.create({ | ||
id: this.menuRemoveId, | ||
title: "Remove Open in This Container", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "Un-assign this site from this Container"
webextension/js/confirm-page.js
Outdated
@@ -0,0 +1,25 @@ | |||
const redirectUrl = new URL(window.location).searchParams.get("url"); | |||
document.getElementById("redirect-url").textContent = redirectUrl; | |||
const redirectOrigin = new URL(redirectUrl).origin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const redirectHostname = new URL(redirectUrl).hostname
and textContent = redirectHostname
will probably look cleaner?
webextension/confirm-page.html
Outdated
</p> | ||
<div id="redirect-url"></div> | ||
<p> | ||
You asked for <span id="redirect-origin"></span> to always open in <span id="container-name">this</span> container, are you sure you want to confirm?<br /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe You assigned <span id="redirect-hostname"></span> to <span id="container-name">this</span> container, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to change "asked for" to "added" as above however. I personally think that is less code'y.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either copy is fine there. But "are you sure you want to confirm" is redundant? Should be "Are you sure you want to open the page in this container?" right?
@@ -383,7 +383,7 @@ span ~ .panel-header-text { | |||
.panel-footer { | |||
align-items: center; | |||
background: #efefef; | |||
block-size: 55px; | |||
block-size: 54px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screw you 55th pixel!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was unrelated but part of the menu being unaligned.
webextension/manifest.json
Outdated
"storage", | ||
"tabs", | ||
"webRequestBlocking", | ||
"webRequest" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, we really are creating a tab-manager add-on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were just faking it till we made it before, now we are the real deal 🦊
90beb31
to
5598e70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost perfect. But, during my spot-checks, I still seemed to lose the context menu feature and the originSettings completely? I'm using jpm watchpost
... so maybe a file-change triggered an .xpi re-install? Will the origin settings survive an addon upgrade?
webextension/confirm-page.html
Outdated
</p> | ||
<div id="redirect-url"></div> | ||
<p> | ||
You asked for <span id="redirect-origin"></span> to always open in <span id="container-name">this</span> container, are you sure you want to confirm?<br /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either copy is fine there. But "are you sure you want to confirm" is redundant? Should be "Are you sure you want to open the page in this container?" right?
webextension/background.js
Outdated
} | ||
resolve(null); | ||
}).catch(() => { | ||
reject(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a reason here. .catch((e) => { reject(e); });
would be fine.
Also, this needs a version bump to 2.1.0 |
webextension/background.js
Outdated
browser.notifications.create({ | ||
type: "basic", | ||
title: "Containers", | ||
message: `Successfully ${actionName} ${pageUrl.origin} to always open in this container`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just remove the ${pageUrl.origin}
completely? A significant origin string overflows the notification interface, and the important feedback here seems to be the action. Can we assume the user knows the origin they just assigned, since they just assigned it?
Issues found while testing the Bug [1] "Always Open in This Contianer" is being displayed under the context menu under STR:
Bug [2] Once you've assigned an origin to a specific container, opening that particular origin within PB won't load the website and will produce the following error in the browser console:
Even though an origin has been assigned to a specific container, users should still be able to open that website within PB as those are two separate features. For example, lets say I assigned google.ca to my "Google" container but I want to search for something that won't appear in my history and I don't feel like creating a "throw away" container. I won't be able to use google.ca in this situation. STR:
Bug [3] The "Hey, we heard you liked containers!" intermediate window will still appear for origins that belonged to a specific container that have been deleted. STR:
Bug [4] Related to the above issue (bug 3), the "Always Open in This Container" item will appear under the context menu of an origin that used to belong to a container that has now been removed. Once a user deletes a container, we need to remove all origin associations with that particular container. STR:
Suggestion, possible Bug [5] I'm not sure if this is considered a bug or not, but I personally feel like it's going to be an issue. When clearing "everything" from FX using the "Clear Recent History" feature, should we be removing all the origin associations? Even though we've removed all the cookies, history etc... that origin association is still there and the user will get the "Hey, we heard you liked containers!" window. STR:
Bug [6] Should we be saving the
|
c4f261d
to
e333f91
Compare
@kjozwiak Issues 1,2,6 are solved. Issues 3,4,5 are not. I'm not actually sure 5 is solvable with the extension. 3,4 are not solvable in web extensions see: https://bugzilla.mozilla.org/show_bug.cgi?id=1352189 I will look into message passing from SDK when I get home (I was hoping to completely dog food web extensions here :( ) |
e333f91
to
b02be0b
Compare
b02be0b
to
0c7242e
Compare
Linting rule I wrote is borked... should fix which is annoying as I want this rule to be replaced. |
Also... this latest patch fixes 3 and 4 and rebases. |
d2300f8
to
ce8b4de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. Spot-checks look good.
I would still be good to merge this, but I notice assigning a site to auto-open in a container now triggers a |
Verified that bug#1, 2, 3, 4 and 6 have been fixed. |
ce8b4de
to
3e657a2
Compare
Super WIP PR just to demo the functionality for @johngruen and @groovecoder ...
STR (Assumes default search is google):
Tab created in step 6. Will be in "Google" container.
Loads of polish needed like: