зеркало из https://github.com/mozilla/gecko-dev.git
Merge m-i to m-c.
This commit is contained in:
Коммит
d883880028
|
@ -52,8 +52,6 @@
|
|||
#if defined(XP_WIN) && !defined(__MINGW32__)
|
||||
#include "nsIEProfileMigrator.h"
|
||||
#include "nsIEHistoryEnumerator.h"
|
||||
#elif defined(XP_MACOSX)
|
||||
#include "nsSafariProfileMigrator.h"
|
||||
#endif
|
||||
|
||||
#include "rdf.h"
|
||||
|
@ -80,8 +78,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGNOMEShellService, Init)
|
|||
#if defined(XP_WIN) && !defined(__MINGW32__)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIEProfileMigrator)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIEHistoryEnumerator)
|
||||
#elif defined(XP_MACOSX)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSafariProfileMigrator)
|
||||
#endif
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFeedSniffer)
|
||||
|
@ -101,7 +97,6 @@ NS_DEFINE_NAMED_CID(NS_WINIEPROFILEMIGRATOR_CID);
|
|||
NS_DEFINE_NAMED_CID(NS_WINIEHISTORYENUMERATOR_CID);
|
||||
#elif defined(XP_MACOSX)
|
||||
NS_DEFINE_NAMED_CID(NS_SHELLSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_SAFARIPROFILEMIGRATOR_CID);
|
||||
#endif
|
||||
NS_DEFINE_NAMED_CID(NS_PRIVATE_BROWSING_SERVICE_WRAPPER_CID);
|
||||
|
||||
|
@ -119,7 +114,6 @@ static const mozilla::Module::CIDEntry kBrowserCIDs[] = {
|
|||
{ &kNS_WINIEHISTORYENUMERATOR_CID, false, NULL, nsIEHistoryEnumeratorConstructor },
|
||||
#elif defined(XP_MACOSX)
|
||||
{ &kNS_SHELLSERVICE_CID, false, NULL, nsMacShellServiceConstructor },
|
||||
{ &kNS_SAFARIPROFILEMIGRATOR_CID, false, NULL, nsSafariProfileMigratorConstructor },
|
||||
#endif
|
||||
{ &kNS_PRIVATE_BROWSING_SERVICE_WRAPPER_CID, false, NULL, nsPrivateBrowsingServiceWrapperConstructor },
|
||||
{ NULL }
|
||||
|
@ -154,7 +148,6 @@ static const mozilla::Module::ContractIDEntry kBrowserContracts[] = {
|
|||
{ NS_IEHISTORYENUMERATOR_CONTRACTID, &kNS_WINIEHISTORYENUMERATOR_CID },
|
||||
#elif defined(XP_MACOSX)
|
||||
{ NS_SHELLSERVICE_CONTRACTID, &kNS_SHELLSERVICE_CID },
|
||||
{ NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX "safari", &kNS_SAFARIPROFILEMIGRATOR_CID },
|
||||
#endif
|
||||
{ NS_PRIVATE_BROWSING_SERVICE_CONTRACTID, &kNS_PRIVATE_BROWSING_SERVICE_WRAPPER_CID },
|
||||
{ NULL }
|
||||
|
|
|
@ -46,11 +46,3 @@ DIRS = public src
|
|||
TEST_DIRS += tests
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# Needed for preprocessor removal of IE Profile Migrator label - bug 236901
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
ifdef GNU_CXX
|
||||
DEFINES += -DNO_IE_MIGRATOR=1
|
||||
endif
|
||||
endif
|
||||
|
||||
|
|
|
@ -67,13 +67,8 @@
|
|||
<!-- If you are adding a migrator, please add the appropriate
|
||||
hooks to GetDefaultBrowserMigratorKey in
|
||||
browser/components/migration/src/nsProfileMigrator.cpp -->
|
||||
#ifdef XP_MACOSX
|
||||
<radio id="safari" label="&importFromSafari.label;" accesskey="&importFromSafari.accesskey;"/>
|
||||
#elifdef XP_WIN
|
||||
#ifndef NO_IE_MIGRATOR
|
||||
<radio id="ie" label="&importFromIE.label;" accesskey="&importFromIE.accesskey;"/>
|
||||
#endif
|
||||
#endif
|
||||
<radio id="chrome" label="&importFromChrome.label;" accesskey="&importFromChrome.accesskey;"/>
|
||||
<radio id="firefox" label="&importFromFirefox.label;" accesskey="&importFromFirefox.accesskey;"/>
|
||||
<radio id="fromfile" label="&importFromHTMLFile.label;" accesskey="&importFromHTMLFile.accesskey;" hidden="true"/>
|
||||
|
|
|
@ -4,3 +4,5 @@ component {4cec1de4-1671-4fc3-a53e-6c539dc77a26} ChromeProfileMigrator.js
|
|||
contract @mozilla.org/profile/migrator;1?app=browser&type=chrome {4cec1de4-1671-4fc3-a53e-6c539dc77a26}
|
||||
component {91185366-ba97-4438-acba-48deaca63386} FirefoxProfileMigrator.js
|
||||
contract @mozilla.org/profile/migrator;1?app=browser&type=firefox {91185366-ba97-4438-acba-48deaca63386}
|
||||
component {4b609ecf-60b2-4655-9df4-dc149e474da1} SafariProfileMigrator.js
|
||||
contract @mozilla.org/profile/migrator;1?app=browser&type=safari {4b609ecf-60b2-4655-9df4-dc149e474da1}
|
||||
|
|
|
@ -48,25 +48,27 @@ ifndef MOZ_MEMORY
|
|||
USE_STATIC_LIBS = 1
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH)_$(GNU_CXX),WINNT_)
|
||||
CPPSRCS += nsIEProfileMigrator.cpp \
|
||||
nsBrowserProfileMigratorUtils.cpp \
|
||||
nsIEHistoryEnumerator.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
||||
CPPSRCS += nsSafariProfileMigrator.cpp \
|
||||
nsBrowserProfileMigratorUtils.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
EXTRA_PP_COMPONENTS = \
|
||||
ProfileMigrator.js \
|
||||
ChromeProfileMigrator.js \
|
||||
FirefoxProfileMigrator.js \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH)_$(GNU_CXX),WINNT_)
|
||||
CPPSRCS += nsIEProfileMigrator.cpp \
|
||||
nsBrowserProfileMigratorUtils.cpp \
|
||||
nsIEHistoryEnumerator.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_PP_COMPONENTS += SafariProfileMigrator.js \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
|
||||
EXTRA_PP_COMPONENTS += SafariProfileMigrator.js \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
BrowserProfileMigrators.manifest \
|
||||
$(NULL)
|
||||
|
|
|
@ -406,9 +406,7 @@ let MigrationUtils = Object.freeze({
|
|||
migrator = Cc["@mozilla.org/profile/migrator;1?app=browser&type=" +
|
||||
aKey].createInstance(Ci.nsIBrowserProfileMigrator);
|
||||
}
|
||||
catch(ex) {
|
||||
Cu.reportError("Could not get migrator '" + aKey + "' (" + ex + ")");
|
||||
}
|
||||
catch(ex) { }
|
||||
this._migrators.set(aKey, migrator);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,680 @@
|
|||
/* This Source Code is subject to the terms of the Mozilla Public License
|
||||
* version 2.0 (the "License"). You can obtain a copy of the License at
|
||||
* http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
let Cc = Components.classes;
|
||||
let Ci = Components.interfaces;
|
||||
let Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource:///modules/MigrationUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PropertyListUtils",
|
||||
"resource://gre/modules/PropertyListUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
|
||||
"resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
function Bookmarks(aBookmarksFile) {
|
||||
this._file = aBookmarksFile;
|
||||
}
|
||||
Bookmarks.prototype = {
|
||||
type: MigrationUtils.resourceTypes.BOOKMARKS,
|
||||
|
||||
migrate: function B_migrate(aCallback) {
|
||||
PropertyListUtils.read(this._file,
|
||||
MigrationUtils.wrapMigrateFunction(function migrateBookmarks(aDict) {
|
||||
if (!aDict)
|
||||
throw new Error("Could not read Bookmarks.plist");
|
||||
|
||||
let children = aDict.get("Children");;
|
||||
if (!children)
|
||||
throw new Error("Invalid Bookmarks.plist format");
|
||||
|
||||
PlacesUtils.bookmarks.runInBatchMode({
|
||||
runBatched: function() {
|
||||
let collection = aDict.get("Title") == "com.apple.ReadingList" ?
|
||||
this.READING_LIST_COLLECTION : this.ROOT_COLLECTION;
|
||||
this._migrateCollection(children, collection);
|
||||
}.bind(this)
|
||||
}, null);
|
||||
}.bind(this), aCallback));
|
||||
},
|
||||
|
||||
// Bookmarks collections in Safari. Constants for migrateCollection.
|
||||
ROOT_COLLECTION: 0,
|
||||
MENU_COLLECTION: 1,
|
||||
TOOLBAR_COLLECTION: 2,
|
||||
READING_LIST_COLLECTION: 3,
|
||||
|
||||
/**
|
||||
* Recursively migrate a Safari collection of bookmarks.
|
||||
*
|
||||
* @param aEntries
|
||||
* the collection's children
|
||||
* @param aCollection
|
||||
* one of the values above.
|
||||
*/
|
||||
_migrateCollection: function B__migrateCollection(aEntries, aCollection) {
|
||||
// A collection of bookmarks in Safari resembles places roots. In the
|
||||
// property list files (Bookmarks.plist, ReadingList.plist) they are
|
||||
// stored as regular bookmarks folders, and thus can only be distinguished
|
||||
// from by their names and places in the hierarchy.
|
||||
|
||||
let entriesFiltered = [];
|
||||
if (aCollection == this.ROOT_COLLECTION) {
|
||||
for (let entry of aEntries) {
|
||||
let type = entry.get("WebBookmarkType");
|
||||
if (type == "WebBookmarkTypeList" && entry.has("Children")) {
|
||||
let title = entry.get("Title");
|
||||
let children = entry.get("Children");
|
||||
if (title == "BookmarksBar")
|
||||
this._migrateCollection(children, this.TOOLBAR_COLLECTION);
|
||||
else if (title == "BookmarksMenu")
|
||||
this._migrateCollection(children, this.MENU_COLLECTION);
|
||||
else if (title == "com.apple.ReadingList")
|
||||
this._migrateCollection(children, this.READING_LIST_COLLECTION);
|
||||
else if (entry.get("ShouldOmitFromUI") !== true)
|
||||
entriesFiltered.push(entry);
|
||||
}
|
||||
else if (type == "WebBookmarkTypeLeaf") {
|
||||
entriesFiltered.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
entriesFiltered = aEntries;
|
||||
}
|
||||
|
||||
if (entriesFiltered.length == 0)
|
||||
return;
|
||||
|
||||
let folder = -1;
|
||||
switch (aCollection) {
|
||||
case this.ROOT_COLLECTION: {
|
||||
// In Safari, it is possible (though quite cumbersome) to move
|
||||
// bookmarks to the bookmarks root, which is the parent folder of
|
||||
// all bookmarks "collections". That is somewhat in parallel with
|
||||
// both the places root and the unfiled-bookmarks root.
|
||||
// Because the former is only an implementation detail in our UI,
|
||||
// the unfiled root seems to be the best choice.
|
||||
folder = PlacesUtils.unfiledBookmarksFolderId;
|
||||
break;
|
||||
}
|
||||
case this.MENU_COLLECTION: {
|
||||
folder = PlacesUtils.bookmarksMenuFolderId;
|
||||
if (!MigrationUtils.isStartupMigration) {
|
||||
folder = MigrationUtils.createImportedBookmarksFolder("Safari",
|
||||
folder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case this.TOOLBAR_COLLECTION: {
|
||||
folder = PlacesUtils.toolbarFolderId;
|
||||
if (!MigrationUtils.isStartupMigration) {
|
||||
folder = MigrationUtils.createImportedBookmarksFolder("Safari",
|
||||
folder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case this.READING_LIST_COLLECTION: {
|
||||
// Reading list items are imported as regular bookmarks.
|
||||
// They are imported under their own folder, created either under the
|
||||
// bookmarks menu (in the case of startup migration).
|
||||
folder = PlacesUtils.bookmarks.createFolder(
|
||||
PlacesUtils.bookmarksMenuFolderId,
|
||||
MigrationUtils.getLocalizedString("importedSafariReadingList"),
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error("Unexpected value for aCollection!");
|
||||
}
|
||||
|
||||
this._migrateEntries(entriesFiltered, folder);
|
||||
},
|
||||
|
||||
// migrate the given array of safari bookmarks to the given places
|
||||
// folder.
|
||||
_migrateEntries: function B__migrateEntries(aEntries, aFolderId) {
|
||||
for (let entry of aEntries) {
|
||||
let type = entry.get("WebBookmarkType");
|
||||
if (type == "WebBookmarkTypeList" && entry.has("Children")) {
|
||||
let title = entry.get("Title");
|
||||
let folderId = PlacesUtils.bookmarks.createFolder(
|
||||
aFolderId, title, PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
|
||||
// Empty folders may not have a children array.
|
||||
if (entry.has("Children"))
|
||||
this._migrateEntries(entry.get("Children"), folderId, false);
|
||||
}
|
||||
else if (type == "WebBookmarkTypeLeaf" && entry.has("URLString")) {
|
||||
let title, uri;
|
||||
if (entry.has("URIDictionary"))
|
||||
title = entry.get("URIDictionary").get("title");
|
||||
|
||||
try {
|
||||
uri = NetUtil.newURI(entry.get("URLString"));
|
||||
}
|
||||
catch(ex) {
|
||||
Cu.reportError("Invalid uri set for Safari bookmark: " + entry.get("URLString"));
|
||||
}
|
||||
if (uri) {
|
||||
PlacesUtils.bookmarks.insertBookmark(aFolderId, uri,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function History(aHistoryFile) {
|
||||
this._file = aHistoryFile;
|
||||
}
|
||||
History.prototype = {
|
||||
type: MigrationUtils.resourceTypes.HISTORY,
|
||||
|
||||
// Helper method for converting the visit date property to a PRTime value.
|
||||
// The visit date is stored as a string, so it's not read as a Date
|
||||
// object by PropertyListUtils.
|
||||
_parseCocoaDate: function H___parseCocoaDate(aCocoaDateStr) {
|
||||
let asDouble = parseFloat(aCocoaDateStr);
|
||||
if (!isNaN(asDouble)) {
|
||||
// reference date of NSDate.
|
||||
let date = new Date("1 January 2001, GMT");
|
||||
date.setMilliseconds(asDouble * 1000);
|
||||
return date * 1000;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
migrate: function H_migrate(aCallback) {
|
||||
PropertyListUtils.read(this._file, function migrateHistory(aDict) {
|
||||
try {
|
||||
if (!aDict)
|
||||
throw new Error("Could not read history property list");
|
||||
if (!aDict.has("WebHistoryDates"))
|
||||
throw new Error("Unexpected history-property list format");
|
||||
|
||||
// Safari's History file contains only top-level urls. It does not
|
||||
// distinguish between typed urls and linked urls.
|
||||
let transType = PlacesUtils.history.TRANSITION_LINK;
|
||||
|
||||
let places = [];
|
||||
let entries = aDict.get("WebHistoryDates");
|
||||
for (let entry of entries) {
|
||||
if (entry.has("lastVisitedDate")) {
|
||||
let visitDate = this._parseCocoaDate(entry.get("lastVisitedDate"));
|
||||
places.push({ uri: NetUtil.newURI(entry.get("")),
|
||||
title: entry.get("title"),
|
||||
visits: [{ transitionType: transType,
|
||||
visitDate: visitDate }] });
|
||||
}
|
||||
}
|
||||
if (places.length > 0) {
|
||||
PlacesUtils.asyncHistory.updatePlaces(places, {
|
||||
_success: false,
|
||||
handleResult: function() {
|
||||
// Importing any entry is considered a successful import.
|
||||
this._success = true;
|
||||
},
|
||||
handleError: function() {},
|
||||
handleCompletion: function() {
|
||||
aCallback(this._success);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
aCallback(false);
|
||||
}
|
||||
}
|
||||
catch(ex) {
|
||||
Cu.reportError(ex);
|
||||
aCallback(false);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Safari's preferences property list is independently used for three purposes:
|
||||
* (a) importation of preferences
|
||||
* (b) importation of search strings
|
||||
* (c) retrieving the home page.
|
||||
*
|
||||
* So, rather than reading it three times, it's cached and managed here.
|
||||
*/
|
||||
function MainPreferencesPropertyList(aPreferencesFile) {
|
||||
this._file = aPreferencesFile;
|
||||
this._callbacks = [];
|
||||
}
|
||||
MainPreferencesPropertyList.prototype = {
|
||||
/**
|
||||
* @see PropertyListUtils.read
|
||||
*/
|
||||
read: function MPPL_read(aCallback) {
|
||||
if ("_dict" in this) {
|
||||
aCallback(this._dict);
|
||||
return;
|
||||
}
|
||||
|
||||
let alreadyReading = this._callbacks.length > 0;
|
||||
this._callbacks.push(aCallback);
|
||||
if (!alreadyReading) {
|
||||
PropertyListUtils.read(this._file, function readPrefs(aDict) {
|
||||
this._dict = aDict;
|
||||
for (let callback of this._callbacks) {
|
||||
try {
|
||||
callback(aDict);
|
||||
}
|
||||
catch(ex) {
|
||||
Cu.reportError(ex);
|
||||
}
|
||||
}
|
||||
this._callbacks.splice(0);
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
// Workaround for nsIBrowserProfileMigrator.sourceHomePageURL until
|
||||
// it's replaced with an async method.
|
||||
_readSync: function MPPL__readSync() {
|
||||
if ("_dict" in this)
|
||||
return this._dict;
|
||||
|
||||
let inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
inputStream.init(this._file, -1, -1, 0);
|
||||
let binaryStream = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
binaryStream.setInputStream(inputStream);
|
||||
let bytes = binaryStream.readByteArray(inputStream.available());
|
||||
this._dict = PropertyListUtils._readFromArrayBufferSync(
|
||||
Uint8Array(bytes).buffer);
|
||||
return this._dict;
|
||||
}
|
||||
};
|
||||
|
||||
function Preferences(aMainPreferencesPropertyListInstance) {
|
||||
this._mainPreferencesPropertyList = aMainPreferencesPropertyListInstance;
|
||||
}
|
||||
Preferences.prototype = {
|
||||
type: MigrationUtils.resourceTypes.SETTINGS,
|
||||
|
||||
migrate: function MPR_migrate(aCallback) {
|
||||
this._mainPreferencesPropertyList.read(
|
||||
MigrationUtils.wrapMigrateFunction(function migratePrefs(aDict) {
|
||||
if (!aDict)
|
||||
throw new Error("Could not read preferences file");
|
||||
|
||||
this._dict = aDict;
|
||||
|
||||
let invert = function(webkitVal) !webkitVal;
|
||||
this._set("AutoFillPasswords", "signon.rememberSignons");
|
||||
this._set("OpenNewTabsInFront", "browser.tabs.loadInBackground", invert);
|
||||
this._set("WebKitJavaScriptCanOpenWindowsAutomatically",
|
||||
"dom.disable_open_during_load", invert);
|
||||
|
||||
// layout.spellcheckDefault is a boolean stored as a number.
|
||||
this._set("WebContinuousSpellCheckingEnabled",
|
||||
"layout.spellcheckDefault", Number);
|
||||
|
||||
// Auto-load images
|
||||
// Firefox has an elaborate set of Image preferences. The correlation is:
|
||||
// Mode: Safari Firefox
|
||||
// Blocked FALSE 2
|
||||
// Allowed TRUE 1
|
||||
// Allowed, originating site only -- 3
|
||||
this._set("WebKitDisplayImagesKey", "permissions.default.image",
|
||||
function(webkitVal) webkitVal ? 1 : 2);
|
||||
|
||||
// Default charset migration
|
||||
this._set("WebKitDefaultTextEncodingName", "intl.charset.default",
|
||||
function(webkitCharset) {
|
||||
// We don't support x-mac-korean (see bug 713516), but it mostly matches
|
||||
// x-windows-949.
|
||||
if (webkitCharset == "x-mac-korean")
|
||||
return "x-windows-949";
|
||||
|
||||
// getCharsetAlias throws if an invalid value is passed in.
|
||||
try {
|
||||
return Cc["@mozilla.org/charset-converter-manager;1"].
|
||||
getService(Ci.nsICharsetConverterManager).
|
||||
getCharsetAlias(webkitCharset);
|
||||
}
|
||||
catch(ex) {
|
||||
Cu.reportError("Could not convert webkit charset '" + webkitCharset +
|
||||
"' to a supported charset");
|
||||
}
|
||||
// Don't set the preference if we could not get the corresponding
|
||||
// charset.
|
||||
return undefined;
|
||||
});
|
||||
|
||||
#ifdef XP_WIN
|
||||
// Cookie-accept policy.
|
||||
// For the OS X version, see WebFoundationCookieBehavior.
|
||||
// Setting Safari Firefox
|
||||
// Always Accept 0 0
|
||||
// Accept from Originating 2 1
|
||||
// Never Accept 1 2
|
||||
this._set("WebKitCookieStorageAcceptPolicy",
|
||||
"network.cookie.cookieBehavior",
|
||||
function(webkitVal) webkitVal == 0 ? 0 : webkitVal == 1 ? 2 : 1);
|
||||
#endif
|
||||
|
||||
this._migrateFontSettings();
|
||||
this._migrateDownloadsFolder();
|
||||
}.bind(this), aCallback));
|
||||
},
|
||||
|
||||
/**
|
||||
* Attempts to migrates a preference from Safari. Returns whether the preference
|
||||
* has been migrated.
|
||||
* @param aSafariKey
|
||||
* The dictionary key for the preference of Safari.
|
||||
* @param aMozPref
|
||||
* The gecko/firefox preference to which aSafariKey should be migrated
|
||||
* @param [optional] aConvertFunction(aSafariValue)
|
||||
* a function that converts the safari-preference value to the
|
||||
* appropriate value for aMozPref. If it's not passed, then the
|
||||
* Safari value is set as is.
|
||||
* If aConvertFunction returns undefined, then aMozPref is not set
|
||||
* at all.
|
||||
* @return whether or not aMozPref was set.
|
||||
*/
|
||||
_set: function MPR_set(aSafariKey, aMozPref, aConvertFunction) {
|
||||
if (this._dict.has(aSafariKey)) {
|
||||
let safariVal = this._dict.get(aSafariKey);
|
||||
let mozVal = aConvertFunction !== undefined ?
|
||||
aConvertFunction(safariVal) : safariVal;
|
||||
switch (typeof(mozVal)) {
|
||||
case "string":
|
||||
Services.prefs.setCharPref(aMozPref, mozVal);
|
||||
break;
|
||||
case "number":
|
||||
Services.prefs.setIntPref(aMozPref, mozVal);
|
||||
break;
|
||||
case "boolean":
|
||||
Services.prefs.setBoolPref(aMozPref, mozVal);
|
||||
break;
|
||||
case "undefined":
|
||||
return false;
|
||||
default:
|
||||
throw new Error("Unexpected value type: " + typeof(mozVal));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
// Fonts settings are quite problematic for migration, for a couple of
|
||||
// reasons:
|
||||
// (a) Every font preference in Gecko is set for a particular language.
|
||||
// In Safari, each font preference applies to all languages.
|
||||
// (b) The current underlying implementation of nsIFontEnumerator cannot
|
||||
// really tell you anything about a font: no matter what language or type
|
||||
// you try to enumerate with EnumerateFonts, you get an array of all
|
||||
// fonts in the systems (This also breaks our fonts dialog).
|
||||
// (c) In Gecko, each langauge has a distinct serif and sans-serif font
|
||||
// preference. Safari has only one default font setting. It seems that
|
||||
// it checks if it's a serif or sans serif font, and when a site
|
||||
// explicitly asks to use serif/sans-serif font, it uses the default font
|
||||
// only if it applies to this type.
|
||||
// (d) The solution of guessing the lang-group out of the default charset (as
|
||||
// done in the old Safari migrator) can only work when:
|
||||
// (1) The default charset preference is set.
|
||||
// (2) It's not a unicode charset.
|
||||
// For now, we use the language implied by the system locale as the
|
||||
// lang-group. The only exception is minimal font size, which is an
|
||||
// accessibility preference in Safari (under the Advanced tab). If it is set,
|
||||
// we set it for all languages.
|
||||
// As for the font type of the default font (serif/sans-serif), the default
|
||||
// type for the given language is used (set in font.default.LANGGROUP).
|
||||
_migrateFontSettings: function MPR__migrateFontSettings() {
|
||||
// If "Never use font sizes smaller than [ ] is set", migrate it for all
|
||||
// languages.
|
||||
if (this._dict.has("WebKitMinimumFontSize")) {
|
||||
let minimumSize = this._dict.get("WebKitMinimumFontSize");
|
||||
if (typeof(minimumSize) == "number") {
|
||||
let prefs = Services.prefs.getChildList("font.minimum-size");
|
||||
for (let pref of prefs) {
|
||||
Services.prefs.setIntPref(pref, minimumSize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Cu.reportError("WebKitMinimumFontSize was set to an invalid value: " +
|
||||
minimumSize);
|
||||
}
|
||||
}
|
||||
|
||||
// In theory, the lang group could be "x-unicode". This will result
|
||||
// in setting the fonts for "Other Languages".
|
||||
let lang = this._getLocaleLangGroup();
|
||||
|
||||
let anySet = false;
|
||||
let fontType = Services.prefs.getCharPref("font.default." + lang);
|
||||
anySet |= this._set("WebKitFixedFont", "font.name.monospace." + lang);
|
||||
anySet |= this._set("WebKitDefaultFixedFontSize", "font.size.fixed." + lang);
|
||||
anySet |= this._set("WebKitStandardFont",
|
||||
"font.name." + fontType + "." + lang);
|
||||
anySet |= this._set("WebKitDefaultFontSize", "font.size.variable." + lang);
|
||||
|
||||
// If we set font settings for a particular language, we'll also set the
|
||||
// fonts dialog to open with the fonts settings for that langauge.
|
||||
if (anySet)
|
||||
Services.prefs.setCharPref("font.language.group", lang);
|
||||
},
|
||||
|
||||
// Get the language group for the system locale.
|
||||
_getLocaleLangGroup: function MPR__getLocaleLangGroup() {
|
||||
let locale = Services.locale.getLocaleComponentForUserAgent();
|
||||
|
||||
// See nsLanguageAtomService::GetLanguageGroup
|
||||
let localeLangGroup = "x-unicode";
|
||||
let bundle = Services.strings.createBundle(
|
||||
"resource://gre/res/langGroups.properties");
|
||||
try {
|
||||
localeLangGroup = bundle.GetStringFromName(locale);
|
||||
}
|
||||
catch(ex) {
|
||||
let hyphenAt = locale.indexOf("-");
|
||||
if (hyphenAt != -1) {
|
||||
try {
|
||||
localeLangGroup = bundle.GetStringFromName(locale.substr(0, hyphenAt));
|
||||
}
|
||||
catch(ex2) { }
|
||||
}
|
||||
}
|
||||
return localeLangGroup;
|
||||
},
|
||||
|
||||
_migrateDownloadsFolder: function MPR__migrateDownloadsFolder() {
|
||||
// Windows Safari uses DownloadPath while Mac uses DownloadsPath.
|
||||
// Check both for future compatibility.
|
||||
let key;
|
||||
if (this._dict.has("DownloadsPath"))
|
||||
key = "DownloadsPath";
|
||||
else if (this._dict.has("DownloadPath"))
|
||||
key = "DownloadPath";
|
||||
else
|
||||
return;
|
||||
|
||||
let downloadsFolder = FileUtils.File(this._dict.get(key));
|
||||
|
||||
// If the download folder is set to the Desktop or to ~/Downloads, set the
|
||||
// folderList pref appropriately so that "Desktop"/Downloads is shown with
|
||||
// pretty name in the preferences dialog.
|
||||
let folderListVal = 2;
|
||||
if (downloadsFolder.equals(FileUtils.getDir("Desk", []))) {
|
||||
folderListVal = 0;
|
||||
}
|
||||
else {
|
||||
let dnldMgr = Cc["@mozilla.org/download-manager;1"].
|
||||
getService(Ci.nsIDownloadManager);
|
||||
if (downloadsFolder.equals(dnldMgr.defaultDownloadsDirectory))
|
||||
folderListVal = 1;
|
||||
}
|
||||
Services.prefs.setIntPref("browser.download.folderList", folderListVal);
|
||||
Services.prefs.setComplexValue("browser.download.dir", Ci.nsILocalFile,
|
||||
downloadsFolder);
|
||||
}
|
||||
};
|
||||
|
||||
function SearchStrings(aMainPreferencesPropertyListInstance) {
|
||||
this._mainPreferencesPropertyList = aMainPreferencesPropertyListInstance;
|
||||
}
|
||||
SearchStrings.prototype = {
|
||||
type: MigrationUtils.resourceTypes.OTHERDATA,
|
||||
|
||||
migrate: function SS_migrate(aCallback) {
|
||||
this._mainPreferencesPropertyList.read(MigrationUtils.wrapMigrateFunction(
|
||||
function migrateSearchStrings(aDict) {
|
||||
if (!aDict)
|
||||
throw new Error("Could not get preferences dictionary");
|
||||
|
||||
if (aDict.has("RecentSearchStrings")) {
|
||||
let recentSearchStrings = aDict.get("RecentSearchStrings");
|
||||
if (recentSearchStrings && recentSearchStrings.length > 0) {
|
||||
let formHistory = Cc["@mozilla.org/satchel/form-history;1"].
|
||||
getService(Ci.nsIFormHistory2);
|
||||
for (let searchString of recentSearchStrings) {
|
||||
formHistory.addEntry("searchbar-history", searchString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.bind(this), aCallback));
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
// On OS X, the cookie-accept policy preference is stored in a separate
|
||||
// property list.
|
||||
// For the Windows version, check Preferences.migrate.
|
||||
function WebFoundationCookieBehavior(aWebFoundationFile) {
|
||||
this._file = aWebFoundationFile;
|
||||
}
|
||||
WebFoundationCookieBehavior.prototype = {
|
||||
type: MigrationUtils.resourceTypes.SETTINGS,
|
||||
|
||||
migrate: function WFPL_migrate(aCallback) {
|
||||
PropertyListUtils.read(this._file, MigrationUtils.wrapMigrateFunction(
|
||||
function migrateCookieBehavior(aDict) {
|
||||
if (!aDict)
|
||||
throw new Error("Could not read com.apple.WebFoundation.plist");
|
||||
|
||||
if (aDict.has("NSHTTPAcceptCookies")) {
|
||||
// Setting Safari Firefox
|
||||
// Always Accept always 0
|
||||
// Accept from Originating current page 1
|
||||
// Never Accept never 2
|
||||
let acceptCookies = aDict.get("NSHTTPAcceptCookies");
|
||||
let cookieValue = acceptCookies == "never" ? 2 :
|
||||
acceptCookies == "current page" ? 1 : 0;
|
||||
Services.prefs.setIntPref("network.cookie.cookieBehavior",
|
||||
cookieValue);
|
||||
}
|
||||
}.bind(this), aCallback));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
function SafariProfileMigrator() {
|
||||
}
|
||||
|
||||
SafariProfileMigrator.prototype = Object.create(MigratorPrototype);
|
||||
|
||||
SafariProfileMigrator.prototype.getResources = function SM_getResources() {
|
||||
let profileDir =
|
||||
#ifdef XP_MACOSX
|
||||
FileUtils.getDir("ULibDir", ["Safari"], false);
|
||||
#else
|
||||
FileUtils.getDir("AppData", ["Apple Computer", "Safari"], false);
|
||||
#endif
|
||||
if (!profileDir.exists())
|
||||
return null;
|
||||
|
||||
let resources = [];
|
||||
let pushProfileFileResource = function(aFileName, aConstructor) {
|
||||
let file = profileDir.clone();
|
||||
file.append(aFileName);
|
||||
if (file.exists())
|
||||
resources.push(new aConstructor(file));
|
||||
};
|
||||
|
||||
pushProfileFileResource("History.plist", History);
|
||||
pushProfileFileResource("Bookmarks.plist", Bookmarks);
|
||||
|
||||
// The Reading List feature was introduced at the same time in Windows and
|
||||
// Mac versions of Safari. Not surprisingly, they are stored in the same
|
||||
// format in both versions. Surpsingly, only on Windows there is a
|
||||
// separate property list for it. This isn't #ifdefed out on mac, because
|
||||
// Apple may fix this at some point.
|
||||
pushProfileFileResource("ReadingList.plist", Bookmarks);
|
||||
|
||||
let prefsDir =
|
||||
#ifdef XP_MACOSX
|
||||
FileUtils.getDir("UsrPrfs", [], false);
|
||||
#else
|
||||
FileUtils.getDir("AppData", ["Apple Computer", "Preferences"], false);
|
||||
#endif
|
||||
|
||||
let prefs = this.mainPreferencesPropertyList;
|
||||
if (prefs) {
|
||||
resources.push(new Preferences(prefs));
|
||||
resources.push(new SearchStrings(prefs));
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
// On OS X, the cookie-accept policy preference is stored in a separate
|
||||
// property list.
|
||||
let wfFile = FileUtils.getFile("UsrPrfs", ["com.apple.WebFoundation.plist"]);
|
||||
if (wfFile.exists())
|
||||
resources.push(new WebFoundationCookieBehavior(wfFile));
|
||||
#endif
|
||||
|
||||
return resources;
|
||||
};
|
||||
|
||||
Object.defineProperty(SafariProfileMigrator.prototype, "mainPreferencesPropertyList", {
|
||||
get: function get_mainPreferencesPropertyList() {
|
||||
if (this._mainPreferencesPropertyList === undefined) {
|
||||
let file =
|
||||
#ifdef XP_MACOSX
|
||||
FileUtils.getDir("UsrPrfs", [], false);
|
||||
#else
|
||||
FileUtils.getDir("AppData", ["Apple Computer", "Preferences"], false);
|
||||
#endif
|
||||
if (file.exists()) {
|
||||
file.append("com.apple.Safari.plist");
|
||||
if (file.exists()) {
|
||||
return this._mainPreferencesPropertyList =
|
||||
new MainPreferencesPropertyList(file);
|
||||
}
|
||||
}
|
||||
return this._mainPreferencesPropertyList = null;
|
||||
}
|
||||
return this._mainPreferencesPropertyList;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(SafariProfileMigrator.prototype, "sourceHomePageURL", {
|
||||
get: function get_sourceHomePageURL() {
|
||||
if (this.mainPreferencesPropertyList) {
|
||||
let dict = this.mainPreferencesPropertyList._readSync();
|
||||
if (dict.has("HomePage"))
|
||||
return dict.get("HomePage");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
SafariProfileMigrator.prototype.classDescription = "Safari Profile Migrator";
|
||||
SafariProfileMigrator.prototype.contractID = "@mozilla.org/profile/migrator;1?app=browser&type=safari";
|
||||
SafariProfileMigrator.prototype.classID = Components.ID("{4b609ecf-60b2-4655-9df4-dc149e474da1}");
|
||||
|
||||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([SafariProfileMigrator]);
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,134 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is The Browser Profile Migrator.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Ben Goodger.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@bengoodger.com>
|
||||
* Asaf Romano <mozilla.mano@sent.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef safariprofilemigrator___h___
|
||||
#define safariprofilemigrator___h___
|
||||
|
||||
#include "nsIBrowserProfileMigrator.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsINavHistoryService.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
class nsIPrefBranch;
|
||||
class nsINavBookmarksService;
|
||||
class nsIRDFResource;
|
||||
class nsIRDFDataSource;
|
||||
|
||||
class nsSafariProfileMigrator : public nsIBrowserProfileMigrator,
|
||||
public nsINavHistoryBatchCallback
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIBROWSERPROFILEMIGRATOR
|
||||
NS_DECL_NSINAVHISTORYBATCHCALLBACK
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsSafariProfileMigrator();
|
||||
virtual ~nsSafariProfileMigrator();
|
||||
|
||||
typedef enum { STRING, INT, BOOL } PrefType;
|
||||
|
||||
typedef nsresult(*prefConverter)(void*, nsIPrefBranch*);
|
||||
|
||||
struct PrefTransform {
|
||||
CFStringRef keyName;
|
||||
PrefType type;
|
||||
const char* targetPrefName;
|
||||
prefConverter prefSetterFunc;
|
||||
bool prefHasValue;
|
||||
union {
|
||||
PRInt32 intValue;
|
||||
bool boolValue;
|
||||
char* stringValue;
|
||||
};
|
||||
};
|
||||
|
||||
static nsresult SetBool(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetBoolInverted(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetString(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetInt(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetDefaultEncoding(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetDownloadFolder(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetDownloadHandlers(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetDownloadRetention(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetDisplayImages(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetFontName(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static nsresult SetFontSize(void* aTransform, nsIPrefBranch* aBranch);
|
||||
static void CleanResource(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource);
|
||||
|
||||
protected:
|
||||
nsresult CopyPreferences(bool aReplace);
|
||||
nsresult CopyCookies(bool aReplace);
|
||||
/**
|
||||
* Migrate history to Places.
|
||||
* This will end up calling CopyHistoryBatched helper, that provides batch
|
||||
* support. Batching allows for better performances and integrity.
|
||||
*
|
||||
* @param aReplace
|
||||
* Indicates if we should replace current history or append to it.
|
||||
*/
|
||||
nsresult CopyHistory(bool aReplace);
|
||||
nsresult CopyHistoryBatched(bool aReplace);
|
||||
/**
|
||||
* Migrate bookmarks to Places.
|
||||
* This will end up calling CopyBookmarksBatched helper, that provides batch
|
||||
* support. Batching allows for better performances and integrity.
|
||||
*
|
||||
* @param aReplace
|
||||
* Indicates if we should replace current bookmarks or append to them.
|
||||
* When appending we will usually default to bookmarks menu.
|
||||
*/
|
||||
nsresult CopyBookmarks(bool aReplace);
|
||||
nsresult CopyBookmarksBatched(bool aReplace);
|
||||
nsresult ParseBookmarksFolder(CFArrayRef aChildren,
|
||||
PRInt64 aParentFolder,
|
||||
nsINavBookmarksService * aBookmarksService,
|
||||
bool aIsAtRootLevel);
|
||||
nsresult CopyFormData(bool aReplace);
|
||||
nsresult CopyOtherData(bool aReplace);
|
||||
|
||||
nsresult ProfileHasContentStyleSheet(bool *outExists);
|
||||
nsresult GetSafariUserStyleSheet(nsILocalFile** aResult);
|
||||
|
||||
private:
|
||||
bool HasFormDataToImport();
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -166,14 +166,26 @@ PlacesViewBase.prototype = {
|
|||
window.content.focus();
|
||||
},
|
||||
|
||||
_cleanPopup: function PVB_cleanPopup(aPopup) {
|
||||
_cleanPopup: function PVB_cleanPopup(aPopup, aDelay) {
|
||||
// Remove Places nodes from the popup.
|
||||
let child = aPopup._startMarker;
|
||||
while (child.nextSibling != aPopup._endMarker) {
|
||||
if (child.nextSibling._placesNode)
|
||||
aPopup.removeChild(child.nextSibling);
|
||||
else
|
||||
let sibling = child.nextSibling;
|
||||
if (sibling._placesNode && !aDelay) {
|
||||
aPopup.removeChild(sibling);
|
||||
}
|
||||
else if (sibling._placesNode && aDelay) {
|
||||
// HACK (bug 733419): the popups originating from the OS X native
|
||||
// menubar don't live-update while open, thus we don't clean it
|
||||
// until the next popupshowing, to avoid zombie menuitems.
|
||||
if (!aPopup._delayedRemovals)
|
||||
aPopup._delayedRemovals = [];
|
||||
aPopup._delayedRemovals.push(sibling);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
else {
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -395,7 +407,8 @@ PlacesViewBase.prototype = {
|
|||
}
|
||||
else {
|
||||
// The livemark has finished loading.
|
||||
aPopup.removeChild(aPopup._statusMenuitem);
|
||||
if (aPopup._statusMenuitem.parentNode == aPopup)
|
||||
aPopup.removeChild(aPopup._statusMenuitem);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -671,7 +684,9 @@ PlacesViewBase.prototype = {
|
|||
_populateLivemarkPopup: function PVB__populateLivemarkPopup(aPopup)
|
||||
{
|
||||
this._setLivemarkSiteURIMenuItem(aPopup);
|
||||
this._setLivemarkStatusMenuItem(aPopup, Ci.mozILivemark.STATUS_LOADING);
|
||||
// Show the loading status only if there are no entries yet.
|
||||
if (aPopup._startMarker.nextSibling == aPopup._endMarker)
|
||||
this._setLivemarkStatusMenuItem(aPopup, Ci.mozILivemark.STATUS_LOADING);
|
||||
|
||||
PlacesUtils.livemarks.getLivemark({ id: aPopup._placesNode.itemId },
|
||||
(function (aStatus, aLivemark) {
|
||||
|
@ -679,8 +694,10 @@ PlacesViewBase.prototype = {
|
|||
if (!Components.isSuccessCode(aStatus) || !placesNode.containerOpen)
|
||||
return;
|
||||
|
||||
this._setLivemarkStatusMenuItem(aPopup, aLivemark.status);
|
||||
this._cleanPopup(aPopup);
|
||||
if (aLivemark.status != Ci.mozILivemark.STATUS_LOADING)
|
||||
this._setLivemarkStatusMenuItem(aPopup, aLivemark.status);
|
||||
this._cleanPopup(aPopup,
|
||||
this._nativeView && aPopup.parentNode.hasAttribute("open"));
|
||||
|
||||
let children = aLivemark.getNodesForContainer(placesNode);
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
|
@ -835,6 +852,13 @@ PlacesViewBase.prototype = {
|
|||
|
||||
this._ensureMarkers(popup);
|
||||
|
||||
// Remove any delayed element, see _cleanPopup for details.
|
||||
if ("_delayedRemovals" in popup) {
|
||||
while (popup._delayedRemovals.length > 0) {
|
||||
popup.removeChild(popup._delayedRemovals.shift());
|
||||
}
|
||||
}
|
||||
|
||||
if (popup._placesNode && PlacesUIUtils.getViewForNode(popup) == this) {
|
||||
if (!popup._placesNode.containerOpen)
|
||||
popup._placesNode.containerOpen = true;
|
||||
|
@ -1738,8 +1762,12 @@ function PlacesMenu(aPopupShowingEvent, aPlace) {
|
|||
this._addEventListeners(window, ["unload"], false);
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
if (this._viewElt.parentNode.localName == "menubar") {
|
||||
this._nativeView = true;
|
||||
// Must walk up to support views in sub-menus, like Bookmarks Toolbar menu.
|
||||
for (let elt = this._viewElt.parentNode; elt; elt = elt.parentNode) {
|
||||
if (elt.localName == "menubar") {
|
||||
this._nativeView = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ importedSearchURLsFolder=Keyword Searches (From %S)
|
|||
importedSearchURLsTitle=Search on %S
|
||||
importedSearchUrlDesc=Type "%S <search query>" in the Location Bar to perform a search on %S.
|
||||
|
||||
importedSafariBookmarks=From Safari
|
||||
importedSafariReadingList=Reading List (From Safari)
|
||||
|
||||
# Import Sources
|
||||
1_ie=Internet Options
|
||||
|
|
|
@ -2099,9 +2099,9 @@ nsRange::CloneRange(nsIDOMRange** aReturn)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRange::InsertNode(nsIDOMNode* aN)
|
||||
nsRange::InsertNode(nsIDOMNode* aNode)
|
||||
{
|
||||
VALIDATE_ACCESS(aN);
|
||||
VALIDATE_ACCESS(aNode);
|
||||
|
||||
nsresult res;
|
||||
PRInt32 tStartOffset;
|
||||
|
@ -2109,51 +2109,63 @@ nsRange::InsertNode(nsIDOMNode* aN)
|
|||
|
||||
nsCOMPtr<nsIDOMNode> tStartContainer;
|
||||
res = this->GetStartContainer(getter_AddRefs(tStartContainer));
|
||||
if(NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
// This is the node we'll be inserting before, and its parent
|
||||
nsCOMPtr<nsIDOMNode> referenceNode;
|
||||
nsCOMPtr<nsIDOMNode> referenceParentNode = tStartContainer;
|
||||
|
||||
nsCOMPtr<nsIDOMText> startTextNode(do_QueryInterface(tStartContainer));
|
||||
if (startTextNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> tSCParentNode;
|
||||
res = tStartContainer->GetParentNode(getter_AddRefs(tSCParentNode));
|
||||
if(NS_FAILED(res)) return res;
|
||||
NS_ENSURE_TRUE(tSCParentNode, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
||||
|
||||
PRInt32 tEndOffset;
|
||||
GetEndOffset(&tEndOffset);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> tEndContainer;
|
||||
res = this->GetEndContainer(getter_AddRefs(tEndContainer));
|
||||
if(NS_FAILED(res)) return res;
|
||||
nsCOMPtr<nsIDOMNodeList> tChildList;
|
||||
if (startTextNode) {
|
||||
res = tStartContainer->GetParentNode(getter_AddRefs(referenceParentNode));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
NS_ENSURE_TRUE(referenceParentNode, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
|
||||
|
||||
nsCOMPtr<nsIDOMText> secondPart;
|
||||
res = startTextNode->SplitText(tStartOffset, getter_AddRefs(secondPart));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> tResultNode;
|
||||
res = tSCParentNode->InsertBefore(aN, secondPart, getter_AddRefs(tResultNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
referenceNode = secondPart;
|
||||
} else {
|
||||
res = tStartContainer->GetChildNodes(getter_AddRefs(tChildList));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
if (tEndContainer == tStartContainer && tEndOffset != tStartOffset)
|
||||
res = SetEnd(secondPart, tEndOffset - tStartOffset);
|
||||
// find the insertion point in the DOM and insert the Node
|
||||
res = tChildList->Item(tStartOffset, getter_AddRefs(referenceNode));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
// We might need to update the end to include the new node (bug 433662)
|
||||
PRInt32 newOffset;
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList>tChildList;
|
||||
res = tStartContainer->GetChildNodes(getter_AddRefs(tChildList));
|
||||
if(NS_FAILED(res)) return res;
|
||||
PRUint32 tChildListLength;
|
||||
res = tChildList->GetLength(&tChildListLength);
|
||||
if(NS_FAILED(res)) return res;
|
||||
if (Collapsed()) {
|
||||
if (referenceNode) {
|
||||
newOffset = IndexOf(referenceNode);
|
||||
} else {
|
||||
PRUint32 length;
|
||||
res = tChildList->GetLength(&length);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
newOffset = length;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||
NS_ENSURE_STATE(node);
|
||||
if (node->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
|
||||
newOffset += node->GetChildCount();
|
||||
} else {
|
||||
newOffset++;
|
||||
}
|
||||
}
|
||||
|
||||
// find the insertion point in the DOM and insert the Node
|
||||
nsCOMPtr<nsIDOMNode>tChildNode;
|
||||
res = tChildList->Item(tStartOffset, getter_AddRefs(tChildNode));
|
||||
if(NS_FAILED(res)) return res;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> tResultNode;
|
||||
return tStartContainer->InsertBefore(aN, tChildNode, getter_AddRefs(tResultNode));
|
||||
res = referenceParentNode->InsertBefore(aNode, referenceNode, getter_AddRefs(tResultNode));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
if (Collapsed()) {
|
||||
return SetEnd(referenceParentNode, newOffset);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -577,6 +577,7 @@ _TEST_FILES2 = \
|
|||
file_bug650386_report.sjs \
|
||||
test_bug719533.html \
|
||||
test_bug737087.html \
|
||||
test_bug433662.html \
|
||||
$(NULL)
|
||||
|
||||
_CHROME_FILES = \
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=433662
|
||||
-->
|
||||
<title>Test for Bug 433662</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=433662">Mozilla Bug 433662</a>
|
||||
<script>
|
||||
|
||||
/** Test for Bug 433662 **/
|
||||
var range = document.createRange();
|
||||
range.setStart(document.body, 0);
|
||||
range.insertNode(document.createComment("abc"));
|
||||
is(document.body.firstChild.nodeType, Node.COMMENT_NODE,
|
||||
"Comment must be inserted (start of node)");
|
||||
is(document.body.firstChild.nodeValue, "abc",
|
||||
"Comment must have right contents (start of node)");
|
||||
is(range.endOffset, 1,
|
||||
"insertNode() needs to include the newly-added node (start of node)");
|
||||
|
||||
range.setStart(document.body, document.body.childNodes.length);
|
||||
range.insertNode(document.createComment("def"));
|
||||
is(document.body.lastChild.nodeType, Node.COMMENT_NODE,
|
||||
"Comment must be inserted (end of node)");
|
||||
is(document.body.lastChild.nodeValue, "def",
|
||||
"Comment must have right contents (end of node)");
|
||||
is(range.endOffset, document.body.childNodes.length,
|
||||
"insertNode() needs to include the newly-added node (end of node)");
|
||||
|
||||
</script>
|
|
@ -77,12 +77,12 @@ function testInsertNode(node) {
|
|||
p = create('g<b>h</b>');
|
||||
select(p.childNodes[0],0,p.childNodes[0],0);
|
||||
insertClone(node);
|
||||
check(p.childNodes[0],0,p.childNodes[0],0);
|
||||
check(p.childNodes[0],0,p,2);
|
||||
|
||||
p = create('i<b>j</b>');
|
||||
select(p.childNodes[0],1,p.childNodes[0],1);
|
||||
insertClone(node);
|
||||
check(p.childNodes[0],1,p.childNodes[0],1);
|
||||
check(p.childNodes[0],1,p,2);
|
||||
|
||||
p = create('k<b>l</b>');
|
||||
select(p.childNodes[0],0,p.childNodes[1].childNodes[0],0);
|
||||
|
@ -137,12 +137,12 @@ function testInsertNode(node) {
|
|||
p = create('<i>O</i><b>P</b>');
|
||||
select(p,1,p,1);
|
||||
insertClone(node);
|
||||
check(p,1,p,1);
|
||||
check(p,1,p,2);
|
||||
|
||||
p = create('<i>Q</i><b>R</b>');
|
||||
select(p,2,p,2);
|
||||
insertClone(node);
|
||||
check(p,2,p,2);
|
||||
check(p,2,p,3);
|
||||
|
||||
p = create('<i>S</i><b>T</b>');
|
||||
select(p,1,p,1);
|
||||
|
|
|
@ -84,6 +84,7 @@ CPPSRCS += \
|
|||
GonkHal.cpp \
|
||||
Power.cpp \
|
||||
GonkSensor.cpp \
|
||||
UeventPoller.cpp \
|
||||
$(NULL)
|
||||
else ifeq (Linux,$(OS_TARGET))
|
||||
CPPSRCS += \
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* 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/. */
|
||||
|
||||
#include "base/message_loop.h"
|
||||
#include "hardware_legacy/uevent.h"
|
||||
#include "Hal.h"
|
||||
#include "HalImpl.h"
|
||||
|
@ -19,9 +20,11 @@
|
|||
#include "nsIThread.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "hardware/lights.h"
|
||||
#include "hardware/hardware.h"
|
||||
#include "hardware_legacy/vibrator.h"
|
||||
#include "UeventPoller.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -196,70 +199,74 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class UEventWatcher : public nsRunnable {
|
||||
} // anonymous namespace
|
||||
|
||||
class BatteryObserver : public IUeventObserver,
|
||||
public RefCounted<BatteryObserver>
|
||||
{
|
||||
public:
|
||||
UEventWatcher()
|
||||
: mUpdater(new BatteryUpdater())
|
||||
, mRunning(false)
|
||||
BatteryObserver()
|
||||
:mUpdater(new BatteryUpdater())
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
virtual void Notify(const NetlinkEvent &aEvent)
|
||||
{
|
||||
while (mRunning) {
|
||||
char buf[1024];
|
||||
int count = uevent_next_event(buf, sizeof(buf) - 1);
|
||||
if (!count) {
|
||||
NS_WARNING("uevent_next_event() returned 0!");
|
||||
continue;
|
||||
}
|
||||
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
if (strstr(buf, "battery"))
|
||||
NS_DispatchToMainThread(mUpdater);
|
||||
// this will run on IO thread
|
||||
NetlinkEvent *event = const_cast<NetlinkEvent*>(&aEvent);
|
||||
const char *subsystem = event->getSubsystem();
|
||||
// e.g. DEVPATH=/devices/platform/sec-battery/power_supply/battery
|
||||
const char *devpath = event->findParam("DEVPATH");
|
||||
if (strcmp(subsystem, "power_supply") == 0 &&
|
||||
strstr(devpath, "battery")) {
|
||||
// aEvent will be valid only in this method.
|
||||
NS_DispatchToMainThread(mUpdater);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool mRunning;
|
||||
|
||||
private:
|
||||
nsRefPtr<BatteryUpdater> mUpdater;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
// sBatteryObserver is owned by the IO thread. Only the IO thread may
|
||||
// create or destroy it.
|
||||
static BatteryObserver *sBatteryObserver = NULL;
|
||||
|
||||
static bool sUEventInitialized = false;
|
||||
static UEventWatcher *sWatcher = NULL;
|
||||
static nsIThread *sWatcherThread = NULL;
|
||||
static void
|
||||
RegisterBatteryObserverIOThread()
|
||||
{
|
||||
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
||||
MOZ_ASSERT(!sBatteryObserver);
|
||||
|
||||
sBatteryObserver = new BatteryObserver();
|
||||
RegisterUeventListener(sBatteryObserver);
|
||||
}
|
||||
|
||||
void
|
||||
EnableBatteryNotifications()
|
||||
{
|
||||
if (!sUEventInitialized)
|
||||
sUEventInitialized = uevent_init();
|
||||
if (!sUEventInitialized) {
|
||||
NS_WARNING("uevent_init() failed!");
|
||||
return;
|
||||
}
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
NewRunnableFunction(RegisterBatteryObserverIOThread));
|
||||
}
|
||||
|
||||
if (!sWatcher)
|
||||
sWatcher = new UEventWatcher();
|
||||
NS_ADDREF(sWatcher);
|
||||
static void
|
||||
UnregisterBatteryObserverIOThread()
|
||||
{
|
||||
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
||||
MOZ_ASSERT(sBatteryObserver);
|
||||
|
||||
sWatcher->mRunning = true;
|
||||
nsresult rv = NS_NewThread(&sWatcherThread, sWatcher);
|
||||
if (NS_FAILED(rv))
|
||||
NS_WARNING("Failed to get new thread for uevent watching");
|
||||
UnregisterUeventListener(sBatteryObserver);
|
||||
delete sBatteryObserver;
|
||||
sBatteryObserver = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
DisableBatteryNotifications()
|
||||
{
|
||||
sWatcher->mRunning = false;
|
||||
sWatcherThread->Shutdown();
|
||||
NS_IF_RELEASE(sWatcherThread);
|
||||
delete sWatcher;
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
NewRunnableFunction(UnregisterBatteryObserverIOThread));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -0,0 +1,198 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "base/message_loop.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
#include "UeventPoller.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
static void ShutdownUevent();
|
||||
|
||||
class NetlinkPoller : public MessageLoopForIO::Watcher
|
||||
{
|
||||
public:
|
||||
NetlinkPoller() : mSocket(-1),
|
||||
mIOLoop(MessageLoopForIO::current())
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~NetlinkPoller() {}
|
||||
|
||||
bool OpenSocket();
|
||||
|
||||
virtual void OnFileCanReadWithoutBlocking(int fd);
|
||||
|
||||
// no writing to the netlink socket
|
||||
virtual void OnFileCanWriteWithoutBlocking(int fd)
|
||||
{
|
||||
MOZ_NOT_REACHED("Must not write to netlink socket");
|
||||
}
|
||||
|
||||
MessageLoopForIO *GetIOLoop () const { return mIOLoop; }
|
||||
void RegisterObserver(IUeventObserver *aObserver)
|
||||
{
|
||||
mUeventObserverList.AddObserver(aObserver);
|
||||
}
|
||||
|
||||
void UnregisterObserver(IUeventObserver *aObserver)
|
||||
{
|
||||
mUeventObserverList.RemoveObserver(aObserver);
|
||||
if (mUeventObserverList.Length() == 0)
|
||||
ShutdownUevent(); // this will destroy self
|
||||
}
|
||||
|
||||
private:
|
||||
ScopedClose mSocket;
|
||||
MessageLoopForIO* mIOLoop;
|
||||
MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
|
||||
|
||||
NetlinkEvent mNetlinkEvent;
|
||||
const static int kBuffsize = 64 * 1024;
|
||||
uint8_t mBuffer [kBuffsize];
|
||||
|
||||
typedef ObserverList<NetlinkEvent> UeventObserverList;
|
||||
UeventObserverList mUeventObserverList;
|
||||
};
|
||||
|
||||
bool
|
||||
NetlinkPoller::OpenSocket()
|
||||
{
|
||||
mSocket.rwget() = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
|
||||
if (mSocket.get() < 0)
|
||||
return false;
|
||||
|
||||
int sz = kBuffsize;
|
||||
|
||||
if (setsockopt(mSocket.get(), SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0)
|
||||
return false;
|
||||
|
||||
// add FD_CLOEXEC flag
|
||||
int flags = fcntl(mSocket.get(), F_GETFD);
|
||||
if (flags == -1) {
|
||||
return false;
|
||||
}
|
||||
flags |= FD_CLOEXEC;
|
||||
if (fcntl(mSocket.get(), F_SETFD, flags) == -1)
|
||||
return false;
|
||||
|
||||
// set non-blocking
|
||||
if (fcntl(mSocket.get(), F_SETFL, O_NONBLOCK) == -1)
|
||||
return false;
|
||||
|
||||
struct sockaddr_nl saddr;
|
||||
bzero(&saddr, sizeof(saddr));
|
||||
saddr.nl_family = AF_NETLINK;
|
||||
saddr.nl_groups = 1;
|
||||
saddr.nl_pid = getpid();
|
||||
|
||||
if (bind(mSocket.get(), (struct sockaddr *)&saddr, sizeof(saddr)) == -1)
|
||||
return false;
|
||||
|
||||
if (!mIOLoop->WatchFileDescriptor(mSocket.get(),
|
||||
true,
|
||||
MessageLoopForIO::WATCH_READ,
|
||||
&mReadWatcher,
|
||||
this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static nsAutoPtr<NetlinkPoller> sPoller;
|
||||
|
||||
class UeventInitTask : public Task
|
||||
{
|
||||
virtual void Run()
|
||||
{
|
||||
if (!sPoller) {
|
||||
return;
|
||||
}
|
||||
if (sPoller->OpenSocket()) {
|
||||
return;
|
||||
}
|
||||
sPoller->GetIOLoop()->PostDelayedTask(FROM_HERE, new UeventInitTask(), 1000);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
NetlinkPoller::OnFileCanReadWithoutBlocking(int fd)
|
||||
{
|
||||
MOZ_ASSERT(fd == mSocket.mFd);
|
||||
while (true) {
|
||||
int ret = read(fd, mBuffer, kBuffsize);
|
||||
if (ret == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
return;
|
||||
}
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (ret <= 0) {
|
||||
// fatal error on netlink socket which should not happen
|
||||
_exit(1);
|
||||
}
|
||||
mNetlinkEvent.decode(reinterpret_cast<char*>(mBuffer), ret);
|
||||
mUeventObserverList.Broadcast(mNetlinkEvent);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
InitializeUevent()
|
||||
{
|
||||
MOZ_ASSERT(!sPoller);
|
||||
sPoller = new NetlinkPoller();
|
||||
sPoller->GetIOLoop()->PostTask(FROM_HERE, new UeventInitTask());
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
ShutdownUevent()
|
||||
{
|
||||
sPoller = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
RegisterUeventListener(IUeventObserver *aObserver)
|
||||
{
|
||||
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
||||
|
||||
if (!sPoller)
|
||||
InitializeUevent();
|
||||
sPoller->RegisterObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterUeventListener(IUeventObserver *aObserver)
|
||||
{
|
||||
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
||||
|
||||
sPoller->UnregisterObserver(aObserver);
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // mozilla
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef _mozilla_uevent_poller_h_
|
||||
#define _mozilla_uevent_poller_h_
|
||||
|
||||
#include <sysutils/NetlinkEvent.h>
|
||||
#include "mozilla/Observer.h"
|
||||
|
||||
class NetlinkEvent;
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
typedef mozilla::Observer<NetlinkEvent> IUeventObserver;
|
||||
|
||||
/**
|
||||
* Register for uevent notification. Note that the method should run on the
|
||||
* <b> IO Thread </b>
|
||||
* @aObserver the observer to be added. The observer's Notify() is only called
|
||||
* on the <b> IO Thread </b>
|
||||
*/
|
||||
void RegisterUeventListener(IUeventObserver *aObserver);
|
||||
|
||||
/**
|
||||
* Unregister for uevent notification. Note that the method should run on the
|
||||
* <b> IO Thread </b>
|
||||
* @aObserver the observer to be removed
|
||||
*/
|
||||
void UnregisterUeventListener(IUeventObserver *aObserver);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -158,9 +158,20 @@ PrintBacktrace()
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \
|
||||
do \
|
||||
{ \
|
||||
if (++OOM_counter > OOM_maxAllocations) { \
|
||||
JS_OOM_EMIT_BACKTRACE();\
|
||||
js_ReportOutOfMemory(cx);\
|
||||
return NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
# else
|
||||
# define JS_OOM_POSSIBLY_FAIL() do {} while(0)
|
||||
# endif
|
||||
# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0)
|
||||
# endif /* DEBUG */
|
||||
|
||||
/*
|
||||
* SpiderMonkey code should not be calling these allocation functions directly.
|
||||
|
|
|
@ -440,7 +440,7 @@ NewGCThing(JSContext *cx, js::gc::AllocKind kind, size_t thingSize)
|
|||
JS_ASSERT(!cx->runtime->noGCOrAllocationCheck);
|
||||
|
||||
/* For testing out of memory conditions */
|
||||
JS_OOM_POSSIBLY_FAIL();
|
||||
JS_OOM_POSSIBLY_FAIL_REPORT(cx);
|
||||
|
||||
#ifdef JS_GC_ZEAL
|
||||
if (cx->runtime->needZealousGC())
|
||||
|
|
|
@ -90,7 +90,7 @@ pref("ui.scrollbarsCanOverlapContent", 1);
|
|||
|
||||
/* cache prefs */
|
||||
pref("browser.cache.disk.enable", true);
|
||||
pref("browser.cache.disk.capacity", 10240); // kilobytes
|
||||
pref("browser.cache.disk.capacity", 20480); // kilobytes
|
||||
pref("browser.cache.disk.smart_size.enabled", false);
|
||||
pref("browser.cache.disk.smart_size.first_run", false);
|
||||
|
||||
|
@ -377,6 +377,10 @@ pref("gfx.displayport.strategy_fm.danger_y", -1); // danger zone on y-axis when
|
|||
pref("gfx.displayport.strategy_vb.multiplier", -1); // displayport dimension multiplier
|
||||
pref("gfx.displayport.strategy_vb.threshold", -1); // velocity threshold in pixels/frame when multiplied by screen DPI
|
||||
pref("gfx.displayport.strategy_vb.reverse_buffer", -1); // fraction of buffer to keep in reverse direction from scroll
|
||||
pref("gfx.displayport.strategy_vb.danger_x_base", -1); // danger zone on x-axis when multiplied by viewport width
|
||||
pref("gfx.displayport.strategy_vb.danger_y_base", -1); // danger zone on y-axis when multiplied by viewport height
|
||||
pref("gfx.displayport.strategy_vb.danger_x_incr", -1); // additional danger zone on x-axis when multiplied by viewport width and velocity
|
||||
pref("gfx.displayport.strategy_vb.danger_y_incr", -1); // additional danger zone on y-axis when multiplied by viewport height and velocity
|
||||
#endif
|
||||
|
||||
// don't allow JS to move and resize existing windows
|
||||
|
|
|
@ -24,6 +24,10 @@ final class DisplayPortCalculator {
|
|||
private static final String PREF_DISPLAYPORT_VB_MULTIPLIER = "gfx.displayport.strategy_vb.multiplier";
|
||||
private static final String PREF_DISPLAYPORT_VB_VELOCITY_THRESHOLD = "gfx.displayport.strategy_vb.threshold";
|
||||
private static final String PREF_DISPLAYPORT_VB_REVERSE_BUFFER = "gfx.displayport.strategy_vb.reverse_buffer";
|
||||
private static final String PREF_DISPLAYPORT_VB_DANGER_X_BASE = "gfx.displayport.strategy_vb.danger_x_base";
|
||||
private static final String PREF_DISPLAYPORT_VB_DANGER_Y_BASE = "gfx.displayport.strategy_vb.danger_y_base";
|
||||
private static final String PREF_DISPLAYPORT_VB_DANGER_X_INCR = "gfx.displayport.strategy_vb.danger_x_incr";
|
||||
private static final String PREF_DISPLAYPORT_VB_DANGER_Y_INCR = "gfx.displayport.strategy_vb.danger_y_incr";
|
||||
|
||||
private static DisplayPortStrategy sStrategy = new VelocityBiasStrategy(null);
|
||||
|
||||
|
@ -46,6 +50,10 @@ final class DisplayPortCalculator {
|
|||
prefs.put(PREF_DISPLAYPORT_VB_MULTIPLIER);
|
||||
prefs.put(PREF_DISPLAYPORT_VB_VELOCITY_THRESHOLD);
|
||||
prefs.put(PREF_DISPLAYPORT_VB_REVERSE_BUFFER);
|
||||
prefs.put(PREF_DISPLAYPORT_VB_DANGER_X_BASE);
|
||||
prefs.put(PREF_DISPLAYPORT_VB_DANGER_Y_BASE);
|
||||
prefs.put(PREF_DISPLAYPORT_VB_DANGER_X_INCR);
|
||||
prefs.put(PREF_DISPLAYPORT_VB_DANGER_Y_INCR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,11 +288,55 @@ final class DisplayPortCalculator {
|
|||
private final float VELOCITY_THRESHOLD;
|
||||
// How much of the buffer to keep in the reverse direction of the velocity
|
||||
private final float REVERSE_BUFFER;
|
||||
// If the visible rect is within the danger zone we start redrawing to minimize
|
||||
// checkerboarding. the danger zone amount is a linear function of the form:
|
||||
// viewportsize * (base + velocity * incr)
|
||||
// where base and incr are configurable values.
|
||||
private final float DANGER_ZONE_BASE_X_MULTIPLIER;
|
||||
private final float DANGER_ZONE_BASE_Y_MULTIPLIER;
|
||||
private final float DANGER_ZONE_INCR_X_MULTIPLIER;
|
||||
private final float DANGER_ZONE_INCR_Y_MULTIPLIER;
|
||||
|
||||
VelocityBiasStrategy(Map<String, Integer> prefs) {
|
||||
SIZE_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_MULTIPLIER, 1500);
|
||||
VELOCITY_THRESHOLD = GeckoAppShell.getDpi() * getFloatPref(prefs, PREF_DISPLAYPORT_VB_VELOCITY_THRESHOLD, 32);
|
||||
REVERSE_BUFFER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_REVERSE_BUFFER, 200);
|
||||
DANGER_ZONE_BASE_X_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_DANGER_X_BASE, 1000);
|
||||
DANGER_ZONE_BASE_Y_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_DANGER_Y_BASE, 1000);
|
||||
DANGER_ZONE_INCR_X_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_DANGER_X_INCR, 0);
|
||||
DANGER_ZONE_INCR_Y_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_DANGER_Y_INCR, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the given amounts into margins based on the VELOCITY_THRESHOLD and REVERSE_BUFFER values.
|
||||
* If the velocity is above the VELOCITY_THRESHOLD on an axis, split the amount into REVERSE_BUFFER
|
||||
* and 1.0 - REVERSE_BUFFER fractions. The REVERSE_BUFFER fraction is set as the margin in the
|
||||
* direction opposite to the velocity, and the remaining fraction is set as the margin in the direction
|
||||
* of the velocity. If the velocity is lower than VELOCITY_THRESHOLD, split the amount evenly into the
|
||||
* two margins on that axis.
|
||||
*/
|
||||
private RectF velocityBiasedMargins(float xAmount, float yAmount, PointF velocity) {
|
||||
RectF margins = new RectF();
|
||||
|
||||
if (velocity.x > VELOCITY_THRESHOLD) {
|
||||
margins.left = xAmount * REVERSE_BUFFER;
|
||||
} else if (velocity.x < -VELOCITY_THRESHOLD) {
|
||||
margins.left = xAmount * (1.0f - REVERSE_BUFFER);
|
||||
} else {
|
||||
margins.left = xAmount / 2.0f;
|
||||
}
|
||||
margins.right = xAmount - margins.left;
|
||||
|
||||
if (velocity.y > VELOCITY_THRESHOLD) {
|
||||
margins.top = yAmount * REVERSE_BUFFER;
|
||||
} else if (velocity.y < -VELOCITY_THRESHOLD) {
|
||||
margins.top = yAmount * (1.0f - REVERSE_BUFFER);
|
||||
} else {
|
||||
margins.top = yAmount / 2.0f;
|
||||
}
|
||||
margins.bottom = yAmount - margins.top;
|
||||
|
||||
return margins;
|
||||
}
|
||||
|
||||
public DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity) {
|
||||
|
@ -306,29 +358,9 @@ final class DisplayPortCalculator {
|
|||
float horizontalBuffer = displayPortWidth - metrics.getWidth();
|
||||
float verticalBuffer = displayPortHeight - metrics.getHeight();
|
||||
|
||||
// if we're panning above the VELOCITY_THRESHOLD on an axis, apply the margin so that it
|
||||
// is entirely in the direction of panning. Otherwise, split the margin evenly on both sides of
|
||||
// the display port.
|
||||
RectF margins = new RectF();
|
||||
if (velocity.x > VELOCITY_THRESHOLD) {
|
||||
margins.left = horizontalBuffer * REVERSE_BUFFER;
|
||||
} else if (velocity.x < -VELOCITY_THRESHOLD) {
|
||||
margins.left = horizontalBuffer * (1.0f - REVERSE_BUFFER);
|
||||
} else {
|
||||
margins.left = horizontalBuffer / 2.0f;
|
||||
}
|
||||
margins.right = horizontalBuffer - margins.left;
|
||||
|
||||
if (velocity.y > VELOCITY_THRESHOLD) {
|
||||
margins.top = verticalBuffer * REVERSE_BUFFER;
|
||||
} else if (velocity.y < -VELOCITY_THRESHOLD) {
|
||||
margins.top = verticalBuffer * (1.0f - REVERSE_BUFFER);
|
||||
} else {
|
||||
margins.top = verticalBuffer / 2.0f;
|
||||
}
|
||||
margins.bottom = verticalBuffer - margins.top;
|
||||
|
||||
// and finally shift the margins to account for page bounds
|
||||
// split the buffer amounts into margins based on velocity, and shift it to
|
||||
// take into account the page bounds
|
||||
RectF margins = velocityBiasedMargins(horizontalBuffer, verticalBuffer, velocity);
|
||||
margins = shiftMarginsForPageBounds(margins, metrics);
|
||||
|
||||
return new DisplayPortMetrics(metrics.viewportRectLeft - margins.left,
|
||||
|
@ -339,17 +371,34 @@ final class DisplayPortCalculator {
|
|||
}
|
||||
|
||||
public boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
|
||||
// Since we have such a small margin, we want to be drawing more aggressively. At the start of a
|
||||
// pan the velocity is going to be large so we're almost certainly going to go into checkerboard
|
||||
// on every frame, so drawing all the time seems like the right thing. At the end of the pan we
|
||||
// want to re-center the displayport and draw stuff on all sides, so again we don't want to throttle
|
||||
// there. When we're not panning we're not drawing anyway so it doesn't make a difference there.
|
||||
return true;
|
||||
// calculate the danger zone amounts based on the prefs
|
||||
float dangerZoneX = metrics.getWidth() * (DANGER_ZONE_BASE_X_MULTIPLIER + (velocity.x * DANGER_ZONE_INCR_X_MULTIPLIER));
|
||||
float dangerZoneY = metrics.getHeight() * (DANGER_ZONE_BASE_Y_MULTIPLIER + (velocity.y * DANGER_ZONE_INCR_Y_MULTIPLIER));
|
||||
// clamp it such that when added to the viewport, they don't exceed page size.
|
||||
// this is a prerequisite to calling shiftMarginsForPageBounds as we do below.
|
||||
dangerZoneX = Math.min(dangerZoneX, metrics.pageSizeWidth - metrics.getWidth());
|
||||
dangerZoneY = Math.min(dangerZoneY, metrics.pageSizeHeight - metrics.getHeight());
|
||||
|
||||
// split the danger zone into margins based on velocity, and ensure it doesn't exceed
|
||||
// page bounds.
|
||||
RectF dangerMargins = velocityBiasedMargins(dangerZoneX, dangerZoneY, velocity);
|
||||
dangerMargins = shiftMarginsForPageBounds(dangerMargins, metrics);
|
||||
|
||||
// we're about to checkerboard if the current viewport area + the danger zone margins
|
||||
// fall out of the current displayport anywhere.
|
||||
RectF adjustedViewport = new RectF(
|
||||
metrics.viewportRectLeft - dangerMargins.left,
|
||||
metrics.viewportRectTop - dangerMargins.top,
|
||||
metrics.viewportRectRight + dangerMargins.right,
|
||||
metrics.viewportRectBottom + dangerMargins.bottom);
|
||||
return !displayPort.contains(adjustedViewport);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VelocityBiasStrategy mult=" + SIZE_MULTIPLIER + ", threshold=" + VELOCITY_THRESHOLD + ", reverse=" + REVERSE_BUFFER;
|
||||
return "VelocityBiasStrategy mult=" + SIZE_MULTIPLIER + ", threshold=" + VELOCITY_THRESHOLD + ", reverse=" + REVERSE_BUFFER
|
||||
+ ", dangerBaseX=" + DANGER_ZONE_BASE_X_MULTIPLIER + ", dangerBaseY=" + DANGER_ZONE_BASE_Y_MULTIPLIER
|
||||
+ ", dangerIncrX=" + DANGER_ZONE_INCR_Y_MULTIPLIER + ", dangerIncrY=" + DANGER_ZONE_INCR_Y_MULTIPLIER;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -395,6 +395,7 @@ OS_LIBS += \
|
|||
-lhardware \
|
||||
-lutils \
|
||||
-lcutils \
|
||||
-lsysutils \
|
||||
-lcamera_client \
|
||||
-lbinder \
|
||||
-lsensorservice \
|
||||
|
|
|
@ -5641,9 +5641,13 @@ var XPIDatabase = {
|
|||
|
||||
if (fullCount > 0) {
|
||||
LOG("Writing add-ons list");
|
||||
var fos = FileUtils.openSafeFileOutputStream(addonsList);
|
||||
|
||||
let addonsListTmp = FileUtils.getFile(KEY_PROFILEDIR, [FILE_XPI_ADDONS_LIST + ".tmp"],
|
||||
true);
|
||||
var fos = FileUtils.openFileOutputStream(addonsListTmp);
|
||||
fos.write(text, text.length);
|
||||
FileUtils.closeSafeFileOutputStream(fos);
|
||||
fos.close();
|
||||
addonsListTmp.moveTo(addonsListTmp.parent, FILE_XPI_ADDONS_LIST);
|
||||
|
||||
Services.prefs.setCharPref(PREF_EM_ENABLED_ADDONS, enabledAddons.join(","));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче