summaryrefslogtreecommitdiffstats
path: root/chrome/browser/devtools/devtools_embedder_message_dispatcher.h
blob: badf46f83ef98cf0a0280ece1ef29ed116d0dbdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2013 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.

#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_

#include <map>
#include <string>

#include "base/callback.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

namespace base {
class ListValue;
class Value;
}

/**
 * Dispatcher for messages sent from the DevTools frontend running in an
 * isolated renderer (on chrome-devtools://) to the embedder in the browser.
 *
 * The messages are sent via InspectorFrontendHost.sendMessageToEmbedder method.
 */
class DevToolsEmbedderMessageDispatcher {
 public:
  class Delegate {
   public:
    using DispatchCallback = base::Callback<void(const base::Value*)>;

    virtual ~Delegate() {}

    virtual void ActivateWindow() = 0;
    virtual void CloseWindow() = 0;
    virtual void LoadCompleted() = 0;
    virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0;
    virtual void InspectElementCompleted() = 0;
    virtual void InspectedURLChanged(const std::string& url) = 0;
    virtual void SetIsDocked(const DispatchCallback& callback,
                             bool is_docked) = 0;
    virtual void OpenInNewTab(const std::string& url) = 0;
    virtual void SaveToFile(const std::string& url,
                            const std::string& content,
                            bool save_as) = 0;
    virtual void AppendToFile(const std::string& url,
                              const std::string& content) = 0;
    virtual void RequestFileSystems() = 0;
    virtual void AddFileSystem() = 0;
    virtual void RemoveFileSystem(const std::string& file_system_path) = 0;
    virtual void UpgradeDraggedFileSystemPermissions(
        const std::string& file_system_url) = 0;
    virtual void IndexPath(int index_request_id,
                           const std::string& file_system_path) = 0;
    virtual void StopIndexing(int index_request_id) = 0;
    virtual void LoadNetworkResource(const DispatchCallback& callback,
                                     const std::string& url,
                                     const std::string& headers,
                                     int stream_id) = 0;
    virtual void SearchInPath(int search_request_id,
                              const std::string& file_system_path,
                              const std::string& query) = 0;
    virtual void SetWhitelistedShortcuts(const std::string& message) = 0;
    virtual void ZoomIn() = 0;
    virtual void ZoomOut() = 0;
    virtual void ResetZoom() = 0;
    virtual void SetDevicesUpdatesEnabled(bool enabled) = 0;
    virtual void GetPreferences(const DispatchCallback& callback) = 0;
    virtual void SetPreference(const std::string& name,
                               const std::string& value) = 0;
    virtual void RemovePreference(const std::string& name) = 0;
    virtual void ClearPreferences() = 0;
    virtual void SendMessageToBrowser(const std::string& message) = 0;
    virtual void RecordEnumeratedHistogram(const std::string& name,
                                           int sample,
                                           int boundary_value) = 0;
    virtual void SendJsonRequest(const DispatchCallback& callback,
                                 const std::string& browser_id,
                                 const std::string& url) = 0;
  };

  using DispatchCallback = Delegate::DispatchCallback;

  virtual ~DevToolsEmbedderMessageDispatcher() {}
  virtual bool Dispatch(const DispatchCallback& callback,
                        const std::string& method,
                        const base::ListValue* params) = 0;

  static DevToolsEmbedderMessageDispatcher* CreateForDevToolsFrontend(
      Delegate* delegate);
};

#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_