| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/renderer_host/offline_resource_throttle.h" | 5 #include "chrome/browser/renderer_host/offline_resource_throttle.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "chrome/browser/chromeos/offline/offline_load_page.h" | 14 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
| 15 #include "chrome/browser/net/chrome_url_request_context.h" | 15 #include "chrome/browser/net/chrome_url_request_context.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/browser/resource_request_info.h" | 20 #include "content/public/browser/resource_request_info.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 24 #include "net/base/network_change_notifier.h" | 24 #include "net/base/network_change_notifier.h" |
| 25 #include "net/base/url_constants.h" |
| 25 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
| 26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 27 #include "webkit/browser/appcache/appcache_service.h" | 28 #include "webkit/browser/appcache/appcache_service.h" |
| 28 | 29 |
| 29 using content::BrowserThread; | 30 using content::BrowserThread; |
| 30 using content::RenderViewHost; | 31 using content::RenderViewHost; |
| 31 using content::WebContents; | 32 using content::WebContents; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 112 | 113 |
| 113 if (proceed) { | 114 if (proceed) { |
| 114 controller()->Resume(); | 115 controller()->Resume(); |
| 115 } else { | 116 } else { |
| 116 controller()->Cancel(); | 117 controller()->Cancel(); |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 bool OfflineResourceThrottle::IsRemote(const GURL& url) const { | 121 bool OfflineResourceThrottle::IsRemote(const GURL& url) const { |
| 121 return !net::IsLocalhost(url.host()) && (url.SchemeIs(content::kFtpScheme) || | 122 return !net::IsLocalhost(url.host()) && |
| 122 url.SchemeIs(content::kHttpScheme) || | 123 (url.SchemeIs(content::kFtpScheme) || url.SchemeIs(net::kHttpScheme) || |
| 123 url.SchemeIs(content::kHttpsScheme)); | 124 url.SchemeIs(net::kHttpsScheme)); |
| 124 } | 125 } |
| 125 | 126 |
| 126 bool OfflineResourceThrottle::ShouldShowOfflinePage(const GURL& url) const { | 127 bool OfflineResourceThrottle::ShouldShowOfflinePage(const GURL& url) const { |
| 127 // If the network is disconnected while loading other resources, we'll simply | 128 // If the network is disconnected while loading other resources, we'll simply |
| 128 // show broken link/images. | 129 // show broken link/images. |
| 129 return IsRemote(url) && net::NetworkChangeNotifier::IsOffline(); | 130 return IsRemote(url) && net::NetworkChangeNotifier::IsOffline(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void OfflineResourceThrottle::OnCanHandleOfflineComplete(int rv) { | 133 void OfflineResourceThrottle::OnCanHandleOfflineComplete(int rv) { |
| 133 appcache_completion_callback_.Cancel(); | 134 appcache_completion_callback_.Cancel(); |
| 134 | 135 |
| 135 if (rv == net::OK) { | 136 if (rv == net::OK) { |
| 136 controller()->Resume(); | 137 controller()->Resume(); |
| 137 } else { | 138 } else { |
| 138 const content::ResourceRequestInfo* info = | 139 const content::ResourceRequestInfo* info = |
| 139 content::ResourceRequestInfo::ForRequest(request_); | 140 content::ResourceRequestInfo::ForRequest(request_); |
| 140 BrowserThread::PostTask( | 141 BrowserThread::PostTask( |
| 141 BrowserThread::UI, | 142 BrowserThread::UI, |
| 142 FROM_HERE, | 143 FROM_HERE, |
| 143 base::Bind( | 144 base::Bind( |
| 144 &ShowOfflinePage, | 145 &ShowOfflinePage, |
| 145 info->GetChildID(), | 146 info->GetChildID(), |
| 146 info->GetRouteID(), | 147 info->GetRouteID(), |
| 147 request_->url(), | 148 request_->url(), |
| 148 base::Bind( | 149 base::Bind( |
| 149 &OfflineResourceThrottle::OnBlockingPageComplete, | 150 &OfflineResourceThrottle::OnBlockingPageComplete, |
| 150 AsWeakPtr()))); | 151 AsWeakPtr()))); |
| 151 } | 152 } |
| 152 } | 153 } |
| OLD | NEW |