summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 00:50:34 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 00:50:34 +0000
commitf34871868e10fd8a454ab8d262b87381ef4456b0 (patch)
tree085b90357ac0854f1baf2b880f1d5b9a0ac410e2 /chrome/browser/chromeos
parente06c3beae331e70eb038a859b0ab6945fef041fb (diff)
downloadchromium_src-f34871868e10fd8a454ab8d262b87381ef4456b0.zip
chromium_src-f34871868e10fd8a454ab8d262b87381ef4456b0.tar.gz
chromium_src-f34871868e10fd8a454ab8d262b87381ef4456b0.tar.bz2
New offline page that is closer to mock. This is intermediate solution and I will work on merging chrome's error page and
offline page after beta. BUG=chromium-os:5066, chromium-os:8285 TEST=turn off wifi, disconnect ethernet. open app from ntp and/or type in url in omnibox. New offline page should be shown as in 5066. Review URL: http://codereview.chromium.org/5151006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/offline/offline_load_page.cc95
-rw-r--r--chrome/browser/chromeos/offline/offline_load_page.h10
2 files changed, 90 insertions, 15 deletions
diff --git a/chrome/browser/chromeos/offline/offline_load_page.cc b/chrome/browser/chromeos/offline/offline_load_page.cc
index e4829e7..94893a1 100644
--- a/chrome/browser/chromeos/offline/offline_load_page.cc
+++ b/chrome/browser/chromeos/offline/offline_load_page.cc
@@ -12,14 +12,19 @@
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/notification_type.h"
+#include "chrome/common/url_constants.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
@@ -63,28 +68,46 @@ OfflineLoadPage::OfflineLoadPage(TabContents* tab_contents,
std::string OfflineLoadPage::GetHTMLContents() {
DictionaryValue strings;
- SetString(&strings, "headLine", IDS_OFFLINE_LOAD_HEADLINE);
- SetString(&strings, "description", IDS_OFFLINE_LOAD_DESCRIPTION);
- SetString(&strings, "load_button", IDS_OFFLINE_LOAD_BUTTON);
- SetString(&strings, "back_button", IDS_OFFLINE_BACK_BUTTON);
-
- // TODO(oshima): tab()->GetTitle() always return url. This has to be
- // a cached title.
- strings.SetString("title", tab()->GetTitle());
- strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
- strings.SetString("display_go_back",
+ // Toggle Cancel button.
+ strings.SetString("display_cancel",
tab()->controller().CanGoBack() ? "inline" : "none");
+
int64 time_to_wait = std::max(
static_cast<int64>(0),
kMaxBlankPeriod -
- NetworkStateNotifier::GetOfflineDuration().InMilliseconds());
+ NetworkStateNotifier::GetOfflineDuration().InMilliseconds());
+ // Set the timeout to show the page.
strings.SetString("on_load",
WideToUTF16Hack(base::StringPrintf(L"startTimer(%ld)",
- time_to_wait)));
+ time_to_wait)));
+ // Button labels
+ SetString(&strings, "load_button", IDS_OFFLINE_LOAD_BUTTON);
+ SetString(&strings, "cancel_button", IDS_OFFLINE_CANCEL_BUTTON);
+
+ SetString(&strings, "heading", IDS_OFFLINE_LOAD_HEADLINE);
+ SetString(&strings, "network_settings", IDS_OFFLINE_NETWORK_SETTINGS);
- // TODO(oshima): thumbnail is not working yet. fix this.
- const std::string url = "chrome://thumb/" + GetURL().spec();
- strings.SetString("thumbnailUrl", "url(" + url + ")");
+ bool rtl = base::i18n::IsRTL();
+ strings.SetString("textdirection", rtl ? "rtl" : "ltr");
+
+ string16 failed_url(ASCIIToUTF16(url().spec()));
+ if (rtl)
+ base::i18n::WrapStringWithLTRFormatting(&failed_url);
+ strings.SetString("url", failed_url);
+
+ // The offline page for app has icons and slightly different message.
+ Profile* profile = tab()->profile();
+ DCHECK(profile);
+ const Extension* extension = NULL;
+ ExtensionsService* extensions_service = profile->GetExtensionsService();
+ // Extension service does not exist in test.
+ if (extensions_service)
+ extension = extensions_service->GetExtensionByWebExtent(url());
+
+ if (extension)
+ GetAppOfflineStrings(extension, failed_url, &strings);
+ else
+ GetNormalOfflineStrings(failed_url, &strings);
base::StringPiece html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
@@ -92,6 +115,44 @@ std::string OfflineLoadPage::GetHTMLContents() {
return jstemplate_builder::GetI18nTemplateHtml(html, &strings);
}
+void OfflineLoadPage::GetAppOfflineStrings(
+ const Extension* app,
+ const string16& failed_url,
+ DictionaryValue* strings) const {
+ strings->SetString("title", app->name());
+
+ GURL icon_url = app->GetIconURL(Extension::EXTENSION_ICON_LARGE,
+ ExtensionIconSet::MATCH_EXACTLY);
+ if (icon_url.is_empty()) {
+ strings->SetString("display_icon", "none");
+ strings->SetString("icon", string16());
+ } else {
+ // Default icon is not accessible from interstitial page.
+ // TODO(oshima): Figure out how to use default icon.
+ strings->SetString("display_icon", "block");
+ strings->SetString("icon", icon_url.spec());
+ }
+
+ strings->SetString(
+ "msg",
+ l10n_util::GetStringFUTF16(IDS_APP_OFFLINE_LOAD_DESCRIPTION,
+ failed_url));
+}
+
+void OfflineLoadPage::GetNormalOfflineStrings(
+ const string16& failed_url, DictionaryValue* strings) const {
+ strings->SetString("title", tab()->GetTitle());
+
+ // No icon for normal web site.
+ strings->SetString("display_icon", "none");
+ strings->SetString("icon", string16());
+
+ strings->SetString(
+ "msg",
+ l10n_util::GetStringFUTF16(IDS_SITE_OFFLINE_LOAD_DESCRIPTION,
+ failed_url));
+}
+
void OfflineLoadPage::CommandReceived(const std::string& cmd) {
std::string command(cmd);
// The Jasonified response has quotes, remove them.
@@ -103,6 +164,10 @@ void OfflineLoadPage::CommandReceived(const std::string& cmd) {
Proceed();
} else if (command == "dontproceed") {
DontProceed();
+ } else if (command == "open_network_settings") {
+ Browser* browser = BrowserList::GetLastActive();
+ DCHECK(browser);
+ browser->ShowOptionsTab(chrome::kInternetOptionsSubPage);
} else {
LOG(WARNING) << "Unknown command:" << cmd;
}
diff --git a/chrome/browser/chromeos/offline/offline_load_page.h b/chrome/browser/chromeos/offline/offline_load_page.h
index b6eb046..fc8c528 100644
--- a/chrome/browser/chromeos/offline/offline_load_page.h
+++ b/chrome/browser/chromeos/offline/offline_load_page.h
@@ -13,6 +13,8 @@
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_service.h"
+class DictionaryValue;
+class Extension;
class TabContents;
namespace chromeos {
@@ -59,6 +61,14 @@ class OfflineLoadPage : public InterstitialPage {
const NotificationSource& source,
const NotificationDetails& details);
+ // Retrieves template strings of the offline page for app and
+ // normal site.
+ void GetAppOfflineStrings(const Extension* app,
+ const string16& faield_url,
+ DictionaryValue* strings) const;
+ void GetNormalOfflineStrings(const string16& faield_url,
+ DictionaryValue* strings) const;
+
Delegate* delegate_;
NotificationRegistrar registrar_;