2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 07:04:46 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
|
|
|
|
#include <string>
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/atom_browser_context.h"
|
|
|
|
#include "atom/browser/atom_javascript_dialog_manager.h"
|
|
|
|
#include "atom/browser/browser.h"
|
2014-04-04 16:10:57 +00:00
|
|
|
#include "atom/browser/ui/file_dialog.h"
|
2014-10-31 09:37:32 +00:00
|
|
|
#include "atom/browser/web_dialog_helper.h"
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/window_list.h"
|
2014-04-04 14:04:42 +00:00
|
|
|
#include "atom/common/api/api_messages.h"
|
|
|
|
#include "atom/common/atom_version.h"
|
2014-06-25 01:05:10 +00:00
|
|
|
#include "atom/common/chrome_version.h"
|
2014-06-23 14:26:01 +00:00
|
|
|
#include "atom/common/native_mate_converters/image_converter.h"
|
2014-06-23 14:08:40 +00:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2014-04-04 14:04:42 +00:00
|
|
|
#include "atom/common/options_switches.h"
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/file_util.h"
|
2014-04-04 16:10:57 +00:00
|
|
|
#include "base/json/json_writer.h"
|
2014-04-04 14:04:42 +00:00
|
|
|
#include "base/prefs/pref_service.h"
|
|
|
|
#include "base/message_loop/message_loop.h"
|
2014-06-16 10:52:04 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2014-04-04 14:04:42 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2014-08-11 02:01:05 +00:00
|
|
|
#include "brightray/browser/inspectable_web_contents.h"
|
|
|
|
#include "brightray/browser/inspectable_web_contents_view.h"
|
2014-08-21 12:49:18 +00:00
|
|
|
#include "chrome/browser/printing/print_view_manager_basic.h"
|
2014-10-31 14:53:15 +00:00
|
|
|
#include "chrome/browser/ui/browser_dialogs.h"
|
2013-07-18 11:21:25 +00:00
|
|
|
#include "content/public/browser/devtools_agent_host.h"
|
2013-06-10 12:42:10 +00:00
|
|
|
#include "content/public/browser/invalidate_type.h"
|
2013-04-18 12:50:58 +00:00
|
|
|
#include "content/public/browser/navigation_entry.h"
|
|
|
|
#include "content/public/browser/notification_details.h"
|
|
|
|
#include "content/public/browser/notification_source.h"
|
|
|
|
#include "content/public/browser/notification_types.h"
|
2014-05-22 15:48:00 +00:00
|
|
|
#include "content/public/browser/plugin_service.h"
|
2014-06-28 14:33:00 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2013-04-23 04:18:07 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2013-05-01 07:42:30 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2013-08-16 04:56:25 +00:00
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2014-09-18 13:49:04 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2013-12-05 03:21:11 +00:00
|
|
|
#include "content/public/common/renderer_preferences.h"
|
2014-06-28 14:33:00 +00:00
|
|
|
#include "content/public/common/user_agent.h"
|
2014-10-11 11:11:34 +00:00
|
|
|
#include "content/public/common/web_preferences.h"
|
2013-04-22 13:32:48 +00:00
|
|
|
#include "ipc/ipc_message_macros.h"
|
2014-06-23 13:51:42 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2013-11-21 13:50:06 +00:00
|
|
|
#include "ui/gfx/codec/png_codec.h"
|
2014-11-24 05:44:45 +00:00
|
|
|
#include "ui/gfx/geometry/size_conversions.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
#include "ui/gfx/point.h"
|
|
|
|
#include "ui/gfx/rect.h"
|
2014-11-24 05:44:45 +00:00
|
|
|
#include "ui/gfx/screen.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
#include "ui/gfx/size.h"
|
|
|
|
|
2013-04-18 12:50:58 +00:00
|
|
|
using content::NavigationEntry;
|
2014-11-24 05:44:45 +00:00
|
|
|
using content::RenderWidgetHostView;
|
|
|
|
using content::RenderWidgetHost;
|
2013-04-18 12:50:58 +00:00
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2014-09-09 05:21:15 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Array of available web runtime features.
|
|
|
|
const char* kWebRuntimeFeatures[] = {
|
|
|
|
switches::kExperimentalFeatures,
|
|
|
|
switches::kExperimentalCanvasFeatures,
|
|
|
|
switches::kSubpixelFontScaling,
|
|
|
|
switches::kOverlayScrollbars,
|
|
|
|
switches::kOverlayFullscreenVideo,
|
|
|
|
switches::kSharedWorker,
|
|
|
|
};
|
|
|
|
|
2014-09-12 15:08:13 +00:00
|
|
|
std::string RemoveWhitespace(const std::string& str) {
|
|
|
|
std::string trimmed;
|
|
|
|
if (base::RemoveChars(str, " ", &trimmed))
|
|
|
|
return trimmed;
|
|
|
|
else
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2014-09-09 05:21:15 +00:00
|
|
|
} // namespace
|
|
|
|
|
2013-04-20 05:42:39 +00:00
|
|
|
NativeWindow::NativeWindow(content::WebContents* web_contents,
|
2014-06-23 13:51:42 +00:00
|
|
|
const mate::Dictionary& options)
|
2013-04-22 13:32:48 +00:00
|
|
|
: content::WebContentsObserver(web_contents),
|
2013-09-05 13:43:47 +00:00
|
|
|
has_frame_(true),
|
2014-08-17 04:23:00 +00:00
|
|
|
enable_larger_than_screen_(false),
|
2013-05-02 12:08:23 +00:00
|
|
|
is_closed_(false),
|
2014-10-25 11:20:04 +00:00
|
|
|
node_integration_(true),
|
2014-02-10 12:07:38 +00:00
|
|
|
has_dialog_attached_(false),
|
2014-06-16 10:52:04 +00:00
|
|
|
zoom_factor_(1.0),
|
2014-04-11 10:43:01 +00:00
|
|
|
weak_factory_(this),
|
|
|
|
inspectable_web_contents_(
|
|
|
|
brightray::InspectableWebContents::Create(web_contents)) {
|
2014-08-21 12:49:18 +00:00
|
|
|
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
|
|
|
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kFrame, &has_frame_);
|
2014-08-17 04:23:00 +00:00
|
|
|
options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
|
2014-10-25 11:20:04 +00:00
|
|
|
options.Get(switches::kNodeIntegration, &node_integration_);
|
2013-09-05 13:43:47 +00:00
|
|
|
|
2014-01-30 13:57:01 +00:00
|
|
|
// Read icon before window is created.
|
2014-08-11 02:06:46 +00:00
|
|
|
options.Get(switches::kIcon, &icon_);
|
2014-01-30 13:57:01 +00:00
|
|
|
|
2014-11-12 07:04:03 +00:00
|
|
|
// The "preload" option must be absolute path.
|
|
|
|
if (options.Get(switches::kPreloadScript, &preload_script_) &&
|
|
|
|
!preload_script_.IsAbsolute()) {
|
|
|
|
LOG(ERROR) << "Path of \"preload\" script must be absolute.";
|
|
|
|
preload_script_.clear();
|
|
|
|
}
|
|
|
|
|
2014-10-25 11:20:04 +00:00
|
|
|
// Be compatible with old API of "node-integration" option.
|
|
|
|
std::string old_string_token;
|
|
|
|
if (options.Get(switches::kNodeIntegration, &old_string_token) &&
|
|
|
|
old_string_token != "disable")
|
|
|
|
node_integration_ = true;
|
2013-11-11 11:23:35 +00:00
|
|
|
|
2014-05-22 14:54:09 +00:00
|
|
|
// Read the web preferences.
|
2014-07-21 05:08:52 +00:00
|
|
|
options.Get(switches::kWebPreferences, &web_preferences_);
|
2014-05-22 14:54:09 +00:00
|
|
|
|
2014-06-16 10:52:04 +00:00
|
|
|
// Read the zoom factor before any navigation.
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kZoomFactor, &zoom_factor_);
|
2014-06-16 10:52:04 +00:00
|
|
|
|
2013-04-18 12:50:58 +00:00
|
|
|
web_contents->SetDelegate(this);
|
2014-03-04 09:08:30 +00:00
|
|
|
inspectable_web_contents()->SetDelegate(this);
|
2013-04-18 12:50:58 +00:00
|
|
|
|
2013-05-02 14:54:09 +00:00
|
|
|
WindowList::AddWindow(this);
|
2013-04-30 12:32:23 +00:00
|
|
|
|
2013-12-05 03:21:11 +00:00
|
|
|
// Override the user agent to contain application and atom-shell's version.
|
|
|
|
Browser* browser = Browser::Get();
|
|
|
|
std::string product_name = base::StringPrintf(
|
2014-09-12 15:08:13 +00:00
|
|
|
"%s/%s Chrome/%s AtomShell/" ATOM_VERSION_STRING,
|
|
|
|
RemoveWhitespace(browser->GetName()).c_str(),
|
2014-06-25 01:05:10 +00:00
|
|
|
browser->GetVersion().c_str(),
|
|
|
|
CHROME_VERSION_STRING);
|
2013-12-05 03:21:11 +00:00
|
|
|
web_contents->GetMutableRendererPrefs()->user_agent_override =
|
2014-06-28 14:33:00 +00:00
|
|
|
content::BuildUserAgentFromProduct(product_name);
|
2013-12-05 03:21:11 +00:00
|
|
|
|
2013-04-21 03:01:04 +00:00
|
|
|
// Get notified of title updated message.
|
2013-04-18 12:50:58 +00:00
|
|
|
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
|
|
|
|
content::Source<content::WebContents>(web_contents));
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NativeWindow::~NativeWindow() {
|
2013-05-02 12:08:23 +00:00
|
|
|
// It's possible that the windows gets destroyed before it's closed, in that
|
|
|
|
// case we need to ensure the OnWindowClosed message is still notified.
|
|
|
|
NotifyWindowClosed();
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 05:42:39 +00:00
|
|
|
// static
|
2014-06-23 13:51:42 +00:00
|
|
|
NativeWindow* NativeWindow::Create(const mate::Dictionary& options) {
|
2013-04-20 05:42:39 +00:00
|
|
|
content::WebContents::CreateParams create_params(AtomBrowserContext::Get());
|
|
|
|
return Create(content::WebContents::Create(create_params), options);
|
|
|
|
}
|
|
|
|
|
2013-04-30 12:32:23 +00:00
|
|
|
// static
|
2013-05-03 11:31:24 +00:00
|
|
|
NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
|
2013-04-30 12:32:23 +00:00
|
|
|
// Stupid iterating.
|
2013-05-02 14:54:09 +00:00
|
|
|
WindowList& window_list = *WindowList::GetInstance();
|
2013-07-01 14:01:17 +00:00
|
|
|
for (auto w = window_list.begin(); w != window_list.end(); ++w) {
|
|
|
|
auto& window = *w;
|
2013-04-30 12:32:23 +00:00
|
|
|
content::WebContents* web_contents = window->GetWebContents();
|
|
|
|
int window_process_id = web_contents->GetRenderProcessHost()->GetID();
|
|
|
|
int window_routing_id = web_contents->GetRoutingID();
|
|
|
|
if (window_routing_id == routing_id && window_process_id == process_id)
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-23 13:51:42 +00:00
|
|
|
void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
2013-04-12 07:04:46 +00:00
|
|
|
// Setup window from options.
|
2013-07-01 14:01:17 +00:00
|
|
|
int x = -1, y = -1;
|
2013-05-10 12:34:05 +00:00
|
|
|
bool center;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (options.Get(switches::kX, &x) && options.Get(switches::kY, &y)) {
|
2013-07-01 14:01:17 +00:00
|
|
|
int width = -1, height = -1;
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kWidth, &width);
|
|
|
|
options.Get(switches::kHeight, &height);
|
2013-04-12 07:04:46 +00:00
|
|
|
Move(gfx::Rect(x, y, width, height));
|
2014-06-23 13:51:42 +00:00
|
|
|
} else if (options.Get(switches::kCenter, ¢er) && center) {
|
2013-05-10 12:34:05 +00:00
|
|
|
Center();
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
2014-08-19 13:43:18 +00:00
|
|
|
int min_height = 0, min_width = 0;
|
2014-08-21 06:43:35 +00:00
|
|
|
if (options.Get(switches::kMinHeight, &min_height) |
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kMinWidth, &min_width)) {
|
2013-04-17 14:49:49 +00:00
|
|
|
SetMinimumSize(gfx::Size(min_width, min_height));
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
2013-07-01 14:01:17 +00:00
|
|
|
int max_height = -1, max_width = -1;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (options.Get(switches::kMaxHeight, &max_height) &&
|
|
|
|
options.Get(switches::kMaxWidth, &max_width)) {
|
2013-04-17 14:49:49 +00:00
|
|
|
SetMaximumSize(gfx::Size(max_width, max_height));
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
bool resizable;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (options.Get(switches::kResizable, &resizable)) {
|
2013-04-12 07:04:46 +00:00
|
|
|
SetResizable(resizable);
|
|
|
|
}
|
|
|
|
bool top;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (options.Get(switches::kAlwaysOnTop, &top) && top) {
|
2013-04-12 07:04:46 +00:00
|
|
|
SetAlwaysOnTop(true);
|
|
|
|
}
|
|
|
|
bool fullscreen;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (options.Get(switches::kFullscreen, &fullscreen) && fullscreen) {
|
2013-04-12 07:04:46 +00:00
|
|
|
SetFullscreen(true);
|
|
|
|
}
|
2014-06-16 02:29:51 +00:00
|
|
|
bool skip;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (options.Get(switches::kSkipTaskbar, &skip) && skip) {
|
2014-06-16 02:29:51 +00:00
|
|
|
SetSkipTaskbar(skip);
|
|
|
|
}
|
2013-04-12 07:04:46 +00:00
|
|
|
bool kiosk;
|
2014-06-23 13:51:42 +00:00
|
|
|
if (options.Get(switches::kKiosk, &kiosk) && kiosk) {
|
2013-04-12 07:04:46 +00:00
|
|
|
SetKiosk(kiosk);
|
|
|
|
}
|
|
|
|
std::string title("Atom Shell");
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kTitle, &title);
|
2013-04-12 07:04:46 +00:00
|
|
|
SetTitle(title);
|
|
|
|
|
|
|
|
// Then show it.
|
|
|
|
bool show = true;
|
2014-06-23 13:51:42 +00:00
|
|
|
options.Get(switches::kShow, &show);
|
2013-04-12 07:04:46 +00:00
|
|
|
if (show)
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
2014-05-27 06:15:34 +00:00
|
|
|
void NativeWindow::SetRepresentedFilename(const std::string& filename) {
|
|
|
|
}
|
|
|
|
|
2014-07-18 13:42:26 +00:00
|
|
|
std::string NativeWindow::GetRepresentedFilename() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-05-27 06:15:34 +00:00
|
|
|
void NativeWindow::SetDocumentEdited(bool edited) {
|
|
|
|
}
|
|
|
|
|
2014-08-21 13:00:49 +00:00
|
|
|
bool NativeWindow::IsDocumentEdited() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-04 08:54:10 +00:00
|
|
|
void NativeWindow::SetMenu(ui::MenuModel* menu) {
|
|
|
|
}
|
|
|
|
|
2014-08-22 07:01:07 +00:00
|
|
|
void NativeWindow::Print(bool silent, bool print_background) {
|
2014-08-21 13:00:49 +00:00
|
|
|
printing::PrintViewManagerBasic::FromWebContents(GetWebContents())->
|
2014-08-22 07:01:07 +00:00
|
|
|
PrintNow(silent, print_background);
|
2014-07-24 07:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 09:36:20 +00:00
|
|
|
void NativeWindow::SetAutoHideMenuBar(bool auto_hide) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindow::IsMenuBarAutoHide() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetMenuBarVisibility(bool visible) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindow::IsMenuBarVisible() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-10 12:07:38 +00:00
|
|
|
bool NativeWindow::HasModalDialog() {
|
|
|
|
return has_dialog_attached_;
|
|
|
|
}
|
|
|
|
|
2013-05-10 12:34:05 +00:00
|
|
|
void NativeWindow::OpenDevTools() {
|
2014-06-25 05:21:04 +00:00
|
|
|
inspectable_web_contents()->ShowDevTools();
|
2013-04-12 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::CloseDevTools() {
|
2014-06-25 05:21:04 +00:00
|
|
|
inspectable_web_contents()->CloseDevTools();
|
2013-04-12 07:53:29 +00:00
|
|
|
}
|
|
|
|
|
2013-11-05 02:32:45 +00:00
|
|
|
bool NativeWindow::IsDevToolsOpened() {
|
2014-06-25 05:21:04 +00:00
|
|
|
return inspectable_web_contents()->IsDevToolsViewShowing();
|
2013-11-05 02:32:45 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 11:21:25 +00:00
|
|
|
void NativeWindow::InspectElement(int x, int y) {
|
|
|
|
OpenDevTools();
|
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent(
|
2014-10-11 11:11:34 +00:00
|
|
|
content::DevToolsAgentHost::GetOrCreateFor(GetWebContents()));
|
2013-07-18 11:21:25 +00:00
|
|
|
agent->InspectElement(x, y);
|
|
|
|
}
|
|
|
|
|
2013-05-24 09:51:15 +00:00
|
|
|
void NativeWindow::FocusOnWebView() {
|
|
|
|
GetWebContents()->GetRenderViewHost()->Focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::BlurWebView() {
|
|
|
|
GetWebContents()->GetRenderViewHost()->Blur();
|
|
|
|
}
|
|
|
|
|
2013-08-16 04:56:25 +00:00
|
|
|
bool NativeWindow::IsWebViewFocused() {
|
2014-11-24 05:44:45 +00:00
|
|
|
RenderWidgetHostView* host_view =
|
2014-03-10 01:24:51 +00:00
|
|
|
GetWebContents()->GetRenderViewHost()->GetView();
|
|
|
|
return host_view && host_view->HasFocus();
|
2013-08-16 04:56:25 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 13:50:06 +00:00
|
|
|
void NativeWindow::CapturePage(const gfx::Rect& rect,
|
|
|
|
const CapturePageCallback& callback) {
|
2014-11-24 05:44:45 +00:00
|
|
|
content::WebContents* contents = GetWebContents();
|
|
|
|
RenderWidgetHostView* const view = contents->GetRenderWidgetHostView();
|
|
|
|
RenderWidgetHost* const host = view ? view->GetRenderWidgetHost() : nullptr;
|
|
|
|
if (!view || !host) {
|
2014-04-07 07:43:15 +00:00
|
|
|
callback.Run(std::vector<unsigned char>());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-24 05:44:45 +00:00
|
|
|
// Capture full page if user doesn't specify a |rect|.
|
|
|
|
const gfx::Size view_size = rect.IsEmpty() ? view->GetViewBounds().size() :
|
|
|
|
rect.size();
|
|
|
|
|
|
|
|
// By default, the requested bitmap size is the view size in screen
|
|
|
|
// coordinates. However, if there's more pixel detail available on the
|
|
|
|
// current system, increase the requested bitmap size to capture it all.
|
|
|
|
gfx::Size bitmap_size = view_size;
|
|
|
|
const gfx::NativeView native_view = view->GetNativeView();
|
|
|
|
gfx::Screen* const screen = gfx::Screen::GetScreenFor(native_view);
|
|
|
|
const float scale =
|
|
|
|
screen->GetDisplayNearestWindow(native_view).device_scale_factor();
|
|
|
|
if (scale > 1.0f)
|
|
|
|
bitmap_size = gfx::ToCeiledSize(gfx::ScaleSize(view_size, scale));
|
|
|
|
|
|
|
|
host->CopyFromBackingStore(
|
|
|
|
rect.IsEmpty() ? gfx::Rect(view_size) : rect,
|
|
|
|
bitmap_size,
|
2013-11-21 13:50:06 +00:00
|
|
|
base::Bind(&NativeWindow::OnCapturePageDone,
|
2013-11-29 06:52:12 +00:00
|
|
|
weak_factory_.GetWeakPtr(),
|
2014-06-28 14:33:00 +00:00
|
|
|
callback),
|
2014-11-24 05:44:45 +00:00
|
|
|
kBGRA_8888_SkColorType);
|
2013-11-21 13:50:06 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void NativeWindow::DestroyWebContents() {
|
2014-04-23 01:53:38 +00:00
|
|
|
if (!inspectable_web_contents_)
|
|
|
|
return;
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
inspectable_web_contents_.reset();
|
|
|
|
}
|
|
|
|
|
2013-05-01 08:12:00 +00:00
|
|
|
void NativeWindow::CloseWebContents() {
|
2013-05-01 08:33:19 +00:00
|
|
|
bool prevent_default = false;
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
|
|
|
observers_,
|
|
|
|
WillCloseWindow(&prevent_default));
|
2013-06-26 07:35:10 +00:00
|
|
|
if (prevent_default) {
|
|
|
|
WindowList::WindowCloseCancelled(this);
|
2013-05-01 08:33:19 +00:00
|
|
|
return;
|
2013-06-26 07:35:10 +00:00
|
|
|
}
|
2013-05-01 08:33:19 +00:00
|
|
|
|
2013-05-01 07:42:30 +00:00
|
|
|
content::WebContents* web_contents(GetWebContents());
|
2014-05-09 01:26:46 +00:00
|
|
|
if (!web_contents) {
|
|
|
|
CloseImmediately();
|
|
|
|
return;
|
|
|
|
}
|
2013-05-01 07:42:30 +00:00
|
|
|
|
2013-11-29 06:52:12 +00:00
|
|
|
// Assume the window is not responding if it doesn't cancel the close and is
|
2014-05-09 04:10:37 +00:00
|
|
|
// not closed in 5s, in this way we can quickly show the unresponsive
|
2013-11-29 06:52:12 +00:00
|
|
|
// dialog when the window is busy executing some script withouth waiting for
|
|
|
|
// the unresponsive timeout.
|
2014-04-08 06:22:22 +00:00
|
|
|
if (window_unresposive_closure_.IsCancelled())
|
2014-05-09 04:10:37 +00:00
|
|
|
ScheduleUnresponsiveEvent(5000);
|
2013-11-29 06:52:12 +00:00
|
|
|
|
2013-05-01 07:42:30 +00:00
|
|
|
if (web_contents->NeedToFireBeforeUnload())
|
2014-07-28 07:29:51 +00:00
|
|
|
web_contents->DispatchBeforeUnload(false);
|
2013-05-01 07:42:30 +00:00
|
|
|
else
|
|
|
|
web_contents->Close();
|
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
content::WebContents* NativeWindow::GetWebContents() const {
|
2014-05-09 01:26:46 +00:00
|
|
|
if (!inspectable_web_contents_)
|
|
|
|
return NULL;
|
|
|
|
return inspectable_web_contents()->GetWebContents();
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-02-24 03:53:13 +00:00
|
|
|
content::WebContents* NativeWindow::GetDevToolsWebContents() const {
|
2014-05-09 01:26:46 +00:00
|
|
|
if (!inspectable_web_contents_)
|
|
|
|
return NULL;
|
2014-03-04 06:25:15 +00:00
|
|
|
return inspectable_web_contents()->devtools_web_contents();
|
2014-02-24 03:53:13 +00:00
|
|
|
}
|
|
|
|
|
2014-06-28 14:33:00 +00:00
|
|
|
void NativeWindow::AppendExtraCommandLineSwitches(
|
|
|
|
base::CommandLine* command_line, int child_process_id) {
|
2014-03-06 02:40:10 +00:00
|
|
|
// Append --node-integration to renderer process.
|
|
|
|
command_line->AppendSwitchASCII(switches::kNodeIntegration,
|
2014-10-25 11:20:04 +00:00
|
|
|
node_integration_ ? "true" : "false");
|
2014-06-16 10:52:04 +00:00
|
|
|
|
2014-11-12 07:04:03 +00:00
|
|
|
// Append --preload.
|
|
|
|
if (!preload_script_.empty())
|
|
|
|
command_line->AppendSwitchPath(switches::kPreloadScript, preload_script_);
|
|
|
|
|
2014-06-16 10:52:04 +00:00
|
|
|
// Append --zoom-factor.
|
|
|
|
if (zoom_factor_ != 1.0)
|
|
|
|
command_line->AppendSwitchASCII(switches::kZoomFactor,
|
|
|
|
base::DoubleToString(zoom_factor_));
|
2014-09-09 03:08:30 +00:00
|
|
|
|
|
|
|
if (web_preferences_.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2014-09-18 13:49:04 +00:00
|
|
|
bool b;
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Check if DirectWrite is disabled.
|
|
|
|
if (web_preferences_.Get(switches::kDirectWrite, &b) && !b)
|
|
|
|
command_line->AppendSwitch(::switches::kDisableDirectWrite);
|
|
|
|
#endif
|
|
|
|
|
2014-10-26 06:05:54 +00:00
|
|
|
// Check if plugins are enabled.
|
|
|
|
if (web_preferences_.Get("plugins", &b) && b)
|
|
|
|
command_line->AppendSwitch(switches::kEnablePlugins);
|
|
|
|
|
2014-09-09 03:08:30 +00:00
|
|
|
// This set of options are not availabe in WebPreferences, so we have to pass
|
|
|
|
// them via command line and enable them in renderer procss.
|
2014-09-09 05:21:15 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
|
|
|
|
const char* feature = kWebRuntimeFeatures[i];
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get(feature, &b))
|
2014-09-09 05:21:15 +00:00
|
|
|
command_line->AppendSwitchASCII(feature, b ? "true" : "false");
|
2014-09-09 03:08:30 +00:00
|
|
|
}
|
2014-03-06 02:40:10 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 11:11:34 +00:00
|
|
|
void NativeWindow::OverrideWebkitPrefs(const GURL& url,
|
|
|
|
content::WebPreferences* prefs) {
|
2014-07-21 05:08:52 +00:00
|
|
|
if (web_preferences_.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2014-05-22 14:54:09 +00:00
|
|
|
bool b;
|
2014-06-23 14:08:40 +00:00
|
|
|
std::vector<base::FilePath> list;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("javascript", &b))
|
2014-05-22 14:54:09 +00:00
|
|
|
prefs->javascript_enabled = b;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("web-security", &b))
|
2014-05-22 14:54:09 +00:00
|
|
|
prefs->web_security_enabled = b;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("images", &b))
|
2014-05-22 14:54:09 +00:00
|
|
|
prefs->images_enabled = b;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("java", &b))
|
2014-05-22 14:54:09 +00:00
|
|
|
prefs->java_enabled = b;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("text-areas-are-resizable", &b))
|
2014-05-22 14:54:09 +00:00
|
|
|
prefs->text_areas_are_resizable = b;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("webgl", &b))
|
2014-05-22 14:54:09 +00:00
|
|
|
prefs->experimental_webgl_enabled = b;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("webaudio", &b))
|
2014-05-22 14:54:09 +00:00
|
|
|
prefs->webaudio_enabled = b;
|
2014-09-09 06:13:21 +00:00
|
|
|
if (web_preferences_.Get("extra-plugin-dirs", &list))
|
2014-06-23 14:08:40 +00:00
|
|
|
for (size_t i = 0; i < list.size(); ++i)
|
|
|
|
content::PluginService::GetInstance()->AddExtraPluginDir(list[i]);
|
2014-03-06 03:07:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 12:08:23 +00:00
|
|
|
void NativeWindow::NotifyWindowClosed() {
|
|
|
|
if (is_closed_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
is_closed_ = true;
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed());
|
2013-05-07 08:20:52 +00:00
|
|
|
|
2014-05-09 01:47:11 +00:00
|
|
|
// Do not receive any notification after window has been closed, there is a
|
|
|
|
// crash that seems to be caused by this: http://git.io/YqMG5g.
|
|
|
|
registrar_.RemoveAll();
|
|
|
|
|
2013-05-07 08:20:52 +00:00
|
|
|
WindowList::RemoveWindow(this);
|
2013-05-02 12:08:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 09:51:15 +00:00
|
|
|
void NativeWindow::NotifyWindowBlur() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
|
|
|
|
}
|
|
|
|
|
2014-05-21 17:46:13 +00:00
|
|
|
void NativeWindow::NotifyWindowFocus() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus());
|
|
|
|
}
|
|
|
|
|
2014-11-25 04:43:25 +00:00
|
|
|
void NativeWindow::NotifyWindowMaximize() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMaximize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowUnmaximize() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowUnmaximize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowMinimize() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMinimize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowRestore() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowRestore());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowEnterFullScreen() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
|
|
|
OnWindowEnterFullScreen());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowLeaveFullScreen() {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
|
|
|
OnWindowLeaveFullScreen());
|
|
|
|
}
|
|
|
|
|
2014-10-27 08:56:28 +00:00
|
|
|
bool NativeWindow::ShouldCreateWebContents(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
int route_id,
|
|
|
|
WindowContainerType window_container_type,
|
|
|
|
const base::string16& frame_name,
|
|
|
|
const GURL& target_url,
|
|
|
|
const std::string& partition_id,
|
|
|
|
content::SessionStorageNamespace* session_storage_namespace) {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
|
|
|
observers_,
|
|
|
|
WillCreatePopupWindow(frame_name,
|
|
|
|
target_url,
|
2014-11-04 09:59:15 +00:00
|
|
|
partition_id,
|
2014-11-04 10:49:57 +00:00
|
|
|
NEW_FOREGROUND_TAB));
|
2014-10-27 08:56:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-14 08:03:01 +00:00
|
|
|
// In atom-shell all reloads and navigations started by renderer process would
|
|
|
|
// be redirected to this method, so we can have precise control of how we
|
|
|
|
// would open the url (in our case, is to restart the renderer process). See
|
|
|
|
// AtomRendererClient::ShouldFork for how this is done.
|
|
|
|
content::WebContents* NativeWindow::OpenURLFromTab(
|
|
|
|
content::WebContents* source,
|
|
|
|
const content::OpenURLParams& params) {
|
2014-11-04 09:59:15 +00:00
|
|
|
if (params.disposition != CURRENT_TAB) {
|
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
|
|
|
observers_,
|
|
|
|
WillCreatePopupWindow(base::string16(),
|
|
|
|
params.url,
|
|
|
|
"",
|
|
|
|
params.disposition));
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-01-14 08:03:01 +00:00
|
|
|
|
|
|
|
content::NavigationController::LoadURLParams load_url_params(params.url);
|
|
|
|
load_url_params.referrer = params.referrer;
|
|
|
|
load_url_params.transition_type = params.transition;
|
|
|
|
load_url_params.extra_headers = params.extra_headers;
|
|
|
|
load_url_params.should_replace_current_entry =
|
|
|
|
params.should_replace_current_entry;
|
|
|
|
load_url_params.is_renderer_initiated = params.is_renderer_initiated;
|
|
|
|
load_url_params.transferred_global_request_id =
|
|
|
|
params.transferred_global_request_id;
|
|
|
|
|
|
|
|
source->GetController().LoadURLWithParams(load_url_params);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2013-04-30 15:56:50 +00:00
|
|
|
content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager() {
|
|
|
|
if (!dialog_manager_)
|
|
|
|
dialog_manager_.reset(new AtomJavaScriptDialogManager);
|
|
|
|
|
|
|
|
return dialog_manager_.get();
|
|
|
|
}
|
|
|
|
|
2013-05-02 15:43:23 +00:00
|
|
|
void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
|
|
|
|
bool proceed,
|
|
|
|
bool* proceed_to_fire_unload) {
|
|
|
|
*proceed_to_fire_unload = proceed;
|
|
|
|
|
2014-05-09 03:40:48 +00:00
|
|
|
if (!proceed) {
|
2013-05-02 15:43:23 +00:00
|
|
|
WindowList::WindowCloseCancelled(this);
|
2013-11-29 06:52:12 +00:00
|
|
|
|
2014-05-09 03:40:48 +00:00
|
|
|
// Cancel unresponsive event when window close is cancelled.
|
|
|
|
window_unresposive_closure_.Cancel();
|
|
|
|
}
|
2013-05-02 15:43:23 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 14:53:15 +00:00
|
|
|
content::ColorChooser* NativeWindow::OpenColorChooser(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
SkColor color,
|
|
|
|
const std::vector<content::ColorSuggestion>& suggestions) {
|
|
|
|
return chrome::ShowColorChooser(web_contents, color);
|
|
|
|
}
|
|
|
|
|
2014-10-31 09:37:32 +00:00
|
|
|
void NativeWindow::RunFileChooser(content::WebContents* web_contents,
|
|
|
|
const content::FileChooserParams& params) {
|
|
|
|
if (!web_dialog_helper_)
|
|
|
|
web_dialog_helper_.reset(new WebDialogHelper(this));
|
|
|
|
web_dialog_helper_->RunFileChooser(web_contents, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::EnumerateDirectory(content::WebContents* web_contents,
|
|
|
|
int request_id,
|
|
|
|
const base::FilePath& path) {
|
|
|
|
if (!web_dialog_helper_)
|
|
|
|
web_dialog_helper_.reset(new WebDialogHelper(this));
|
|
|
|
web_dialog_helper_->EnumerateDirectory(web_contents, request_id, path);
|
|
|
|
}
|
|
|
|
|
2013-05-15 11:11:30 +00:00
|
|
|
void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
|
|
|
|
bool user_gesture,
|
|
|
|
bool last_unlocked_by_target) {
|
|
|
|
GetWebContents()->GotResponseToLockMouseRequest(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeWindow::CanOverscrollContent() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::ActivateContents(content::WebContents* contents) {
|
2013-05-24 09:51:15 +00:00
|
|
|
FocusOnWebView();
|
2013-05-15 11:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::DeactivateContents(content::WebContents* contents) {
|
2013-05-24 09:51:15 +00:00
|
|
|
BlurWebView();
|
2013-05-15 11:11:30 +00:00
|
|
|
}
|
|
|
|
|
2013-05-15 05:56:25 +00:00
|
|
|
void NativeWindow::MoveContents(content::WebContents* source,
|
|
|
|
const gfx::Rect& pos) {
|
|
|
|
SetPosition(pos.origin());
|
|
|
|
SetSize(pos.size());
|
|
|
|
}
|
|
|
|
|
2013-05-01 07:42:30 +00:00
|
|
|
void NativeWindow::CloseContents(content::WebContents* source) {
|
2014-08-04 06:55:08 +00:00
|
|
|
// Destroy the WebContents before we close the window.
|
|
|
|
DestroyWebContents();
|
|
|
|
|
2013-05-01 07:42:30 +00:00
|
|
|
// When the web contents is gone, close the window immediately, but the
|
2013-05-01 08:12:00 +00:00
|
|
|
// memory will not be freed until you call delete.
|
2013-05-01 08:33:19 +00:00
|
|
|
// In this way, it would be safe to manage windows via smart pointers. If you
|
|
|
|
// want to free memory when the window is closed, you can do deleting by
|
2013-05-15 05:47:15 +00:00
|
|
|
// overriding the OnWindowClosed method in the observer.
|
2013-05-01 08:12:00 +00:00
|
|
|
CloseImmediately();
|
2013-05-01 08:33:19 +00:00
|
|
|
|
2013-11-29 06:52:12 +00:00
|
|
|
// Do not sent "unresponsive" event after window is closed.
|
2013-12-04 09:10:59 +00:00
|
|
|
window_unresposive_closure_.Cancel();
|
2013-05-01 07:42:30 +00:00
|
|
|
}
|
|
|
|
|
2013-05-15 05:56:25 +00:00
|
|
|
bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
|
|
|
// Only popup window can use things like window.moveTo.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-06 11:45:48 +00:00
|
|
|
void NativeWindow::RendererUnresponsive(content::WebContents* source) {
|
2014-03-25 10:10:51 +00:00
|
|
|
// Schedule the unresponsive shortly later, since we may receive the
|
2014-05-09 03:26:13 +00:00
|
|
|
// responsive event soon. This could happen after the whole application had
|
|
|
|
// blocked for a while.
|
|
|
|
// Also notice that when closing this event would be ignored because we have
|
|
|
|
// explicity started a close timeout counter. This is on purpose because we
|
|
|
|
// don't want the unresponsive event to be sent too early when user is closing
|
|
|
|
// the window.
|
2014-03-25 10:10:51 +00:00
|
|
|
ScheduleUnresponsiveEvent(50);
|
2013-06-06 11:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
2013-12-04 09:10:59 +00:00
|
|
|
window_unresposive_closure_.Cancel();
|
2013-06-06 11:45:48 +00:00
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
void NativeWindow::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.
|
|
|
|
}
|
|
|
|
|
2013-04-21 03:01:04 +00:00
|
|
|
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
|
2013-04-22 13:32:48 +00:00
|
|
|
bool handled = true;
|
|
|
|
IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
|
2013-09-05 12:06:54 +00:00
|
|
|
IPC_MESSAGE_HANDLER(AtomViewHostMsg_UpdateDraggableRegions,
|
|
|
|
UpdateDraggableRegions)
|
2013-04-22 13:32:48 +00:00
|
|
|
IPC_MESSAGE_UNHANDLED(handled = false)
|
|
|
|
IPC_END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
return handled;
|
2013-04-21 03:01:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 12:50:58 +00:00
|
|
|
void NativeWindow::Observe(int type,
|
|
|
|
const content::NotificationSource& source,
|
|
|
|
const content::NotificationDetails& details) {
|
|
|
|
if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) {
|
|
|
|
std::pair<NavigationEntry*, bool>* title =
|
|
|
|
content::Details<std::pair<NavigationEntry*, bool>>(details).ptr();
|
|
|
|
|
|
|
|
if (title->first) {
|
|
|
|
bool prevent_default = false;
|
2014-07-11 04:19:01 +00:00
|
|
|
std::string text = base::UTF16ToUTF8(title->first->GetTitle());
|
2013-04-18 12:50:58 +00:00
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
|
|
|
observers_,
|
|
|
|
OnPageTitleUpdated(&prevent_default, text));
|
|
|
|
|
|
|
|
if (!prevent_default)
|
|
|
|
SetTitle(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 16:10:57 +00:00
|
|
|
void NativeWindow::DevToolsSaveToFile(const std::string& url,
|
|
|
|
const std::string& content,
|
|
|
|
bool save_as) {
|
|
|
|
base::FilePath path;
|
|
|
|
PathsMap::iterator it = saved_files_.find(url);
|
|
|
|
if (it != saved_files_.end() && !save_as) {
|
|
|
|
path = it->second;
|
|
|
|
} else {
|
2014-08-06 04:44:02 +00:00
|
|
|
file_dialog::Filters filters;
|
2014-04-29 03:39:31 +00:00
|
|
|
base::FilePath default_path(base::FilePath::FromUTF8Unsafe(url));
|
2014-08-06 04:44:02 +00:00
|
|
|
if (!file_dialog::ShowSaveDialog(this, url, default_path, filters, &path)) {
|
2014-07-09 07:41:16 +00:00
|
|
|
base::StringValue url_value(url);
|
|
|
|
CallDevToolsFunction("InspectorFrontendAPI.canceledSaveURL", &url_value);
|
2014-04-04 16:10:57 +00:00
|
|
|
return;
|
2014-07-09 07:41:16 +00:00
|
|
|
}
|
2014-04-04 16:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
saved_files_[url] = path;
|
2014-06-28 14:33:00 +00:00
|
|
|
base::WriteFile(path, content.data(), content.size());
|
2014-04-04 16:10:57 +00:00
|
|
|
|
|
|
|
// Notify devtools.
|
|
|
|
base::StringValue url_value(url);
|
|
|
|
CallDevToolsFunction("InspectorFrontendAPI.savedURL", &url_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::DevToolsAppendToFile(const std::string& url,
|
|
|
|
const std::string& content) {
|
|
|
|
PathsMap::iterator it = saved_files_.find(url);
|
|
|
|
if (it == saved_files_.end())
|
|
|
|
return;
|
2014-06-28 14:33:00 +00:00
|
|
|
base::AppendToFile(it->second, content.data(), content.size());
|
2014-04-04 16:10:57 +00:00
|
|
|
|
|
|
|
// Notify devtools.
|
|
|
|
base::StringValue url_value(url);
|
|
|
|
CallDevToolsFunction("InspectorFrontendAPI.appendedToURL", &url_value);
|
|
|
|
}
|
|
|
|
|
2014-03-25 10:10:51 +00:00
|
|
|
void NativeWindow::ScheduleUnresponsiveEvent(int ms) {
|
2014-05-09 03:26:13 +00:00
|
|
|
if (!window_unresposive_closure_.IsCancelled())
|
|
|
|
return;
|
|
|
|
|
2014-03-25 10:10:51 +00:00
|
|
|
window_unresposive_closure_.Reset(
|
|
|
|
base::Bind(&NativeWindow::NotifyWindowUnresponsive,
|
|
|
|
weak_factory_.GetWeakPtr()));
|
|
|
|
base::MessageLoop::current()->PostDelayedTask(
|
|
|
|
FROM_HERE,
|
|
|
|
window_unresposive_closure_.callback(),
|
|
|
|
base::TimeDelta::FromMilliseconds(ms));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowUnresponsive() {
|
|
|
|
window_unresposive_closure_.Cancel();
|
|
|
|
|
2014-05-09 04:08:15 +00:00
|
|
|
if (!is_closed_ && !HasModalDialog())
|
2014-03-25 10:10:51 +00:00
|
|
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
|
|
|
observers_,
|
|
|
|
OnRendererUnresponsive());
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:03:29 +00:00
|
|
|
void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
|
2013-11-21 13:50:06 +00:00
|
|
|
bool succeed,
|
|
|
|
const SkBitmap& bitmap) {
|
2014-11-24 05:44:45 +00:00
|
|
|
SkAutoLockPixels screen_capture_lock(bitmap);
|
2013-11-21 13:50:06 +00:00
|
|
|
std::vector<unsigned char> data;
|
2013-11-21 14:03:29 +00:00
|
|
|
if (succeed)
|
|
|
|
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &data);
|
|
|
|
callback.Run(data);
|
2013-11-21 13:50:06 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 16:10:57 +00:00
|
|
|
void NativeWindow::CallDevToolsFunction(const std::string& function_name,
|
|
|
|
const base::Value* arg1,
|
|
|
|
const base::Value* arg2,
|
|
|
|
const base::Value* arg3) {
|
|
|
|
std::string params;
|
|
|
|
if (arg1) {
|
|
|
|
std::string json;
|
|
|
|
base::JSONWriter::Write(arg1, &json);
|
|
|
|
params.append(json);
|
|
|
|
if (arg2) {
|
|
|
|
base::JSONWriter::Write(arg2, &json);
|
|
|
|
params.append(", " + json);
|
|
|
|
if (arg3) {
|
|
|
|
base::JSONWriter::Write(arg3, &json);
|
|
|
|
params.append(", " + json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-09 07:41:16 +00:00
|
|
|
base::string16 javascript =
|
|
|
|
base::UTF8ToUTF16(function_name + "(" + params + ");");
|
|
|
|
GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
2014-04-04 16:10:57 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
} // namespace atom
|