| 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 #import "ios/web/web_state/web_state_impl.h" | 5 #import "ios/web/web_state/web_state_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #import "ios/web/interstitials/web_interstitial_impl.h" | 14 #import "ios/web/interstitials/web_interstitial_impl.h" |
| 15 #import "ios/web/navigation/crw_session_controller.h" | 15 #import "ios/web/navigation/crw_session_controller.h" |
| 16 #import "ios/web/navigation/crw_session_entry.h" | 16 #import "ios/web/navigation/crw_session_entry.h" |
| 17 #import "ios/web/navigation/navigation_item_impl.h" | 17 #import "ios/web/navigation/navigation_item_impl.h" |
| 18 #import "ios/web/navigation/navigation_manager_storage_builder.h" |
| 18 #include "ios/web/public/browser_state.h" | 19 #include "ios/web/public/browser_state.h" |
| 20 #import "ios/web/public/crw_navigation_manager_storage.h" |
| 19 #import "ios/web/public/image_fetcher/image_data_fetcher.h" | 21 #import "ios/web/public/image_fetcher/image_data_fetcher.h" |
| 20 #import "ios/web/public/java_script_dialog_presenter.h" | 22 #import "ios/web/public/java_script_dialog_presenter.h" |
| 21 #import "ios/web/public/navigation_item.h" | 23 #import "ios/web/public/navigation_item.h" |
| 22 #include "ios/web/public/url_util.h" | 24 #include "ios/web/public/url_util.h" |
| 23 #import "ios/web/public/web_client.h" | 25 #import "ios/web/public/web_client.h" |
| 24 #import "ios/web/public/web_state/context_menu_params.h" | 26 #import "ios/web/public/web_state/context_menu_params.h" |
| 25 #include "ios/web/public/web_state/credential.h" | 27 #include "ios/web/public/web_state/credential.h" |
| 26 #import "ios/web/public/web_state/ui/crw_content_view.h" | 28 #import "ios/web/public/web_state/ui/crw_content_view.h" |
| 27 #import "ios/web/public/web_state/web_state_delegate.h" | 29 #import "ios/web/public/web_state/web_state_delegate.h" |
| 28 #include "ios/web/public/web_state/web_state_observer.h" | 30 #include "ios/web/public/web_state/web_state_observer.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 42 #include "skia/ext/skia_utils_ios.h" | 44 #include "skia/ext/skia_utils_ios.h" |
| 43 #include "third_party/skia/include/core/SkBitmap.h" | 45 #include "third_party/skia/include/core/SkBitmap.h" |
| 44 | 46 |
| 45 namespace web { | 47 namespace web { |
| 46 | 48 |
| 47 /* static */ | 49 /* static */ |
| 48 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { | 50 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { |
| 49 std::unique_ptr<WebStateImpl> web_state( | 51 std::unique_ptr<WebStateImpl> web_state( |
| 50 new WebStateImpl(params.browser_state)); | 52 new WebStateImpl(params.browser_state)); |
| 51 | 53 |
| 54 // Initialized the new session. |
| 52 NSString* window_name = nil; | 55 NSString* window_name = nil; |
| 53 NSString* opener_id = nil; | 56 NSString* opener_id = nil; |
| 54 BOOL opened_by_dom = NO; | 57 BOOL opened_by_dom = NO; |
| 55 int opener_navigation_index = 0; | 58 int opener_navigation_index = 0; |
| 56 web_state->GetNavigationManagerImpl().InitializeSession( | 59 web_state->GetNavigationManagerImpl().InitializeSession( |
| 57 window_name, opener_id, opened_by_dom, opener_navigation_index); | 60 window_name, opener_id, opened_by_dom, opener_navigation_index); |
| 58 | 61 |
| 59 // This std::move is required to compile with the version of clang shipping | 62 // This std::move is required to compile with the version of clang shipping |
| 60 // with Xcode 8.0+. Evalute whether the issue is fixed once a new version of | 63 // with Xcode 8.0+. Evalute whether the issue is fixed once a new version of |
| 61 // Xcode is released. | 64 // Xcode is released. |
| 62 return std::move(web_state); | 65 return std::move(web_state); |
| 63 } | 66 } |
| 64 | 67 |
| 68 /* static */ |
| 69 std::unique_ptr<WebState> WebState::Create( |
| 70 const CreateParams& params, |
| 71 CRWNavigationManagerStorage* session_storage) { |
| 72 std::unique_ptr<WebStateImpl> web_state( |
| 73 new WebStateImpl(params.browser_state, session_storage)); |
| 74 |
| 75 // This std::move is required to compile with the version of clang shipping |
| 76 // with Xcode 8.0+. Evalute whether the issue is fixed once a new version of |
| 77 // Xcode is released. |
| 78 return std::move(web_state); |
| 79 } |
| 80 |
| 65 WebStateImpl::WebStateImpl(BrowserState* browser_state) | 81 WebStateImpl::WebStateImpl(BrowserState* browser_state) |
| 82 : WebStateImpl(browser_state, nullptr) {} |
| 83 |
| 84 WebStateImpl::WebStateImpl(BrowserState* browser_state, |
| 85 CRWNavigationManagerStorage* session_storage) |
| 66 : delegate_(nullptr), | 86 : delegate_(nullptr), |
| 67 is_loading_(false), | 87 is_loading_(false), |
| 68 is_being_destroyed_(false), | 88 is_being_destroyed_(false), |
| 69 facade_delegate_(nullptr), | 89 facade_delegate_(nullptr), |
| 70 web_controller_(nil), | 90 web_controller_(nil), |
| 71 navigation_manager_(this, browser_state), | |
| 72 interstitial_(nullptr), | 91 interstitial_(nullptr), |
| 73 weak_factory_(this) { | 92 weak_factory_(this) { |
| 93 // Create or deserialize the NavigationManager. |
| 94 if (session_storage) { |
| 95 NavigationManagerStorageBuilder session_storage_builder; |
| 96 navigation_manager_ = |
| 97 session_storage_builder.BuildNavigationManagerImpl(session_storage); |
| 98 } else { |
| 99 navigation_manager_.reset(new NavigationManagerImpl()); |
| 100 } |
| 101 navigation_manager_->SetDelegate(this); |
| 102 navigation_manager_->SetBrowserState(browser_state); |
| 103 // Send creation event and create the web controller. |
| 74 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); | 104 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); |
| 75 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); | 105 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); |
| 106 // Set up the image fetcher. |
| 76 image_fetcher_ = | 107 image_fetcher_ = |
| 77 base::MakeUnique<ImageDataFetcher>(web::WebThread::GetBlockingPool()); | 108 base::MakeUnique<ImageDataFetcher>(web::WebThread::GetBlockingPool()); |
| 78 image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext()); | 109 image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext()); |
| 79 } | 110 } |
| 80 | 111 |
| 81 WebStateImpl::~WebStateImpl() { | 112 WebStateImpl::~WebStateImpl() { |
| 82 [web_controller_ close]; | 113 [web_controller_ close]; |
| 83 is_being_destroyed_ = true; | 114 is_being_destroyed_ = true; |
| 84 | 115 |
| 85 // WebUI depends on web state so it must be destroyed first in case any WebUI | 116 // WebUI depends on web state so it must be destroyed first in case any WebUI |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 188 } |
| 158 | 189 |
| 159 WebStateFacadeDelegate* WebStateImpl::GetFacadeDelegate() const { | 190 WebStateFacadeDelegate* WebStateImpl::GetFacadeDelegate() const { |
| 160 return facade_delegate_; | 191 return facade_delegate_; |
| 161 } | 192 } |
| 162 | 193 |
| 163 void WebStateImpl::SetFacadeDelegate(WebStateFacadeDelegate* facade_delegate) { | 194 void WebStateImpl::SetFacadeDelegate(WebStateFacadeDelegate* facade_delegate) { |
| 164 facade_delegate_ = facade_delegate; | 195 facade_delegate_ = facade_delegate; |
| 165 } | 196 } |
| 166 | 197 |
| 167 WebStateImpl* WebStateImpl::CopyForSessionWindow() { | |
| 168 WebStateImpl* copy = new WebStateImpl(GetBrowserState()); | |
| 169 copy->GetNavigationManagerImpl().CopyState(&navigation_manager_); | |
| 170 return copy; | |
| 171 } | |
| 172 | |
| 173 void WebStateImpl::OnNavigationCommitted(const GURL& url) { | 198 void WebStateImpl::OnNavigationCommitted(const GURL& url) { |
| 174 UpdateHttpResponseHeaders(url); | 199 UpdateHttpResponseHeaders(url); |
| 175 } | 200 } |
| 176 | 201 |
| 177 void WebStateImpl::OnUrlHashChanged() { | 202 void WebStateImpl::OnUrlHashChanged() { |
| 178 for (auto& observer : observers_) | 203 for (auto& observer : observers_) |
| 179 observer.UrlHashChanged(); | 204 observer.UrlHashChanged(); |
| 180 } | 205 } |
| 181 | 206 |
| 182 void WebStateImpl::OnHistoryStateChanged() { | 207 void WebStateImpl::OnHistoryStateChanged() { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 observer.SignInFailed(request_id, source_url); | 328 observer.SignInFailed(request_id, source_url); |
| 304 } | 329 } |
| 305 | 330 |
| 306 void WebStateImpl::OnDocumentSubmitted(const std::string& form_name, | 331 void WebStateImpl::OnDocumentSubmitted(const std::string& form_name, |
| 307 bool user_initiated) { | 332 bool user_initiated) { |
| 308 for (auto& observer : observers_) | 333 for (auto& observer : observers_) |
| 309 observer.DocumentSubmitted(form_name, user_initiated); | 334 observer.DocumentSubmitted(form_name, user_initiated); |
| 310 } | 335 } |
| 311 | 336 |
| 312 NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() { | 337 NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() { |
| 313 return navigation_manager_; | 338 return *navigation_manager_; |
| 314 } | 339 } |
| 315 | 340 |
| 316 const NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() const { | 341 const NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() const { |
| 317 return navigation_manager_; | 342 return *navigation_manager_; |
| 318 } | 343 } |
| 319 | 344 |
| 320 void WebStateImpl::CreateWebUI(const GURL& url) { | 345 void WebStateImpl::CreateWebUI(const GURL& url) { |
| 321 web_ui_ = CreateWebUIIOS(url); | 346 web_ui_ = CreateWebUIIOS(url); |
| 322 } | 347 } |
| 323 | 348 |
| 324 void WebStateImpl::ClearWebUI() { | 349 void WebStateImpl::ClearWebUI() { |
| 325 web_ui_.reset(); | 350 web_ui_.reset(); |
| 326 } | 351 } |
| 327 | 352 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 339 void WebStateImpl::LoadWebUIHtml(const base::string16& html, const GURL& url) { | 364 void WebStateImpl::LoadWebUIHtml(const base::string16& html, const GURL& url) { |
| 340 CHECK(web::GetWebClient()->IsAppSpecificURL(url)); | 365 CHECK(web::GetWebClient()->IsAppSpecificURL(url)); |
| 341 [web_controller_ loadHTML:base::SysUTF16ToNSString(html) | 366 [web_controller_ loadHTML:base::SysUTF16ToNSString(html) |
| 342 forAppSpecificURL:url]; | 367 forAppSpecificURL:url]; |
| 343 } | 368 } |
| 344 | 369 |
| 345 const base::string16& WebStateImpl::GetTitle() const { | 370 const base::string16& WebStateImpl::GetTitle() const { |
| 346 // TODO(stuartmorgan): Implement the NavigationManager logic necessary to | 371 // TODO(stuartmorgan): Implement the NavigationManager logic necessary to |
| 347 // match the WebContents implementation of this method. | 372 // match the WebContents implementation of this method. |
| 348 DCHECK(Configured()); | 373 DCHECK(Configured()); |
| 349 web::NavigationItem* item = navigation_manager_.GetLastCommittedItem(); | 374 web::NavigationItem* item = navigation_manager_->GetLastCommittedItem(); |
| 350 return item ? item->GetTitleForDisplay() : empty_string16_; | 375 return item ? item->GetTitleForDisplay() : empty_string16_; |
| 351 } | 376 } |
| 352 | 377 |
| 353 void WebStateImpl::ShowTransientContentView(CRWContentView* content_view) { | 378 void WebStateImpl::ShowTransientContentView(CRWContentView* content_view) { |
| 354 DCHECK(Configured()); | 379 DCHECK(Configured()); |
| 355 DCHECK(content_view); | 380 DCHECK(content_view); |
| 356 DCHECK(content_view.scrollView); | 381 DCHECK(content_view.scrollView); |
| 357 [web_controller_ showTransientContentView:content_view]; | 382 [web_controller_ showTransientContentView:content_view]; |
| 358 } | 383 } |
| 359 | 384 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 624 |
| 600 void WebStateImpl::SetShouldSuppressDialogs(bool should_suppress) { | 625 void WebStateImpl::SetShouldSuppressDialogs(bool should_suppress) { |
| 601 [web_controller_ setShouldSuppressDialogs:should_suppress]; | 626 [web_controller_ setShouldSuppressDialogs:should_suppress]; |
| 602 } | 627 } |
| 603 | 628 |
| 604 UIView* WebStateImpl::GetView() { | 629 UIView* WebStateImpl::GetView() { |
| 605 return [web_controller_ view]; | 630 return [web_controller_ view]; |
| 606 } | 631 } |
| 607 | 632 |
| 608 BrowserState* WebStateImpl::GetBrowserState() const { | 633 BrowserState* WebStateImpl::GetBrowserState() const { |
| 609 return navigation_manager_.GetBrowserState(); | 634 return navigation_manager_->GetBrowserState(); |
| 610 } | 635 } |
| 611 | 636 |
| 612 void WebStateImpl::OpenURL(const WebState::OpenURLParams& params) { | 637 void WebStateImpl::OpenURL(const WebState::OpenURLParams& params) { |
| 613 DCHECK(Configured()); | 638 DCHECK(Configured()); |
| 614 ClearTransientContentView(); | 639 ClearTransientContentView(); |
| 615 if (delegate_) | 640 if (delegate_) |
| 616 delegate_->OpenURLFromWebState(this, params); | 641 delegate_->OpenURLFromWebState(this, params); |
| 617 } | 642 } |
| 618 | 643 |
| 619 void WebStateImpl::Stop() { | 644 void WebStateImpl::Stop() { |
| 620 [web_controller_ stopLoading]; | 645 [web_controller_ stopLoading]; |
| 621 } | 646 } |
| 622 | 647 |
| 623 const NavigationManager* WebStateImpl::GetNavigationManager() const { | 648 const NavigationManager* WebStateImpl::GetNavigationManager() const { |
| 624 return &GetNavigationManagerImpl(); | 649 return &GetNavigationManagerImpl(); |
| 625 } | 650 } |
| 626 | 651 |
| 627 NavigationManager* WebStateImpl::GetNavigationManager() { | 652 NavigationManager* WebStateImpl::GetNavigationManager() { |
| 628 return &GetNavigationManagerImpl(); | 653 return &GetNavigationManagerImpl(); |
| 629 } | 654 } |
| 630 | 655 |
| 656 CRWNavigationManagerStorage* WebStateImpl::BuildSerializedNavigationManager() { |
| 657 NavigationManagerStorageBuilder session_storage_builder; |
| 658 return session_storage_builder.BuildSerialization(navigation_manager_.get()); |
| 659 } |
| 660 |
| 631 CRWJSInjectionReceiver* WebStateImpl::GetJSInjectionReceiver() const { | 661 CRWJSInjectionReceiver* WebStateImpl::GetJSInjectionReceiver() const { |
| 632 return [web_controller_ jsInjectionReceiver]; | 662 return [web_controller_ jsInjectionReceiver]; |
| 633 } | 663 } |
| 634 | 664 |
| 635 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript) { | 665 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript) { |
| 636 [web_controller_ executeJavaScript:base::SysUTF16ToNSString(javascript) | 666 [web_controller_ executeJavaScript:base::SysUTF16ToNSString(javascript) |
| 637 completionHandler:nil]; | 667 completionHandler:nil]; |
| 638 } | 668 } |
| 639 | 669 |
| 640 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript, | 670 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 658 | 688 |
| 659 const std::string& WebStateImpl::GetContentsMimeType() const { | 689 const std::string& WebStateImpl::GetContentsMimeType() const { |
| 660 return mime_type_; | 690 return mime_type_; |
| 661 } | 691 } |
| 662 | 692 |
| 663 bool WebStateImpl::ContentIsHTML() const { | 693 bool WebStateImpl::ContentIsHTML() const { |
| 664 return [web_controller_ contentIsHTML]; | 694 return [web_controller_ contentIsHTML]; |
| 665 } | 695 } |
| 666 | 696 |
| 667 const GURL& WebStateImpl::GetVisibleURL() const { | 697 const GURL& WebStateImpl::GetVisibleURL() const { |
| 668 web::NavigationItem* item = navigation_manager_.GetVisibleItem(); | 698 web::NavigationItem* item = navigation_manager_->GetVisibleItem(); |
| 669 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 699 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 670 } | 700 } |
| 671 | 701 |
| 672 const GURL& WebStateImpl::GetLastCommittedURL() const { | 702 const GURL& WebStateImpl::GetLastCommittedURL() const { |
| 673 web::NavigationItem* item = navigation_manager_.GetLastCommittedItem(); | 703 web::NavigationItem* item = navigation_manager_->GetLastCommittedItem(); |
| 674 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 704 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 675 } | 705 } |
| 676 | 706 |
| 677 GURL WebStateImpl::GetCurrentURL(URLVerificationTrustLevel* trust_level) const { | 707 GURL WebStateImpl::GetCurrentURL(URLVerificationTrustLevel* trust_level) const { |
| 678 GURL URL = [web_controller_ currentURLWithTrustLevel:trust_level]; | 708 GURL URL = [web_controller_ currentURLWithTrustLevel:trust_level]; |
| 679 bool equalURLs = web::GURLByRemovingRefFromGURL(URL) == | 709 bool equalURLs = web::GURLByRemovingRefFromGURL(URL) == |
| 680 web::GURLByRemovingRefFromGURL(GetLastCommittedURL()); | 710 web::GURLByRemovingRefFromGURL(GetLastCommittedURL()); |
| 681 DCHECK(equalURLs); | 711 DCHECK(equalURLs); |
| 682 UMA_HISTOGRAM_BOOLEAN("Web.CurrentURLEqualsLastCommittedURL", equalURLs); | 712 UMA_HISTOGRAM_BOOLEAN("Web.CurrentURLEqualsLastCommittedURL", equalURLs); |
| 683 return URL; | 713 return URL; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 const LoadCommittedDetails& load_details) { | 764 const LoadCommittedDetails& load_details) { |
| 735 for (auto& observer : observers_) | 765 for (auto& observer : observers_) |
| 736 observer.NavigationItemCommitted(load_details); | 766 observer.NavigationItemCommitted(load_details); |
| 737 } | 767 } |
| 738 | 768 |
| 739 WebState* WebStateImpl::GetWebState() { | 769 WebState* WebStateImpl::GetWebState() { |
| 740 return this; | 770 return this; |
| 741 } | 771 } |
| 742 | 772 |
| 743 } // namespace web | 773 } // namespace web |
| OLD | NEW |