Commit 65fa6e77 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Handle send to self in multi-windows

The infobars pop-up in every window, letting the user
select where they want the new tab. Once a selection or dismissal
is done, all other infobars are dismissed.

Bug: 1068482
Change-Id: I39dff75a69ec74258e50516ba246938b6e0c9a14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2232547
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779242}
parent c927c117
......@@ -5,8 +5,8 @@
source_set("send_tab_to_self") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"ios_send_tab_to_self_infobar_delegate.cc",
"ios_send_tab_to_self_infobar_delegate.h",
"ios_send_tab_to_self_infobar_delegate.mm",
"send_tab_to_self_browser_agent.h",
"send_tab_to_self_browser_agent.mm",
"send_tab_to_self_util.h",
......
......@@ -30,7 +30,7 @@ class IOSSendTabToSelfInfoBarDelegate : public ConfirmInfoBarDelegate {
private:
// ConfirmInfoBarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
int GetButtons() const override;
base::string16 GetButtonLabel(InfoBarButton button) const override;
int GetIconId() const override;
......@@ -39,15 +39,23 @@ class IOSSendTabToSelfInfoBarDelegate : public ConfirmInfoBarDelegate {
bool Accept() override;
bool Cancel() override;
// Send the notice of conclusion of this infobar to other windows.
void SendConclusionNotification();
// The entry that was share to this device. Must outlive this instance.
const SendTabToSelfEntry* entry_ = nullptr;
// The SendTabToSelfModel that holds the |entry_|. Must outlive this instance.
SendTabToSelfModel* model_ = nullptr;
// Registration with NSNotificationCenter for this window.
__strong id<NSObject> registration_ = nil;
base::WeakPtrFactory<IOSSendTabToSelfInfoBarDelegate> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(IOSSendTabToSelfInfoBarDelegate);
};
} // namespace send_tab_to_self
#endif // IOS_CHROME_BROWSER_SEND_TAB_TO_SELF_IOS_SEND_TAB_TO_SELF_INFOBAR_DELEGATE_H_
\ No newline at end of file
#endif // IOS_CHROME_BROWSER_SEND_TAB_TO_SELF_IOS_SEND_TAB_TO_SELF_INFOBAR_DELEGATE_H_
......@@ -4,6 +4,8 @@
#include "ios/chrome/browser/send_tab_to_self/ios_send_tab_to_self_infobar_delegate.h"
#import <Foundation/Foundation.h>
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
......@@ -15,6 +17,17 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/window_open_disposition.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
NSString* kSendTabToSendConclusionNotification =
@"SendTabToSendConclusionNotification";
} // namespace
namespace send_tab_to_self {
// static
......@@ -24,14 +37,43 @@ IOSSendTabToSelfInfoBarDelegate::Create(const SendTabToSelfEntry* entry,
return std::make_unique<IOSSendTabToSelfInfoBarDelegate>(entry, model);
}
IOSSendTabToSelfInfoBarDelegate::~IOSSendTabToSelfInfoBarDelegate() {}
IOSSendTabToSelfInfoBarDelegate::~IOSSendTabToSelfInfoBarDelegate() {
[[NSNotificationCenter defaultCenter]
removeObserver:registration_
name:kSendTabToSendConclusionNotification
object:nil];
}
IOSSendTabToSelfInfoBarDelegate::IOSSendTabToSelfInfoBarDelegate(
const SendTabToSelfEntry* entry,
SendTabToSelfModel* model)
: entry_(entry), model_(model) {
: entry_(entry), model_(model), weak_ptr_factory_(this) {
DCHECK(entry);
DCHECK(model);
base::WeakPtr<IOSSendTabToSelfInfoBarDelegate> weakPtr =
weak_ptr_factory_.GetWeakPtr();
// Observe for conclusion notification from other instances.
registration_ = [[NSNotificationCenter defaultCenter]
addObserverForName:kSendTabToSendConclusionNotification
object:nil
queue:nil
usingBlock:^(NSNotification* note) {
if (!weakPtr)
return;
// Ignore the notification if it was sent by |weakPtr| (i.e. the
// instance that responded first to the send to self infobar)
if (note.object == weakPtr->registration_)
return;
infobars::InfoBar* infobar = weakPtr->infobar();
infobars::InfoBarManager* owner = infobar->owner();
if (!owner)
return;
owner->RemoveInfoBar(infobar);
}];
}
infobars::InfoBarDelegate::InfoBarIdentifier
......@@ -64,12 +106,21 @@ bool IOSSendTabToSelfInfoBarDelegate::Accept() {
model_->MarkEntryOpened(entry_->GetGUID());
infobar()->owner()->OpenURL(entry_->GetURL(),
WindowOpenDisposition::NEW_FOREGROUND_TAB);
SendConclusionNotification();
return true;
}
bool IOSSendTabToSelfInfoBarDelegate::Cancel() {
model_->DismissEntry(entry_->GetGUID());
SendConclusionNotification();
return true;
}
void IOSSendTabToSelfInfoBarDelegate::SendConclusionNotification() {
[[NSNotificationCenter defaultCenter]
postNotificationName:kSendTabToSendConclusionNotification
object:registration_
userInfo:nil];
}
} // namespace send_tab_to_self
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