Merge pull request #2039 from atom/cleanup-web-contents-js
Some cleanup of WebContents and BrowserWindow code
This commit is contained in:
commit
3b762fddfb
18 changed files with 200 additions and 133 deletions
|
@ -46,18 +46,17 @@ bool GetCookieListFromStore(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunGetCookiesCallbackOnUIThread(const std::string& error_message,
|
void RunGetCookiesCallbackOnUIThread(v8::Isolate* isolate,
|
||||||
|
const std::string& error_message,
|
||||||
const net::CookieList& cookie_list,
|
const net::CookieList& cookie_list,
|
||||||
const Cookies::CookiesCallback& callback) {
|
const Cookies::CookiesCallback& callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
||||||
v8::Locker locker(isolate);
|
v8::Locker locker(isolate);
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
if (!error_message.empty()) {
|
if (!error_message.empty()) {
|
||||||
v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
|
v8::Local<v8::Value> error = mate::ConvertToV8(isolate, error_message);
|
||||||
error_message.c_str());
|
|
||||||
callback.Run(error, v8::Null(isolate));
|
callback.Run(error, v8::Null(isolate));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -65,17 +64,16 @@ void RunGetCookiesCallbackOnUIThread(const std::string& error_message,
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunRemoveCookiesCallbackOnUIThread(
|
void RunRemoveCookiesCallbackOnUIThread(
|
||||||
|
v8::Isolate* isolate,
|
||||||
const std::string& error_message,
|
const std::string& error_message,
|
||||||
const Cookies::CookiesCallback& callback) {
|
const Cookies::CookiesCallback& callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
||||||
v8::Locker locker(isolate);
|
v8::Locker locker(isolate);
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
if (!error_message.empty()) {
|
if (!error_message.empty()) {
|
||||||
v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
|
v8::Local<v8::Value> error = mate::ConvertToV8(isolate, error_message);
|
||||||
error_message.c_str());
|
|
||||||
callback.Run(error, v8::Null(isolate));
|
callback.Run(error, v8::Null(isolate));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -83,24 +81,23 @@ void RunRemoveCookiesCallbackOnUIThread(
|
||||||
callback.Run(v8::Null(isolate), v8::Null(isolate));
|
callback.Run(v8::Null(isolate), v8::Null(isolate));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunSetCookiesCallbackOnUIThread(const std::string& error_message,
|
void RunSetCookiesCallbackOnUIThread(v8::Isolate* isolate,
|
||||||
|
const std::string& error_message,
|
||||||
bool set_success,
|
bool set_success,
|
||||||
const Cookies::CookiesCallback& callback) {
|
const Cookies::CookiesCallback& callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
||||||
v8::Locker locker(isolate);
|
v8::Locker locker(isolate);
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
if (!error_message.empty()) {
|
if (!error_message.empty()) {
|
||||||
v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
|
v8::Local<v8::Value> error = mate::ConvertToV8(isolate, error_message);
|
||||||
error_message.c_str());
|
|
||||||
callback.Run(error, v8::Null(isolate));
|
callback.Run(error, v8::Null(isolate));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!set_success) {
|
if (!set_success) {
|
||||||
v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
|
v8::Local<v8::Value> error = mate::ConvertToV8(
|
||||||
"Failed to set cookies");
|
isolate, "Failed to set cookies");
|
||||||
callback.Run(error, v8::Null(isolate));
|
callback.Run(error, v8::Null(isolate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,8 +206,8 @@ void Cookies::GetCookiesOnIOThread(scoped_ptr<base::DictionaryValue> filter,
|
||||||
base::Bind(&Cookies::OnGetCookies, base::Unretained(this),
|
base::Bind(&Cookies::OnGetCookies, base::Unretained(this),
|
||||||
Passed(&filter), callback))) {
|
Passed(&filter), callback))) {
|
||||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&RunGetCookiesCallbackOnUIThread, "Url is not valid",
|
base::Bind(&RunGetCookiesCallbackOnUIThread, isolate(),
|
||||||
net::CookieList(), callback));
|
"Url is not valid", net::CookieList(), callback));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +220,7 @@ void Cookies::OnGetCookies(scoped_ptr<base::DictionaryValue> filter,
|
||||||
result.push_back(cookie);
|
result.push_back(cookie);
|
||||||
}
|
}
|
||||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
|
||||||
&RunGetCookiesCallbackOnUIThread, "", result, callback));
|
&RunGetCookiesCallbackOnUIThread, isolate(), "", result, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cookies::Remove(const mate::Dictionary& details,
|
void Cookies::Remove(const mate::Dictionary& details,
|
||||||
|
@ -238,7 +235,7 @@ void Cookies::Remove(const mate::Dictionary& details,
|
||||||
error_message = "Url is not valid.";
|
error_message = "Url is not valid.";
|
||||||
}
|
}
|
||||||
if (!error_message.empty()) {
|
if (!error_message.empty()) {
|
||||||
RunRemoveCookiesCallbackOnUIThread(error_message, callback);
|
RunRemoveCookiesCallbackOnUIThread(isolate(), error_message, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
content::BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
content::BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||||
|
@ -256,7 +253,7 @@ void Cookies::RemoveCookiesOnIOThread(const GURL& url, const std::string& name,
|
||||||
|
|
||||||
void Cookies::OnRemoveCookies(const CookiesCallback& callback) {
|
void Cookies::OnRemoveCookies(const CookiesCallback& callback) {
|
||||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&RunRemoveCookiesCallbackOnUIThread, "", callback));
|
base::Bind(&RunRemoveCookiesCallbackOnUIThread, isolate(), "", callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cookies::Set(const base::DictionaryValue& options,
|
void Cookies::Set(const base::DictionaryValue& options,
|
||||||
|
@ -273,7 +270,7 @@ void Cookies::Set(const base::DictionaryValue& options,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error_message.empty()) {
|
if (!error_message.empty()) {
|
||||||
RunSetCookiesCallbackOnUIThread(error_message, false, callback);
|
RunSetCookiesCallbackOnUIThread(isolate(), error_message, false, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +325,8 @@ void Cookies::SetCookiesOnIOThread(scoped_ptr<base::DictionaryValue> details,
|
||||||
void Cookies::OnSetCookies(const CookiesCallback& callback,
|
void Cookies::OnSetCookies(const CookiesCallback& callback,
|
||||||
bool set_success) {
|
bool set_success) {
|
||||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&RunSetCookiesCallbackOnUIThread, "", set_success, callback));
|
base::Bind(&RunSetCookiesCallbackOnUIThread, isolate(), "", set_success,
|
||||||
|
callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
mate::ObjectTemplateBuilder Cookies::GetObjectTemplateBuilder(
|
mate::ObjectTemplateBuilder Cookies::GetObjectTemplateBuilder(
|
||||||
|
|
|
@ -55,11 +55,10 @@ bool Menu::IsCommandIdVisible(int command_id) const {
|
||||||
|
|
||||||
bool Menu::GetAcceleratorForCommandId(int command_id,
|
bool Menu::GetAcceleratorForCommandId(int command_id,
|
||||||
ui::Accelerator* accelerator) {
|
ui::Accelerator* accelerator) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Locker locker(isolate());
|
||||||
v8::Locker locker(isolate);
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::HandleScope handle_scope(isolate);
|
|
||||||
v8::Local<v8::Value> val = get_accelerator_.Run(command_id);
|
v8::Local<v8::Value> val = get_accelerator_.Run(command_id);
|
||||||
return mate::ConvertFromV8(isolate, val, accelerator);
|
return mate::ConvertFromV8(isolate(), val, accelerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::ExecuteCommand(int command_id, int event_flags) {
|
void Menu::ExecuteCommand(int command_id, int event_flags) {
|
||||||
|
|
|
@ -67,9 +67,8 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
void GetJobTypeInUI() override {
|
void GetJobTypeInUI() override {
|
||||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Locker locker(registry_->isolate());
|
||||||
v8::Locker locker(isolate);
|
v8::HandleScope handle_scope(registry_->isolate());
|
||||||
v8::HandleScope handle_scope(isolate);
|
|
||||||
|
|
||||||
// Call the JS handler.
|
// Call the JS handler.
|
||||||
Protocol::JsProtocolHandler callback =
|
Protocol::JsProtocolHandler callback =
|
||||||
|
@ -85,7 +84,7 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
return;
|
return;
|
||||||
} else if (result->IsObject()) {
|
} else if (result->IsObject()) {
|
||||||
v8::Local<v8::Object> obj = result->ToObject();
|
v8::Local<v8::Object> obj = result->ToObject();
|
||||||
mate::Dictionary dict(isolate, obj);
|
mate::Dictionary dict(registry_->isolate(), obj);
|
||||||
std::string name = mate::V8ToString(obj->GetConstructorName());
|
std::string name = mate::V8ToString(obj->GetConstructorName());
|
||||||
if (name == "RequestStringJob") {
|
if (name == "RequestStringJob") {
|
||||||
std::string mime_type, charset, data;
|
std::string mime_type, charset, data;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#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/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
|
#include "atom/common/event_emitter_caller.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
#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"
|
||||||
|
@ -90,6 +91,22 @@ struct Converter<PrintSettings> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<WindowOpenDisposition> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
WindowOpenDisposition val) {
|
||||||
|
std::string disposition = "other";
|
||||||
|
switch (val) {
|
||||||
|
case CURRENT_TAB: disposition = "default"; break;
|
||||||
|
case NEW_FOREGROUND_TAB: disposition = "foreground-tab"; break;
|
||||||
|
case NEW_BACKGROUND_TAB: disposition = "background-tab"; break;
|
||||||
|
case NEW_POPUP: case NEW_WINDOW: disposition = "new-window"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return mate::ConvertToV8(isolate, disposition);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,10 +204,7 @@ bool WebContents::ShouldCreateWebContents(
|
||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
const std::string& partition_id,
|
const std::string& partition_id,
|
||||||
content::SessionStorageNamespace* session_storage_namespace) {
|
content::SessionStorageNamespace* session_storage_namespace) {
|
||||||
Emit("-new-window",
|
Emit("new-window", target_url, frame_name, NEW_FOREGROUND_TAB);
|
||||||
target_url,
|
|
||||||
frame_name,
|
|
||||||
static_cast<int>(NEW_FOREGROUND_TAB));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +216,7 @@ content::WebContents* WebContents::OpenURLFromTab(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
const content::OpenURLParams& params) {
|
const content::OpenURLParams& params) {
|
||||||
if (params.disposition != CURRENT_TAB) {
|
if (params.disposition != CURRENT_TAB) {
|
||||||
Emit("-new-window", params.url, "", static_cast<int>(params.disposition));
|
Emit("new-window", params.url, "", params.disposition);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,9 +250,17 @@ void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||||
Emit("render-view-deleted",
|
int process_id = render_view_host->GetProcess()->GetID();
|
||||||
render_view_host->GetProcess()->GetID(),
|
Emit("render-view-deleted", process_id);
|
||||||
render_view_host->GetRoutingID());
|
|
||||||
|
// process.emit('ATOM_BROWSER_RELEASE_RENDER_VIEW', processId);
|
||||||
|
// Tell the rpc server that a render view has been deleted and we need to
|
||||||
|
// release all objects owned by it.
|
||||||
|
v8::Locker locker(isolate());
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
node::Environment* env = node::Environment::GetCurrent(isolate());
|
||||||
|
mate::EmitEvent(isolate(), env->process_object(),
|
||||||
|
"ATOM_BROWSER_RELEASE_RENDER_VIEW", process_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
||||||
|
@ -299,9 +321,8 @@ void WebContents::DidStopLoading() {
|
||||||
|
|
||||||
void WebContents::DidGetResourceResponseStart(
|
void WebContents::DidGetResourceResponseStart(
|
||||||
const content::ResourceRequestDetails& details) {
|
const content::ResourceRequestDetails& details) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Locker locker(isolate());
|
||||||
v8::Locker locker(isolate);
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::HandleScope handle_scope(isolate);
|
|
||||||
base::DictionaryValue response_headers;
|
base::DictionaryValue response_headers;
|
||||||
|
|
||||||
net::HttpResponseHeaders* headers = details.headers.get();
|
net::HttpResponseHeaders* headers = details.headers.get();
|
||||||
|
@ -453,6 +474,14 @@ bool WebContents::IsAlive() const {
|
||||||
return web_contents() != NULL;
|
return web_contents() != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WebContents::GetID() const {
|
||||||
|
return web_contents()->GetRenderProcessHost()->GetID();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebContents::Equal(const WebContents* web_contents) const {
|
||||||
|
return GetID() == web_contents->GetID();
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||||
content::NavigationController::LoadURLParams params(url);
|
content::NavigationController::LoadURLParams params(url);
|
||||||
|
|
||||||
|
@ -506,14 +535,6 @@ void WebContents::GoToOffset(int offset) {
|
||||||
web_contents()->GetController().GoToOffset(offset);
|
web_contents()->GetController().GoToOffset(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebContents::GetRoutingID() const {
|
|
||||||
return web_contents()->GetRoutingID();
|
|
||||||
}
|
|
||||||
|
|
||||||
int WebContents::GetProcessID() const {
|
|
||||||
return web_contents()->GetRenderProcessHost()->GetID();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WebContents::IsCrashed() const {
|
bool WebContents::IsCrashed() const {
|
||||||
return web_contents()->IsCrashed();
|
return web_contents()->IsCrashed();
|
||||||
}
|
}
|
||||||
|
@ -745,18 +766,15 @@ void WebContents::SetAllowTransparency(bool allow) {
|
||||||
if (guest_opaque_ != allow)
|
if (guest_opaque_ != allow)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto render_view_host = web_contents()->GetRenderViewHost();
|
||||||
guest_opaque_ = !allow;
|
guest_opaque_ = !allow;
|
||||||
if (!web_contents()->GetRenderViewHost()->GetView())
|
if (!render_view_host->GetView())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (guest_opaque_) {
|
if (guest_opaque_) {
|
||||||
web_contents()
|
render_view_host->GetView()->SetBackgroundColorToDefault();
|
||||||
->GetRenderViewHost()
|
|
||||||
->GetView()
|
|
||||||
->SetBackgroundColorToDefault();
|
|
||||||
} else {
|
} else {
|
||||||
web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor(
|
render_view_host->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||||
SK_ColorTRANSPARENT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,6 +788,8 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
||||||
.SetMethod("destroy", &WebContents::Destroy)
|
.SetMethod("destroy", &WebContents::Destroy)
|
||||||
.SetMethod("isAlive", &WebContents::IsAlive)
|
.SetMethod("isAlive", &WebContents::IsAlive)
|
||||||
|
.SetMethod("getId", &WebContents::GetID)
|
||||||
|
.SetMethod("equal", &WebContents::Equal)
|
||||||
.SetMethod("_loadUrl", &WebContents::LoadURL)
|
.SetMethod("_loadUrl", &WebContents::LoadURL)
|
||||||
.SetMethod("getTitle", &WebContents::GetTitle)
|
.SetMethod("getTitle", &WebContents::GetTitle)
|
||||||
.SetMethod("isLoading", &WebContents::IsLoading)
|
.SetMethod("isLoading", &WebContents::IsLoading)
|
||||||
|
@ -779,8 +799,6 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
.SetMethod("_goBack", &WebContents::GoBack)
|
.SetMethod("_goBack", &WebContents::GoBack)
|
||||||
.SetMethod("_goForward", &WebContents::GoForward)
|
.SetMethod("_goForward", &WebContents::GoForward)
|
||||||
.SetMethod("_goToOffset", &WebContents::GoToOffset)
|
.SetMethod("_goToOffset", &WebContents::GoToOffset)
|
||||||
.SetMethod("getRoutingId", &WebContents::GetRoutingID)
|
|
||||||
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
|
||||||
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
||||||
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
|
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
|
||||||
.SetMethod("insertCSS", &WebContents::InsertCSS)
|
.SetMethod("insertCSS", &WebContents::InsertCSS)
|
||||||
|
|
|
@ -68,6 +68,8 @@ class WebContents : public mate::EventEmitter,
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
bool IsAlive() const;
|
bool IsAlive() const;
|
||||||
|
int GetID() const;
|
||||||
|
bool Equal(const WebContents* web_contents) const;
|
||||||
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
void LoadURL(const GURL& url, const mate::Dictionary& options);
|
||||||
base::string16 GetTitle() const;
|
base::string16 GetTitle() const;
|
||||||
bool IsLoading() const;
|
bool IsLoading() const;
|
||||||
|
@ -77,8 +79,6 @@ class WebContents : public mate::EventEmitter,
|
||||||
void GoBack();
|
void GoBack();
|
||||||
void GoForward();
|
void GoForward();
|
||||||
void GoToOffset(int offset);
|
void GoToOffset(int offset);
|
||||||
int GetRoutingID() const;
|
|
||||||
int GetProcessID() const;
|
|
||||||
bool IsCrashed() const;
|
bool IsCrashed() const;
|
||||||
void SetUserAgent(const std::string& user_agent);
|
void SetUserAgent(const std::string& user_agent);
|
||||||
void InsertCSS(const std::string& css);
|
void InsertCSS(const std::string& css);
|
||||||
|
|
|
@ -58,7 +58,7 @@ void Window::WillCreatePopupWindow(const base::string16& frame_name,
|
||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
const std::string& partition_id,
|
const std::string& partition_id,
|
||||||
WindowOpenDisposition disposition) {
|
WindowOpenDisposition disposition) {
|
||||||
Emit("-new-window", target_url, frame_name, static_cast<int>(disposition));
|
Emit("-new-window", target_url, frame_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::WillNavigate(bool* prevent_default, const GURL& url) {
|
void Window::WillNavigate(bool* prevent_default, const GURL& url) {
|
||||||
|
@ -142,20 +142,18 @@ void Window::OnDevToolsFocus() {
|
||||||
void Window::OnDevToolsOpened() {
|
void Window::OnDevToolsOpened() {
|
||||||
Emit("devtools-opened");
|
Emit("devtools-opened");
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Locker locker(isolate());
|
||||||
v8::Locker locker(isolate);
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::HandleScope handle_scope(isolate);
|
auto handle = WebContents::CreateFrom(isolate(),
|
||||||
auto handle =
|
window_->GetDevToolsWebContents());
|
||||||
WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
|
devtools_web_contents_.Reset(isolate(), handle.ToV8());
|
||||||
devtools_web_contents_.Reset(isolate, handle.ToV8());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OnDevToolsClosed() {
|
void Window::OnDevToolsClosed() {
|
||||||
Emit("devtools-closed");
|
Emit("devtools-closed");
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Locker locker(isolate());
|
||||||
v8::Locker locker(isolate);
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::HandleScope handle_scope(isolate);
|
|
||||||
devtools_web_contents_.Reset();
|
devtools_web_contents_.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
#include "native_mate/arguments.h"
|
#include "native_mate/arguments.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -38,11 +36,9 @@ v8::Local<v8::Object> CreateEventObject(v8::Isolate* isolate) {
|
||||||
EventEmitter::EventEmitter() {
|
EventEmitter::EventEmitter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventEmitter::CallEmit(v8::Isolate* isolate,
|
v8::Local<v8::Object> EventEmitter::CreateEvent(v8::Isolate* isolate,
|
||||||
const base::StringPiece& name,
|
|
||||||
content::WebContents* sender,
|
content::WebContents* sender,
|
||||||
IPC::Message* message,
|
IPC::Message* message) const {
|
||||||
ValueArray args) {
|
|
||||||
v8::Local<v8::Object> event;
|
v8::Local<v8::Object> event;
|
||||||
bool use_native_event = sender && message;
|
bool use_native_event = sender && message;
|
||||||
|
|
||||||
|
@ -53,16 +49,7 @@ bool EventEmitter::CallEmit(v8::Isolate* isolate,
|
||||||
} else {
|
} else {
|
||||||
event = CreateEventObject(isolate);
|
event = CreateEventObject(isolate);
|
||||||
}
|
}
|
||||||
|
return event;
|
||||||
// args = [name, event, args...];
|
|
||||||
args.insert(args.begin(), event);
|
|
||||||
args.insert(args.begin(), mate::StringToV8(isolate, name));
|
|
||||||
|
|
||||||
// this.emit.apply(this, args);
|
|
||||||
node::MakeCallback(isolate, GetWrapper(isolate), "emit", args.size(),
|
|
||||||
&args[0]);
|
|
||||||
|
|
||||||
return event->Get(StringToV8(isolate, "defaultPrevented"))->BooleanValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom/common/event_emitter_caller.h"
|
||||||
#include "native_mate/wrappable.h"
|
#include "native_mate/wrappable.h"
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
|
@ -39,21 +40,18 @@ class EventEmitter : public Wrappable {
|
||||||
content::WebContents* sender,
|
content::WebContents* sender,
|
||||||
IPC::Message* message,
|
IPC::Message* message,
|
||||||
const Args&... args) {
|
const Args&... args) {
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Locker locker(isolate());
|
||||||
v8::Locker locker(isolate);
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::Local<v8::Object> event = CreateEvent(isolate(), sender, message);
|
||||||
|
EmitEvent(isolate(), GetWrapper(isolate()), name, event, args...);
|
||||||
ValueArray converted = { ConvertToV8(isolate, args)... };
|
return event->Get(
|
||||||
return CallEmit(isolate, name, sender, message, converted);
|
StringToV8(isolate(), "defaultPrevented"))->BooleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Lower level implementations.
|
v8::Local<v8::Object> CreateEvent(v8::Isolate* isolate,
|
||||||
bool CallEmit(v8::Isolate* isolate,
|
|
||||||
const base::StringPiece& name,
|
|
||||||
content::WebContents* sender,
|
content::WebContents* sender,
|
||||||
IPC::Message* message,
|
IPC::Message* message) const;
|
||||||
ValueArray args);
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(EventEmitter);
|
DISALLOW_COPY_AND_ASSIGN(EventEmitter);
|
||||||
};
|
};
|
||||||
|
|
|
@ -79,8 +79,6 @@ BrowserWindow::getPageTitle = -> @webContents.getTitle()
|
||||||
BrowserWindow::isLoading = -> @webContents.isLoading()
|
BrowserWindow::isLoading = -> @webContents.isLoading()
|
||||||
BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()
|
BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()
|
||||||
BrowserWindow::stop = -> @webContents.stop()
|
BrowserWindow::stop = -> @webContents.stop()
|
||||||
BrowserWindow::getRoutingId = -> @webContents.getRoutingId()
|
|
||||||
BrowserWindow::getProcessId = -> @webContents.getProcessId()
|
|
||||||
BrowserWindow::isCrashed = -> @webContents.isCrashed()
|
BrowserWindow::isCrashed = -> @webContents.isCrashed()
|
||||||
BrowserWindow::executeJavaScriptInDevTools = (code) -> @devToolsWebContents?.executeJavaScript code
|
BrowserWindow::executeJavaScriptInDevTools = (code) -> @devToolsWebContents?.executeJavaScript code
|
||||||
BrowserWindow::openDevTools = -> @webContents.openDevTools.apply @webContents, arguments
|
BrowserWindow::openDevTools = -> @webContents.openDevTools.apply @webContents, arguments
|
||||||
|
|
|
@ -24,32 +24,12 @@ wrapWebContents = (webContents) ->
|
||||||
else
|
else
|
||||||
webContents.once 'did-finish-load', @_executeJavaScript.bind(this, code)
|
webContents.once 'did-finish-load', @_executeJavaScript.bind(this, code)
|
||||||
|
|
||||||
# The processId and routingId and identify a webContents.
|
|
||||||
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
|
|
||||||
webContents.equal = (other) -> @getId() is other.getId()
|
|
||||||
|
|
||||||
# The navigation controller.
|
# The navigation controller.
|
||||||
controller = new NavigationController(webContents)
|
controller = new NavigationController(webContents)
|
||||||
for name, method of NavigationController.prototype when method instanceof Function
|
for name, method of NavigationController.prototype when method instanceof Function
|
||||||
do (name, method) ->
|
do (name, method) ->
|
||||||
webContents[name] = -> method.apply controller, arguments
|
webContents[name] = -> method.apply controller, arguments
|
||||||
|
|
||||||
# Translate |disposition| to string for 'new-window' event.
|
|
||||||
webContents.on '-new-window', (args..., disposition) ->
|
|
||||||
disposition =
|
|
||||||
switch disposition
|
|
||||||
when 2 then 'default'
|
|
||||||
when 4 then 'foreground-tab'
|
|
||||||
when 5 then 'background-tab'
|
|
||||||
when 6, 7 then 'new-window'
|
|
||||||
else 'other'
|
|
||||||
@emit 'new-window', args..., disposition
|
|
||||||
|
|
||||||
# Tell the rpc server that a render view has been deleted and we need to
|
|
||||||
# release all objects owned by it.
|
|
||||||
webContents.on 'render-view-deleted', (event, processId, routingId) ->
|
|
||||||
process.emit 'ATOM_BROWSER_RELEASE_RENDER_VIEW', "#{processId}-#{routingId}"
|
|
||||||
|
|
||||||
# Dispatch IPC messages to the ipc module.
|
# Dispatch IPC messages to the ipc module.
|
||||||
webContents.on 'ipc-message', (event, packed) ->
|
webContents.on 'ipc-message', (event, packed) ->
|
||||||
[channel, args...] = packed
|
[channel, args...] = packed
|
||||||
|
@ -99,9 +79,7 @@ wrapWebContents = (webContents) ->
|
||||||
if options.printBackgrounds
|
if options.printBackgrounds
|
||||||
printingSetting.shouldPrintBackgrounds = options.printBackground
|
printingSetting.shouldPrintBackgrounds = options.printBackground
|
||||||
|
|
||||||
webContents._printToPDF printingSetting, callback
|
@_printToPDF printingSetting, callback
|
||||||
|
|
||||||
webContents
|
|
||||||
|
|
||||||
binding._setWrapWebContents wrapWebContents
|
binding._setWrapWebContents wrapWebContents
|
||||||
process.once 'exit', binding._clearWrapWebContents
|
process.once 'exit', binding._clearWrapWebContents
|
||||||
|
|
|
@ -41,7 +41,7 @@ createGuest = (embedder, url, frameName, options) ->
|
||||||
# Routed window.open messages.
|
# Routed window.open messages.
|
||||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
|
||||||
[url, frameName, options] = args
|
[url, frameName, options] = args
|
||||||
event.sender.emit '-new-window', event, url, frameName, 7
|
event.sender.emit 'new-window', event, url, frameName, 'new-window'
|
||||||
if event.sender.isGuest() or event.defaultPrevented
|
if event.sender.isGuest() or event.defaultPrevented
|
||||||
event.returnValue = null
|
event.returnValue = null
|
||||||
else
|
else
|
||||||
|
|
33
atom/common/event_emitter_caller.cc
Normal file
33
atom/common/event_emitter_caller.cc
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// 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/common/event_emitter_caller.h"
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
v8::Local<v8::Value> CallEmitWithArgs(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Object> obj,
|
||||||
|
ValueVector* args) {
|
||||||
|
v8::Local<v8::String> emit_name = StringToSymbol(isolate, "emit");
|
||||||
|
v8::Local<v8::Value> emit = obj->Get(emit_name);
|
||||||
|
if (emit.IsEmpty() || !emit->IsFunction()) {
|
||||||
|
isolate->ThrowException(v8::Exception::TypeError(
|
||||||
|
StringToV8(isolate, "\"emit\" is not a function")));
|
||||||
|
return v8::Undefined(isolate);
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::MaybeLocal<v8::Value> result = emit.As<v8::Function>()->Call(
|
||||||
|
isolate->GetCurrentContext(), obj, args->size(), &args->front());
|
||||||
|
if (result.IsEmpty()) {
|
||||||
|
return v8::Undefined(isolate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.ToLocalChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
} // namespace mate
|
53
atom/common/event_emitter_caller.h
Normal file
53
atom/common/event_emitter_caller.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_COMMON_EVENT_EMITTER_CALLER_H_
|
||||||
|
#define ATOM_COMMON_EVENT_EMITTER_CALLER_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "native_mate/converter.h"
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
using ValueVector = std::vector<v8::Local<v8::Value>>;
|
||||||
|
|
||||||
|
v8::Local<v8::Value> CallEmitWithArgs(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Object> obj,
|
||||||
|
ValueVector* args);
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
// obj.emit.apply(obj, name, args...);
|
||||||
|
// The caller is responsible of allocating a HandleScope.
|
||||||
|
template<typename StringType, typename... Args>
|
||||||
|
v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Object> obj,
|
||||||
|
const StringType& name,
|
||||||
|
const internal::ValueVector& args) {
|
||||||
|
internal::ValueVector concatenated_args = { StringToV8(isolate, name) };
|
||||||
|
concatenated_args.reserve(1 + args.size());
|
||||||
|
concatenated_args.insert(concatenated_args.end(), args.begin(), args.end());
|
||||||
|
return internal::CallEmitWithArgs(isolate, obj, &concatenated_args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// obj.emit(name, args...);
|
||||||
|
// The caller is responsible of allocating a HandleScope.
|
||||||
|
template<typename StringType, typename... Args>
|
||||||
|
v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Object> obj,
|
||||||
|
const StringType& name,
|
||||||
|
const Args&... args) {
|
||||||
|
internal::ValueVector converted_args = {
|
||||||
|
StringToV8(isolate, name),
|
||||||
|
ConvertToV8(isolate, args)...,
|
||||||
|
};
|
||||||
|
return internal::CallEmitWithArgs(isolate, obj, &converted_args);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mate
|
||||||
|
|
||||||
|
#endif // ATOM_COMMON_EVENT_EMITTER_CALLER_H_
|
|
@ -29,6 +29,12 @@ struct Converter<base::string16> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline v8::Local<v8::String> StringToV8(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
const base::string16& input) {
|
||||||
|
return ConvertToV8(isolate, input).As<v8::String>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_
|
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/common/atom_command_line.h"
|
#include "atom/common/atom_command_line.h"
|
||||||
|
#include "atom/common/event_emitter_caller.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/base_paths.h"
|
#include "base/base_paths.h"
|
||||||
|
@ -185,8 +186,7 @@ void NodeBindings::LoadEnvironment(node::Environment* env) {
|
||||||
if (node::use_debug_agent)
|
if (node::use_debug_agent)
|
||||||
node::EnableDebug(env);
|
node::EnableDebug(env);
|
||||||
|
|
||||||
v8::Local<v8::Value> msg = mate::StringToV8(env->isolate(), "loaded");
|
mate::EmitEvent(env->isolate(), env->process_object(), "loaded");
|
||||||
node::MakeCallback(env->isolate(), env->process_object(), "emit", 1, &msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBindings::PrepareMessageLoop() {
|
void NodeBindings::PrepareMessageLoop() {
|
||||||
|
|
|
@ -7,8 +7,11 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/common/api/api_messages.h"
|
// Put this before event_emitter_caller.h to have string16 support.
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
|
|
||||||
|
#include "atom/common/api/api_messages.h"
|
||||||
|
#include "atom/common/event_emitter_caller.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
#include "atom/renderer/atom_renderer_client.h"
|
#include "atom/renderer/atom_renderer_client.h"
|
||||||
|
@ -134,13 +137,10 @@ void AtomRenderViewObserver::OnBrowserMessage(const base::string16& channel,
|
||||||
v8::Local<v8::Context> context = frame->mainWorldScriptContext();
|
v8::Local<v8::Context> context = frame->mainWorldScriptContext();
|
||||||
v8::Context::Scope context_scope(context);
|
v8::Context::Scope context_scope(context);
|
||||||
|
|
||||||
std::vector<v8::Local<v8::Value>> arguments = ListValueToVector(
|
|
||||||
isolate, args);
|
|
||||||
arguments.insert(arguments.begin(), mate::ConvertToV8(isolate, channel));
|
|
||||||
|
|
||||||
v8::Local<v8::Object> ipc;
|
v8::Local<v8::Object> ipc;
|
||||||
if (GetIPCObject(isolate, context, &ipc))
|
if (GetIPCObject(isolate, context, &ipc)) {
|
||||||
node::MakeCallback(isolate, ipc, "emit", arguments.size(), &arguments[0]);
|
mate::EmitEvent(isolate, ipc, channel, ListValueToVector(isolate, args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -251,6 +251,8 @@
|
||||||
'atom/common/crash_reporter/win/crash_service_main.h',
|
'atom/common/crash_reporter/win/crash_service_main.h',
|
||||||
'atom/common/draggable_region.cc',
|
'atom/common/draggable_region.cc',
|
||||||
'atom/common/draggable_region.h',
|
'atom/common/draggable_region.h',
|
||||||
|
'atom/common/event_emitter_caller.cc',
|
||||||
|
'atom/common/event_emitter_caller.h',
|
||||||
'atom/common/google_api_key.h',
|
'atom/common/google_api_key.h',
|
||||||
'atom/common/linux/application_info.cc',
|
'atom/common/linux/application_info.cc',
|
||||||
'atom/common/native_mate_converters/accelerator_converter.cc',
|
'atom/common/native_mate_converters/accelerator_converter.cc',
|
||||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit ad207eeabb0185f74c017e70ca3411d522627ff0
|
Subproject commit cad1fa50a95ca4185c435846e4868d5bd6cc94df
|
Loading…
Reference in a new issue