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

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

Powered by Google App Engine
This is Rietveld 408576698