Chromium Code Reviews| 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 #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 #include "ios/web/public/image_fetcher/raw_image_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 RawImageFetcher(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 Loading... | |
| 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 g_download_id = 0; |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
nit: g_ prefix means "global", so please don't use
gambard
2016/12/01 15:14:21
Done.
| |
| 543 callback:callback]; | 549 int localDownloadId = ++g_download_id; |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
s/localDownloadId/local_download_id
Same comments
gambard
2016/12/01 15:14:21
Done.
| |
| 550 __block web::WebState::ImageDownloadCallback localImageCallback = callback; | |
| 551 __block GURL localUrl(url); | |
| 552 ImageFetchedCallback localCallback = | |
| 553 ^(const GURL& originalUrl, const int responseCode, NSData* data) { | |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
nit: you can drop |originalUrl|
gambard
2016/12/01 15:14:21
Done.
| |
| 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 (responseCode != net::URLFetcher::RESPONSE_CODE_INVALID) { | |
| 563 localImageCallback.Run(localDownloadId, responseCode, localUrl, | |
| 564 frames, sizes); | |
| 565 } | |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
We should also call callback for failure cases, un
gambard
2016/12/01 15:14:21
This is not for failure. From the comments on the
| |
| 566 }; | |
| 567 // |imageFetcher_| may have been reset if the tab got closed. | |
|
Eugene But (OOO till 7-30)
2016/11/30 17:13:50
Please don't mention tab here, web does not know a
gambard
2016/12/01 15:14:21
Done.
| |
| 568 if (image_fetcher_) | |
| 569 image_fetcher_->StartDownload(url, localCallback); | |
| 570 return g_download_id; | |
| 544 } | 571 } |
| 545 | 572 |
| 546 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { | 573 service_manager::InterfaceRegistry* WebStateImpl::GetMojoInterfaceRegistry() { |
| 547 if (!mojo_interface_registry_) { | 574 if (!mojo_interface_registry_) { |
| 548 mojo_interface_registry_.reset( | 575 mojo_interface_registry_.reset( |
| 549 new service_manager::InterfaceRegistry(std::string())); | 576 new service_manager::InterfaceRegistry(std::string())); |
| 550 } | 577 } |
| 551 return mojo_interface_registry_.get(); | 578 return mojo_interface_registry_.get(); |
| 552 } | 579 } |
| 553 | 580 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 const LoadCommittedDetails& load_details) { | 732 const LoadCommittedDetails& load_details) { |
| 706 for (auto& observer : observers_) | 733 for (auto& observer : observers_) |
| 707 observer.NavigationItemCommitted(load_details); | 734 observer.NavigationItemCommitted(load_details); |
| 708 } | 735 } |
| 709 | 736 |
| 710 WebState* WebStateImpl::GetWebState() { | 737 WebState* WebStateImpl::GetWebState() { |
| 711 return this; | 738 return this; |
| 712 } | 739 } |
| 713 | 740 |
| 714 } // namespace web | 741 } // namespace web |
| OLD | NEW |