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

Side by Side Diff: chrome/browser/chromeos/offline/offline_load_page.cc

Issue 5151006: New offline page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/offline/offline_load_page.h" 5 #include "chrome/browser/chromeos/offline/offline_load_page.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/string_piece.h" 11 #include "base/string_piece.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_list.h"
15 #include "chrome/browser/browser_thread.h" 16 #include "chrome/browser/browser_thread.h"
17 #include "chrome/browser/extensions/extensions_service.h"
18 #include "chrome/browser/profile.h"
16 #include "chrome/browser/tab_contents/navigation_controller.h" 19 #include "chrome/browser/tab_contents/navigation_controller.h"
17 #include "chrome/browser/tab_contents/navigation_entry.h" 20 #include "chrome/browser/tab_contents/navigation_entry.h"
18 #include "chrome/browser/tab_contents/tab_contents.h" 21 #include "chrome/browser/tab_contents/tab_contents.h"
19 #include "chrome/browser/tab_contents/tab_util.h" 22 #include "chrome/browser/tab_contents/tab_util.h"
20 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/common/extensions/extension.h"
21 #include "chrome/common/jstemplate_builder.h" 25 #include "chrome/common/jstemplate_builder.h"
22 #include "chrome/common/notification_type.h" 26 #include "chrome/common/notification_type.h"
27 #include "chrome/common/url_constants.h"
23 #include "grit/browser_resources.h" 28 #include "grit/browser_resources.h"
24 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
25 30
26 namespace { 31 namespace {
27 32
28 // Maximum time to show a blank page. 33 // Maximum time to show a blank page.
29 const int kMaxBlankPeriod = 3000; 34 const int kMaxBlankPeriod = 3000;
30 35
31 // A utility function to set the dictionary's value given by |resource_id|. 36 // A utility function to set the dictionary's value given by |resource_id|.
32 void SetString(DictionaryValue* strings, const char* name, int resource_id) { 37 void SetString(DictionaryValue* strings, const char* name, int resource_id) {
(...skipping 23 matching lines...) Expand all
56 const GURL& url, 61 const GURL& url,
57 Delegate* delegate) 62 Delegate* delegate)
58 : InterstitialPage(tab_contents, true, url), 63 : InterstitialPage(tab_contents, true, url),
59 delegate_(delegate) { 64 delegate_(delegate) {
60 registrar_.Add(this, NotificationType::NETWORK_STATE_CHANGED, 65 registrar_.Add(this, NotificationType::NETWORK_STATE_CHANGED,
61 NotificationService::AllSources()); 66 NotificationService::AllSources());
62 } 67 }
63 68
64 std::string OfflineLoadPage::GetHTMLContents() { 69 std::string OfflineLoadPage::GetHTMLContents() {
65 DictionaryValue strings; 70 DictionaryValue strings;
66 SetString(&strings, "headLine", IDS_OFFLINE_LOAD_HEADLINE); 71 // Toggle Cancel button.
67 SetString(&strings, "description", IDS_OFFLINE_LOAD_DESCRIPTION); 72 strings.SetString("display_cancel",
68 SetString(&strings, "load_button", IDS_OFFLINE_LOAD_BUTTON); 73 tab()->controller().CanGoBack() ? "inline" : "none");
69 SetString(&strings, "back_button", IDS_OFFLINE_BACK_BUTTON);
70 74
71 // TODO(oshima): tab()->GetTitle() always return url. This has to be
72 // a cached title.
73 strings.SetString("title", tab()->GetTitle());
74 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
75 strings.SetString("display_go_back",
76 tab()->controller().CanGoBack() ? "inline" : "none");
77 int64 time_to_wait = std::max( 75 int64 time_to_wait = std::max(
78 static_cast<int64>(0), 76 static_cast<int64>(0),
79 kMaxBlankPeriod - 77 kMaxBlankPeriod -
80 NetworkStateNotifier::GetOfflineDuration().InMilliseconds()); 78 NetworkStateNotifier::GetOfflineDuration().InMilliseconds());
79 // Set the timeout to show the page.
81 strings.SetString("on_load", 80 strings.SetString("on_load",
82 WideToUTF16Hack(base::StringPrintf(L"startTimer(%ld)", 81 WideToUTF16Hack(base::StringPrintf(L"startTimer(%ld)",
83 time_to_wait))); 82 time_to_wait)));
83 // Button labels
84 SetString(&strings, "load_button", IDS_OFFLINE_LOAD_BUTTON);
85 SetString(&strings, "cancel_button", IDS_OFFLINE_CANCEL_BUTTON);
84 86
85 // TODO(oshima): thumbnail is not working yet. fix this. 87 SetString(&strings, "heading", IDS_OFFLINE_LOAD_HEADLINE);
86 const std::string url = "chrome://thumb/" + GetURL().spec(); 88 SetString(&strings, "network_settings", IDS_OFFLINE_NETWORK_SETTINGS);
87 strings.SetString("thumbnailUrl", "url(" + url + ")"); 89
90 bool rtl = base::i18n::IsRTL();
91 strings.SetString("textdirection", rtl ? "rtl" : "ltr");
92
93 string16 failed_url(ASCIIToUTF16(url().spec()));
94 if (rtl)
95 base::i18n::WrapStringWithLTRFormatting(&failed_url);
96 strings.SetString("url", failed_url);
97
98 // The offline page for app has icons and slightly different message.
99 Profile* profile = tab()->profile();
100 DCHECK(profile);
101 const Extension* extension = NULL;
102 ExtensionsService* extensions_service = profile->GetExtensionsService();
103 // Extension service does not exist in test.
104 if (extensions_service)
105 extension = extensions_service->GetExtensionByWebExtent(url());
106
107 if (extension)
108 GetAppOfflineStrings(extension, failed_url, &strings);
109 else
110 GetNormalOfflineStrings(failed_url, &strings);
88 111
89 base::StringPiece html( 112 base::StringPiece html(
90 ResourceBundle::GetSharedInstance().GetRawDataResource( 113 ResourceBundle::GetSharedInstance().GetRawDataResource(
91 IDR_OFFLINE_LOAD_HTML)); 114 IDR_OFFLINE_LOAD_HTML));
92 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); 115 return jstemplate_builder::GetI18nTemplateHtml(html, &strings);
93 } 116 }
94 117
118 void OfflineLoadPage::GetAppOfflineStrings(
119 const Extension* app,
120 const string16& failed_url,
121 DictionaryValue* strings) const {
122 strings->SetString("title", app->name());
123
124 GURL icon_url = app->GetIconURL(Extension::EXTENSION_ICON_LARGE,
125 ExtensionIconSet::MATCH_EXACTLY);
126 if (icon_url.is_empty()) {
127 strings->SetString("display_icon", "none");
128 strings->SetString("icon", string16());
129 } else {
130 // Default icon is not accessible from interstitial page.
131 // TODO(oshima): Figure out how to use default icon.
132 strings->SetString("display_icon", "block");
133 strings->SetString("icon", icon_url.spec());
134 }
135
136 strings->SetString(
137 "msg",
138 l10n_util::GetStringFUTF16(IDS_APP_OFFLINE_LOAD_DESCRIPTION,
139 failed_url));
140 }
141
142 void OfflineLoadPage::GetNormalOfflineStrings(
143 const string16& failed_url, DictionaryValue* strings) const {
144 strings->SetString("title", tab()->GetTitle());
145
146 // No icon for normal web site.
147 strings->SetString("display_icon", "none");
148 strings->SetString("icon", string16());
149
150 strings->SetString(
151 "msg",
152 l10n_util::GetStringFUTF16(IDS_SITE_OFFLINE_LOAD_DESCRIPTION,
153 failed_url));
154 }
155
95 void OfflineLoadPage::CommandReceived(const std::string& cmd) { 156 void OfflineLoadPage::CommandReceived(const std::string& cmd) {
96 std::string command(cmd); 157 std::string command(cmd);
97 // The Jasonified response has quotes, remove them. 158 // The Jasonified response has quotes, remove them.
98 if (command.length() > 1 && command[0] == '"') { 159 if (command.length() > 1 && command[0] == '"') {
99 command = command.substr(1, command.length() - 2); 160 command = command.substr(1, command.length() - 2);
100 } 161 }
101 // TODO(oshima): record action for metrics. 162 // TODO(oshima): record action for metrics.
102 if (command == "proceed") { 163 if (command == "proceed") {
103 Proceed(); 164 Proceed();
104 } else if (command == "dontproceed") { 165 } else if (command == "dontproceed") {
105 DontProceed(); 166 DontProceed();
167 } else if (command == "open_network_settings") {
168 Browser* browser = BrowserList::GetLastActive();
169 DCHECK(browser);
170 browser->ShowOptionsTab(chrome::kInternetOptionsSubPage);
106 } else { 171 } else {
107 LOG(WARNING) << "Unknown command:" << cmd; 172 LOG(WARNING) << "Unknown command:" << cmd;
108 } 173 }
109 } 174 }
110 175
111 void OfflineLoadPage::Proceed() { 176 void OfflineLoadPage::Proceed() {
112 delegate_->OnBlockingPageComplete(true); 177 delegate_->OnBlockingPageComplete(true);
113 InterstitialPage::Proceed(); 178 InterstitialPage::Proceed();
114 } 179 }
115 180
(...skipping 15 matching lines...) Expand all
131 registrar_.Remove(this, NotificationType::NETWORK_STATE_CHANGED, 196 registrar_.Remove(this, NotificationType::NETWORK_STATE_CHANGED,
132 NotificationService::AllSources()); 197 NotificationService::AllSources());
133 Proceed(); 198 Proceed();
134 } 199 }
135 } else { 200 } else {
136 InterstitialPage::Observe(type, source, details); 201 InterstitialPage::Observe(type, source, details);
137 } 202 }
138 } 203 }
139 204
140 } // namespace chromeos 205 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698