Merge remote-tracking branch 'atom/master'
This commit is contained in:
commit
3669113ad2
35 changed files with 682 additions and 434 deletions
|
@ -45,6 +45,7 @@ contains documents describing how to build and contribute to Electron.
|
||||||
|
|
||||||
## Documentation Translations
|
## Documentation Translations
|
||||||
|
|
||||||
|
- [Brazilian Portuguese](https://github.com/atom/electron/tree/master/docs-translations/pt-BR)
|
||||||
- [Korean](https://github.com/atom/electron/tree/master/docs-translations/ko)
|
- [Korean](https://github.com/atom/electron/tree/master/docs-translations/ko)
|
||||||
- [Japanese](https://github.com/atom/electron/tree/master/docs-translations/jp)
|
- [Japanese](https://github.com/atom/electron/tree/master/docs-translations/jp)
|
||||||
- [Spanish](https://github.com/atom/electron/tree/master/docs-translations/es)
|
- [Spanish](https://github.com/atom/electron/tree/master/docs-translations/es)
|
||||||
|
|
|
@ -233,16 +233,16 @@ void SetProxyInIO(net::URLRequestContextGetter* getter,
|
||||||
Session::Session(AtomBrowserContext* browser_context)
|
Session::Session(AtomBrowserContext* browser_context)
|
||||||
: browser_context_(browser_context) {
|
: browser_context_(browser_context) {
|
||||||
AttachAsUserData(browser_context);
|
AttachAsUserData(browser_context);
|
||||||
|
|
||||||
// Observe DownloadManger to get download notifications.
|
// Observe DownloadManger to get download notifications.
|
||||||
auto download_manager =
|
content::BrowserContext::GetDownloadManager(browser_context)->
|
||||||
content::BrowserContext::GetDownloadManager(browser_context);
|
AddObserver(this);
|
||||||
download_manager->AddObserver(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Session::~Session() {
|
Session::~Session() {
|
||||||
auto download_manager =
|
content::BrowserContext::GetDownloadManager(browser_context())->
|
||||||
content::BrowserContext::GetDownloadManager(browser_context_);
|
RemoveObserver(this);
|
||||||
download_manager->RemoveObserver(this);
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||||
|
@ -257,8 +257,16 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Session::IsDestroyed() const {
|
||||||
|
return !browser_context_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::Destroy() {
|
||||||
|
browser_context_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void Session::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
|
void Session::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
|
||||||
new ResolveProxyHelper(browser_context_, url, callback);
|
new ResolveProxyHelper(browser_context(), url, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::ClearCache(const net::CompletionCallback& callback) {
|
void Session::ClearCache(const net::CompletionCallback& callback) {
|
||||||
|
@ -279,7 +287,7 @@ void Session::ClearStorageData(mate::Arguments* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto storage_partition =
|
auto storage_partition =
|
||||||
content::BrowserContext::GetStoragePartition(browser_context_, nullptr);
|
content::BrowserContext::GetStoragePartition(browser_context(), nullptr);
|
||||||
storage_partition->ClearData(
|
storage_partition->ClearData(
|
||||||
options.storage_types, options.quota_types, options.origin,
|
options.storage_types, options.quota_types, options.origin,
|
||||||
content::StoragePartition::OriginMatcherFunction(),
|
content::StoragePartition::OriginMatcherFunction(),
|
||||||
|
@ -300,7 +308,7 @@ void Session::SetDownloadPath(const base::FilePath& path) {
|
||||||
|
|
||||||
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
|
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
|
||||||
if (cookies_.IsEmpty()) {
|
if (cookies_.IsEmpty()) {
|
||||||
auto handle = atom::api::Cookies::Create(isolate, browser_context_);
|
auto handle = atom::api::Cookies::Create(isolate, browser_context());
|
||||||
cookies_.Reset(isolate, handle.ToV8());
|
cookies_.Reset(isolate, handle.ToV8());
|
||||||
}
|
}
|
||||||
return v8::Local<v8::Value>::New(isolate, cookies_);
|
return v8::Local<v8::Value>::New(isolate, cookies_);
|
||||||
|
@ -319,8 +327,7 @@ mate::ObjectTemplateBuilder Session::GetObjectTemplateBuilder(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<Session> Session::CreateFrom(
|
mate::Handle<Session> Session::CreateFrom(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate, AtomBrowserContext* browser_context) {
|
||||||
AtomBrowserContext* browser_context) {
|
|
||||||
auto existing = TrackableObject::FromWrappedClass(isolate, browser_context);
|
auto existing = TrackableObject::FromWrappedClass(isolate, browser_context);
|
||||||
if (existing)
|
if (existing)
|
||||||
return mate::CreateHandle(isolate, static_cast<Session*>(existing));
|
return mate::CreateHandle(isolate, static_cast<Session*>(existing));
|
||||||
|
@ -330,6 +337,14 @@ mate::Handle<Session> Session::CreateFrom(
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
mate::Handle<Session> Session::FromPartition(
|
||||||
|
v8::Isolate* isolate, const std::string& partition, bool in_memory) {
|
||||||
|
auto browser_context = brightray::BrowserContext::From(partition, in_memory);
|
||||||
|
return CreateFrom(isolate,
|
||||||
|
static_cast<AtomBrowserContext*>(browser_context.get()));
|
||||||
|
}
|
||||||
|
|
||||||
void SetWrapSession(const WrapSessionCallback& callback) {
|
void SetWrapSession(const WrapSessionCallback& callback) {
|
||||||
g_wrap_session = callback;
|
g_wrap_session = callback;
|
||||||
}
|
}
|
||||||
|
@ -348,6 +363,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
|
dict.SetMethod("fromPartition", &atom::api::Session::FromPartition);
|
||||||
dict.SetMethod("_setWrapSession", &atom::api::SetWrapSession);
|
dict.SetMethod("_setWrapSession", &atom::api::SetWrapSession);
|
||||||
dict.SetMethod("_clearWrapSession", &atom::api::ClearWrapSession);
|
dict.SetMethod("_clearWrapSession", &atom::api::ClearWrapSession);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,11 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
static mate::Handle<Session> CreateFrom(
|
static mate::Handle<Session> CreateFrom(
|
||||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
|
||||||
AtomBrowserContext* browser_context() const { return browser_context_; }
|
// Gets the Session of |partition| and |in_memory|.
|
||||||
|
static mate::Handle<Session> FromPartition(
|
||||||
|
v8::Isolate* isolate, const std::string& partition, bool in_memory);
|
||||||
|
|
||||||
|
AtomBrowserContext* browser_context() const { return browser_context_.get(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Session(AtomBrowserContext* browser_context);
|
explicit Session(AtomBrowserContext* browser_context);
|
||||||
|
@ -47,11 +51,15 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
void OnDownloadCreated(content::DownloadManager* manager,
|
void OnDownloadCreated(content::DownloadManager* manager,
|
||||||
content::DownloadItem* item) override;
|
content::DownloadItem* item) override;
|
||||||
|
|
||||||
// mate::Wrappable implementations:
|
// mate::Wrappable:
|
||||||
mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
v8::Isolate* isolate) override;
|
v8::Isolate* isolate) override;
|
||||||
|
bool IsDestroyed() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// mate::TrackableObject:
|
||||||
|
void Destroy() override;
|
||||||
|
|
||||||
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
||||||
void ClearCache(const net::CompletionCallback& callback);
|
void ClearCache(const net::CompletionCallback& callback);
|
||||||
void ClearStorageData(mate::Arguments* args);
|
void ClearStorageData(mate::Arguments* args);
|
||||||
|
@ -59,9 +67,10 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
void SetDownloadPath(const base::FilePath& path);
|
void SetDownloadPath(const base::FilePath& path);
|
||||||
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
// Cached object for cookies API.
|
||||||
v8::Global<v8::Value> cookies_;
|
v8::Global<v8::Value> cookies_;
|
||||||
|
|
||||||
AtomBrowserContext* browser_context_; // weak ref
|
scoped_refptr<AtomBrowserContext> browser_context_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Session);
|
DISALLOW_COPY_AND_ASSIGN(Session);
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
#include "atom/browser/web_view_guest_delegate.h"
|
#include "atom/browser/web_view_guest_delegate.h"
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/api/event_emitter_caller.h"
|
#include "atom/common/api/event_emitter_caller.h"
|
||||||
|
@ -153,31 +154,41 @@ WebContents::WebContents(content::WebContents* web_contents)
|
||||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents::WebContents(const mate::Dictionary& options) {
|
WebContents::WebContents(v8::Isolate* isolate,
|
||||||
|
const mate::Dictionary& options) {
|
||||||
|
// Whether it is a guest WebContents.
|
||||||
bool is_guest = false;
|
bool is_guest = false;
|
||||||
options.Get("isGuest", &is_guest);
|
options.Get("isGuest", &is_guest);
|
||||||
|
|
||||||
type_ = is_guest ? WEB_VIEW : BROWSER_WINDOW;
|
type_ = is_guest ? WEB_VIEW : BROWSER_WINDOW;
|
||||||
|
|
||||||
content::BrowserContext* browser_context =
|
// Obtain the session.
|
||||||
AtomBrowserMainParts::Get()->browser_context();
|
std::string partition;
|
||||||
|
mate::Handle<api::Session> session;
|
||||||
|
if (options.Get("session", &session)) {
|
||||||
|
} else if (options.Get("partition", &partition) && !partition.empty()) {
|
||||||
|
bool in_memory = true;
|
||||||
|
if (base::StartsWith(partition, "persist:", base::CompareCase::SENSITIVE)) {
|
||||||
|
in_memory = false;
|
||||||
|
partition = partition.substr(8);
|
||||||
|
}
|
||||||
|
session = Session::FromPartition(isolate, partition, in_memory);
|
||||||
|
} else {
|
||||||
|
// Use the default session if not specified.
|
||||||
|
session = Session::FromPartition(isolate, "", false);
|
||||||
|
}
|
||||||
|
session_.Reset(isolate, session.ToV8());
|
||||||
|
|
||||||
content::WebContents* web_contents;
|
content::WebContents* web_contents;
|
||||||
if (is_guest) {
|
if (is_guest) {
|
||||||
GURL guest_site;
|
content::SiteInstance* site_instance = content::SiteInstance::CreateForURL(
|
||||||
options.Get("partition", &guest_site);
|
session->browser_context(), GURL("chrome-guest://fake-host"));
|
||||||
// use hosts' browser_context when no partition is specified.
|
content::WebContents::CreateParams params(
|
||||||
if (!guest_site.query().empty()) {
|
session->browser_context(), site_instance);
|
||||||
browser_context = AtomBrowserMainParts::Get()
|
|
||||||
->GetBrowserContextForPartition(guest_site);
|
|
||||||
}
|
|
||||||
auto site_instance =
|
|
||||||
content::SiteInstance::CreateForURL(browser_context, guest_site);
|
|
||||||
content::WebContents::CreateParams params(browser_context, site_instance);
|
|
||||||
guest_delegate_.reset(new WebViewGuestDelegate);
|
guest_delegate_.reset(new WebViewGuestDelegate);
|
||||||
params.guest_delegate = guest_delegate_.get();
|
params.guest_delegate = guest_delegate_.get();
|
||||||
web_contents = content::WebContents::Create(params);
|
web_contents = content::WebContents::Create(params);
|
||||||
} else {
|
} else {
|
||||||
content::WebContents::CreateParams params(browser_context);
|
content::WebContents::CreateParams params(session->browser_context());
|
||||||
web_contents = content::WebContents::Create(params);
|
web_contents = content::WebContents::Create(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +196,11 @@ WebContents::WebContents(const mate::Dictionary& options) {
|
||||||
AttachAsUserData(web_contents);
|
AttachAsUserData(web_contents);
|
||||||
InitWithWebContents(web_contents);
|
InitWithWebContents(web_contents);
|
||||||
|
|
||||||
|
// Save the preferences.
|
||||||
|
base::DictionaryValue web_preferences;
|
||||||
|
mate::ConvertFromV8(isolate, options.GetHandle(), &web_preferences);
|
||||||
|
new WebContentsPreferences(web_contents, &web_preferences);
|
||||||
|
|
||||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
||||||
|
|
||||||
if (is_guest) {
|
if (is_guest) {
|
||||||
|
@ -489,6 +505,7 @@ void WebContents::NavigationEntryCommitted(
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::Destroy() {
|
void WebContents::Destroy() {
|
||||||
|
session_.Reset();
|
||||||
if (type_ == WEB_VIEW && managed_web_contents()) {
|
if (type_ == WEB_VIEW && managed_web_contents()) {
|
||||||
// When force destroying the "destroyed" event is not emitted.
|
// When force destroying the "destroyed" event is not emitted.
|
||||||
WebContentsDestroyed();
|
WebContentsDestroyed();
|
||||||
|
@ -651,10 +668,6 @@ void WebContents::InspectServiceWorker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
|
v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
|
||||||
if (session_.IsEmpty()) {
|
|
||||||
auto handle = Session::CreateFrom(isolate, GetBrowserContext());
|
|
||||||
session_.Reset(isolate, handle.ToV8());
|
|
||||||
}
|
|
||||||
return v8::Local<v8::Value>::New(isolate, session_);
|
return v8::Local<v8::Value>::New(isolate, session_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,7 +903,7 @@ mate::Handle<WebContents> WebContents::CreateFrom(
|
||||||
// static
|
// static
|
||||||
mate::Handle<WebContents> WebContents::Create(
|
mate::Handle<WebContents> WebContents::Create(
|
||||||
v8::Isolate* isolate, const mate::Dictionary& options) {
|
v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||||
auto handle = mate::CreateHandle(isolate, new WebContents(options));
|
auto handle = mate::CreateHandle(isolate, new WebContents(isolate, options));
|
||||||
g_wrap_web_contents.Run(handle.ToV8());
|
g_wrap_web_contents.Run(handle.ToV8());
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
static mate::Handle<WebContents> Create(
|
static mate::Handle<WebContents> Create(
|
||||||
v8::Isolate* isolate, const mate::Dictionary& options);
|
v8::Isolate* isolate, const mate::Dictionary& options);
|
||||||
|
|
||||||
void Destroy();
|
// mate::TrackableObject:
|
||||||
|
void Destroy() override;
|
||||||
|
|
||||||
bool IsAlive() const;
|
bool IsAlive() const;
|
||||||
int GetID() const;
|
int GetID() const;
|
||||||
bool Equal(const WebContents* web_contents) const;
|
bool Equal(const WebContents* web_contents) const;
|
||||||
|
@ -116,7 +118,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit WebContents(content::WebContents* web_contents);
|
explicit WebContents(content::WebContents* web_contents);
|
||||||
explicit WebContents(const mate::Dictionary& options);
|
WebContents(v8::Isolate* isolate, const mate::Dictionary& options);
|
||||||
~WebContents();
|
~WebContents();
|
||||||
|
|
||||||
// mate::Wrappable:
|
// mate::Wrappable:
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_web_contents.h"
|
#include "atom/browser/api/atom_api_web_contents.h"
|
||||||
#include "atom/browser/web_view_constants.h"
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
#include "atom/browser/web_view_manager.h"
|
#include "atom/browser/web_view_manager.h"
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
|
#include "atom/common/node_includes.h"
|
||||||
#include "content/public/browser/browser_context.h"
|
#include "content/public/browser/browser_context.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "net/base/filename_util.h"
|
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
|
@ -26,31 +24,6 @@ struct Converter<content::WebContents*> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
|
||||||
struct Converter<atom::WebViewManager::WebViewInfo> {
|
|
||||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
||||||
atom::WebViewManager::WebViewInfo* out) {
|
|
||||||
Dictionary options;
|
|
||||||
if (!ConvertFromV8(isolate, val, &options))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
GURL preload_url;
|
|
||||||
if (!options.Get(atom::web_view::kPreloadUrl, &preload_url))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!preload_url.is_empty() &&
|
|
||||||
!net::FileURLToFilePath(preload_url, &(out->preload_script)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return options.Get(atom::web_view::kNodeIntegration,
|
|
||||||
&(out->node_integration)) &&
|
|
||||||
options.Get(atom::web_view::kPlugins, &(out->plugins)) &&
|
|
||||||
options.Get(atom::web_view::kPartitionId, &(out->partition_id)) &&
|
|
||||||
options.Get(atom::web_view::kDisableWebSecurity,
|
|
||||||
&(out->disable_web_security));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -69,17 +42,13 @@ void AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* guest_web_contents,
|
content::WebContents* guest_web_contents,
|
||||||
atom::WebViewManager::WebViewInfo info) {
|
const base::DictionaryValue& options) {
|
||||||
auto manager = GetWebViewManager(embedder);
|
auto manager = GetWebViewManager(embedder);
|
||||||
if (manager)
|
if (manager)
|
||||||
manager->AddGuest(guest_instance_id, element_instance_id, embedder,
|
manager->AddGuest(guest_instance_id, element_instance_id, embedder,
|
||||||
guest_web_contents);
|
guest_web_contents);
|
||||||
|
|
||||||
info.guest_instance_id = guest_instance_id;
|
atom::WebContentsPreferences::From(guest_web_contents)->Merge(options);
|
||||||
info.embedder = embedder;
|
|
||||||
auto data = new atom::WebViewManager::WebViewInfoUserData(info);
|
|
||||||
guest_web_contents->SetUserData(
|
|
||||||
atom::web_view::kWebViewInfoKeyName, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "atom/common/native_mate_converters/image_converter.h"
|
#include "atom/common/native_mate_converters/image_converter.h"
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
|
#include "atom/common/options_switches.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "native_mate/constructor.h"
|
#include "native_mate/constructor.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
@ -64,9 +65,22 @@ void OnCapturePageDone(
|
||||||
|
|
||||||
|
|
||||||
Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
|
Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||||
|
// Use options['web-preferences'] to create WebContents.
|
||||||
|
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
||||||
|
options.Get(switches::kWebPreferences, &web_preferences);
|
||||||
|
|
||||||
|
// Be compatible with old options which are now in web_preferences.
|
||||||
|
std::string str;
|
||||||
|
double d;
|
||||||
|
if (options.Get(switches::kNodeIntegration, &str))
|
||||||
|
web_preferences.Set(switches::kNodeIntegration, str);
|
||||||
|
if (options.Get(switches::kPreloadScript, &str))
|
||||||
|
web_preferences.Set(switches::kPreloadScript, str);
|
||||||
|
if (options.Get(switches::kZoomFactor, &d))
|
||||||
|
web_preferences.Set(switches::kZoomFactor, d);
|
||||||
|
|
||||||
// Creates the WebContents used by BrowserWindow.
|
// Creates the WebContents used by BrowserWindow.
|
||||||
mate::Dictionary web_contents_options(isolate, v8::Object::New(isolate));
|
auto web_contents = WebContents::Create(isolate, web_preferences);
|
||||||
auto web_contents = WebContents::Create(isolate, web_contents_options);
|
|
||||||
web_contents_.Reset(isolate, web_contents.ToV8());
|
web_contents_.Reset(isolate, web_contents.ToV8());
|
||||||
api_web_contents_ = web_contents.get();
|
api_web_contents_ = web_contents.get();
|
||||||
|
|
||||||
|
@ -207,7 +221,10 @@ bool Window::IsDestroyed() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::Destroy() {
|
void Window::Destroy() {
|
||||||
window_->CloseContents(nullptr);
|
if (window_) {
|
||||||
|
window_->CloseContents(nullptr);
|
||||||
|
window_.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::Close() {
|
void Window::Close() {
|
||||||
|
|
|
@ -78,8 +78,10 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
bool IsDestroyed() const override;
|
bool IsDestroyed() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// mate::TrackableObject:
|
||||||
|
void Destroy() override;
|
||||||
|
|
||||||
// APIs for NativeWindow.
|
// APIs for NativeWindow.
|
||||||
void Destroy();
|
|
||||||
void Close();
|
void Close();
|
||||||
bool IsClosed();
|
bool IsClosed();
|
||||||
void Focus();
|
void Focus();
|
||||||
|
|
|
@ -29,7 +29,9 @@ class IDUserData : public base::SupportsUserData::Data {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TrackableObjectBase::TrackableObjectBase()
|
TrackableObjectBase::TrackableObjectBase()
|
||||||
: weak_map_id_(0), wrapped_(nullptr) {
|
: weak_map_id_(0), wrapped_(nullptr), weak_factory_(this) {
|
||||||
|
RegisterDestructionCallback(
|
||||||
|
base::Bind(&TrackableObjectBase::Destroy, weak_factory_.GetWeakPtr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackableObjectBase::~TrackableObjectBase() {
|
TrackableObjectBase::~TrackableObjectBase() {
|
||||||
|
@ -61,8 +63,9 @@ int32_t TrackableObjectBase::GetIDFromWrappedClass(base::SupportsUserData* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void TrackableObjectBase::RegisterDestructionCallback(void (*c)()) {
|
void TrackableObjectBase::RegisterDestructionCallback(
|
||||||
atom::AtomBrowserMainParts::Get()->RegisterDestructionCallback(base::Bind(c));
|
const base::Closure& closure) {
|
||||||
|
atom::AtomBrowserMainParts::Get()->RegisterDestructionCallback(closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
|
|
||||||
#include "atom/browser/api/event_emitter.h"
|
#include "atom/browser/api/event_emitter.h"
|
||||||
#include "atom/common/id_weak_map.h"
|
#include "atom/common/id_weak_map.h"
|
||||||
|
#include "base/bind.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
class SupportsUserData;
|
class SupportsUserData;
|
||||||
|
@ -28,6 +30,9 @@ class TrackableObjectBase : public mate::EventEmitter {
|
||||||
// Wrap TrackableObject into a class that SupportsUserData.
|
// Wrap TrackableObject into a class that SupportsUserData.
|
||||||
void AttachAsUserData(base::SupportsUserData* wrapped);
|
void AttachAsUserData(base::SupportsUserData* wrapped);
|
||||||
|
|
||||||
|
// Subclasses should implement this to destroy their native types.
|
||||||
|
virtual void Destroy() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~TrackableObjectBase() override;
|
~TrackableObjectBase() override;
|
||||||
|
|
||||||
|
@ -39,12 +44,14 @@ class TrackableObjectBase : public mate::EventEmitter {
|
||||||
|
|
||||||
// Register a callback that should be destroyed before JavaScript environment
|
// Register a callback that should be destroyed before JavaScript environment
|
||||||
// gets destroyed.
|
// gets destroyed.
|
||||||
static void RegisterDestructionCallback(void (*callback)());
|
static void RegisterDestructionCallback(const base::Closure& closure);
|
||||||
|
|
||||||
int32_t weak_map_id_;
|
int32_t weak_map_id_;
|
||||||
base::SupportsUserData* wrapped_;
|
base::SupportsUserData* wrapped_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
base::WeakPtrFactory<TrackableObjectBase> weak_factory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(TrackableObjectBase);
|
DISALLOW_COPY_AND_ASSIGN(TrackableObjectBase);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,7 +92,8 @@ class TrackableObject : public TrackableObjectBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackableObject() {
|
TrackableObject() {
|
||||||
RegisterDestructionCallback(&TrackableObject<T>::ReleaseAllWeakReferences);
|
RegisterDestructionCallback(
|
||||||
|
base::Bind(&TrackableObject<T>::ReleaseAllWeakReferences));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes this instance from the weak map.
|
// Removes this instance from the weak map.
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/web_view_manager.h"
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
#include "atom/browser/web_view_constants.h"
|
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
|
@ -38,6 +37,7 @@
|
||||||
#include "net/ssl/ssl_cert_request_info.h"
|
#include "net/ssl/ssl_cert_request_info.h"
|
||||||
#include "ppapi/host/ppapi_host.h"
|
#include "ppapi/host/ppapi_host.h"
|
||||||
#include "ui/base/l10n/l10n_util.h"
|
#include "ui/base/l10n/l10n_util.h"
|
||||||
|
#include "v8/include/v8.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -54,37 +54,6 @@ bool g_suppress_renderer_process_restart = false;
|
||||||
// Custom schemes to be registered to standard.
|
// Custom schemes to be registered to standard.
|
||||||
std::string g_custom_schemes = "";
|
std::string g_custom_schemes = "";
|
||||||
|
|
||||||
// Find out the owner of the child process according to |process_id|.
|
|
||||||
enum ProcessOwner {
|
|
||||||
OWNER_NATIVE_WINDOW,
|
|
||||||
OWNER_GUEST_WEB_CONTENTS,
|
|
||||||
OWNER_NONE, // it might be devtools though.
|
|
||||||
};
|
|
||||||
|
|
||||||
ProcessOwner GetProcessOwner(int process_id,
|
|
||||||
NativeWindow** window,
|
|
||||||
WebViewManager::WebViewInfo* info) {
|
|
||||||
content::WebContents* web_contents = content::WebContents::FromRenderViewHost(
|
|
||||||
content::RenderViewHost::FromID(process_id, kDefaultRoutingID));
|
|
||||||
if (!web_contents)
|
|
||||||
return OWNER_NONE;
|
|
||||||
|
|
||||||
// First search for NativeWindow.
|
|
||||||
*window = NativeWindow::FromWebContents(web_contents);
|
|
||||||
if (*window)
|
|
||||||
return OWNER_NATIVE_WINDOW;
|
|
||||||
|
|
||||||
// Then search for guest WebContents.
|
|
||||||
auto data = static_cast<WebViewManager::WebViewInfoUserData*>(
|
|
||||||
web_contents->GetUserData(web_view::kWebViewInfoKeyName));
|
|
||||||
if (data) {
|
|
||||||
*info = data->web_view_info();
|
|
||||||
return OWNER_GUEST_WEB_CONTENTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OWNER_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
scoped_refptr<net::X509Certificate> ImportCertFromFile(
|
scoped_refptr<net::X509Certificate> ImportCertFromFile(
|
||||||
const base::FilePath& path) {
|
const base::FilePath& path) {
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
|
@ -160,16 +129,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
||||||
|
|
||||||
// Custom preferences of guest page.
|
// Custom preferences of guest page.
|
||||||
auto web_contents = content::WebContents::FromRenderViewHost(host);
|
auto web_contents = content::WebContents::FromRenderViewHost(host);
|
||||||
auto info = static_cast<WebViewManager::WebViewInfoUserData*>(
|
WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs);
|
||||||
web_contents->GetUserData(web_view::kWebViewInfoKeyName));
|
|
||||||
if (info) {
|
|
||||||
prefs->web_security_enabled = !info->web_view_info().disable_web_security;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeWindow* window = NativeWindow::FromWebContents(web_contents);
|
|
||||||
if (window)
|
|
||||||
window->OverrideWebkitPrefs(prefs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AtomBrowserClient::GetApplicationLocale() {
|
std::string AtomBrowserClient::GetApplicationLocale() {
|
||||||
|
@ -225,23 +185,14 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
if (ContainsKey(pending_processes_, process_id))
|
if (ContainsKey(pending_processes_, process_id))
|
||||||
process_id = pending_processes_[process_id];
|
process_id = pending_processes_[process_id];
|
||||||
|
|
||||||
NativeWindow* window;
|
// Get the WebContents of the render process.
|
||||||
WebViewManager::WebViewInfo info;
|
content::WebContents* web_contents = content::WebContents::FromRenderViewHost(
|
||||||
ProcessOwner owner = GetProcessOwner(process_id, &window, &info);
|
content::RenderViewHost::FromID(process_id, kDefaultRoutingID));
|
||||||
|
if (!web_contents)
|
||||||
|
return;
|
||||||
|
|
||||||
if (owner == OWNER_NATIVE_WINDOW) {
|
WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||||
window->AppendExtraCommandLineSwitches(command_line);
|
web_contents, command_line);
|
||||||
} else if (owner == OWNER_GUEST_WEB_CONTENTS) {
|
|
||||||
command_line->AppendSwitchASCII(
|
|
||||||
switches::kGuestInstanceID, base::IntToString(info.guest_instance_id));
|
|
||||||
command_line->AppendSwitchASCII(
|
|
||||||
switches::kNodeIntegration, info.node_integration ? "true" : "false");
|
|
||||||
if (info.plugins)
|
|
||||||
command_line->AppendSwitch(switches::kEnablePlugins);
|
|
||||||
if (!info.preload_script.empty())
|
|
||||||
command_line->AppendSwitchPath(
|
|
||||||
switches::kPreloadScript, info.preload_script);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomBrowserClient::DidCreatePpapiPlugin(
|
void AtomBrowserClient::DidCreatePpapiPlugin(
|
||||||
|
|
|
@ -56,8 +56,10 @@ std::string RemoveWhitespace(const std::string& str) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
AtomBrowserContext::AtomBrowserContext()
|
AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
||||||
: job_factory_(new AtomURLRequestJobFactory) {
|
bool in_memory)
|
||||||
|
: brightray::BrowserContext(partition, in_memory),
|
||||||
|
job_factory_(new AtomURLRequestJobFactory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomBrowserContext::~AtomBrowserContext() {
|
AtomBrowserContext::~AtomBrowserContext() {
|
||||||
|
@ -150,7 +152,7 @@ AtomBrowserContext::GetDownloadManagerDelegate() {
|
||||||
|
|
||||||
content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() {
|
content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() {
|
||||||
if (!guest_manager_)
|
if (!guest_manager_)
|
||||||
guest_manager_.reset(new WebViewManager(this));
|
guest_manager_.reset(new WebViewManager);
|
||||||
return guest_manager_.get();
|
return guest_manager_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,3 +164,13 @@ void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
|
||||||
|
// static
|
||||||
|
scoped_refptr<BrowserContext> BrowserContext::Create(
|
||||||
|
const std::string& partition, bool in_memory) {
|
||||||
|
return make_scoped_refptr(new atom::AtomBrowserContext(partition, in_memory));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace brightray
|
||||||
|
|
|
@ -17,8 +17,8 @@ class WebViewManager;
|
||||||
|
|
||||||
class AtomBrowserContext : public brightray::BrowserContext {
|
class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
public:
|
public:
|
||||||
AtomBrowserContext();
|
AtomBrowserContext(const std::string& partition, bool in_memory);
|
||||||
virtual ~AtomBrowserContext();
|
~AtomBrowserContext() override;
|
||||||
|
|
||||||
// brightray::URLRequestContextGetter::Delegate:
|
// brightray::URLRequestContextGetter::Delegate:
|
||||||
std::string GetUserAgent() override;
|
std::string GetUserAgent() override;
|
||||||
|
@ -41,7 +41,8 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
scoped_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
|
scoped_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
|
||||||
scoped_ptr<WebViewManager> guest_manager_;
|
scoped_ptr<WebViewManager> guest_manager_;
|
||||||
|
|
||||||
AtomURLRequestJobFactory* job_factory_; // Weak reference.
|
// Managed by brightray::BrowserContext.
|
||||||
|
AtomURLRequestJobFactory* job_factory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
|
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,23 +26,6 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
const base::FilePath::CharType kStoragePartitionDirname[] = "Partitions";
|
|
||||||
|
|
||||||
void GetStoragePartitionConfig(const GURL& partition,
|
|
||||||
base::FilePath* partition_path,
|
|
||||||
bool* in_memory,
|
|
||||||
std::string* id) {
|
|
||||||
*in_memory = (partition.path() != "/persist");
|
|
||||||
net::UnescapeRule::Type flags =
|
|
||||||
net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS;
|
|
||||||
*id = net::UnescapeURLComponent(partition.query(), flags);
|
|
||||||
*partition_path = base::FilePath(kStoragePartitionDirname).AppendASCII(*id);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
|
AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
|
||||||
|
|
||||||
|
@ -67,30 +50,11 @@ AtomBrowserMainParts* AtomBrowserMainParts::Get() {
|
||||||
return self_;
|
return self_;
|
||||||
}
|
}
|
||||||
|
|
||||||
content::BrowserContext* AtomBrowserMainParts::GetBrowserContextForPartition(
|
|
||||||
const GURL& partition) {
|
|
||||||
std::string id;
|
|
||||||
bool in_memory;
|
|
||||||
base::FilePath partition_path;
|
|
||||||
GetStoragePartitionConfig(partition, &partition_path, &in_memory, &id);
|
|
||||||
if (browser_context_map_.contains(id))
|
|
||||||
return browser_context_map_.get(id);
|
|
||||||
|
|
||||||
scoped_ptr<brightray::BrowserContext> browser_context(CreateBrowserContext());
|
|
||||||
browser_context->Initialize(partition_path.value(), in_memory);
|
|
||||||
browser_context_map_.set(id, browser_context.Pass());
|
|
||||||
return browser_context_map_.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AtomBrowserMainParts::RegisterDestructionCallback(
|
void AtomBrowserMainParts::RegisterDestructionCallback(
|
||||||
const base::Closure& callback) {
|
const base::Closure& callback) {
|
||||||
destruction_callbacks_.push_back(callback);
|
destruction_callbacks_.push_back(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() {
|
|
||||||
return new AtomBrowserContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AtomBrowserMainParts::PostEarlyInitialization() {
|
void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||||
brightray::BrowserMainParts::PostEarlyInitialization();
|
brightray::BrowserMainParts::PostEarlyInitialization();
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,9 @@
|
||||||
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "base/containers/scoped_ptr_hash_map.h"
|
|
||||||
#include "base/timer/timer.h"
|
#include "base/timer/timer.h"
|
||||||
#include "brightray/browser/browser_main_parts.h"
|
#include "brightray/browser/browser_main_parts.h"
|
||||||
#include "content/public/browser/browser_context.h"
|
#include "content/public/browser/browser_context.h"
|
||||||
|
@ -33,10 +31,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||||
|
|
||||||
static AtomBrowserMainParts* Get();
|
static AtomBrowserMainParts* Get();
|
||||||
|
|
||||||
// Returns the BrowserContext associated with the partition.
|
|
||||||
content::BrowserContext* GetBrowserContextForPartition(
|
|
||||||
const GURL& partition);
|
|
||||||
|
|
||||||
// Register a callback that should be destroyed before JavaScript environment
|
// Register a callback that should be destroyed before JavaScript environment
|
||||||
// gets destroyed.
|
// gets destroyed.
|
||||||
void RegisterDestructionCallback(const base::Closure& callback);
|
void RegisterDestructionCallback(const base::Closure& callback);
|
||||||
|
@ -44,10 +38,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||||
Browser* browser() { return browser_.get(); }
|
Browser* browser() { return browser_.get(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Implementations of brightray::BrowserMainParts.
|
// content::BrowserMainParts:
|
||||||
brightray::BrowserContext* CreateBrowserContext() override;
|
|
||||||
|
|
||||||
// Implementations of content::BrowserMainParts.
|
|
||||||
void PostEarlyInitialization() override;
|
void PostEarlyInitialization() override;
|
||||||
void PreMainMessageLoopRun() override;
|
void PreMainMessageLoopRun() override;
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
@ -78,10 +69,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||||
// List of callbacks should be executed before destroying JS env.
|
// List of callbacks should be executed before destroying JS env.
|
||||||
std::list<base::Closure> destruction_callbacks_;
|
std::list<base::Closure> destruction_callbacks_;
|
||||||
|
|
||||||
// partition_id => browser_context
|
|
||||||
base::ScopedPtrHashMap<std::string, scoped_ptr<brightray::BrowserContext>>
|
|
||||||
browser_context_map_;
|
|
||||||
|
|
||||||
static AtomBrowserMainParts* self_;
|
static AtomBrowserMainParts* self_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
|
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
|
||||||
|
|
|
@ -38,29 +38,12 @@ moveLastToFirst = (list) ->
|
||||||
getNextInstanceId = (webContents) ->
|
getNextInstanceId = (webContents) ->
|
||||||
++nextInstanceId
|
++nextInstanceId
|
||||||
|
|
||||||
# Generate URL encoded partition id.
|
|
||||||
getPartitionId = (partition) ->
|
|
||||||
# Guest site url will be chrome-guest://fake-host/{persist}?{partitionId}
|
|
||||||
partitionId = "chrome-guest://fake-host/"
|
|
||||||
if partition
|
|
||||||
persist = partition.startsWith('persist:')
|
|
||||||
if persist
|
|
||||||
partition = partition.substring('persist:'.length)
|
|
||||||
partitionId += 'persist?'
|
|
||||||
else
|
|
||||||
# Just to differentiate from same persistant ID
|
|
||||||
partition += "_temp"
|
|
||||||
partitionId += '?'
|
|
||||||
partitionId += encodeURIComponent(partition)
|
|
||||||
return partitionId
|
|
||||||
|
|
||||||
# Create a new guest instance.
|
# Create a new guest instance.
|
||||||
createGuest = (embedder, params) ->
|
createGuest = (embedder, params) ->
|
||||||
webViewManager ?= process.atomBinding 'web_view_manager'
|
webViewManager ?= process.atomBinding 'web_view_manager'
|
||||||
|
|
||||||
id = getNextInstanceId embedder
|
id = getNextInstanceId embedder
|
||||||
partitionId = getPartitionId params.partition
|
guest = webContents.create {isGuest: true, partition: params.partition, embedder}
|
||||||
guest = webContents.create {isGuest: true, partition: partitionId, embedder}
|
|
||||||
guestInstances[id] = {guest, embedder}
|
guestInstances[id] = {guest, embedder}
|
||||||
|
|
||||||
# Destroy guest when the embedder is gone or navigated.
|
# Destroy guest when the embedder is gone or navigated.
|
||||||
|
@ -132,12 +115,13 @@ attachGuest = (embedder, elementInstanceId, guestInstanceId, params) ->
|
||||||
return unless guestInstances[oldGuestInstanceId]?
|
return unless guestInstances[oldGuestInstanceId]?
|
||||||
destroyGuest embedder, oldGuestInstanceId
|
destroyGuest embedder, oldGuestInstanceId
|
||||||
|
|
||||||
webViewManager.addGuest guestInstanceId, elementInstanceId, embedder, guest,
|
webPreferences =
|
||||||
nodeIntegration: params.nodeintegration
|
'guest-instance-id': guestInstanceId
|
||||||
plugins: params.plugins
|
'node-integration': params.nodeintegration ? false
|
||||||
disableWebSecurity: params.disablewebsecurity
|
'plugins': params.plugins
|
||||||
preloadUrl: params.preload ? ''
|
'web-security': !params.disablewebsecurity
|
||||||
partitionId: getPartitionId(params.partition)
|
webPreferences['preload-url'] = params.preload if params.preload
|
||||||
|
webViewManager.addGuest guestInstanceId, elementInstanceId, embedder, guest, webPreferences
|
||||||
|
|
||||||
guest.attachParams = params
|
guest.attachParams = params
|
||||||
embedderElementsMap[key] = guestInstanceId
|
embedderElementsMap[key] = guestInstanceId
|
||||||
|
|
|
@ -15,12 +15,10 @@
|
||||||
#include "atom/common/native_mate_converters/image_converter.h"
|
#include "atom/common/native_mate_converters/image_converter.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/command_line.h"
|
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
#include "base/json/json_writer.h"
|
#include "base/json/json_writer.h"
|
||||||
#include "base/prefs/pref_service.h"
|
#include "base/prefs/pref_service.h"
|
||||||
#include "base/message_loop/message_loop.h"
|
#include "base/message_loop/message_loop.h"
|
||||||
#include "base/strings/string_number_conversions.h"
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "brightray/browser/inspectable_web_contents.h"
|
#include "brightray/browser/inspectable_web_contents.h"
|
||||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||||
|
@ -31,8 +29,6 @@
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
#include "content/public/browser/render_widget_host_view.h"
|
#include "content/public/browser/render_widget_host_view.h"
|
||||||
#include "content/public/common/content_switches.h"
|
#include "content/public/common/content_switches.h"
|
||||||
#include "content/public/common/renderer_preferences.h"
|
|
||||||
#include "content/public/common/web_preferences.h"
|
|
||||||
#include "ipc/ipc_message_macros.h"
|
#include "ipc/ipc_message_macros.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "ui/gfx/codec/png_codec.h"
|
#include "ui/gfx/codec/png_codec.h"
|
||||||
|
@ -43,10 +39,6 @@
|
||||||
#include "ui/gfx/screen.h"
|
#include "ui/gfx/screen.h"
|
||||||
#include "ui/gl/gpu_switching_manager.h"
|
#include "ui/gl/gpu_switching_manager.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
#include "ui/gfx/switches.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using content::NavigationEntry;
|
using content::NavigationEntry;
|
||||||
using content::RenderWidgetHostView;
|
using content::RenderWidgetHostView;
|
||||||
using content::RenderWidgetHost;
|
using content::RenderWidgetHost;
|
||||||
|
@ -57,17 +49,6 @@ namespace atom {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Array of available web runtime features.
|
|
||||||
const char* kWebRuntimeFeatures[] = {
|
|
||||||
switches::kExperimentalFeatures,
|
|
||||||
switches::kExperimentalCanvasFeatures,
|
|
||||||
switches::kSubpixelFontScaling,
|
|
||||||
switches::kOverlayScrollbars,
|
|
||||||
switches::kOverlayFullscreenVideo,
|
|
||||||
switches::kSharedWorker,
|
|
||||||
switches::kPageVisibility,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Convert draggable regions in raw format to SkRegion format. Caller is
|
// Convert draggable regions in raw format to SkRegion format. Caller is
|
||||||
// responsible for deleting the returned SkRegion instance.
|
// responsible for deleting the returned SkRegion instance.
|
||||||
scoped_ptr<SkRegion> DraggableRegionsToSkRegion(
|
scoped_ptr<SkRegion> DraggableRegionsToSkRegion(
|
||||||
|
@ -94,9 +75,7 @@ NativeWindow::NativeWindow(
|
||||||
transparent_(false),
|
transparent_(false),
|
||||||
enable_larger_than_screen_(false),
|
enable_larger_than_screen_(false),
|
||||||
is_closed_(false),
|
is_closed_(false),
|
||||||
node_integration_(true),
|
|
||||||
has_dialog_attached_(false),
|
has_dialog_attached_(false),
|
||||||
zoom_factor_(1.0),
|
|
||||||
aspect_ratio_(0.0),
|
aspect_ratio_(0.0),
|
||||||
inspectable_web_contents_(inspectable_web_contents),
|
inspectable_web_contents_(inspectable_web_contents),
|
||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
|
@ -105,7 +84,6 @@ NativeWindow::NativeWindow(
|
||||||
options.Get(switches::kFrame, &has_frame_);
|
options.Get(switches::kFrame, &has_frame_);
|
||||||
options.Get(switches::kTransparent, &transparent_);
|
options.Get(switches::kTransparent, &transparent_);
|
||||||
options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
|
options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
|
||||||
options.Get(switches::kNodeIntegration, &node_integration_);
|
|
||||||
|
|
||||||
// Tell the content module to initialize renderer widget with transparent
|
// Tell the content module to initialize renderer widget with transparent
|
||||||
// mode.
|
// mode.
|
||||||
|
@ -114,25 +92,6 @@ NativeWindow::NativeWindow(
|
||||||
// Read icon before window is created.
|
// Read icon before window is created.
|
||||||
options.Get(switches::kIcon, &icon_);
|
options.Get(switches::kIcon, &icon_);
|
||||||
|
|
||||||
// The "preload" option must be absolute path.
|
|
||||||
if (options.Get(switches::kPreloadScript, &preload_script_) &&
|
|
||||||
!preload_script_.IsAbsolute()) {
|
|
||||||
LOG(ERROR) << "Path of \"preload\" script must be absolute.";
|
|
||||||
preload_script_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Be compatible with old API of "node-integration" option.
|
|
||||||
std::string old_string_token;
|
|
||||||
if (options.Get(switches::kNodeIntegration, &old_string_token) &&
|
|
||||||
old_string_token != "disable")
|
|
||||||
node_integration_ = true;
|
|
||||||
|
|
||||||
// Read the web preferences.
|
|
||||||
options.Get(switches::kWebPreferences, &web_preferences_);
|
|
||||||
|
|
||||||
// Read the zoom factor before any navigation.
|
|
||||||
options.Get(switches::kZoomFactor, &zoom_factor_);
|
|
||||||
|
|
||||||
WindowList::AddWindow(this);
|
WindowList::AddWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,81 +340,6 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::AppendExtraCommandLineSwitches(
|
|
||||||
base::CommandLine* command_line) {
|
|
||||||
// Append --node-integration to renderer process.
|
|
||||||
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
|
||||||
node_integration_ ? "true" : "false");
|
|
||||||
|
|
||||||
// Append --preload.
|
|
||||||
if (!preload_script_.empty())
|
|
||||||
command_line->AppendSwitchPath(switches::kPreloadScript, preload_script_);
|
|
||||||
|
|
||||||
// Append --zoom-factor.
|
|
||||||
if (zoom_factor_ != 1.0)
|
|
||||||
command_line->AppendSwitchASCII(switches::kZoomFactor,
|
|
||||||
base::DoubleToString(zoom_factor_));
|
|
||||||
|
|
||||||
if (web_preferences_.IsEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool b;
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
// Check if DirectWrite is disabled.
|
|
||||||
if (web_preferences_.Get(switches::kDirectWrite, &b) && !b)
|
|
||||||
command_line->AppendSwitch(::switches::kDisableDirectWrite);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Check if plugins are enabled.
|
|
||||||
if (web_preferences_.Get("plugins", &b) && b)
|
|
||||||
command_line->AppendSwitch(switches::kEnablePlugins);
|
|
||||||
|
|
||||||
// This set of options are not availabe in WebPreferences, so we have to pass
|
|
||||||
// them via command line and enable them in renderer procss.
|
|
||||||
for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
|
|
||||||
const char* feature = kWebRuntimeFeatures[i];
|
|
||||||
if (web_preferences_.Get(feature, &b))
|
|
||||||
command_line->AppendSwitchASCII(feature, b ? "true" : "false");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) {
|
|
||||||
if (web_preferences_.IsEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool b;
|
|
||||||
std::vector<base::FilePath> list;
|
|
||||||
if (web_preferences_.Get("javascript", &b))
|
|
||||||
prefs->javascript_enabled = b;
|
|
||||||
if (web_preferences_.Get("images", &b))
|
|
||||||
prefs->images_enabled = b;
|
|
||||||
if (web_preferences_.Get("java", &b))
|
|
||||||
prefs->java_enabled = b;
|
|
||||||
if (web_preferences_.Get("text-areas-are-resizable", &b))
|
|
||||||
prefs->text_areas_are_resizable = b;
|
|
||||||
if (web_preferences_.Get("webgl", &b))
|
|
||||||
prefs->experimental_webgl_enabled = b;
|
|
||||||
if (web_preferences_.Get("webaudio", &b))
|
|
||||||
prefs->webaudio_enabled = b;
|
|
||||||
if (web_preferences_.Get("web-security", &b)) {
|
|
||||||
prefs->web_security_enabled = b;
|
|
||||||
prefs->allow_displaying_insecure_content = !b;
|
|
||||||
prefs->allow_running_insecure_content = !b;
|
|
||||||
}
|
|
||||||
if (web_preferences_.Get("allow-displaying-insecure-content", &b))
|
|
||||||
prefs->allow_displaying_insecure_content = b;
|
|
||||||
if (web_preferences_.Get("allow-running-insecure-content", &b))
|
|
||||||
prefs->allow_running_insecure_content = b;
|
|
||||||
if (web_preferences_.Get("extra-plugin-dirs", &list)) {
|
|
||||||
if (content::PluginService::GetInstance()->NPAPIPluginsSupported()) {
|
|
||||||
for (size_t i = 0; i < list.size(); ++i)
|
|
||||||
content::PluginService::GetInstance()->AddExtraPluginDir(list[i]);
|
|
||||||
} else {
|
|
||||||
LOG(WARNING) << "NPAPI plugins not supported on this platform";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowClosed() {
|
void NativeWindow::NotifyWindowClosed() {
|
||||||
if (is_closed_)
|
if (is_closed_)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,23 +19,17 @@
|
||||||
#include "content/public/browser/readback_types.h"
|
#include "content/public/browser/readback_types.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
#include "content/public/browser/web_contents_user_data.h"
|
#include "content/public/browser/web_contents_user_data.h"
|
||||||
#include "native_mate/persistent_dictionary.h"
|
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
#include "ui/gfx/image/image_skia.h"
|
#include "ui/gfx/image/image_skia.h"
|
||||||
|
|
||||||
class SkRegion;
|
class SkRegion;
|
||||||
|
|
||||||
namespace base {
|
|
||||||
class CommandLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
class InspectableWebContents;
|
class InspectableWebContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
struct NativeWebKeyboardEvent;
|
struct NativeWebKeyboardEvent;
|
||||||
struct WebPreferences;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
@ -189,10 +183,6 @@ class NativeWindow : public content::WebContentsObserver,
|
||||||
content::WebContents*,
|
content::WebContents*,
|
||||||
const content::NativeWebKeyboardEvent& event) {}
|
const content::NativeWebKeyboardEvent& event) {}
|
||||||
|
|
||||||
// Called when renderer process is going to be started.
|
|
||||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line);
|
|
||||||
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
|
||||||
|
|
||||||
// Public API used by platform-dependent delegates and observers to send UI
|
// Public API used by platform-dependent delegates and observers to send UI
|
||||||
// related notifications.
|
// related notifications.
|
||||||
void NotifyWindowClosed();
|
void NotifyWindowClosed();
|
||||||
|
@ -282,9 +272,6 @@ class NativeWindow : public content::WebContentsObserver,
|
||||||
// The windows has been closed.
|
// The windows has been closed.
|
||||||
bool is_closed_;
|
bool is_closed_;
|
||||||
|
|
||||||
// Whether node integration is enabled.
|
|
||||||
bool node_integration_;
|
|
||||||
|
|
||||||
// There is a dialog that has been attached to window.
|
// There is a dialog that has been attached to window.
|
||||||
bool has_dialog_attached_;
|
bool has_dialog_attached_;
|
||||||
|
|
||||||
|
@ -292,15 +279,6 @@ class NativeWindow : public content::WebContentsObserver,
|
||||||
// it should be cancelled when we can prove that the window is responsive.
|
// it should be cancelled when we can prove that the window is responsive.
|
||||||
base::CancelableClosure window_unresposive_closure_;
|
base::CancelableClosure window_unresposive_closure_;
|
||||||
|
|
||||||
// Web preferences.
|
|
||||||
mate::PersistentDictionary web_preferences_;
|
|
||||||
|
|
||||||
// The script to load before page's JavaScript starts to run.
|
|
||||||
base::FilePath preload_script_;
|
|
||||||
|
|
||||||
// Page's default zoom factor.
|
|
||||||
double zoom_factor_;
|
|
||||||
|
|
||||||
// Used to maintain the aspect ratio of a view which is inside of the
|
// Used to maintain the aspect ratio of a view which is inside of the
|
||||||
// content view.
|
// content view.
|
||||||
double aspect_ratio_;
|
double aspect_ratio_;
|
||||||
|
|
162
atom/browser/web_contents_preferences.cc
Normal file
162
atom/browser/web_contents_preferences.cc
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
// Copyright (c) 2015 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "atom/browser/web_contents_preferences.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "atom/common/options_switches.h"
|
||||||
|
#include "base/command_line.h"
|
||||||
|
#include "base/strings/string_number_conversions.h"
|
||||||
|
#include "content/public/common/web_preferences.h"
|
||||||
|
#include "net/base/filename_util.h"
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
#include "ui/gfx/switches.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Pointer as WebContents's user data key.
|
||||||
|
const char* kWebPreferencesKey = "WebContentsPreferences";
|
||||||
|
|
||||||
|
// Array of available web runtime features.
|
||||||
|
const char* kWebRuntimeFeatures[] = {
|
||||||
|
switches::kExperimentalFeatures,
|
||||||
|
switches::kExperimentalCanvasFeatures,
|
||||||
|
switches::kSubpixelFontScaling,
|
||||||
|
switches::kOverlayScrollbars,
|
||||||
|
switches::kOverlayFullscreenVideo,
|
||||||
|
switches::kSharedWorker,
|
||||||
|
switches::kPageVisibility,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
WebContentsPreferences::WebContentsPreferences(
|
||||||
|
content::WebContents* web_contents,
|
||||||
|
base::DictionaryValue* web_preferences) {
|
||||||
|
web_preferences_.Swap(web_preferences);
|
||||||
|
web_contents->SetUserData(kWebPreferencesKey, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
WebContentsPreferences::~WebContentsPreferences() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
|
||||||
|
web_preferences_.MergeDictionary(&extend);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
WebContentsPreferences* WebContentsPreferences::From(
|
||||||
|
content::WebContents* web_contents) {
|
||||||
|
return static_cast<WebContentsPreferences*>(
|
||||||
|
web_contents->GetUserData(kWebPreferencesKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||||
|
content::WebContents* web_contents, base::CommandLine* command_line) {
|
||||||
|
WebContentsPreferences* self = From(web_contents);
|
||||||
|
if (!self)
|
||||||
|
return;
|
||||||
|
|
||||||
|
base::DictionaryValue& web_preferences = self->web_preferences_;
|
||||||
|
|
||||||
|
bool b;
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
// Check if DirectWrite is disabled.
|
||||||
|
if (web_preferences.GetBoolean(switches::kDirectWrite, &b) && !b)
|
||||||
|
command_line->AppendSwitch(::switches::kDisableDirectWrite);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Check if plugins are enabled.
|
||||||
|
if (web_preferences.GetBoolean("plugins", &b) && b)
|
||||||
|
command_line->AppendSwitch(switches::kEnablePlugins);
|
||||||
|
|
||||||
|
// This set of options are not availabe in WebPreferences, so we have to pass
|
||||||
|
// them via command line and enable them in renderer procss.
|
||||||
|
for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
|
||||||
|
const char* feature = kWebRuntimeFeatures[i];
|
||||||
|
if (web_preferences.GetBoolean(feature, &b))
|
||||||
|
command_line->AppendSwitchASCII(feature, b ? "true" : "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we have node integration specified.
|
||||||
|
bool node_integration = true;
|
||||||
|
web_preferences.GetBoolean(switches::kNodeIntegration, &node_integration);
|
||||||
|
// Be compatible with old API of "node-integration" option.
|
||||||
|
std::string old_token;
|
||||||
|
if (web_preferences.GetString(switches::kNodeIntegration, &old_token) &&
|
||||||
|
old_token != "disable")
|
||||||
|
node_integration = true;
|
||||||
|
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
||||||
|
node_integration ? "true" : "false");
|
||||||
|
|
||||||
|
// The preload script.
|
||||||
|
base::FilePath::StringType preload;
|
||||||
|
if (web_preferences.GetString(switches::kPreloadScript, &preload)) {
|
||||||
|
if (base::FilePath(preload).IsAbsolute())
|
||||||
|
command_line->AppendSwitchNative(switches::kPreloadScript, preload);
|
||||||
|
else
|
||||||
|
LOG(ERROR) << "preload script must have abosulute path.";
|
||||||
|
} else if (web_preferences.GetString(switches::kPreloadUrl, &preload)) {
|
||||||
|
// Translate to file path if there is "preload-url" option.
|
||||||
|
base::FilePath preload_path;
|
||||||
|
if (net::FileURLToFilePath(GURL(preload), &preload_path))
|
||||||
|
command_line->AppendSwitchPath(switches::kPreloadScript, preload_path);
|
||||||
|
else
|
||||||
|
LOG(ERROR) << "preload url must be file:// protocol.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// The zoom factor.
|
||||||
|
double zoom_factor = 1.0;
|
||||||
|
if (web_preferences.GetDouble(switches::kZoomFactor, &zoom_factor) &&
|
||||||
|
zoom_factor != 1.0)
|
||||||
|
command_line->AppendSwitchASCII(switches::kZoomFactor,
|
||||||
|
base::DoubleToString(zoom_factor));
|
||||||
|
|
||||||
|
// --guest-instance-id, which is used to identify guest WebContents.
|
||||||
|
int guest_instance_id;
|
||||||
|
if (web_preferences.GetInteger(switches::kGuestInstanceID,
|
||||||
|
&guest_instance_id))
|
||||||
|
command_line->AppendSwitchASCII(switches::kGuestInstanceID,
|
||||||
|
base::IntToString(guest_instance_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void WebContentsPreferences::OverrideWebkitPrefs(
|
||||||
|
content::WebContents* web_contents, content::WebPreferences* prefs) {
|
||||||
|
WebContentsPreferences* self = From(web_contents);
|
||||||
|
if (!self)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool b;
|
||||||
|
if (self->web_preferences_.GetBoolean("javascript", &b))
|
||||||
|
prefs->javascript_enabled = b;
|
||||||
|
if (self->web_preferences_.GetBoolean("images", &b))
|
||||||
|
prefs->images_enabled = b;
|
||||||
|
if (self->web_preferences_.GetBoolean("java", &b))
|
||||||
|
prefs->java_enabled = b;
|
||||||
|
if (self->web_preferences_.GetBoolean("text-areas-are-resizable", &b))
|
||||||
|
prefs->text_areas_are_resizable = b;
|
||||||
|
if (self->web_preferences_.GetBoolean("webgl", &b))
|
||||||
|
prefs->experimental_webgl_enabled = b;
|
||||||
|
if (self->web_preferences_.GetBoolean("webaudio", &b))
|
||||||
|
prefs->webaudio_enabled = b;
|
||||||
|
if (self->web_preferences_.GetBoolean("web-security", &b)) {
|
||||||
|
prefs->web_security_enabled = b;
|
||||||
|
prefs->allow_displaying_insecure_content = !b;
|
||||||
|
prefs->allow_running_insecure_content = !b;
|
||||||
|
}
|
||||||
|
if (self->web_preferences_.GetBoolean("allow-displaying-insecure-content",
|
||||||
|
&b))
|
||||||
|
prefs->allow_displaying_insecure_content = b;
|
||||||
|
if (self->web_preferences_.GetBoolean("allow-running-insecure-content", &b))
|
||||||
|
prefs->allow_running_insecure_content = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace atom
|
53
atom/browser/web_contents_preferences.h
Normal file
53
atom/browser/web_contents_preferences.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// Copyright (c) 2015 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
||||||
|
#define ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
||||||
|
|
||||||
|
#include "base/values.h"
|
||||||
|
#include "content/public/browser/web_contents_user_data.h"
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
class CommandLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace content {
|
||||||
|
struct WebPreferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
// Stores and applies the preferences of WebContents.
|
||||||
|
class WebContentsPreferences
|
||||||
|
: public content::WebContentsUserData<WebContentsPreferences> {
|
||||||
|
public:
|
||||||
|
// Get the preferences of |web_contents|.
|
||||||
|
static WebContentsPreferences* From(content::WebContents* web_contents);
|
||||||
|
|
||||||
|
// Append command paramters according to |web_contents|'s preferences.
|
||||||
|
static void AppendExtraCommandLineSwitches(
|
||||||
|
content::WebContents* web_contents, base::CommandLine* command_line);
|
||||||
|
|
||||||
|
// Modify the WebPreferences according to |web_contents|'s preferences.
|
||||||
|
static void OverrideWebkitPrefs(
|
||||||
|
content::WebContents* web_contents, content::WebPreferences* prefs);
|
||||||
|
|
||||||
|
WebContentsPreferences(content::WebContents* web_contents,
|
||||||
|
base::DictionaryValue* web_preferences);
|
||||||
|
~WebContentsPreferences() override;
|
||||||
|
|
||||||
|
// $.extend(|web_preferences_|, |new_web_preferences|).
|
||||||
|
void Merge(const base::DictionaryValue& new_web_preferences);
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class content::WebContentsUserData<WebContentsPreferences>;
|
||||||
|
|
||||||
|
base::DictionaryValue web_preferences_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
|
@ -5,13 +5,12 @@
|
||||||
#include "atom/browser/web_view_manager.h"
|
#include "atom/browser/web_view_manager.h"
|
||||||
|
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
WebViewManager::WebViewManager(content::BrowserContext* context) {
|
WebViewManager::WebViewManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewManager::~WebViewManager() {
|
WebViewManager::~WebViewManager() {
|
||||||
|
@ -21,7 +20,6 @@ void WebViewManager::AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* web_contents) {
|
content::WebContents* web_contents) {
|
||||||
base::AutoLock auto_lock(lock_);
|
|
||||||
web_contents_embedder_map_[guest_instance_id] = { web_contents, embedder };
|
web_contents_embedder_map_[guest_instance_id] = { web_contents, embedder };
|
||||||
|
|
||||||
// Map the element in embedder to guest.
|
// Map the element in embedder to guest.
|
||||||
|
@ -31,7 +29,6 @@ void WebViewManager::AddGuest(int guest_instance_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebViewManager::RemoveGuest(int guest_instance_id) {
|
void WebViewManager::RemoveGuest(int guest_instance_id) {
|
||||||
base::AutoLock auto_lock(lock_);
|
|
||||||
if (!ContainsKey(web_contents_embedder_map_, guest_instance_id))
|
if (!ContainsKey(web_contents_embedder_map_, guest_instance_id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -7,45 +7,14 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "base/files/file_path.h"
|
|
||||||
#include "base/supports_user_data.h"
|
|
||||||
#include "base/synchronization/lock.h"
|
|
||||||
#include "content/public/browser/browser_plugin_guest_manager.h"
|
#include "content/public/browser/browser_plugin_guest_manager.h"
|
||||||
#include "content/public/browser/site_instance.h"
|
|
||||||
|
|
||||||
namespace content {
|
|
||||||
class BrowserContext;
|
|
||||||
class RenderProcessHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class WebViewManager : public content::BrowserPluginGuestManager {
|
class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
public:
|
public:
|
||||||
struct WebViewInfo {
|
WebViewManager();
|
||||||
int guest_instance_id;
|
~WebViewManager() override;
|
||||||
content::WebContents* embedder;
|
|
||||||
bool node_integration;
|
|
||||||
bool plugins;
|
|
||||||
bool disable_web_security;
|
|
||||||
base::FilePath preload_script;
|
|
||||||
GURL partition_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WebViewInfoUserData : public base::SupportsUserData::Data {
|
|
||||||
public:
|
|
||||||
explicit WebViewInfoUserData(WebViewInfo info)
|
|
||||||
: web_view_info_(info) {}
|
|
||||||
~WebViewInfoUserData() override {}
|
|
||||||
|
|
||||||
WebViewInfo& web_view_info() { return web_view_info_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
WebViewInfo web_view_info_;
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit WebViewManager(content::BrowserContext* context);
|
|
||||||
virtual ~WebViewManager();
|
|
||||||
|
|
||||||
void AddGuest(int guest_instance_id,
|
void AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
|
@ -90,8 +59,6 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
// (embedder_process_id, element_instance_id) => guest_instance_id
|
// (embedder_process_id, element_instance_id) => guest_instance_id
|
||||||
std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
|
std::map<ElementInstanceKey, int> element_instance_id_to_guest_map_;
|
||||||
|
|
||||||
base::Lock lock_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WebViewManager);
|
DISALLOW_COPY_AND_ASSIGN(WebViewManager);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,9 @@ const char kGuestInstanceID[] = "guest-instance-id";
|
||||||
// Script that will be loaded by guest WebContents before other scripts.
|
// Script that will be loaded by guest WebContents before other scripts.
|
||||||
const char kPreloadScript[] = "preload";
|
const char kPreloadScript[] = "preload";
|
||||||
|
|
||||||
|
// Like --preload, but the passed argument is an URL.
|
||||||
|
const char kPreloadUrl[] = "preload-url";
|
||||||
|
|
||||||
// Whether the window should be transparent.
|
// Whether the window should be transparent.
|
||||||
const char kTransparent[] = "transparent";
|
const char kTransparent[] = "transparent";
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ extern const char kPpapiFlashPath[];
|
||||||
extern const char kPpapiFlashVersion[];
|
extern const char kPpapiFlashVersion[];
|
||||||
extern const char kGuestInstanceID[];
|
extern const char kGuestInstanceID[];
|
||||||
extern const char kPreloadScript[];
|
extern const char kPreloadScript[];
|
||||||
|
extern const char kPreloadUrl[];
|
||||||
extern const char kTransparent[];
|
extern const char kTransparent[];
|
||||||
extern const char kType[];
|
extern const char kType[];
|
||||||
extern const char kDisableAutoHideCursor[];
|
extern const char kDisableAutoHideCursor[];
|
||||||
|
|
|
@ -15,7 +15,7 @@ contentTracing.startRecording('*', contentTracing.DEFAULT_OPTIONS, function() {
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
``
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
|
|
70
docs-translations/pt-BR/README-pt-BR.md
Normal file
70
docs-translations/pt-BR/README-pt-BR.md
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
## Guias
|
||||||
|
|
||||||
|
* [Distribuir Aplicação](../../docs/tutorial/application-distribution.md)
|
||||||
|
* [Empacotamento da aplicação](../../docs/tutorial/application-packaging.md)
|
||||||
|
* [Usando módulos nativos](../../docs/tutorial/using-native-node-modules.md)
|
||||||
|
* [Depuração do processo principal](../../docs/tutorial/debugging-main-process.md)
|
||||||
|
* [Usando Selenium e WebDriver](../../docs/tutorial/using-selenium-and-webdriver.md)
|
||||||
|
* [Extensão DevTools](../../docs/tutorial/devtools-extension.md)
|
||||||
|
* [Usando o plugin papper flash](../../docs/tutorial/using-pepper-flash-plugin.md)
|
||||||
|
|
||||||
|
## Tutoriais
|
||||||
|
|
||||||
|
* [Introdução](../../docs/tutorial/quick-start.md)
|
||||||
|
* [A integração com o ambiente de desenvolvimento](../../docs/tutorial/desktop-environment-integration.md)
|
||||||
|
* [Evento de detecção on-line/off-line](../../docs/tutorial/online-offline-events.md)
|
||||||
|
|
||||||
|
## API - Referencias
|
||||||
|
|
||||||
|
* [Sinopse](../../docs/api/synopsis.md)
|
||||||
|
* [Processos](../../docs/api/process.md)
|
||||||
|
* [Parâmetros CLI suportados (Chrome)](../../docs/api/chrome-command-line-switches.md)
|
||||||
|
|
||||||
|
DOM elementos personalizados:
|
||||||
|
|
||||||
|
* [Objeto `File`](../../docs/api/file-object.md)
|
||||||
|
* [Tag `<webview>`](../../docs/api/web-view-tag.md)
|
||||||
|
* [Função `window.open`](../../docs/api/window-open.md)
|
||||||
|
|
||||||
|
Os principais módulos:
|
||||||
|
|
||||||
|
* [app](../../docs/api/app.md)
|
||||||
|
* [auto-updater](../../docs/api/auto-updater.md)
|
||||||
|
* [browser-window](../../docs/api/browser-window.md)
|
||||||
|
* [content-tracing](../../docs/api/content-tracing.md)
|
||||||
|
* [dialog](../../docs/api/dialog.md)
|
||||||
|
* [global-shortcut](../../docs/api/global-shortcut.md)
|
||||||
|
* [ipc (main process)](../../docs/api/ipc-main-process.md)
|
||||||
|
* [menu](../../docs/api/menu.md)
|
||||||
|
* [menu-item](../../docs/api/menu-item.md)
|
||||||
|
* [power-monitor](../../docs/api/power-monitor.md)
|
||||||
|
* [power-save-blocker](../../docs/api/power-save-blocker.md)
|
||||||
|
* [protocol](../../docs/api/protocol.md)
|
||||||
|
* [session](../../docs/api/session.md)
|
||||||
|
* [webContents](../../docs/api/web-contents.md)
|
||||||
|
* [tray](../../docs/api/tray.md)
|
||||||
|
|
||||||
|
Módulos do renderizador (web page):
|
||||||
|
|
||||||
|
* [ipc (renderer)](../../docs/api/ipc-renderer.md)
|
||||||
|
* [remote](../../docs/api/remote.md)
|
||||||
|
* [web-frame](../../docs/api/web-frame.md)
|
||||||
|
|
||||||
|
Módulos de ambos os processos:
|
||||||
|
|
||||||
|
* [clipboard](../../docs/api/clipboard.md)
|
||||||
|
* [crash-reporter](../../docs/api/crash-reporter.md)
|
||||||
|
* [native-image](../../docs/api/native-image.md)
|
||||||
|
* [screen](../../docs/api/screen.md)
|
||||||
|
* [shell](../../docs/api/shell.md)
|
||||||
|
|
||||||
|
## Desenvolvimento
|
||||||
|
|
||||||
|
* [Estilo de código](../../docs/development/coding-style.md)
|
||||||
|
* [Estrutura de diretórios padrão](../../docs/development/source-code-directory-structure.md)
|
||||||
|
* [Diferenças técnicas do NW.js (antigo node-webkit)](../../docs/development/atom-shell-vs-node-webkit.md)
|
||||||
|
* [Visão geral do build](../../docs/development/build-system-overview.md)
|
||||||
|
* [Instrução de build (Mac)](../../docs/development/build-instructions-osx.md)
|
||||||
|
* [Instrução de build (Windows)](../../docs/development/build-instructions-windows.md)
|
||||||
|
* [Instrução de build (Linux)](../../docs/development/build-instructions-linux.md)
|
||||||
|
* [Configurando um symbol server no debugger](../../docs/development/setting-up-symbol-server.md)
|
77
docs-translations/pt-BR/styleguide-pt-BR.md
Normal file
77
docs-translations/pt-BR/styleguide-pt-BR.md
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
# Styleguide do Electron
|
||||||
|
|
||||||
|
Localize a seção apropriada para a sua tarefa: [Lendo a documentação do Electron](#)
|
||||||
|
ou [Escrevendo documentação para o Electron](#).
|
||||||
|
|
||||||
|
## Escrevendo documentação para o Electron
|
||||||
|
|
||||||
|
Estas são as formas que escrevemos a documentação do Electron.
|
||||||
|
|
||||||
|
- No Máximo um `h1` por página.
|
||||||
|
- Usar `bash` ao invés de` cmd` em blocos de código (por causa do syntax highlighter).
|
||||||
|
- Títulos `h1` deve coincidir com o nome do objeto (i.e. `browser-window` →
|
||||||
|
`BrowserWindow`).
|
||||||
|
- Nomes de arquivos separados por hífen.
|
||||||
|
- Adicionar pelo menos uma descrição a cada frase.
|
||||||
|
- Métodos de cabeçalhos são envolto em `code`.
|
||||||
|
- Cabeçalhos de eventos são envolto em single 'quotation' marks.
|
||||||
|
- Não há listas com identação com mais de 2 níveis (por causa do markdown).
|
||||||
|
- Adicione títulos nas seções: Events, Class Methods e Instance Methods.
|
||||||
|
- Use 'will' ao invéis de 'would' ao descrever os resultados.
|
||||||
|
- Eventos e métodos são com cabeçalhos `h3`.
|
||||||
|
- Argumentos opcionais escritos como `function (required[, optional])`.
|
||||||
|
- Argumentos opcionais são indicados quando chamado na lista.
|
||||||
|
- Comprimento da linha é de 80 caracteres com colunas quebradas.
|
||||||
|
- Métodos específicos para uma plataforma são postos em itálico seguindo o cabeçalho do método.
|
||||||
|
- ```### `method(foo, bar)` _OS X_```
|
||||||
|
|
||||||
|
## Lendo a documentação do Electron
|
||||||
|
|
||||||
|
Aqui estão algumas dicas de como entender a sintaxe da documentacão do Electron.
|
||||||
|
|
||||||
|
### Métodos
|
||||||
|
|
||||||
|
Um exemplo de [method](https://developer.mozilla.org/en-US/docs/Glossary/Method)
|
||||||
|
documentação:
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
`methodName(required[, optional]))`
|
||||||
|
|
||||||
|
* `require` String, **required**
|
||||||
|
* `optional` Integer
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
O nome do método é seguido pelos seus argumentos. Argumentos opcionais são
|
||||||
|
simbolizada por colchetes que cercam o argumento opcional, bem como a vírgula
|
||||||
|
requerido se este argumento opcional segue outro argumento.
|
||||||
|
|
||||||
|
Abaixo o método é para obter informações detalhadas sobre cada um dos argumentos. O tipo
|
||||||
|
de argumento é simbolizada por qualquer um dos tipos mais comuns: [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [` Number`](https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript Referência/Global_Objects/Object), [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
|
||||||
|
ou um tipo personalizado como o de Electron [`webContent`](api/web-content.md).
|
||||||
|
|
||||||
|
### Eventos
|
||||||
|
|
||||||
|
Um exemplo de [evento](https://developer.mozilla.org/en-US/docs/Web/API/Event)
|
||||||
|
documentação:
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Event: 'wake-up'
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
* `time` String
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
O evento é uma cadeia que é utilizada após um `.on` em um método listner. Se ela retorna
|
||||||
|
-lhe um valor e seu tipo é observado abaixo. Se você quiser um método para esctuar e responder
|
||||||
|
crie algo parecido com o exemplo abaixo:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
Alarm.on('wake-up', function(time) {
|
||||||
|
console.log(time)
|
||||||
|
})
|
||||||
|
```
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
* [應用程式發布](tutorial/application-distribution.md)
|
* [應用程式發布](tutorial/application-distribution.md)
|
||||||
* [應用程式打包](tutorial/application-packaging.md)
|
* [應用程式打包](tutorial/application-packaging.md)
|
||||||
* [使用原生模組](tutorial/using-native-node-modules.md)
|
* [使用原生 node 模組](tutorial/using-native-node-modules.md)
|
||||||
* [Debug 主行程](tutorial/debugging-main-process.md)
|
* [主行程 Debug](tutorial/debugging-main-process.md)
|
||||||
* [使用 Selenium 和 WebDriver](tutorial/using-selenium-and-webdriver.md)
|
* [使用 Selenium 和 WebDriver](tutorial/using-selenium-and-webdriver.md)
|
||||||
* [DevTools 擴充](tutorial/devtools-extension.md)
|
* [DevTools 擴充](tutorial/devtools-extension.md)
|
||||||
* [使用 Pepper Flash 套件](tutorial/using-pepper-flash-plugin.md)
|
* [使用 Pepper Flash 套件](tutorial/using-pepper-flash-plugin.md)
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
客製的 DOM 元素:
|
客製的 DOM 元素:
|
||||||
|
|
||||||
* [`File`對象](api/file-object.md)
|
* [`File`物件](api/file-object.md)
|
||||||
* [`<webview>`物件](api/web-view-tag.md)
|
* [`<webview>`物件](api/web-view-tag.md)
|
||||||
* [`window.open`函數](api/window-open.md)
|
* [`window.open`函數](api/window-open.md)
|
||||||
|
|
||||||
|
|
69
docs-translations/zh-TW/api/ipc-main-process.md
Normal file
69
docs-translations/zh-TW/api/ipc-main-process.md
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
# ipc (主行程)
|
||||||
|
|
||||||
|
當在主行程裡使用 `ipc` 模組,這個模組負責處理來自渲染行程(網頁)的非同步與同步訊息。
|
||||||
|
來自渲染器的訊息將會被注入到這個模組裡。
|
||||||
|
|
||||||
|
## 傳送訊息
|
||||||
|
|
||||||
|
同樣的也可以透過主行程來傳送訊息到渲染行程,更多資訊請參考 [WebContents.send](browser-window.md#webcontentssendchannel-args)
|
||||||
|
|
||||||
|
- 當傳送一個訊息, 事件名稱為 `channel`
|
||||||
|
- 回覆同步訊息,你需要設定 `event.returnValue`
|
||||||
|
- 送出一個非同步訊息回給發送端,你可以使用 `event.sender.send(...)`
|
||||||
|
|
||||||
|
這裏是一個傳送和處理訊息的範例,在渲染行程與主行程之間:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// 在主行程裡
|
||||||
|
var ipc = require('ipc');
|
||||||
|
ipc.on('asynchronous-message', function(event, arg) {
|
||||||
|
console.log(arg); // 輸出 "ping"
|
||||||
|
event.sender.send('asynchronous-reply', 'pong');
|
||||||
|
});
|
||||||
|
|
||||||
|
ipc.on('synchronous-message', function(event, arg) {
|
||||||
|
console.log(arg); // 輸出 "ping"
|
||||||
|
event.returnValue = 'pong';
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// 在渲染行程裡 (網頁).
|
||||||
|
var ipc = require('ipc');
|
||||||
|
console.log(ipc.sendSync('synchronous-message', 'ping')); // 輸出 "pong"
|
||||||
|
|
||||||
|
ipc.on('asynchronous-reply', function(arg) {
|
||||||
|
console.log(arg); // 輸出 "pong"
|
||||||
|
});
|
||||||
|
ipc.send('asynchronous-message', 'ping');
|
||||||
|
```
|
||||||
|
|
||||||
|
## 聆聽訊息
|
||||||
|
|
||||||
|
`ipc` 模組擁有下列幾個方法去聆聽事件:
|
||||||
|
|
||||||
|
### `ipc.on(channel, callback)`
|
||||||
|
|
||||||
|
* `channel` String - 事件名稱
|
||||||
|
* `callback` Function
|
||||||
|
|
||||||
|
當一個事件發生 `callback` 會帶著 `event` 物件和一個訊息 `arg`
|
||||||
|
|
||||||
|
## IPC 事件
|
||||||
|
|
||||||
|
`event` 物件被傳入 `callback` 具有以下幾個方法:
|
||||||
|
|
||||||
|
### `Event.returnValue`
|
||||||
|
|
||||||
|
設定這個值可以回傳一個同步訊息
|
||||||
|
|
||||||
|
### `Event.sender`
|
||||||
|
|
||||||
|
回傳 `WebContents` 可以送出訊息
|
||||||
|
|
||||||
|
### `Event.sender.send(channel[, arg1][, arg2][, ...])`
|
||||||
|
|
||||||
|
* `channel` String - 事件名稱
|
||||||
|
* `arg` (選用)
|
||||||
|
|
||||||
|
此傳送訊息是非同步的訊息,至渲染行程,可以是一個一系列的參數 `arg` 可以是任何型態。
|
46
docs-translations/zh-TW/api/shell.md
Normal file
46
docs-translations/zh-TW/api/shell.md
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# shell
|
||||||
|
|
||||||
|
`shell` 模組提供一些整合桌面應用的功能。
|
||||||
|
|
||||||
|
|
||||||
|
一個範例示範如何利用使用者的預設瀏覽器開啟 URL:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var shell = require('shell');
|
||||||
|
|
||||||
|
shell.openExternal('https://github.com');
|
||||||
|
```
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
`shell` 模組有以下幾個方法:
|
||||||
|
|
||||||
|
### `shell.showItemInFolder(fullPath)`
|
||||||
|
|
||||||
|
* `fullPath` String
|
||||||
|
|
||||||
|
顯示在檔案管理中指定的檔案,如果可以的話,選擇該檔案。
|
||||||
|
|
||||||
|
### `shell.openItem(fullPath)`
|
||||||
|
|
||||||
|
* `fullPath` String
|
||||||
|
|
||||||
|
打開指定的檔案,在桌面的預設方式。
|
||||||
|
Open the given file in the desktop's default manner.
|
||||||
|
|
||||||
|
### `shell.openExternal(url)`
|
||||||
|
|
||||||
|
* `url` String
|
||||||
|
|
||||||
|
打開一個指定的外部協定 URL 在桌面的預設方式。(舉例來說 mailto: URLs 會打開使用者的預設信箱)
|
||||||
|
|
||||||
|
|
||||||
|
### `shell.moveItemToTrash(fullPath)`
|
||||||
|
|
||||||
|
* `fullPath` String
|
||||||
|
|
||||||
|
移動指定檔案至垃圾桶,並會對這個操作回傳一個 boolean 狀態
|
||||||
|
|
||||||
|
### `shell.beep()`
|
||||||
|
|
||||||
|
播放 beep 聲音。
|
|
@ -48,8 +48,6 @@ Properties `width` and `height` are required.
|
||||||
* `fullscreen` Boolean - Whether the window should show in fullscreen. When
|
* `fullscreen` Boolean - Whether the window should show in fullscreen. When
|
||||||
set to `false` the fullscreen button will also be hidden on OS X.
|
set to `false` the fullscreen button will also be hidden on OS X.
|
||||||
* `skip-taskbar` Boolean - Whether to show the window in taskbar.
|
* `skip-taskbar` Boolean - Whether to show the window in taskbar.
|
||||||
* `zoom-factor` Number - The default zoom factor of the page, `3.0` represents
|
|
||||||
`300%`.
|
|
||||||
* `kiosk` Boolean - The kiosk mode.
|
* `kiosk` Boolean - The kiosk mode.
|
||||||
* `title` String - Default window title.
|
* `title` String - Default window title.
|
||||||
* `icon` [NativeImage](native-image.md) - The window icon, when omitted on
|
* `icon` [NativeImage](native-image.md) - The window icon, when omitted on
|
||||||
|
@ -57,8 +55,6 @@ Properties `width` and `height` are required.
|
||||||
* `show` Boolean - Whether window should be shown when created.
|
* `show` Boolean - Whether window should be shown when created.
|
||||||
* `frame` Boolean - Specify `false` to create a
|
* `frame` Boolean - Specify `false` to create a
|
||||||
[Frameless Window](frameless-window.md).
|
[Frameless Window](frameless-window.md).
|
||||||
* `node-integration` Boolean - Whether node integration is enabled. Default
|
|
||||||
is `true`.
|
|
||||||
* `accept-first-mouse` Boolean - Whether the web view accepts a single
|
* `accept-first-mouse` Boolean - Whether the web view accepts a single
|
||||||
mouse-down event that simultaneously activates the window.
|
mouse-down event that simultaneously activates the window.
|
||||||
* `disable-auto-hide-cursor` Boolean - Whether to hide cursor when typing.
|
* `disable-auto-hide-cursor` Boolean - Whether to hide cursor when typing.
|
||||||
|
@ -68,10 +64,6 @@ Properties `width` and `height` are required.
|
||||||
than screen.
|
than screen.
|
||||||
* `dark-theme` Boolean - Forces using dark theme for the window, only works on
|
* `dark-theme` Boolean - Forces using dark theme for the window, only works on
|
||||||
some GTK+3 desktop environments.
|
some GTK+3 desktop environments.
|
||||||
* `preload` String - Specifies a script that will be loaded before other
|
|
||||||
scripts run in the window. This script will always have access to node APIs
|
|
||||||
no matter whether node integration is turned on for the window, and the path
|
|
||||||
of `preload` script has to be absolute path.
|
|
||||||
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
|
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
|
||||||
* `type` String - Specifies the type of the window, possible types are
|
* `type` String - Specifies the type of the window, possible types are
|
||||||
`desktop`, `dock`, `toolbar`, `splash`, `notification`. This only works on
|
`desktop`, `dock`, `toolbar`, `splash`, `notification`. This only works on
|
||||||
|
@ -79,11 +71,25 @@ Properties `width` and `height` are required.
|
||||||
* `standard-window` Boolean - Uses the OS X's standard window instead of the
|
* `standard-window` Boolean - Uses the OS X's standard window instead of the
|
||||||
textured window. Defaults to `true`.
|
textured window. Defaults to `true`.
|
||||||
* `web-preferences` Object - Settings of web page's features, properties:
|
* `web-preferences` Object - Settings of web page's features, properties:
|
||||||
|
* `node-integration` Boolean - Whether node integration is enabled. Default
|
||||||
|
is `true`.
|
||||||
|
* `preload` String - Specifies a script that will be loaded before other
|
||||||
|
scripts run in the page. This script will always have access to node APIs
|
||||||
|
no matter whether node integration is turned on for the page, and the path
|
||||||
|
of `preload` script has to be absolute path.
|
||||||
|
* `partition` String - Sets the session used by the page. If `partition`
|
||||||
|
starts with `persist:`, the page will use a persistent session available to
|
||||||
|
all pages in the app with the same `partition`. if there is no `persist:`
|
||||||
|
prefix, the page will use an in-memory session. By assigning the same
|
||||||
|
`partition`, multiple pages can share the same session. If the `partition`
|
||||||
|
is unset then default session of the app will be used.
|
||||||
|
* `zoom-factor` Number - The default zoom factor of the page, `3.0` represents
|
||||||
|
`300%`.
|
||||||
* `javascript` Boolean
|
* `javascript` Boolean
|
||||||
* `web-security` Boolean - When setting `false`, it will disable the
|
* `web-security` Boolean - When setting `false`, it will disable the
|
||||||
same-origin policy (Usually using testing websites by people), and set `allow_displaying_insecure_content`
|
same-origin policy (Usually using testing websites by people), and set
|
||||||
and `allow_running_insecure_content` to `true` if these two options are not
|
`allow_displaying_insecure_content` and `allow_running_insecure_content` to
|
||||||
set by user.
|
`true` if these two options are not set by user.
|
||||||
* `allow-displaying-insecure-content` Boolean - Allow an https page to display
|
* `allow-displaying-insecure-content` Boolean - Allow an https page to display
|
||||||
content like images from http URLs.
|
content like images from http URLs.
|
||||||
* `allow-running-insecure-content` Boolean - Allow a https page to run
|
* `allow-running-insecure-content` Boolean - Allow a https page to run
|
||||||
|
@ -93,13 +99,7 @@ Properties `width` and `height` are required.
|
||||||
* `text-areas-are-resizable` Boolean
|
* `text-areas-are-resizable` Boolean
|
||||||
* `webgl` Boolean
|
* `webgl` Boolean
|
||||||
* `webaudio` Boolean
|
* `webaudio` Boolean
|
||||||
* `plugins` Boolean - Whether plugins should be enabled, currently only
|
* `plugins` Boolean - Whether plugins should be enabled.
|
||||||
`NPAPI` plugins are supported.
|
|
||||||
* `extra-plugin-dirs` Array - Array of paths that would be searched for
|
|
||||||
plugins. Note that if you want to add a directory under your app, you
|
|
||||||
should use `__dirname` or `process.resourcesPath` to join the paths to
|
|
||||||
make them absolute, using relative paths would make Electron search
|
|
||||||
under current working directory.
|
|
||||||
* `experimental-features` Boolean
|
* `experimental-features` Boolean
|
||||||
* `experimental-canvas-features` Boolean
|
* `experimental-canvas-features` Boolean
|
||||||
* `subpixel-font-scaling` Boolean
|
* `subpixel-font-scaling` Boolean
|
||||||
|
|
|
@ -138,16 +138,16 @@ If "on", the guest page will have web security disabled.
|
||||||
<webview src="http://electron.atom.io" partition="electron"></webview>
|
<webview src="http://electron.atom.io" partition="electron"></webview>
|
||||||
```
|
```
|
||||||
|
|
||||||
Sets the storage partition used by the `webview`. If the storage partition ID starts with `persist:`,
|
Sets the session used by the page. If `partition` starts with `persist:`, the
|
||||||
the `webview` will use a persistent storage partition available to all `webview` in the app with
|
page will use a persistent session available to all pages in the app with the
|
||||||
the same storage partition ID. if there is no `persist:` prefix, the `webview` will
|
same `partition`. if there is no `persist:` prefix, the page will use an
|
||||||
use an in-memory storage partition. By assigning the same partition ID, multiple `webview`
|
in-memory session. By assigning the same `partition`, multiple pages can share
|
||||||
can share the same storage partition. If the storage partition ID is unset then default storage
|
the same session. If the `partition` is unset then default session of the app
|
||||||
of the app will be used.
|
will be used.
|
||||||
|
|
||||||
This value can only be modified before the first navigation, since the storage partition of an active
|
This value can only be modified before the first navigation, since the session
|
||||||
renderer process cannot change. Subsequent attempts to modify the value will fail with a
|
of an active renderer process cannot change. Subsequent attempts to modify the
|
||||||
DOM exception.
|
value will fail with a DOM exception.
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
|
|
|
@ -226,14 +226,16 @@
|
||||||
'atom/browser/ui/x/window_state_watcher.h',
|
'atom/browser/ui/x/window_state_watcher.h',
|
||||||
'atom/browser/ui/x/x_window_utils.cc',
|
'atom/browser/ui/x/x_window_utils.cc',
|
||||||
'atom/browser/ui/x/x_window_utils.h',
|
'atom/browser/ui/x/x_window_utils.h',
|
||||||
|
'atom/browser/web_contents_preferences.cc',
|
||||||
|
'atom/browser/web_contents_preferences.h',
|
||||||
|
'atom/browser/web_dialog_helper.cc',
|
||||||
|
'atom/browser/web_dialog_helper.h',
|
||||||
'atom/browser/web_view_constants.cc',
|
'atom/browser/web_view_constants.cc',
|
||||||
'atom/browser/web_view_constants.h',
|
'atom/browser/web_view_constants.h',
|
||||||
'atom/browser/web_view_guest_delegate.cc',
|
'atom/browser/web_view_guest_delegate.cc',
|
||||||
'atom/browser/web_view_guest_delegate.h',
|
'atom/browser/web_view_guest_delegate.h',
|
||||||
'atom/browser/web_view_manager.cc',
|
'atom/browser/web_view_manager.cc',
|
||||||
'atom/browser/web_view_manager.h',
|
'atom/browser/web_view_manager.h',
|
||||||
'atom/browser/web_dialog_helper.cc',
|
|
||||||
'atom/browser/web_dialog_helper.h',
|
|
||||||
'atom/browser/window_list.cc',
|
'atom/browser/window_list.cc',
|
||||||
'atom/browser/window_list.h',
|
'atom/browser/window_list.h',
|
||||||
'atom/browser/window_list_observer.h',
|
'atom/browser/window_list_observer.h',
|
||||||
|
|
|
@ -160,7 +160,7 @@ describe '<webview> tag', ->
|
||||||
assert.equal e.message, 'undefined undefined undefined undefined'
|
assert.equal e.message, 'undefined undefined undefined undefined'
|
||||||
done()
|
done()
|
||||||
webview.src = "file://#{fixtures}/pages/c.html"
|
webview.src = "file://#{fixtures}/pages/c.html"
|
||||||
webview.partition = "test"
|
webview.partition = 'test1'
|
||||||
document.body.appendChild webview
|
document.body.appendChild webview
|
||||||
|
|
||||||
it 'inserts node symbols when set', (done) ->
|
it 'inserts node symbols when set', (done) ->
|
||||||
|
@ -169,7 +169,7 @@ describe '<webview> tag', ->
|
||||||
done()
|
done()
|
||||||
webview.setAttribute 'nodeintegration', 'on'
|
webview.setAttribute 'nodeintegration', 'on'
|
||||||
webview.src = "file://#{fixtures}/pages/d.html"
|
webview.src = "file://#{fixtures}/pages/d.html"
|
||||||
webview.partition = "test"
|
webview.partition = 'test2'
|
||||||
document.body.appendChild webview
|
document.body.appendChild webview
|
||||||
|
|
||||||
it 'isolates storage for different id', (done) ->
|
it 'isolates storage for different id', (done) ->
|
||||||
|
@ -180,7 +180,7 @@ describe '<webview> tag', ->
|
||||||
window.localStorage.setItem 'test', 'one'
|
window.localStorage.setItem 'test', 'one'
|
||||||
webview.addEventListener 'console-message', listener
|
webview.addEventListener 'console-message', listener
|
||||||
webview.src = "file://#{fixtures}/pages/partition/one.html"
|
webview.src = "file://#{fixtures}/pages/partition/one.html"
|
||||||
webview.partition = "test"
|
webview.partition = 'test3'
|
||||||
document.body.appendChild webview
|
document.body.appendChild webview
|
||||||
|
|
||||||
it 'uses current session storage when no id is provided', (done) ->
|
it 'uses current session storage when no id is provided', (done) ->
|
||||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 4d8f5d879d484db54895c3456ded3a3d3246415d
|
Subproject commit 8d64120b51b48be46eaa419957b965c0ccfc6c8f
|
Loading…
Add table
Reference in a new issue