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

Side by Side Diff: content/browser/webui/web_ui_message_handler.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.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/public/browser/web_ui_message_handler.h"
6
7 #include "base/i18n/rtl.h"
8 #include "base/logging.h"
9 #include "base/values.h"
10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h"
12 #include "googleurl/src/gurl.h"
13
14 namespace content {
15
16 void WebUIMessageHandler::SetURLAndTitle(DictionaryValue* dictionary,
17 string16 title,
18 const GURL& gurl) {
19 dictionary->SetString("url", gurl.spec());
20
21 bool using_url_as_the_title = false;
22 if (title.empty()) {
23 using_url_as_the_title = true;
24 title = UTF8ToUTF16(gurl.spec());
25 }
26
27 // Since the title can contain BiDi text, we need to mark the text as either
28 // RTL or LTR, depending on the characters in the string. If we use the URL
29 // as the title, we mark the title as LTR since URLs are always treated as
30 // left to right strings.
31 string16 title_to_set(title);
32 if (base::i18n::IsRTL()) {
33 if (using_url_as_the_title) {
34 base::i18n::WrapStringWithLTRFormatting(&title_to_set);
35 } else {
36 base::i18n::AdjustStringForLocaleDirection(&title_to_set);
37 }
38 }
39 dictionary->SetString("title", title_to_set);
40 }
41
42 bool WebUIMessageHandler::ExtractIntegerValue(const ListValue* value,
43 int* out_int) {
44 std::string string_value;
45 if (value->GetString(0, &string_value))
46 return base::StringToInt(string_value, out_int);
47 double double_value;
48 if (value->GetDouble(0, &double_value)) {
49 *out_int = static_cast<int>(double_value);
50 return true;
51 }
52 NOTREACHED();
53 return false;
54 }
55
56 bool WebUIMessageHandler::ExtractDoubleValue(const ListValue* value,
57 double* out_value) {
58 std::string string_value;
59 if (value->GetString(0, &string_value))
60 return base::StringToDouble(string_value, out_value);
61 NOTREACHED();
62 return false;
63 }
64
65 string16 WebUIMessageHandler::ExtractStringValue(const ListValue* value) {
66 string16 string16_value;
67 if (value->GetString(0, &string16_value))
68 return string16_value;
69 NOTREACHED();
70 return string16();
71 }
72
73 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/web_ui.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698