Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / content / browser / webui / web_ui_impl.h
blobd38da2a80062b8d6b280274dc1578bccef1fee1d
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_
6 #define CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_
8 #include <map>
9 #include <set>
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/public/browser/web_ui.h"
15 #include "ipc/ipc_listener.h"
17 namespace content {
18 class RenderFrameHost;
19 class RenderViewHost;
21 class CONTENT_EXPORT WebUIImpl : public WebUI,
22 public IPC::Listener,
23 public base::SupportsWeakPtr<WebUIImpl> {
24 public:
25 WebUIImpl(WebContents* contents, const std::string& frame_name);
26 ~WebUIImpl() override;
28 // Called by WebContentsImpl when the RenderView is first created. This is
29 // *not* called for every page load because in some cases
30 // RenderFrameHostManager will reuse RenderView instances.
31 void RenderViewCreated(RenderViewHost* render_view_host);
33 // WebUI implementation:
34 WebContents* GetWebContents() const override;
35 WebUIController* GetController() const override;
36 void SetController(WebUIController* controller) override;
37 float GetDeviceScaleFactor() const override;
38 const base::string16& GetOverriddenTitle() const override;
39 void OverrideTitle(const base::string16& title) override;
40 ui::PageTransition GetLinkTransitionType() const override;
41 void SetLinkTransitionType(ui::PageTransition type) override;
42 int GetBindings() const override;
43 void SetBindings(int bindings) override;
44 void AddMessageHandler(WebUIMessageHandler* handler) override;
45 typedef base::Callback<void(const base::ListValue*)> MessageCallback;
46 void RegisterMessageCallback(const std::string& message,
47 const MessageCallback& callback) override;
48 void ProcessWebUIMessage(const GURL& source_url,
49 const std::string& message,
50 const base::ListValue& args) override;
51 void CallJavascriptFunction(const std::string& function_name) override;
52 void CallJavascriptFunction(const std::string& function_name,
53 const base::Value& arg) override;
54 void CallJavascriptFunction(const std::string& function_name,
55 const base::Value& arg1,
56 const base::Value& arg2) override;
57 void CallJavascriptFunction(const std::string& function_name,
58 const base::Value& arg1,
59 const base::Value& arg2,
60 const base::Value& arg3) override;
61 void CallJavascriptFunction(const std::string& function_name,
62 const base::Value& arg1,
63 const base::Value& arg2,
64 const base::Value& arg3,
65 const base::Value& arg4) override;
66 void CallJavascriptFunction(
67 const std::string& function_name,
68 const std::vector<const base::Value*>& args) override;
70 // IPC::Listener implementation:
71 bool OnMessageReceived(const IPC::Message& message) override;
73 private:
74 // IPC message handling.
75 void OnWebUISend(const GURL& source_url,
76 const std::string& message,
77 const base::ListValue& args);
79 // Execute a string of raw JavaScript on the page.
80 void ExecuteJavascript(const base::string16& javascript);
82 // Finds the frame in which to execute JavaScript based on |frame_name_|. If
83 // |frame_name_| is empty, the main frame is returned. May return NULL if no
84 // frame of the specified name exists in the page.
85 RenderFrameHost* TargetFrame();
87 // A helper function for TargetFrame; adds a frame to the specified set if its
88 // name matches |frame_name_|.
89 void AddToSetIfFrameNameMatches(std::set<RenderFrameHost*>* frame_set,
90 RenderFrameHost* host);
92 // A map of message name -> message handling callback.
93 typedef std::map<std::string, MessageCallback> MessageCallbackMap;
94 MessageCallbackMap message_callbacks_;
96 // Options that may be overridden by individual Web UI implementations. The
97 // bool options default to false. See the public getters for more information.
98 base::string16 overridden_title_; // Defaults to empty string.
99 ui::PageTransition link_transition_type_; // Defaults to LINK.
100 int bindings_; // The bindings from BindingsPolicy that should be enabled for
101 // this page.
103 // The WebUIMessageHandlers we own.
104 ScopedVector<WebUIMessageHandler> handlers_;
106 // Non-owning pointer to the WebContents this WebUI is associated with.
107 WebContents* web_contents_;
109 // The name of the frame this WebUI is embedded in. If empty, the main frame
110 // is used.
111 const std::string frame_name_;
113 scoped_ptr<WebUIController> controller_;
115 DISALLOW_COPY_AND_ASSIGN(WebUIImpl);
118 } // namespace content
120 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_