Commit c31e7872 authored by Caroline Rising's avatar Caroline Rising Committed by Commit Bot

Disable read later star menu option for non-http/https urls.

This restriction comes from ReadingListModel's implementation.

Bug: 1117023
Change-Id: Ibc3f05b7d9523e1dde3661a9559936adb12c52f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2399015
Commit-Queue: Caroline Rising <corising@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805372}
parent eadf7030
...@@ -1030,6 +1030,15 @@ bool CanBookmarkAllTabs(const Browser* browser) { ...@@ -1030,6 +1030,15 @@ bool CanBookmarkAllTabs(const Browser* browser) {
CanBookmarkCurrentTab(browser); CanBookmarkCurrentTab(browser);
} }
bool CanMoveActiveTabToReadLater(Browser* browser) {
GURL url =
GetURLToBookmark(browser->tab_strip_model()->GetActiveWebContents());
ReadingListModel* model = GetReadingListModel(browser);
if (!model)
return false;
return model->IsUrlSupported(url);
}
bool MoveCurrentTabToReadLater(Browser* browser) { bool MoveCurrentTabToReadLater(Browser* browser) {
GURL url; GURL url;
base::string16 title; base::string16 title;
......
...@@ -140,6 +140,7 @@ void BookmarkCurrentTab(Browser* browser); ...@@ -140,6 +140,7 @@ void BookmarkCurrentTab(Browser* browser);
bool CanBookmarkCurrentTab(const Browser* browser); bool CanBookmarkCurrentTab(const Browser* browser);
void BookmarkAllTabs(Browser* browser); void BookmarkAllTabs(Browser* browser);
bool CanBookmarkAllTabs(const Browser* browser); bool CanBookmarkAllTabs(const Browser* browser);
bool CanMoveActiveTabToReadLater(Browser* browser);
bool MoveCurrentTabToReadLater(Browser* browser); bool MoveCurrentTabToReadLater(Browser* browser);
bool MarkCurrentTabAsReadInReadLater(Browser* browser); bool MarkCurrentTabAsReadInReadLater(Browser* browser);
bool IsCurrentTabUnreadInReadLater(Browser* browser); bool IsCurrentTabUnreadInReadLater(Browser* browser);
......
...@@ -8,23 +8,27 @@ ...@@ -8,23 +8,27 @@
#include "components/omnibox/browser/vector_icons.h" #include "components/omnibox/browser/vector_icons.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "ui/base/models/image_model.h" #include "ui/base/models/image_model.h"
#include "ui/native_theme/native_theme.h"
StarMenuModel::StarMenuModel(ui::SimpleMenuModel::Delegate* delegate, StarMenuModel::StarMenuModel(ui::SimpleMenuModel::Delegate* delegate,
bool bookmarked, bool bookmarked,
bool can_move_to_read_later,
bool exists_as_unread_in_read_later) bool exists_as_unread_in_read_later)
: SimpleMenuModel(delegate) { : SimpleMenuModel(delegate) {
Build(bookmarked, exists_as_unread_in_read_later); Build(bookmarked, can_move_to_read_later, exists_as_unread_in_read_later);
} }
StarMenuModel::~StarMenuModel() = default; StarMenuModel::~StarMenuModel() = default;
void StarMenuModel::Build(bool bookmarked, void StarMenuModel::Build(bool bookmarked,
bool can_move_to_read_later,
bool exists_as_unread_in_read_later) { bool exists_as_unread_in_read_later) {
AddItemWithStringIdAndIcon( AddItemWithStringIdAndIcon(
CommandBookmark, CommandBookmark,
bookmarked ? IDS_STAR_VIEW_MENU_EDIT_BOOKMARK bookmarked ? IDS_STAR_VIEW_MENU_EDIT_BOOKMARK
: IDS_STAR_VIEW_MENU_ADD_BOOKMARK, : IDS_STAR_VIEW_MENU_ADD_BOOKMARK,
ui::ImageModel::FromVectorIcon(omnibox::kStarIcon)); ui::ImageModel::FromVectorIcon(
omnibox::kStarIcon, ui::NativeTheme::kColorId_DefaultIconColor));
// TODO(corising): Replace placeholder folder icon with read-later icon once // TODO(corising): Replace placeholder folder icon with read-later icon once
// available. // available.
AddItemWithStringIdAndIcon( AddItemWithStringIdAndIcon(
...@@ -32,5 +36,13 @@ void StarMenuModel::Build(bool bookmarked, ...@@ -32,5 +36,13 @@ void StarMenuModel::Build(bool bookmarked,
: CommandMoveToReadLater, : CommandMoveToReadLater,
exists_as_unread_in_read_later ? IDS_STAR_VIEW_MENU_MARK_AS_READ exists_as_unread_in_read_later ? IDS_STAR_VIEW_MENU_MARK_AS_READ
: IDS_STAR_VIEW_MENU_MOVE_TO_READ_LATER, : IDS_STAR_VIEW_MENU_MOVE_TO_READ_LATER,
ui::ImageModel::FromVectorIcon(vector_icons::kFolderIcon)); ui::ImageModel::FromVectorIcon(
vector_icons::kFolderIcon,
can_move_to_read_later
? ui::NativeTheme::kColorId_DefaultIconColor
: ui::NativeTheme::kColorId_DisabledIconColor));
int index = GetIndexOfCommandId(CommandMoveToReadLater);
if (index != -1) {
SetEnabledAt(index, can_move_to_read_later);
}
} }
...@@ -12,6 +12,7 @@ class StarMenuModel : public ui::SimpleMenuModel { ...@@ -12,6 +12,7 @@ class StarMenuModel : public ui::SimpleMenuModel {
public: public:
StarMenuModel(ui::SimpleMenuModel::Delegate* delegate, StarMenuModel(ui::SimpleMenuModel::Delegate* delegate,
bool bookmarked, bool bookmarked,
bool can_move_to_read_later,
bool exists_as_unread_in_read_later); bool exists_as_unread_in_read_later);
StarMenuModel(const StarMenuModel&) = delete; StarMenuModel(const StarMenuModel&) = delete;
StarMenuModel& operator=(const StarMenuModel&) = delete; StarMenuModel& operator=(const StarMenuModel&) = delete;
...@@ -24,7 +25,9 @@ class StarMenuModel : public ui::SimpleMenuModel { ...@@ -24,7 +25,9 @@ class StarMenuModel : public ui::SimpleMenuModel {
}; };
private: private:
void Build(bool bookmarked, bool exists_as_unread_in_read_later); void Build(bool bookmarked,
bool can_move_to_read_later,
bool exists_as_unread_in_read_later);
}; };
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_STAR_MENU_MODEL_H_ #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_STAR_MENU_MODEL_H_
...@@ -77,7 +77,8 @@ void StarView::OnExecuting(PageActionIconView::ExecuteSource execute_source) { ...@@ -77,7 +77,8 @@ void StarView::OnExecuting(PageActionIconView::ExecuteSource execute_source) {
void StarView::ExecuteCommand(ExecuteSource source) { void StarView::ExecuteCommand(ExecuteSource source) {
if (base::FeatureList::IsEnabled(features::kReadLater)) { if (base::FeatureList::IsEnabled(features::kReadLater)) {
menu_model_ = std::make_unique<StarMenuModel>( menu_model_ = std::make_unique<StarMenuModel>(
this, active(), chrome::IsCurrentTabUnreadInReadLater(browser_)); this, active(), chrome::CanMoveActiveTabToReadLater(browser_),
chrome::IsCurrentTabUnreadInReadLater(browser_));
menu_runner_ = std::make_unique<views::MenuRunner>( menu_runner_ = std::make_unique<views::MenuRunner>(
menu_model_.get(), menu_model_.get(),
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::FIXED_ANCHOR); views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::FIXED_ANCHOR);
......
...@@ -92,6 +92,9 @@ class ReadingListModel { ...@@ -92,6 +92,9 @@ class ReadingListModel {
// entries available offline. // entries available offline.
virtual const ReadingListEntry* GetFirstUnreadEntry(bool distilled) const = 0; virtual const ReadingListEntry* GetFirstUnreadEntry(bool distilled) const = 0;
// Returns true if |url| can be added to the reading list.
virtual bool IsUrlSupported(const GURL& url) = 0;
// Adds |url| at the top of the unread entries, and removes entries with the // Adds |url| at the top of the unread entries, and removes entries with the
// same |url| from everywhere else if they exist. The entry title will be a // same |url| from everywhere else if they exist. The entry title will be a
// trimmed copy of |title|. // trimmed copy of |title|.
......
...@@ -318,13 +318,17 @@ void ReadingListModelImpl::RemoveEntryByURLImpl(const GURL& url, ...@@ -318,13 +318,17 @@ void ReadingListModelImpl::RemoveEntryByURLImpl(const GURL& url,
observer.ReadingListDidApplyChanges(this); observer.ReadingListDidApplyChanges(this);
} }
bool ReadingListModelImpl::IsUrlSupported(const GURL& url) {
return url.SchemeIsHTTPOrHTTPS();
}
const ReadingListEntry& ReadingListModelImpl::AddEntry( const ReadingListEntry& ReadingListModelImpl::AddEntry(
const GURL& url, const GURL& url,
const std::string& title, const std::string& title,
reading_list::EntrySource source) { reading_list::EntrySource source) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(loaded()); DCHECK(loaded());
DCHECK(url.SchemeIsHTTPOrHTTPS()); DCHECK(IsUrlSupported(url));
std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate> std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
scoped_model_batch_updates = nullptr; scoped_model_batch_updates = nullptr;
if (GetEntryByURL(url)) { if (GetEntryByURL(url)) {
......
...@@ -65,6 +65,8 @@ class ReadingListModelImpl : public ReadingListModel, ...@@ -65,6 +65,8 @@ class ReadingListModelImpl : public ReadingListModel,
void RemoveEntryByURL(const GURL& url) override; void RemoveEntryByURL(const GURL& url) override;
bool IsUrlSupported(const GURL& url) override;
const ReadingListEntry& AddEntry(const GURL& url, const ReadingListEntry& AddEntry(const GURL& url,
const std::string& title, const std::string& title,
reading_list::EntrySource source) override; reading_list::EntrySource source) override;
......
...@@ -89,6 +89,11 @@ class FakeReadingListModel : public ReadingListModel { ...@@ -89,6 +89,11 @@ class FakeReadingListModel : public ReadingListModel {
return nullptr; return nullptr;
} }
bool IsUrlSupported(const GURL& url) override {
NOTREACHED();
return false;
}
const ReadingListEntry& AddEntry(const GURL& url, const ReadingListEntry& AddEntry(const GURL& url,
const std::string& title, const std::string& title,
reading_list::EntrySource source) override { reading_list::EntrySource source) override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment