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

Unified Diff: components/bookmarks/browser/bookmark_utils.cc

Issue 437423005: Show paste option on right click of bookmark bar if some URL is copied from outside browser or from… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build break. Created 6 years, 3 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
« no previous file with comments | « no previous file | components/bookmarks/browser/bookmark_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/bookmarks/browser/bookmark_utils.cc
diff --git a/components/bookmarks/browser/bookmark_utils.cc b/components/bookmarks/browser/bookmark_utils.cc
index b0769ff946b7014cc6a77b9680c0c087d7e8bbc5..a60a86d0020c6eeb0f231b13e5ee0be270b581e2 100644
--- a/components/bookmarks/browser/bookmark_utils.cc
+++ b/components/bookmarks/browser/bookmark_utils.cc
@@ -22,6 +22,7 @@
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/query_parser/query_parser.h"
#include "net/base/net_util.h"
+#include "ui/base/clipboard/clipboard.h"
#include "ui/base/models/tree_node_iterator.h"
#include "url/gurl.h"
@@ -143,6 +144,17 @@ std::string TruncateUrl(const std::string& url) {
return url.substr(0, kCleanedUpUrlMaxLength);
}
+// Returns the URL from the clipboard. If there is no URL an empty URL is
+// returned.
+GURL GetUrlFromClipboard() {
+ base::string16 url_text;
+#if !defined(OS_IOS)
+ ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE,
+ &url_text);
+#endif
+ return GURL(url_text);
+}
+
} // namespace
QueryFields::QueryFields() {}
@@ -196,9 +208,14 @@ void PasteFromClipboard(BookmarkModel* model,
return;
BookmarkNodeData bookmark_data;
- if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE))
- return;
-
+ if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) {
+ GURL url = GetUrlFromClipboard();
+ if (!url.is_valid())
+ return;
+ BookmarkNode node(url);
+ node.SetTitle(base::ASCIIToUTF16(url.spec()));
+ bookmark_data = BookmarkNodeData(&node);
+ }
if (index == -1)
index = parent->child_count();
ScopedGroupBookmarkActions group_paste(model);
@@ -208,7 +225,8 @@ void PasteFromClipboard(BookmarkModel* model,
bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) {
if (!node || !model->client()->CanBeEditedByUser(node))
return false;
- return BookmarkNodeData::ClipboardContainsBookmarks();
+ return (BookmarkNodeData::ClipboardContainsBookmarks() ||
+ GetUrlFromClipboard().is_valid());
}
std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders(
« no previous file with comments | « no previous file | components/bookmarks/browser/bookmark_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698