forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ios/web_view will provide a view similar to WKWebView while additionally exposing Chromium features. BUG= 622967 Review-Url: https://codereview.chromium.org/2643773005 Cr-Commit-Position: refs/heads/master@{#446056}
- Loading branch information
1 parent
cb0c494
commit 05089d2
Showing
55 changed files
with
2,462 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2016 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
# Public target that should be used to depend on web_view. Only give access | ||
# to the web_view public headers while still linking with the implementation. | ||
group("web_view") { | ||
public_deps = [ | ||
"//ios/web_view/public", | ||
] | ||
deps = [ | ||
"//ios/web_view/internal", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include_rules = [ | ||
# The subdirectories in ios/web_view/ will manually allow their own include | ||
# directories in ios/web_view/ so we disallow all of them. | ||
"-ios/web_view", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
eugenebut@chromium.org | ||
rohitrao@chromium.org | ||
|
||
# These are for the common case of adding or renaming files. If you're doing | ||
# structural changes, please get a review from an OWNER. | ||
per-file BUILD.gn=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2016 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
source_set("internal") { | ||
visibility = [ | ||
"//ios/web_view", | ||
"//ios/web_view/internal/*", | ||
] | ||
|
||
sources = [ | ||
"criwv.mm", | ||
"criwv_browser_state.h", | ||
"criwv_browser_state.mm", | ||
"criwv_network_delegate.cc", | ||
"criwv_network_delegate.h", | ||
"criwv_url_request_context_getter.h", | ||
"criwv_url_request_context_getter.mm", | ||
"criwv_web_client.h", | ||
"criwv_web_client.mm", | ||
"criwv_web_main_delegate.h", | ||
"criwv_web_main_delegate.mm", | ||
"criwv_web_main_parts.h", | ||
"criwv_web_main_parts.mm", | ||
"criwv_web_view_impl.h", | ||
"criwv_web_view_impl.mm", | ||
"pref_names.cc", | ||
"pref_names.h", | ||
] | ||
deps = [ | ||
"//base", | ||
"//components/pref_registry", | ||
"//components/prefs", | ||
"//components/translate/core/browser", | ||
"//components/translate/core/common", | ||
"//ios/net", | ||
"//ios/web", | ||
"//ios/web:user_agent", | ||
"//ios/web/public/app", | ||
"//ios/web_view/internal/translate", | ||
"//ios/web_view/public", | ||
"//net", | ||
"//net:extras", | ||
"//ui/base", | ||
"//url", | ||
] | ||
allow_circular_includes_from = [ "//ios/web_view/internal/translate" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
include_rules = [ | ||
"+base", | ||
"+components/infobars/core", | ||
"+components/keyed_service/core", | ||
"+components/keyed_service/ios", | ||
"+components/pref_registry", | ||
"+components/prefs", | ||
"+components/translate/core", | ||
"+components/translate/ios", | ||
"+ios/net", | ||
"+ios/web/public", | ||
"+ios/web_view", | ||
"+net", | ||
"+ui/base", | ||
|
||
# TODO(crbug.com/622967): Remove these exceptions. | ||
"+ios/web/navigation/crw_session_controller.h", | ||
"+ios/web/web_state/ui/crw_web_controller.h", | ||
"+ios/web/web_state/web_state_impl.h", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/web_view/public/criwv.h" | ||
|
||
#include <memory> | ||
|
||
#include "base/location.h" | ||
#import "base/mac/bind_objc_block.h" | ||
#include "base/single_thread_task_runner.h" | ||
#include "ios/web/public/app/web_main.h" | ||
#include "ios/web/public/web_thread.h" | ||
#include "ios/web_view/internal/criwv_browser_state.h" | ||
#import "ios/web_view/internal/criwv_web_client.h" | ||
#import "ios/web_view/internal/criwv_web_main_delegate.h" | ||
#import "ios/web_view/internal/criwv_web_view_impl.h" | ||
#import "ios/web_view/public/criwv_delegate.h" | ||
|
||
namespace { | ||
CRIWV* g_criwv = nil; | ||
} | ||
|
||
@interface CRIWV () { | ||
id<CRIWVDelegate> _delegate; | ||
std::unique_ptr<ios_web_view::CRIWVWebMainDelegate> _webMainDelegate; | ||
std::unique_ptr<web::WebMain> _webMain; | ||
} | ||
|
||
- (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate; | ||
- (ios_web_view::CRIWVBrowserState*)browserState; | ||
@end | ||
|
||
@implementation CRIWV | ||
|
||
+ (void)configureWithDelegate:(id<CRIWVDelegate>)delegate { | ||
g_criwv = [[CRIWV alloc] initWithDelegate:delegate]; | ||
} | ||
|
||
+ (void)shutDown { | ||
[g_criwv release]; | ||
g_criwv = nil; | ||
} | ||
|
||
+ (id<CRIWVWebView>)webView { | ||
return [[[CRIWVWebViewImpl alloc] initWithBrowserState:[g_criwv browserState]] | ||
autorelease]; | ||
} | ||
|
||
- (instancetype)initWithDelegate:(id<CRIWVDelegate>)delegate { | ||
self = [super init]; | ||
if (self) { | ||
_delegate = delegate; | ||
_webMainDelegate.reset(new ios_web_view::CRIWVWebMainDelegate(_delegate)); | ||
web::WebMainParams params(_webMainDelegate.get()); | ||
_webMain.reset(new web::WebMain(params)); | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
_webMain.reset(); | ||
_webMainDelegate.reset(); | ||
[super dealloc]; | ||
} | ||
|
||
- (ios_web_view::CRIWVBrowserState*)browserState { | ||
ios_web_view::CRIWVWebClient* client = | ||
static_cast<ios_web_view::CRIWVWebClient*>(web::GetWebClient()); | ||
return client->browser_state(); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_WEB_VIEW_INTERNAL_CRIWV_BROWSER_STATE_H_ | ||
#define IOS_WEB_VIEW_INTERNAL_CRIWV_BROWSER_STATE_H_ | ||
|
||
#include <memory> | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/macros.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "ios/web/public/browser_state.h" | ||
|
||
namespace user_prefs { | ||
class PrefRegistrySyncable; | ||
} | ||
|
||
namespace ios_web_view { | ||
|
||
class CRIWVURLRequestContextGetter; | ||
|
||
// CRIWV implementation of BrowserState. Can only be called from the UI thread. | ||
class CRIWVBrowserState : public web::BrowserState { | ||
public: | ||
CRIWVBrowserState(); | ||
~CRIWVBrowserState() override; | ||
|
||
// web::BrowserState implementation. | ||
bool IsOffTheRecord() const override; | ||
base::FilePath GetStatePath() const override; | ||
net::URLRequestContextGetter* GetRequestContext() override; | ||
|
||
// Returns the associated PrefService. | ||
PrefService* GetPrefs(); | ||
|
||
// Converts from web::BrowserState to CRIWVBrowserState. | ||
static CRIWVBrowserState* FromBrowserState(web::BrowserState* browser_state); | ||
|
||
private: | ||
// Registers the preferences for this BrowserState. | ||
void RegisterPrefs(user_prefs::PrefRegistrySyncable* pref_registry); | ||
|
||
// The path associated with this BrowserState object. | ||
base::FilePath path_; | ||
|
||
// The request context getter for this BrowserState object. | ||
scoped_refptr<CRIWVURLRequestContextGetter> request_context_getter_; | ||
|
||
// The PrefService associated with this BrowserState. | ||
std::unique_ptr<PrefService> prefs_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(CRIWVBrowserState); | ||
}; | ||
|
||
} // namespace ios_web_view | ||
|
||
#endif // IOS_WEB_VIEW_INTERNAL_CRIWV_BROWSER_STATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ios/web_view/internal/criwv_browser_state.h" | ||
|
||
#include <memory> | ||
|
||
#include "base/base_paths.h" | ||
#include "base/files/file_path.h" | ||
#include "base/message_loop/message_loop.h" | ||
#include "base/path_service.h" | ||
#include "base/threading/thread_restrictions.h" | ||
#include "components/pref_registry/pref_registry_syncable.h" | ||
#include "components/prefs/json_pref_store.h" | ||
#include "components/prefs/pref_filter.h" | ||
#include "components/prefs/pref_service_factory.h" | ||
#include "components/translate/core/browser/translate_prefs.h" | ||
#include "components/translate/core/common/translate_pref_names.h" | ||
#include "ios/web/public/web_thread.h" | ||
#include "ios/web_view/internal/criwv_url_request_context_getter.h" | ||
#include "ios/web_view/internal/pref_names.h" | ||
#include "ui/base/l10n/l10n_util_mac.h" | ||
|
||
namespace { | ||
const char kPreferencesFilename[] = "Preferences"; | ||
} | ||
|
||
namespace ios_web_view { | ||
|
||
CRIWVBrowserState::CRIWVBrowserState() : web::BrowserState() { | ||
CHECK(PathService::Get(base::DIR_APP_DATA, &path_)); | ||
|
||
request_context_getter_ = new CRIWVURLRequestContextGetter( | ||
GetStatePath(), | ||
web::WebThread::GetTaskRunnerForThread(web::WebThread::IO), | ||
web::WebThread::GetTaskRunnerForThread(web::WebThread::FILE), | ||
web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE)); | ||
|
||
// Initialize prefs. | ||
scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry = | ||
new user_prefs::PrefRegistrySyncable; | ||
RegisterPrefs(pref_registry.get()); | ||
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner = | ||
JsonPrefStore::GetTaskRunnerForFile(path_, | ||
web::WebThread::GetBlockingPool()); | ||
|
||
scoped_refptr<PersistentPrefStore> user_pref_store = new JsonPrefStore( | ||
path_.Append(kPreferencesFilename), sequenced_task_runner, nullptr); | ||
|
||
PrefServiceFactory factory; | ||
factory.set_user_prefs(user_pref_store); | ||
prefs_ = factory.Create(pref_registry.get()); | ||
} | ||
|
||
CRIWVBrowserState::~CRIWVBrowserState() {} | ||
|
||
PrefService* CRIWVBrowserState::GetPrefs() { | ||
DCHECK(prefs_); | ||
return prefs_.get(); | ||
} | ||
|
||
// static | ||
CRIWVBrowserState* CRIWVBrowserState::FromBrowserState( | ||
web::BrowserState* browser_state) { | ||
return static_cast<CRIWVBrowserState*>(browser_state); | ||
} | ||
|
||
bool CRIWVBrowserState::IsOffTheRecord() const { | ||
return false; | ||
} | ||
|
||
base::FilePath CRIWVBrowserState::GetStatePath() const { | ||
return path_; | ||
} | ||
|
||
net::URLRequestContextGetter* CRIWVBrowserState::GetRequestContext() { | ||
return request_context_getter_.get(); | ||
} | ||
|
||
void CRIWVBrowserState::RegisterPrefs( | ||
user_prefs::PrefRegistrySyncable* pref_registry) { | ||
// TODO(crbug.com/679895): Find a good value for the kAcceptLanguages pref. | ||
// TODO(crbug.com/679895): Pass this value to the network stack somehow, for | ||
// the HTTP header. | ||
pref_registry->RegisterStringPref(prefs::kAcceptLanguages, | ||
l10n_util::GetLocaleOverride()); | ||
pref_registry->RegisterBooleanPref(prefs::kEnableTranslate, true); | ||
translate::TranslatePrefs::RegisterProfilePrefs(pref_registry); | ||
} | ||
|
||
} // namespace ios_web_view |
Oops, something went wrong.