diff options
-rw-r--r-- | chrome/app/nibs/FirstRunDialog.xib | 44 | ||||
-rw-r--r-- | chrome/browser/cocoa/first_run_dialog.h | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/first_run_dialog.mm | 1 | ||||
-rw-r--r-- | chrome/browser/first_run_mac.mm | 5 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 18 | ||||
-rw-r--r-- | chrome/browser/importer/safari_importer.h | 7 | ||||
-rw-r--r-- | chrome/browser/importer/safari_importer.mm | 41 | ||||
-rw-r--r-- | chrome/browser/importer/safari_importer_unittest.mm | 27 |
8 files changed, 129 insertions, 16 deletions
diff --git a/chrome/app/nibs/FirstRunDialog.xib b/chrome/app/nibs/FirstRunDialog.xib index b18830e..8408fdf 100644 --- a/chrome/app/nibs/FirstRunDialog.xib +++ b/chrome/app/nibs/FirstRunDialog.xib @@ -587,7 +587,7 @@ <string key="label">enabled: importBookmarks</string> <reference key="source" ref="21765562"/> <reference key="destination" ref="1001"/> - <object class="NSNibBindingConnector" key="connector"> + <object class="NSNibBindingConnector" key="connector" id="760401606"> <reference key="NSSource" ref="21765562"/> <reference key="NSDestination" ref="1001"/> <string key="NSLabel">enabled: importBookmarks</string> @@ -638,6 +638,39 @@ </object> <int key="connectionID">92</int> </object> + <object class="IBConnectionRecord"> + <object class="IBBindingConnection" key="connection"> + <string key="label">hidden: browserImportListHidden</string> + <reference key="source" ref="690083374"/> + <reference key="destination" ref="1001"/> + <object class="NSNibBindingConnector" key="connector"> + <reference key="NSSource" ref="690083374"/> + <reference key="NSDestination" ref="1001"/> + <string key="NSLabel">hidden: browserImportListHidden</string> + <string key="NSBinding">hidden</string> + <string key="NSKeyPath">browserImportListHidden</string> + <int key="NSNibBindingConnectorVersion">2</int> + </object> + </object> + <int key="connectionID">94</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBBindingConnection" key="connection"> + <string key="label">hidden: browserImportListHidden</string> + <reference key="source" ref="21765562"/> + <reference key="destination" ref="1001"/> + <object class="NSNibBindingConnector" key="connector"> + <reference key="NSSource" ref="21765562"/> + <reference key="NSDestination" ref="1001"/> + <string key="NSLabel">hidden: browserImportListHidden</string> + <string key="NSBinding">hidden</string> + <string key="NSKeyPath">browserImportListHidden</string> + <reference key="NSPreviousConnector" ref="760401606"/> + <int key="NSNibBindingConnectorVersion">2</int> + </object> + </object> + <int key="connectionID">96</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -1007,7 +1040,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">92</int> + <int key="maxID">96</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -1080,6 +1113,13 @@ <string key="minorKey">browser/cocoa/tab_strip_model_observer_bridge.h</string> </object> </object> + <object class="IBPartialClassDescription"> + <string key="className">NSWindow</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/nswindow_local_state.h</string> + </object> + </object> </object> </object> <int key="IBDocument.localizationMode">0</int> diff --git a/chrome/browser/cocoa/first_run_dialog.h b/chrome/browser/cocoa/first_run_dialog.h index 0b3f07a..08a184b 100644 --- a/chrome/browser/cocoa/first_run_dialog.h +++ b/chrome/browser/cocoa/first_run_dialog.h @@ -18,6 +18,7 @@ BOOL usage_stats_checkbox_hidden_; int browser_import_selected_index_; NSArray* browser_import_list_; + BOOL browser_import_list_hidden_; } // Called when the "Start Google Chrome" button is pressed. @@ -36,6 +37,7 @@ @property(assign) BOOL importBookmarks; @property(assign) int browserImportSelectedIndex; @property(retain) NSArray* browserImportList; +@property(assign) BOOL browserImportListHidden; @end diff --git a/chrome/browser/cocoa/first_run_dialog.mm b/chrome/browser/cocoa/first_run_dialog.mm index 4fe80bc..e1daf6d 100644 --- a/chrome/browser/cocoa/first_run_dialog.mm +++ b/chrome/browser/cocoa/first_run_dialog.mm @@ -16,6 +16,7 @@ @synthesize importBookmarks = import_bookmarks_; @synthesize browserImportSelectedIndex = browser_import_selected_index_; @synthesize browserImportList = browser_import_list_; +@synthesize browserImportListHidden = browser_import_list_hidden_; - (id)init { self = [super initWithWindowNibName:@"FirstRunDialog"]; diff --git a/chrome/browser/first_run_mac.mm b/chrome/browser/first_run_mac.mm index 32ea144..52e18a6 100644 --- a/chrome/browser/first_run_mac.mm +++ b/chrome/browser/first_run_mac.mm @@ -179,6 +179,9 @@ bool FirstRunController::DoFirstRun(Profile* profile, } [dialog.get() setBrowserImportList:browsers]; + BOOL browser_import_disabled = profiles_count == 0; + [dialog.get() setBrowserImportListHidden:browser_import_disabled]; + // FirstRunDialogController will call exit if "Cancel" is clicked. [dialog.get() showWindow:nil]; @@ -214,7 +217,7 @@ bool FirstRunController::DoFirstRun(Profile* profile, } // Import bookmarks. - if ([dialog.get() importBookmarks]) { + if (!browser_import_disabled && [dialog.get() importBookmarks]) { const ProfileInfo& source_profile = importer_host_->GetSourceProfileInfoAt( [dialog.get() browserImportSelectedIndex]); int16 items = source_profile.services_supported; diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index ab02a41..62cbf52 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -834,13 +834,15 @@ void ImporterHost::DetectGoogleToolbarProfiles() { #if defined(OS_MACOSX) void ImporterHost::DetectSafariProfiles() { - // TODO(jeremy):Check that Safari folder is in fact present. - ProfileInfo* safari = new ProfileInfo(); - safari->browser_type = SAFARI; - safari->description = l10n_util::GetString(IDS_IMPORT_FROM_SAFARI); - safari->source_path.clear(); - safari->app_path.clear(); - safari->services_supported = HISTORY | FAVORITES | HOME_PAGE; - source_profiles_.push_back(safari); + uint16 items = NONE; + if (SafariImporter::CanImport(mac_util::GetUserLibraryPath(), &items)) { + ProfileInfo* safari = new ProfileInfo(); + safari->browser_type = SAFARI; + safari->description = l10n_util::GetString(IDS_IMPORT_FROM_SAFARI); + safari->source_path.clear(); + safari->app_path.clear(); + safari->services_supported = items; + source_profiles_.push_back(safari); + } } #endif // OS_MACOSX diff --git a/chrome/browser/importer/safari_importer.h b/chrome/browser/importer/safari_importer.h index 75f2a65..e443242 100644 --- a/chrome/browser/importer/safari_importer.h +++ b/chrome/browser/importer/safari_importer.h @@ -36,6 +36,13 @@ class SafariImporter : public Importer { MessageLoop* delegate_loop, ImporterHost* host); + + // Does this user account have a Safari Profile and if so, what items + // are supported? + // in: library_dir - ~/Library or a standin for testing purposes. + // out: services_supported - the service supported for import. + // returns true if we can import the Safari profile. + static bool CanImport(const FilePath& library_dir, uint16 *services_supported); private: FRIEND_TEST(SafariImporterTest, BookmarkImport); FRIEND_TEST(SafariImporterTest, FavIconImport); diff --git a/chrome/browser/importer/safari_importer.mm b/chrome/browser/importer/safari_importer.mm index e862b97..e08e582 100644 --- a/chrome/browser/importer/safari_importer.mm +++ b/chrome/browser/importer/safari_importer.mm @@ -10,6 +10,7 @@ #include <vector> #include "app/l10n_util.h" +#include "base/file_util.h" #include "base/message_loop.h" #include "base/scoped_nsobject.h" #include "base/string16.h" @@ -44,8 +45,38 @@ SafariImporter::SafariImporter(const FilePath& library_dir) SafariImporter::~SafariImporter() { } +// static +bool SafariImporter::CanImport(const FilePath& library_dir, + uint16 *services_supported) { + DCHECK(services_supported); + *services_supported = NONE; + + // Import features are toggled by the following: + // bookmarks import: existance of ~/Library/Safari/Bookmarks.plist file. + // history import: existance of ~/Library/Safari/History.plist file. + // homepage import: existance of appropriate key in defaults. + FilePath safari_dir = library_dir.Append("Safari"); + FilePath bookmarks_path = safari_dir.Append("Bookmarks.plist"); + FilePath history_path = safari_dir.Append("History.plist"); + + using file_util::PathExists; + if (PathExists(bookmarks_path)) + *services_supported |= FAVORITES; + if (PathExists(history_path)) + *services_supported |= HISTORY; + + const scoped_nsobject<NSString> homepage_ns( + reinterpret_cast<const NSString*>( + CFPreferencesCopyAppValue(CFSTR("HomePage"), + CFSTR("com.apple.Safari")))); + if (homepage_ns.get()) + *services_supported |= HOME_PAGE; + + return *services_supported != NONE; +} + void SafariImporter::StartImport(ProfileInfo profile_info, - uint16 items, ProfileWriter* writer, + uint16 services_supported, ProfileWriter* writer, MessageLoop* delegate_loop, ImporterHost* host) { writer_ = writer; @@ -53,19 +84,19 @@ void SafariImporter::StartImport(ProfileInfo profile_info, // The order here is important! NotifyStarted(); - if ((items & HOME_PAGE) && !cancelled()) + if ((services_supported & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. - if ((items & HISTORY) && !cancelled()) { + if ((services_supported & HISTORY) && !cancelled()) { NotifyItemStarted(HISTORY); ImportHistory(); NotifyItemEnded(HISTORY); } - if ((items & FAVORITES) && !cancelled()) { + if ((services_supported & FAVORITES) && !cancelled()) { NotifyItemStarted(FAVORITES); ImportBookmarks(); NotifyItemEnded(FAVORITES); } - if ((items & PASSWORDS) && !cancelled()) { + if ((services_supported & PASSWORDS) && !cancelled()) { NotifyItemStarted(PASSWORDS); ImportPasswords(); NotifyItemEnded(PASSWORDS); diff --git a/chrome/browser/importer/safari_importer_unittest.mm b/chrome/browser/importer/safari_importer_unittest.mm index 94d2517..7a4d99f 100644 --- a/chrome/browser/importer/safari_importer_unittest.mm +++ b/chrome/browser/importer/safari_importer_unittest.mm @@ -10,6 +10,7 @@ #include "base/path_service.h" #include "base/sys_string_conversions.h" #include "chrome/common/chrome_paths.h" +#include "chrome/test/file_test_utils.h" #include "testing/platform_test.h" // In order to test the Safari import functionality effectively, we store a @@ -142,3 +143,29 @@ TEST_F(SafariImporterTest, FavIconImport) { GURL("http://www.opensearch.org/Special:Search?search=lalala&go=Search")) != fav1.urls.end()); } + +TEST_F(SafariImporterTest, CanImport) { + uint16 items = NONE; + EXPECT_TRUE(SafariImporter::CanImport(GetTestSafariLibraryPath(), &items)); + // We can't check the exact value of items because the HOME_PAGE bit depends + // on the defaults of the current machine. + EXPECT_EQ(items & HISTORY, HISTORY); + EXPECT_EQ(items & FAVORITES, FAVORITES); + EXPECT_EQ(items & COOKIES, NONE); + EXPECT_EQ(items & PASSWORDS, NONE); + EXPECT_EQ(items & SEARCH_ENGINES, NONE); + + // Check that we don't import anything from a bogus library directory. + FilePath fake_library_dir; + file_util::CreateNewTempDirectory("FakeSafariLibrary", &fake_library_dir); + FileAutoDeleter deleter(fake_library_dir); + + // Despite the fact that we're pointing to an empty library directory, + // CanImport may still return true on systems where the Safari defaults + // are defined. This means that we can't make assumptions about the return + // value here. + SafariImporter::CanImport(fake_library_dir, &items); + EXPECT_EQ(items & ~HOME_PAGE, NONE); // See comment above about HOME_PAGE. + + +} |