devtools_embedder_message_dispatcher.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2013 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-CHROMIUM file.
  4. #ifndef BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
  5. #define BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
  6. #include <map>
  7. #include <string>
  8. #include "base/callback.h"
  9. #include "ui/gfx/geometry/insets.h"
  10. #include "ui/gfx/geometry/rect.h"
  11. #include "ui/gfx/geometry/size.h"
  12. namespace base {
  13. class ListValue;
  14. class Value;
  15. } // namespace base
  16. namespace brightray {
  17. /**
  18. * Dispatcher for messages sent from the DevTools frontend running in an
  19. * isolated renderer (on chrome-devtools://) to the embedder in the browser.
  20. *
  21. * The messages are sent via InspectorFrontendHost.sendMessageToEmbedder method.
  22. */
  23. class DevToolsEmbedderMessageDispatcher {
  24. public:
  25. class Delegate {
  26. public:
  27. using DispatchCallback = base::Callback<void(const base::Value*)>;
  28. virtual ~Delegate() {}
  29. virtual void ActivateWindow() = 0;
  30. virtual void CloseWindow() = 0;
  31. virtual void LoadCompleted() = 0;
  32. virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0;
  33. virtual void InspectElementCompleted() = 0;
  34. virtual void InspectedURLChanged(const std::string& url) = 0;
  35. virtual void SetIsDocked(const DispatchCallback& callback,
  36. bool is_docked) = 0;
  37. virtual void OpenInNewTab(const std::string& url) = 0;
  38. virtual void SaveToFile(const std::string& url,
  39. const std::string& content,
  40. bool save_as) = 0;
  41. virtual void AppendToFile(const std::string& url,
  42. const std::string& content) = 0;
  43. virtual void RequestFileSystems() = 0;
  44. virtual void AddFileSystem(const std::string& file_system_path) = 0;
  45. virtual void RemoveFileSystem(const std::string& file_system_path) = 0;
  46. virtual void UpgradeDraggedFileSystemPermissions(
  47. const std::string& file_system_url) = 0;
  48. virtual void IndexPath(int index_request_id,
  49. const std::string& file_system_path) = 0;
  50. virtual void StopIndexing(int index_request_id) = 0;
  51. virtual void LoadNetworkResource(const DispatchCallback& callback,
  52. const std::string& url,
  53. const std::string& headers,
  54. int stream_id) = 0;
  55. virtual void SearchInPath(int search_request_id,
  56. const std::string& file_system_path,
  57. const std::string& query) = 0;
  58. virtual void SetWhitelistedShortcuts(const std::string& message) = 0;
  59. virtual void ZoomIn() = 0;
  60. virtual void ZoomOut() = 0;
  61. virtual void ResetZoom() = 0;
  62. virtual void SetDevicesUpdatesEnabled(bool enabled) = 0;
  63. virtual void DispatchProtocolMessageFromDevToolsFrontend(
  64. const std::string& message) = 0;
  65. virtual void SendJsonRequest(const DispatchCallback& callback,
  66. const std::string& browser_id,
  67. const std::string& url) = 0;
  68. virtual void GetPreferences(const DispatchCallback& callback) = 0;
  69. virtual void SetPreference(const std::string& name,
  70. const std::string& value) = 0;
  71. virtual void RemovePreference(const std::string& name) = 0;
  72. virtual void ClearPreferences() = 0;
  73. virtual void RegisterExtensionsAPI(const std::string& origin,
  74. const std::string& script) = 0;
  75. };
  76. using DispatchCallback = Delegate::DispatchCallback;
  77. virtual ~DevToolsEmbedderMessageDispatcher() {}
  78. virtual bool Dispatch(const DispatchCallback& callback,
  79. const std::string& method,
  80. const base::ListValue* params) = 0;
  81. static DevToolsEmbedderMessageDispatcher* CreateForDevToolsFrontend(
  82. Delegate* delegate);
  83. };
  84. } // namespace brightray
  85. #endif // BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_