2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-04-24 08:45:25 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
|
|
|
|
2015-04-25 04:43:52 +00:00
|
|
|
#include <set>
|
|
|
|
|
2015-06-16 09:23:29 +00:00
|
|
|
#include "atom/browser/api/atom_api_session.h"
|
2015-10-01 05:45:59 +00:00
|
|
|
#include "atom/browser/api/atom_api_window.h"
|
2015-05-11 06:40:40 +00:00
|
|
|
#include "atom/browser/atom_browser_client.h"
|
2014-10-23 06:04:13 +00:00
|
|
|
#include "atom/browser/atom_browser_context.h"
|
2015-06-18 09:01:23 +00:00
|
|
|
#include "atom/browser/atom_browser_main_parts.h"
|
2014-12-18 20:58:17 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
2015-09-04 16:44:22 +00:00
|
|
|
#include "atom/browser/web_contents_preferences.h"
|
2015-06-25 06:28:13 +00:00
|
|
|
#include "atom/browser/web_view_guest_delegate.h"
|
2014-04-25 05:10:16 +00:00
|
|
|
#include "atom/common/api/api_messages.h"
|
2015-08-07 11:34:00 +00:00
|
|
|
#include "atom/common/api/event_emitter_caller.h"
|
2015-09-18 03:06:38 +00:00
|
|
|
#include "atom/common/native_mate_converters/blink_converter.h"
|
2015-08-07 10:10:19 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2015-10-31 13:39:07 +00:00
|
|
|
#include "atom/common/native_mate_converters/content_converter.h"
|
2015-07-24 09:39:11 +00:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2014-10-24 06:37:14 +00:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2014-04-24 09:00:41 +00:00
|
|
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
2015-04-20 06:50:04 +00:00
|
|
|
#include "atom/common/native_mate_converters/image_converter.h"
|
2014-04-24 09:00:41 +00:00
|
|
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
2014-04-25 05:10:16 +00:00
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2015-05-21 21:22:52 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2014-04-25 08:13:16 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2014-11-03 14:12:56 +00:00
|
|
|
#include "brightray/browser/inspectable_web_contents.h"
|
2015-10-01 03:14:19 +00:00
|
|
|
#include "brightray/browser/inspectable_web_contents_view.h"
|
2015-06-13 13:23:45 +00:00
|
|
|
#include "chrome/browser/printing/print_view_manager_basic.h"
|
2015-06-09 05:07:40 +00:00
|
|
|
#include "chrome/browser/printing/print_preview_message_handler.h"
|
2015-08-31 09:19:19 +00:00
|
|
|
#include "content/common/view_messages.h"
|
2015-10-06 15:33:14 +00:00
|
|
|
#include "content/public/browser/browser_plugin_guest_manager.h"
|
2015-04-20 06:50:04 +00:00
|
|
|
#include "content/public/browser/favicon_status.h"
|
2015-09-18 06:20:31 +00:00
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
2014-12-09 22:38:43 +00:00
|
|
|
#include "content/public/browser/navigation_details.h"
|
2015-03-05 14:39:27 +00:00
|
|
|
#include "content/public/browser/navigation_entry.h"
|
2015-05-12 19:35:56 +00:00
|
|
|
#include "content/public/browser/plugin_service.h"
|
2014-07-28 07:29:51 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2014-04-24 09:00:41 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2014-04-25 02:34:40 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2015-09-18 06:20:31 +00:00
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2014-10-24 15:05:25 +00:00
|
|
|
#include "content/public/browser/resource_request_details.h"
|
2015-04-30 13:15:19 +00:00
|
|
|
#include "content/public/browser/service_worker_context.h"
|
|
|
|
#include "content/public/browser/storage_partition.h"
|
2014-10-24 12:20:56 +00:00
|
|
|
#include "content/public/browser/site_instance.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2015-11-02 15:28:45 +00:00
|
|
|
#include "content/public/common/context_menu_params.h"
|
2014-10-23 06:04:13 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
#include "native_mate/object_template_builder.h"
|
2015-05-21 21:22:52 +00:00
|
|
|
#include "net/http/http_response_headers.h"
|
2015-07-12 20:50:15 +00:00
|
|
|
#include "net/url_request/static_http_user_agent_settings.h"
|
2015-05-20 10:44:57 +00:00
|
|
|
#include "net/url_request/url_request_context.h"
|
2015-09-18 06:20:31 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebInputEvent.h"
|
2015-10-09 07:48:37 +00:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
|
2015-06-13 13:23:45 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct PrintSettings {
|
|
|
|
bool silent;
|
|
|
|
bool print_background;
|
|
|
|
};
|
|
|
|
|
2015-07-12 20:50:15 +00:00
|
|
|
void SetUserAgentInIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
2015-10-09 07:48:37 +00:00
|
|
|
std::string accept_lang,
|
2015-07-12 20:50:15 +00:00
|
|
|
std::string user_agent) {
|
|
|
|
getter->GetURLRequestContext()->set_http_user_agent_settings(
|
2015-10-09 07:48:37 +00:00
|
|
|
new net::StaticHttpUserAgentSettings(
|
|
|
|
net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang),
|
|
|
|
user_agent));
|
2015-07-12 20:50:15 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 15:33:14 +00:00
|
|
|
bool NotifyZoomLevelChanged(
|
|
|
|
double level, content::WebContents* guest_web_contents) {
|
|
|
|
guest_web_contents->SendToAllFrames(
|
|
|
|
new AtomViewMsg_SetZoomLevel(MSG_ROUTING_NONE, level));
|
|
|
|
|
|
|
|
// Return false to iterate over all guests.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-13 13:23:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-05-29 03:12:55 +00:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<>
|
2015-06-25 06:28:13 +00:00
|
|
|
struct Converter<atom::SetSizeParams> {
|
2015-05-29 03:12:55 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
2015-06-25 06:28:13 +00:00
|
|
|
atom::SetSizeParams* out) {
|
2015-05-29 03:12:55 +00:00
|
|
|
mate::Dictionary params;
|
|
|
|
if (!ConvertFromV8(isolate, val, ¶ms))
|
|
|
|
return false;
|
|
|
|
bool autosize;
|
|
|
|
if (params.Get("enableAutoSize", &autosize))
|
|
|
|
out->enable_auto_size.reset(new bool(true));
|
|
|
|
gfx::Size size;
|
|
|
|
if (params.Get("min", &size))
|
|
|
|
out->min_size.reset(new gfx::Size(size));
|
|
|
|
if (params.Get("max", &size))
|
|
|
|
out->max_size.reset(new gfx::Size(size));
|
2015-05-29 05:47:09 +00:00
|
|
|
if (params.Get("normal", &size))
|
2015-05-29 03:44:49 +00:00
|
|
|
out->normal_size.reset(new gfx::Size(size));
|
2015-05-29 03:12:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-13 13:23:45 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<PrintSettings> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
PrintSettings* out) {
|
|
|
|
mate::Dictionary dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
dict.Get("silent", &(out->silent));
|
|
|
|
dict.Get("printBackground", &(out->print_background));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-23 08:34:22 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-18 10:01:31 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<net::HttpResponseHeaders*> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
net::HttpResponseHeaders* headers) {
|
|
|
|
base::DictionaryValue response_headers;
|
|
|
|
if (headers) {
|
|
|
|
void* iter = nullptr;
|
|
|
|
std::string key;
|
|
|
|
std::string value;
|
|
|
|
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
|
|
|
|
key = base::StringToLowerASCII(key);
|
|
|
|
if (response_headers.HasKey(key)) {
|
|
|
|
base::ListValue* values = nullptr;
|
|
|
|
if (response_headers.GetList(key, &values))
|
|
|
|
values->AppendString(value);
|
|
|
|
} else {
|
|
|
|
scoped_ptr<base::ListValue> values(new base::ListValue());
|
|
|
|
values->AppendString(value);
|
|
|
|
response_headers.Set(key, values.Pass());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ConvertToV8(isolate, response_headers);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-14 04:41:31 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<content::SavePageType> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
|
|
|
content::SavePageType* out) {
|
|
|
|
std::string save_type;
|
|
|
|
if (!ConvertFromV8(isolate, val, &save_type))
|
|
|
|
return false;
|
2015-11-02 13:19:00 +00:00
|
|
|
save_type = base::StringToLowerASCII(save_type);
|
|
|
|
if (save_type == "htmlonly") {
|
2015-10-14 04:41:31 +00:00
|
|
|
*out = content::SAVE_PAGE_TYPE_AS_ONLY_HTML;
|
2015-11-02 13:19:00 +00:00
|
|
|
} else if (save_type == "htmlcomplete") {
|
2015-10-14 04:41:31 +00:00
|
|
|
*out = content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML;
|
2015-11-02 13:19:00 +00:00
|
|
|
} else if (save_type == "mhtml") {
|
2015-10-14 04:41:31 +00:00
|
|
|
*out = content::SAVE_PAGE_TYPE_AS_MHTML;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-29 03:12:55 +00:00
|
|
|
} // namespace mate
|
|
|
|
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2014-10-23 05:31:10 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
v8::Persistent<v8::ObjectTemplate> template_;
|
|
|
|
|
2015-09-18 10:01:31 +00:00
|
|
|
// The wrapWebContents function which is implemented in JavaScript
|
2015-06-05 09:01:17 +00:00
|
|
|
using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
|
|
|
WrapWebContentsCallback g_wrap_web_contents;
|
|
|
|
|
2015-04-30 13:15:19 +00:00
|
|
|
content::ServiceWorkerContext* GetServiceWorkerContext(
|
|
|
|
const content::WebContents* web_contents) {
|
|
|
|
auto context = web_contents->GetBrowserContext();
|
|
|
|
auto site_instance = web_contents->GetSiteInstance();
|
|
|
|
if (!context || !site_instance)
|
|
|
|
return nullptr;
|
|
|
|
|
2015-06-05 07:41:03 +00:00
|
|
|
auto storage_partition =
|
|
|
|
content::BrowserContext::GetStoragePartition(context, site_instance);
|
|
|
|
if (!storage_partition)
|
|
|
|
return nullptr;
|
2015-04-30 13:15:19 +00:00
|
|
|
|
|
|
|
return storage_partition->GetServiceWorkerContext();
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:31:10 +00:00
|
|
|
} // namespace
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
WebContents::WebContents(content::WebContents* web_contents)
|
2015-06-24 14:23:38 +00:00
|
|
|
: content::WebContentsObserver(web_contents),
|
2015-06-25 06:32:38 +00:00
|
|
|
type_(REMOTE) {
|
2015-06-24 07:37:04 +00:00
|
|
|
AttachAsUserData(web_contents);
|
2015-07-14 19:13:25 +00:00
|
|
|
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
2014-10-23 06:04:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 16:44:22 +00:00
|
|
|
WebContents::WebContents(v8::Isolate* isolate,
|
|
|
|
const mate::Dictionary& options) {
|
2015-09-05 14:39:48 +00:00
|
|
|
// Whether it is a guest WebContents.
|
2015-06-24 15:29:32 +00:00
|
|
|
bool is_guest = false;
|
|
|
|
options.Get("isGuest", &is_guest);
|
|
|
|
type_ = is_guest ? WEB_VIEW : BROWSER_WINDOW;
|
|
|
|
|
2015-09-05 14:39:48 +00:00
|
|
|
// Obtain the session.
|
|
|
|
std::string partition;
|
|
|
|
mate::Handle<api::Session> session;
|
|
|
|
if (options.Get("session", &session)) {
|
2015-09-06 01:22:32 +00:00
|
|
|
} else if (options.Get("partition", &partition) && !partition.empty()) {
|
2015-09-05 14:39:48 +00:00
|
|
|
bool in_memory = true;
|
2015-09-06 01:22:32 +00:00
|
|
|
if (base::StartsWith(partition, "persist:", base::CompareCase::SENSITIVE)) {
|
|
|
|
in_memory = false;
|
|
|
|
partition = partition.substr(8);
|
|
|
|
}
|
2015-09-05 14:39:48 +00:00
|
|
|
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());
|
|
|
|
|
2015-06-24 15:29:32 +00:00
|
|
|
content::WebContents* web_contents;
|
|
|
|
if (is_guest) {
|
2015-09-05 11:47:44 +00:00
|
|
|
content::SiteInstance* site_instance = content::SiteInstance::CreateForURL(
|
2015-09-05 14:39:48 +00:00
|
|
|
session->browser_context(), GURL("chrome-guest://fake-host"));
|
|
|
|
content::WebContents::CreateParams params(
|
|
|
|
session->browser_context(), site_instance);
|
2015-06-25 06:28:13 +00:00
|
|
|
guest_delegate_.reset(new WebViewGuestDelegate);
|
|
|
|
params.guest_delegate = guest_delegate_.get();
|
2015-06-24 15:29:32 +00:00
|
|
|
web_contents = content::WebContents::Create(params);
|
|
|
|
} else {
|
2015-09-05 14:39:48 +00:00
|
|
|
content::WebContents::CreateParams params(session->browser_context());
|
2015-06-24 15:29:32 +00:00
|
|
|
web_contents = content::WebContents::Create(params);
|
2015-06-24 14:14:46 +00:00
|
|
|
}
|
2015-06-09 07:50:20 +00:00
|
|
|
|
2015-06-24 15:29:32 +00:00
|
|
|
Observe(web_contents);
|
2015-06-24 07:37:04 +00:00
|
|
|
AttachAsUserData(web_contents);
|
2015-06-24 15:29:32 +00:00
|
|
|
InitWithWebContents(web_contents);
|
2015-06-05 07:01:51 +00:00
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
managed_web_contents()->GetView()->SetDelegate(this);
|
|
|
|
|
2015-09-22 13:56:56 +00:00
|
|
|
// Save the preferences in C++.
|
2015-11-11 02:32:25 +00:00
|
|
|
new WebContentsPreferences(web_contents, options);
|
2015-09-04 16:44:22 +00:00
|
|
|
|
2015-07-14 19:13:25 +00:00
|
|
|
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
|
|
|
|
2015-06-24 15:29:32 +00:00
|
|
|
if (is_guest) {
|
2015-06-25 06:28:13 +00:00
|
|
|
guest_delegate_->Initialize(this);
|
|
|
|
|
2015-06-24 15:29:32 +00:00
|
|
|
NativeWindow* owner_window = nullptr;
|
|
|
|
WebContents* embedder = nullptr;
|
|
|
|
if (options.Get("embedder", &embedder) && embedder) {
|
|
|
|
// New WebContents's owner_window is the embedder's owner_window.
|
|
|
|
auto relay = NativeWindowRelay::FromWebContents(embedder->web_contents());
|
|
|
|
if (relay)
|
|
|
|
owner_window = relay->window.get();
|
|
|
|
}
|
|
|
|
if (owner_window)
|
|
|
|
SetOwnerWindow(owner_window);
|
|
|
|
}
|
2014-10-23 06:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebContents::~WebContents() {
|
2014-10-23 09:54:52 +00:00
|
|
|
Destroy();
|
2014-04-24 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-25 02:01:19 +00:00
|
|
|
bool WebContents::AddMessageToConsole(content::WebContents* source,
|
|
|
|
int32 level,
|
|
|
|
const base::string16& message,
|
|
|
|
int32 line_no,
|
|
|
|
const base::string16& source_id) {
|
2015-06-25 03:07:23 +00:00
|
|
|
if (type_ == BROWSER_WINDOW) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
Emit("console-message", level, message, line_no, source_id);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-25 02:01:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-25 05:21:09 +00:00
|
|
|
bool WebContents::ShouldCreateWebContents(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
int route_id,
|
2015-03-10 22:54:21 +00:00
|
|
|
int main_frame_route_id,
|
2014-10-25 05:21:09 +00:00
|
|
|
WindowContainerType window_container_type,
|
2015-09-02 07:16:49 +00:00
|
|
|
const std::string& frame_name,
|
2014-10-25 05:21:09 +00:00
|
|
|
const GURL& target_url,
|
|
|
|
const std::string& partition_id,
|
|
|
|
content::SessionStorageNamespace* session_storage_namespace) {
|
2015-06-25 03:07:23 +00:00
|
|
|
if (type_ == BROWSER_WINDOW)
|
|
|
|
Emit("-new-window", target_url, frame_name, NEW_FOREGROUND_TAB);
|
|
|
|
else
|
|
|
|
Emit("new-window", target_url, frame_name, NEW_FOREGROUND_TAB);
|
2014-10-25 05:21:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-24 10:06:32 +00:00
|
|
|
content::WebContents* WebContents::OpenURLFromTab(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::OpenURLParams& params) {
|
2014-11-04 09:59:15 +00:00
|
|
|
if (params.disposition != CURRENT_TAB) {
|
2015-06-25 03:07:23 +00:00
|
|
|
if (type_ == BROWSER_WINDOW)
|
|
|
|
Emit("-new-window", params.url, "", params.disposition);
|
|
|
|
else
|
|
|
|
Emit("new-window", params.url, "", params.disposition);
|
2014-12-17 22:55:22 +00:00
|
|
|
return nullptr;
|
2014-11-04 09:59:15 +00:00
|
|
|
}
|
2014-10-24 10:06:32 +00:00
|
|
|
|
2014-12-17 22:55:22 +00:00
|
|
|
// Give user a chance to cancel navigation.
|
2015-01-15 01:51:54 +00:00
|
|
|
if (Emit("will-navigate", params.url))
|
2014-12-17 22:55:22 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2015-06-05 09:45:17 +00:00
|
|
|
return CommonWebContentsDelegate::OpenURLFromTab(source, params);
|
2014-10-24 10:06:32 +00:00
|
|
|
}
|
|
|
|
|
2015-06-25 03:07:23 +00:00
|
|
|
void WebContents::BeforeUnloadFired(content::WebContents* tab,
|
|
|
|
bool proceed,
|
|
|
|
bool* proceed_to_fire_unload) {
|
|
|
|
if (type_ == BROWSER_WINDOW)
|
|
|
|
*proceed_to_fire_unload = proceed;
|
|
|
|
else
|
|
|
|
*proceed_to_fire_unload = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::MoveContents(content::WebContents* source,
|
|
|
|
const gfx::Rect& pos) {
|
|
|
|
Emit("move", pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::CloseContents(content::WebContents* source) {
|
2015-07-10 02:38:15 +00:00
|
|
|
Emit("close");
|
2015-06-25 03:07:23 +00:00
|
|
|
if (type_ == BROWSER_WINDOW)
|
|
|
|
owner_window()->CloseContents(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::ActivateContents(content::WebContents* source) {
|
2015-06-25 05:18:36 +00:00
|
|
|
Emit("activate");
|
2015-06-25 03:07:23 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 14:23:38 +00:00
|
|
|
bool WebContents::IsPopupOrPanel(const content::WebContents* source) const {
|
|
|
|
return type_ == BROWSER_WINDOW;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:46:47 +00:00
|
|
|
void WebContents::HandleKeyboardEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
2015-08-18 17:02:34 +00:00
|
|
|
if (event.windowsKeyCode == ui::VKEY_ESCAPE && is_html_fullscreen()) {
|
|
|
|
// Escape exits tabbed fullscreen mode.
|
|
|
|
ExitFullscreenModeForTab(source);
|
|
|
|
} else if (type_ == BROWSER_WINDOW) {
|
2015-06-25 03:07:23 +00:00
|
|
|
owner_window()->HandleKeyboardEvent(source, event);
|
2015-06-25 06:28:13 +00:00
|
|
|
} else if (type_ == WEB_VIEW && guest_delegate_) {
|
2015-06-25 03:07:23 +00:00
|
|
|
// Send the unhandled keyboard events back to the embedder.
|
2015-06-25 06:28:13 +00:00
|
|
|
guest_delegate_->HandleKeyboardEvent(source, event);
|
2015-06-25 03:07:23 +00:00
|
|
|
}
|
2014-10-24 13:46:47 +00:00
|
|
|
}
|
|
|
|
|
2015-05-09 12:17:40 +00:00
|
|
|
void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
|
2015-05-08 06:18:15 +00:00
|
|
|
const GURL& origin) {
|
2015-06-05 09:27:24 +00:00
|
|
|
CommonWebContentsDelegate::EnterFullscreenModeForTab(source, origin);
|
|
|
|
Emit("enter-html-full-screen");
|
2015-05-08 06:18:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-09 12:17:40 +00:00
|
|
|
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
2015-06-05 09:27:24 +00:00
|
|
|
CommonWebContentsDelegate::ExitFullscreenModeForTab(source);
|
|
|
|
Emit("leave-html-full-screen");
|
2015-05-08 06:18:15 +00:00
|
|
|
}
|
|
|
|
|
2015-06-25 03:07:23 +00:00
|
|
|
void WebContents::RendererUnresponsive(content::WebContents* source) {
|
|
|
|
Emit("unresponsive");
|
|
|
|
if (type_ == BROWSER_WINDOW)
|
|
|
|
owner_window()->RendererUnresponsive(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::RendererResponsive(content::WebContents* source) {
|
|
|
|
Emit("responsive");
|
|
|
|
if (type_ == BROWSER_WINDOW)
|
|
|
|
owner_window()->RendererResponsive(source);
|
|
|
|
}
|
|
|
|
|
2015-10-31 13:39:07 +00:00
|
|
|
bool WebContents::HandleContextMenu(const content::ContextMenuParams& params) {
|
2015-11-02 15:28:45 +00:00
|
|
|
if (!params.custom_context.is_pepper_menu)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Emit("pepper-context-menu", std::make_pair(params, web_contents()));
|
|
|
|
web_contents()->NotifyContextMenuClosed(params.custom_context);
|
2015-10-31 13:39:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-25 03:07:23 +00:00
|
|
|
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
|
|
|
// Do nothing, we override this method just to avoid compilation error since
|
|
|
|
// there are two virtual functions named BeforeUnloadFired.
|
|
|
|
}
|
|
|
|
|
2014-04-25 04:40:04 +00:00
|
|
|
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
2015-06-23 13:27:50 +00:00
|
|
|
int process_id = render_view_host->GetProcess()->GetID();
|
|
|
|
Emit("render-view-deleted", process_id);
|
|
|
|
|
|
|
|
// 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);
|
2014-04-25 03:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
|
|
|
Emit("crashed");
|
|
|
|
}
|
|
|
|
|
2015-05-12 19:35:56 +00:00
|
|
|
void WebContents::PluginCrashed(const base::FilePath& plugin_path,
|
|
|
|
base::ProcessId plugin_pid) {
|
|
|
|
content::WebPluginInfo info;
|
|
|
|
auto plugin_service = content::PluginService::GetInstance();
|
|
|
|
plugin_service->GetPluginInfoByPath(plugin_path, &info);
|
|
|
|
Emit("plugin-crashed", info.name, info.version);
|
|
|
|
}
|
|
|
|
|
2015-04-29 13:49:31 +00:00
|
|
|
void WebContents::DocumentLoadedInFrame(
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
if (!render_frame_host->GetParent())
|
|
|
|
Emit("dom-ready");
|
|
|
|
}
|
|
|
|
|
2014-10-11 11:11:34 +00:00
|
|
|
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url) {
|
|
|
|
bool is_main_frame = !render_frame_host->GetParent();
|
2015-01-15 01:51:54 +00:00
|
|
|
Emit("did-frame-finish-load", is_main_frame);
|
2014-06-09 04:03:19 +00:00
|
|
|
|
|
|
|
if (is_main_frame)
|
|
|
|
Emit("did-finish-load");
|
2014-04-25 04:22:16 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 03:28:30 +00:00
|
|
|
void WebContents::DidFailProvisionalLoad(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
2015-12-01 08:55:52 +00:00
|
|
|
const GURL& url,
|
2015-03-14 03:28:30 +00:00
|
|
|
int error_code,
|
2015-09-02 07:16:49 +00:00
|
|
|
const base::string16& error_description,
|
|
|
|
bool was_ignored_by_handler) {
|
2015-12-01 08:55:52 +00:00
|
|
|
Emit("did-fail-provisional-load", error_code, error_description, url);
|
2015-03-14 03:28:30 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 15:05:25 +00:00
|
|
|
void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url,
|
|
|
|
int error_code,
|
2015-09-02 07:16:49 +00:00
|
|
|
const base::string16& error_description,
|
|
|
|
bool was_ignored_by_handler) {
|
2015-08-31 09:18:10 +00:00
|
|
|
Emit("did-fail-load", error_code, error_description, validated_url);
|
2014-10-24 15:05:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 07:24:34 +00:00
|
|
|
void WebContents::DidStartLoading() {
|
2014-04-25 04:22:16 +00:00
|
|
|
Emit("did-start-loading");
|
|
|
|
}
|
|
|
|
|
2015-05-22 07:24:34 +00:00
|
|
|
void WebContents::DidStopLoading() {
|
2014-04-25 04:22:16 +00:00
|
|
|
Emit("did-stop-loading");
|
|
|
|
}
|
|
|
|
|
2015-04-08 13:44:47 +00:00
|
|
|
void WebContents::DidGetResourceResponseStart(
|
|
|
|
const content::ResourceRequestDetails& details) {
|
|
|
|
Emit("did-get-response-details",
|
|
|
|
details.socket_address.IsEmpty(),
|
|
|
|
details.url,
|
|
|
|
details.original_url,
|
|
|
|
details.http_response_code,
|
|
|
|
details.method,
|
2015-05-20 15:54:59 +00:00
|
|
|
details.referrer,
|
2015-09-18 10:01:31 +00:00
|
|
|
details.headers.get());
|
2015-04-08 13:44:47 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 15:05:25 +00:00
|
|
|
void WebContents::DidGetRedirectForResourceRequest(
|
2015-03-10 22:54:21 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2014-10-24 15:05:25 +00:00
|
|
|
const content::ResourceRedirectDetails& details) {
|
2015-01-15 01:51:54 +00:00
|
|
|
Emit("did-get-redirect-request",
|
|
|
|
details.url,
|
|
|
|
details.new_url,
|
2015-09-18 10:01:31 +00:00
|
|
|
(details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME),
|
|
|
|
details.http_response_code,
|
|
|
|
details.method,
|
|
|
|
details.referrer,
|
|
|
|
details.headers.get());
|
2014-10-24 15:05:25 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 22:38:43 +00:00
|
|
|
void WebContents::DidNavigateMainFrame(
|
|
|
|
const content::LoadCommittedDetails& details,
|
|
|
|
const content::FrameNavigateParams& params) {
|
|
|
|
if (details.is_navigation_to_different_page())
|
|
|
|
Emit("did-navigate-to-different-page");
|
|
|
|
}
|
|
|
|
|
2015-04-05 09:20:42 +00:00
|
|
|
void WebContents::TitleWasSet(content::NavigationEntry* entry,
|
|
|
|
bool explicit_set) {
|
2015-04-29 03:27:49 +00:00
|
|
|
if (entry)
|
2015-12-01 10:50:56 +00:00
|
|
|
Emit("-page-title-updated", entry->GetTitle(), explicit_set);
|
2015-12-01 09:52:13 +00:00
|
|
|
else
|
2015-12-01 10:50:56 +00:00
|
|
|
Emit("-page-title-updated", "", explicit_set);
|
2015-04-05 09:20:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 19:55:31 +00:00
|
|
|
void WebContents::DidUpdateFaviconURL(
|
|
|
|
const std::vector<content::FaviconURL>& urls) {
|
|
|
|
std::set<GURL> unique_urls;
|
|
|
|
for (auto iter = urls.begin(); iter != urls.end(); ++iter) {
|
|
|
|
if (iter->icon_type != content::FaviconURL::FAVICON)
|
|
|
|
continue;
|
|
|
|
const GURL& url = iter->icon_url;
|
|
|
|
if (url.is_valid())
|
|
|
|
unique_urls.insert(url);
|
|
|
|
}
|
2015-04-20 06:50:04 +00:00
|
|
|
Emit("page-favicon-updated", unique_urls);
|
2015-04-17 19:55:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
void WebContents::DevToolsFocused() {
|
|
|
|
Emit("devtools-focused");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::DevToolsOpened() {
|
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
auto handle = WebContents::CreateFrom(
|
|
|
|
isolate(), managed_web_contents()->GetDevToolsWebContents());
|
|
|
|
devtools_web_contents_.Reset(isolate(), handle.ToV8());
|
|
|
|
|
2015-10-01 06:41:01 +00:00
|
|
|
// Inherit owner window in devtools.
|
|
|
|
if (owner_window())
|
|
|
|
handle->SetOwnerWindow(managed_web_contents()->GetDevToolsWebContents(),
|
|
|
|
owner_window());
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
Emit("devtools-opened");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::DevToolsClosed() {
|
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
devtools_web_contents_.Reset();
|
|
|
|
|
|
|
|
Emit("devtools-closed");
|
|
|
|
}
|
|
|
|
|
2014-04-25 08:13:16 +00:00
|
|
|
bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
|
|
|
bool handled = true;
|
|
|
|
IPC_BEGIN_MESSAGE_MAP(WebContents, message)
|
|
|
|
IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message, OnRendererMessage)
|
|
|
|
IPC_MESSAGE_HANDLER_DELAY_REPLY(AtomViewHostMsg_Message_Sync,
|
|
|
|
OnRendererMessageSync)
|
2015-10-06 15:33:14 +00:00
|
|
|
IPC_MESSAGE_HANDLER(AtomViewHostMsg_ZoomLevelChanged, OnZoomLevelChanged)
|
2014-04-25 08:13:16 +00:00
|
|
|
IPC_MESSAGE_UNHANDLED(handled = false)
|
|
|
|
IPC_END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2014-07-28 07:29:51 +00:00
|
|
|
void WebContents::WebContentsDestroyed() {
|
2014-04-25 05:10:16 +00:00
|
|
|
// The RenderViewDeleted was not called when the WebContents is destroyed.
|
2014-10-23 06:04:13 +00:00
|
|
|
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
2014-04-25 03:59:33 +00:00
|
|
|
Emit("destroyed");
|
2015-06-24 09:58:12 +00:00
|
|
|
RemoveFromWeakMap();
|
2014-04-25 03:22:51 +00:00
|
|
|
}
|
|
|
|
|
2015-03-05 14:39:27 +00:00
|
|
|
void WebContents::NavigationEntryCommitted(
|
2015-05-11 05:51:52 +00:00
|
|
|
const content::LoadCommittedDetails& details) {
|
|
|
|
Emit("navigation-entry-commited", details.entry->GetURL(),
|
|
|
|
details.is_in_page, details.did_replace_entry);
|
2015-03-05 14:39:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
void WebContents::Destroy() {
|
2015-09-05 14:39:48 +00:00
|
|
|
session_.Reset();
|
2015-06-24 14:23:38 +00:00
|
|
|
if (type_ == WEB_VIEW && managed_web_contents()) {
|
2014-12-18 04:44:15 +00:00
|
|
|
// When force destroying the "destroyed" event is not emitted.
|
|
|
|
WebContentsDestroyed();
|
|
|
|
|
2015-06-25 06:28:13 +00:00
|
|
|
guest_delegate_->Destroy();
|
2015-05-22 07:24:34 +00:00
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
Observe(nullptr);
|
2015-06-05 07:01:51 +00:00
|
|
|
DestroyWebContents();
|
2014-10-23 06:04:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 08:16:10 +00:00
|
|
|
int WebContents::GetID() const {
|
|
|
|
return web_contents()->GetRenderProcessHost()->GetID();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContents::Equal(const WebContents* web_contents) const {
|
|
|
|
return GetID() == web_contents->GetID();
|
|
|
|
}
|
|
|
|
|
2014-11-06 19:29:41 +00:00
|
|
|
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
2014-04-25 04:52:30 +00:00
|
|
|
content::NavigationController::LoadURLParams params(url);
|
2014-11-06 19:29:41 +00:00
|
|
|
|
2014-11-12 02:28:50 +00:00
|
|
|
GURL http_referrer;
|
2015-06-09 01:27:57 +00:00
|
|
|
if (options.Get("httpReferrer", &http_referrer))
|
2014-11-12 02:28:50 +00:00
|
|
|
params.referrer = content::Referrer(http_referrer.GetAsReferrer(),
|
|
|
|
blink::WebReferrerPolicyDefault);
|
2014-11-06 19:29:41 +00:00
|
|
|
|
2015-05-06 04:01:41 +00:00
|
|
|
std::string user_agent;
|
2015-06-09 01:27:57 +00:00
|
|
|
if (options.Get("userAgent", &user_agent))
|
2015-05-06 21:21:43 +00:00
|
|
|
SetUserAgent(user_agent);
|
2015-05-06 04:01:41 +00:00
|
|
|
|
2015-10-26 21:18:16 +00:00
|
|
|
std::string extra_headers;
|
|
|
|
if (options.Get("extraHeaders", &extra_headers))
|
|
|
|
params.extra_headers = extra_headers;
|
|
|
|
|
2014-12-07 15:43:26 +00:00
|
|
|
params.transition_type = ui::PAGE_TRANSITION_TYPED;
|
2015-04-26 13:31:48 +00:00
|
|
|
params.should_clear_history_list = true;
|
2014-04-25 04:52:30 +00:00
|
|
|
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
2014-04-25 05:10:16 +00:00
|
|
|
web_contents()->GetController().LoadURLWithParams(params);
|
2014-04-25 04:52:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 01:17:45 +00:00
|
|
|
GURL WebContents::GetURL() const {
|
|
|
|
return web_contents()->GetURL();
|
|
|
|
}
|
|
|
|
|
2014-06-28 11:36:57 +00:00
|
|
|
base::string16 WebContents::GetTitle() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
return web_contents()->GetTitle();
|
2014-04-24 09:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContents::IsLoading() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
return web_contents()->IsLoading();
|
2014-04-24 09:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContents::IsWaitingForResponse() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
return web_contents()->IsWaitingForResponse();
|
2014-04-24 09:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::Stop() {
|
2014-04-25 05:10:16 +00:00
|
|
|
web_contents()->Stop();
|
2014-04-24 09:00:41 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 06:30:26 +00:00
|
|
|
void WebContents::GoBack() {
|
2015-05-11 06:40:40 +00:00
|
|
|
atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
|
2015-05-11 06:30:26 +00:00
|
|
|
web_contents()->GetController().GoBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::GoForward() {
|
2015-05-11 06:40:40 +00:00
|
|
|
atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
|
2015-05-11 06:30:26 +00:00
|
|
|
web_contents()->GetController().GoForward();
|
|
|
|
}
|
|
|
|
|
2015-05-11 08:44:01 +00:00
|
|
|
void WebContents::GoToOffset(int offset) {
|
|
|
|
atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
|
|
|
|
web_contents()->GetController().GoToOffset(offset);
|
|
|
|
}
|
|
|
|
|
2014-04-24 09:00:41 +00:00
|
|
|
bool WebContents::IsCrashed() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
return web_contents()->IsCrashed();
|
2014-04-24 09:00:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 12:57:44 +00:00
|
|
|
void WebContents::SetUserAgent(const std::string& user_agent) {
|
|
|
|
web_contents()->SetUserAgentOverride(user_agent);
|
2015-07-12 20:50:15 +00:00
|
|
|
scoped_refptr<net::URLRequestContextGetter> getter =
|
|
|
|
web_contents()->GetBrowserContext()->GetRequestContext();
|
2015-10-09 07:48:37 +00:00
|
|
|
|
|
|
|
auto accept_lang = l10n_util::GetApplicationLocale("");
|
2015-07-12 20:50:15 +00:00
|
|
|
getter->GetNetworkTaskRunner()->PostTask(FROM_HERE,
|
2015-10-09 07:48:37 +00:00
|
|
|
base::Bind(&SetUserAgentInIO, getter, accept_lang, user_agent));
|
2014-10-24 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 04:25:10 +00:00
|
|
|
std::string WebContents::GetUserAgent() {
|
|
|
|
return web_contents()->GetUserAgentOverride();
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:04:50 +00:00
|
|
|
void WebContents::InsertCSS(const std::string& css) {
|
|
|
|
web_contents()->InsertCSS(css);
|
|
|
|
}
|
|
|
|
|
2015-10-14 04:41:31 +00:00
|
|
|
bool WebContents::SavePage(const base::FilePath& full_file_path,
|
|
|
|
const content::SavePageType& save_type,
|
|
|
|
const SavePageHandler::SavePageCallback& callback) {
|
|
|
|
auto handler = new SavePageHandler(web_contents(), callback);
|
|
|
|
return handler->Handle(full_file_path, save_type);
|
|
|
|
}
|
|
|
|
|
2015-07-30 09:12:03 +00:00
|
|
|
void WebContents::ExecuteJavaScript(const base::string16& code,
|
|
|
|
bool has_user_gesture) {
|
|
|
|
Send(new AtomViewMsg_ExecuteJavaScript(routing_id(), code, has_user_gesture));
|
2014-04-25 02:34:40 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 09:01:17 +00:00
|
|
|
void WebContents::OpenDevTools(mate::Arguments* args) {
|
2015-06-24 14:23:38 +00:00
|
|
|
if (type_ == REMOTE)
|
2015-06-05 07:41:03 +00:00
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
2015-06-05 09:01:17 +00:00
|
|
|
bool detach = false;
|
2015-06-24 14:23:38 +00:00
|
|
|
if (type_ == WEB_VIEW) {
|
2015-06-05 09:01:17 +00:00
|
|
|
detach = true;
|
|
|
|
} else if (args && args->Length() == 1) {
|
|
|
|
mate::Dictionary options;
|
|
|
|
args->GetNext(&options) && options.Get("detach", &detach);
|
|
|
|
}
|
2015-06-25 06:32:38 +00:00
|
|
|
managed_web_contents()->SetCanDock(!detach);
|
|
|
|
managed_web_contents()->ShowDevTools();
|
2014-11-02 14:34:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 14:12:56 +00:00
|
|
|
void WebContents::CloseDevTools() {
|
2015-06-24 14:23:38 +00:00
|
|
|
if (type_ == REMOTE)
|
2015-06-05 07:41:03 +00:00
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
2015-06-25 06:32:38 +00:00
|
|
|
managed_web_contents()->CloseDevTools();
|
2014-11-03 14:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContents::IsDevToolsOpened() {
|
2015-06-24 14:23:38 +00:00
|
|
|
if (type_ == REMOTE)
|
2015-06-05 07:41:03 +00:00
|
|
|
return false;
|
2015-06-25 06:32:38 +00:00
|
|
|
|
|
|
|
return managed_web_contents()->IsDevToolsViewShowing();
|
2014-11-03 14:12:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 03:06:38 +00:00
|
|
|
void WebContents::EnableDeviceEmulation(
|
|
|
|
const blink::WebDeviceEmulationParams& params) {
|
2015-08-31 09:19:19 +00:00
|
|
|
if (type_ == REMOTE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Send(new ViewMsg_EnableDeviceEmulation(routing_id(), params));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::DisableDeviceEmulation() {
|
|
|
|
if (type_ == REMOTE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Send(new ViewMsg_DisableDeviceEmulation(routing_id()));
|
|
|
|
}
|
|
|
|
|
2015-06-05 09:01:17 +00:00
|
|
|
void WebContents::ToggleDevTools() {
|
|
|
|
if (IsDevToolsOpened())
|
|
|
|
CloseDevTools();
|
|
|
|
else
|
|
|
|
OpenDevTools(nullptr);
|
|
|
|
}
|
|
|
|
|
2015-04-22 07:30:10 +00:00
|
|
|
void WebContents::InspectElement(int x, int y) {
|
2015-06-24 14:23:38 +00:00
|
|
|
if (type_ == REMOTE)
|
2015-06-05 07:41:03 +00:00
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
2015-06-05 09:01:17 +00:00
|
|
|
OpenDevTools(nullptr);
|
2015-04-22 07:30:10 +00:00
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent(
|
2015-06-05 07:01:51 +00:00
|
|
|
content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
|
2015-04-22 07:30:10 +00:00
|
|
|
agent->InspectElement(x, y);
|
|
|
|
}
|
|
|
|
|
2015-06-05 07:41:03 +00:00
|
|
|
void WebContents::InspectServiceWorker() {
|
2015-06-24 14:23:38 +00:00
|
|
|
if (type_ == REMOTE)
|
2015-06-05 07:41:03 +00:00
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
2015-06-05 07:41:03 +00:00
|
|
|
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
|
|
|
if (agent_host->GetType() ==
|
|
|
|
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
2015-06-05 09:01:17 +00:00
|
|
|
OpenDevTools(nullptr);
|
2015-06-25 06:32:38 +00:00
|
|
|
managed_web_contents()->AttachTo(agent_host);
|
2015-06-05 07:41:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::HasServiceWorker(
|
|
|
|
const base::Callback<void(bool)>& callback) {
|
|
|
|
auto context = GetServiceWorkerContext(web_contents());
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context->CheckHasServiceWorker(web_contents()->GetLastCommittedURL(),
|
|
|
|
GURL::EmptyGURL(),
|
|
|
|
callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::UnregisterServiceWorker(
|
|
|
|
const base::Callback<void(bool)>& callback) {
|
|
|
|
auto context = GetServiceWorkerContext(web_contents());
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context->UnregisterServiceWorker(web_contents()->GetLastCommittedURL(),
|
|
|
|
callback);
|
|
|
|
}
|
|
|
|
|
2015-06-15 13:40:49 +00:00
|
|
|
void WebContents::SetAudioMuted(bool muted) {
|
|
|
|
web_contents()->SetAudioMuted(muted);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebContents::IsAudioMuted() {
|
|
|
|
return web_contents()->IsAudioMuted();
|
|
|
|
}
|
|
|
|
|
2015-06-13 13:23:45 +00:00
|
|
|
void WebContents::Print(mate::Arguments* args) {
|
|
|
|
PrintSettings settings = { false, false };
|
|
|
|
if (args->Length() == 1 && !args->GetNext(&settings)) {
|
|
|
|
args->ThrowError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printing::PrintViewManagerBasic::FromWebContents(web_contents())->
|
|
|
|
PrintNow(settings.silent, settings.print_background);
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:34:16 +00:00
|
|
|
void WebContents::PrintToPDF(const base::DictionaryValue& setting,
|
2015-06-13 08:02:16 +00:00
|
|
|
const PrintToPDFCallback& callback) {
|
2015-06-09 05:07:40 +00:00
|
|
|
printing::PrintPreviewMessageHandler::FromWebContents(web_contents())->
|
2015-06-10 03:34:16 +00:00
|
|
|
PrintToPDF(setting, callback);
|
2015-06-09 05:07:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-07 08:12:31 +00:00
|
|
|
void WebContents::AddWorkSpace(mate::Arguments* args,
|
|
|
|
const base::FilePath& path) {
|
2015-07-24 09:39:11 +00:00
|
|
|
if (path.empty()) {
|
2015-09-07 08:12:31 +00:00
|
|
|
args->ThrowError("path cannot be empty");
|
2015-07-24 09:39:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DevToolsAddFileSystem(path);
|
|
|
|
}
|
|
|
|
|
2015-09-07 08:12:31 +00:00
|
|
|
void WebContents::RemoveWorkSpace(mate::Arguments* args,
|
|
|
|
const base::FilePath& path) {
|
2015-07-24 09:39:11 +00:00
|
|
|
if (path.empty()) {
|
2015-09-07 08:12:31 +00:00
|
|
|
args->ThrowError("path cannot be empty");
|
2015-07-24 09:39:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DevToolsRemoveFileSystem(path);
|
|
|
|
}
|
|
|
|
|
2015-01-19 20:09:47 +00:00
|
|
|
void WebContents::Undo() {
|
|
|
|
web_contents()->Undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::Redo() {
|
|
|
|
web_contents()->Redo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::Cut() {
|
|
|
|
web_contents()->Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::Copy() {
|
|
|
|
web_contents()->Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::Paste() {
|
|
|
|
web_contents()->Paste();
|
|
|
|
}
|
|
|
|
|
2015-05-15 07:15:19 +00:00
|
|
|
void WebContents::PasteAndMatchStyle() {
|
|
|
|
web_contents()->PasteAndMatchStyle();
|
|
|
|
}
|
|
|
|
|
2015-01-19 20:09:47 +00:00
|
|
|
void WebContents::Delete() {
|
|
|
|
web_contents()->Delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::SelectAll() {
|
|
|
|
web_contents()->SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::Unselect() {
|
|
|
|
web_contents()->Unselect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::Replace(const base::string16& word) {
|
|
|
|
web_contents()->Replace(word);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::ReplaceMisspelling(const base::string16& word) {
|
|
|
|
web_contents()->ReplaceMisspelling(word);
|
|
|
|
}
|
|
|
|
|
2015-07-24 04:58:28 +00:00
|
|
|
void WebContents::Focus() {
|
|
|
|
web_contents()->Focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebContents::TabTraverse(bool reverse) {
|
|
|
|
web_contents()->FocusThroughTabTraversal(reverse);
|
|
|
|
}
|
|
|
|
|
2014-06-28 11:36:57 +00:00
|
|
|
bool WebContents::SendIPCMessage(const base::string16& channel,
|
2014-04-25 05:10:16 +00:00
|
|
|
const base::ListValue& args) {
|
|
|
|
return Send(new AtomViewMsg_Message(routing_id(), channel, args));
|
|
|
|
}
|
|
|
|
|
2015-09-18 06:20:31 +00:00
|
|
|
void WebContents::SendInputEvent(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> input_event) {
|
|
|
|
const auto view = web_contents()->GetRenderWidgetHostView();
|
|
|
|
if (!view)
|
|
|
|
return;
|
|
|
|
const auto host = view->GetRenderWidgetHost();
|
|
|
|
if (!host)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int type = mate::GetWebInputEventType(isolate, input_event);
|
|
|
|
if (blink::WebInputEvent::isMouseEventType(type)) {
|
|
|
|
blink::WebMouseEvent mouse_event;
|
|
|
|
if (mate::ConvertFromV8(isolate, input_event, &mouse_event)) {
|
|
|
|
host->ForwardMouseEvent(mouse_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (blink::WebInputEvent::isKeyboardEventType(type)) {
|
|
|
|
content::NativeWebKeyboardEvent keyboard_event;;
|
|
|
|
if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) {
|
|
|
|
host->ForwardKeyboardEvent(keyboard_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == blink::WebInputEvent::MouseWheel) {
|
|
|
|
blink::WebMouseWheelEvent mouse_wheel_event;
|
|
|
|
if (mate::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) {
|
|
|
|
host->ForwardWheelEvent(mouse_wheel_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
|
2015-09-18 10:21:51 +00:00
|
|
|
isolate, "Invalid event object")));
|
2015-09-18 06:20:31 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 07:57:43 +00:00
|
|
|
void WebContents::BeginFrameSubscription(
|
|
|
|
const FrameSubscriber::FrameCaptureCallback& callback) {
|
|
|
|
const auto view = web_contents()->GetRenderWidgetHostView();
|
|
|
|
if (view) {
|
|
|
|
scoped_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
|
|
|
|
isolate(), view->GetVisibleViewportSize(), callback));
|
|
|
|
view->BeginFrameSubscription(frame_subscriber.Pass());
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 06:20:31 +00:00
|
|
|
|
2015-09-18 07:57:43 +00:00
|
|
|
void WebContents::EndFrameSubscription() {
|
|
|
|
const auto view = web_contents()->GetRenderWidgetHostView();
|
|
|
|
if (view)
|
|
|
|
view->EndFrameSubscription();
|
|
|
|
}
|
2015-09-18 06:20:31 +00:00
|
|
|
|
2015-05-29 03:12:55 +00:00
|
|
|
void WebContents::SetSize(const SetSizeParams& params) {
|
2015-06-25 06:28:13 +00:00
|
|
|
if (guest_delegate_)
|
|
|
|
guest_delegate_->SetSize(params);
|
2014-10-24 06:37:14 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 08:48:21 +00:00
|
|
|
void WebContents::SetAllowTransparency(bool allow) {
|
2015-06-25 06:28:13 +00:00
|
|
|
if (guest_delegate_)
|
|
|
|
guest_delegate_->SetAllowTransparency(allow);
|
2014-10-24 08:48:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 07:18:15 +00:00
|
|
|
bool WebContents::IsGuest() const {
|
2015-06-24 14:23:38 +00:00
|
|
|
return type_ == WEB_VIEW;
|
2015-06-05 07:18:15 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 13:56:56 +00:00
|
|
|
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
|
|
|
WebContentsPreferences* web_preferences =
|
|
|
|
WebContentsPreferences::FromWebContents(web_contents());
|
|
|
|
return mate::ConvertToV8(isolate, *web_preferences->web_preferences());
|
|
|
|
}
|
|
|
|
|
2015-10-01 05:45:59 +00:00
|
|
|
v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow() {
|
|
|
|
if (owner_window())
|
|
|
|
return Window::From(isolate(), owner_window());
|
|
|
|
else
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
|
|
|
|
return v8::Local<v8::Value>::New(isolate, session_);
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> WebContents::DevToolsWebContents(v8::Isolate* isolate) {
|
|
|
|
if (devtools_web_contents_.IsEmpty())
|
|
|
|
return v8::Null(isolate);
|
|
|
|
else
|
|
|
|
return v8::Local<v8::Value>::New(isolate, devtools_web_contents_);
|
|
|
|
}
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) {
|
2014-10-23 05:31:10 +00:00
|
|
|
if (template_.IsEmpty())
|
|
|
|
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
2015-07-06 13:26:50 +00:00
|
|
|
.SetMethod("destroy", &WebContents::Destroy, true)
|
2015-11-19 09:08:16 +00:00
|
|
|
.SetMethod("isDestroyed", &WebContents::IsDestroyed, true)
|
2015-06-23 08:16:10 +00:00
|
|
|
.SetMethod("getId", &WebContents::GetID)
|
|
|
|
.SetMethod("equal", &WebContents::Equal)
|
2015-11-13 08:03:40 +00:00
|
|
|
.SetMethod("_loadURL", &WebContents::LoadURL)
|
|
|
|
.SetMethod("_getURL", &WebContents::GetURL)
|
2014-10-23 05:31:10 +00:00
|
|
|
.SetMethod("getTitle", &WebContents::GetTitle)
|
|
|
|
.SetMethod("isLoading", &WebContents::IsLoading)
|
|
|
|
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
|
2015-04-26 13:28:30 +00:00
|
|
|
.SetMethod("_stop", &WebContents::Stop)
|
2015-05-11 06:30:26 +00:00
|
|
|
.SetMethod("_goBack", &WebContents::GoBack)
|
|
|
|
.SetMethod("_goForward", &WebContents::GoForward)
|
2015-05-11 08:44:01 +00:00
|
|
|
.SetMethod("_goToOffset", &WebContents::GoToOffset)
|
2014-10-23 05:31:10 +00:00
|
|
|
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
2014-10-24 12:57:44 +00:00
|
|
|
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
|
2015-07-22 04:25:10 +00:00
|
|
|
.SetMethod("getUserAgent", &WebContents::GetUserAgent)
|
2014-10-24 13:04:50 +00:00
|
|
|
.SetMethod("insertCSS", &WebContents::InsertCSS)
|
2015-10-14 04:41:31 +00:00
|
|
|
.SetMethod("savePage", &WebContents::SavePage)
|
2014-10-23 05:31:10 +00:00
|
|
|
.SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript)
|
2015-01-19 20:09:47 +00:00
|
|
|
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
|
|
|
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
|
|
|
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
2015-08-31 09:19:19 +00:00
|
|
|
.SetMethod("enableDeviceEmulation",
|
|
|
|
&WebContents::EnableDeviceEmulation)
|
|
|
|
.SetMethod("disableDeviceEmulation",
|
|
|
|
&WebContents::DisableDeviceEmulation)
|
2015-06-05 09:01:17 +00:00
|
|
|
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
|
2015-04-22 07:30:10 +00:00
|
|
|
.SetMethod("inspectElement", &WebContents::InspectElement)
|
2015-06-15 13:40:49 +00:00
|
|
|
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
|
|
|
|
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
|
2015-01-19 20:09:47 +00:00
|
|
|
.SetMethod("undo", &WebContents::Undo)
|
|
|
|
.SetMethod("redo", &WebContents::Redo)
|
|
|
|
.SetMethod("cut", &WebContents::Cut)
|
|
|
|
.SetMethod("copy", &WebContents::Copy)
|
|
|
|
.SetMethod("paste", &WebContents::Paste)
|
2015-05-15 07:15:19 +00:00
|
|
|
.SetMethod("pasteAndMatchStyle", &WebContents::PasteAndMatchStyle)
|
2015-01-19 20:09:47 +00:00
|
|
|
.SetMethod("delete", &WebContents::Delete)
|
|
|
|
.SetMethod("selectAll", &WebContents::SelectAll)
|
|
|
|
.SetMethod("unselect", &WebContents::Unselect)
|
|
|
|
.SetMethod("replace", &WebContents::Replace)
|
|
|
|
.SetMethod("replaceMisspelling", &WebContents::ReplaceMisspelling)
|
2015-07-24 04:58:28 +00:00
|
|
|
.SetMethod("focus", &WebContents::Focus)
|
|
|
|
.SetMethod("tabTraverse", &WebContents::TabTraverse)
|
2015-07-06 13:26:50 +00:00
|
|
|
.SetMethod("_send", &WebContents::SendIPCMessage, true)
|
2015-09-18 06:20:31 +00:00
|
|
|
.SetMethod("sendInputEvent", &WebContents::SendInputEvent)
|
2015-09-18 07:57:43 +00:00
|
|
|
.SetMethod("beginFrameSubscription",
|
|
|
|
&WebContents::BeginFrameSubscription)
|
|
|
|
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
2015-05-29 03:12:55 +00:00
|
|
|
.SetMethod("setSize", &WebContents::SetSize)
|
2014-10-24 08:48:21 +00:00
|
|
|
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
2015-06-05 07:18:15 +00:00
|
|
|
.SetMethod("isGuest", &WebContents::IsGuest)
|
2015-09-22 13:56:56 +00:00
|
|
|
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
|
2015-10-01 05:45:59 +00:00
|
|
|
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
|
2015-04-30 13:15:19 +00:00
|
|
|
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
|
|
|
|
.SetMethod("unregisterServiceWorker",
|
|
|
|
&WebContents::UnregisterServiceWorker)
|
2015-05-18 13:49:33 +00:00
|
|
|
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
|
2015-06-13 13:23:45 +00:00
|
|
|
.SetMethod("print", &WebContents::Print)
|
2015-06-10 03:34:16 +00:00
|
|
|
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
2015-07-24 09:39:11 +00:00
|
|
|
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
|
|
|
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
2015-10-01 03:14:19 +00:00
|
|
|
.SetProperty("session", &WebContents::Session, true)
|
|
|
|
.SetProperty("devToolsWebContents",
|
|
|
|
&WebContents::DevToolsWebContents, true)
|
2014-10-23 05:31:10 +00:00
|
|
|
.Build());
|
|
|
|
|
|
|
|
return mate::ObjectTemplateBuilder(
|
|
|
|
isolate, v8::Local<v8::ObjectTemplate>::New(isolate, template_));
|
2014-04-25 08:13:16 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 10:21:04 +00:00
|
|
|
bool WebContents::IsDestroyed() const {
|
2015-11-19 09:08:16 +00:00
|
|
|
return !web_contents();
|
2015-07-06 10:21:04 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 19:13:25 +00:00
|
|
|
AtomBrowserContext* WebContents::GetBrowserContext() const {
|
|
|
|
return static_cast<AtomBrowserContext*>(web_contents()->GetBrowserContext());
|
|
|
|
}
|
|
|
|
|
2014-06-28 11:36:57 +00:00
|
|
|
void WebContents::OnRendererMessage(const base::string16& channel,
|
2014-04-25 08:13:16 +00:00
|
|
|
const base::ListValue& args) {
|
|
|
|
// webContents.emit(channel, new Event(), args...);
|
2014-10-24 06:37:14 +00:00
|
|
|
Emit(base::UTF16ToUTF8(channel), args);
|
2014-04-25 08:13:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-28 11:36:57 +00:00
|
|
|
void WebContents::OnRendererMessageSync(const base::string16& channel,
|
2014-04-25 08:13:16 +00:00
|
|
|
const base::ListValue& args,
|
|
|
|
IPC::Message* message) {
|
|
|
|
// webContents.emit(channel, new Event(sender, message), args...);
|
2015-01-15 01:51:54 +00:00
|
|
|
EmitWithSender(base::UTF16ToUTF8(channel), web_contents(), message, args);
|
2014-04-24 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 15:33:14 +00:00
|
|
|
void WebContents::OnZoomLevelChanged(double level) {
|
|
|
|
auto manager = web_contents()->GetBrowserContext()->GetGuestManager();
|
|
|
|
if (!manager)
|
|
|
|
return;
|
|
|
|
manager->ForEachGuest(web_contents(),
|
|
|
|
base::Bind(&NotifyZoomLevelChanged,
|
|
|
|
level));
|
|
|
|
}
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
// static
|
2014-10-23 06:04:13 +00:00
|
|
|
mate::Handle<WebContents> WebContents::CreateFrom(
|
2014-04-24 08:45:25 +00:00
|
|
|
v8::Isolate* isolate, content::WebContents* web_contents) {
|
2015-06-24 07:09:50 +00:00
|
|
|
// We have an existing WebContents object in JS.
|
|
|
|
auto existing = TrackableObject::FromWrappedClass(isolate, web_contents);
|
|
|
|
if (existing)
|
|
|
|
return mate::CreateHandle(isolate, static_cast<WebContents*>(existing));
|
|
|
|
|
|
|
|
// Otherwise create a new WebContents wrapper object.
|
2015-06-05 09:01:17 +00:00
|
|
|
auto handle = mate::CreateHandle(isolate, new WebContents(web_contents));
|
|
|
|
g_wrap_web_contents.Run(handle.ToV8());
|
|
|
|
return handle;
|
2014-04-24 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
// static
|
|
|
|
mate::Handle<WebContents> WebContents::Create(
|
|
|
|
v8::Isolate* isolate, const mate::Dictionary& options) {
|
2015-09-22 13:56:56 +00:00
|
|
|
auto handle = mate::CreateHandle(isolate, new WebContents(isolate, options));
|
2015-06-05 09:01:17 +00:00
|
|
|
g_wrap_web_contents.Run(handle.ToV8());
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2015-11-04 08:54:36 +00:00
|
|
|
void ClearWrapWebContents() {
|
|
|
|
g_wrap_web_contents.Reset();
|
|
|
|
}
|
|
|
|
|
2015-06-05 09:01:17 +00:00
|
|
|
void SetWrapWebContents(const WrapWebContentsCallback& callback) {
|
|
|
|
g_wrap_web_contents = callback;
|
|
|
|
|
2015-11-04 08:54:36 +00:00
|
|
|
// Cleanup the wrapper on exit.
|
|
|
|
atom::AtomBrowserMainParts::Get()->RegisterDestructionCallback(
|
|
|
|
base::Bind(ClearWrapWebContents));
|
2014-10-23 06:04:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
2014-10-23 06:04:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
2014-10-23 06:04:13 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
|
|
|
dict.SetMethod("create", &atom::api::WebContents::Create);
|
2015-06-05 09:01:17 +00:00
|
|
|
dict.SetMethod("_setWrapWebContents", &atom::api::SetWrapWebContents);
|
2014-10-23 06:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_web_contents, Initialize)
|