| 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 "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" | 5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_login_delegate.h" | 7 #include "android_webview/browser/aw_login_delegate.h" |
| 8 #include "android_webview/browser/aw_contents_io_thread_client.h" | 8 #include "android_webview/browser/aw_contents_io_thread_client.h" |
| 9 #include "android_webview/common/url_constants.h" | 9 #include "android_webview/common/url_constants.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "content/components/navigation_interception/intercept_navigation_delega
te.h" | 12 #include "content/components/navigation_interception/intercept_navigation_delega
te.h" |
| 13 #include "content/public/browser/resource_controller.h" | 13 #include "content/public/browser/resource_controller.h" |
| 14 #include "content/public/browser/resource_dispatcher_host.h" | 14 #include "content/public/browser/resource_dispatcher_host.h" |
| 15 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 15 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
| 16 #include "content/public/browser/resource_throttle.h" | 16 #include "content/public/browser/resource_throttle.h" |
| 17 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 18 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 19 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
| 20 | 20 |
| 21 using content::InterceptNavigationDelegate; | 21 using content::InterceptNavigationDelegate; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 using android_webview::AwContentsIoThreadClient; | 25 using android_webview::AwContentsIoThreadClient; |
| 26 | 26 |
| 27 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> | 27 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> |
| 28 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; | 28 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; |
| 29 | 29 |
| 30 void SetOnlyAllowLoadFromCache( | 30 void SetCacheControlFlag( |
| 31 net::URLRequest* request) { | 31 net::URLRequest* request, int flag) { |
| 32 const int all_cache_control_flags = net::LOAD_BYPASS_CACHE | |
| 33 net::LOAD_VALIDATE_CACHE | |
| 34 net::LOAD_PREFERRING_CACHE | |
| 35 net::LOAD_ONLY_FROM_CACHE; |
| 36 DCHECK((flag & all_cache_control_flags) == flag); |
| 32 int load_flags = request->load_flags(); | 37 int load_flags = request->load_flags(); |
| 33 load_flags &= ~(net::LOAD_BYPASS_CACHE & | 38 load_flags &= ~all_cache_control_flags; |
| 34 net::LOAD_VALIDATE_CACHE & | 39 load_flags |= flag; |
| 35 net::LOAD_PREFERRING_CACHE); | |
| 36 load_flags |= net::LOAD_ONLY_FROM_CACHE; | |
| 37 request->set_load_flags(load_flags); | 40 request->set_load_flags(load_flags); |
| 38 } | 41 } |
| 39 | 42 |
| 40 // May cancel this resource request based on result of Java callbacks. | 43 // Calls through the IoThreadClient to check the embedders settings to determine |
| 41 class MaybeCancelResourceThrottle : public content::ResourceThrottle { | 44 // if the request should be cancelled. |
| 45 class IoThreadClientThrottle : public content::ResourceThrottle { |
| 42 public: | 46 public: |
| 43 MaybeCancelResourceThrottle(int child_id, | 47 IoThreadClientThrottle(int child_id, |
| 44 int route_id, | 48 int route_id, |
| 45 net::URLRequest* request) | 49 net::URLRequest* request) |
| 46 : child_id_(child_id), | 50 : child_id_(child_id), |
| 47 route_id_(route_id), | 51 route_id_(route_id), |
| 48 request_(request) { } | 52 request_(request) { } |
| 49 virtual void WillStartRequest(bool* defer) OVERRIDE; | 53 virtual void WillStartRequest(bool* defer) OVERRIDE; |
| 50 | 54 |
| 51 scoped_ptr<AwContentsIoThreadClient> GetIoThreadClient() { | 55 scoped_ptr<AwContentsIoThreadClient> GetIoThreadClient() { |
| 52 return AwContentsIoThreadClient::FromID(child_id_, route_id_); | 56 return AwContentsIoThreadClient::FromID(child_id_, route_id_); |
| 53 } | 57 } |
| 54 | 58 |
| 55 private: | 59 private: |
| 56 int child_id_; | 60 int child_id_; |
| 57 int route_id_; | 61 int route_id_; |
| 58 net::URLRequest* request_; | 62 net::URLRequest* request_; |
| 59 }; | 63 }; |
| 60 | 64 |
| 61 void MaybeCancelResourceThrottle::WillStartRequest(bool* defer) { | 65 void IoThreadClientThrottle::WillStartRequest(bool* defer) { |
| 62 // If there is no IO thread client set at this point, use a | 66 // If there is no IO thread client set at this point, use a |
| 63 // restrictive policy. This can happen for blocked popup | 67 // restrictive policy. This can happen for blocked popup |
| 64 // windows for example. | 68 // windows for example. |
| 65 // TODO(benm): Revert this to a DCHECK when the we support | 69 // TODO(benm): Revert this to a DCHECK when the we support |
| 66 // pop up windows being created in the WebView, as at that | 70 // pop up windows being created in the WebView, as at that |
| 67 // time we should always have an IoThreadClient at this | 71 // time we should always have an IoThreadClient at this |
| 68 // point (i.e., the one associated with the new popup). | 72 // point (i.e., the one associated with the new popup). |
| 69 if (!GetIoThreadClient()) { | 73 if (!GetIoThreadClient()) { |
| 70 controller()->CancelWithError(net::ERR_ACCESS_DENIED); | 74 controller()->CancelWithError(net::ERR_ACCESS_DENIED); |
| 71 return; | 75 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 89 controller()->CancelWithError(net::ERR_ACCESS_DENIED); | 93 controller()->CancelWithError(net::ERR_ACCESS_DENIED); |
| 90 return; | 94 return; |
| 91 } | 95 } |
| 92 } | 96 } |
| 93 | 97 |
| 94 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) { | 98 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) { |
| 95 if (request_->url().SchemeIs(chrome::kFtpScheme)) { | 99 if (request_->url().SchemeIs(chrome::kFtpScheme)) { |
| 96 controller()->CancelWithError(net::ERR_ACCESS_DENIED); | 100 controller()->CancelWithError(net::ERR_ACCESS_DENIED); |
| 97 return; | 101 return; |
| 98 } | 102 } |
| 99 SetOnlyAllowLoadFromCache(request_); | 103 SetCacheControlFlag(request_, net::LOAD_ONLY_FROM_CACHE); |
| 104 } else { |
| 105 AwContentsIoThreadClient::CacheMode cache_mode = |
| 106 GetIoThreadClient()->GetCacheMode(); |
| 107 switch(cache_mode) { |
| 108 case AwContentsIoThreadClient::LOAD_CACHE_ELSE_NETWORK: |
| 109 SetCacheControlFlag(request_, net::LOAD_PREFERRING_CACHE); |
| 110 break; |
| 111 case AwContentsIoThreadClient::LOAD_NO_CACHE: |
| 112 SetCacheControlFlag(request_, net::LOAD_BYPASS_CACHE); |
| 113 break; |
| 114 case AwContentsIoThreadClient::LOAD_CACHE_ONLY: |
| 115 SetCacheControlFlag(request_, net::LOAD_ONLY_FROM_CACHE); |
| 116 break; |
| 117 default: |
| 118 break; |
| 119 } |
| 100 } | 120 } |
| 101 } | 121 } |
| 102 | 122 |
| 103 } // namespace | 123 } // namespace |
| 104 | 124 |
| 105 namespace android_webview { | 125 namespace android_webview { |
| 106 | 126 |
| 107 // static | 127 // static |
| 108 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() { | 128 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() { |
| 109 content::ResourceDispatcherHost::Get()->SetDelegate( | 129 content::ResourceDispatcherHost::Get()->SetDelegate( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 120 void AwResourceDispatcherHostDelegate::RequestBeginning( | 140 void AwResourceDispatcherHostDelegate::RequestBeginning( |
| 121 net::URLRequest* request, | 141 net::URLRequest* request, |
| 122 content::ResourceContext* resource_context, | 142 content::ResourceContext* resource_context, |
| 123 appcache::AppCacheService* appcache_service, | 143 appcache::AppCacheService* appcache_service, |
| 124 ResourceType::Type resource_type, | 144 ResourceType::Type resource_type, |
| 125 int child_id, | 145 int child_id, |
| 126 int route_id, | 146 int route_id, |
| 127 bool is_continuation_of_transferred_request, | 147 bool is_continuation_of_transferred_request, |
| 128 ScopedVector<content::ResourceThrottle>* throttles) { | 148 ScopedVector<content::ResourceThrottle>* throttles) { |
| 129 | 149 |
| 130 throttles->push_back(new MaybeCancelResourceThrottle( | 150 throttles->push_back(new IoThreadClientThrottle( |
| 131 child_id, route_id, request)); | 151 child_id, route_id, request)); |
| 132 | 152 |
| 133 bool allow_intercepting = | 153 bool allow_intercepting = |
| 134 // We ignore POST requests because of BUG=155250. | 154 // We ignore POST requests because of BUG=155250. |
| 135 request->method() != "POST" && | 155 request->method() != "POST" && |
| 136 // We allow intercepting navigations within subframes, but only if the | 156 // We allow intercepting navigations within subframes, but only if the |
| 137 // scheme other than http or https. This is because the embedder | 157 // scheme other than http or https. This is because the embedder |
| 138 // can't distinguish main frame and subframe callbacks (which could lead | 158 // can't distinguish main frame and subframe callbacks (which could lead |
| 139 // to broken content if the embedder decides to not ignore the main frame | 159 // to broken content if the embedder decides to not ignore the main frame |
| 140 // navigation, but ignores the subframe navigation). | 160 // navigation, but ignores the subframe navigation). |
| (...skipping 26 matching lines...) Expand all Loading... |
| 167 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url, | 187 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url, |
| 168 int child_id, | 188 int child_id, |
| 169 int route_id) { | 189 int route_id) { |
| 170 // The AwURLRequestJobFactory implementation should ensure this method never | 190 // The AwURLRequestJobFactory implementation should ensure this method never |
| 171 // gets called. | 191 // gets called. |
| 172 NOTREACHED(); | 192 NOTREACHED(); |
| 173 return false; | 193 return false; |
| 174 } | 194 } |
| 175 | 195 |
| 176 } | 196 } |
| OLD | NEW |