Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / webui / web_ui_impl.h
blobc08db2927f6a33f52350d011adfda47c7f538d4e
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 explicit WebUIImpl(WebContents* contents);
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 OverrideJavaScriptFrame(const std::string& frame_name) override;
45 void AddMessageHandler(WebUIMessageHandler* handler) override;
46 typedef base::Callback<void(const base::ListValue*)> MessageCallback;
47 void RegisterMessageCallback(const std::string& message,
48 const MessageCallback& callback) override;
49 void ProcessWebUIMessage(const GURL& source_url,
50 const std::string& message,
51 const base::ListValue& args) override;
52 void CallJavascriptFunction(const std::string& function_name) override;
53 void CallJavascriptFunction(const std::string& function_name,
54 const base::Value& arg) override;
55 void CallJavascriptFunction(const std::string& function_name,
56 const base::Value& arg1,
57 const base::Value& arg2) override;
58 void CallJavascriptFunction(const std::string& function_name,
59 const base::Value& arg1,
60 const base::Value& arg2,
61 const base::Value& arg3) override;
62 void CallJavascriptFunction(const std::string& function_name,
63 const base::Value& arg1,
64 const base::Value& arg2,
65 const base::Value& arg3,
66 const base::Value& arg4) override;
67 void CallJavascriptFunction(
68 const std::string& function_name,
69 const std::vector<const base::Value*>& args) override;
71 // IPC::Listener implementation:
72 bool OnMessageReceived(const IPC::Message& message) override;
74 private:
75 // IPC message handling.
76 void OnWebUISend(const GURL& source_url,
77 const std::string& message,
78 const base::ListValue& args);
80 // Execute a string of raw JavaScript on the page.
81 void ExecuteJavascript(const base::string16& javascript);
83 // Finds the frame in which to execute JavaScript (the one specified by
84 // OverrideJavaScriptFrame). May return NULL if no frame of the specified name
85 // exists in the page.
86 RenderFrameHost* TargetFrame();
88 // A helper function for TargetFrame; adds a frame to the specified set if its
89 // name matches frame_name_.
90 void AddToSetIfFrameNameMatches(std::set<RenderFrameHost*>* frame_set,
91 RenderFrameHost* host);
93 // A map of message name -> message handling callback.
94 typedef std::map<std::string, MessageCallback> MessageCallbackMap;
95 MessageCallbackMap message_callbacks_;
97 // Options that may be overridden by individual Web UI implementations. The
98 // bool options default to false. See the public getters for more information.
99 base::string16 overridden_title_; // Defaults to empty string.
100 ui::PageTransition link_transition_type_; // Defaults to LINK.
101 int bindings_; // The bindings from BindingsPolicy that should be enabled for
102 // this page.
104 // The WebUIMessageHandlers we own.
105 ScopedVector<WebUIMessageHandler> handlers_;
107 // Non-owning pointer to the WebContents this WebUI is associated with.
108 WebContents* web_contents_;
110 // The name of the iframe this WebUI is embedded in (empty if not explicitly
111 // overridden with OverrideJavaScriptFrame).
112 std::string frame_name_;
114 scoped_ptr<WebUIController> controller_;
116 DISALLOW_COPY_AND_ASSIGN(WebUIImpl);
119 } // namespace content
121 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_