| 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 #include "ios/web/public/browser_state.h" | 18 #include "ios/web/public/browser_state.h" |
| 19 #import "ios/web/public/crw_navigation_manager_serialization.h" |
| 19 #import "ios/web/public/image_fetcher/image_data_fetcher.h" | 20 #import "ios/web/public/image_fetcher/image_data_fetcher.h" |
| 20 #import "ios/web/public/java_script_dialog_presenter.h" | 21 #import "ios/web/public/java_script_dialog_presenter.h" |
| 21 #import "ios/web/public/navigation_item.h" | 22 #import "ios/web/public/navigation_item.h" |
| 22 #include "ios/web/public/url_util.h" | 23 #include "ios/web/public/url_util.h" |
| 23 #import "ios/web/public/web_client.h" | 24 #import "ios/web/public/web_client.h" |
| 24 #import "ios/web/public/web_state/context_menu_params.h" | 25 #import "ios/web/public/web_state/context_menu_params.h" |
| 25 #include "ios/web/public/web_state/credential.h" | 26 #include "ios/web/public/web_state/credential.h" |
| 26 #import "ios/web/public/web_state/ui/crw_content_view.h" | 27 #import "ios/web/public/web_state/ui/crw_content_view.h" |
| 27 #import "ios/web/public/web_state/web_state_delegate.h" | 28 #import "ios/web/public/web_state/web_state_delegate.h" |
| 28 #include "ios/web/public/web_state/web_state_observer.h" | 29 #include "ios/web/public/web_state/web_state_observer.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 40 #include "net/url_request/url_request_context_getter.h" | 41 #include "net/url_request/url_request_context_getter.h" |
| 41 #include "services/service_manager/public/cpp/interface_registry.h" | 42 #include "services/service_manager/public/cpp/interface_registry.h" |
| 42 #include "skia/ext/skia_utils_ios.h" | 43 #include "skia/ext/skia_utils_ios.h" |
| 43 #include "third_party/skia/include/core/SkBitmap.h" | 44 #include "third_party/skia/include/core/SkBitmap.h" |
| 44 | 45 |
| 45 namespace web { | 46 namespace web { |
| 46 | 47 |
| 47 /* static */ | 48 /* static */ |
| 48 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { | 49 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { |
| 49 std::unique_ptr<WebStateImpl> web_state( | 50 std::unique_ptr<WebStateImpl> web_state( |
| 50 new WebStateImpl(params.browser_state)); | 51 new WebStateImpl(params.browser_state, params.serialization)); |
| 51 | 52 |
| 52 NSString* window_name = nil; | 53 if (!params.serialization) { |
| 53 NSString* opener_id = nil; | 54 // Initialize the session if not creating from serialization. |
| 54 BOOL opened_by_dom = NO; | 55 NSString* window_name = nil; |
| 55 int opener_navigation_index = 0; | 56 NSString* opener_id = nil; |
| 56 web_state->GetNavigationManagerImpl().InitializeSession( | 57 BOOL opened_by_dom = NO; |
| 57 window_name, opener_id, opened_by_dom, opener_navigation_index); | 58 int opener_navigation_index = 0; |
| 59 web_state->GetNavigationManagerImpl().InitializeSession( |
| 60 window_name, opener_id, opened_by_dom, opener_navigation_index); |
| 61 } |
| 58 | 62 |
| 59 // This std::move is required to compile with the version of clang shipping | 63 // 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 | 64 // with Xcode 8.0+. Evalute whether the issue is fixed once a new version of |
| 61 // Xcode is released. | 65 // Xcode is released. |
| 62 return std::move(web_state); | 66 return std::move(web_state); |
| 63 } | 67 } |
| 64 | 68 |
| 65 WebStateImpl::WebStateImpl(BrowserState* browser_state) | 69 WebStateImpl::WebStateImpl(BrowserState* browser_state) |
| 70 : WebStateImpl(browser_state, nullptr) {} |
| 71 |
| 72 WebStateImpl::WebStateImpl( |
| 73 BrowserState* browser_state, |
| 74 CRWNavigationManagerSerialization* serialized_session) |
| 66 : delegate_(nullptr), | 75 : delegate_(nullptr), |
| 67 is_loading_(false), | 76 is_loading_(false), |
| 68 is_being_destroyed_(false), | 77 is_being_destroyed_(false), |
| 69 facade_delegate_(nullptr), | 78 facade_delegate_(nullptr), |
| 70 web_controller_(nil), | 79 web_controller_(nil), |
| 71 navigation_manager_(this, browser_state), | |
| 72 interstitial_(nullptr), | 80 interstitial_(nullptr), |
| 73 weak_factory_(this) { | 81 weak_factory_(this) { |
| 82 // Create or deserialize the NavigationManager. |
| 83 if (serialized_session) { |
| 84 navigation_manager_ = |
| 85 serialization_builder_.BuildNavigationManagerImpl(serialized_session); |
| 86 } else { |
| 87 navigation_manager_.reset(new NavigationManagerImpl()); |
| 88 } |
| 89 navigation_manager_->SetDelegate(this); |
| 90 navigation_manager_->SetBrowserState(browser_state); |
| 91 // Send creation event and create the web controller. |
| 74 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); | 92 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); |
| 75 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); | 93 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); |
| 94 // Set up the image fetcher. |
| 76 image_fetcher_ = | 95 image_fetcher_ = |
| 77 base::MakeUnique<ImageDataFetcher>(web::WebThread::GetBlockingPool()); | 96 base::MakeUnique<ImageDataFetcher>(web::WebThread::GetBlockingPool()); |
| 78 image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext()); | 97 image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext()); |
| 79 } | 98 } |
| 80 | 99 |
| 81 WebStateImpl::~WebStateImpl() { | 100 WebStateImpl::~WebStateImpl() { |
| 82 [web_controller_ close]; | 101 [web_controller_ close]; |
| 83 is_being_destroyed_ = true; | 102 is_being_destroyed_ = true; |
| 84 | 103 |
| 85 // WebUI depends on web state so it must be destroyed first in case any WebUI | 104 // 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 } | 176 } |
| 158 | 177 |
| 159 WebStateFacadeDelegate* WebStateImpl::GetFacadeDelegate() const { | 178 WebStateFacadeDelegate* WebStateImpl::GetFacadeDelegate() const { |
| 160 return facade_delegate_; | 179 return facade_delegate_; |
| 161 } | 180 } |
| 162 | 181 |
| 163 void WebStateImpl::SetFacadeDelegate(WebStateFacadeDelegate* facade_delegate) { | 182 void WebStateImpl::SetFacadeDelegate(WebStateFacadeDelegate* facade_delegate) { |
| 164 facade_delegate_ = facade_delegate; | 183 facade_delegate_ = facade_delegate; |
| 165 } | 184 } |
| 166 | 185 |
| 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) { | 186 void WebStateImpl::OnNavigationCommitted(const GURL& url) { |
| 174 UpdateHttpResponseHeaders(url); | 187 UpdateHttpResponseHeaders(url); |
| 175 } | 188 } |
| 176 | 189 |
| 177 void WebStateImpl::OnUrlHashChanged() { | 190 void WebStateImpl::OnUrlHashChanged() { |
| 178 for (auto& observer : observers_) | 191 for (auto& observer : observers_) |
| 179 observer.UrlHashChanged(); | 192 observer.UrlHashChanged(); |
| 180 } | 193 } |
| 181 | 194 |
| 182 void WebStateImpl::OnHistoryStateChanged() { | 195 void WebStateImpl::OnHistoryStateChanged() { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 observer.SignInFailed(request_id, source_url); | 316 observer.SignInFailed(request_id, source_url); |
| 304 } | 317 } |
| 305 | 318 |
| 306 void WebStateImpl::OnDocumentSubmitted(const std::string& form_name, | 319 void WebStateImpl::OnDocumentSubmitted(const std::string& form_name, |
| 307 bool user_initiated) { | 320 bool user_initiated) { |
| 308 for (auto& observer : observers_) | 321 for (auto& observer : observers_) |
| 309 observer.DocumentSubmitted(form_name, user_initiated); | 322 observer.DocumentSubmitted(form_name, user_initiated); |
| 310 } | 323 } |
| 311 | 324 |
| 312 NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() { | 325 NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() { |
| 313 return navigation_manager_; | 326 return *navigation_manager_; |
| 314 } | 327 } |
| 315 | 328 |
| 316 const NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() const { | 329 const NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() const { |
| 317 return navigation_manager_; | 330 return *navigation_manager_; |
| 318 } | 331 } |
| 319 | 332 |
| 320 void WebStateImpl::CreateWebUI(const GURL& url) { | 333 void WebStateImpl::CreateWebUI(const GURL& url) { |
| 321 web_ui_ = CreateWebUIIOS(url); | 334 web_ui_ = CreateWebUIIOS(url); |
| 322 } | 335 } |
| 323 | 336 |
| 324 void WebStateImpl::ClearWebUI() { | 337 void WebStateImpl::ClearWebUI() { |
| 325 web_ui_.reset(); | 338 web_ui_.reset(); |
| 326 } | 339 } |
| 327 | 340 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 339 void WebStateImpl::LoadWebUIHtml(const base::string16& html, const GURL& url) { | 352 void WebStateImpl::LoadWebUIHtml(const base::string16& html, const GURL& url) { |
| 340 CHECK(web::GetWebClient()->IsAppSpecificURL(url)); | 353 CHECK(web::GetWebClient()->IsAppSpecificURL(url)); |
| 341 [web_controller_ loadHTML:base::SysUTF16ToNSString(html) | 354 [web_controller_ loadHTML:base::SysUTF16ToNSString(html) |
| 342 forAppSpecificURL:url]; | 355 forAppSpecificURL:url]; |
| 343 } | 356 } |
| 344 | 357 |
| 345 const base::string16& WebStateImpl::GetTitle() const { | 358 const base::string16& WebStateImpl::GetTitle() const { |
| 346 // TODO(stuartmorgan): Implement the NavigationManager logic necessary to | 359 // TODO(stuartmorgan): Implement the NavigationManager logic necessary to |
| 347 // match the WebContents implementation of this method. | 360 // match the WebContents implementation of this method. |
| 348 DCHECK(Configured()); | 361 DCHECK(Configured()); |
| 349 web::NavigationItem* item = navigation_manager_.GetLastCommittedItem(); | 362 web::NavigationItem* item = navigation_manager_->GetLastCommittedItem(); |
| 350 return item ? item->GetTitleForDisplay() : empty_string16_; | 363 return item ? item->GetTitleForDisplay() : empty_string16_; |
| 351 } | 364 } |
| 352 | 365 |
| 353 void WebStateImpl::ShowTransientContentView(CRWContentView* content_view) { | 366 void WebStateImpl::ShowTransientContentView(CRWContentView* content_view) { |
| 354 DCHECK(Configured()); | 367 DCHECK(Configured()); |
| 355 DCHECK(content_view); | 368 DCHECK(content_view); |
| 356 DCHECK(content_view.scrollView); | 369 DCHECK(content_view.scrollView); |
| 357 [web_controller_ showTransientContentView:content_view]; | 370 [web_controller_ showTransientContentView:content_view]; |
| 358 } | 371 } |
| 359 | 372 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 603 |
| 591 void WebStateImpl::SetShouldSuppressDialogs(bool should_suppress) { | 604 void WebStateImpl::SetShouldSuppressDialogs(bool should_suppress) { |
| 592 [web_controller_ setShouldSuppressDialogs:should_suppress]; | 605 [web_controller_ setShouldSuppressDialogs:should_suppress]; |
| 593 } | 606 } |
| 594 | 607 |
| 595 UIView* WebStateImpl::GetView() { | 608 UIView* WebStateImpl::GetView() { |
| 596 return [web_controller_ view]; | 609 return [web_controller_ view]; |
| 597 } | 610 } |
| 598 | 611 |
| 599 BrowserState* WebStateImpl::GetBrowserState() const { | 612 BrowserState* WebStateImpl::GetBrowserState() const { |
| 600 return navigation_manager_.GetBrowserState(); | 613 return navigation_manager_->GetBrowserState(); |
| 601 } | 614 } |
| 602 | 615 |
| 603 void WebStateImpl::OpenURL(const WebState::OpenURLParams& params) { | 616 void WebStateImpl::OpenURL(const WebState::OpenURLParams& params) { |
| 604 DCHECK(Configured()); | 617 DCHECK(Configured()); |
| 605 ClearTransientContentView(); | 618 ClearTransientContentView(); |
| 606 if (delegate_) | 619 if (delegate_) |
| 607 delegate_->OpenURLFromWebState(this, params); | 620 delegate_->OpenURLFromWebState(this, params); |
| 608 } | 621 } |
| 609 | 622 |
| 610 void WebStateImpl::Stop() { | 623 void WebStateImpl::Stop() { |
| 611 [web_controller_ stopLoading]; | 624 [web_controller_ stopLoading]; |
| 612 } | 625 } |
| 613 | 626 |
| 614 const NavigationManager* WebStateImpl::GetNavigationManager() const { | 627 const NavigationManager* WebStateImpl::GetNavigationManager() const { |
| 615 return &GetNavigationManagerImpl(); | 628 return &GetNavigationManagerImpl(); |
| 616 } | 629 } |
| 617 | 630 |
| 618 NavigationManager* WebStateImpl::GetNavigationManager() { | 631 NavigationManager* WebStateImpl::GetNavigationManager() { |
| 619 return &GetNavigationManagerImpl(); | 632 return &GetNavigationManagerImpl(); |
| 620 } | 633 } |
| 621 | 634 |
| 635 CRWNavigationManagerSerialization* |
| 636 WebStateImpl::BuildSerializedNavigationManager() { |
| 637 return serialization_builder_.BuildSerialization(navigation_manager_.get()); |
| 638 } |
| 639 |
| 622 CRWJSInjectionReceiver* WebStateImpl::GetJSInjectionReceiver() const { | 640 CRWJSInjectionReceiver* WebStateImpl::GetJSInjectionReceiver() const { |
| 623 return [web_controller_ jsInjectionReceiver]; | 641 return [web_controller_ jsInjectionReceiver]; |
| 624 } | 642 } |
| 625 | 643 |
| 626 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript) { | 644 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript) { |
| 627 [web_controller_ executeJavaScript:base::SysUTF16ToNSString(javascript) | 645 [web_controller_ executeJavaScript:base::SysUTF16ToNSString(javascript) |
| 628 completionHandler:nil]; | 646 completionHandler:nil]; |
| 629 } | 647 } |
| 630 | 648 |
| 631 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript, | 649 void WebStateImpl::ExecuteJavaScript(const base::string16& javascript, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 649 | 667 |
| 650 const std::string& WebStateImpl::GetContentsMimeType() const { | 668 const std::string& WebStateImpl::GetContentsMimeType() const { |
| 651 return mime_type_; | 669 return mime_type_; |
| 652 } | 670 } |
| 653 | 671 |
| 654 bool WebStateImpl::ContentIsHTML() const { | 672 bool WebStateImpl::ContentIsHTML() const { |
| 655 return [web_controller_ contentIsHTML]; | 673 return [web_controller_ contentIsHTML]; |
| 656 } | 674 } |
| 657 | 675 |
| 658 const GURL& WebStateImpl::GetVisibleURL() const { | 676 const GURL& WebStateImpl::GetVisibleURL() const { |
| 659 web::NavigationItem* item = navigation_manager_.GetVisibleItem(); | 677 web::NavigationItem* item = navigation_manager_->GetVisibleItem(); |
| 660 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 678 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 661 } | 679 } |
| 662 | 680 |
| 663 const GURL& WebStateImpl::GetLastCommittedURL() const { | 681 const GURL& WebStateImpl::GetLastCommittedURL() const { |
| 664 web::NavigationItem* item = navigation_manager_.GetLastCommittedItem(); | 682 web::NavigationItem* item = navigation_manager_->GetLastCommittedItem(); |
| 665 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 683 return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 666 } | 684 } |
| 667 | 685 |
| 668 GURL WebStateImpl::GetCurrentURL(URLVerificationTrustLevel* trust_level) const { | 686 GURL WebStateImpl::GetCurrentURL(URLVerificationTrustLevel* trust_level) const { |
| 669 GURL URL = [web_controller_ currentURLWithTrustLevel:trust_level]; | 687 GURL URL = [web_controller_ currentURLWithTrustLevel:trust_level]; |
| 670 bool equalURLs = web::GURLByRemovingRefFromGURL(URL) == | 688 bool equalURLs = web::GURLByRemovingRefFromGURL(URL) == |
| 671 web::GURLByRemovingRefFromGURL(GetLastCommittedURL()); | 689 web::GURLByRemovingRefFromGURL(GetLastCommittedURL()); |
| 672 DCHECK(equalURLs); | 690 DCHECK(equalURLs); |
| 673 UMA_HISTOGRAM_BOOLEAN("Web.CurrentURLEqualsLastCommittedURL", equalURLs); | 691 UMA_HISTOGRAM_BOOLEAN("Web.CurrentURLEqualsLastCommittedURL", equalURLs); |
| 674 return URL; | 692 return URL; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 const LoadCommittedDetails& load_details) { | 743 const LoadCommittedDetails& load_details) { |
| 726 for (auto& observer : observers_) | 744 for (auto& observer : observers_) |
| 727 observer.NavigationItemCommitted(load_details); | 745 observer.NavigationItemCommitted(load_details); |
| 728 } | 746 } |
| 729 | 747 |
| 730 WebState* WebStateImpl::GetWebState() { | 748 WebState* WebStateImpl::GetWebState() { |
| 731 return this; | 749 return this; |
| 732 } | 750 } |
| 733 | 751 |
| 734 } // namespace web | 752 } // namespace web |
| OLD | NEW |