IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / webui / web_ui_impl.h
blob8715e43e226aea887304e4f881b6a6df9fa43b9f
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>
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/web_ui.h"
14 #include "ipc/ipc_listener.h"
16 namespace content {
17 class RenderViewHost;
19 class CONTENT_EXPORT WebUIImpl : public WebUI,
20 public IPC::Listener,
21 public base::SupportsWeakPtr<WebUIImpl> {
22 public:
23 explicit WebUIImpl(WebContents* contents);
24 virtual ~WebUIImpl();
26 // Called by WebContentsImpl when the RenderView is first created. This is
27 // *not* called for every page load because in some cases
28 // RenderFrameHostManager will reuse RenderView instances.
29 void RenderViewCreated(RenderViewHost* render_view_host);
31 // WebUI implementation:
32 virtual WebContents* GetWebContents() const OVERRIDE;
33 virtual WebUIController* GetController() const OVERRIDE;
34 virtual void SetController(WebUIController* controller) OVERRIDE;
35 virtual ui::ScaleFactor GetDeviceScaleFactor() const OVERRIDE;
36 virtual const base::string16& GetOverriddenTitle() const OVERRIDE;
37 virtual void OverrideTitle(const base::string16& title) OVERRIDE;
38 virtual PageTransition GetLinkTransitionType() const OVERRIDE;
39 virtual void SetLinkTransitionType(PageTransition type) OVERRIDE;
40 virtual int GetBindings() const OVERRIDE;
41 virtual void SetBindings(int bindings) OVERRIDE;
42 virtual void SetFrameXPath(const std::string& xpath) OVERRIDE;
43 virtual void AddMessageHandler(WebUIMessageHandler* handler) OVERRIDE;
44 typedef base::Callback<void(const base::ListValue*)> MessageCallback;
45 virtual void RegisterMessageCallback(
46 const std::string& message,
47 const MessageCallback& callback) OVERRIDE;
48 virtual void ProcessWebUIMessage(const GURL& source_url,
49 const std::string& message,
50 const base::ListValue& args) OVERRIDE;
51 virtual void CallJavascriptFunction(
52 const std::string& function_name) OVERRIDE;
53 virtual void CallJavascriptFunction(const std::string& function_name,
54 const base::Value& arg) OVERRIDE;
55 virtual void CallJavascriptFunction(const std::string& function_name,
56 const base::Value& arg1,
57 const base::Value& arg2) OVERRIDE;
58 virtual void CallJavascriptFunction(const std::string& function_name,
59 const base::Value& arg1,
60 const base::Value& arg2,
61 const base::Value& arg3) OVERRIDE;
62 virtual 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 virtual void CallJavascriptFunction(
68 const std::string& function_name,
69 const std::vector<const base::Value*>& args) OVERRIDE;
71 // IPC::Listener implementation:
72 virtual 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 // A map of message name -> message handling callback.
84 typedef std::map<std::string, MessageCallback> MessageCallbackMap;
85 MessageCallbackMap message_callbacks_;
87 // Options that may be overridden by individual Web UI implementations. The
88 // bool options default to false. See the public getters for more information.
89 base::string16 overridden_title_; // Defaults to empty string.
90 PageTransition link_transition_type_; // Defaults to LINK.
91 int bindings_; // The bindings from BindingsPolicy that should be enabled for
92 // this page.
94 // The WebUIMessageHandlers we own.
95 ScopedVector<WebUIMessageHandler> handlers_;
97 // Non-owning pointer to the WebContents this WebUI is associated with.
98 WebContents* web_contents_;
100 // The path for the iframe this WebUI is embedded in (empty if not in an
101 // iframe).
102 std::string frame_xpath_;
104 scoped_ptr<WebUIController> controller_;
106 DISALLOW_COPY_AND_ASSIGN(WebUIImpl);
109 } // namespace content
111 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_IMPL_H_