www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

extensionsOverlay.js (3962B)


      1 /*
      2     ***** BEGIN LICENSE BLOCK *****
      3     
      4     Copyright © 2011 Center for History and New Media
      5                      George Mason University, Fairfax, Virginia, USA
      6                      http://zotero.org
      7     
      8     This file is part of Zotero.
      9     
     10     Zotero is free software: you can redistribute it and/or modify
     11     it under the terms of the GNU Affero General Public License as published by
     12     the Free Software Foundation, either version 3 of the License, or
     13     (at your option) any later version.
     14     
     15     Zotero is distributed in the hope that it will be useful,
     16     but WITHOUT ANY WARRANTY; without even the implied warranty of
     17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18     GNU Affero General Public License for more details.
     19     
     20     You should have received a copy of the GNU Affero General Public License
     21     along with Zotero.  If not, see <http://www.gnu.org/licenses/>.
     22     
     23     The Original Code is the Extension Manager UI.
     24     
     25     The Initial Developer of the Original Code is the Mozilla Foundation.
     26     Portions created by the Initial Developer are Copyright (C) 2010
     27     the Initial Developer. All Rights Reserved.
     28     
     29     Contributor(s):
     30       Blair McBride <bmcbride@mozilla.com>
     31       Simon Kornblith <simon@zotero.org</a>
     32     
     33     ***** END LICENSE BLOCK *****
     34 */
     35 
     36 gDiscoverView.onLocationChange = function(aWebProgress, aRequest, aLocation) {
     37 	// Ignore the about:blank load
     38 	if (aLocation.spec == "about:blank")
     39 		return;
     40 
     41 	// When using the real session history the inner-frame will update the
     42 	// session history automatically, if using the fake history though it must
     43 	// be manually updated
     44 	if (gHistory == FakeHistory) {
     45 		var docshell = aWebProgress.QueryInterface(Ci.nsIDocShell);
     46 
     47 		var state = {
     48 			view: "addons://discover/",
     49 			url: aLocation.spec
     50 		};
     51 
     52 		var replaceHistory = Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY << 16;
     53 		if (docshell.loadType & replaceHistory)
     54 			gHistory.replaceState(state);
     55 		else
     56 			gHistory.pushState(state);
     57 		gViewController.lastHistoryIndex = gHistory.index;
     58 	}
     59 
     60 	gViewController.updateCommands();
     61 	
     62 	// In Zotero, we override the behavior below to allow pages on other sites
     63 	
     64 	/*// If the hostname is the same as the new location's host and either the
     65 	// default scheme is insecure or the new location is secure then continue
     66 	// with the load
     67 	if (aLocation.host == this.homepageURL.host &&
     68 			(!this.homepageURL.schemeIs("https") || aLocation.schemeIs("https")))
     69 		return;
     70 
     71 	// Canceling the request will send an error to onStateChange which will show
     72 	// the error page
     73 	aRequest.cancel(Components.results.NS_BINDING_ABORTED);*/
     74 };
     75 
     76 gDiscoverView.onStateChange = function(aWebProgress, aRequest, aStateFlags, aStatus) {
     77 	// Only care about the network events
     78 	if (!(aStateFlags & (Ci.nsIWebProgressListener.STATE_IS_NETWORK)))
     79 		return;
     80 
     81 	// If this is the start of network activity then show the loading page
     82 	if (aStateFlags & (Ci.nsIWebProgressListener.STATE_START))
     83 		this.node.selectedPanel = this._loading;
     84 
     85 	// Ignore anything except stop events
     86 	if (!(aStateFlags & (Ci.nsIWebProgressListener.STATE_STOP)))
     87 		return;
     88 
     89 	// Consider the successful load of about:blank as still loading
     90 	if (aRequest instanceof Ci.nsIChannel && aRequest.URI.spec == "about:blank")
     91 		return;
     92 
     93 	// If there was an error loading the page or the new hostname is not the
     94 	// same as the default hostname or the default scheme is secure and the new
     95 	// scheme is insecure then show the error page
     96 	if (aRequest && aRequest instanceof Ci.nsIHttpChannel && !aRequest.requestSucceeded) {
     97 		this.showError();
     98 	} else {
     99 		// Got a successful load, make sure the browser is visible
    100 		this.node.selectedPanel = this._browser;
    101 		gViewController.updateCommands();
    102 	}
    103 
    104 	var listeners = this._loadListeners;
    105 	this._loadListeners = [];
    106 
    107 	listeners.forEach(function(aListener) {
    108 		aListener();
    109 	});
    110 };
    111 
    112 // Don't care about http/https
    113 gDiscoverView.onSecurityChange = function() {};