diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 18 | ||||
-rw-r--r-- | chrome/browser/chromeos/offline/offline_load_page.cc | 95 | ||||
-rw-r--r-- | chrome/browser/chromeos/offline/offline_load_page.h | 10 | ||||
-rw-r--r-- | chrome/browser/resources/offline_load.html | 143 |
4 files changed, 174 insertions, 92 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index d28e759..6d092ca 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -7402,17 +7402,25 @@ Keep your key file in a safe place. You will need it to create new versions of y <!-- Offline page --> <if expr="pp_ifdef('chromeos')"> <message name="IDS_OFFLINE_LOAD_HEADLINE" desc="Offline Page HTML headline"> - Network is not available. + Your device is offline. </message> - <message name="IDS_OFFLINE_LOAD_DESCRIPTION" desc="Offline Page HTML description"> - Page will be loaded when network becomes available. Press 'Load Now' if you want to load now. + <message name="IDS_SITE_OFFLINE_LOAD_DESCRIPTION" desc="offline site"> + The webpage at <ph name="HOST_NAME"><strong>$1<ex>www.offline.com</ex></strong></ph> cannot be reached because your network connection is down. The page will be loaded when the network connection is restored. <br> + Try reconnecting, connecting to another network or proceeding with loading anyway. + </message> + <message name="IDS_APP_OFFLINE_LOAD_DESCRIPTION" desc="offline app"> + The app at <ph name="HOST_NAME"><strong>$1<ex>www.offline.com</ex></strong></ph> cannot be reached because your network connection is down. The page will be loaded when the network connection is restored. <br> + Try reconnecting, connecting to another network or proceeding with loading anyway. </message> <message name="IDS_OFFLINE_LOAD_BUTTON"> - Load Now + Load Anyway </message> - <message name="IDS_OFFLINE_BACK_BUTTON"> + <message name="IDS_OFFLINE_CANCEL_BUTTON"> Cancel </message> + <message name="IDS_OFFLINE_NETWORK_SETTINGS"> + Network Settings ... + </message> </if> <!-- SafeBrowsing --> 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_; diff --git a/chrome/browser/resources/offline_load.html b/chrome/browser/resources/offline_load.html index b2042a3..1c1f002 100644 --- a/chrome/browser/resources/offline_load.html +++ b/chrome/browser/resources/offline_load.html @@ -1,75 +1,67 @@ <!DOCTYPE html> <html id="template_root" i18n-values="dir:textdirection"> <head> -<title i18n-content="title"></title> +<title i18n-content="title"> +</title> <style> -body { - background-color:#E0E0E0; - font-family:Helvetica,Arial,sans-serif; - margin:0px; - visibility: hidden; -} -.background { - position:absolute; - width:100%; - height:100%; -} -.cell { - padding:40px; -} -.box { - width:80%; - background-color:white; - color:black; - font-size:10pt; - line-height:16pt; - text-align:left; - padding:20px; - position:relative; - -webkit-box-shadow:3px 3px 8px #200; - border-radius:5px; +html { + height: 100%; } -html[dir='rtl'] .box { - text-align:right; +body { + color: #000; + font-family: Helvetica, Arial, sans-serif; + background-image: -webkit-gradient( + linear, + left bottom, + left top, + color-stop(0, rgb(236,244,255)), + color-stop(0.50, rgb(255,255,255)) + ); + height: 100%; + padding: 0px; + margin: 0px; + display: -webkit-box; + -webkit-box-orient: horizontal; } -.icon { - position:absolute; +#spacer { + -webkit-box-flex: 0.5; } -.title { - margin:0px 87px 0px; - font-size:18pt; - line-height: 140%; - margin-bottom:6pt; - font-weight:bold; - color:#660000; + +#error { + margin-top: 150px; + font-size: 24px; + -webkit-box-flex: 1; + display: -webkit-box; + -webkit-box-orient: horizontal; + max-width : 800px; + width: 80%; } -.main { - margin:0px 90px 0px; + +#error img { + margin-right: 10px; + vertical-align: middle; + -webkit-box-flex: 0; } -.submission { - margin:15px 5px 15px 0px; - padding:0px; + +#error #msg_box { + vertical-align: middle; + -webkit-box-flex: 1; } -input { - margin:0px; + +#heading { + font-weight: bold; } -.thumbnail { - background-repeat: no-repeat; - background-position: center center; - width:400px; - height:250px; - padding:20px; - position:relative; - -webkit-box-shadow:3px 3px 8px #200; - border-radius:5px; - visibility: hidden; +#msg { + font-size: 16px; } +#msg_box a { + font-size: 16px; } -</style> +</style> <script> function sendCommand(cmd) { window.domAutomationController.setAutomationId(1); @@ -86,22 +78,29 @@ function startTimer(time) { } </script> </head> -<body oncontextmenu="return false;" i18n-values="onload:on_load"> -<table width="100%" cellspacing="0" cellpadding="0"> - <td class="cell" valign="middle" align="center"> - <div class="box" id="box"> - <div class="title" i18n-content="headLine"></div> - <div class="main" i18n-values=".innerHTML:description"></div> - <div class="main"> - <form class="submission"> - <input type="button" name="continue_button" i18n-values="value:load_button" onclick="sendCommand('proceed')"><br> - <input type="button" name="back_button" i18n-values="value:back_button;.style.display:display_go_back" onclick="sendCommand('dontproceed')"> - </form> - </div> - </div> - <div id="thumbnail" class="thumbnail" i18n-values=".style.background-image:thumbnailUrl"> - </div> - </td> -</table> + +<body oncontextmenu="return false;" jsvalues="onload:on_load"> +<div id="spacer"> </div> +<div id="error" jsvalues=".title:url"> + <img i18n-values=".src:icon;.style.display:display_icon" + width="96" height="96"> + <div id="msg_box"> + <div id="headling" i18n-values=".innerText:heading"></div> + <div id="msg" i18n-values=".innerHTML:msg"></div> + + <button id="continue_button" i18n-content="load_button" + onclick="sendCommand('proceed')"> + </button> + <button id="cancel_button" i18n-content="cancel_button" + i18n-values=".style.display:display_cancel" + onclick="sendCommand('dontproceed')"> + </button> + <a href="chrome://settings/internet" + onclick="sendCommand('open_network_settings')" + i18n-content="network_settings"> + </a> + </div> +</div> +<div id="spacer"> </div> </body> </html> |