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

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

Issue 9224002: Make WebUI objects not derive from WebUI. WebUI objects own the controller. This is the ownership... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head to clear linux_chromeos browsertest failures 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
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 #include "content/browser/webui/web_ui.h" 5 #include "content/browser/webui/web_ui.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 23 matching lines...) Expand all
34 if (i > 0) 34 if (i > 0)
35 parameters += char16(','); 35 parameters += char16(',');
36 36
37 base::JSONWriter::Write(arg_list[i], false, &json); 37 base::JSONWriter::Write(arg_list[i], false, &json);
38 parameters += UTF8ToUTF16(json); 38 parameters += UTF8ToUTF16(json);
39 } 39 }
40 return ASCIIToUTF16(function_name) + 40 return ASCIIToUTF16(function_name) +
41 char16('(') + parameters + char16(')') + char16(';'); 41 char16('(') + parameters + char16(')') + char16(';');
42 } 42 }
43 43
44 WebUI::WebUI(WebContents* contents, 44 WebUI::WebUI(WebContents* contents)
45 WebUIController* controller) 45 : focus_location_bar_by_default_(false),
46 : hide_favicon_(false),
47 focus_location_bar_by_default_(false),
48 should_hide_url_(false), 46 should_hide_url_(false),
49 link_transition_type_(content::PAGE_TRANSITION_LINK), 47 link_transition_type_(content::PAGE_TRANSITION_LINK),
50 bindings_(content::BINDINGS_POLICY_WEB_UI), 48 bindings_(content::BINDINGS_POLICY_WEB_UI),
51 register_callback_overwrites_(false), 49 register_callback_overwrites_(false),
52 web_contents_(contents), 50 web_contents_(contents) {
53 controller_(controller) {
54 DCHECK(contents); 51 DCHECK(contents);
55 AddMessageHandler(new GenericHandler()); 52 AddMessageHandler(new GenericHandler());
56 } 53 }
57 54
58 WebUI::~WebUI() { 55 WebUI::~WebUI() {
56 // Delete the controller first, since it may also be keeping a pointer to some
57 // of the handlers and can call them at destruction.
58 controller_.reset();
59 STLDeleteContainerPointers(handlers_.begin(), handlers_.end()); 59 STLDeleteContainerPointers(handlers_.begin(), handlers_.end());
60 } 60 }
61 61
62 // WebUI, public: ------------------------------------------------------------- 62 // WebUI, public: -------------------------------------------------------------
63 63
64 const WebUI::TypeID WebUI::kNoWebUI = NULL; 64 const WebUI::TypeID WebUI::kNoWebUI = NULL;
65 65
66 bool WebUI::OnMessageReceived(const IPC::Message& message) { 66 bool WebUI::OnMessageReceived(const IPC::Message& message) {
67 bool handled = true; 67 bool handled = true;
68 IPC_BEGIN_MESSAGE_MAP(WebUI, message) 68 IPC_BEGIN_MESSAGE_MAP(WebUI, message)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 #endif // defined(TOOLKIT_VIEWS) 108 #endif // defined(TOOLKIT_VIEWS)
109 109
110 // Let the WebUI know that we're looking for UI that's optimized for touch 110 // Let the WebUI know that we're looking for UI that's optimized for touch
111 // input. 111 // input.
112 // TODO(rbyers) Figure out the right model for enabling touch-optimized UI 112 // TODO(rbyers) Figure out the right model for enabling touch-optimized UI
113 // (http://crbug.com/105380). 113 // (http://crbug.com/105380).
114 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTouchOptimizedUI)) 114 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTouchOptimizedUI))
115 render_view_host->SetWebUIProperty("touchOptimized", "true"); 115 render_view_host->SetWebUIProperty("touchOptimized", "true");
116 } 116 }
117 117
118 WebContents* WebUI::GetWebContents() const {
119 return web_contents_;
120 }
121
122 bool WebUI::ShouldHideFavicon() const {
123 return hide_favicon_;
124 }
125
126 void WebUI::HideFavicon() {
127 hide_favicon_ = true;
128 }
129
130 bool WebUI::ShouldFocusLocationBarByDefault() const {
131 return focus_location_bar_by_default_;
132 }
133
134 void WebUI::FocusLocationBarByDefault() {
135 focus_location_bar_by_default_ = true;
136 }
137
138 bool WebUI::ShouldHideURL() const {
139 return should_hide_url_;
140 }
141
142 void WebUI::HideURL() {
143 should_hide_url_ = true;
144 }
145
146 const string16& WebUI::GetOverriddenTitle() const {
147 return overridden_title_;
148 }
149
150 void WebUI::OverrideTitle(const string16& title) {
151 overridden_title_ = title;
152 }
153
154 content::PageTransition WebUI::GetLinkTransitionType() const {
155 return link_transition_type_;
156 }
157
158 void WebUI::SetLinkTransitionType(content::PageTransition type) {
159 link_transition_type_ = type;
160 }
161
162 int WebUI::GetBindings() const {
163 return bindings_;
164 }
165
166 void WebUI::SetBindings(int bindings) {
167 bindings_ = bindings;
168 }
169
170 void WebUI::SetFrameXPath(const std::string& xpath) {
171 frame_xpath_ = xpath;
172 }
173
174 WebUIController* WebUI::GetController() const {
175 return controller_.get();
176 }
177
178 void WebUI::SetController(WebUIController* controller) {
179 controller_.reset(controller);
Jói 2012/01/17 17:34:05 There might be a bug here w.r.t. the ownership mod
jam 2012/01/17 17:38:35 scoped_ptr::reset() does that :)
180 }
181
118 void WebUI::CallJavascriptFunction(const std::string& function_name) { 182 void WebUI::CallJavascriptFunction(const std::string& function_name) {
119 DCHECK(IsStringASCII(function_name)); 183 DCHECK(IsStringASCII(function_name));
120 string16 javascript = ASCIIToUTF16(function_name + "();"); 184 string16 javascript = ASCIIToUTF16(function_name + "();");
121 ExecuteJavascript(javascript); 185 ExecuteJavascript(javascript);
122 } 186 }
123 187
124 void WebUI::CallJavascriptFunction(const std::string& function_name, 188 void WebUI::CallJavascriptFunction(const std::string& function_name,
125 const Value& arg) { 189 const Value& arg) {
126 DCHECK(IsStringASCII(function_name)); 190 DCHECK(IsStringASCII(function_name));
127 std::vector<const Value*> args; 191 std::vector<const Value*> args;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 DCHECK(!handler->web_ui()); 252 DCHECK(!handler->web_ui());
189 handler->set_web_ui(this); 253 handler->set_web_ui(this);
190 handler->RegisterMessages(); 254 handler->RegisterMessages();
191 handlers_.push_back(handler); 255 handlers_.push_back(handler);
192 } 256 }
193 257
194 void WebUI::ExecuteJavascript(const string16& javascript) { 258 void WebUI::ExecuteJavascript(const string16& javascript) {
195 web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( 259 web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
196 ASCIIToUTF16(frame_xpath_), javascript); 260 ASCIIToUTF16(frame_xpath_), javascript);
197 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698