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/session_storage_builder.h" | 18 #import "ios/web/navigation/session_storage_builder.h" |
19 #include "ios/web/public/browser_state.h" | 19 #include "ios/web/public/browser_state.h" |
20 #import "ios/web/public/crw_session_storage.h" | 20 #import "ios/web/public/crw_session_storage.h" |
21 #import "ios/web/public/image_fetcher/image_data_fetcher.h" | |
22 #import "ios/web/public/java_script_dialog_presenter.h" | 21 #import "ios/web/public/java_script_dialog_presenter.h" |
23 #import "ios/web/public/navigation_item.h" | 22 #import "ios/web/public/navigation_item.h" |
24 #include "ios/web/public/url_util.h" | 23 #include "ios/web/public/url_util.h" |
25 #import "ios/web/public/web_client.h" | 24 #import "ios/web/public/web_client.h" |
26 #import "ios/web/public/web_state/context_menu_params.h" | 25 #import "ios/web/public/web_state/context_menu_params.h" |
27 #include "ios/web/public/web_state/credential.h" | 26 #include "ios/web/public/web_state/credential.h" |
28 #import "ios/web/public/web_state/ui/crw_content_view.h" | 27 #import "ios/web/public/web_state/ui/crw_content_view.h" |
29 #import "ios/web/public/web_state/web_state_delegate.h" | 28 #import "ios/web/public/web_state/web_state_delegate.h" |
30 #include "ios/web/public/web_state/web_state_observer.h" | 29 #include "ios/web/public/web_state/web_state_observer.h" |
31 #import "ios/web/public/web_state/web_state_policy_decider.h" | 30 #import "ios/web/public/web_state/web_state_policy_decider.h" |
32 #include "ios/web/public/web_thread.h" | 31 #include "ios/web/public/web_thread.h" |
33 #include "ios/web/public/webui/web_ui_ios_controller.h" | 32 #include "ios/web/public/webui/web_ui_ios_controller.h" |
34 #include "ios/web/web_state/global_web_state_event_tracker.h" | 33 #include "ios/web/web_state/global_web_state_event_tracker.h" |
35 #import "ios/web/web_state/ui/crw_web_controller.h" | 34 #import "ios/web/web_state/ui/crw_web_controller.h" |
36 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" | 35 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
37 #include "ios/web/web_state/web_state_facade_delegate.h" | 36 #include "ios/web/web_state/web_state_facade_delegate.h" |
38 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h" | 37 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h" |
39 #include "ios/web/webui/web_ui_ios_impl.h" | 38 #include "ios/web/webui/web_ui_ios_impl.h" |
40 #include "net/http/http_response_headers.h" | 39 #include "net/http/http_response_headers.h" |
41 #include "net/url_request/url_fetcher.h" | |
42 #include "net/url_request/url_request_context_getter.h" | |
43 #include "services/service_manager/public/cpp/interface_registry.h" | 40 #include "services/service_manager/public/cpp/interface_registry.h" |
44 #include "skia/ext/skia_utils_ios.h" | |
45 #include "third_party/skia/include/core/SkBitmap.h" | |
46 | 41 |
47 namespace web { | 42 namespace web { |
48 | 43 |
49 /* static */ | 44 /* static */ |
50 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { | 45 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { |
51 std::unique_ptr<WebStateImpl> web_state( | 46 std::unique_ptr<WebStateImpl> web_state( |
52 new WebStateImpl(params.browser_state)); | 47 new WebStateImpl(params.browser_state)); |
53 | 48 |
54 // Initialized the new session. | 49 // Initialized the new session. |
55 NSString* window_name = nil; | 50 NSString* window_name = nil; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 SessionStorageBuilder session_storage_builder; | 89 SessionStorageBuilder session_storage_builder; |
95 session_storage_builder.ExtractSessionState(this, session_storage); | 90 session_storage_builder.ExtractSessionState(this, session_storage); |
96 } else { | 91 } else { |
97 navigation_manager_.reset(new NavigationManagerImpl()); | 92 navigation_manager_.reset(new NavigationManagerImpl()); |
98 } | 93 } |
99 navigation_manager_->SetDelegate(this); | 94 navigation_manager_->SetDelegate(this); |
100 navigation_manager_->SetBrowserState(browser_state); | 95 navigation_manager_->SetBrowserState(browser_state); |
101 // Send creation event and create the web controller. | 96 // Send creation event and create the web controller. |
102 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); | 97 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); |
103 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); | 98 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); |
104 // Set up the image fetcher. | |
105 image_fetcher_ = | |
106 base::MakeUnique<ImageDataFetcher>(web::WebThread::GetBlockingPool()); | |
107 image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext()); | |
108 } | 99 } |
109 | 100 |
110 WebStateImpl::~WebStateImpl() { | 101 WebStateImpl::~WebStateImpl() { |
111 [web_controller_ close]; | 102 [web_controller_ close]; |
112 is_being_destroyed_ = true; | 103 is_being_destroyed_ = true; |
113 | 104 |
114 // WebUI depends on web state so it must be destroyed first in case any WebUI | 105 // WebUI depends on web state so it must be destroyed first in case any WebUI |
115 // implementations depends on accessing web state during destruction. | 106 // implementations depends on accessing web state during destruction. |
116 ClearWebUI(); | 107 ClearWebUI(); |
117 | 108 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 bool WebStateImpl::ShouldAllowResponse(NSURLResponse* response) { | 547 bool WebStateImpl::ShouldAllowResponse(NSURLResponse* response) { |
557 for (auto& policy_decider : policy_deciders_) { | 548 for (auto& policy_decider : policy_deciders_) { |
558 if (!policy_decider.ShouldAllowResponse(response)) | 549 if (!policy_decider.ShouldAllowResponse(response)) |
559 return false; | 550 return false; |
560 } | 551 } |
561 return true; | 552 return true; |
562 } | 553 } |
563 | 554 |
564 #pragma mark - RequestTracker management | 555 #pragma mark - RequestTracker management |
565 | 556 |
566 int WebStateImpl::DownloadImage( | |
567 const GURL& url, | |
568 bool is_favicon, | |
569 uint32_t max_bitmap_size, | |
570 bool bypass_cache, | |
571 const ImageDownloadCallback& callback) { | |
572 // |is_favicon| specifies whether the download of the image occurs with | |
573 // cookies or not. Currently, only downloads without cookies are supported. | |
574 // |bypass_cache| is ignored since the downloads never go through a cache. | |
575 DCHECK(is_favicon); | |
576 | |
577 static int downloaded_image_count = 0; | |
578 int local_download_id = ++downloaded_image_count; | |
579 __block web::WebState::ImageDownloadCallback local_image_callback = callback; | |
580 __block GURL local_url(url); | |
581 ImageFetchedCallback local_callback = | |
582 ^(const GURL&, const int response_code, NSData* data) { | |
583 std::vector<SkBitmap> frames; | |
584 std::vector<gfx::Size> sizes; | |
585 if (data) { | |
586 frames = skia::ImageDataToSkBitmaps(data); | |
587 for (auto& frame : frames) { | |
588 sizes.push_back(gfx::Size(frame.width(), frame.height())); | |
589 } | |
590 } | |
591 if (response_code != net::URLFetcher::RESPONSE_CODE_INVALID) { | |
592 local_image_callback.Run(local_download_id, response_code, local_url, | |
593 frames, sizes); | |
594 } | |
595 }; | |
596 image_fetcher_->StartDownload(url, local_callback); | |
597 return downloaded_image_count; | |
598 } | |
599 | |
600 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { | 557 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { |
601 if (!mojo_interface_registry_) { | 558 if (!mojo_interface_registry_) { |
602 mojo_interface_registry_ = | 559 mojo_interface_registry_ = |
603 base::MakeUnique<service_manager::InterfaceRegistry>(std::string()); | 560 base::MakeUnique<service_manager::InterfaceRegistry>(std::string()); |
604 } | 561 } |
605 return mojo_interface_registry_.get(); | 562 return mojo_interface_registry_.get(); |
606 } | 563 } |
607 | 564 |
608 base::WeakPtr<WebState> WebStateImpl::AsWeakPtr() { | 565 base::WeakPtr<WebState> WebStateImpl::AsWeakPtr() { |
609 return weak_factory_.GetWeakPtr(); | 566 return weak_factory_.GetWeakPtr(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 const LoadCommittedDetails& load_details) { | 722 const LoadCommittedDetails& load_details) { |
766 for (auto& observer : observers_) | 723 for (auto& observer : observers_) |
767 observer.NavigationItemCommitted(load_details); | 724 observer.NavigationItemCommitted(load_details); |
768 } | 725 } |
769 | 726 |
770 WebState* WebStateImpl::GetWebState() { | 727 WebState* WebStateImpl::GetWebState() { |
771 return this; | 728 return this; |
772 } | 729 } |
773 | 730 |
774 } // namespace web | 731 } // namespace web |
OLD | NEW |