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

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

Issue 2528043002: Implement DownloadImage directly in WebStateImpl (Closed)
Patch Set: Restrict DEPS Created 4 years 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 #include "ios/web/web_state/web_state_impl.h" 5 #include "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/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "ios/web/interstitials/web_interstitial_impl.h" 13 #include "ios/web/interstitials/web_interstitial_impl.h"
14 #import "ios/web/navigation/crw_session_controller.h" 14 #import "ios/web/navigation/crw_session_controller.h"
15 #import "ios/web/navigation/crw_session_entry.h" 15 #import "ios/web/navigation/crw_session_entry.h"
16 #include "ios/web/navigation/navigation_item_impl.h" 16 #include "ios/web/navigation/navigation_item_impl.h"
17 #include "ios/web/net/request_group_util.h" 17 #include "ios/web/net/request_group_util.h"
18 #include "ios/web/public/browser_state.h" 18 #include "ios/web/public/browser_state.h"
19 #import "ios/web/public/image_fetcher/image_data_fetcher.h"
19 #import "ios/web/public/java_script_dialog_presenter.h" 20 #import "ios/web/public/java_script_dialog_presenter.h"
20 #include "ios/web/public/navigation_item.h" 21 #include "ios/web/public/navigation_item.h"
21 #include "ios/web/public/url_util.h" 22 #include "ios/web/public/url_util.h"
22 #include "ios/web/public/web_client.h" 23 #include "ios/web/public/web_client.h"
23 #import "ios/web/public/web_state/context_menu_params.h" 24 #import "ios/web/public/web_state/context_menu_params.h"
24 #include "ios/web/public/web_state/credential.h" 25 #include "ios/web/public/web_state/credential.h"
25 #include "ios/web/public/web_state/ui/crw_content_view.h" 26 #include "ios/web/public/web_state/ui/crw_content_view.h"
26 #include "ios/web/public/web_state/web_state_delegate.h" 27 #include "ios/web/public/web_state/web_state_delegate.h"
27 #include "ios/web/public/web_state/web_state_observer.h" 28 #include "ios/web/public/web_state/web_state_observer.h"
28 #include "ios/web/public/web_state/web_state_policy_decider.h" 29 #include "ios/web/public/web_state/web_state_policy_decider.h"
29 #include "ios/web/web_state/global_web_state_event_tracker.h" 30 #include "ios/web/web_state/global_web_state_event_tracker.h"
30 #import "ios/web/web_state/ui/crw_web_controller.h" 31 #import "ios/web/web_state/ui/crw_web_controller.h"
31 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" 32 #import "ios/web/web_state/ui/crw_web_controller_container_view.h"
32 #include "ios/web/web_state/web_state_facade_delegate.h" 33 #include "ios/web/web_state/web_state_facade_delegate.h"
33 #import "ios/web/webui/web_ui_ios_controller_factory_registry.h" 34 #import "ios/web/webui/web_ui_ios_controller_factory_registry.h"
34 #import "ios/web/webui/web_ui_ios_impl.h" 35 #import "ios/web/webui/web_ui_ios_impl.h"
35 #include "net/http/http_response_headers.h" 36 #include "net/http/http_response_headers.h"
37 #include "net/url_request/url_fetcher.h"
36 #include "services/service_manager/public/cpp/interface_registry.h" 38 #include "services/service_manager/public/cpp/interface_registry.h"
39 #include "skia/ext/skia_utils_ios.h"
40 #include "third_party/skia/include/core/SkBitmap.h"
37 41
38 namespace web { 42 namespace web {
39 43
40 /* static */ 44 /* static */
41 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) { 45 std::unique_ptr<WebState> WebState::Create(const CreateParams& params) {
42 std::unique_ptr<WebStateImpl> web_state( 46 std::unique_ptr<WebStateImpl> web_state(
43 new WebStateImpl(params.browser_state)); 47 new WebStateImpl(params.browser_state));
44 48
45 NSString* window_name = nil; 49 NSString* window_name = nil;
46 NSString* opener_id = nil; 50 NSString* opener_id = nil;
47 BOOL opened_by_dom = NO; 51 BOOL opened_by_dom = NO;
48 int opener_navigation_index = 0; 52 int opener_navigation_index = 0;
49 web_state->GetNavigationManagerImpl().InitializeSession( 53 web_state->GetNavigationManagerImpl().InitializeSession(
50 window_name, opener_id, opened_by_dom, opener_navigation_index); 54 window_name, opener_id, opened_by_dom, opener_navigation_index);
51 55
52 return std::unique_ptr<WebState>(web_state.release()); 56 return std::unique_ptr<WebState>(web_state.release());
53 } 57 }
54 58
55 WebStateImpl::WebStateImpl(BrowserState* browser_state) 59 WebStateImpl::WebStateImpl(BrowserState* browser_state)
56 : delegate_(nullptr), 60 : delegate_(nullptr),
57 is_loading_(false), 61 is_loading_(false),
58 is_being_destroyed_(false), 62 is_being_destroyed_(false),
59 facade_delegate_(nullptr), 63 facade_delegate_(nullptr),
60 web_controller_(nil), 64 web_controller_(nil),
61 navigation_manager_(this, browser_state), 65 navigation_manager_(this, browser_state),
62 interstitial_(nullptr), 66 interstitial_(nullptr),
63 weak_factory_(this) { 67 weak_factory_(this) {
64 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this); 68 GlobalWebStateEventTracker::GetInstance()->OnWebStateCreated(this);
65 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]); 69 web_controller_.reset([[CRWWebController alloc] initWithWebState:this]);
70 image_fetcher_.reset(new ImageDataFetcher(web::WebThread::GetBlockingPool()));
71 image_fetcher_->SetRequestContextGetter(browser_state->GetRequestContext());
66 } 72 }
67 73
68 WebStateImpl::~WebStateImpl() { 74 WebStateImpl::~WebStateImpl() {
69 [web_controller_ close]; 75 [web_controller_ close];
70 is_being_destroyed_ = true; 76 is_being_destroyed_ = true;
71 77
72 // WebUI depends on web state so it must be destroyed first in case any WebUI 78 // WebUI depends on web state so it must be destroyed first in case any WebUI
73 // implementations depends on accessing web state during destruction. 79 // implementations depends on accessing web state during destruction.
74 ClearWebUI(); 80 ClearWebUI();
75 81
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 int WebStateImpl::DownloadImage( 537 int WebStateImpl::DownloadImage(
532 const GURL& url, 538 const GURL& url,
533 bool is_favicon, 539 bool is_favicon,
534 uint32_t max_bitmap_size, 540 uint32_t max_bitmap_size,
535 bool bypass_cache, 541 bool bypass_cache,
536 const ImageDownloadCallback& callback) { 542 const ImageDownloadCallback& callback) {
537 // |is_favicon| specifies whether the download of the image occurs with 543 // |is_favicon| specifies whether the download of the image occurs with
538 // cookies or not. Currently, only downloads without cookies are supported. 544 // cookies or not. Currently, only downloads without cookies are supported.
539 // |bypass_cache| is ignored since the downloads never go through a cache. 545 // |bypass_cache| is ignored since the downloads never go through a cache.
540 DCHECK(is_favicon); 546 DCHECK(is_favicon);
541 return [[web_controller_ delegate] downloadImageAtUrl:url 547
542 maxBitmapSize:max_bitmap_size 548 static int downloaded_image_count = 0;
543 callback:callback]; 549 int local_download_id = ++downloaded_image_count;
550 __block web::WebState::ImageDownloadCallback local_image_callback = callback;
551 __block GURL local_url(url);
552 ImageFetchedCallback local_callback =
553 ^(const GURL&, const int response_code, NSData* data) {
554 std::vector<SkBitmap> frames;
555 std::vector<gfx::Size> sizes;
556 if (data) {
557 frames = skia::ImageDataToSkBitmaps(data);
558 for (auto& frame : frames) {
559 sizes.push_back(gfx::Size(frame.width(), frame.height()));
560 }
561 }
562 if (response_code != net::URLFetcher::RESPONSE_CODE_INVALID) {
563 local_image_callback.Run(local_download_id, response_code, local_url,
564 frames, sizes);
565 }
566 };
567 image_fetcher_->StartDownload(url, local_callback);
568 return downloaded_image_count;
544 } 569 }
545 570
546 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { 571 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() {
547 if (!mojo_interface_registry_) { 572 if (!mojo_interface_registry_) {
548 mojo_interface_registry_.reset( 573 mojo_interface_registry_.reset(
549 new service_manager::InterfaceRegistry(std::string())); 574 new service_manager::InterfaceRegistry(std::string()));
550 } 575 }
551 return mojo_interface_registry_.get(); 576 return mojo_interface_registry_.get();
552 } 577 }
553 578
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 const LoadCommittedDetails& load_details) { 730 const LoadCommittedDetails& load_details) {
706 for (auto& observer : observers_) 731 for (auto& observer : observers_)
707 observer.NavigationItemCommitted(load_details); 732 observer.NavigationItemCommitted(load_details);
708 } 733 }
709 734
710 WebState* WebStateImpl::GetWebState() { 735 WebState* WebStateImpl::GetWebState() {
711 return this; 736 return this;
712 } 737 }
713 738
714 } // namespace web 739 } // 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