зеркало из https://github.com/mozilla/gecko-dev.git
Bug 718088: offer to re-set keyword.URL if it has a non-default value, r=bz on the docshell parts, r=fryn on the rest, ui-r=limi.
This commit is contained in:
Родитель
2f94fd89cb
Коммит
2b2e7edf42
|
@ -50,6 +50,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "webrtcUI",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
||||
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "KeywordURLResetPrompter",
|
||||
"resource:///modules/KeywordURLResetPrompter.jsm");
|
||||
|
||||
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
||||
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
||||
|
||||
|
@ -258,6 +261,13 @@ BrowserGlue.prototype = {
|
|||
this._initPlaces(false);
|
||||
}
|
||||
break;
|
||||
case "defaultURIFixup-using-keyword-pref":
|
||||
if (KeywordURLResetPrompter.shouldPrompt) {
|
||||
let keywordURI = subject.QueryInterface(Ci.nsIURI);
|
||||
KeywordURLResetPrompter.prompt(this.getMostRecentBrowserWindow(),
|
||||
keywordURI);
|
||||
}
|
||||
break;
|
||||
case "initial-migration-will-import-default-bookmarks":
|
||||
this._migrationImportsDefaultBookmarks = true;
|
||||
break;
|
||||
|
@ -294,6 +304,7 @@ BrowserGlue.prototype = {
|
|||
os.addObserver(this, "distribution-customization-complete", false);
|
||||
os.addObserver(this, "places-shutdown", false);
|
||||
this._isPlacesShutdownObserver = true;
|
||||
os.addObserver(this, "defaultURIFixup-using-keyword-pref", false);
|
||||
},
|
||||
|
||||
// cleanup (called on application shutdown)
|
||||
|
@ -323,6 +334,7 @@ BrowserGlue.prototype = {
|
|||
os.removeObserver(this, "places-database-locked");
|
||||
if (this._isPlacesShutdownObserver)
|
||||
os.removeObserver(this, "places-shutdown");
|
||||
os.removeObserver(this, "defaultURIFixup-using-keyword-pref");
|
||||
UserAgentOverrides.uninit();
|
||||
webappsUI.uninit();
|
||||
SignInToWebsiteUX.uninit();
|
||||
|
|
|
@ -370,6 +370,21 @@ telemetryYesButtonAccessKey = Y
|
|||
telemetryNoButtonLabel = No
|
||||
telemetryNoButtonAccessKey = N
|
||||
|
||||
# Keyword.URL reset prompt
|
||||
# LOCALIZATION NOTE (keywordPrompt.message):
|
||||
# - %1$S is brandShortName
|
||||
# - %2$S is a host name (e.g. "somewebsearch.com") from the current value of keyword.URL
|
||||
# - %3$S is the name of the default search engine (e.g. "Google")
|
||||
keywordPrompt.message = %1$S is using '%2$S' for searches from the location bar. Would you like to restore the default search (%3$S)?
|
||||
|
||||
# LOCALIZATION NOTE (keywordPrompt.yesButton): %1$S is the name of the default search engine
|
||||
keywordPrompt.yesButton = Yes, use %1$S
|
||||
keywordPrompt.yesButton.accessKey = Y
|
||||
|
||||
# LOCALIZATION NOTE (keywordPrompt.noButton): %1$S is a host name (e.g. "somewebsearch.com") from the current value of keyword.URL
|
||||
keywordPrompt.noButton = No, continue using '%1$S'
|
||||
keywordPrompt.noButton.accessKey = N
|
||||
|
||||
# Webapps notification popup
|
||||
webapps.install = Install
|
||||
webapps.install.accesskey = I
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
let EXPORTED_SYMBOLS = [ "KeywordURLResetPrompter" ];
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const KEYWORD_PROMPT_REV = 1;
|
||||
|
||||
let KeywordURLResetPrompter = {
|
||||
get shouldPrompt() {
|
||||
let keywordURLUserSet = Services.prefs.prefHasUserValue("keyword.URL");
|
||||
let declinedRev;
|
||||
try {
|
||||
declinedRev = Services.prefs.getIntPref("browser.keywordURLPromptDeclined");
|
||||
} catch (ex) {}
|
||||
|
||||
return keywordURLUserSet && declinedRev != KEYWORD_PROMPT_REV;
|
||||
},
|
||||
|
||||
prompt: function KeywordURLResetPrompter_prompt(win, keywordURI) {
|
||||
let tabbrowser = win.gBrowser;
|
||||
let notifyBox = tabbrowser.getNotificationBox();
|
||||
|
||||
let existingNotification = notifyBox.getNotificationWithValue("keywordURL-reset");
|
||||
if (existingNotification)
|
||||
return;
|
||||
|
||||
// Find the name/URI of this build's original default engine.
|
||||
// XXX: Can't use originalDefaultEngine getter here, because that doesn't
|
||||
// use the default pref branch.
|
||||
let defaultURI;
|
||||
let defaultEngine;
|
||||
try {
|
||||
let defaultPB = Services.prefs.getDefaultBranch(null);
|
||||
const nsIPLS = Ci.nsIPrefLocalizedString;
|
||||
let defaultName = defaultPB.getComplexValue("browser.search.defaultenginename", nsIPLS).data;
|
||||
defaultEngine = Services.search.getEngineByName(defaultName);
|
||||
defaultURI = defaultEngine.getSubmission("foo").uri;
|
||||
} catch (ex) {
|
||||
// Something went horribly wrong! bail out
|
||||
return;
|
||||
}
|
||||
|
||||
// If the user-set value has the same base domain as the default, don't
|
||||
// prompt.
|
||||
let keywordBaseDomain;
|
||||
try {
|
||||
keywordBaseDomain = Services.eTLD.getBaseDomain(keywordURI);
|
||||
if (keywordBaseDomain == Services.eTLD.getBaseDomain(defaultURI))
|
||||
return;
|
||||
} catch (ex) {}
|
||||
|
||||
if (!keywordBaseDomain)
|
||||
return;
|
||||
|
||||
let brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
||||
let brandShortName = brandBundle.GetStringFromName("brandShortName");
|
||||
|
||||
let browserBundle = win.gNavigatorBundle;
|
||||
let msg = browserBundle.getFormattedString("keywordPrompt.message",
|
||||
[brandShortName, keywordBaseDomain,
|
||||
defaultEngine.name]);
|
||||
let buttons = [
|
||||
{
|
||||
label: browserBundle.getFormattedString("keywordPrompt.yesButton",
|
||||
[defaultEngine.name]),
|
||||
accessKey: browserBundle.getString("keywordPrompt.yesButton.accessKey"),
|
||||
popup: null,
|
||||
callback: function(aNotificationBar, aButton) {
|
||||
Services.prefs.clearUserPref("keyword.URL");
|
||||
try {
|
||||
// If the currently loaded URI still has the same base domain as the
|
||||
// keyword URI (this is used as a rough approximation of whether the
|
||||
// user is still seeing search results as opposed to having clicked
|
||||
// on a result link), load the default engine's searchForm URL so
|
||||
// that they can re-do their search.
|
||||
let currentBaseDomain = Services.eTLD.getBaseDomain(tabbrowser.currentURI);
|
||||
if (currentBaseDomain == keywordBaseDomain)
|
||||
tabbrowser.loadURI(defaultEngine.searchForm);
|
||||
} catch (ex) {}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: browserBundle.getFormattedString("keywordPrompt.noButton",
|
||||
[keywordBaseDomain]),
|
||||
accessKey: browserBundle.getString("keywordPrompt.noButton.accessKey"),
|
||||
popup: null,
|
||||
callback: function(aNotificationBar, aButton) {
|
||||
Services.prefs.setIntPref("browser.keywordURLPromptDeclined", KEYWORD_PROMPT_REV);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
let notification = notifyBox.appendNotification(msg, "keywordURL-reset", null, notifyBox.PRIORITY_WARNING_HIGH, buttons);
|
||||
notification.setAttribute("hideclose", true);
|
||||
// stick around for a few page loads in case there are redirects involved
|
||||
notification.persistence = 3;
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ EXTRA_JS_MODULES = \
|
|||
Social.jsm \
|
||||
webappsUI.jsm \
|
||||
webrtcUI.jsm \
|
||||
KeywordURLResetPrompter.jsm \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "nsIURIFixup.h"
|
||||
#include "nsDefaultURIFixup.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -344,7 +345,17 @@ NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword,
|
|||
|
||||
spec.Insert(url, 0);
|
||||
|
||||
return NS_NewURI(aURI, spec);
|
||||
nsresult rv = NS_NewURI(aURI, spec);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
||||
if (obsSvc) {
|
||||
obsSvc->NotifyObservers(*aURI,
|
||||
"defaultURIFixup-using-keyword-pref",
|
||||
nullptr);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef MOZ_TOOLKIT_SEARCH
|
||||
|
|
Загрузка…
Ссылка в новой задаче