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

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

Issue 8986007: Move WebUIMessageHandler to its own file in the public directory and put it in the content namesp... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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.cc ('k') | content/browser/webui/web_ui.cc » ('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.h" 13 #include "base/callback.h"
14 #include "base/callback_old.h" 14 #include "base/callback_old.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
18 #include "content/public/common/page_transition_types.h" 18 #include "content/public/common/page_transition_types.h"
19 #include "ipc/ipc_channel.h" 19 #include "ipc/ipc_channel.h"
20 20
21 class GURL; 21 class GURL;
22 class RenderViewHost; 22 class RenderViewHost;
23 class WebUIMessageHandler;
24 23
25 namespace base { 24 namespace base {
26 class DictionaryValue;
27 class ListValue; 25 class ListValue;
28 class Value; 26 class Value;
29 } 27 }
30 28
31 namespace content { 29 namespace content {
32 class WebContents; 30 class WebContents;
31 class WebUIMessageHandler;
33 } 32 }
34 33
35 // A WebUI sets up the datasources and message handlers for a given HTML-based 34 // A WebUI sets up the datasources and message handlers for a given HTML-based
36 // UI. 35 // UI.
37 // 36 //
38 // NOTE: If you're creating a new WebUI for Chrome code, make sure you extend 37 // NOTE: If you're creating a new WebUI for Chrome code, make sure you extend
39 // ChromeWebUI. 38 // ChromeWebUI.
40 class CONTENT_EXPORT WebUI : public IPC::Channel::Listener { 39 class CONTENT_EXPORT WebUI : public IPC::Channel::Listener {
41 public: 40 public:
42 explicit WebUI(content::WebContents* contents); 41 explicit WebUI(content::WebContents* contents);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 static const TypeID kNoWebUI; 159 static const TypeID kNoWebUI;
161 160
162 // Returns JavaScript code that, when executed, calls the function specified 161 // Returns JavaScript code that, when executed, calls the function specified
163 // by |function_name| with the arguments specified in |arg_list|. 162 // by |function_name| with the arguments specified in |arg_list|.
164 static string16 GetJavascriptCall( 163 static string16 GetJavascriptCall(
165 const std::string& function_name, 164 const std::string& function_name,
166 const std::vector<const base::Value*>& arg_list); 165 const std::vector<const base::Value*>& arg_list);
167 166
168 protected: 167 protected:
169 // Takes ownership of |handler|, which will be destroyed when the WebUI is. 168 // Takes ownership of |handler|, which will be destroyed when the WebUI is.
170 void AddMessageHandler(WebUIMessageHandler* handler); 169 void AddMessageHandler(content::WebUIMessageHandler* handler);
171 170
172 // Execute a string of raw Javascript on the page. Overridable for 171 // Execute a string of raw Javascript on the page. Overridable for
173 // testing purposes. 172 // testing purposes.
174 virtual void ExecuteJavascript(const string16& javascript); 173 virtual void ExecuteJavascript(const string16& javascript);
175 174
176 // Options that may be overridden by individual Web UI implementations. The 175 // Options that may be overridden by individual Web UI implementations. The
177 // bool options default to false. See the public getters for more information. 176 // bool options default to false. See the public getters for more information.
178 bool hide_favicon_; 177 bool hide_favicon_;
179 bool focus_location_bar_by_default_; 178 bool focus_location_bar_by_default_;
180 bool should_hide_url_; 179 bool should_hide_url_;
181 string16 overridden_title_; // Defaults to empty string. 180 string16 overridden_title_; // Defaults to empty string.
182 content::PageTransition link_transition_type_; // Defaults to LINK. 181 content::PageTransition link_transition_type_; // Defaults to LINK.
183 int bindings_; // The bindings from BindingsPolicy that should be enabled for 182 int bindings_; // The bindings from BindingsPolicy that should be enabled for
184 // this page. 183 // this page.
185 184
186 // Used by test mocks. See the public getters for more information. 185 // Used by test mocks. See the public getters for more information.
187 bool register_callback_overwrites_; // Defaults to false. 186 bool register_callback_overwrites_; // Defaults to false.
188 187
189 // The WebUIMessageHandlers we own. 188 // The WebUIMessageHandlers we own.
190 std::vector<WebUIMessageHandler*> handlers_; 189 std::vector<content::WebUIMessageHandler*> handlers_;
191 190
192 // Non-owning pointer to the WebContents this WebUI is associated with. 191 // Non-owning pointer to the WebContents this WebUI is associated with.
193 content::WebContents* web_contents_; 192 content::WebContents* web_contents_;
194 193
195 private: 194 private:
196 // A map of message name -> message handling callback. 195 // A map of message name -> message handling callback.
197 typedef std::map<std::string, MessageCallback> MessageCallbackMap; 196 typedef std::map<std::string, MessageCallback> MessageCallbackMap;
198 MessageCallbackMap message_callbacks_; 197 MessageCallbackMap message_callbacks_;
199 198
200 // The path for the iframe this WebUI is embedded in (empty if not in an 199 // The path for the iframe this WebUI is embedded in (empty if not in an
201 // iframe). 200 // iframe).
202 std::string frame_xpath_; 201 std::string frame_xpath_;
203 202
204 DISALLOW_COPY_AND_ASSIGN(WebUI); 203 DISALLOW_COPY_AND_ASSIGN(WebUI);
205 }; 204 };
206 205
207 // Messages sent from the DOM are forwarded via the WebUI to handler
208 // classes. These objects are owned by WebUI and destroyed when the
209 // host is destroyed.
210 class CONTENT_EXPORT WebUIMessageHandler {
211 public:
212 WebUIMessageHandler();
213 virtual ~WebUIMessageHandler();
214
215 protected:
216 // Helper methods:
217
218 // Adds "url" and "title" keys on incoming dictionary, setting title
219 // as the url as a fallback on empty title.
220 static void SetURLAndTitle(base::DictionaryValue* dictionary,
221 string16 title,
222 const GURL& gurl);
223
224 // Extract an integer value from a list Value.
225 static bool ExtractIntegerValue(const base::ListValue* value, int* out_int);
226
227 // Extract a floating point (double) value from a list Value.
228 static bool ExtractDoubleValue(const base::ListValue* value,
229 double* out_value);
230
231 // Extract a string value from a list Value.
232 static string16 ExtractStringValue(const base::ListValue* value);
233
234 // This is where subclasses specify which messages they'd like to handle and
235 // perform any additional initialization.. At this point web_ui() will return
236 // the associated WebUI object.
237 virtual void RegisterMessages() = 0;
238
239 // Returns the attached WebUI for this handler.
240 WebUI* web_ui() const { return web_ui_; }
241
242 private:
243 friend class WebUI;
244 friend class WebUIBrowserTest;
245
246 void set_web_ui(WebUI* web_ui) { web_ui_ = web_ui; }
247
248 WebUI* web_ui_;
249
250 DISALLOW_COPY_AND_ASSIGN(WebUIMessageHandler);
251 };
252
253 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_ 206 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_
OLDNEW
« no previous file with comments | « content/browser/webui/generic_handler.cc ('k') | content/browser/webui/web_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698