summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreugenebut <eugenebut@chromium.org>2015-08-21 09:45:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-21 16:45:53 +0000
commitaf2bbbef70127d35f9d7997e933bb563aa812a96 (patch)
tree6b64a3b1209f73a3df400240755f2f8eb4a9c5c2
parent0f5aff326a6ba9c77b0107a6fa0860aba56f4a53 (diff)
downloadchromium_src-af2bbbef70127d35f9d7997e933bb563aa812a96.zip
chromium_src-af2bbbef70127d35f9d7997e933bb563aa812a96.tar.gz
chromium_src-af2bbbef70127d35f9d7997e933bb563aa812a96.tar.bz2
WKWebView: Allow Ephemeral OTR browsing starting from iOS9.
nonPersistentDataStore is used when web::BrowserState's IsOffTheRecord returns true. This CL does not turn on Off The Record browsing for Chrome for iOS, so embedder still has to enable OTR UI. BUG=520583 Review URL: https://codereview.chromium.org/1298223008 Cr-Commit-Position: refs/heads/master@{#344790}
-rw-r--r--ios/web/public/test/test_browser_state.cc9
-rw-r--r--ios/web/public/test/test_browser_state.h4
-rw-r--r--ios/web/web_state/ui/wk_web_view_configuration_provider.h5
-rw-r--r--ios/web/web_state/ui/wk_web_view_configuration_provider.mm22
-rw-r--r--ios/web/web_state/ui/wk_web_view_configuration_provider_unittest.mm32
5 files changed, 64 insertions, 8 deletions
diff --git a/ios/web/public/test/test_browser_state.cc b/ios/web/public/test/test_browser_state.cc
index 35f958a..d001bc3 100644
--- a/ios/web/public/test/test_browser_state.cc
+++ b/ios/web/public/test/test_browser_state.cc
@@ -34,14 +34,13 @@ class TestContextURLRequestContextGetter : public net::URLRequestContextGetter {
} // namespace
namespace web {
-TestBrowserState::TestBrowserState() {
-}
+TestBrowserState::TestBrowserState() : is_off_the_record_(false) {}
TestBrowserState::~TestBrowserState() {
}
bool TestBrowserState::IsOffTheRecord() const {
- return false;
+ return is_off_the_record_;
}
base::FilePath TestBrowserState::GetStatePath() const {
@@ -54,4 +53,8 @@ net::URLRequestContextGetter* TestBrowserState::GetRequestContext() {
return request_context_.get();
}
+void TestBrowserState::SetOffTheRecord(bool flag) {
+ is_off_the_record_ = flag;
+}
+
} // namespace web
diff --git a/ios/web/public/test/test_browser_state.h b/ios/web/public/test/test_browser_state.h
index 841e191..8935041 100644
--- a/ios/web/public/test/test_browser_state.h
+++ b/ios/web/public/test/test_browser_state.h
@@ -19,8 +19,12 @@ class TestBrowserState : public BrowserState {
base::FilePath GetStatePath() const override;
net::URLRequestContextGetter* GetRequestContext() override;
+ // Makes |IsOffTheRecord| return the given flag value.
+ void SetOffTheRecord(bool flag);
+
private:
scoped_refptr<net::URLRequestContextGetter> request_context_;
+ bool is_off_the_record_;
};
} // namespace web
diff --git a/ios/web/web_state/ui/wk_web_view_configuration_provider.h b/ios/web/web_state/ui/wk_web_view_configuration_provider.h
index 6186886..32a4130 100644
--- a/ios/web/web_state/ui/wk_web_view_configuration_provider.h
+++ b/ios/web/web_state/ui/wk_web_view_configuration_provider.h
@@ -38,10 +38,13 @@ class WKWebViewConfigurationProvider : public base::SupportsUserData::Data {
void Purge();
private:
- WKWebViewConfigurationProvider();
+ explicit WKWebViewConfigurationProvider(bool is_off_the_record);
+ WKWebViewConfigurationProvider() = delete;
~WKWebViewConfigurationProvider() override;
base::scoped_nsobject<WKWebViewConfiguration> configuration_;
+ // Result of |web::BrowserState::IsOffTheRecord| call.
+ bool is_off_the_record_;
DISALLOW_COPY_AND_ASSIGN(WKWebViewConfigurationProvider);
};
diff --git a/ios/web/web_state/ui/wk_web_view_configuration_provider.mm b/ios/web/web_state/ui/wk_web_view_configuration_provider.mm
index 107cb70..a30defd 100644
--- a/ios/web/web_state/ui/wk_web_view_configuration_provider.mm
+++ b/ios/web/web_state/ui/wk_web_view_configuration_provider.mm
@@ -7,6 +7,7 @@
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
+#include "base/ios/ios_util.h"
#import "base/ios/weak_nsobject.h"
#import "base/logging.h"
#import "ios/web/alloc_with_zone_interceptor.h"
@@ -67,15 +68,18 @@ WKWebViewConfigurationProvider::FromBrowserState(BrowserState* browser_state) {
DCHECK([NSThread isMainThread]);
DCHECK(browser_state);
if (!browser_state->GetUserData(kWKWebViewConfigProviderKeyName)) {
- browser_state->SetUserData(kWKWebViewConfigProviderKeyName,
- new WKWebViewConfigurationProvider());
+ bool is_off_the_record = browser_state->IsOffTheRecord();
+ browser_state->SetUserData(
+ kWKWebViewConfigProviderKeyName,
+ new WKWebViewConfigurationProvider(is_off_the_record));
}
return *(static_cast<WKWebViewConfigurationProvider*>(
browser_state->GetUserData(kWKWebViewConfigProviderKeyName)));
}
-WKWebViewConfigurationProvider::WKWebViewConfigurationProvider() {
-}
+WKWebViewConfigurationProvider::WKWebViewConfigurationProvider(
+ bool is_off_the_record)
+ : is_off_the_record_(is_off_the_record) {}
WKWebViewConfigurationProvider::~WKWebViewConfigurationProvider() {
}
@@ -85,6 +89,16 @@ WKWebViewConfigurationProvider::GetWebViewConfiguration() {
DCHECK([NSThread isMainThread]);
if (!configuration_) {
configuration_.reset([[WKWebViewConfiguration alloc] init]);
+// TODO(eugenebut): Cleanup this macro, once all bots switched to iOS9 SDK
+// (crbug.com/523365).
+#if defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
+ if (is_off_the_record_ && base::ios::IsRunningOnIOS9OrLater()) {
+ // WKWebsiteDataStore is iOS9 only.
+ [configuration_
+ setWebsiteDataStore:[WKWebsiteDataStore nonPersistentDataStore]];
+ }
+#endif // defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >=
+ // __IPHONE_9_0
// setJavaScriptCanOpenWindowsAutomatically is required to support popups.
[[configuration_ preferences] setJavaScriptCanOpenWindowsAutomatically:YES];
[[configuration_ userContentController] addUserScript:GetEarlyPageScript()];
diff --git a/ios/web/web_state/ui/wk_web_view_configuration_provider_unittest.mm b/ios/web/web_state/ui/wk_web_view_configuration_provider_unittest.mm
index 69523ab..a75bc03 100644
--- a/ios/web/web_state/ui/wk_web_view_configuration_provider_unittest.mm
+++ b/ios/web/web_state/ui/wk_web_view_configuration_provider_unittest.mm
@@ -6,6 +6,7 @@
#import <WebKit/WebKit.h>
+#include "base/ios/ios_util.h"
#import "base/ios/weak_nsobject.h"
#include "ios/web/public/test/test_browser_state.h"
#include "ios/web/public/test/web_test_util.h"
@@ -68,6 +69,37 @@ TEST_F(WKWebViewConfigurationProviderTest, ConfigurationOwnerhip) {
other_provider.GetWebViewConfiguration().processPool);
}
+// TODO(eugenebut): Cleanup this macro, once all bots switched to iOS9 SDK
+// (crbug.com/523365).
+#if defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
+
+// Tests Non-OffTheRecord configuration.
+TEST_F(WKWebViewConfigurationProviderTest, NoneOffTheRecordConfiguration) {
+ CR_TEST_REQUIRES_WK_WEB_VIEW();
+ if (!base::ios::IsRunningOnIOS9OrLater())
+ return;
+
+ browser_state_.SetOffTheRecord(false);
+ WKWebViewConfigurationProvider& provider = GetProvider(&browser_state_);
+ EXPECT_TRUE(provider.GetWebViewConfiguration().websiteDataStore.persistent);
+}
+
+// Tests OffTheRecord configuration.
+TEST_F(WKWebViewConfigurationProviderTest, OffTheRecordConfiguration) {
+ CR_TEST_REQUIRES_WK_WEB_VIEW();
+ if (!base::ios::IsRunningOnIOS9OrLater())
+ return;
+
+ browser_state_.SetOffTheRecord(true);
+ WKWebViewConfigurationProvider& provider = GetProvider(&browser_state_);
+ WKWebViewConfiguration* config = provider.GetWebViewConfiguration();
+ ASSERT_TRUE(config);
+ EXPECT_FALSE(config.websiteDataStore.persistent);
+}
+
+#endif // defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >=
+ // __IPHONE_9_0
+
// Tests that internal configuration object can not be changed by clients.
TEST_F(WKWebViewConfigurationProviderTest, ConfigurationProtection) {
CR_TEST_REQUIRES_WK_WEB_VIEW();