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

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

Issue 9188056: Start splitting out WebUI into an implementation class and an interface that each page implements... (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/tab_contents/tab_contents_unittest.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) 2012 The Chromium Authors. All rights reserved. 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 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/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/public/common/page_transition_types.h" 17 #include "content/public/common/page_transition_types.h"
18 #include "ipc/ipc_channel.h" 18 #include "ipc/ipc_channel.h"
19 19
20 class GURL; 20 class GURL;
21 class RenderViewHost; 21 class RenderViewHost;
22 22
23 namespace base { 23 namespace base {
24 class ListValue; 24 class ListValue;
25 class Value; 25 class Value;
26 } 26 }
27 27
28 namespace content { 28 namespace content {
29 class WebContents; 29 class WebContents;
30 class WebUIController;
30 class WebUIMessageHandler; 31 class WebUIMessageHandler;
31 } 32 }
32 33
33 // 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
34 // UI. 35 // UI.
35 // 36 //
36 // 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
37 // ChromeWebUI. 38 // ChromeWebUI.
38 class CONTENT_EXPORT WebUI : public IPC::Channel::Listener { 39 class CONTENT_EXPORT WebUI : public IPC::Channel::Listener {
39 public: 40 public:
40 explicit WebUI(content::WebContents* contents); 41 WebUI(content::WebContents* contents, content::WebUIController* controller);
41 virtual ~WebUI(); 42 virtual ~WebUI();
42 43
43 // IPC message handling. 44 // IPC::Channel::Listener implementation:
44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
45 virtual void OnWebUISend(const GURL& source_url,
46 const std::string& message,
47 const base::ListValue& args);
48 46
49 // Called by RenderViewHost when the RenderView is first created. This is 47 // Called by TabContents when the RenderView is first created. This is *not*
50 // *not* called for every page load because in some cases 48 // called for every page load because in some cases RenderViewHostManager will
51 // RenderViewHostManager will reuse RenderView instances. In those cases, 49 // reuse RenderView instances.
52 // RenderViewReused will be called instead. 50 void RenderViewCreated(RenderViewHost* render_view_host);
53 virtual void RenderViewCreated(RenderViewHost* render_view_host);
54
55 // Called by RenderViewHostManager when a RenderView is reused to display a
56 // page.
57 virtual void RenderViewReused(RenderViewHost* render_view_host) {}
58
59 // Called when this becomes the active WebUI instance for a re-used
60 // RenderView; this is the point at which this WebUI instance will receive
61 // DOM messages instead of the previous WebUI instance.
62 //
63 // If a WebUI instance has code that is usually triggered from a JavaScript
64 // onload handler, this should be overridden to check to see if the web page's
65 // DOM is still intact (e.g., due to a back/forward navigation that remains
66 // within the same page), and if so trigger that code manually since onload
67 // won't be run in that case.
68 virtual void DidBecomeActiveForReusedRenderView() {}
69 51
70 // Used by WebUIMessageHandlers. If the given message is already registered, 52 // Used by WebUIMessageHandlers. If the given message is already registered,
71 // the call has no effect unless |register_callback_overwrites_| is set to 53 // the call has no effect unless |register_callback_overwrites_| is set to
72 // true. 54 // true.
73 typedef base::Callback<void(const base::ListValue*)> MessageCallback; 55 typedef base::Callback<void(const base::ListValue*)> MessageCallback;
74 void RegisterMessageCallback(const std::string& message, 56 void RegisterMessageCallback(const std::string& message,
75 const MessageCallback& callback); 57 const MessageCallback& callback);
76 58
77 // Returns true if the favicon should be hidden for the current tab. 59 // Returns true if the favicon should be hidden for the current tab.
78 bool hide_favicon() const { 60 bool hide_favicon() const {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 98 }
117 99
118 void set_register_callback_overwrites(bool value) { 100 void set_register_callback_overwrites(bool value) {
119 register_callback_overwrites_ = value; 101 register_callback_overwrites_ = value;
120 } 102 }
121 103
122 void set_frame_xpath(const std::string& xpath) { 104 void set_frame_xpath(const std::string& xpath) {
123 frame_xpath_ = xpath; 105 frame_xpath_ = xpath;
124 } 106 }
125 107
108 content::WebUIController* controller() const { return controller_; }
109
126 // Call a Javascript function by sending its name and arguments down to 110 // Call a Javascript function by sending its name and arguments down to
127 // the renderer. This is asynchronous; there's no way to get the result 111 // the renderer. This is asynchronous; there's no way to get the result
128 // of the call, and should be thought of more like sending a message to 112 // of the call, and should be thought of more like sending a message to
129 // the page. 113 // the page.
130 // All function names in WebUI must consist of only ASCII characters. 114 // All function names in WebUI must consist of only ASCII characters.
131 // There are variants for calls with more arguments. 115 // There are variants for calls with more arguments.
132 void CallJavascriptFunction(const std::string& function_name); 116 void CallJavascriptFunction(const std::string& function_name);
133 void CallJavascriptFunction(const std::string& function_name, 117 void CallJavascriptFunction(const std::string& function_name,
134 const base::Value& arg); 118 const base::Value& arg);
135 void CallJavascriptFunction(const std::string& function_name, 119 void CallJavascriptFunction(const std::string& function_name,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 167
184 // Used by test mocks. See the public getters for more information. 168 // Used by test mocks. See the public getters for more information.
185 bool register_callback_overwrites_; // Defaults to false. 169 bool register_callback_overwrites_; // Defaults to false.
186 170
187 // The WebUIMessageHandlers we own. 171 // The WebUIMessageHandlers we own.
188 std::vector<content::WebUIMessageHandler*> handlers_; 172 std::vector<content::WebUIMessageHandler*> handlers_;
189 173
190 // Non-owning pointer to the WebContents this WebUI is associated with. 174 // Non-owning pointer to the WebContents this WebUI is associated with.
191 content::WebContents* web_contents_; 175 content::WebContents* web_contents_;
192 176
177 // TODO(jam): once WebUI objects aren't also WebUIController, make one own the
178 // other.
179 content::WebUIController* controller_;
180
193 private: 181 private:
182 // IPC message handling.
183 void OnWebUISend(const GURL& source_url,
184 const std::string& message,
185 const base::ListValue& args);
186
194 // A map of message name -> message handling callback. 187 // A map of message name -> message handling callback.
195 typedef std::map<std::string, MessageCallback> MessageCallbackMap; 188 typedef std::map<std::string, MessageCallback> MessageCallbackMap;
196 MessageCallbackMap message_callbacks_; 189 MessageCallbackMap message_callbacks_;
197 190
198 // The path for the iframe this WebUI is embedded in (empty if not in an 191 // The path for the iframe this WebUI is embedded in (empty if not in an
199 // iframe). 192 // iframe).
200 std::string frame_xpath_; 193 std::string frame_xpath_;
201 194
202 DISALLOW_COPY_AND_ASSIGN(WebUI); 195 DISALLOW_COPY_AND_ASSIGN(WebUI);
203 }; 196 };
204 197
205 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_ 198 #endif // CONTENT_BROWSER_WEBUI_WEB_UI_H_
OLDNEW
« no previous file with comments | « content/browser/tab_contents/tab_contents_unittest.cc ('k') | content/browser/webui/web_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698