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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_resource_cache_android.cc

Issue 9558014: Add an android specific ntp resource cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
6
7 #include "base/command_line.h"
Dan Beam 2012/03/01 03:45:32 I don't think you need many of these headers.
Ted C 2012/03/01 18:35:54 Ah yes...I initially had this file match closer wh
8 #include "base/string16.h"
9 #include "base/string_piece.h"
10 #include "base/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "base/memory/ref_counted_memory.h"
13 #include "chrome/browser/google/google_util.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
16 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
17 #include "chrome/common/jstemplate_builder.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_service.h"
20 #include "grit/browser_resources.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h"
24
25 using content::BrowserThread;
26
27 namespace {
28
29 const char kLearnMoreIncognitoUrl[] =
30 "https://www.google.com/support/chrome/bin/answer.py?answer=95464";
31
32 } // namespace
33
34 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) {}
35
36 NTPResourceCache::~NTPResourceCache() {}
37
38 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 // Android uses same html/css for incognito NTP and normal NTP
41 if (!new_tab_html_.get())
42 CreateNewTabHTML();
43 return new_tab_html_.get();
44 }
45
46 RefCountedMemory* NTPResourceCache::GetNewTabCSS(bool is_incognito) {
47 // This is used for themes, which are not currently supported on Android.
48 NOTIMPLEMENTED();
49 return NULL;
50 }
51
52 void NTPResourceCache::Observe(int type,
53 const content::NotificationSource& source,
54 const content::NotificationDetails& details) {
55 // No notificaitons necessary in Android.
Dan Beam 2012/03/01 03:45:32 notifications
Ted C 2012/03/01 18:35:54 Done.
56 }
57
58 void NTPResourceCache::CreateNewTabHTML() {
59 // TODO(estade): these strings should be defined in their relevant handlers
60 // (in GetLocalizedValues) and should have more legible names.
61 // Show the profile name in the title and most visited labels if the current
62 // profile is not the default.
63 DictionaryValue localized_strings;
64 localized_strings.SetString("hasattribution", "false");
65 localized_strings.SetString("title",
66 l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
67 localized_strings.SetString("mostvisited",
68 l10n_util::GetStringUTF16(IDS_NEW_TAB_MOST_VISITED));
69 localized_strings.SetString("recentlyclosed",
70 l10n_util::GetStringUTF16(IDS_NEW_TAB_RECENTLY_CLOSED));
71
72 NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings);
73
74 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings);
75
76 base::StringPiece new_tab_html(ResourceBundle::GetSharedInstance().
77 GetRawDataResource(IDR_NEW_TAB_4_HTML));
78
79 const char* new_tab_link = kLearnMoreIncognitoUrl;
80 string16 learnMoreLink = ASCIIToUTF16(
81 google_util::AppendGoogleLocaleParam(GURL(new_tab_link)).spec());
82 localized_strings.SetString("content",
83 l10n_util::GetStringFUTF16(IDS_NEW_TAB_OTR_MESSAGE, learnMoreLink));
84
85 // Load the new tab page appropriate for this build
Dan Beam 2012/03/01 03:45:32 nit: end comment with .
Ted C 2012/03/01 18:35:54 Done.
86 std::string full_html;
87
88 // Inject the template data into the HTML so that it is available before any
89 // layout is needed.
90 std::string json_html;
91 jstemplate_builder::AppendJsonHtml(&localized_strings, &json_html);
92
93 static const base::StringPiece template_data_placeholder(
94 "<!-- template data placeholder -->");
95 size_t pos = new_tab_html.find(template_data_placeholder);
96
97 if (pos != base::StringPiece::npos) {
98 full_html.assign(new_tab_html.data(), pos);
99 full_html.append(json_html);
100 size_t after_offset = pos + template_data_placeholder.size();
101 full_html.append(new_tab_html.data() + after_offset,
102 new_tab_html.size() - after_offset);
103 } else {
104 NOTREACHED();
105 full_html.assign(new_tab_html.data(), new_tab_html.size());
106 }
107
108 new_tab_html_ = base::RefCountedString::TakeString(&full_html);
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698