Commit 87d09290 authored by juncai's avatar juncai Committed by Commit bot

Show device connection and paired status in chooser on Mac

This CL added code to show an icon for connected device in the
chooser, and show "Paired" text below the device name if the
device is paired.

I uploaded some screenshots in the issue page.

BUG=543466

Review-Url: https://codereview.chromium.org/2304213002
Cr-Commit-Position: refs/heads/master@{#418774}
parent aa83588d
......@@ -15104,6 +15104,9 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@gmail.com</ex
<message name="IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT" desc="Text of the 'Get help' link at the bottom of the chooser popup.">
Get help
</message>
<message name="IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT" desc="The label that is used to inform the user that the device is paired.">
Paired
</message>
</if>
<if expr="is_android">
......
......@@ -58,3 +58,11 @@ bool ChooserController::ShouldShowIconBeforeText() const {
int ChooserController::GetSignalStrengthLevel(size_t index) const {
return -1;
}
bool ChooserController::IsConnected(size_t index) const {
return false;
}
bool ChooserController::IsPaired(size_t index) const {
return false;
}
......@@ -85,6 +85,14 @@ class ChooserController {
// The |index|th option string which is listed in the chooser.
virtual base::string16 GetOption(size_t index) const = 0;
// Returns if the |index|th option is connected.
// This function returns false by default.
virtual bool IsConnected(size_t index) const;
// Returns if the |index|th option is paired.
// This function returns false by default.
virtual bool IsPaired(size_t index) const;
// Refresh the list of options.
virtual void RefreshOptions() = 0;
......
......@@ -44,6 +44,16 @@ base::string16 MockChooserController::GetOption(size_t index) const {
return options_[index].name;
}
bool MockChooserController::IsConnected(size_t index) const {
return options_[index].connected_paired_status &
ConnectedPairedStatus::CONNECTED;
}
bool MockChooserController::IsPaired(size_t index) const {
return options_[index].connected_paired_status &
ConnectedPairedStatus::PAIRED;
}
base::string16 MockChooserController::GetStatus() const {
return status_text_;
}
......@@ -98,8 +108,10 @@ void MockChooserController::OnDiscoveryStateChanged(
}
void MockChooserController::OptionAdded(const base::string16& option_name,
int signal_strength_level) {
options_.push_back({option_name, signal_strength_level});
int signal_strength_level,
int connected_paired_status) {
options_.push_back(
{option_name, signal_strength_level, connected_paired_status});
if (view())
view()->OnOptionAdded(options_.size() - 1);
}
......@@ -121,20 +133,22 @@ void MockChooserController::OptionRemoved(const base::string16& option_name) {
void MockChooserController::OptionUpdated(
const base::string16& previous_option_name,
const base::string16& new_option_name,
int new_signal_strength_level) {
int new_signal_strength_level,
int new_connected_paired_status) {
auto it = std::find_if(options_.begin(), options_.end(),
[&previous_option_name](const OptionInfo& option) {
return option.name == previous_option_name;
});
if (it != options_.end()) {
*it = {new_option_name, new_signal_strength_level};
*it = {new_option_name, new_signal_strength_level,
new_connected_paired_status};
if (view())
view()->OnOptionUpdated(it - options_.begin());
}
}
const int MockChooserController::kNoImage = -1;
const int MockChooserController::kNoSignalStrengthLevelImage = -1;
const int MockChooserController::kSignalStrengthLevel0Bar = 0;
const int MockChooserController::kSignalStrengthLevel1Bar = 1;
const int MockChooserController::kSignalStrengthLevel2Bar = 2;
......
......@@ -14,6 +14,12 @@
class MockChooserController : public ChooserController {
public:
enum ConnectedPairedStatus {
NONE = 0,
CONNECTED = 1 << 0,
PAIRED = 1 << 1,
};
explicit MockChooserController(content::RenderFrameHost* owner);
~MockChooserController() override;
......@@ -24,6 +30,8 @@ class MockChooserController : public ChooserController {
size_t NumOptions() const override;
int GetSignalStrengthLevel(size_t index) const override;
base::string16 GetOption(size_t index) const override;
bool IsConnected(size_t index) const override;
bool IsPaired(size_t index) const override;
base::string16 GetStatus() const override;
MOCK_METHOD0(RefreshOptions, void());
MOCK_METHOD1(Select, void(size_t index));
......@@ -36,13 +44,15 @@ class MockChooserController : public ChooserController {
void OnDiscoveryStateChanged(content::BluetoothChooser::DiscoveryState state);
void OptionAdded(const base::string16& option_name,
int signal_strength_level);
int signal_strength_level,
int connected_paired_status);
void OptionRemoved(const base::string16& option_name);
void OptionUpdated(const base::string16& previous_option_name,
const base::string16& new_option_name,
int new_signal_strengh_level);
int new_signal_strengh_level,
int new_connected_paired_status);
static const int kNoImage;
static const int kNoSignalStrengthLevelImage;
static const int kSignalStrengthLevel0Bar;
static const int kSignalStrengthLevel1Bar;
static const int kSignalStrengthLevel2Bar;
......@@ -55,6 +65,8 @@ class MockChooserController : public ChooserController {
struct OptionInfo {
base::string16 name;
int signal_strength_level;
// This value is the '|' of ConnectedPairedStatus values.
int connected_paired_status;
};
std::vector<OptionInfo> options_;
......
......@@ -67,6 +67,14 @@ int BluetoothChooserController::GetSignalStrengthLevel(size_t index) const {
return devices_[index].signal_strength_level;
}
bool BluetoothChooserController::IsConnected(size_t index) const {
return devices_[index].is_connected;
}
bool BluetoothChooserController::IsPaired(size_t index) const {
return devices_[index].is_paired;
}
base::string16 BluetoothChooserController::GetOption(size_t index) const {
DCHECK_LT(index, devices_.size());
const std::string& device_id = devices_[index].id;
......@@ -208,19 +216,20 @@ void BluetoothChooserController::AddOrUpdateDevice(
});
DCHECK(device_it != devices_.end());
// http://crbug.com/543466 Update connection and paired status
// When Bluetooth device scanning stops, the |signal_strength_level|
// is -1, and in this case, should still use the previously stored
// signal strength level value.
if (signal_strength_level != -1)
device_it->signal_strength_level = signal_strength_level;
device_it->is_connected = is_gatt_connected;
device_it->is_paired = is_paired;
if (view())
view()->OnOptionUpdated(device_it - devices_.begin());
return;
}
devices_.push_back({device_id, signal_strength_level});
devices_.push_back(
{device_id, signal_strength_level, is_gatt_connected, is_paired});
device_id_to_name_map_.insert({device_id, device_name});
++device_name_counts_[device_name];
if (view())
......
......@@ -33,6 +33,8 @@ class BluetoothChooserController : public ChooserController {
base::string16 GetOkButtonLabel() const override;
size_t NumOptions() const override;
int GetSignalStrengthLevel(size_t index) const override;
bool IsConnected(size_t index) const override;
bool IsPaired(size_t index) const override;
base::string16 GetOption(size_t index) const override;
void RefreshOptions() override;
base::string16 GetStatus() const override;
......@@ -69,6 +71,8 @@ class BluetoothChooserController : public ChooserController {
struct BluetoothDeviceInfo {
std::string id;
int signal_strength_level;
bool is_connected;
bool is_paired;
};
// Clears |device_names_and_ids_| and |device_name_counts_|. Called when
......
......@@ -71,7 +71,7 @@ class ChooserController;
- (base::scoped_nsobject<NSTextField>)createChooserTitle:(NSString*)title;
// Creates a table row view for the chooser.
- (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)rowIndex;
- (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)row;
// The height of a table row view.
- (CGFloat)tableRowViewHeight:(NSInteger)row;
......@@ -88,9 +88,6 @@ class ChooserController;
// Creates the separator.
- (base::scoped_nsobject<NSBox>)createSeparator;
// Creates a text field with |text|.
- (base::scoped_nsobject<NSTextField>)createTextField:(NSString*)text;
// Creates a hyperlink button with |text|.
- (base::scoped_nsobject<NSButton>)createHyperlinkButtonWithText:
(NSString*)text;
......@@ -164,6 +161,9 @@ class ChooserController;
// Gets the text from table row view. For testing only.
- (NSTextField*)tableRowViewText:(NSInteger)row;
// Gets the paired status from table row view. For testing only.
- (NSTextField*)tableRowViewPairedStatus:(NSInteger)row;
@end
#endif // CHROME_BROWSER_UI_COCOA_CHOOSER_CONTENT_VIEW_COCOA_H_
......@@ -47,8 +47,8 @@ initWithChooserDialogCocoa:(ChooserDialogCocoa*)chooserDialogCocoa
- (NSView*)tableView:(NSTableView*)tableView
viewForTableColumn:(NSTableColumn*)tableColumn
row:(NSInteger)rowIndex {
return [chooserContentView_ createTableRowView:rowIndex].autorelease();
row:(NSInteger)row {
return [chooserContentView_ createTableRowView:row].autorelease();
}
- (BOOL)tableView:(NSTableView*)aTableView
......
......@@ -190,8 +190,8 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
- (NSView*)tableView:(NSTableView*)tableView
viewForTableColumn:(NSTableColumn*)tableColumn
row:(NSInteger)rowIndex {
return [chooserContentView_ createTableRowView:rowIndex].autorelease();
row:(NSInteger)row {
return [chooserContentView_ createTableRowView:row].autorelease();
}
- (BOOL)tableView:(NSTableView*)aTableView
......
......@@ -352,9 +352,8 @@ void BluetoothDeviceChooserController::AddFilteredDevice(
base::Optional<int8_t> rssi = device.GetInquiryRSSI();
chooser_->AddOrUpdateDevice(
device.GetAddress(), !!device.GetName() /* should_update_name */,
device.GetNameForDisplay(),
// TODO(http://crbug.com/543466): Show connection and paired status.
false /* is_gatt_connected */, false /* is_paired */,
device.GetNameForDisplay(), device.IsGattConnected(),
web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
}
}
......
......@@ -206,6 +206,12 @@ void WebBluetoothServiceImpl::SetClientConnectionErrorHandler(
binding_.set_connection_error_handler(closure);
}
bool WebBluetoothServiceImpl::IsDevicePaired(
const std::string& device_address) {
return allowed_devices_map_.GetDeviceId(GetOrigin(), device_address) !=
nullptr;
}
void WebBluetoothServiceImpl::DidFinishNavigation(
NavigationHandle* navigation_handle) {
if (navigation_handle->HasCommitted() &&
......
......@@ -61,6 +61,10 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
// Sets the connection error handler for WebBluetoothServiceImpl's Binding.
void SetClientConnectionErrorHandler(base::Closure closure);
// Returns whether the device is paired with the |render_frame_host_|'s
// GetLastCommittedOrigin().
bool IsDevicePaired(const std::string& device_address);
private:
friend class FrameConnectedBluetoothDevicesTest;
typedef base::Callback<void(device::BluetoothDevice*)>
......
......@@ -17,6 +17,7 @@ action("aggregate_vector_icons") {
"bar_close.1x.icon",
"bar_close.icon",
"blocked_badge.icon",
"bluetooth_connected.icon",
"browser_tools.icon",
"browser_tools_error.icon",
"browser_tools_update.icon",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
MOVE_TO, 14, 24,
R_LINE_TO, -4, -4,
R_LINE_TO, -4, 4,
R_LINE_TO, 4, 4,
R_LINE_TO, 4, -4,
CLOSE,
R_MOVE_TO, 21.41f, -8.59f,
LINE_TO, 24, 4,
R_H_LINE_TO, -2,
R_V_LINE_TO, 15.17f,
LINE_TO, 12.83f, 10,
LINE_TO, 10, 12.83f,
LINE_TO, 21.17f, 24,
LINE_TO, 10, 35.17f,
LINE_TO, 12.83f, 38,
LINE_TO, 22, 28.83f,
V_LINE_TO, 44,
R_H_LINE_TO, 2,
R_LINE_TO, 11.41f, -11.41f,
LINE_TO, 26.83f, 24,
R_LINE_TO, 8.58f, -8.59f,
CLOSE,
MOVE_TO, 26, 11.66f,
R_LINE_TO, 3.76f, 3.76f,
LINE_TO, 26, 19.17f,
R_V_LINE_TO, -7.51f,
CLOSE,
R_MOVE_TO, 3.76f, 20.93f,
LINE_TO, 26, 36.34f,
R_V_LINE_TO, -7.52f,
R_LINE_TO, 3.76f, 3.77f,
CLOSE,
MOVE_TO, 38, 20,
R_LINE_TO, -4, 4,
R_LINE_TO, 4, 4,
R_LINE_TO, 4, -4,
R_LINE_TO, -4, -4,
CLOSE,
END
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