| OLD | NEW | 
|    1 // Copyright 2015 The Chromium Authors. All rights reserved. |    1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 /** |    5 /** | 
|    6  * @fileoverview |    6  * @fileoverview | 
|    7  * 'site-details-permission' handles showing the state of one permission, such |    7  * 'site-details-permission' handles showing the state of one permission, such | 
|    8  * as Geolocation, for a given origin. |    8  * as Geolocation, for a given origin. | 
|    9  */ |    9  */ | 
|   10 Polymer({ |   10 Polymer({ | 
|   11   is: 'site-details-permission', |   11   is: 'site-details-permission', | 
|   12  |   12  | 
|   13   behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], |   13   behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], | 
|   14  |   14  | 
|   15   properties: { |   15   properties: { | 
|   16     /** |   16     /** | 
|   17      * The site that this widget is showing details for. |   17      * The site that this widget is showing details for. | 
|   18      * @type {SiteException} |   18      * @type {SiteException} | 
|   19      */ |   19      */ | 
|   20     site: Object, |   20     site: Object, | 
|   21   }, |   21   }, | 
|   22  |   22  | 
|   23   observers: ['siteChanged_(site, category)'], |   23   observers: ['siteChanged_(site, category)'], | 
|   24  |   24  | 
|   25   /** @override */ |   25   /** @override */ | 
|   26   attached: function() { |   26   attached: function() { | 
|   27     this.addWebUIListener('contentSettingSitePermissionChanged', |   27     this.addWebUIListener( | 
 |   28         'contentSettingSitePermissionChanged', | 
|   28         this.sitePermissionChanged_.bind(this)); |   29         this.sitePermissionChanged_.bind(this)); | 
|   29   }, |   30   }, | 
|   30  |   31  | 
|   31   /** |   32   /** | 
|   32    * Returns true if the origins match, e.g. http://google.com and |   33    * Returns true if the origins match, e.g. http://google.com and | 
|   33    * http://[*.]google.com. |   34    * http://[*.]google.com. | 
|   34    * @param {string} left The first origin to compare. |   35    * @param {string} left The first origin to compare. | 
|   35    * @param {string} right The second origin to compare. |   36    * @param {string} right The second origin to compare. | 
|   36    * @return {boolean} True if the origins are the same. |   37    * @return {boolean} True if the origins are the same. | 
|   37    * @private |   38    * @private | 
|   38    */ |   39    */ | 
|   39   sameOrigin_: function(left, right) { |   40   sameOrigin_: function(left, right) { | 
|   40     return this.removePatternWildcard(left) == |   41     return this.removePatternWildcard(left) == | 
|   41         this.removePatternWildcard(right); |   42         this.removePatternWildcard(right); | 
|   42   }, |   43   }, | 
|   43  |   44  | 
|   44   /** @private */ |   45   /** @private */ | 
|   45   isCookiesCategory_: function(category) { |   46   isCookiesCategory_: function(category) { | 
|   46     return category == settings.ContentSettingsTypes.COOKIES; |   47     return category == settings.ContentSettingsTypes.COOKIES; | 
|   47   }, |   48   }, | 
|   48  |   49  | 
|   49   /** |   50   /** | 
|   50    * Sets the site to display. |   51    * Sets the site to display. | 
|   51    * @param {!SiteException} site The site to display. |   52    * @param {!SiteException} site The site to display. | 
|   52    * @private |   53    * @private | 
|   53    */ |   54    */ | 
|   54   siteChanged_: function(site) { |   55   siteChanged_: function(site) { | 
|   55  |   56  | 
|   56     this.browserProxy.getExceptionList(this.category).then( |   57     this.browserProxy.getExceptionList(this.category) | 
|   57         function(exceptionList) { |   58         .then(function(exceptionList) { | 
|   58       for (var i = 0; i < exceptionList.length; ++i) { |   59           for (var i = 0; i < exceptionList.length; ++i) { | 
|   59         if (exceptionList[i].embeddingOrigin == site.embeddingOrigin && |   60             if (exceptionList[i].embeddingOrigin == site.embeddingOrigin && | 
|   60             this.sameOrigin_(exceptionList[i].origin, site.origin)) { |   61                 this.sameOrigin_(exceptionList[i].origin, site.origin)) { | 
|   61           this.$.permission.value = exceptionList[i].setting; |   62               this.$.permission.value = exceptionList[i].setting; | 
|   62           break; |   63               break; | 
|   63         } |   64             } | 
|   64       } |   65           } | 
|   65     }.bind(this)); |   66         }.bind(this)); | 
|   66   }, |   67   }, | 
|   67  |   68  | 
|   68   /** |   69   /** | 
|   69    * Called when a site within a category has been changed. |   70    * Called when a site within a category has been changed. | 
|   70    * @param {number} category The category that changed. |   71    * @param {number} category The category that changed. | 
|   71    * @param {string} origin The origin of the site that changed. |   72    * @param {string} origin The origin of the site that changed. | 
|   72    * @param {string} embeddingOrigin The embedding origin of the site that |   73    * @param {string} embeddingOrigin The embedding origin of the site that | 
|   73    *     changed. |   74    *     changed. | 
|   74    * @private |   75    * @private | 
|   75    */ |   76    */ | 
|   76   sitePermissionChanged_: function(category, origin, embeddingOrigin) { |   77   sitePermissionChanged_: function(category, origin, embeddingOrigin) { | 
|   77     if (this.site === undefined) |   78     if (this.site === undefined) | 
|   78       return; |   79       return; | 
|   79     if (category != this.category) |   80     if (category != this.category) | 
|   80       return; |   81       return; | 
|   81  |   82  | 
|   82     if (origin == '' || (origin == this.site.origin && |   83     if (origin == '' || | 
|   83                          embeddingOrigin == this.site.embeddingOrigin)) { |   84         (origin == this.site.origin && | 
 |   85          embeddingOrigin == this.site.embeddingOrigin)) { | 
|   84       this.siteChanged_(this.site); |   86       this.siteChanged_(this.site); | 
|   85     } |   87     } | 
|   86   }, |   88   }, | 
|   87  |   89  | 
|   88   /** |   90   /** | 
|   89    * Resets the category permission for this origin. |   91    * Resets the category permission for this origin. | 
|   90    */ |   92    */ | 
|   91   resetPermission: function() { |   93   resetPermission: function() { | 
|   92     this.browserProxy.resetCategoryPermissionForOrigin( |   94     this.browserProxy.resetCategoryPermissionForOrigin( | 
|   93         this.site.origin, this.site.embeddingOrigin, this.category, |   95         this.site.origin, this.site.embeddingOrigin, this.category, | 
|   94         this.site.incognito); |   96         this.site.incognito); | 
|   95   }, |   97   }, | 
|   96  |   98  | 
|   97   /** |   99   /** | 
|   98    * Handles the category permission changing for this origin. |  100    * Handles the category permission changing for this origin. | 
|   99    * @private |  101    * @private | 
|  100    */ |  102    */ | 
|  101   onPermissionSelectionChange_: function() { |  103   onPermissionSelectionChange_: function() { | 
|  102     this.browserProxy.setCategoryPermissionForOrigin( |  104     this.browserProxy.setCategoryPermissionForOrigin( | 
|  103         this.site.origin, this.site.embeddingOrigin, this.category, |  105         this.site.origin, this.site.embeddingOrigin, this.category, | 
|  104         this.$.permission.value, this.site.incognito); |  106         this.$.permission.value, this.site.incognito); | 
|  105   }, |  107   }, | 
|  106 }); |  108 }); | 
| OLD | NEW |