[chrome-gnome-shell] update-check: make python-requests dependency optional.



commit d6d3aeb6fccc8199aa253bdbdf384cf0dc330a79
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Mon Mar 20 23:44:23 2017 +0400

    update-check: make python-requests dependency optional.
    
    Drop frontend update check and webRequest optional permission.

 connector/chrome-gnome-shell.py     |   15 ++++--
 extension/_locales/en/messages.json |   11 +---
 extension/css/options.css           |    1 +
 extension/include/sweettooth-api.js |    3 +-
 extension/include/update.js         |   85 +-------------------------------
 extension/manifest.json             |    3 +-
 extension/options.html              |   15 ++----
 extension/options.js                |   92 +++++++++++++++++-----------------
 po/template.pot                     |   20 +++-----
 9 files changed, 77 insertions(+), 168 deletions(-)
---
diff --git a/connector/chrome-gnome-shell.py b/connector/chrome-gnome-shell.py
index 5d49acb..3603764 100755
--- a/connector/chrome-gnome-shell.py
+++ b/connector/chrome-gnome-shell.py
@@ -23,6 +23,12 @@ import struct
 import sys
 import traceback
 
+REQUESTS_IMPORTED = True
+try:
+    import requests
+except ImportError:
+    REQUESTS_IMPORTED = False
+
 CONNECTOR_VERSION = 8.2
 DEBUG_ENABLED = False
 
@@ -365,6 +371,10 @@ class ChromeGNOMEShell(Gio.Application):
                 else:
                     disable_version_check = False
 
+                supports = ['notifications']
+                if REQUESTS_IMPORTED:
+                    supports.append('update-check')
+
                 self.send_message(
                     {
                         'success': True,
@@ -372,10 +382,7 @@ class ChromeGNOMEShell(Gio.Application):
                             'connectorVersion': CONNECTOR_VERSION,
                             'shellVersion': shell_version.unpack() if shell_version is not None else None,
                             'versionValidationEnabled': not disable_version_check,
-                            'supports': [
-                                'notifications',
-                                'update-check'
-                            ]
+                            'supports': supports
                         }
                     }
                 )
diff --git a/extension/_locales/en/messages.json b/extension/_locales/en/messages.json
index 6e508a1..247ad09 100644
--- a/extension/_locales/en/messages.json
+++ b/extension/_locales/en/messages.json
@@ -87,18 +87,13 @@
                "message": "Check for extensions update",
                "description": "Option name. Allow enable/disable update check for GNOME Shell extensions."
        },
+       "options_update_check_notice": {
+               "message": "Your native host connector does not support check for GNOME Shell extensions 
updates. Probably python-requests package is missing."
+       },
        "options_check_period": {
                "message": "Update check period",
                "description": "Option name. Allow to set interval between GNOME Shell extensions update 
checks."
        },
