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

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

Issue 2677993002: Use IOSImageDataFetcherWrapper for favicon (Closed)
Patch Set: Add header Created 3 years, 10 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
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" 18 #import "ios/web/navigation/navigation_manager_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_navigation_manager_storage.h" 20 #import "ios/web/public/crw_navigation_manager_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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 navigation_manager_ = 91 navigation_manager_ =
97 session_storage_builder.BuildNavigationManagerImpl(session_storage); 92 session_storage_builder.BuildNavigationManagerImpl(session_storage);
98 } else { 93 } else {
99 navigation_manager_.reset(new NavigationManagerImpl()); 94 navigation_manager_.reset(new NavigationManagerImpl());
100 } 95 }
101 navigation_manager_->SetDelegate(this); 96 navigation_manager_->SetDelegate(this);
102 navigation_manager_->SetBrowserState(browser_state); 97 navigation_manager_->SetBrowserState(browser_state);
103 // Send creation event and create the web controller. 98 // Send creation event and create the web controller.
104 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); 99 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this);
105 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); 100 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]);
106 // Set up the image fetcher.
107 image_fetcher_ =
108 base::MakeUnique<ImageDataFetcher>(web::WebThread::GetBlockingPool());
109 image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext());
110 } 101 }
111 102
112 WebStateImpl::~WebStateImpl() { 103 WebStateImpl::~WebStateImpl() {
113 [web_controller_ close]; 104 [web_controller_ close];
114 is_being_destroyed_ = true; 105 is_being_destroyed_ = true;
115 106
116 // WebUI depends on web state so it must be destroyed first in case any WebUI 107 // WebUI depends on web state so it must be destroyed first in case any WebUI
117 // implementations depends on accessing web state during destruction. 108 // implementations depends on accessing web state during destruction.
118 ClearWebUI(); 109 ClearWebUI();
119 110
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 bool WebStateImpl::ShouldAllowResponse(NSURLResponse* response) { 549 bool WebStateImpl::ShouldAllowResponse(NSURLResponse* response) {
559 for (auto& policy_decider : policy_deciders_) { 550 for (auto& policy_decider : policy_deciders_) {
560 if (!policy_decider.ShouldAllowResponse(response)) 551 if (!policy_decider.ShouldAllowResponse(response))
561 return false; 552 return false;
562 } 553 }
563 return true; 554 return true;
564 } 555 }
565 556
566 #pragma mark - RequestTracker management 557 #pragma mark - RequestTracker management
567 558
568 int WebStateImpl::DownloadImage(
569 const GURL& url,
570 bool is_favicon,
571 uint32_t max_bitmap_size,
572 bool bypass_cache,
573 const ImageDownloadCallback& callback) {
574 // |is_favicon| specifies whether the download of the image occurs with
575 // cookies or not. Currently, only downloads without cookies are supported.
576 // |bypass_cache| is ignored since the downloads never go through a cache.
577 DCHECK(is_favicon);
578
579 static int downloaded_image_count = 0;
580 int local_download_id = ++downloaded_image_count;
581 __block web::WebState::ImageDownloadCallback local_image_callback = callback;
582 __block GURL local_url(url);
583 ImageFetchedCallback local_callback =
584 ^(const GURL&, const int response_code, NSData* data) {
585 std::vector<SkBitmap> frames;
586 std::vector<gfx::Size> sizes;
587 if (data) {
588 frames = skia::ImageDataToSkBitmaps(data);
589 for (auto& frame : frames) {
590 sizes.push_back(gfx::Size(frame.width(), frame.height()));
591 }
592 }
593 if (response_code != net::URLFetcher::RESPONSE_CODE_INVALID) {
594 local_image_callback.Run(local_download_id, response_code, local_url,
595 frames, sizes);
596 }
597 };
598 image_fetcher_->StartDownload(url, local_callback);
599 return downloaded_image_count;
600 }
601
602 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { 559 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() {
603 if (!mojo_interface_registry_) { 560 if (!mojo_interface_registry_) {
604 mojo_interface_registry_ = 561 mojo_interface_registry_ =
605 base::MakeUnique<service_manager::InterfaceRegistry>(std::string()); 562 base::MakeUnique<service_manager::InterfaceRegistry>(std::string());
606 } 563 }
607 return mojo_interface_registry_.get(); 564 return mojo_interface_registry_.get();
608 } 565 }
609 566
610 base::WeakPtr<WebState> WebStateImpl::AsWeakPtr() { 567 base::WeakPtr<WebState> WebStateImpl::AsWeakPtr() {
611 return weak_factory_.GetWeakPtr(); 568 return weak_factory_.GetWeakPtr();
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 const LoadCommittedDetails& load_details) { 724 const LoadCommittedDetails& load_details) {
768 for (auto& observer : observers_) 725 for (auto& observer : observers_)
769 observer.NavigationItemCommitted(load_details); 726 observer.NavigationItemCommitted(load_details);
770 } 727 }
771 728
772 WebState* WebStateImpl::GetWebState() { 729 WebState* WebStateImpl::GetWebState() {
773 return this; 730 return this;
774 } 731 }
775 732
776 } // namespace web 733 } // namespace web
OLDNEW
« components/image_fetcher/image_data_fetcher.h ('K') | « 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