Commit 427a7884 authored by mpawlowski@opera.com's avatar mpawlowski@opera.com

Fixing Firefox 21+ password import

Firefox 21 changed the directory layout within Firefox.app.
Some libs and content were moved from Firefox.app/Content/MacOS to
Firefox.app/Content/MacOS/browser, and this new location was
read as app_path_ by the importer. However, libnss3.dylib is still
in Firefox.app/Content/MacOS.

Changing utils to set app_path_ based on compatibility.ini's
LastPlatformDir (which always has Firefox.app/Content/MacOS)
instead of LastAppDir (which was changed to
Firefox.app/Content/MacOS/browser).

'searchplugins' subdir was moved into the new 'browser' subdir
so search engine importing code has to be adjusted.

Enabling Firefox importer browser tests on Mac. They didn't
work because they attempted to use Windows nss libraries. 
They should have been using Mac-specific libraries which are 
already available for Mac unit tests.

BUG=321112, 48007

Review URL: https://codereview.chromium.org/117123002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245198 0039d316-1c4b-4281-b951-d872f2087c98
parent ca3b7743
......@@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
......@@ -93,6 +94,40 @@ base::FilePath GetFirefoxProfilePathFromDictionary(
return GetProfilePath(root, profiles.front());
}
#if defined(OS_MACOSX)
// Find the "*.app" component of the path and build up from there.
// The resulting path will be .../Firefox.app/Contents/MacOS.
// We do this because we don't trust LastAppDir to always be
// this particular path, without any subdirs, and we want to make
// our assumption about Firefox's root being in that path explicit.
bool ComposeMacAppPath(const std::string& path_from_file,
base::FilePath* output) {
base::FilePath path(path_from_file);
typedef std::vector<base::FilePath::StringType> ComponentVector;
ComponentVector path_components;
path.GetComponents(&path_components);
if (path_components.empty())
return false;
// The first path component is special because it may be absolute. Calling
// Append with an absolute path component will trigger an assert, so we
// must handle it differently and initialize output with it.
*output = base::FilePath(path_components[0]);
// Append next path components untill we find the *.app component. When we do,
// append Contents/MacOS.
for (size_t i = 1; i < path_components.size(); ++i) {
*output = output->Append(path_components[i]);
if (EndsWith(path_components[i], ".app", true)) {
*output = output->Append("Contents");
*output = output->Append("MacOS");
return true;
}
}
LOG(ERROR) << path_from_file << " doesn't look like a valid Firefox "
<< "installation path: missing /*.app/ directory.";
return false;
}
#endif // OS_MACOSX
bool GetFirefoxVersionAndPathFromProfile(const base::FilePath& profile_path,
int* version,
base::FilePath* app_path) {
......@@ -120,7 +155,15 @@ bool GetFirefoxVersionAndPathFromProfile(const base::FilePath& profile_path,
// UTF-8, what does Firefox do? If it puts raw bytes in the
// file, we could go straight from bytes -> filepath;
// otherwise, we're out of luck here.
#if defined(OS_MACOSX)
// Extract path from "LastAppDir=/actual/path"
size_t separator_pos = line.find_first_of('=');
const std::string& path_from_ini = line.substr(separator_pos + 1);
if (!ComposeMacAppPath(path_from_ini, app_path))
return false;
#else // !OS_MACOSX
*app_path = base::FilePath::FromUTF8Unsafe(line.substr(equal + 1));
#endif // OS_MACOSX
}
}
}
......
......@@ -383,6 +383,9 @@ void FirefoxImporter::ImportHomepage() {
void FirefoxImporter::GetSearchEnginesXMLData(
std::vector<std::string>* search_engine_data) {
// TODO(mpawlowski): This may no longer work, search engines are stored in
// search.json since Firefox 3.5, not in search.sqlite. XML definitions are
// still necessary. http://crbug.com/329175
base::FilePath file = source_path_.AppendASCII("search.sqlite");
if (!base::PathExists(file))
return;
......@@ -401,8 +404,21 @@ void FirefoxImporter::GetSearchEnginesXMLData(
if (!s.is_valid())
return;
base::FilePath app_path = app_path_.AppendASCII("searchplugins");
base::FilePath profile_path = source_path_.AppendASCII("searchplugins");
const base::FilePath searchplugins_path(FILE_PATH_LITERAL("searchplugins"));
// Search engine definitions are XMLs stored in two directories. Default
// engines are in the app directory (app_path_) and custom engines are
// in the profile directory (source_path_).
// Since Firefox 21, app_path_ engines are in 'browser' subdirectory:
base::FilePath app_path =
app_path_.AppendASCII("browser").Append(searchplugins_path);
if (!base::PathExists(app_path)) {
// This might be an older Firefox, try old location without the 'browser'
// path component:
app_path = app_path_.Append(searchplugins_path);
}
base::FilePath profile_path = source_path_.Append(searchplugins_path);
// Firefox doesn't store a search engine in its sqlite database unless the
// user has added a engine. So we get search engines from sqlite db as well
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment