Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: chrome/utility/importer/bookmark_html_reader.cc

Issue 616763002: Importing certain bookmarks from firefox and HTML file as search engines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/utility/importer/bookmark_html_reader.cc
diff --git a/chrome/utility/importer/bookmark_html_reader.cc b/chrome/utility/importer/bookmark_html_reader.cc
index e11dc1d7761f68631aede24d93a78fe37839f162..0821359189c21bf7c84ad62ee35d48d806d66988 100644
--- a/chrome/utility/importer/bookmark_html_reader.cc
+++ b/chrome/utility/importer/bookmark_html_reader.cc
@@ -10,6 +10,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/common/importer/imported_bookmark_entry.h"
#include "chrome/common/importer/imported_favicon_usage.h"
@@ -91,6 +92,7 @@ void ImportBookmarksFile(
const base::Callback<bool(const GURL&)>& valid_url_callback,
const base::FilePath& file_path,
std::vector<ImportedBookmarkEntry>* bookmarks,
+ std::vector<importer::URLKeywordInfo>* search_engine_keywords,
std::vector<ImportedFaviconUsage>* favicons) {
std::string content;
base::ReadFileToString(file_path, &content);
@@ -153,14 +155,27 @@ void ImportBookmarksFile(
if (is_bookmark)
last_folder_is_empty = false;
+ importer::URLKeywordInfo search_engine_keyword;
+ bool is_valid_replaceable_url =
Peter Kasting 2014/10/07 23:17:38 Nit: Why are the variable and the function named t
Tapu Ghose 2014/10/12 00:58:20 Renamed to search_engine with type as SearchEngine
+ CanImportURLAsSearchEngine(url, shortcut,
+ title, &search_engine_keyword);
Ilya Sherman 2014/10/07 22:08:22 nit: This formatting looks off. Please run "git c
Peter Kasting 2014/10/07 23:17:38 No, this formatting is legal.
Tapu Ghose 2014/10/12 00:58:20 Acknowledged.
Tapu Ghose 2014/10/12 00:58:20 Acknowledged.
+
if (is_bookmark &&
post_data.empty() &&
- (valid_url_callback.is_null() || valid_url_callback.Run(url))) {
+ (valid_url_callback.is_null() || valid_url_callback.Run(url) ||
+ is_valid_replaceable_url)) {
if (toolbar_folder_index > path.size() && !path.empty()) {
NOTREACHED(); // error in parsing.
break;
}
+ // If bookmark contains a valid replaceable url and a keyword then import
+ // it as search engine.
+ if (is_valid_replaceable_url && !shortcut.empty()) {
+ search_engine_keywords->push_back(search_engine_keyword);
+ continue;
+ }
+
ImportedBookmarkEntry entry;
entry.creation_time = add_date;
entry.url = url;
@@ -238,6 +253,36 @@ void ImportBookmarksFile(
}
}
+bool CanImportURLAsSearchEngine(const GURL& url,
+ const base::string16& keyword,
+ const base::string16& title,
+ importer::URLKeywordInfo* search_engine_info) {
+ // |url| can be imported as search engine if it contains replacement term(s).
+ // Usually, a |url| containing replacement term in host is considered as
+ // invalid. Hence, return false for valid |url|.
Ilya Sherman 2014/10/07 22:08:22 Hmm, what if the replacement term is outside the h
Tapu Ghose 2014/10/12 00:58:20 Removed the condition. After looking at the flow i
+ if (url.is_valid())
+ return false;
+
+ std::string raw_url = net::UnescapeURLComponent(
+ url.possibly_invalid_spec(),
+ net::UnescapeRule::SPACES |
+ net::UnescapeRule::URL_SPECIAL_CHARS |
+ net::UnescapeRule::REPLACE_PLUS_WITH_SPACE);
Ilya Sherman 2014/10/07 22:08:22 Hmm, why do you need to unescape spaces?
Peter Kasting 2014/10/07 23:17:38 And pluses? Does this need to be some sort of "fu
Tapu Ghose 2014/10/12 00:58:20 Removed REPLACE_PLUS_WITH_SPACE.
Tapu Ghose 2014/10/12 00:58:20 As I mentioned in Patch Set 1...... when I try to
Tapu Ghose 2014/11/06 00:23:52 Finally, the dependency issue has been resolved. I
+ search_engine_info->raw_url.assign(base::UTF8ToUTF16(raw_url));
+ search_engine_info->keyword = keyword;
+ search_engine_info->display_name = title;
+
+ const std::string kReplacementTerm("%s");
+ if (raw_url.find(kReplacementTerm) == std::string::npos)
+ return false;
+
+ // Substitute replacement term with arbitrary value. Return false if the
+ // resulted output is an invalid url.
+ const std::string kReplacementVal("val");
+ ReplaceSubstringsAfterOffset(&raw_url, 0, kReplacementTerm, kReplacementVal);
+ return GURL(raw_url).is_valid();
+}
+
namespace internal {
bool ParseCharsetFromLine(const std::string& line, std::string* charset) {

Powered by Google App Engine
This is Rietveld 408576698