OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_RENDERER_WEB_UI_BINDINGS_H_ | |
6 #define CHROME_RENDERER_WEB_UI_BINDINGS_H_ | |
7 #pragma once | |
8 | |
9 #include "ipc/ipc_message.h" | |
10 #include "webkit/glue/cpp_bound_class.h" | |
11 | |
12 // A DOMBoundBrowserObject is a backing for some object bound to the window | |
13 // in JS that knows how to dispatch messages to an associated c++ object living | |
14 // in the browser process. | |
15 class DOMBoundBrowserObject : public CppBoundClass { | |
16 public: | |
17 DOMBoundBrowserObject(); | |
18 virtual ~DOMBoundBrowserObject(); | |
19 | |
20 // Set the message channel back to the browser. | |
21 void set_message_sender(IPC::Message::Sender* sender) { | |
22 sender_ = sender; | |
23 } | |
24 | |
25 // Set the routing id for messages back to the browser. | |
26 void set_routing_id(int routing_id) { | |
27 routing_id_ = routing_id; | |
28 } | |
29 | |
30 IPC::Message::Sender* sender() { return sender_; } | |
31 int routing_id() { return routing_id_; } | |
32 | |
33 // Sets a property with the given name and value. | |
34 void SetProperty(const std::string& name, const std::string& value); | |
35 | |
36 private: | |
37 // Our channel back to the browser is a message sender | |
38 // and routing id. | |
39 IPC::Message::Sender* sender_; | |
40 int routing_id_; | |
41 | |
42 // The list of properties that have been set. We keep track of this so we | |
43 // can free them on destruction. | |
44 typedef std::vector<CppVariant*> PropertyList; | |
45 PropertyList properties_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(DOMBoundBrowserObject); | |
48 }; | |
49 | |
50 // WebUIBindings is the class backing the "chrome" object accessible | |
51 // from Javascript from privileged pages. | |
52 // | |
53 // We expose one function, for sending a message to the browser: | |
54 // send(String name, Object argument); | |
55 // It's plumbed through to the OnWebUIMessage callback on RenderViewHost | |
56 // delegate. | |
57 class WebUIBindings : public DOMBoundBrowserObject { | |
58 public: | |
59 WebUIBindings(); | |
60 virtual ~WebUIBindings(); | |
61 | |
62 // The send() function provided to Javascript. | |
63 void send(const CppArgumentList& args, CppVariant* result); | |
64 private: | |
65 DISALLOW_COPY_AND_ASSIGN(WebUIBindings); | |
66 }; | |
67 | |
68 #endif // CHROME_RENDERER_WEB_UI_BINDINGS_H_ | |
OLD | NEW |