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

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

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/web_ui.h ('k') | content/browser/webui/web_ui_message_handler.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 #include "content/browser/webui/web_ui.h" 5 #include "content/browser/webui/web_ui.h"
6 6
7 #include "base/i18n/rtl.h"
8 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
9 #include "base/stl_util.h" 8 #include "base/stl_util.h"
10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 10 #include "base/values.h"
13 #include "content/browser/child_process_security_policy.h" 11 #include "content/browser/child_process_security_policy.h"
14 #include "content/browser/renderer_host/render_process_host_impl.h" 12 #include "content/browser/renderer_host/render_process_host_impl.h"
15 #include "content/browser/renderer_host/render_view_host.h" 13 #include "content/browser/renderer_host/render_view_host.h"
16 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
17 #include "content/browser/tab_contents/tab_contents_view.h" 15 #include "content/browser/tab_contents/tab_contents_view.h"
18 #include "content/browser/webui/generic_handler.h" 16 #include "content/browser/webui/generic_handler.h"
19 #include "content/common/view_messages.h" 17 #include "content/common/view_messages.h"
20 #include "content/public/common/bindings_policy.h" 18 #include "content/public/common/bindings_policy.h"
21 #include "ipc/ipc_message.h"
22 #include "ipc/ipc_message_macros.h"
23 19
24 using content::WebContents; 20 using content::WebContents;
21 using content::WebUIMessageHandler;
25 22
26 // static 23 // static
27 string16 WebUI::GetJavascriptCall( 24 string16 WebUI::GetJavascriptCall(
28 const std::string& function_name, 25 const std::string& function_name,
29 const std::vector<const Value*>& arg_list) { 26 const std::vector<const Value*>& arg_list) {
30 string16 parameters; 27 string16 parameters;
31 std::string json; 28 std::string json;
32 for (size_t i = 0; i < arg_list.size(); ++i) { 29 for (size_t i = 0; i < arg_list.size(); ++i) {
33 if (i > 0) 30 if (i > 0)
34 parameters += char16(','); 31 parameters += char16(',');
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 DCHECK(!handler->web_ui()); 170 DCHECK(!handler->web_ui());
174 handler->set_web_ui(this); 171 handler->set_web_ui(this);
175 handler->RegisterMessages(); 172 handler->RegisterMessages();
176 handlers_.push_back(handler); 173 handlers_.push_back(handler);
177 } 174 }
178 175
179 void WebUI::ExecuteJavascript(const string16& javascript) { 176 void WebUI::ExecuteJavascript(const string16& javascript) {
180 web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( 177 web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
181 ASCIIToUTF16(frame_xpath_), javascript); 178 ASCIIToUTF16(frame_xpath_), javascript);
182 } 179 }
183
184 ///////////////////////////////////////////////////////////////////////////////
185 // WebUIMessageHandler
186 WebUIMessageHandler::WebUIMessageHandler() : web_ui_(NULL) {
187 }
188
189 WebUIMessageHandler::~WebUIMessageHandler() {
190 }
191
192 // WebUIMessageHandler, protected: ---------------------------------------------
193
194 void WebUIMessageHandler::SetURLAndTitle(DictionaryValue* dictionary,
195 string16 title,
196 const GURL& gurl) {
197 dictionary->SetString("url", gurl.spec());
198
199 bool using_url_as_the_title = false;
200 if (title.empty()) {
201 using_url_as_the_title = true;
202 title = UTF8ToUTF16(gurl.spec());
203 }
204
205 // Since the title can contain BiDi text, we need to mark the text as either
206 // RTL or LTR, depending on the characters in the string. If we use the URL
207 // as the title, we mark the title as LTR since URLs are always treated as
208 // left to right strings.
209 string16 title_to_set(title);
210 if (base::i18n::IsRTL()) {
211 if (using_url_as_the_title) {
212 base::i18n::WrapStringWithLTRFormatting(&title_to_set);
213 } else {
214 base::i18n::AdjustStringForLocaleDirection(&title_to_set);
215 }
216 }
217 dictionary->SetString("title", title_to_set);
218 }
219
220 bool WebUIMessageHandler::ExtractIntegerValue(const ListValue* value,
221 int* out_int) {
222 std::string string_value;
223 if (value->GetString(0, &string_value))
224 return base::StringToInt(string_value, out_int);
225 double double_value;
226 if (value->GetDouble(0, &double_value)) {
227 *out_int = static_cast<int>(double_value);
228 return true;
229 }
230 NOTREACHED();
231 return false;
232 }
233
234 bool WebUIMessageHandler::ExtractDoubleValue(const ListValue* value,
235 double* out_value) {
236 std::string string_value;
237 if (value->GetString(0, &string_value))
238 return base::StringToDouble(string_value, out_value);
239 NOTREACHED();
240 return false;
241 }
242
243 string16 WebUIMessageHandler::ExtractStringValue(const ListValue* value) {
244 string16 string16_value;
245 if (value->GetString(0, &string16_value))
246 return string16_value;
247 NOTREACHED();
248 return string16();
249 }
OLDNEW
« no previous file with comments | « content/browser/webui/web_ui.h ('k') | content/browser/webui/web_ui_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698