| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ios/web/web_state/web_state_impl.h" | 5 #include "ios/web/web_state/web_state_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "ios/web/interstitials/web_interstitial_impl.h" | 8 #include "ios/web/interstitials/web_interstitial_impl.h" |
| 9 #import "ios/web/navigation/crw_session_controller.h" | 9 #import "ios/web/navigation/crw_session_controller.h" |
| 10 #import "ios/web/navigation/crw_session_entry.h" | 10 #import "ios/web/navigation/crw_session_entry.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #import "ios/web/web_state/ui/crw_web_controller.h" | 21 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 22 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" | 22 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
| 23 #include "ios/web/web_state/web_state_facade_delegate.h" | 23 #include "ios/web/web_state/web_state_facade_delegate.h" |
| 24 #import "ios/web/webui/web_ui_ios_controller_factory_registry.h" | 24 #import "ios/web/webui/web_ui_ios_controller_factory_registry.h" |
| 25 #import "ios/web/webui/web_ui_ios_impl.h" | 25 #import "ios/web/webui/web_ui_ios_impl.h" |
| 26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 27 | 27 |
| 28 namespace web { | 28 namespace web { |
| 29 | 29 |
| 30 WebStateImpl::WebStateImpl(BrowserState* browser_state) | 30 WebStateImpl::WebStateImpl(BrowserState* browser_state) |
| 31 : WebStateImpl(browser_state, nullptr) {} |
| 32 |
| 33 WebStateImpl::WebStateImpl(BrowserState* browser_state, |
| 34 scoped_ptr<NavigationManagerImpl> navigation_manager) |
| 31 : is_loading_(false), | 35 : is_loading_(false), |
| 32 facade_delegate_(nullptr), | 36 facade_delegate_(nullptr), |
| 33 web_controller_(nil), | 37 web_controller_(nil), |
| 34 navigation_manager_(this, browser_state), | 38 navigation_manager_(navigation_manager.Pass()), |
| 35 interstitial_(nullptr), | 39 interstitial_(nullptr), |
| 36 cache_mode_(net::RequestTracker::CACHE_NORMAL) { | 40 cache_mode_(net::RequestTracker::CACHE_NORMAL) { |
| 41 if (!navigation_manager_) |
| 42 navigation_manager_.reset(new NavigationManagerImpl()); |
| 43 navigation_manager_->SetDelegate(this); |
| 44 navigation_manager_->SetBrowserState(browser_state); |
| 37 } | 45 } |
| 38 | 46 |
| 39 WebStateImpl::~WebStateImpl() { | 47 WebStateImpl::~WebStateImpl() { |
| 40 // WebUI depends on web state so it must be destroyed first in case any WebUI | 48 // WebUI depends on web state so it must be destroyed first in case any WebUI |
| 41 // implementations depends on accessing web state during destruction. | 49 // implementations depends on accessing web state during destruction. |
| 42 ClearWebUI(); | 50 ClearWebUI(); |
| 43 | 51 |
| 44 // The facade layer (owned by the delegate) should be destroyed before the web | 52 // The facade layer (owned by the delegate) should be destroyed before the web |
| 45 // layer. | 53 // layer. |
| 46 DCHECK(!facade_delegate_); | 54 DCHECK(!facade_delegate_); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 99 } |
| 92 | 100 |
| 93 WebStateFacadeDelegate* WebStateImpl::GetFacadeDelegate() const { | 101 WebStateFacadeDelegate* WebStateImpl::GetFacadeDelegate() const { |
| 94 return facade_delegate_; | 102 return facade_delegate_; |
| 95 } | 103 } |
| 96 | 104 |
| 97 void WebStateImpl::SetFacadeDelegate(WebStateFacadeDelegate* facade_delegate) { | 105 void WebStateImpl::SetFacadeDelegate(WebStateFacadeDelegate* facade_delegate) { |
| 98 facade_delegate_ = facade_delegate; | 106 facade_delegate_ = facade_delegate; |
| 99 } | 107 } |
| 100 | 108 |
| 101 WebStateImpl* WebStateImpl::CopyForSessionWindow() { | 109 scoped_ptr<WebStateImpl> WebStateImpl::CopyForSerialization() const { |
| 102 WebStateImpl* copy = new WebStateImpl(GetBrowserState()); | 110 return scoped_ptr<WebStateImpl>(new WebStateImpl( |
| 103 copy->GetNavigationManagerImpl().CopyState(&navigation_manager_); | 111 GetBrowserState(), navigation_manager_->CopyForSerialization())); |
| 104 return copy; | |
| 105 } | 112 } |
| 106 | 113 |
| 107 void WebStateImpl::OnUrlHashChanged() { | 114 void WebStateImpl::OnUrlHashChanged() { |
| 108 FOR_EACH_OBSERVER(WebStateObserver, observers_, UrlHashChanged()); | 115 FOR_EACH_OBSERVER(WebStateObserver, observers_, UrlHashChanged()); |
| 109 } | 116 } |
| 110 | 117 |
| 111 void WebStateImpl::OnHistoryStateChanged() { | 118 void WebStateImpl::OnHistoryStateChanged() { |
| 112 FOR_EACH_OBSERVER(WebStateObserver, observers_, HistoryStateChanged()); | 119 FOR_EACH_OBSERVER(WebStateObserver, observers_, HistoryStateChanged()); |
| 113 } | 120 } |
| 114 | 121 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 SignInFailed(request_id, source_url)); | 224 SignInFailed(request_id, source_url)); |
| 218 } | 225 } |
| 219 | 226 |
| 220 void WebStateImpl::OnDocumentSubmitted(const std::string& form_name, | 227 void WebStateImpl::OnDocumentSubmitted(const std::string& form_name, |
| 221 bool user_initiated) { | 228 bool user_initiated) { |
| 222 FOR_EACH_OBSERVER(WebStateObserver, observers_, | 229 FOR_EACH_OBSERVER(WebStateObserver, observers_, |
| 223 DocumentSubmitted(form_name, user_initiated)); | 230 DocumentSubmitted(form_name, user_initiated)); |
| 224 } | 231 } |
| 225 | 232 |
| 226 NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() { | 233 NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() { |
| 227 return navigation_manager_; | 234 return *navigation_manager_; |
| 228 } | 235 } |
| 229 | 236 |
| 230 const NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() const { | 237 const NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() const { |
| 231 return navigation_manager_; | 238 return *navigation_manager_; |
| 232 } | 239 } |
| 233 | 240 |
| 234 // There are currently two kinds of WebUI: those that have been adapted to | 241 // There are currently two kinds of WebUI: those that have been adapted to |
| 235 // web::WebUIIOS, and those that are still using content::WebUI. Try to create | 242 // web::WebUIIOS, and those that are still using content::WebUI. Try to create |
| 236 // it as the first, and then fall back to the latter if necessary. | 243 // it as the first, and then fall back to the latter if necessary. |
| 237 void WebStateImpl::CreateWebUI(const GURL& url) { | 244 void WebStateImpl::CreateWebUI(const GURL& url) { |
| 238 web_ui_.reset(CreateWebUIIOS(url)); | 245 web_ui_.reset(CreateWebUIIOS(url)); |
| 239 if (!web_ui_ && facade_delegate_) | 246 if (!web_ui_ && facade_delegate_) |
| 240 facade_delegate_->CreateLegacyWebUI(url); | 247 facade_delegate_->CreateLegacyWebUI(url); |
| 241 } | 248 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 264 void WebStateImpl::LoadWebUIHtml(const base::string16& html, const GURL& url) { | 271 void WebStateImpl::LoadWebUIHtml(const base::string16& html, const GURL& url) { |
| 265 CHECK(web::GetWebClient()->IsAppSpecificURL(url)); | 272 CHECK(web::GetWebClient()->IsAppSpecificURL(url)); |
| 266 [web_controller_ loadHTML:base::SysUTF16ToNSString(html) | 273 [web_controller_ loadHTML:base::SysUTF16ToNSString(html) |
| 267 forAppSpecificURL:url]; | 274 forAppSpecificURL:url]; |
| 268 } | 275 } |
| 269 | 276 |
| 270 const base::string16& WebStateImpl::GetTitle() const { | 277 const base::string16& WebStateImpl::GetTitle() const { |
| 271 // TODO(stuartmorgan): Implement the NavigationManager logic necessary to | 278 // TODO(stuartmorgan): Implement the NavigationManager logic necessary to |
| 272 // match the WebContents implementation of this method. | 279 // match the WebContents implementation of this method. |
| 273 DCHECK(Configured()); | 280 DCHECK(Configured()); |
| 274 web::NavigationItem* item = navigation_manager_.GetLastCommittedItem(); | 281 web::NavigationItem* item = navigation_manager_->GetLastCommittedItem(); |
| 275 if (item) { | 282 if (item) { |
| 276 return item->GetTitleForDisplay( | 283 return item->GetTitleForDisplay( |
| 277 web::GetWebClient()->GetAcceptLangs(GetBrowserState())); | 284 web::GetWebClient()->GetAcceptLangs(GetBrowserState())); |
| 278 } | 285 } |
| 279 return empty_string16_; | 286 return empty_string16_; |
| 280 } | 287 } |
| 281 | 288 |
| 282 void WebStateImpl::ShowTransientContentView(CRWContentView* content_view) { | 289 void WebStateImpl::ShowTransientContentView(CRWContentView* content_view) { |
| 283 DCHECK(Configured()); | 290 DCHECK(Configured()); |
| 284 DCHECK(content_view); | 291 DCHECK(content_view); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 void WebStateImpl::ShowWebInterstitial(WebInterstitialImpl* interstitial) { | 352 void WebStateImpl::ShowWebInterstitial(WebInterstitialImpl* interstitial) { |
| 346 DCHECK(Configured()); | 353 DCHECK(Configured()); |
| 347 DCHECK(interstitial); | 354 DCHECK(interstitial); |
| 348 interstitial_ = interstitial; | 355 interstitial_ = interstitial; |
| 349 ShowTransientContentView(interstitial_->GetContentView()); | 356 ShowTransientContentView(interstitial_->GetContentView()); |
| 350 } | 357 } |
| 351 | 358 |
| 352 void WebStateImpl::ClearTransientContentView() { | 359 void WebStateImpl::ClearTransientContentView() { |
| 353 if (interstitial_) { | 360 if (interstitial_) { |
| 354 CRWSessionController* sessionController = | 361 CRWSessionController* sessionController = |
| 355 navigation_manager_.GetSessionController(); | 362 navigation_manager_->GetSessionController(); |
| 356 web::NavigationItem* currentItem = | 363 web::NavigationItem* currentItem = |
| 357 [sessionController.currentEntry navigationItem]; | 364 [sessionController.currentEntry navigationItem]; |
| 358 if (currentItem->IsUnsafe()) { | 365 if (currentItem->IsUnsafe()) { |
| 359 // The unsafe page or page with bad SSL cert should be removed from the | 366 // The unsafe page or page with bad SSL cert should be removed from the |
| 360 // history, and, in fact, Safe Browsing and SSL interstitials will do | 367 // history, and, in fact, Safe Browsing and SSL interstitials will do |
| 361 // just that *provided* that it isn't the current page. | 368 // just that *provided* that it isn't the current page. |
| 362 // So to make this happen, before removing the interstitial, have the | 369 // So to make this happen, before removing the interstitial, have the |
| 363 // session controller go back one page. | 370 // session controller go back one page. |
| 364 [sessionController goBack]; | 371 [sessionController goBack]; |
| 365 } | 372 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (!policy_decider->ShouldAllowResponse(response)) | 424 if (!policy_decider->ShouldAllowResponse(response)) |
| 418 return false; | 425 return false; |
| 419 } | 426 } |
| 420 return true; | 427 return true; |
| 421 } | 428 } |
| 422 | 429 |
| 423 #pragma mark - RequestTracker management | 430 #pragma mark - RequestTracker management |
| 424 | 431 |
| 425 void WebStateImpl::InitializeRequestTracker( | 432 void WebStateImpl::InitializeRequestTracker( |
| 426 id<CRWRequestTrackerDelegate> delegate) { | 433 id<CRWRequestTrackerDelegate> delegate) { |
| 427 BrowserState* browser_state = navigation_manager_.GetBrowserState(); | 434 BrowserState* browser_state = navigation_manager_->GetBrowserState(); |
| 428 request_tracker_ = RequestTrackerImpl::CreateTrackerForRequestGroupID( | 435 request_tracker_ = RequestTrackerImpl::CreateTrackerForRequestGroupID( |
| 429 GetRequestGroupID(), browser_state, browser_state->GetRequestContext(), | 436 GetRequestGroupID(), browser_state, browser_state->GetRequestContext(), |
| 430 delegate); | 437 delegate); |
| 431 } | 438 } |
| 432 | 439 |
| 433 void WebStateImpl::CloseRequestTracker() { | 440 void WebStateImpl::CloseRequestTracker() { |
| 434 request_tracker_->Close(); | 441 request_tracker_->Close(); |
| 435 request_tracker_ = NULL; | 442 request_tracker_ = NULL; |
| 436 } | 443 } |
| 437 | 444 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 481 |
| 475 UIView* WebStateImpl::GetView() { | 482 UIView* WebStateImpl::GetView() { |
| 476 return [web_controller_ view]; | 483 return [web_controller_ view]; |
| 477 } | 484 } |
| 478 | 485 |
| 479 WebViewType WebStateImpl::GetWebViewType() const { | 486 WebViewType WebStateImpl::GetWebViewType() const { |
| 480 return [web_controller_ webViewType]; | 487 return [web_controller_ webViewType]; |
| 481 } | 488 } |
| 482 | 489 |
| 483 BrowserState* WebStateImpl::GetBrowserState() const { | 490 BrowserState* WebStateImpl::GetBrowserState() const { |
| 484 return navigation_manager_.GetBrowserState(); | 491 return navigation_manager_->GetBrowserState(); |
| 485 } | 492 } |
| 486 | 493 |
| 487 void WebStateImpl::OpenURL(const WebState::OpenURLParams& params) { | 494 void WebStateImpl::OpenURL(const WebState::OpenURLParams& params) { |
| 488 DCHECK(Configured()); | 495 DCHECK(Configured()); |
| 489 ClearTransientContentView(); | 496 ClearTransientContentView(); |
| 490 [[web_controller_ delegate] openURLWithParams:params]; | 497 [[web_controller_ delegate] openURLWithParams:params]; |
| 491 } | 498 } |
| 492 | 499 |
| 493 NavigationManager* WebStateImpl::GetNavigationManager() { | 500 NavigationManager* WebStateImpl::GetNavigationManager() { |
| 494 return &GetNavigationManagerImpl(); | 501 return &GetNavigationManagerImpl(); |
| 495 } | 502 } |
| 496 | 503 |
| 497 CRWJSInjectionReceiver* WebStateImpl::GetJSInjectionReceiver() const { | 504 CRWJSInjectionReceiver* WebStateImpl::GetJSInjectionReceiver() const { |
| 498 return [web_controller_ jsInjectionReceiver]; | 505 return [web_controller_ jsInjectionReceiver]; |
| 499 } | 506 } |
| 500 | 507 |
| 501 const std::string& WebStateImpl::GetContentLanguageHeader() const { | 508 const std::string& WebStateImpl::GetContentLanguageHeader() const { |
| 502 return content_language_header_; | 509 return content_language_header_; |
| 503 } | 510 } |
| 504 | 511 |
| 505 const std::string& WebStateImpl::GetContentsMimeType() const { | 512 const std::string& WebStateImpl::GetContentsMimeType() const { |
| 506 return mime_type_; | 513 return mime_type_; |
| 507 } | 514 } |
| 508 | 515 |
| 509 bool WebStateImpl::ContentIsHTML() const { | 516 bool WebStateImpl::ContentIsHTML() const { |
| 510 return [web_controller_ contentIsHTML]; | 517 return [web_controller_ contentIsHTML]; |
| 511 } | 518 } |
| 512 | 519 |
| 513 const GURL& WebStateImpl::GetVisibleURL() const { | 520 const GURL& WebStateImpl::GetVisibleURL() const { |
| 514 web::NavigationItem* item = navigation_manager_.GetVisibleItem(); | 521 web::NavigationItem* item = navigation_manager_->GetVisibleItem(); |
| 515 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 522 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 516 } | 523 } |
| 517 | 524 |
| 518 const GURL& WebStateImpl::GetLastCommittedURL() const { | 525 const GURL& WebStateImpl::GetLastCommittedURL() const { |
| 519 web::NavigationItem* item = navigation_manager_.GetLastCommittedItem(); | 526 web::NavigationItem* item = navigation_manager_->GetLastCommittedItem(); |
| 520 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 527 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 521 } | 528 } |
| 522 | 529 |
| 523 GURL WebStateImpl::GetCurrentURL(URLVerificationTrustLevel* trust_level) const { | 530 GURL WebStateImpl::GetCurrentURL(URLVerificationTrustLevel* trust_level) const { |
| 524 return [web_controller_ currentURLWithTrustLevel:trust_level]; | 531 return [web_controller_ currentURLWithTrustLevel:trust_level]; |
| 525 } | 532 } |
| 526 | 533 |
| 527 void WebStateImpl::AddScriptCommandCallback( | 534 void WebStateImpl::AddScriptCommandCallback( |
| 528 const ScriptCommandCallback& callback, | 535 const ScriptCommandCallback& callback, |
| 529 const std::string& command_prefix) { | 536 const std::string& command_prefix) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 const LoadCommittedDetails& load_details) { | 569 const LoadCommittedDetails& load_details) { |
| 563 FOR_EACH_OBSERVER(WebStateObserver, observers_, | 570 FOR_EACH_OBSERVER(WebStateObserver, observers_, |
| 564 NavigationItemCommitted(load_details)); | 571 NavigationItemCommitted(load_details)); |
| 565 } | 572 } |
| 566 | 573 |
| 567 WebState* WebStateImpl::GetWebState() { | 574 WebState* WebStateImpl::GetWebState() { |
| 568 return this; | 575 return this; |
| 569 } | 576 } |
| 570 | 577 |
| 571 } // namespace web | 578 } // namespace web |
| OLD | NEW |