Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: content/browser/webui/web_ui.h

Issue 7259019: Move base/values.h into the base namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/webui/generic_handler.h ('k') | content/common/font_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_H_ 5 #ifndef CONTENT_BROWSER_WEBUI_WEB_UI_H_
6 #define CONTENT_BROWSER_WEBUI_WEB_UI_H_ 6 #define CONTENT_BROWSER_WEBUI_WEB_UI_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback_old.h" 13 #include "base/callback_old.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "content/common/page_transition_types.h" 16 #include "content/common/page_transition_types.h"
17 #include "ipc/ipc_channel.h" 17 #include "ipc/ipc_channel.h"
18 18
19 class DictionaryValue;
20 class WebUIMessageHandler; 19 class WebUIMessageHandler;
21 class GURL; 20 class GURL;
22 class ListValue;
23 class Profile; 21 class Profile;
24 class RenderViewHost; 22 class RenderViewHost;
25 class TabContents; 23 class TabContents;
24
25 namespace base {
26 class DictionaryValue;
27 class ListValue;
26 class Value; 28 class Value;
29 }
27 30
28 // A WebUI sets up the datasources and message handlers for a given HTML-based 31 // A WebUI sets up the datasources and message handlers for a given HTML-based
29 // UI. 32 // UI.
30 // 33 //
31 // NOTE: If you're creating a new WebUI for Chrome code, make sure you extend 34 // NOTE: If you're creating a new WebUI for Chrome code, make sure you extend
32 // ChromeWebUI. 35 // ChromeWebUI.
33 class WebUI : public IPC::Channel::Listener { 36 class WebUI : public IPC::Channel::Listener {
34 public: 37 public:
35 explicit WebUI(TabContents* contents); 38 explicit WebUI(TabContents* contents);
36 virtual ~WebUI(); 39 virtual ~WebUI();
37 40
38 // IPC message handling. 41 // IPC message handling.
39 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
40 virtual void OnWebUISend(const GURL& source_url, 43 virtual void OnWebUISend(const GURL& source_url,
41 const std::string& message, 44 const std::string& message,
42 const ListValue& args); 45 const base::ListValue& args);
43 46
44 // Called by RenderViewHost when the RenderView is first created. This is 47 // Called by RenderViewHost when the RenderView is first created. This is
45 // *not* called for every page load because in some cases 48 // *not* called for every page load because in some cases
46 // RenderViewHostManager will reuse RenderView instances. In those cases, 49 // RenderViewHostManager will reuse RenderView instances. In those cases,
47 // RenderViewReused will be called instead. 50 // RenderViewReused will be called instead.
48 virtual void RenderViewCreated(RenderViewHost* render_view_host) {} 51 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
49 52
50 // Called by RenderViewHostManager when a RenderView is reused to display a 53 // Called by RenderViewHostManager when a RenderView is reused to display a
51 // page. 54 // page.
52 virtual void RenderViewReused(RenderViewHost* render_view_host) {} 55 virtual void RenderViewReused(RenderViewHost* render_view_host) {}
53 56
54 // Called when this becomes the active WebUI instance for a re-used 57 // Called when this becomes the active WebUI instance for a re-used
55 // RenderView; this is the point at which this WebUI instance will receive 58 // RenderView; this is the point at which this WebUI instance will receive
56 // DOM messages instead of the previous WebUI instance. 59 // DOM messages instead of the previous WebUI instance.
57 // 60 //
58 // If a WebUI instance has code that is usually triggered from a JavaScript 61 // If a WebUI instance has code that is usually triggered from a JavaScript
59 // onload handler, this should be overridden to check to see if the web page's 62 // onload handler, this should be overridden to check to see if the web page's
60 // DOM is still intact (e.g., due to a back/forward navigation that remains 63 // DOM is still intact (e.g., due to a back/forward navigation that remains
61 // within the same page), and if so trigger that code manually since onload 64 // within the same page), and if so trigger that code manually since onload
62 // won't be run in that case. 65 // won't be run in that case.
63 virtual void DidBecomeActiveForReusedRenderView() {} 66 virtual void DidBecomeActiveForReusedRenderView() {}
64 67
65 // Used by WebUIMessageHandlers. 68 // Used by WebUIMessageHandlers.
66 typedef Callback1<const ListValue*>::Type MessageCallback; 69 typedef Callback1<const base::ListValue*>::Type MessageCallback;
67 void RegisterMessageCallback(const std::string& message, 70 void RegisterMessageCallback(const std::string& message,
68 MessageCallback* callback); 71 MessageCallback* callback);
69 72
70 // Returns true if the favicon should be hidden for the current tab. 73 // Returns true if the favicon should be hidden for the current tab.
71 bool hide_favicon() const { 74 bool hide_favicon() const {
72 return hide_favicon_; 75 return hide_favicon_;
73 } 76 }
74 77
75 // Returns true if the location bar should be focused by default rather than 78 // Returns true if the location bar should be focused by default rather than
76 // the page contents. Some pages will want to use this to encourage the user 79 // the page contents. Some pages will want to use this to encourage the user
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 116 }
114 117
115 // Call a Javascript function by sending its name and arguments down to 118 // Call a Javascript function by sending its name and arguments down to
116 // the renderer. This is asynchronous; there's no way to get the result 119 // the renderer. This is asynchronous; there's no way to get the result
117 // of the call, and should be thought of more like sending a message to 120 // of the call, and should be thought of more like sending a message to
118 // the page. 121 // the page.
119 // All function names in WebUI must consist of only ASCII characters. 122 // All function names in WebUI must consist of only ASCII characters.
120 // There are variants for calls with more arguments. 123 // There are variants for calls with more arguments.
121 void CallJavascriptFunction(const std::string& function_name); 124 void CallJavascriptFunction(const std::string& function_name);
122 void CallJavascriptFunction(const std::string& function_name, 125 void CallJavascriptFunction(const std::string& function_name,
123 const Value& arg); 126 const base::Value& arg);
124 void CallJavascriptFunction(const std::string& function_name, 127 void CallJavascriptFunction(const std::string& function_name,
125 const Value& arg1, 128 const base::Value& arg1,
126 const Value& arg2); 129 const base::Value& arg2);
127 void CallJavascriptFunction(const std::string& function_name, 130 void CallJavascriptFunction(const std::string& function_name,
128 const Value& arg1, 131 const base::Value& arg1,
129 const Value& arg2, 132 const base::Value& arg2,
130 const Value& arg3); 133 const base::Value& arg3);
131 void CallJavascriptFunction(const std::string& function_name, 134 void CallJavascriptFunction(const std::string& function_name,
132 const Value& arg1, 135 const base::Value& arg1,
133 const Value& arg2, 136 const base::Value& arg2,
134 const Value& arg3, 137 const base::Value& arg3,
135 const Value& arg4); 138 const base::Value& arg4);
136 void CallJavascriptFunction(const std::string& function_name, 139 void CallJavascriptFunction(const std::string& function_name,
137 const std::vector<const Value*>& args); 140 const std::vector<const base::Value*>& args);
138 141
139 // May be overridden by WebUI's which do not have a tab contents. 142 // May be overridden by WebUI's which do not have a tab contents.
140 // TODO(estade): removing this Profile dependency is predicated on reworking 143 // TODO(estade): removing this Profile dependency is predicated on reworking
141 // TabContents's Profile ownership. 144 // TabContents's Profile ownership.
142 virtual Profile* GetProfile() const; 145 virtual Profile* GetProfile() const;
143 146
144 // May be overridden by WebUI's which do not have a tab contents. 147 // May be overridden by WebUI's which do not have a tab contents.
145 virtual RenderViewHost* GetRenderViewHost() const; 148 virtual RenderViewHost* GetRenderViewHost() const;
146 149
147 TabContents* tab_contents() const { return tab_contents_; } 150 TabContents* tab_contents() const { return tab_contents_; }
148 151
149 // An opaque identifier used to identify a WebUI. This can only be compared to 152 // An opaque identifier used to identify a WebUI. This can only be compared to
150 // kNoWebUI or other WebUI types. See GetWebUIType. 153 // kNoWebUI or other WebUI types. See GetWebUIType.
151 typedef void* TypeID; 154 typedef void* TypeID;
152 155
153 // A special WebUI type that signifies that a given page would not use the 156 // A special WebUI type that signifies that a given page would not use the
154 // Web UI system. 157 // Web UI system.
155 static const TypeID kNoWebUI; 158 static const TypeID kNoWebUI;
156 159
157 // Returns JavaScript code that, when executed, calls the function specified 160 // Returns JavaScript code that, when executed, calls the function specified
158 // by |function_name| with the arguments specified in |arg_list|. 161 // by |function_name| with the arguments specified in |arg_list|.
159 static string16 GetJavascriptCall(const std::string& function_name, 162 static string16 GetJavascriptCall(
160 const std::vector<const Value*>& arg_list); 163 const std::string& function_name,
164 const std::vector<const base::Value*>& arg_list);
161 165
162 protected: 166 protected:
163 void AddMessageHandler(WebUIMessageHandler* handler); 167 void AddMessageHandler(WebUIMessageHandler* handler);
164 168
165 // Execute a string of raw Javascript on the page. Overridable for 169 // Execute a string of raw Javascript on the page. Overridable for
166 // testing purposes. 170 // testing purposes.
167 virtual void ExecuteJavascript(const string16& javascript); 171 virtual void ExecuteJavascript(const string16& javascript);
168 172
169 // Options that may be overridden by individual Web UI implementations. The 173 // Options that may be overridden by individual Web UI implementations. The
170 // bool options default to false. See the public getters for more information. 174 // bool options default to false. See the public getters for more information.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 virtual ~WebUIMessageHandler(); 206 virtual ~WebUIMessageHandler();
203 207
204 // Attaches |this| to |web_ui| in order to handle messages from it. Declared 208 // Attaches |this| to |web_ui| in order to handle messages from it. Declared
205 // virtual so that subclasses can do special init work as soon as the web_ui 209 // virtual so that subclasses can do special init work as soon as the web_ui
206 // is provided. Returns |this| for convenience. 210 // is provided. Returns |this| for convenience.
207 virtual WebUIMessageHandler* Attach(WebUI* web_ui); 211 virtual WebUIMessageHandler* Attach(WebUI* web_ui);
208 212
209 protected: 213 protected:
210 // Adds "url" and "title" keys on incoming dictionary, setting title 214 // Adds "url" and "title" keys on incoming dictionary, setting title
211 // as the url as a fallback on empty title. 215 // as the url as a fallback on empty title.
212 static void SetURLAndTitle(DictionaryValue* dictionary, 216 static void SetURLAndTitle(base::DictionaryValue* dictionary,
213 string16 title, 217 string16 title,
214 const GURL& gurl); 218 const GURL& gurl);
215 219
216 // This is where subclasses specify which messages they'd like to handle. 220 // This is where subclasses specify which messages they'd like to handle.
217 virtual void RegisterMessages() = 0; 221 virtual void RegisterMessages() = 0;
218 222
219 // Extract an integer value from a list Value. 223 // Extract an integer value from a list Value.
220 bool ExtractIntegerValue(const ListValue* value, int* out_int); 224 bool ExtractIntegerValue(const base::ListValue* value, int* out_int);
221 225
222 // Extract a string value from a list Value. 226 // Extract a string value from a list Value.
223 string16 ExtractStringValue(const ListValue* value); 227 string16 ExtractStringValue(const base::ListValue* value);
224 228
225 WebUI* web_ui_; 229 WebUI* web_ui_;
226 230
227 private: 231 private:
228 DISALLOW_COPY_AND_ASSIGN(WebUIMessageHandler); 232 DISALLOW_COPY_AND_ASSIGN(WebUIMessageHandler);
229 }; 233 };
230 234
231 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_ 235 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_
OLDNEW
« no previous file with comments | « content/browser/webui/generic_handler.h ('k') | content/common/font_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698