-       "options_show_network_errors": {
-               "message": "Show information about network errors",
-               "description": "Option name. By default Chrome do not reveal exact network error in case of 
request failure. Allow enable/disable extended error information."
-       },
-       "options_show_network_errors_notice": {
-               "message": "Chrome permission «webRequest» required.",
-               "description": "This is a notice under option name. Warns user that additional browser 
permission is required if option will be enabled."
-       },
        "options_show_release_notes": {
                "message": "Show release notes when extension updated",
                "description": "Option name. Allow to enable/disable popup with release notes when Web 
extension is updated."
diff --git a/extension/css/options.css b/extension/css/options.css
index 734e43d..54d9c52 100644
--- a/extension/css/options.css
+++ b/extension/css/options.css
@@ -18,6 +18,7 @@ body {
 
 .buttons { text-align: center; margin-top: 1em; }
 .notice { font-size: 90%; font-weight: normal; margin-top: 0.5em; white-space: nowrap; }
+.update-notice { display: none; }
 .wrapped { white-space: normal; }
 
 fieldset {
diff --git a/extension/include/sweettooth-api.js b/extension/include/sweettooth-api.js
index 0a52e07..7189202 100644
--- a/extension/include/sweettooth-api.js
+++ b/extension/include/sweettooth-api.js
@@ -89,8 +89,7 @@ window.SweetTooth = function () {
                                apiObject.versionValidationEnabled = response.versionValidationEnabled;
 
                                let REQUIRED_APIS = [
-                                       "notifications",
-                                       "update-check"
+                                       "notifications"
                                ];
 
                                if(response.supports)
diff --git a/extension/include/update.js b/extension/include/update.js
index 92bf693..3cd56a8 100644
--- a/extension/include/update.js
+++ b/extension/include/update.js
@@ -48,7 +48,9 @@ GSC.update = (function($) {
                                }
                                else
                                {
-                                       _frontendCheck(shellVersion);
+                                       chrome.storage.sync.set({
+                                               updateCheck: false
+                                       });
                                }
                        }
                        else
@@ -58,83 +60,6 @@ GSC.update = (function($) {
                });
        }
 
-       /*
-        * TODO: remove in version 9
-        * @Deprecated
-        */
-       function _frontendCheck(shellVersion)
-       {
-               GSC.sendNativeRequest({execute: 'listExtensions'}, function (extensionsResponse) {
-                       if (extensionsResponse.success)
-                       {
-                               if ($.isEmptyObject(extensionsResponse.extensions))
-                                       return;
-
-                               var request = {
-                                       shell_version: shellVersion,
-                                       installed: {}
-                               };
-
-                               for (uuid in extensionsResponse.extensions)
-                               {
-                                       if (GSC.isUUID(uuid) && extensionsResponse.extensions[uuid].type == 
EXTENSION_TYPE.PER_USER)
-                                       {
-                                               request.installed[uuid] = {version: 
parseInt(extensionsResponse.extensions[uuid].version) || 1};
-                                       }
-                               }
-
-                               request.installed = JSON.stringify(request.installed);
-
-                               chrome.permissions.contains({
-                                       permissions: ["webRequest"]
-                               }, function (webRequestEnabled) {
-                                       if (webRequestEnabled)
-                                       {
-                                               chrome.webRequest.onErrorOccurred.addListener(
-                                                               onNetworkError,
-                                                               {
-                                                                       urls: [UPDATE_URL + "*"],
-                                                                       types: ['xmlhttprequest']
-                                                               }
-                                               );
-                                       }
-
-                                       $.ajax({
-                                               url: UPDATE_URL,
-                                               data: request,
-                                               dataType: 'json',
-                                               method: 'GET',
-                                               cache: false
-                                       })
-                                               .done(function(data) {
-                                                       onSweetToothResponse(data, 
extensionsResponse.extensions)
-                                               })
-                                               .fail(function (jqXHR, textStatus, errorThrown) {
-                                                       if (textStatus === 'error' && !errorThrown)
-                                                       {
-                                                               if (webRequestEnabled)
-                                                               {
-                                                                       return;
-                                                               }
-
-                                                               textStatus = m('network_error');
-                                                       }
-
-                                                       createUpdateFailedNotification(textStatus);
-                                               }).always(function () {
-                                                       if (webRequestEnabled)
-                                                       {
-                                                               
chrome.webRequest.onErrorOccurred.removeListener(onNetworkError);
-                                                       }
-                                               });
-                               });
-                       } else
-                       {
-                               createUpdateFailedNotification(response.message ? response.message : 
m('native_request_failed', 'listExtensions'));
-                       }
-               });
-       }
-
        function onSweetToothResponse(data, installedExtensions) {
                GSC.notifications.remove(NOTIFICATION_UPDATE_CHECK_FAILED);
 
@@ -175,10 +100,6 @@ GSC.update = (function($) {
                });
        }
 
-       function onNetworkError(details) {
-               createUpdateFailedNotification(details.error);
-       }
-
        function init() {
                function onNotificationAction(notificationId, buttonIndex) {
                        if ($.inArray(notificationId, [NOTIFICATION_UPDATE_AVAILABLE, 
NOTIFICATION_UPDATE_CHECK_FAILED]) === -1)
diff --git a/extension/manifest.json b/extension/manifest.json
index 91d0307..539c3bd 100644
--- a/extension/manifest.json
+++ b/extension/manifest.json
@@ -48,8 +48,7 @@
     "https://extensions.gnome.org/";
   ],
   "optional_permissions": [
-    "idle",
-    "webRequest"
+    "idle"
   ],
   "web_accessible_resources": ["include/sweettooth-api.js"]
 }
diff --git a/extension/options.html b/extension/options.html
index d84bc5a..7b64c8b 100644
--- a/extension/options.html
+++ b/extension/options.html
@@ -25,7 +25,10 @@
 
                                <fieldset>
                                        <dl>
-                                               <dt><span data-i18n="options_update_check"></span>:</dt>
+                                               <dt>
+                                                       <span data-i18n="options_update_check"></span>:<br 
class="update-notice"/>
+                                                       <span class="notice wrapped update-notice" 
data-i18n="options_update_check_notice"></span>
+                                               </dt>
                                                <dd>
                                                        <label for='update_check_yes' 
data-i18n="yes"></label> <input type='radio' id='update_check_yes' name='update_check' />
                                                        <label for='update_check_no' data-i18n="no"></label> 
<input type='radio' id='update_check_no' name='update_check' />
@@ -52,16 +55,6 @@
                                                </dd>
                                        </dl>
                                        <dl>
-                                               <dt>
-                                                       <label for='show_network_errors_yes' 
data-i18n="options_show_network_errors"></label>:<br />
-                                                       <span class="notice wrapped" 
data-i18n="options_show_network_errors_notice"></span>
-                                               </dt>
-                                               <dd>
-                                                       <label for='show_network_errors_yes' 
data-i18n="yes"></label> <input type='radio' id='show_network_errors_yes' name='show_network_errors' />
-                                                       <label for='show_network_errors_no' 
data-i18n="no"></label> <input type='radio' id='show_network_errors_no' name='show_network_errors' />
-                                               </dd>
-                                       </dl>
-                                       <dl>
                                                <dt><span data-i18n="options_show_release_notes"></span>:</dt>
                                                <dd>
                                                        <label for='show_release_notes_yes' 
data-i18n="yes"></label> <input type='radio' id='show_release_notes_yes' name='show_release_notes' />
diff --git a/extension/options.js b/extension/options.js
index 56547e5..17b0feb 100644
--- a/extension/options.js
+++ b/extension/options.js
@@ -83,17 +83,54 @@ function restore_options()
        tabby.init();
 
        chrome.storage.sync.get(DEFAULT_SYNC_OPTIONS, function (items) {
-               setCheckUpdate(items.updateCheck);
-               $('#update_check_period').val(items.updateCheckPeriod);
-               setReleaseNotes(items.showReleaseNotes);
+               function toggle_update_notice(show) {
+                       let notice = $('#update_check_yes')
+                               .closest('dl')
+                               .find('dt br, dt span.notice');
 
-               retrieveUpdateTimes();
-       });
+                       if (show)
+                       {
+                               notice.show();
+                       }
+                       else
+                       {
+                               notice.hide();
+                       }
+               }
+
+               function disable_update_check() {
+                       if (items.updateCheck)
+                       {
+                               items.updateCheck = false;
+
+                               chrome.storage.sync.set({
+                                       updateCheck: items.updateCheck
+                               });
+                       }
 
-       chrome.permissions.contains({
-               permissions: ["webRequest"]
-       }, function(result) {
-               setNetworkErrors(result);
+                       $("[name='update_check'], #update_check_period").prop('disabled', 'disabled');
+
+                       toggle_update_notice(true);
+               }
+
+               GSC.onInitialize().then(function (response) {
+                       if (!GSC.nativeUpdateCheckSupported(response))
+                       {
+                               disable_update_check();
+                       }
+                       else
+                       {
+                               $('#update_check_period').val(items.updateCheckPeriod);
+                               toggle_update_notice(false);
+                               retrieveUpdateTimes();
+                       }
+
+                       setCheckUpdate(items.updateCheck);
+               }, function(response) {
+                       disable_update_check();
+               });
+
+               setReleaseNotes(items.showReleaseNotes);
        });
 
        if(COMPAT.SYNC_STORAGE)
@@ -124,11 +161,6 @@ function restore_options()
        {
                $('dialog').hide();
        }
-
-       if(!COMPAT.PERMISSIONS_CONTAINS)
-       {
-               $('#show_network_errors_yes').parents('dl:first').hide();
-       }
 }
 
 function retrieveUpdateTimes()
@@ -179,14 +211,6 @@ function setReleaseNotes(result)
                $('#show_release_notes_no').prop('checked', true);
 }
 
-function setNetworkErrors(result)
-{
-       if(result)
-               $('#show_network_errors_yes').prop('checked', true);
-       else
-               $('#show_network_errors_no').prop('checked', true);
-}
-
 function setSyncExtensions(result)
 {
        if(result)
@@ -195,26 +219,6 @@ function setSyncExtensions(result)
                $('#synchronize_extensions_no').prop('checked', true);
 }
 
-function handleWebrequestPermission()
-{
-       if($('#show_network_errors_yes').prop('checked'))
-       {
-               chrome.permissions.request({
-                       permissions: ["webRequest"]
-               }, function(granted) {
-                       setNetworkErrors(granted);
-               });
-       }
-       else
-       {
-               chrome.permissions.remove({
-                       permissions: ["webRequest"]
-               }, function(removed) {
-                       setNetworkErrors(!removed);
-               });
-       }
-}
-
 function handleSynchronize()
 {
        if($('#synchronize_extensions_yes').is(':checked'))
@@ -309,10 +313,6 @@ i18n();
 document.addEventListener('DOMContentLoaded', restore_options);
 document.getElementById('save').addEventListener('click', save_options);
 
-$.each(document.getElementsByName('show_network_errors'), function(index, control) {
-       control.addEventListener('change', handleWebrequestPermission);
-});
-
 $.each(document.getElementsByName('synchronize_extensions'), function(index, control) {
        control.addEventListener('change', handleSynchronize);
 });
diff --git a/po/template.pot b/po/template.pot
index a088855..57b99e8 100644
--- a/po/template.pot
+++ b/po/template.pot
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: 1.0\n"
 "Report-Msgid-Bugs-To: ykonotopov gnome org\n"
-"POT-Creation-Date: 2017-03-08 18:00+0000\n"
+"POT-Creation-Date: 2017-03-20 19:36+0000\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
@@ -149,18 +149,6 @@ msgstr ""
 msgid "Options saved."
 msgstr ""
 
-#. Option name. By default Chrome do not reveal exact network error in case of
-#. request failure. Allow enable/disable extended error information.
-#: chrome-gnome-shell-key-options_show_network_errors:1
-msgid "Show information about network errors"
-msgstr ""
-
-#. This is a notice under option name. Warns user that additional browser
-#. permission is required if option will be enabled.
-#: chrome-gnome-shell-key-options_show_network_errors_notice:1
-msgid "Chrome permission «webRequest» required."
-msgstr ""
-
 #. Option name. Allow to enable/disable popup with release notes when Web
 #. extension is updated.
 #: chrome-gnome-shell-key-options_show_release_notes:1
@@ -196,6 +184,12 @@ msgstr ""
 msgid "Check for extensions update"
 msgstr ""
 
+#: chrome-gnome-shell-key-options_update_check_notice:1
+msgid ""
+"Your native host connector does not support check for GNOME Shell extensions"
+" updates. Probably python-requests package is missing."
+msgstr ""
+
 #: chrome-gnome-shell-key-platform_not_supported:1
 msgid "Native host connector is not supported for your platform."
 msgstr ""


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]