Commit 62cb0af6 authored by stkhapugin@chromium.org's avatar stkhapugin@chromium.org Committed by Commit Bot

[ObjC ARC] Converts part of ios/web to ARC.

Converts web_state-related files to ARC.

Notable issues:
 - Had to fix WebUIMojoTest.MessageExchange. See comment.

Bug: 
Change-Id: Ia8a58433ab82d67ebae4f61b8c4ea954f84df202
Reviewed-on: https://chromium-review.googlesource.com/570402
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487544}
parent cb4e9764
...@@ -252,6 +252,16 @@ source_set("web_arc") { ...@@ -252,6 +252,16 @@ source_set("web_arc") {
"web_state/ui/wk_web_view_configuration_provider.mm", "web_state/ui/wk_web_view_configuration_provider.mm",
"web_state/web_controller_observer_bridge.h", "web_state/web_controller_observer_bridge.h",
"web_state/web_controller_observer_bridge.mm", "web_state/web_controller_observer_bridge.mm",
"web_state/web_state.mm",
"web_state/web_state_delegate.mm",
"web_state/web_state_delegate_bridge.mm",
"web_state/web_state_impl.h",
"web_state/web_state_impl.mm",
"web_state/web_state_observer.mm",
"web_state/web_state_observer_bridge.mm",
"web_state/web_state_policy_decider.mm",
"web_state/web_state_weak_ptr_factory.h",
"web_state/web_state_weak_ptr_factory.mm",
"web_state/web_view_internal_creation_util.h", "web_state/web_view_internal_creation_util.h",
"web_state/web_view_internal_creation_util.mm", "web_state/web_view_internal_creation_util.mm",
"web_state/wk_web_view_security_util.h", "web_state/wk_web_view_security_util.h",
...@@ -326,16 +336,6 @@ source_set("web") { ...@@ -326,16 +336,6 @@ source_set("web") {
"web_state/ui/crw_web_controller.mm", "web_state/ui/crw_web_controller.mm",
"web_state/ui/crw_web_controller_container_view.h", "web_state/ui/crw_web_controller_container_view.h",
"web_state/ui/crw_web_controller_container_view.mm", "web_state/ui/crw_web_controller_container_view.mm",
"web_state/web_state.mm",
"web_state/web_state_delegate.mm",
"web_state/web_state_delegate_bridge.mm",
"web_state/web_state_impl.h",
"web_state/web_state_impl.mm",
"web_state/web_state_observer.mm",
"web_state/web_state_observer_bridge.mm",
"web_state/web_state_policy_decider.mm",
"web_state/web_state_weak_ptr_factory.h",
"web_state/web_state_weak_ptr_factory.mm",
] ]
libs = [ libs = [
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
WebState::CreateParams::CreateParams(web::BrowserState* browser_state) WebState::CreateParams::CreateParams(web::BrowserState* browser_state)
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
WebStateDelegate::WebStateDelegate() {} WebStateDelegate::WebStateDelegate() {}
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include "base/logging.h" #include "base/logging.h"
#import "ios/web/public/web_state/context_menu_params.h" #import "ios/web/public/web_state/context_menu_params.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
WebStateDelegateBridge::WebStateDelegateBridge(id<CRWWebStateDelegate> delegate) WebStateDelegateBridge::WebStateDelegateBridge(id<CRWWebStateDelegate> delegate)
......
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
/* static */ /* static */
...@@ -173,7 +177,7 @@ CRWWebController* WebStateImpl::GetWebController() { ...@@ -173,7 +177,7 @@ CRWWebController* WebStateImpl::GetWebController() {
void WebStateImpl::SetWebController(CRWWebController* web_controller) { void WebStateImpl::SetWebController(CRWWebController* web_controller) {
[web_controller_ close]; [web_controller_ close];
web_controller_.reset([web_controller retain]); web_controller_.reset(web_controller);
} }
void WebStateImpl::OnTitleChanged() { void WebStateImpl::OnTitleChanged() {
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include "ios/web/public/load_committed_details.h" #include "ios/web/public/load_committed_details.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
WebStateObserver::WebStateObserver(WebState* web_state) : web_state_(nullptr) { WebStateObserver::WebStateObserver(WebState* web_state) : web_state_(nullptr) {
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#import "ios/web/public/web_state/web_state_observer_bridge.h" #import "ios/web/public/web_state/web_state_observer_bridge.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
WebStateObserverBridge::WebStateObserverBridge(web::WebState* webState, WebStateObserverBridge::WebStateObserverBridge(web::WebState* webState,
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#import "ios/web/web_state/web_state_impl.h" #import "ios/web/web_state/web_state_impl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
WebStatePolicyDecider::WebStatePolicyDecider(WebState* web_state) WebStatePolicyDecider::WebStatePolicyDecider(WebState* web_state)
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
// static // static
......
...@@ -147,6 +147,23 @@ class WebUIMojoTest : public WebIntTest { ...@@ -147,6 +147,23 @@ class WebUIMojoTest : public WebIntTest {
new TestWebUIControllerFactory(ui_handler_.get())); new TestWebUIControllerFactory(ui_handler_.get()));
} }
void TearDown() override {
@autoreleasepool {
// WebState owns CRWWebUIManager. When WebState is destroyed,
// CRWWebUIManager is autoreleased and will be destroyed upon autorelease
// pool purge. However in this test, WebTest destructor is called before
// PlatformTest, thus CRWWebUIManager outlives the WebThreadBundle.
// However, CRWWebUIManager owns a URLFetcherImpl, which DCHECKs that its
// destructor is called on UI web thread. Hence, URLFetcherImpl has to
// outlive the WebThreadBundle, since [NSThread mainThread] will not be
// WebThread::UI once WebThreadBundle is destroyed.
web_state_.reset();
ui_handler_.reset();
}
WebIntTest::TearDown();
}
// Returns WebState which loads test WebUI page. // Returns WebState which loads test WebUI page.
WebStateImpl* web_state() { return web_state_.get(); } WebStateImpl* web_state() { return web_state_.get(); }
// Returns UI handler which communicates with WebUI page. // Returns UI handler which communicates with WebUI page.
...@@ -167,31 +184,33 @@ class WebUIMojoTest : public WebIntTest { ...@@ -167,31 +184,33 @@ class WebUIMojoTest : public WebIntTest {
#endif #endif
// TODO(crbug.com/720098): Enable this test on device. // TODO(crbug.com/720098): Enable this test on device.
TEST_F(WebUIMojoTest, MAYBE_MessageExchange) { TEST_F(WebUIMojoTest, MAYBE_MessageExchange) {
web_state()->SetWebUsageEnabled(true); @autoreleasepool {
web_state()->GetView(); // WebState won't load URL without view. web_state()->SetWebUsageEnabled(true);
GURL url( web_state()->GetView(); // WebState won't load URL without view.
url::SchemeHostPort(kTestWebUIScheme, kTestWebUIURLHost, 0).Serialize()); GURL url(url::SchemeHostPort(kTestWebUIScheme, kTestWebUIURLHost, 0)
NavigationManager::WebLoadParams load_params(url); .Serialize());
web_state()->GetNavigationManager()->LoadURLWithParams(load_params); NavigationManager::WebLoadParams load_params(url);
web_state()->GetNavigationManager()->LoadURLWithParams(load_params);
// Wait until |TestUIHandler| receives "fin" message from WebUI page.
bool fin_received = testing::WaitUntilConditionOrTimeout(kMessageTimeout, ^{ // Wait until |TestUIHandler| receives "fin" message from WebUI page.
// Flush any pending tasks. Don't RunUntilIdle() because bool fin_received = testing::WaitUntilConditionOrTimeout(kMessageTimeout, ^{
// RunUntilIdle() is incompatible with mojo::SimpleWatcher's // Flush any pending tasks. Don't RunUntilIdle() because
// automatic arming behavior, which Mojo JS still depends upon. // RunUntilIdle() is incompatible with mojo::SimpleWatcher's
// // automatic arming behavior, which Mojo JS still depends upon.
// TODO(crbug.com/701875): Introduce the full watcher API to JS and get rid //
// of this hack. // TODO(crbug.com/701875): Introduce the full watcher API to JS and get
base::RunLoop loop; // rid of this hack.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::RunLoop loop;
loop.QuitClosure()); base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
loop.Run(); loop.QuitClosure());
return test_ui_handler()->IsFinReceived(); loop.Run();
}); return test_ui_handler()->IsFinReceived();
});
ASSERT_TRUE(fin_received);
EXPECT_FALSE(web_state()->IsLoading()); ASSERT_TRUE(fin_received);
EXPECT_EQ(url, web_state()->GetLastCommittedURL()); EXPECT_FALSE(web_state()->IsLoading());
EXPECT_EQ(url, web_state()->GetLastCommittedURL());
}
} }
} // namespace web } // namespace web
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment