Move the ability to create BrowserContext to embedder

This commit is contained in:
Cheng Zhao 2016-07-12 21:39:54 +09:00
parent 400bb8d0f3
commit 00804e5f98
5 changed files with 22 additions and 17 deletions

View file

@ -537,18 +537,17 @@ mate::Handle<Session> Session::CreateFrom(
// static
mate::Handle<Session> Session::FromPartition(
v8::Isolate* isolate, const std::string& partition) {
scoped_refptr<brightray::BrowserContext> browser_context;
scoped_refptr<AtomBrowserContext> browser_context;
if (partition.empty()) {
browser_context = brightray::BrowserContext::From("", false);
browser_context = AtomBrowserContext::From("", false);
} else if (base::StartsWith(partition, kPersistPrefix,
base::CompareCase::SENSITIVE)) {
std::string name = partition.substr(8);
browser_context = brightray::BrowserContext::From(name, false);
browser_context = AtomBrowserContext::From(name, false);
} else {
browser_context = brightray::BrowserContext::From(partition, true);
browser_context = AtomBrowserContext::From(partition, true);
}
return CreateFrom(
isolate, static_cast<AtomBrowserContext*>(browser_context.get()));
return CreateFrom(isolate, browser_context.get());
}
// static

View file

@ -46,7 +46,7 @@ void AtomAccessTokenStore::SaveAccessToken(const GURL& server_url,
}
void AtomAccessTokenStore::GetRequestContextOnUIThread() {
auto browser_context = brightray::BrowserContext::From("", false);
auto browser_context = AtomBrowserContext::From("", false);
request_context_getter_ = browser_context->GetRequestContext();
}

View file

@ -190,14 +190,14 @@ void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
pref_registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
}
} // namespace atom
namespace brightray {
// static
scoped_refptr<BrowserContext> BrowserContext::Create(
scoped_refptr<AtomBrowserContext> AtomBrowserContext::From(
const std::string& partition, bool in_memory) {
return make_scoped_refptr(new atom::AtomBrowserContext(partition, in_memory));
auto browser_context = brightray::BrowserContext::Get(partition, in_memory);
if (browser_context)
return static_cast<AtomBrowserContext*>(browser_context.get());
return new AtomBrowserContext(partition, in_memory);
}
} // namespace brightray
} // namespace atom

View file

@ -18,8 +18,10 @@ class WebViewManager;
class AtomBrowserContext : public brightray::BrowserContext {
public:
AtomBrowserContext(const std::string& partition, bool in_memory);
~AtomBrowserContext() override;
// Get or create the BrowserContext according to its |partition| and
// |in_memory|.
static scoped_refptr<AtomBrowserContext> From(
const std::string& partition, bool in_memory);
void SetUserAgent(const std::string& user_agent);
@ -43,6 +45,10 @@ class AtomBrowserContext : public brightray::BrowserContext {
AtomNetworkDelegate* network_delegate() const { return network_delegate_; }
protected:
AtomBrowserContext(const std::string& partition, bool in_memory);
~AtomBrowserContext() override;
private:
std::unique_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
std::unique_ptr<WebViewManager> guest_manager_;

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit 3b993f9fd7ffdd0e92bb77521a8b7f32af5eba5b
Subproject commit 91abdb01a1825c12522fd5fc2349a7ba9a091a48