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 13 namespace base { 14 class ListValue; 15 } 16 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: ~Delegate()27 virtual ~Delegate() {} 28 29 virtual void ActivateWindow() = 0; 30 virtual void CloseWindow() = 0; 31 virtual void SetWindowBounds(int x, int y, int width, int height) = 0; 32 virtual void MoveWindow(int x, int y) = 0; 33 virtual void SetDockSide(const std::string& side) = 0; 34 virtual void OpenInNewTab(const std::string& url) = 0; 35 virtual void SaveToFile(const std::string& url, 36 const std::string& content, 37 bool save_as) = 0; 38 virtual void AppendToFile(const std::string& url, 39 const std::string& content) = 0; 40 virtual void RequestFileSystems() = 0; 41 virtual void AddFileSystem() = 0; 42 virtual void RemoveFileSystem(const std::string& file_system_path) = 0; 43 virtual void UpgradeDraggedFileSystemPermissions( 44 const std::string& file_system_url) = 0; 45 virtual void IndexPath(int request_id, 46 const std::string& file_system_path) = 0; 47 virtual void StopIndexing(int request_id) = 0; 48 virtual void SearchInPath(int request_id, 49 const std::string& file_system_path, 50 const std::string& query) = 0; 51 }; 52 53 explicit DevToolsEmbedderMessageDispatcher(Delegate* delegate); 54 55 ~DevToolsEmbedderMessageDispatcher(); 56 57 std::string Dispatch(const std::string& method, base::ListValue* params); 58 59 private: 60 typedef base::Callback<bool(const base::ListValue&)> Handler; 61 void RegisterHandler(const std::string& method, const Handler& handler); 62 63 typedef std::map<std::string, Handler> HandlerMap; 64 HandlerMap handlers_; 65 }; 66 67 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_ 68