devtools_embedder_message_dispatcher.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 file.
4
5#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
6#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
7
8#include <map>
9#include <string>
10
11#include "base/callback.h"
12#include "ui/gfx/insets.h"
13#include "ui/gfx/size.h"
14
15namespace base {
16class ListValue;
17}
18
19/**
20 * Dispatcher for messages sent from the DevTools frontend running in an
21 * isolated renderer (on chrome-devtools://) to the embedder in the browser.
22 *
23 * The messages are sent via InspectorFrontendHost.sendMessageToEmbedder method.
24 */
25class DevToolsEmbedderMessageDispatcher {
26 public:
27  class Delegate {
28   public:
29    virtual ~Delegate() {}
30
31    virtual void ActivateWindow() = 0;
32    virtual void CloseWindow() = 0;
33    virtual void SetContentsInsets(
34        int top, int left, int bottom, int right) = 0;
35    virtual void SetContentsResizingStrategy(
36        const gfx::Insets& insets, const gfx::Size& min_size) = 0;
37    virtual void InspectElementCompleted() = 0;
38    virtual void MoveWindow(int x, int y) = 0;
39    virtual void SetIsDocked(bool is_docked) = 0;
40    virtual void OpenInNewTab(const std::string& url) = 0;
41    virtual void SaveToFile(const std::string& url,
42                            const std::string& content,
43                            bool save_as) = 0;
44    virtual void AppendToFile(const std::string& url,
45                              const std::string& content) = 0;
46    virtual void RequestFileSystems() = 0;
47    virtual void AddFileSystem() = 0;
48    virtual void RemoveFileSystem(const std::string& file_system_path) = 0;
49    virtual void UpgradeDraggedFileSystemPermissions(
50        const std::string& file_system_url) = 0;
51    virtual void IndexPath(int request_id,
52                           const std::string& file_system_path) = 0;
53    virtual void StopIndexing(int request_id) = 0;
54    virtual void SearchInPath(int request_id,
55                              const std::string& file_system_path,
56                              const std::string& query) = 0;
57    virtual void ZoomIn() = 0;
58    virtual void ZoomOut() = 0;
59    virtual void ResetZoom() = 0;
60  };
61
62  explicit DevToolsEmbedderMessageDispatcher(Delegate* delegate);
63
64  ~DevToolsEmbedderMessageDispatcher();
65
66  std::string Dispatch(const std::string& method, base::ListValue* params);
67
68 private:
69  typedef base::Callback<bool(const base::ListValue&)> Handler;
70  void RegisterHandler(const std::string& method, const Handler& handler);
71
72  typedef std::map<std::string, Handler> HandlerMap;
73  HandlerMap handlers_;
74};
75
76#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_
77