network_info_bubble.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_NETWORK_NETWORK_INFO_BUBBLE_H_
  5. #define ASH_SYSTEM_NETWORK_NETWORK_INFO_BUBBLE_H_
  6. #include <string>
  7. #include "ash/ash_export.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "ui/events/event.h"
  10. #include "ui/gfx/geometry/size.h"
  11. #include "ui/views/bubble/bubble_dialog_delegate_view.h"
  12. #include "ui/views/widget/widget.h"
  13. namespace ash {
  14. // This class encapsulates the logic to find and show the IP addresses and mac
  15. // addresses of the default network and available network technologies.
  16. class ASH_EXPORT NetworkInfoBubble : public views::BubbleDialogDelegateView {
  17. public:
  18. // This class declares the interface that should be implemented by any class
  19. // that intends to instantiate NetworkInfoBubble.
  20. class Delegate {
  21. public:
  22. Delegate() = default;
  23. virtual ~Delegate() = default;
  24. // Used to determine whether the info bubble should include the mac
  25. // addresses of the ethernet, WiFi, and cellular devices.
  26. virtual bool ShouldIncludeDeviceAddresses() = 0;
  27. // Used to notify the delegate that the bubble is destructing.
  28. virtual void OnInfoBubbleDestroyed() = 0;
  29. };
  30. NetworkInfoBubble(base::WeakPtr<Delegate> delegate, views::View* anchor);
  31. NetworkInfoBubble(const NetworkInfoBubble&) = delete;
  32. NetworkInfoBubble& operator=(const NetworkInfoBubble&) = delete;
  33. ~NetworkInfoBubble() override;
  34. private:
  35. friend class NetworkInfoBubbleTest;
  36. // Used for testing. This is 1 because view IDs should not be 0.
  37. static constexpr int kNetworkInfoBubbleLabelViewId = 1;
  38. // views::View:
  39. gfx::Size CalculatePreferredSize() const override;
  40. void OnMouseExited(const ui::MouseEvent& event) override;
  41. // views::OnBeforeBubbleWidgetInit:
  42. void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
  43. views::Widget* widget) const override;
  44. // Computes the text to be shown in the info bubble. The text will be
  45. // comprised of the IP addresses, if available, as well as the mac addresses
  46. // for the ethernet, WiFi, and cellular devices.
  47. std::u16string ComputeInfoText();
  48. base::WeakPtr<Delegate> delegate_;
  49. };
  50. } // namespace ash
  51. #endif // ASH_SYSTEM_NETWORK_NETWORK_INFO_BUBBLE_H_