| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "ios/web/web_state/web_state_facade_delegate.h" | 36 #include "ios/web/web_state/web_state_facade_delegate.h" |
| 37 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h" | 37 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h" |
| 38 #include "ios/web/webui/web_ui_ios_impl.h" | 38 #include "ios/web/webui/web_ui_ios_impl.h" |
| 39 #include "net/http/http_response_headers.h" | 39 #include "net/http/http_response_headers.h" |
| 40 #include "services/service_manager/public/cpp/interface_registry.h" | 40 #include "services/service_manager/public/cpp/interface_registry.h" |
| 41 | 41 |
| 42 namespace web { | 42 namespace web { |
| 43 | 43 |
| 44 /* static */ | 44 /* static */ |
| 45 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { | 45 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { |
| 46 std::unique_ptr<WebStateImpl> web_state( | 46 std::unique_ptr<WebStateImpl> web_state(new WebStateImpl(params)); |
| 47 new WebStateImpl(params.browser_state)); | |
| 48 | 47 |
| 49 // Initialize the new session. | 48 // Initialize the new session. |
| 50 BOOL opened_by_dom = NO; | 49 web_state->GetNavigationManagerImpl().InitializeSession(); |
| 51 web_state->GetNavigationManagerImpl().InitializeSession(opened_by_dom); | |
| 52 | 50 |
| 53 // This std::move is required to compile with the version of clang shipping | 51 // This std::move is required to compile with the version of clang shipping |
| 54 // with Xcode 8.0+. Evalute whether the issue is fixed once a new version of | 52 // with Xcode 8.0+. Evalute whether the issue is fixed once a new version of |
| 55 // Xcode is released. | 53 // Xcode is released. |
| 56 return std::move(web_state); | 54 return std::move(web_state); |
| 57 } | 55 } |
| 58 | 56 |
| 59 /* static */ | 57 /* static */ |
| 60 std::unique_ptr<WebState> WebState::Create(const CreateParams& params, | 58 std::unique_ptr<WebState> WebState::Create(const CreateParams& params, |
| 61 CRWSessionStorage* session_storage) { | 59 CRWSessionStorage* session_storage) { |
| 62 std::unique_ptr<WebStateImpl> web_state( | 60 std::unique_ptr<WebStateImpl> web_state( |
| 63 new WebStateImpl(params.browser_state, session_storage)); | 61 new WebStateImpl(params, session_storage)); |
| 64 | 62 |
| 65 // 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 |
| 66 // 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 |
| 67 // Xcode is released. | 65 // Xcode is released. |
| 68 return std::move(web_state); | 66 return std::move(web_state); |
| 69 } | 67 } |
| 70 | 68 |
| 71 WebStateImpl::WebStateImpl(BrowserState* browser_state) | 69 WebStateImpl::WebStateImpl(const CreateParams& params) |
| 72 : WebStateImpl(browser_state, nullptr) {} | 70 : WebStateImpl(params, nullptr) {} |
| 73 | 71 |
| 74 WebStateImpl::WebStateImpl(BrowserState* browser_state, | 72 WebStateImpl::WebStateImpl(const CreateParams& params, |
| 75 CRWSessionStorage* session_storage) | 73 CRWSessionStorage* session_storage) |
| 76 : delegate_(nullptr), | 74 : delegate_(nullptr), |
| 77 is_loading_(false), | 75 is_loading_(false), |
| 78 is_being_destroyed_(false), | 76 is_being_destroyed_(false), |
| 79 facade_delegate_(nullptr), | 77 facade_delegate_(nullptr), |
| 80 web_controller_(nil), | 78 web_controller_(nil), |
| 81 interstitial_(nullptr), | 79 interstitial_(nullptr), |
| 80 opened_by_dom_(params.opened_by_dom), |
| 82 weak_factory_(this) { | 81 weak_factory_(this) { |
| 83 // Create or deserialize the NavigationManager. | 82 // Create or deserialize the NavigationManager. |
| 84 if (session_storage) { | 83 if (session_storage) { |
| 85 SessionStorageBuilder session_storage_builder; | 84 SessionStorageBuilder session_storage_builder; |
| 86 session_storage_builder.ExtractSessionState(this, session_storage); | 85 session_storage_builder.ExtractSessionState(this, session_storage); |
| 87 } else { | 86 } else { |
| 88 navigation_manager_.reset(new NavigationManagerImpl()); | 87 navigation_manager_.reset(new NavigationManagerImpl()); |
| 89 } | 88 } |
| 90 navigation_manager_->SetDelegate(this); | 89 navigation_manager_->SetDelegate(this); |
| 91 navigation_manager_->SetBrowserState(browser_state); | 90 navigation_manager_->SetBrowserState(params.browser_state); |
| 92 // Send creation event and create the web controller. | 91 // Send creation event and create the web controller. |
| 93 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); | 92 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); |
| 94 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); | 93 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); |
| 95 } | 94 } |
| 96 | 95 |
| 97 WebStateImpl::~WebStateImpl() { | 96 WebStateImpl::~WebStateImpl() { |
| 98 [web_controller_ close]; | 97 [web_controller_ close]; |
| 99 is_being_destroyed_ = true; | 98 is_being_destroyed_ = true; |
| 100 | 99 |
| 101 // WebUI depends on web state so it must be destroyed first in case any WebUI | 100 // WebUI depends on web state so it must be destroyed first in case any WebUI |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 const std::string& command_prefix) { | 713 const std::string& command_prefix) { |
| 715 DCHECK(script_command_callbacks_.find(command_prefix) != | 714 DCHECK(script_command_callbacks_.find(command_prefix) != |
| 716 script_command_callbacks_.end()); | 715 script_command_callbacks_.end()); |
| 717 script_command_callbacks_.erase(command_prefix); | 716 script_command_callbacks_.erase(command_prefix); |
| 718 } | 717 } |
| 719 | 718 |
| 720 id<CRWWebViewProxy> WebStateImpl::GetWebViewProxy() const { | 719 id<CRWWebViewProxy> WebStateImpl::GetWebViewProxy() const { |
| 721 return [web_controller_ webViewProxy]; | 720 return [web_controller_ webViewProxy]; |
| 722 } | 721 } |
| 723 | 722 |
| 723 bool WebStateImpl::IsOpenedByDOM() const { |
| 724 return opened_by_dom_; |
| 725 } |
| 726 |
| 724 void WebStateImpl::OnProvisionalNavigationStarted(const GURL& url) { | 727 void WebStateImpl::OnProvisionalNavigationStarted(const GURL& url) { |
| 725 for (auto& observer : observers_) | 728 for (auto& observer : observers_) |
| 726 observer.ProvisionalNavigationStarted(url); | 729 observer.ProvisionalNavigationStarted(url); |
| 727 } | 730 } |
| 728 | 731 |
| 729 #pragma mark - NavigationManagerDelegate implementation | 732 #pragma mark - NavigationManagerDelegate implementation |
| 730 | 733 |
| 731 void WebStateImpl::GoToIndex(int index) { | 734 void WebStateImpl::GoToIndex(int index) { |
| 732 [web_controller_ goToItemAtIndex:index]; | 735 [web_controller_ goToItemAtIndex:index]; |
| 733 } | 736 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 751 const LoadCommittedDetails& load_details) { | 754 const LoadCommittedDetails& load_details) { |
| 752 for (auto& observer : observers_) | 755 for (auto& observer : observers_) |
| 753 observer.NavigationItemCommitted(load_details); | 756 observer.NavigationItemCommitted(load_details); |
| 754 } | 757 } |
| 755 | 758 |
| 756 WebState* WebStateImpl::GetWebState() { | 759 WebState* WebStateImpl::GetWebState() { |
| 757 return this; | 760 return this; |
| 758 } | 761 } |
| 759 | 762 |
| 760 } // namespace web | 763 } // namespace web |
| OLD | NEW |