Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: ios/web/web_state/web_state_impl.mm

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

Powered by Google App Engine
This is Rietveld 408576698