Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "components/open_from_clipboard/clipboard_recent_content.h" |
| 6 | 6 |
| 7 #include "url/url_constants.h" | |
| 8 | |
| 7 namespace { | 9 namespace { |
| 8 ClipboardRecentContent* g_clipboard_recent_content = nullptr; | 10 ClipboardRecentContent* g_clipboard_recent_content = nullptr; |
| 9 } | 11 |
| 12 // Schemes appropriate for suggestion by ClipboardRecentContent. | |
| 13 const char* kAuthorizedSchemes[] = { | |
| 14 url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, | |
| 15 // TODO(mpearson): add support for chrome:// URLs. Right now the scheme | |
| 16 // for that lives in content and is accessible via | |
| 17 // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme | |
| 18 // TODO(mpearson): when adding desktop support, add kFileScheme, kFtpScheme, | |
| 19 // and kGopherScheme. | |
| 20 }; | |
| 21 | |
| 22 } // namespace | |
| 10 | 23 |
| 11 ClipboardRecentContent::ClipboardRecentContent() {} | 24 ClipboardRecentContent::ClipboardRecentContent() {} |
| 12 | 25 |
| 13 ClipboardRecentContent::~ClipboardRecentContent() {} | 26 ClipboardRecentContent::~ClipboardRecentContent() { |
| 27 g_clipboard_recent_content = nullptr; | |
|
Peter Kasting
2017/04/03 23:35:18
I'm still worried about lifetime management here.
Mark P
2017/04/04 04:53:02
Rightly so, you make a good point below.
I see tw
| |
| 28 } | |
| 14 | 29 |
| 15 // static | 30 // static |
| 16 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { | 31 ClipboardRecentContent* ClipboardRecentContent::GetInstance() { |
| 17 return g_clipboard_recent_content; | 32 return g_clipboard_recent_content; |
| 18 } | 33 } |
| 19 | 34 |
| 20 // static | 35 // static |
| 21 void ClipboardRecentContent::SetInstance(ClipboardRecentContent* instance) { | 36 void ClipboardRecentContent::SetInstance(ClipboardRecentContent* instance) { |
| 22 g_clipboard_recent_content = instance; | 37 g_clipboard_recent_content = instance; |
| 23 } | 38 } |
| 39 | |
| 40 // static | |
| 41 bool ClipboardRecentContent::IsAppropriateSuggestion(const GURL& url) { | |
| 42 // Check to make sure it's a scheme we're willing to suggest. | |
| 43 for (const auto* authorized_scheme : kAuthorizedSchemes) { | |
| 44 if (url.SchemeIs(authorized_scheme)) | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 // Not a scheme we're allowed to return. | |
| 49 return false; | |
| 50 } | |
| OLD | NEW |