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 ...@@ -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."> <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 Get help
</message> </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>
<if expr="is_android"> <if expr="is_android">
......
...@@ -58,3 +58,11 @@ bool ChooserController::ShouldShowIconBeforeText() const { ...@@ -58,3 +58,11 @@ bool ChooserController::ShouldShowIconBeforeText() const {
int ChooserController::GetSignalStrengthLevel(size_t index) const { int ChooserController::GetSignalStrengthLevel(size_t index) const {
return -1; 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 { ...@@ -85,6 +85,14 @@ class ChooserController {
// The |index|th option string which is listed in the chooser. // The |index|th option string which is listed in the chooser.
virtual base::string16 GetOption(size_t index) const = 0; 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. // Refresh the list of options.
virtual void RefreshOptions() = 0; virtual void RefreshOptions() = 0;
......
...@@ -44,6 +44,16 @@ base::string16 MockChooserController::GetOption(size_t index) const { ...@@ -44,6 +44,16 @@ base::string16 MockChooserController::GetOption(size_t index) const {
return options_[index].name; 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 { base::string16 MockChooserController::GetStatus() const {
return status_text_; return status_text_;
} }
...@@ -98,8 +108,10 @@ void MockChooserController::OnDiscoveryStateChanged( ...@@ -98,8 +108,10 @@ void MockChooserController::OnDiscoveryStateChanged(
} }
void MockChooserController::OptionAdded(const base::string16& option_name, void MockChooserController::OptionAdded(const base::string16& option_name,
int signal_strength_level) { int signal_strength_level,
options_.push_back({option_name, signal_strength_level}); int connected_paired_status) {
options_.push_back(
{option_name, signal_strength_level, connected_paired_status});
if (view()) if (view())
view()->OnOptionAdded(options_.size() - 1); view()->OnOptionAdded(options_.size() - 1);
} }
...@@ -121,20 +133,22 @@ void MockChooserController::OptionRemoved(const base::string16& option_name) { ...@@ -121,20 +133,22 @@ void MockChooserController::OptionRemoved(const base::string16& option_name) {
void MockChooserController::OptionUpdated( void MockChooserController::OptionUpdated(
const base::string16& previous_option_name, const base::string16& previous_option_name,
const base::string16& new_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(), auto it = std::find_if(options_.begin(), options_.end(),
[&previous_option_name](const OptionInfo& option) { [&previous_option_name](const OptionInfo& option) {
return option.name == previous_option_name; return option.name == previous_option_name;
}); });
if (it != options_.end()) { 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()) if (view())
view()->OnOptionUpdated(it - options_.begin()); view()->OnOptionUpdated(it - options_.begin());
} }
} }
const int MockChooserController::kNoImage = -1; const int MockChooserController::kNoSignalStrengthLevelImage = -1;
const int MockChooserController::kSignalStrengthLevel0Bar = 0; const int MockChooserController::kSignalStrengthLevel0Bar = 0;
const int MockChooserController::kSignalStrengthLevel1Bar = 1; const int MockChooserController::kSignalStrengthLevel1Bar = 1;
const int MockChooserController::kSignalStrengthLevel2Bar = 2; const int MockChooserController::kSignalStrengthLevel2Bar = 2;
......
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
class MockChooserController : public ChooserController { class MockChooserController : public ChooserController {
public: public:
enum ConnectedPairedStatus {
NONE = 0,
CONNECTED = 1 << 0,
PAIRED = 1 << 1,
};
explicit MockChooserController(content::RenderFrameHost* owner); explicit MockChooserController(content::RenderFrameHost* owner);
~MockChooserController() override; ~MockChooserController() override;
...@@ -24,6 +30,8 @@ class MockChooserController : public ChooserController { ...@@ -24,6 +30,8 @@ class MockChooserController : public ChooserController {
size_t NumOptions() const override; size_t NumOptions() const override;
int GetSignalStrengthLevel(size_t index) const override; int GetSignalStrengthLevel(size_t index) const override;
base::string16 GetOption(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; base::string16 GetStatus() const override;
MOCK_METHOD0(RefreshOptions, void()); MOCK_METHOD0(RefreshOptions, void());
MOCK_METHOD1(Select, void(size_t index)); MOCK_METHOD1(Select, void(size_t index));
...@@ -36,13 +44,15 @@ class MockChooserController : public ChooserController { ...@@ -36,13 +44,15 @@ class MockChooserController : public ChooserController {
void OnDiscoveryStateChanged(content::BluetoothChooser::DiscoveryState state); void OnDiscoveryStateChanged(content::BluetoothChooser::DiscoveryState state);
void OptionAdded(const base::string16& option_name, 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 OptionRemoved(const base::string16& option_name);
void OptionUpdated(const base::string16& previous_option_name, void OptionUpdated(const base::string16& previous_option_name,
const base::string16& new_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 kSignalStrengthLevel0Bar;
static const int kSignalStrengthLevel1Bar; static const int kSignalStrengthLevel1Bar;
static const int kSignalStrengthLevel2Bar; static const int kSignalStrengthLevel2Bar;
...@@ -55,6 +65,8 @@ class MockChooserController : public ChooserController { ...@@ -55,6 +65,8 @@ class MockChooserController : public ChooserController {
struct OptionInfo { struct OptionInfo {
base::string16 name; base::string16 name;
int signal_strength_level; int signal_strength_level;
// This value is the '|' of ConnectedPairedStatus values.
int connected_paired_status;
}; };
std::vector<OptionInfo> options_; std::vector<OptionInfo> options_;
......
...@@ -67,6 +67,14 @@ int BluetoothChooserController::GetSignalStrengthLevel(size_t index) const { ...@@ -67,6 +67,14 @@ int BluetoothChooserController::GetSignalStrengthLevel(size_t index) const {
return devices_[index].signal_strength_level; 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 { base::string16 BluetoothChooserController::GetOption(size_t index) const {
DCHECK_LT(index, devices_.size()); DCHECK_LT(index, devices_.size());
const std::string& device_id = devices_[index].id; const std::string& device_id = devices_[index].id;
...@@ -208,19 +216,20 @@ void BluetoothChooserController::AddOrUpdateDevice( ...@@ -208,19 +216,20 @@ void BluetoothChooserController::AddOrUpdateDevice(
}); });
DCHECK(device_it != devices_.end()); DCHECK(device_it != devices_.end());
// http://crbug.com/543466 Update connection and paired status
// When Bluetooth device scanning stops, the |signal_strength_level| // When Bluetooth device scanning stops, the |signal_strength_level|
// is -1, and in this case, should still use the previously stored // is -1, and in this case, should still use the previously stored
// signal strength level value. // signal strength level value.
if (signal_strength_level != -1) if (signal_strength_level != -1)
device_it->signal_strength_level = signal_strength_level; device_it->signal_strength_level = signal_strength_level;
device_it->is_connected = is_gatt_connected;
device_it->is_paired = is_paired;
if (view()) if (view())
view()->OnOptionUpdated(device_it - devices_.begin()); view()->OnOptionUpdated(device_it - devices_.begin());
return; 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_id_to_name_map_.insert({device_id, device_name});
++device_name_counts_[device_name]; ++device_name_counts_[device_name];
if (view()) if (view())
......
...@@ -33,6 +33,8 @@ class BluetoothChooserController : public ChooserController { ...@@ -33,6 +33,8 @@ class BluetoothChooserController : public ChooserController {
base::string16 GetOkButtonLabel() const override; base::string16 GetOkButtonLabel() const override;
size_t NumOptions() const override; size_t NumOptions() const override;
int GetSignalStrengthLevel(size_t index) 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; base::string16 GetOption(size_t index) const override;
void RefreshOptions() override; void RefreshOptions() override;
base::string16 GetStatus() const override; base::string16 GetStatus() const override;
...@@ -69,6 +71,8 @@ class BluetoothChooserController : public ChooserController { ...@@ -69,6 +71,8 @@ class BluetoothChooserController : public ChooserController {
struct BluetoothDeviceInfo { struct BluetoothDeviceInfo {
std::string id; std::string id;
int signal_strength_level; int signal_strength_level;
bool is_connected;
bool is_paired;
}; };
// Clears |device_names_and_ids_| and |device_name_counts_|. Called when // Clears |device_names_and_ids_| and |device_name_counts_|. Called when
......
...@@ -71,7 +71,7 @@ class ChooserController; ...@@ -71,7 +71,7 @@ class ChooserController;
- (base::scoped_nsobject<NSTextField>)createChooserTitle:(NSString*)title; - (base::scoped_nsobject<NSTextField>)createChooserTitle:(NSString*)title;
// Creates a table row view for the chooser. // 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. // The height of a table row view.
- (CGFloat)tableRowViewHeight:(NSInteger)row; - (CGFloat)tableRowViewHeight:(NSInteger)row;
...@@ -88,9 +88,6 @@ class ChooserController; ...@@ -88,9 +88,6 @@ class ChooserController;
// Creates the separator. // Creates the separator.
- (base::scoped_nsobject<NSBox>)createSeparator; - (base::scoped_nsobject<NSBox>)createSeparator;
// Creates a text field with |text|.
- (base::scoped_nsobject<NSTextField>)createTextField:(NSString*)text;
// Creates a hyperlink button with |text|. // Creates a hyperlink button with |text|.
- (base::scoped_nsobject<NSButton>)createHyperlinkButtonWithText: - (base::scoped_nsobject<NSButton>)createHyperlinkButtonWithText:
(NSString*)text; (NSString*)text;
...@@ -164,6 +161,9 @@ class ChooserController; ...@@ -164,6 +161,9 @@ class ChooserController;
// Gets the text from table row view. For testing only. // Gets the text from table row view. For testing only.
- (NSTextField*)tableRowViewText:(NSInteger)row; - (NSTextField*)tableRowViewText:(NSInteger)row;
// Gets the paired status from table row view. For testing only.
- (NSTextField*)tableRowViewPairedStatus:(NSInteger)row;
@end @end
#endif // CHROME_BROWSER_UI_COCOA_CHOOSER_CONTENT_VIEW_COCOA_H_ #endif // CHROME_BROWSER_UI_COCOA_CHOOSER_CONTENT_VIEW_COCOA_H_
...@@ -47,8 +47,8 @@ initWithChooserDialogCocoa:(ChooserDialogCocoa*)chooserDialogCocoa ...@@ -47,8 +47,8 @@ initWithChooserDialogCocoa:(ChooserDialogCocoa*)chooserDialogCocoa
- (NSView*)tableView:(NSTableView*)tableView - (NSView*)tableView:(NSTableView*)tableView
viewForTableColumn:(NSTableColumn*)tableColumn viewForTableColumn:(NSTableColumn*)tableColumn
row:(NSInteger)rowIndex { row:(NSInteger)row {
return [chooserContentView_ createTableRowView:rowIndex].autorelease(); return [chooserContentView_ createTableRowView:row].autorelease();
} }
- (BOOL)tableView:(NSTableView*)aTableView - (BOOL)tableView:(NSTableView*)aTableView
......
...@@ -190,8 +190,8 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { ...@@ -190,8 +190,8 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
- (NSView*)tableView:(NSTableView*)tableView - (NSView*)tableView:(NSTableView*)tableView
viewForTableColumn:(NSTableColumn*)tableColumn viewForTableColumn:(NSTableColumn*)tableColumn
row:(NSInteger)rowIndex { row:(NSInteger)row {
return [chooserContentView_ createTableRowView:rowIndex].autorelease(); return [chooserContentView_ createTableRowView:row].autorelease();
} }
- (BOOL)tableView:(NSTableView*)aTableView - (BOOL)tableView:(NSTableView*)aTableView
......
...@@ -352,9 +352,8 @@ void BluetoothDeviceChooserController::AddFilteredDevice( ...@@ -352,9 +352,8 @@ void BluetoothDeviceChooserController::AddFilteredDevice(
base::Optional<int8_t> rssi = device.GetInquiryRSSI(); base::Optional<int8_t> rssi = device.GetInquiryRSSI();
chooser_->AddOrUpdateDevice( chooser_->AddOrUpdateDevice(
device.GetAddress(), !!device.GetName() /* should_update_name */, device.GetAddress(), !!device.GetName() /* should_update_name */,
device.GetNameForDisplay(), device.GetNameForDisplay(), device.IsGattConnected(),
// TODO(http://crbug.com/543466): Show connection and paired status. web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
false /* is_gatt_connected */, false /* is_paired */,
rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1); rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
} }
} }
......
...@@ -206,6 +206,12 @@ void WebBluetoothServiceImpl::SetClientConnectionErrorHandler( ...@@ -206,6 +206,12 @@ void WebBluetoothServiceImpl::SetClientConnectionErrorHandler(
binding_.set_connection_error_handler(closure); 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( void WebBluetoothServiceImpl::DidFinishNavigation(
NavigationHandle* navigation_handle) { NavigationHandle* navigation_handle) {
if (navigation_handle->HasCommitted() && if (navigation_handle->HasCommitted() &&
......
...@@ -61,6 +61,10 @@ class CONTENT_EXPORT WebBluetoothServiceImpl ...@@ -61,6 +61,10 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
// Sets the connection error handler for WebBluetoothServiceImpl's Binding. // Sets the connection error handler for WebBluetoothServiceImpl's Binding.
void SetClientConnectionErrorHandler(base::Closure closure); 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: private:
friend class FrameConnectedBluetoothDevicesTest; friend class FrameConnectedBluetoothDevicesTest;
typedef base::Callback<void(device::BluetoothDevice*)> typedef base::Callback<void(device::BluetoothDevice*)>
......
...@@ -17,6 +17,7 @@ action("aggregate_vector_icons") { ...@@ -17,6 +17,7 @@ action("aggregate_vector_icons") {
"bar_close.1x.icon", "bar_close.1x.icon",
"bar_close.icon", "bar_close.icon",
"blocked_badge.icon", "blocked_badge.icon",
"bluetooth_connected.icon",
"browser_tools.icon", "browser_tools.icon",
"browser_tools_error.icon", "browser_tools_error.icon",
"browser_tools_update.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