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

Side by Side Diff: components/open_from_clipboard/clipboard_recent_content_generic.cc

Issue 2842793003: Clipboard Recent Content - Code Health - Move kAuthorizedScheme into Subclass (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « components/open_from_clipboard/clipboard_recent_content_generic.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/open_from_clipboard/clipboard_recent_content_generic.h" 5 #include "components/open_from_clipboard/clipboard_recent_content_generic.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "ui/base/clipboard/clipboard.h" 8 #include "ui/base/clipboard/clipboard.h"
9 9
10 namespace {
11 // Schemes appropriate for suggestion by ClipboardRecentContent.
12 const char* kAuthorizedSchemes[] = {
13 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme,
14 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme
15 // for that lives in content and is accessible via
16 // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme
17 // TODO(mpearson): when adding desktop support, add kFileScheme, kFtpScheme,
18 // and kGopherScheme.
19 };
20
21 } // namespace
22
10 ClipboardRecentContentGeneric::ClipboardRecentContentGeneric() {} 23 ClipboardRecentContentGeneric::ClipboardRecentContentGeneric() {}
11 24
12 bool ClipboardRecentContentGeneric::GetRecentURLFromClipboard(GURL* url) { 25 bool ClipboardRecentContentGeneric::GetRecentURLFromClipboard(GURL* url) {
13 if (GetClipboardContentAge() > MaximumAgeOfClipboard()) 26 if (GetClipboardContentAge() > MaximumAgeOfClipboard())
14 return false; 27 return false;
15 28
16 // Get and clean up the clipboard before processing. 29 // Get and clean up the clipboard before processing.
17 std::string gurl_string; 30 std::string gurl_string;
18 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); 31 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
19 clipboard->ReadAsciiText(ui::CLIPBOARD_TYPE_COPY_PASTE, &gurl_string); 32 clipboard->ReadAsciiText(ui::CLIPBOARD_TYPE_COPY_PASTE, &gurl_string);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return base::TimeDelta(); 69 return base::TimeDelta();
57 return now - last_modified_time; 70 return now - last_modified_time;
58 } 71 }
59 72
60 void ClipboardRecentContentGeneric::SuppressClipboardContent() { 73 void ClipboardRecentContentGeneric::SuppressClipboardContent() {
61 // User cleared the user data. The pasteboard entry must be removed from the 74 // User cleared the user data. The pasteboard entry must be removed from the
62 // omnibox list. Do this by pretending the current clipboard is ancient, 75 // omnibox list. Do this by pretending the current clipboard is ancient,
63 // not recent. 76 // not recent.
64 ui::Clipboard::GetForCurrentThread()->ClearLastModifiedTime(); 77 ui::Clipboard::GetForCurrentThread()->ClearLastModifiedTime();
65 } 78 }
79
80 // static
81 bool ClipboardRecentContentGeneric::IsAppropriateSuggestion(const GURL& url) {
82 // Check to make sure it's a scheme we're willing to suggest.
83 for (const auto* authorized_scheme : kAuthorizedSchemes) {
84 if (url.SchemeIs(authorized_scheme))
85 return true;
86 }
87
88 // Not a scheme we're allowed to return.
89 return false;
90 }
OLDNEW
« no previous file with comments | « components/open_from_clipboard/clipboard_recent_content_generic.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698