Commit d8e2189c authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Sharing dialog cleanup.

Follow-up CL with some cleanup after crrev.com/c/1789149.

Bug: None
Change-Id: I0301aba1e20df1fdc8681e8008e86e37ac703517
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852425Reviewed-by: default avatarDavid Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705492}
parent 2de3b7e6
...@@ -382,15 +382,16 @@ void HandleDeviceSelection( ...@@ -382,15 +382,16 @@ void HandleDeviceSelection(
if (!web_contents) if (!web_contents)
return; return;
for (const auto& device : devices) { const auto it = std::find_if(devices.begin(), devices.end(),
if (device->guid() == device_guid) { [&device_guid](const auto& device) {
ClickToCallUiController::GetOrCreateFromWebContents(web_contents) return device->guid() == device_guid;
->OnDeviceSelected(GetUnescapedURLContent(url), *device, });
SharingClickToCallEntryPoint::kLeftClickLink); DCHECK(it != devices.end());
return; auto* device = it->get();
}
} ClickToCallUiController::GetOrCreateFromWebContents(web_contents)
NOTREACHED(); ->OnDeviceSelected(GetUnescapedURLContent(url), *device,
SharingClickToCallEntryPoint::kLeftClickLink);
} }
// Handles |url| if possible. Returns true if it is actually handled. // Handles |url| if possible. Returns true if it is actually handled.
......
...@@ -86,23 +86,19 @@ class MockSharingService : public SharingService { ...@@ -86,23 +86,19 @@ class MockSharingService : public SharingService {
public: public:
MockSharingService() MockSharingService()
: SharingService( : SharingService(
/*sync_prefs=*/nullptr, nullptr,
/*vapid_key_manager=*/nullptr, nullptr,
std::make_unique<SharingDeviceRegistration>( std::make_unique<SharingDeviceRegistration>(nullptr,
/*pref_service=*/nullptr, nullptr,
/*sync_preference=*/nullptr, nullptr,
/*instance_id_driver=*/nullptr, nullptr),
/*vapid_key_manager=*/nullptr), nullptr,
/*fcm_sender=*/nullptr, std::make_unique<SharingFCMHandler>(nullptr, nullptr, nullptr),
std::make_unique<SharingFCMHandler>( nullptr,
/*gcm_driver=*/nullptr, nullptr,
/*sharing_fcm_sender=*/nullptr, nullptr,
/*sync_preference=*/nullptr), nullptr,
/*gcm_driver=*/nullptr, nullptr) {}
/*device_info_tracker=*/nullptr,
/*local_device_info_provider=*/nullptr,
/*sync_service=*/nullptr,
/*notification_display_service=*/nullptr) {}
~MockSharingService() override = default; ~MockSharingService() override = default;
...@@ -1018,7 +1014,7 @@ TEST_F(ArcExternalProtocolDialogTestUtils, TestSelectDeviceForTelLink) { ...@@ -1018,7 +1014,7 @@ TEST_F(ArcExternalProtocolDialogTestUtils, TestSelectDeviceForTelLink) {
std::vector<mojom::IntentHandlerInfoPtr> handlers; std::vector<mojom::IntentHandlerInfoPtr> handlers;
std::vector<std::unique_ptr<syncer::DeviceInfo>> devices; std::vector<std::unique_ptr<syncer::DeviceInfo>> devices;
devices.emplace_back(std::make_unique<syncer::DeviceInfo>( devices.push_back(std::make_unique<syncer::DeviceInfo>(
device_guid, "device_name", "chrome_version", "user_agent", device_guid, "device_name", "chrome_version", "user_agent",
sync_pb::SyncEnums_DeviceType_TYPE_PHONE, "device_id", sync_pb::SyncEnums_DeviceType_TYPE_PHONE, "device_id",
base::SysInfo::HardwareInfo(), base::SysInfo::HardwareInfo(),
......
...@@ -130,7 +130,7 @@ bool ClickToCallContextMenuObserver::IsCommandIdEnabled(int command_id) { ...@@ -130,7 +130,7 @@ bool ClickToCallContextMenuObserver::IsCommandIdEnabled(int command_id) {
void ClickToCallContextMenuObserver::ExecuteCommand(int command_id) { void ClickToCallContextMenuObserver::ExecuteCommand(int command_id) {
if (command_id == IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE) { if (command_id == IDC_CONTENT_CONTEXT_SHARING_CLICK_TO_CALL_SINGLE_DEVICE) {
DCHECK(devices_.size() == 1); DCHECK_EQ(1u, devices_.size());
SendClickToCallMessage(0); SendClickToCallMessage(0);
} }
} }
...@@ -138,7 +138,7 @@ void ClickToCallContextMenuObserver::ExecuteCommand(int command_id) { ...@@ -138,7 +138,7 @@ void ClickToCallContextMenuObserver::ExecuteCommand(int command_id) {
void ClickToCallContextMenuObserver::SendClickToCallMessage( void ClickToCallContextMenuObserver::SendClickToCallMessage(
int chosen_device_index) { int chosen_device_index) {
DCHECK(entry_point_); DCHECK(entry_point_);
if (chosen_device_index >= static_cast<int>(devices_.size())) if (size_t{chosen_device_index} >= devices_.size())
return; return;
LogSharingSelectedDeviceIndex(controller_->GetFeatureMetricsPrefix(), LogSharingSelectedDeviceIndex(controller_->GetFeatureMetricsPrefix(),
......
...@@ -127,14 +127,14 @@ bool SharedClipboardContextMenuObserver::IsCommandIdEnabled(int command_id) { ...@@ -127,14 +127,14 @@ bool SharedClipboardContextMenuObserver::IsCommandIdEnabled(int command_id) {
void SharedClipboardContextMenuObserver::ExecuteCommand(int command_id) { void SharedClipboardContextMenuObserver::ExecuteCommand(int command_id) {
if (command_id == if (command_id ==
IDC_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_SINGLE_DEVICE) { IDC_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_SINGLE_DEVICE) {
DCHECK(devices_.size() == 1); DCHECK_EQ(1u, devices_.size());
SendSharedClipboardMessage(0); SendSharedClipboardMessage(0);
} }
} }
void SharedClipboardContextMenuObserver::SendSharedClipboardMessage( void SharedClipboardContextMenuObserver::SendSharedClipboardMessage(
int chosen_device_index) { int chosen_device_index) {
if (chosen_device_index >= static_cast<int>(devices_.size())) if (size_t{chosen_device_index} >= devices_.size())
return; return;
LogSharingSelectedDeviceIndex(controller_->GetFeatureMetricsPrefix(), LogSharingSelectedDeviceIndex(controller_->GetFeatureMetricsPrefix(),
nullptr /* No suffix */, chosen_device_index); nullptr /* No suffix */, chosen_device_index);
......
...@@ -9,3 +9,6 @@ SharingDialogData::SharingDialogData() = default; ...@@ -9,3 +9,6 @@ SharingDialogData::SharingDialogData() = default;
SharingDialogData::~SharingDialogData() = default; SharingDialogData::~SharingDialogData() = default;
SharingDialogData::SharingDialogData(SharingDialogData&& other) = default; SharingDialogData::SharingDialogData(SharingDialogData&& other) = default;
SharingDialogData& SharingDialogData::operator=(SharingDialogData&& other) =
default;
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <vector> #include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/sharing/sharing_app.h" #include "chrome/browser/sharing/sharing_app.h"
#include "chrome/browser/sharing/sharing_metrics.h" #include "chrome/browser/sharing/sharing_metrics.h"
...@@ -23,6 +22,7 @@ struct SharingDialogData { ...@@ -23,6 +22,7 @@ struct SharingDialogData {
SharingDialogData(); SharingDialogData();
~SharingDialogData(); ~SharingDialogData();
SharingDialogData(SharingDialogData&& other); SharingDialogData(SharingDialogData&& other);
SharingDialogData& operator=(SharingDialogData&& other);
SharingDialogType type = SharingDialogType::kErrorDialog; SharingDialogType type = SharingDialogType::kErrorDialog;
SharingFeatureName prefix = SharingFeatureName::kUnknown; SharingFeatureName prefix = SharingFeatureName::kUnknown;
...@@ -41,9 +41,6 @@ struct SharingDialogData { ...@@ -41,9 +41,6 @@ struct SharingDialogData {
base::OnceCallback<void(const syncer::DeviceInfo&)> device_callback; base::OnceCallback<void(const syncer::DeviceInfo&)> device_callback;
base::OnceCallback<void(const SharingApp&)> app_callback; base::OnceCallback<void(const SharingApp&)> app_callback;
base::OnceCallback<void(SharingDialog*)> close_callback; base::OnceCallback<void(SharingDialog*)> close_callback;
private:
DISALLOW_COPY_AND_ASSIGN(SharingDialogData);
}; };
#endif // CHROME_BROWSER_SHARING_SHARING_DIALOG_DATA_H_ #endif // CHROME_BROWSER_SHARING_SHARING_DIALOG_DATA_H_
...@@ -49,19 +49,99 @@ SharingUiController::SharingUiController(content::WebContents* web_contents) ...@@ -49,19 +49,99 @@ SharingUiController::SharingUiController(content::WebContents* web_contents)
SharingUiController::~SharingUiController() = default; SharingUiController::~SharingUiController() = default;
void SharingUiController::CloseDialog() { base::string16 SharingUiController::GetTitle(SharingDialogType dialog_type) {
if (!dialog_) // We only handle error messages generically.
DCHECK_EQ(SharingDialogType::kErrorDialog, dialog_type);
switch (send_result()) {
case SharingSendMessageResult::kDeviceNotFound:
case SharingSendMessageResult::kNetworkError:
case SharingSendMessageResult::kAckTimeout:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TITLE_GENERIC_ERROR,
base::ToLowerASCII(GetContentType()));
case SharingSendMessageResult::kSuccessful:
NOTREACHED();
FALLTHROUGH;
case SharingSendMessageResult::kPayloadTooLarge:
case SharingSendMessageResult::kInternalError:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TITLE_INTERNAL_ERROR,
base::ToLowerASCII(GetContentType()));
}
}
base::string16 SharingUiController::GetErrorDialogText() const {
switch (send_result()) {
case SharingSendMessageResult::kDeviceNotFound:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_DEVICE_NOT_FOUND,
GetTargetDeviceName());
case SharingSendMessageResult::kNetworkError:
return l10n_util::GetStringUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_NETWORK_ERROR);
case SharingSendMessageResult::kAckTimeout:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_DEVICE_ACK_TIMEOUT,
GetTargetDeviceName());
case SharingSendMessageResult::kSuccessful:
return base::string16();
case SharingSendMessageResult::kPayloadTooLarge:
case SharingSendMessageResult::kInternalError:
return l10n_util::GetStringUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_INTERNAL_ERROR);
}
}
void SharingUiController::OnDialogClosed(SharingDialog* dialog) {
// Ignore already replaced dialogs.
if (dialog != dialog_)
return; return;
dialog_->Hide(); dialog_ = nullptr;
UpdateIcon();
}
// SharingDialog::Hide may close the dialog asynchronously, and therefore not void SharingUiController::OnHelpTextClicked(SharingDialogType dialog_type) {
// call OnDialogClosed immediately. If that is the case, call OnDialogClosed ShowSingletonTab(chrome::FindBrowserWithWebContents(web_contents()),
// now to notify subclasses and clear |dialog_|. GURL(chrome::kSyncLearnMoreURL));
if (dialog_) }
OnDialogClosed(dialog_);
DCHECK(!dialog_); void SharingUiController::OnDialogShown(bool has_devices, bool has_apps) {
if (on_dialog_shown_closure_for_testing_)
std::move(on_dialog_shown_closure_for_testing_).Run();
}
void SharingUiController::ClearLastDialog() {
last_dialog_id_++;
is_loading_ = false;
send_result_ = SharingSendMessageResult::kSuccessful;
CloseDialog();
}
void SharingUiController::UpdateAndShowDialog() {
ClearLastDialog();
DoUpdateApps(base::BindOnce(&SharingUiController::OnAppsReceived,
weak_ptr_factory_.GetWeakPtr(), last_dialog_id_));
}
std::vector<std::unique_ptr<syncer::DeviceInfo>>
SharingUiController::GetDevices() {
return sharing_service_->GetDeviceCandidates(GetRequiredFeature());
}
bool SharingUiController::HasSendFailed() const {
return send_result_ != SharingSendMessageResult::kSuccessful;
}
void SharingUiController::MaybeShowErrorDialog() {
if (HasSendFailed() && web_contents_ == GetCurrentWebContents(web_contents_))
ShowNewDialog(CreateDialogData(SharingDialogType::kErrorDialog));
} }
SharingDialogData SharingUiController::CreateDialogData( SharingDialogData SharingUiController::CreateDialogData(
...@@ -85,40 +165,6 @@ SharingDialogData SharingUiController::CreateDialogData( ...@@ -85,40 +165,6 @@ SharingDialogData SharingUiController::CreateDialogData(
return data; return data;
} }
void SharingUiController::ShowNewDialog(SharingDialogData dialog_data) {
CloseDialog();
BrowserWindow* window = GetWindowFromWebContents(web_contents_);
if (!window)
return;
bool has_devices = !dialog_data.devices.empty();
bool has_apps = !dialog_data.apps.empty();
dialog_ = window->ShowSharingDialog(web_contents(), std::move(dialog_data));
UpdateIcon();
OnDialogShown(has_devices, has_apps);
}
void SharingUiController::UpdateIcon() {
BrowserWindow* window = GetWindowFromWebContents(web_contents_);
if (!window)
return;
window->UpdatePageActionIcon(GetIconType());
}
void SharingUiController::OnDialogClosed(SharingDialog* dialog) {
// Ignore already replaced dialogs.
if (dialog != dialog_)
return;
dialog_ = nullptr;
UpdateIcon();
}
void SharingUiController::MaybeShowErrorDialog() {
if (HasSendFailed() && web_contents_ == GetCurrentWebContents(web_contents_))
ShowNewDialog(CreateDialogData(SharingDialogType::kErrorDialog));
}
void SharingUiController::SendMessageToDevice( void SharingUiController::SendMessageToDevice(
const syncer::DeviceInfo& device, const syncer::DeviceInfo& device,
chrome_browser_sharing::SharingMessage sharing_message) { chrome_browser_sharing::SharingMessage sharing_message) {
...@@ -134,86 +180,54 @@ void SharingUiController::SendMessageToDevice( ...@@ -134,86 +180,54 @@ void SharingUiController::SendMessageToDevice(
weak_ptr_factory_.GetWeakPtr(), last_dialog_id_)); weak_ptr_factory_.GetWeakPtr(), last_dialog_id_));
} }
void SharingUiController::OnMessageSentToDevice( void SharingUiController::UpdateIcon() {
int dialog_id, BrowserWindow* window = GetWindowFromWebContents(web_contents_);
SharingSendMessageResult result) { if (!window)
if (dialog_id != last_dialog_id_)
return; return;
is_loading_ = false; window->UpdatePageActionIcon(GetIconType());
send_result_ = result;
UpdateIcon();
} }
void SharingUiController::ClearLastDialog() { void SharingUiController::CloseDialog() {
last_dialog_id_++; if (!dialog_)
is_loading_ = false; return;
send_result_ = SharingSendMessageResult::kSuccessful;
CloseDialog();
}
void SharingUiController::UpdateAndShowDialog() { dialog_->Hide();
ClearLastDialog();
DoUpdateApps(base::BindOnce(&SharingUiController::OnAppsReceived, // SharingDialog::Hide may close the dialog asynchronously, and therefore not
weak_ptr_factory_.GetWeakPtr(), last_dialog_id_)); // call OnDialogClosed immediately. If that is the case, call OnDialogClosed
// now to notify subclasses and clear |dialog_|.
if (dialog_)
OnDialogClosed(dialog_);
DCHECK(!dialog_);
} }
std::vector<std::unique_ptr<syncer::DeviceInfo>> void SharingUiController::ShowNewDialog(SharingDialogData dialog_data) {
SharingUiController::GetDevices() { CloseDialog();
return sharing_service_->GetDeviceCandidates(GetRequiredFeature()); BrowserWindow* window = GetWindowFromWebContents(web_contents_);
if (!window)
return;
bool has_devices = !dialog_data.devices.empty();
bool has_apps = !dialog_data.apps.empty();
dialog_ = window->ShowSharingDialog(web_contents(), std::move(dialog_data));
UpdateIcon();
OnDialogShown(has_devices, has_apps);
} }
base::string16 SharingUiController::GetTargetDeviceName() const { base::string16 SharingUiController::GetTargetDeviceName() const {
return base::UTF8ToUTF16(target_device_name_); return base::UTF8ToUTF16(target_device_name_);
} }
base::string16 SharingUiController::GetTitle(SharingDialogType dialog_type) { void SharingUiController::OnMessageSentToDevice(
// We only handle error messages generically. int dialog_id,
DCHECK_EQ(SharingDialogType::kErrorDialog, dialog_type); SharingSendMessageResult result) {
switch (send_result()) { if (dialog_id != last_dialog_id_)
case SharingSendMessageResult::kDeviceNotFound: return;
case SharingSendMessageResult::kNetworkError:
case SharingSendMessageResult::kAckTimeout:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TITLE_GENERIC_ERROR,
base::ToLowerASCII(GetContentType()));
case SharingSendMessageResult::kSuccessful:
NOTREACHED();
FALLTHROUGH;
case SharingSendMessageResult::kPayloadTooLarge:
case SharingSendMessageResult::kInternalError:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TITLE_INTERNAL_ERROR,
base::ToLowerASCII(GetContentType()));
}
}
base::string16 SharingUiController::GetErrorDialogText() const {
switch (send_result()) {
case SharingSendMessageResult::kDeviceNotFound:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_DEVICE_NOT_FOUND,
GetTargetDeviceName());
case SharingSendMessageResult::kNetworkError:
return l10n_util::GetStringUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_NETWORK_ERROR);
case SharingSendMessageResult::kAckTimeout:
return l10n_util::GetStringFUTF16(
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_DEVICE_ACK_TIMEOUT,
GetTargetDeviceName());
case SharingSendMessageResult::kSuccessful:
return base::string16();
case SharingSendMessageResult::kPayloadTooLarge: is_loading_ = false;
case SharingSendMessageResult::kInternalError: send_result_ = result;
return l10n_util::GetStringUTF16( UpdateIcon();
IDS_BROWSER_SHARING_ERROR_DIALOG_TEXT_INTERNAL_ERROR);
}
} }
void SharingUiController::OnAppsReceived(int dialog_id, void SharingUiController::OnAppsReceived(int dialog_id,
...@@ -230,17 +244,3 @@ void SharingUiController::OnAppsReceived(int dialog_id, ...@@ -230,17 +244,3 @@ void SharingUiController::OnAppsReceived(int dialog_id,
ShowNewDialog(std::move(dialog_data)); ShowNewDialog(std::move(dialog_data));
} }
bool SharingUiController::HasSendFailed() const {
return send_result_ != SharingSendMessageResult::kSuccessful;
}
void SharingUiController::OnHelpTextClicked(SharingDialogType dialog_type) {
ShowSingletonTab(chrome::FindBrowserWithWebContents(web_contents()),
GURL(chrome::kSyncLearnMoreURL));
}
void SharingUiController::OnDialogShown(bool has_devices, bool has_apps) {
if (on_dialog_shown_closure_for_testing_)
std::move(on_dialog_shown_closure_for_testing_).Run();
}
...@@ -57,9 +57,18 @@ class SharingUiController { ...@@ -57,9 +57,18 @@ class SharingUiController {
virtual base::string16 GetTextForTooltipAndAccessibleName() const = 0; virtual base::string16 GetTextForTooltipAndAccessibleName() const = 0;
// Get the name of the feature to be used as a prefix for the metric name. // Get the name of the feature to be used as a prefix for the metric name.
virtual SharingFeatureName GetFeatureMetricsPrefix() const = 0; virtual SharingFeatureName GetFeatureMetricsPrefix() const = 0;
// Describes the content type of shared data.
virtual base::string16 GetContentType() const = 0;
// Returns the message to be shown in the body of error dialog based on
// |send_result_|.
virtual base::string16 GetErrorDialogText() const;
// Called by the SharingDialog when it is being closed. // Called by the SharingDialog when it is being closed.
virtual void OnDialogClosed(SharingDialog* dialog); virtual void OnDialogClosed(SharingDialog* dialog);
// Called by the SharingDialogView when the help text got clicked.
virtual void OnHelpTextClicked(SharingDialogType dialog_type);
// Called when a new dialog is shown.
virtual void OnDialogShown(bool has_devices, bool has_apps);
// Closes the current dialog and resets all state. // Closes the current dialog and resets all state.
void ClearLastDialog(); void ClearLastDialog();
...@@ -70,12 +79,9 @@ class SharingUiController { ...@@ -70,12 +79,9 @@ class SharingUiController {
// Gets the current list of devices that support the required feature. // Gets the current list of devices that support the required feature.
std::vector<std::unique_ptr<syncer::DeviceInfo>> GetDevices(); std::vector<std::unique_ptr<syncer::DeviceInfo>> GetDevices();
// Describes the content type of shared data. bool HasSendFailed() const;
virtual base::string16 GetContentType() const = 0;
// Returns the message to be shown in the body of error dialog based on void MaybeShowErrorDialog();
// |send_result_|.
virtual base::string16 GetErrorDialogText() const;
// Returns the currently open SharingDialog or nullptr if there is no // Returns the currently open SharingDialog or nullptr if there is no
// dialog open. // dialog open.
...@@ -85,33 +91,21 @@ class SharingUiController { ...@@ -85,33 +91,21 @@ class SharingUiController {
void set_send_result_for_testing(SharingSendMessageResult result) { void set_send_result_for_testing(SharingSendMessageResult result) {
send_result_ = result; send_result_ = result;
} }
bool HasSendFailed() const;
content::WebContents* web_contents() const { return web_contents_; } content::WebContents* web_contents() const { return web_contents_; }
void MaybeShowErrorDialog();
// Called by the SharingDialogView when the help text got clicked.
virtual void OnHelpTextClicked(SharingDialogType dialog_type);
// Called when a new dialog is shown.
virtual void OnDialogShown(bool has_devices, bool has_apps);
void set_on_dialog_shown_closure_for_testing(base::OnceClosure closure) { void set_on_dialog_shown_closure_for_testing(base::OnceClosure closure) {
on_dialog_shown_closure_for_testing_ = std::move(closure); on_dialog_shown_closure_for_testing_ = std::move(closure);
} }
protected: protected:
virtual void DoUpdateApps(UpdateAppsCallback callback) = 0; virtual void DoUpdateApps(UpdateAppsCallback callback) = 0;
// Prepares a new dialog data.
virtual SharingDialogData CreateDialogData(SharingDialogType dialog_type);
void SendMessageToDevice( void SendMessageToDevice(
const syncer::DeviceInfo& device, const syncer::DeviceInfo& device,
chrome_browser_sharing::SharingMessage sharing_message); chrome_browser_sharing::SharingMessage sharing_message);
// Prepares a new dialog data.
virtual SharingDialogData CreateDialogData(SharingDialogType dialog_type);
private: private:
// Updates the omnibox icon if available. // Updates the omnibox icon if available.
void UpdateIcon(); void UpdateIcon();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "components/sync_device_info/device_info.h" #include "components/sync_device_info/device_info.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/border.h" #include "ui/views/border.h"
...@@ -171,8 +172,7 @@ void SharingDialogView::ButtonPressed(views::Button* sender, ...@@ -171,8 +172,7 @@ void SharingDialogView::ButtonPressed(views::Button* sender,
DCHECK(data_.app_callback); DCHECK(data_.app_callback);
if (!sender || sender->tag() < 0) if (!sender || sender->tag() < 0)
return; return;
size_t index = static_cast<size_t>(sender->tag()); size_t index{sender->tag()};
DCHECK(index < data_.devices.size() + data_.apps.size());
if (index < data_.devices.size()) { if (index < data_.devices.size()) {
LogSharingSelectedDeviceIndex(data_.prefix, kSharingUiDialog, index); LogSharingSelectedDeviceIndex(data_.prefix, kSharingUiDialog, index);
...@@ -195,7 +195,7 @@ void SharingDialogView::MaybeShowHeaderImage() { ...@@ -195,7 +195,7 @@ void SharingDialogView::MaybeShowHeaderImage() {
if (!frame_view) if (!frame_view)
return; return;
int image_id = GetNativeTheme()->ShouldUseDarkColors() int image_id = color_utils::IsDark(frame_view->GetBackgroundColor())
? data_.header_image_dark ? data_.header_image_dark
: data_.header_image_light; : data_.header_image_light;
if (!image_id) { if (!image_id) {
......
...@@ -511,6 +511,10 @@ void BubbleFrameView::SetBackgroundColor(SkColor color) { ...@@ -511,6 +511,10 @@ void BubbleFrameView::SetBackgroundColor(SkColor color) {
SchedulePaint(); SchedulePaint();
} }
SkColor BubbleFrameView::GetBackgroundColor() const {
return bubble_border_->background_color();
}
gfx::Rect BubbleFrameView::GetUpdatedWindowBounds( gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(
const gfx::Rect& anchor_rect, const gfx::Rect& anchor_rect,
const BubbleBorder::Arrow delegate_arrow, const BubbleBorder::Arrow delegate_arrow,
......
...@@ -135,6 +135,7 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView, ...@@ -135,6 +135,7 @@ class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
// Set the background color of the bubble border. // Set the background color of the bubble border.
void SetBackgroundColor(SkColor color); void SetBackgroundColor(SkColor color);
SkColor GetBackgroundColor() const;
// Given the size of the contents and the rect to point at, returns the bounds // Given the size of the contents and the rect to point at, returns the bounds
// of the bubble window. The bubble's arrow location may change if the bubble // of the bubble window. The bubble's arrow location may change if the bubble
......
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