Chromium Code Reviews| Index: chrome/browser/net/net_error_tab_helper.cc |
| diff --git a/chrome/browser/net/net_error_tab_helper.cc b/chrome/browser/net/net_error_tab_helper.cc |
| index a0e73cf6cb1e2c50084dc6ce1a1817860884b2fe..f800dcc98a95b58a5557b52a059a0661c808faa5 100644 |
| --- a/chrome/browser/net/net_error_tab_helper.cc |
| +++ b/chrome/browser/net/net_error_tab_helper.cc |
| @@ -13,10 +13,13 @@ |
| #include "chrome/browser/net/net_error_diagnostics_dialog.h" |
| #include "chrome/browser/platform_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/localized_error.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/render_messages.h" |
| #include "components/error_page/common/net_error_info.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/navigation_handle.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "ipc/ipc_message_macros.h" |
| #include "net/base/net_errors.h" |
| @@ -24,7 +27,7 @@ |
| #if defined(OS_ANDROID) |
| #include "chrome/browser/android/tab_android.h" |
| -#endif |
| +#endif // defined(OS_ANDROID) |
| using content::BrowserContext; |
| using content::BrowserThread; |
| @@ -124,8 +127,8 @@ void NetErrorTabHelper::DidStartProvisionalLoadForFrame( |
| is_error_page_ = is_error_page; |
| #if defined(OS_ANDROID) |
| - SetHasOfflinePages(render_frame_host); |
| -#endif |
| + SetOfflinePageInfo(render_frame_host); |
| +#endif // defined(OS_ANDROID) |
| } |
| void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( |
| @@ -177,7 +180,8 @@ bool NetErrorTabHelper::OnMessageReceived( |
| RunNetworkDiagnostics) |
| #if defined(OS_ANDROID) |
| IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) |
| -#endif |
| + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LoadOfflineCopy, LoadOfflineCopy) |
| +#endif // defined(OS_ANDROID) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| @@ -286,23 +290,53 @@ void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
| } |
| #if defined(OS_ANDROID) |
| -void NetErrorTabHelper::SetHasOfflinePages( |
| - content::RenderFrameHost* render_frame_host) { |
| +void NetErrorTabHelper::SetOfflinePageInfo( |
| + content::RenderFrameHost* render_frame_host) { |
| DCHECK(web_contents()); |
| + std::vector<GURL> offline_page_urls; |
| TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| - bool has_offline_pages = tab && tab->HasOfflinePages(); |
| + if (tab) |
| + tab->GetAllOfflinePageURLS(&offline_page_urls); |
| render_frame_host->Send( |
| - new ChromeViewMsg_SetHasOfflinePages( |
| - render_frame_host->GetRoutingID(), |
| - has_offline_pages)); |
| + new ChromeViewMsg_SetOfflinePageInfo( |
| + render_frame_host->GetRoutingID(), offline_page_urls)); |
| } |
| void NetErrorTabHelper::ShowOfflinePages() { |
| + // Makes sure that this is coming from from an error page. |
| + if (!IsFromErrorPage()) |
| + return; |
| + |
| DCHECK(web_contents()); |
| TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| if (tab) |
| tab->ShowOfflinePages(); |
| } |
| -#endif |
| + |
| +void NetErrorTabHelper::LoadOfflineCopy(const GURL& url) { |
| + // Makes sure that this is coming from from an error page. |
| + if (!IsFromErrorPage()) |
| + return; |
| + |
| + GURL validated_url(url); |
| + if (!validated_url.is_valid()) |
| + return; |
| + DCHECK(web_contents()); |
| + if (validated_url != web_contents()->GetVisibleURL()) |
|
nasko
2015/11/19 15:11:41
Why use GetVisibleURL? This is inconsistent with t
mmenke
2015/11/19 17:39:12
I was concerned about allowing any page (Even one
nasko
2015/11/19 17:52:53
A page that has not committed should not be able t
jianli
2015/11/19 23:28:08
We do not allow any page to navigate to any offlin
|
| + return; |
| + |
| + TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| + if (tab) |
| + tab->LoadOfflineCopy(url); |
| +} |
| + |
| +bool NetErrorTabHelper::IsFromErrorPage() const { |
| + content::NavigationEntry* entry = |
| + web_contents()->GetController().GetLastCommittedEntry(); |
| + if (!entry) |
| + return false; |
| + return entry->GetPageType() == content::PAGE_TYPE_ERROR; |
| +} |
| +#endif // defined(OS_ANDROID) |
| } // namespace chrome_browser_net |