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

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

Issue 2693043003: Revert of Use IOSImageDataFetcherWrapper for favicon (Closed)
Patch Set: 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
« 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/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"
21 #import "ios/web/public/java_script_dialog_presenter.h" 22 #import "ios/web/public/java_script_dialog_presenter.h"
22 #import "ios/web/public/navigation_item.h" 23 #import "ios/web/public/navigation_item.h"
23 #include "ios/web/public/url_util.h" 24 #include "ios/web/public/url_util.h"
24 #import "ios/web/public/web_client.h" 25 #import "ios/web/public/web_client.h"
25 #import "ios/web/public/web_state/context_menu_params.h" 26 #import "ios/web/public/web_state/context_menu_params.h"
26 #include "ios/web/public/web_state/credential.h" 27 #include "ios/web/public/web_state/credential.h"
27 #import "ios/web/public/web_state/ui/crw_content_view.h" 28 #import "ios/web/public/web_state/ui/crw_content_view.h"
28 #import "ios/web/public/web_state/web_state_delegate.h" 29 #import "ios/web/public/web_state/web_state_delegate.h"
29 #include "ios/web/public/web_state/web_state_observer.h" 30 #include "ios/web/public/web_state/web_state_observer.h"
30 #import "ios/web/public/web_state/web_state_policy_decider.h" 31 #import "ios/web/public/web_state/web_state_policy_decider.h"
31 #include "ios/web/public/web_thread.h" 32 #include "ios/web/public/web_thread.h"
32 #include "ios/web/public/webui/web_ui_ios_controller.h" 33 #include "ios/web/public/webui/web_ui_ios_controller.h"
33 #include "ios/web/web_state/global_web_state_event_tracker.h" 34 #include "ios/web/web_state/global_web_state_event_tracker.h"
34 #import "ios/web/web_state/ui/crw_web_controller.h" 35 #import "ios/web/web_state/ui/crw_web_controller.h"
35 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" 36 #import "ios/web/web_state/ui/crw_web_controller_container_view.h"
36 #include "ios/web/web_state/web_state_facade_delegate.h" 37 #include "ios/web/web_state/web_state_facade_delegate.h"
37 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h" 38 #include "ios/web/webui/web_ui_ios_controller_factory_registry.h"
38 #include "ios/web/webui/web_ui_ios_impl.h" 39 #include "ios/web/webui/web_ui_ios_impl.h"
39 #include "net/http/http_response_headers.h" 40 #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"
40 #include "services/service_manager/public/cpp/interface_registry.h" 43 #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"
41 46
42 namespace web { 47 namespace web {
43 48
44 /* static */ 49 /* static */
45 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { 50 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) {
46 std::unique_ptr<WebStateImpl> web_state( 51 std::unique_ptr<WebStateImpl> web_state(
47 new WebStateImpl(params.browser_state)); 52 new WebStateImpl(params.browser_state));
48 53
49 // Initialized the new session. 54 // Initialized the new session.
50 NSString* window_name = nil; 55 NSString* window_name = nil;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 SessionStorageBuilder session_storage_builder; 94 SessionStorageBuilder session_storage_builder;
90 session_storage_builder.ExtractSessionState(this, session_storage); 95 session_storage_builder.ExtractSessionState(this, session_storage);
91 } else { 96 } else {
92 navigation_manager_.reset(new NavigationManagerImpl()); 97 navigation_manager_.reset(new NavigationManagerImpl());
93 } 98 }
94 navigation_manager_->SetDelegate(this); 99 navigation_manager_->SetDelegate(this);
95 navigation_manager_->SetBrowserState(browser_state); 100 navigation_manager_->SetBrowserState(browser_state);
96 // Send creation event and create the web controller. 101 // Send creation event and create the web controller.
97 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); 102 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this);
98 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); 103 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());
99 } 108 }
100 109
101 WebStateImpl::~WebStateImpl() { 110 WebStateImpl::~WebStateImpl() {
102 [web_controller_ close]; 111 [web_controller_ close];
103 is_being_destroyed_ = true; 112 is_being_destroyed_ = true;
104 113
105 // WebUI depends on web state so it must be destroyed first in case any WebUI 114 // WebUI depends on web state so it must be destroyed first in case any WebUI
106 // implementations depends on accessing web state during destruction. 115 // implementations depends on accessing web state during destruction.
107 ClearWebUI(); 116 ClearWebUI();
108 117
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 bool WebStateImpl::ShouldAllowResponse(NSURLResponse* response) { 556 bool WebStateImpl::ShouldAllowResponse(NSURLResponse* response) {
548 for (auto& policy_decider : policy_deciders_) { 557 for (auto& policy_decider : policy_deciders_) {
549 if (!policy_decider.ShouldAllowResponse(response)) 558 if (!policy_decider.ShouldAllowResponse(response))
550 return false; 559 return false;
551 } 560 }
552 return true; 561 return true;
553 } 562 }
554 563
555 #pragma mark - RequestTracker management 564 #pragma mark - RequestTracker management
556 565
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
557 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { 600 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() {
558 if (!mojo_interface_registry_) { 601 if (!mojo_interface_registry_) {
559 mojo_interface_registry_ = 602 mojo_interface_registry_ =
560 base::MakeUnique<service_manager::InterfaceRegistry>(std::string()); 603 base::MakeUnique<service_manager::InterfaceRegistry>(std::string());
561 } 604 }
562 return mojo_interface_registry_.get(); 605 return mojo_interface_registry_.get();
563 } 606 }
564 607
565 base::WeakPtr<WebState> WebStateImpl::AsWeakPtr() { 608 base::WeakPtr<WebState> WebStateImpl::AsWeakPtr() {
566 return weak_factory_.GetWeakPtr(); 609 return weak_factory_.GetWeakPtr();
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 const LoadCommittedDetails& load_details) { 765 const LoadCommittedDetails& load_details) {
723 for (auto& observer : observers_) 766 for (auto& observer : observers_)
724 observer.NavigationItemCommitted(load_details); 767 observer.NavigationItemCommitted(load_details);
725 } 768 }
726 769
727 WebState* WebStateImpl::GetWebState() { 770 WebState* WebStateImpl::GetWebState() {
728 return this; 771 return this;
729 } 772 }
730 773
731 } // namespace web 774 } // 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