| 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/bind.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/threading/sequenced_task_runner_handle.h" |
| 14 #import "ios/web/interstitials/web_interstitial_impl.h" | 16 #import "ios/web/interstitials/web_interstitial_impl.h" |
| 15 #import "ios/web/navigation/crw_session_controller.h" | 17 #import "ios/web/navigation/crw_session_controller.h" |
| 16 #import "ios/web/navigation/legacy_navigation_manager_impl.h" | 18 #import "ios/web/navigation/legacy_navigation_manager_impl.h" |
| 17 #import "ios/web/navigation/navigation_item_impl.h" | 19 #import "ios/web/navigation/navigation_item_impl.h" |
| 18 #import "ios/web/navigation/session_storage_builder.h" | 20 #import "ios/web/navigation/session_storage_builder.h" |
| 19 #include "ios/web/public/browser_state.h" | 21 #include "ios/web/public/browser_state.h" |
| 20 #import "ios/web/public/crw_session_storage.h" | 22 #import "ios/web/public/crw_session_storage.h" |
| 21 #import "ios/web/public/java_script_dialog_presenter.h" | 23 #import "ios/web/public/java_script_dialog_presenter.h" |
| 22 #import "ios/web/public/navigation_item.h" | 24 #import "ios/web/public/navigation_item.h" |
| 23 #include "ios/web/public/url_util.h" | 25 #include "ios/web/public/url_util.h" |
| 24 #import "ios/web/public/web_client.h" | 26 #import "ios/web/public/web_client.h" |
| 25 #import "ios/web/public/web_state/context_menu_params.h" | 27 #import "ios/web/public/web_state/context_menu_params.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_interface_provider.h" | 30 #include "ios/web/public/web_state/web_state_interface_provider.h" |
| 29 #include "ios/web/public/web_state/web_state_observer.h" | 31 #include "ios/web/public/web_state/web_state_observer.h" |
| 30 #import "ios/web/public/web_state/web_state_policy_decider.h" | 32 #import "ios/web/public/web_state/web_state_policy_decider.h" |
| 31 #include "ios/web/public/web_thread.h" | 33 #include "ios/web/public/web_thread.h" |
| 32 #include "ios/web/public/webui/web_ui_ios_controller.h" | 34 #include "ios/web/public/webui/web_ui_ios_controller.h" |
| 33 #include "ios/web/web_state/global_web_state_event_tracker.h" | 35 #include "ios/web/web_state/global_web_state_event_tracker.h" |
| 34 #import "ios/web/web_state/navigation_context_impl.h" | 36 #import "ios/web/web_state/navigation_context_impl.h" |
| 35 #import "ios/web/web_state/session_certificate_policy_cache_impl.h" | 37 #import "ios/web/web_state/session_certificate_policy_cache_impl.h" |
| 36 #import "ios/web/web_state/ui/crw_web_controller.h" | 38 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 37 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" | 39 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
| 38 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h" | 40 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h" |
| 39 #include "ios/web/webui/web_ui_ios_impl.h" | 41 #include "ios/web/webui/web_ui_ios_impl.h" |
| 40 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
| 43 #include "ui/gfx/image/image.h" |
| 41 | 44 |
| 42 namespace web { | 45 namespace web { |
| 43 | 46 |
| 44 /* static */ | 47 /* static */ |
| 45 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { | 48 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { |
| 46 std::unique_ptr<WebStateImpl> web_state(new WebStateImpl(params)); | 49 std::unique_ptr<WebStateImpl> web_state(new WebStateImpl(params)); |
| 47 | 50 |
| 48 // Initialize the new session. | 51 // Initialize the new session. |
| 49 web_state->GetNavigationManagerImpl().InitializeSession(); | 52 web_state->GetNavigationManagerImpl().InitializeSession(); |
| 50 | 53 |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 } | 668 } |
| 666 | 669 |
| 667 id<CRWWebViewProxy> WebStateImpl::GetWebViewProxy() const { | 670 id<CRWWebViewProxy> WebStateImpl::GetWebViewProxy() const { |
| 668 return [web_controller_ webViewProxy]; | 671 return [web_controller_ webViewProxy]; |
| 669 } | 672 } |
| 670 | 673 |
| 671 bool WebStateImpl::HasOpener() const { | 674 bool WebStateImpl::HasOpener() const { |
| 672 return created_with_opener_; | 675 return created_with_opener_; |
| 673 } | 676 } |
| 674 | 677 |
| 678 void WebStateImpl::TakeSnapshot(const SnapshotCallback& callback, |
| 679 CGSize target_size) const { |
| 680 UIView* view = [web_controller_ view]; |
| 681 UIImage* snapshot = nil; |
| 682 if (view && !CGRectIsEmpty(view.bounds)) { |
| 683 CGFloat scaled_height = |
| 684 view.bounds.size.height * target_size.width / view.bounds.size.width; |
| 685 CGRect scaled_rect = CGRectMake(0, 0, target_size.width, scaled_height); |
| 686 UIGraphicsBeginImageContextWithOptions(target_size, YES, 0); |
| 687 [view drawViewHierarchyInRect:scaled_rect afterScreenUpdates:NO]; |
| 688 snapshot = UIGraphicsGetImageFromCurrentImageContext(); |
| 689 UIGraphicsEndImageContext(); |
| 690 } |
| 691 base::SequencedTaskRunnerHandle::Get()->PostTask( |
| 692 FROM_HERE, base::Bind(callback, gfx::Image(snapshot))); |
| 693 } |
| 694 |
| 675 void WebStateImpl::OnNavigationStarted(web::NavigationContext* context) { | 695 void WebStateImpl::OnNavigationStarted(web::NavigationContext* context) { |
| 676 for (auto& observer : observers_) | 696 for (auto& observer : observers_) |
| 677 observer.DidStartNavigation(context); | 697 observer.DidStartNavigation(context); |
| 678 } | 698 } |
| 679 | 699 |
| 680 void WebStateImpl::OnNavigationFinished(web::NavigationContext* context) { | 700 void WebStateImpl::OnNavigationFinished(web::NavigationContext* context) { |
| 681 for (auto& observer : observers_) | 701 for (auto& observer : observers_) |
| 682 observer.DidFinishNavigation(context); | 702 observer.DidFinishNavigation(context); |
| 683 } | 703 } |
| 684 | 704 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 711 const LoadCommittedDetails& load_details) { | 731 const LoadCommittedDetails& load_details) { |
| 712 for (auto& observer : observers_) | 732 for (auto& observer : observers_) |
| 713 observer.NavigationItemCommitted(load_details); | 733 observer.NavigationItemCommitted(load_details); |
| 714 } | 734 } |
| 715 | 735 |
| 716 WebState* WebStateImpl::GetWebState() { | 736 WebState* WebStateImpl::GetWebState() { |
| 717 return this; | 737 return this; |
| 718 } | 738 } |
| 719 | 739 |
| 720 } // namespace web | 740 } // namespace web |
| OLD | NEW |