summaryrefslogtreecommitdiffstats
path: root/chrome/utility
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-27 19:20:18 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-27 19:20:18 +0000
commit4f3b44679a442a13d949ca2deea1bc15612e8db0 (patch)
tree467728ace4aace084d1da233b7023b9e28487032 /chrome/utility
parentc7007d8241c86117f650361929c6887fd57522c4 (diff)
downloadchromium_src-4f3b44679a442a13d949ca2deea1bc15612e8db0.zip
chromium_src-4f3b44679a442a13d949ca2deea1bc15612e8db0.tar.gz
chromium_src-4f3b44679a442a13d949ca2deea1bc15612e8db0.tar.bz2
importer: Allow chrome to import internal chrome pages (i.e, chrome:// and about: urls).
Bookmark Manager allow users to import and export bookmarks to a html file, while it allow the users to export bookmarks like about:blank, chrome://version, it doesn't allow to import such bookmarks. This patch changes that behavior allowing the "Import Bookmarks from HTML File" process to import bookmarks with schemes like about: and chrome://. BUG=223528 TEST=bookmark some internal chrome pages (ones that start with chrome://* or about:*). Export then to html file through Bookmark Manager. Now import that html file, all the entries should be imported correctly. TBR=dbeam@chromium.org, isherman@chromium.org, pkasting@chromium.org, thakis@chromium.org Review URL: https://codereview.chromium.org/19461003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/utility')
-rw-r--r--chrome/utility/importer/bookmarks_file_importer.cc53
-rw-r--r--chrome/utility/importer/bookmarks_file_importer_unittest.cc41
-rw-r--r--chrome/utility/importer/firefox_importer.cc17
3 files changed, 109 insertions, 2 deletions
diff --git a/chrome/utility/importer/bookmarks_file_importer.cc b/chrome/utility/importer/bookmarks_file_importer.cc
index 335bc9c..ff888a3 100644
--- a/chrome/utility/importer/bookmarks_file_importer.cc
+++ b/chrome/utility/importer/bookmarks_file_importer.cc
@@ -5,12 +5,14 @@
#include "chrome/utility/importer/bookmarks_file_importer.h"
#include "base/bind.h"
-#include "chrome/common/importer/firefox_importer_utils.h"
#include "chrome/common/importer/imported_bookmark_entry.h"
#include "chrome/common/importer/imported_favicon_usage.h"
#include "chrome/common/importer/importer_bridge.h"
#include "chrome/common/importer/importer_data_types.h"
+#include "chrome/common/net/url_fixer_upper.h"
+#include "chrome/common/url_constants.h"
#include "chrome/utility/importer/bookmark_html_reader.h"
+#include "content/public/common/url_constants.h"
#include "grit/generated_resources.h"
namespace {
@@ -21,6 +23,53 @@ bool IsImporterCancelled(BookmarksFileImporter* importer) {
} // namespace
+namespace internal {
+
+// Returns true if |url| has a valid scheme that we allow to import. We
+// filter out the URL with a unsupported scheme.
+bool CanImportURL(const GURL& url) {
+ // The URL is not valid.
+ if (!url.is_valid())
+ return false;
+
+ // Filter out the URLs with unsupported schemes.
+ const char* const kInvalidSchemes[] = {"wyciwyg", "place"};
+ for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) {
+ if (url.SchemeIs(kInvalidSchemes[i]))
+ return false;
+ }
+
+ // Check if |url| is about:blank.
+ if (url == GURL(content::kAboutBlankURL))
+ return true;
+
+ // If |url| starts with chrome:// or about:, check if it's one of the URLs
+ // that we support.
+ if (url.SchemeIs(chrome::kChromeUIScheme) ||
+ url.SchemeIs(chrome::kAboutScheme)) {
+ GURL fixed_url(URLFixerUpper::FixupURL(url.spec(), std::string()));
+ for (size_t i = 0; i < chrome::kNumberOfChromeHostURLs; ++i) {
+ if (fixed_url.DomainIs(chrome::kChromeHostURLs[i]))
+ return true;
+ }
+
+ for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) {
+ if (fixed_url == GURL(chrome::kChromeDebugURLs[i]))
+ return true;
+ }
+
+ // If url has either chrome:// or about: schemes but wasn't found in the
+ // above lists, it means we don't support it, so we don't allow the user
+ // to import it.
+ return false;
+ }
+
+ // Otherwise, we assume the url has a valid (importable) scheme.
+ return true;
+}
+
+} // namespace internal
+
BookmarksFileImporter::BookmarksFileImporter() {}
BookmarksFileImporter::~BookmarksFileImporter() {}
@@ -41,7 +90,7 @@ void BookmarksFileImporter::StartImport(
bookmark_html_reader::ImportBookmarksFile(
base::Bind(IsImporterCancelled, base::Unretained(this)),
- base::Bind(CanImportURL),
+ base::Bind(internal::CanImportURL),
source_profile.source_path,
&bookmarks,
&favicons);
diff --git a/chrome/utility/importer/bookmarks_file_importer_unittest.cc b/chrome/utility/importer/bookmarks_file_importer_unittest.cc
new file mode 100644
index 0000000..f070a12
--- /dev/null
+++ b/chrome/utility/importer/bookmarks_file_importer_unittest.cc
@@ -0,0 +1,41 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/utility/importer/bookmarks_file_importer.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace internal {
+
+bool CanImportURL(const GURL& url);
+
+} // namespace internal
+
+TEST(BookmarksFileImporterTest, CanImportURL) {
+ struct TestCase {
+ const std::string url;
+ const bool can_be_imported;
+ } test_cases[] = {
+ { "http://www.example.com", true },
+ { "https://www.example.com", true },
+ { "ftp://www.example.com", true },
+ { "aim:GoIm?screenname=myscreenname&message=hello", true },
+ { "chrome://version", true },
+ { "chrome://chrome-urls", true },
+ { "chrome://kill", true },
+ { "about:version", true },
+ { "about:blank", true },
+ { "about:credits", true },
+ { "wyciwyg://example.com", false },
+ { "place://google.com", false },
+ { "about:config", false },
+ { "about:moon", false },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
+ EXPECT_EQ(test_cases[i].can_be_imported,
+ internal::CanImportURL(GURL(test_cases[i].url)));
+ }
+}
diff --git a/chrome/utility/importer/firefox_importer.cc b/chrome/utility/importer/firefox_importer.cc
index c939ea9..2869032 100644
--- a/chrome/utility/importer/firefox_importer.cc
+++ b/chrome/utility/importer/firefox_importer.cc
@@ -59,6 +59,23 @@ void LoadDefaultBookmarks(const base::FilePath& app_path,
urls->insert(bookmarks[i].url);
}
+// Returns true if |url| has a valid scheme that we allow to import. We
+// filter out the URL with a unsupported scheme.
+bool CanImportURL(const GURL& url) {
+ // The URL is not valid.
+ if (!url.is_valid())
+ return false;
+
+ // Filter out the URLs with unsupported schemes.
+ const char* const kInvalidSchemes[] = {"wyciwyg", "place", "about", "chrome"};
+ for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) {
+ if (url.SchemeIs(kInvalidSchemes[i]))
+ return false;
+ }
+
+ return true;
+}
+
} // namespace
struct FirefoxImporter::BookmarkItem {