From 828327df24b3a01e4c30abadbb63c76778212464 Mon Sep 17 00:00:00 2001 From: David Dahl Date: Fri, 4 Feb 2011 11:59:14 -0800 Subject: [PATCH] Bug 628651 - [OSX] show notification bar offering to restart in 32-bit mode when content tries to use a 32-bit plugin using carbon based NPAPI a=hardblocker r=gavin, mossop --- browser/app/profile/firefox.js | 4 ++ browser/base/content/browser.js | 63 +++++++++++++++++-- browser/base/content/test/Makefile.in | 4 ++ .../browser_maconly_carbon_mismatch_plugin.js | 54 ++++++++++++++++ .../en-US/chrome/browser/browser.properties | 3 + 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 browser/base/content/test/browser_maconly_carbon_mismatch_plugin.js diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index fe549823f9ae..5a4736d95503 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -587,6 +587,10 @@ pref("pfs.datasource.url", "https://pfs.mozilla.org/plugins/PluginFinderService. pref("plugins.hide_infobar_for_missing_plugin", false); pref("plugins.hide_infobar_for_outdated_plugin", false); +#ifdef XP_MACOSX +pref("plugins.hide_infobar_for_carbon_failure_plugin", false); +#endif + pref("plugins.update.url", "https://www.mozilla.com/%LOCALE%/plugincheck/"); pref("plugins.update.notifyUser", false); diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 8628b6ce2da9..aea5b6e88bd4 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -1370,6 +1370,9 @@ function prepareForStartup() { gBrowser.addEventListener("PluginOutdated", gPluginHandler, true); gBrowser.addEventListener("PluginDisabled", gPluginHandler, true); gBrowser.addEventListener("NewPluginInstalled", gPluginHandler.newPluginInstalled, true); +#ifdef XP_MACOSX + gBrowser.addEventListener("npapi-carbon-event-model-failure", gPluginHandler, true); +#endif Services.obs.addObserver(gPluginHandler.pluginCrashed, "plugin-crashed", false); @@ -6620,6 +6623,7 @@ var gPluginHandler = { handleEvent : function(event) { let self = gPluginHandler; let plugin = event.target; + let hideBarPrefName; // We're expecting the target to be a plugin. if (!(plugin instanceof Ci.nsIObjectLoadingContent)) @@ -6639,7 +6643,7 @@ var gPluginHandler = { /* FALLTHRU */ case "PluginBlocklisted": case "PluginOutdated": - let hideBarPrefName = event.type == "PluginOutdated" ? + hideBarPrefName = event.type == "PluginOutdated" ? "plugins.hide_infobar_for_outdated_plugin" : "plugins.hide_infobar_for_missing_plugin"; if (gPrefService.getBoolPref(hideBarPrefName)) @@ -6647,7 +6651,15 @@ var gPluginHandler = { self.pluginUnavailable(plugin, event.type); break; +#ifdef XP_MACOSX + case "npapi-carbon-event-model-failure": + hideBarPrefName = "plugins.hide_infobar_for_carbon_failure_plugin"; + if (gPrefService.getBoolPref(hideBarPrefName)) + return; + self.pluginUnavailable(plugin, event.type); + break; +#endif case "PluginDisabled": self.addLinkClickCallback(plugin, "managePlugins"); break; @@ -6705,8 +6717,7 @@ var gPluginHandler = { openHelpLink("plugin-crashed", false); }, - - // event listener for missing/blocklisted/outdated plugins. + // event listener for missing/blocklisted/outdated/carbonFailure plugins. pluginUnavailable: function (plugin, eventType) { let browser = gBrowser.getBrowserForDocument(plugin.ownerDocument .defaultView.top.document); @@ -6751,6 +6762,23 @@ var gPluginHandler = { } } +#ifdef XP_MACOSX + function carbonFailurePluginsRestartBrowser() + { + // Notify all windows that an application quit has been requested. + let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]. + createInstance(Ci.nsISupportsPRBool); + Services.obs.notifyObservers(cancelQuit, "quit-application-requested", null); + + // Something aborted the quit process. + if (cancelQuit.data) + return; + + let as = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); + as.quit(Ci.nsIAppStartup.eRestarti386 | Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit); + } +#endif + let notifications = { PluginBlocklisted : { barID : "blocked-plugins", @@ -6790,9 +6818,36 @@ var gPluginHandler = { popup : null, callback : showPluginsMissing }], - } + }, +#ifdef XP_MACOSX + "npapi-carbon-event-model-failure" : { + barID : "carbon-failure-plugins", + iconURL : "chrome://mozapps/skin/plugins/notifyPluginGeneric.png", + message : gNavigatorBundle.getString("carbonFailurePluginsMessage.title"), + buttons: [{ + label : gNavigatorBundle.getString("carbonFailurePluginsMessage.restartButton.label"), + accessKey : gNavigatorBundle.getString("carbonFailurePluginsMessage.restartButton.accesskey"), + popup : null, + callback : carbonFailurePluginsRestartBrowser + }], + } +#endif }; +#ifdef XP_MACOSX + if (eventType == "npapi-carbon-event-model-failure") { + let carbonFailureNotification = + notificationBox.getNotificationWithValue("carbon-failure-plugins"); + + if (carbonFailureNotification) + carbonFailureNotification.close(); + + let macutils = Cc["@mozilla.org/xpcom/mac-utils;1"].getService(Ci.nsIMacUtils); + // if this is not a Universal build, just follow PluginNotFound path + if (!macutils.isUniversalBinary) + eventType = "PluginNotFound"; + } +#endif if (eventType == "PluginBlocklisted") { if (blockedNotification || missingNotification) return; diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index 7f2c9b7b4355..0fef899f85a7 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -251,6 +251,10 @@ else _BROWSER_FILES += \ browser_customize.js \ $(NULL) + +# TODO: Activate after carbon test plugin lands, bug 628651 +# browser_maconly_carbon_mismatch_plugin.js \ + endif ifneq (gtk2,$(MOZ_WIDGET_TOOLKIT)) diff --git a/browser/base/content/test/browser_maconly_carbon_mismatch_plugin.js b/browser/base/content/test/browser_maconly_carbon_mismatch_plugin.js new file mode 100644 index 000000000000..2c623cedb651 --- /dev/null +++ b/browser/base/content/test/browser_maconly_carbon_mismatch_plugin.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +let tab, browser; + +function tearDown() +{ + while (gBrowser.tabs.length > 1) { + gBrowser.removeCurrentTab(); + } +} + +registerCleanupFunction(tearDown); + +function addTab(aURL) +{ + gBrowser.selectedTab = gBrowser.addTab(); + content.location = aURL; + tab = gBrowser.selectedTab; + browser = gBrowser.getBrowserForTab(tab); +} + +function onLoad() { + executeSoon(function (){ + browser.removeEventListener("npapi-carbon-event-model-failure", + arguments.callee, false); + let notificationBox = gBrowser.getNotificationBox(); + let notificationBar = notificationBox.getNotificationWithValue("carbon-failure-plugins"); + ok(notificationBar, "Carbon Error plugin notification bar was found"); + finish(); + }); +} + +function test() { + try { + let abi = Services.appinfo.XPCOMABI; + if (!abi.match(/64/)) { + todo(false, "canceling test, wrong platform"); + return; + } + let macutils = Cc["@mozilla.org/xpcom/mac-utils;1"].getService(Ci.nsIMacUtils); + if (!macutils.isUniversalBinary) { + todo(false, "canceling test, not a universal build") + return; + } + } + catch (e) { + return; + } + waitForExplicitFinish(); + addTab('data:text/html,

Plugin carbon mismatch test

'); + gBrowser.addEventListener("npapi-carbon-event-model-failure", onLoad, false); +} + diff --git a/browser/locales/en-US/chrome/browser/browser.properties b/browser/locales/en-US/chrome/browser/browser.properties index b5be70286637..b86f256ec4cc 100644 --- a/browser/locales/en-US/chrome/browser/browser.properties +++ b/browser/locales/en-US/chrome/browser/browser.properties @@ -114,6 +114,9 @@ crashedpluginsMessage.reloadButton.accesskey=R crashedpluginsMessage.submitButton.label=Submit a crash report crashedpluginsMessage.submitButton.accesskey=S crashedpluginsMessage.learnMore=Learn Moreā€¦ +carbonFailurePluginsMessage.title=This page requires a plugin that can only run in 32-bit mode +carbonFailurePluginsMessage.restartButton.label=Restart in 32-bit mode +carbonFailurePluginsMessage.restartButton.accesskey=R # Sanitize # LOCALIZATION NOTE (sanitizeDialog2.everything.title): When "Time range to