Skip to content

Loading…

[Firefox on Android] [Request] PageAction to access popup and dashboard #1054

Open
my-password-is-password opened this Issue · 4 comments

3 participants

@my-password-is-password

https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/PageActions.jsm

It adds a ublock icon to the location bar where you can access popup easily. You can also access the dashboard by long pressing on the icon.

ublockandroidpageaction

On my phone I can have a max of 2 icons displayed in the location bar. If theres more it adds a dropdown menu where you can still access them.
ublockandroidpageaction2

This is the code I used but I don't know if this is the proper way to do it. I put the code at https://github.com/gorhill/uBlock/blob/master/platform/firefox/vapi-background.js#L1451 . I also didn't know how to add the icon without using a base64 string. Saw this http://stackoverflow.com/questions/26024959/how-do-i-provide-icons-for-firefox-android-sdk where he said he was only able to use either base64 or drawable for PageActions. Maybe @AlexVallat could implement this the correct way.

// PageAction for Fennec
        if ( !vAPI.pageActionID ) {
            var {PageActions} = Cu.import('resource://gre/modules/PageActions.jsm', null);

            var iconBase64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAHlBMVEXRpKS8eXncubnnz8/////Bg4OWLS2vXl6AAAD///9J2KRXAAAACnRSTlP///////////8AsswszwAAARVJREFUeNrsl8GSwiAQRJs2gP7/D69iNMBAdDqetjI3KrxXySXTjVs/y+6Y67A8w3RoDTA8rjsDY4CLHxjg460BTt4Y4OV7A9x8Z4Cfbw0Q+MYAha8NkPjKAI3fDBD5twEq/zJA5lcDdP5pwAG+GLBw8CCUv892LscwuMi7IB4RxFNwCk7Bfxfk3wiSLkiFyLrgSfCoYPsGvyC2Br8grbmSIecQ6Rc8VkY/PsH1sCB9LeDO4qvnkierbb5cU7isLEKaLtfbMn+HT/MI7yVgUOfXiEOZf4Usqvw75lHkt6BJja+iLiW+DttU+CbuU+DbwkE/31Ueuvm+dNHLm9pHJ2+LJ338oPrSxQ/Ld5zOF+XbXf//BBgA0SB0SI89Zz8AAAAASUVORK5CYII=';

            vAPI.pageActionID = PageActions.add({
                title: 'uBlock',
                icon: iconBase64,

                clickCallback: function() {
                    var win = Services.wm.getMostRecentWindow('navigator:browser');
                    var curTab = getTabBrowser(win).selectedTab;
                    var url = getBrowserForTab(curTab).currentURI.spec;
                    /* 
                     // Don't need this.  Didn't think any of the "about:" pages made net request but some do.
                     var noActionURLs = [
                        'about:',
                        'chrome://global/'
                    ];

                    var i = noActionURLs.length;
                    while ( i-- ) {
                        if ( url.lastIndexOf(noActionURLs[i], 0) === 0 ) {
                            return;
                        }
                    }
                    */

                    var tabId;
                    var popupURL = 'chrome://ublock/content/popup.html?tabId=';
                    if ( url.lastIndexOf(popupURL, 0) === 0 ) {
                        tabId = url.slice(popupURL.length);
                        vAPI.tabs.select(tabId);
                        return;
                    }

                    tabId = vAPI.tabs.getTabId(curTab);
                    vAPI.tabs.open({
                        url: 'popup.html?tabId=' + tabId,
                        index: -1,
                        select: true
                    });
                },

                longClickCallback: function() {
                    vAPI.tabs.open({
                        url: 'dashboard.html',
                        index: -1,
                        select: true
                    });
                }
            });

            cleanupTasks.push(function() {
                if ( vAPI.pageActionID ) {
                    PageActions.remove(vAPI.pageActionID);
                }
            }
@AlexVallat
Collaborator

I'm not entirely convinced that a page action is the appropriate place for uBlock... given the extremely limited space available, I would suggest that it is more for commands that apply for only a few pages, and need to advertise their availability in those situations. uBlock will be present on every page, and therefore always showing an icon there would be wasting the valuable space. I think uBlock more properly belongs on the menu, rather than in the URL bar.

@my-password-is-password

I don't want to get rid of uBlock in the menu. I would just like a quicker way to get to the popups. Maybe an option in Settings like there is for "Make use of context menu where appropriate" for people who do want uBlock in the URL bar? uBlock is the extension I interact with the most and the only extension on Firefox that really matters, so it wouldn't be wasting valuable space for me.

@smlx

An option for this feature would be great - having ublock open in a separate tab can make it difficult to get back to the tab you opened it from.

@AlexVallat
Collaborator

This proposal has nothing to do with opening it in a separate tab. It is just about changing the button from appearing in the tools menu to appearing inside the URL bar - the effect of clicking it would still be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.