Skip to content

Commit d69b242

Browse files
committed
Merge branch 'master' into transparency
Conflicts: src/api/window/window.cc src/browser/native_window.cc src/browser/native_window_win.cc
2 parents cba4197 + c94237a commit d69b242

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1108
-212
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ Jeroen Ransijn <jssrdesign@gmail.com>
1515
Ivo Georgiev <ivo@linvo.org>
1616
Krill Izotov <enykeev@gmail.com>
1717
Zhang Chaobin <zhchbin@gmail.com>
18+
Michael Morrison <mmorrison@wootalyzer.com>
19+
William Towe <willbur1984@gmail.com>

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Introduction
1+
## Introduction
22

33
node-webkit is an app runtime based on `Chromium` and `node.js`. You can
44
write native apps in HTML and Javascript with node-webkit. It also lets you
@@ -9,29 +9,30 @@ It's created and developed in Intel Open Source Technology Center.
99

1010
[Introduction to node-webkit (slides)](https://speakerdeck.com/u/zcbenz/p/node-webkit-app-runtime-based-on-chromium-and-node-dot-js).
1111

12-
# Features
12+
## Features
1313

1414
* Apps written in modern HTML5, CSS3, JS and WebGL.
1515
* Complete support for [Node.js APIs](http://nodejs.org/api/) and all its [third party modules](https://npmjs.org).
1616
* Good performance: Node and WebKit runs in the same thread: Function calls are made straightforward; objects are in the same heap and can just reference each other;
1717
* Easy to package and distribute apps.
1818
* Available on Linux, Mac OSX and Windows
1919

20-
# Downloads
20+
## Downloads
2121

22-
[v0.4.0 release note](https://groups.google.com/d/msg/node-webkit/bTqRSmcfJ_E/9njVffk-k4cJ)
22+
[v0.4.1 release note](https://groups.google.com/d/msg/node-webkit/1JgTNLOEpIs/e2e0FwH9TE4J)
2323

24-
Prebuilt binaries (v0.4.0Jan 18, 2013):
24+
Prebuilt binaries (v0.4.1Feb 1, 2013):
2525

26-
* Linux: [32bit](https://s3.amazonaws.com/node-webkit/v0.4.0/node-webkit-v0.4.0-linux-ia32.tar.gz) / [64bit](https://s3.amazonaws.com/node-webkit/v0.4.0/node-webkit-v0.4.0-linux-x64.tar.gz)
27-
* Windows: [win32](https://s3.amazonaws.com/node-webkit/v0.4.0/node-webkit-v0.4.0-win-ia32.zip)
28-
* Mac: [32bit, 10.7+](https://s3.amazonaws.com/node-webkit/v0.4.0/node-webkit-v0.4.0-osx-ia32.zip)
26+
* Linux: [32bit](https://s3.amazonaws.com/node-webkit/v0.4.1/node-webkit-v0.4.1-linux-ia32.tar.gz) / [64bit](https://s3.amazonaws.com/node-webkit/v0.4.1/node-webkit-v0.4.1-linux-x64.tar.gz)
27+
* Windows: [win32](https://s3.amazonaws.com/node-webkit/v0.4.1/node-webkit-v0.4.1-win-ia32.zip)
28+
* Mac: [32bit, 10.7+](https://s3.amazonaws.com/node-webkit/v0.4.1/node-webkit-v0.4.1-osx-ia32.zip)
2929

3030
[Looking for older versions?](https://github.com/rogerwang/node-webkit/wiki/Downloads-of-old-versions)
3131

32+
###Demos and real apps
3233
You may also be interested in [our demos repository](https://github.com/zcbenz/nw-sample-apps) and the [List of apps and companies using node-webkit](https://github.com/rogerwang/node-webkit/wiki/List-of-apps-and-companies-using-node-webkit).
3334

34-
# Quick Start
35+
## Quick Start
3536

3637
Create `index.html`:
3738

@@ -72,7 +73,7 @@ $ ./nw app.nw
7273

7374
Note: on Windows, you can drag the `app.nw` to `nw.exe` to open it.
7475

75-
# Documents
76+
## Documents
7677

7778
For more information on how to write/package/run apps, see:
7879

@@ -82,11 +83,11 @@ For more information on how to write/package/run apps, see:
8283

8384
And our [Wiki](https://github.com/rogerwang/node-webkit/wiki) for much more.
8485

85-
# Community
86+
## Community
8687

8788
We use [node-webkit group](http://groups.google.com/group/node-webkit) as
8889
our mailing list, subscribe via [node-webkit+subscribe@googlegroups.com](mailto:node-webkit+subscribe@googlegroups.com).
8990

90-
# License
91+
## License
9192

9293
`node-webkit`'s code uses the MIT license, see our `LICENSE` file.

nw.gypi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129
'src/api/window/window.h',
130130
'src/browser/app_controller_mac.h',
131131
'src/browser/app_controller_mac.mm',
132+
'src/browser/capture_page_helper.h',
133+
'src/browser/capture_page_helper.cc',
132134
'src/browser/file_select_helper.cc',
133135
'src/browser/file_select_helper.h',
134136
'src/browser/native_window.cc',
@@ -148,6 +150,9 @@
148150
'src/browser/shell_devtools_delegate.h',
149151
'src/browser/shell_download_manager_delegate.cc',
150152
'src/browser/shell_download_manager_delegate.h',
153+
'src/browser/shell_download_manager_delegate_win.cc',
154+
'src/browser/shell_download_manager_delegate_gtk.cc',
155+
'src/browser/shell_download_manager_delegate_mac.mm',
151156
'src/browser/shell_javascript_dialog_creator.cc',
152157
'src/browser/shell_javascript_dialog_creator.h',
153158
'src/browser/shell_javascript_dialog_gtk.cc',
@@ -198,8 +203,12 @@
198203
'src/paths_mac.mm',
199204
'src/renderer/autofill_agent.h',
200205
'src/renderer/autofill_agent.cc',
206+
'src/renderer/common/render_messages.cc',
207+
'src/renderer/common/render_messages.h',
201208
'src/renderer/prerenderer/prerenderer_client.cc',
202209
'src/renderer/prerenderer/prerenderer_client.h',
210+
'src/renderer/nw_render_view_observer.cc',
211+
'src/renderer/nw_render_view_observer.h',
203212
'src/renderer/shell_content_renderer_client.cc',
204213
'src/renderer/shell_content_renderer_client.h',
205214
'src/renderer/shell_render_process_observer.cc',

src/api/dispatcher_host.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ void DispatcherHost::OnCreateShell(const std::string& url,
211211
&new_renderer) && new_renderer)
212212
browser_context->set_pinning_renderer(false);
213213

214-
WebContents::CreateParams create_params(
215-
browser_context,
216-
base_web_contents->GetSiteInstance());
214+
WebContents::CreateParams create_params(browser_context, NULL);
217215

218216
WebContents* web_contents = content::WebContentsImpl::CreateWithOpener(
219217
create_params,

src/api/menu/menu_win.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ void Menu::Rebuild(const gfx::NativeMenu *parent_menu) {
144144
if (is_menu_modified_) {
145145
// Refresh menu before show.
146146
menu_->Rebuild();
147+
menu_->UpdateStates();
147148
for (size_t index = 0; index < icon_bitmaps_.size(); ++index) {
148149
::DeleteObject(icon_bitmaps_[index]);
149150
}

src/api/window/window.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ void Window::Call(const std::string& method,
122122
shell_->window()->BeginOffclientMouseMove();
123123
} else if (method == "EndOffclientMouseMove") {
124124
shell_->window()->EndOffclientMouseMove();
125+
} else if (method == "CapturePage") {
126+
std::string image_format_str;
127+
if (arguments.GetString(0, &image_format_str))
128+
shell_->window()->CapturePage(image_format_str);
125129
} else {
126130
NOTREACHED() << "Invalid call to Window method:" << method
127131
<< " arguments:" << arguments;

src/api/window_bindings.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,18 @@ Window.prototype.reloadDev = function() {
341341
this.reload(3);
342342
}
343343

344+
Window.prototype.capturePage = function(callback, image_format) {
345+
if (image_format != 'jpeg' && image_format != 'png') {
346+
image_format = 'jpeg';
347+
}
348+
349+
if (typeof callback == 'function') {
350+
this.once('capturepagedone', function(imgdata) {
351+
callback(imgdata);
352+
});
353+
}
354+
355+
CallObjectMethod(this, 'CapturePage', [image_format]);
356+
}
357+
344358
} // function Window.init

src/browser/capture_page_helper.cc

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// Copyright (c) 2012 Intel Corp
2+
// Copyright (c) 2012 The Chromium Authors
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
8+
// pies of the Software, and to permit persons to whom the Software is furnished
9+
// to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in al
12+
// l copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
15+
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
16+
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
17+
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
18+
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
21+
#include "content/nw/src/browser/capture_page_helper.h"
22+
23+
#include <vector>
24+
25+
#include "base/base64.h"
26+
#include "base/bind.h"
27+
#include "base/stl_util.h"
28+
#include "base/stringprintf.h"
29+
#include "content/nw/src/api/api_messages.h"
30+
#include "content/nw/src/nw_shell.h"
31+
#include "content/nw/src/renderer/common/render_messages.h"
32+
#include "content/public/browser/render_view_host.h"
33+
#include "content/public/browser/render_widget_host_view.h"
34+
#include "content/public/browser/web_contents.h"
35+
#include "skia/ext/platform_canvas.h"
36+
#include "ui/gfx/codec/jpeg_codec.h"
37+
#include "ui/gfx/codec/png_codec.h"
38+
#include "ui/gfx/rect.h"
39+
40+
namespace nw {
41+
42+
namespace capture_page_helper_constants {
43+
44+
const char kFormatValueJpeg[] = "jpeg";
45+
const char kFormatValuePng[] = "png";
46+
const char kMimeTypeJpeg[] = "image/jpeg";
47+
const char kMimeTypePng[] = "image/png";
48+
49+
const int kDefaultQuality = 90;
50+
51+
}; // namespace capture_page_helper_constants
52+
53+
namespace keys = nw::capture_page_helper_constants;
54+
55+
// static
56+
scoped_refptr<CapturePageHelper> CapturePageHelper::Create(
57+
content::Shell* shell) {
58+
return make_scoped_refptr(new CapturePageHelper(shell));
59+
}
60+
61+
CapturePageHelper::CapturePageHelper(content::Shell *shell)
62+
: content::WebContentsObserver(shell->web_contents()),
63+
shell_(shell) {
64+
}
65+
66+
CapturePageHelper::~CapturePageHelper() {
67+
}
68+
69+
void CapturePageHelper::StartCapturePage(const std::string& image_format_str) {
70+
image_format_ = FORMAT_JPEG; // default image format.
71+
if (image_format_str == keys::kFormatValueJpeg) {
72+
image_format_ = FORMAT_JPEG;
73+
} else if (image_format_str == keys::kFormatValuePng) {
74+
image_format_ = FORMAT_PNG;
75+
} else {
76+
NOTREACHED() << "Invalid image format";
77+
}
78+
79+
content::WebContents* web_contents = shell_->web_contents();
80+
content::RenderViewHost* render_view_host =
81+
web_contents->GetRenderViewHost();
82+
content::RenderWidgetHostView* view = render_view_host->GetView();
83+
84+
if (!view) {
85+
VLOG(1) << "Get RenderViewWidgetHostView Failed.";
86+
return;
87+
}
88+
89+
skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap;
90+
render_view_host->CopyFromBackingStore(
91+
gfx::Rect(),
92+
view->GetViewBounds().size(),
93+
base::Bind(&CapturePageHelper::CopyFromBackingStoreComplete,
94+
this,
95+
base::Owned(temp_bitmap)),
96+
temp_bitmap);
97+
}
98+
99+
void CapturePageHelper::CopyFromBackingStoreComplete(
100+
skia::PlatformBitmap* bitmap,
101+
bool succeeded) {
102+
if (succeeded) {
103+
// Get image from backing store.
104+
SendResultFromBitmap(bitmap->GetBitmap());
105+
return;
106+
}
107+
108+
// Ask the renderer for a snapshot.
109+
Send(new NwViewMsg_CaptureSnapshot(routing_id()));
110+
}
111+
112+
void CapturePageHelper::SendResultFromBitmap(const SkBitmap& screen_capture) {
113+
std::vector<unsigned char> data;
114+
SkAutoLockPixels screen_capture_lock(screen_capture);
115+
bool encoded = false;
116+
std::string mime_type;
117+
switch (image_format_) {
118+
case FORMAT_JPEG:
119+
encoded = gfx::JPEGCodec::Encode(
120+
reinterpret_cast<unsigned char*>(screen_capture.getAddr32(0, 0)),
121+
gfx::JPEGCodec::FORMAT_SkBitmap,
122+
screen_capture.width(),
123+
screen_capture.height(),
124+
static_cast<int>(screen_capture.rowBytes()),
125+
keys::kDefaultQuality,
126+
&data);
127+
mime_type = keys::kMimeTypeJpeg;
128+
break;
129+
case FORMAT_PNG:
130+
encoded = gfx::PNGCodec::EncodeBGRASkBitmap(
131+
screen_capture,
132+
true, // Discard transparency.
133+
&data);
134+
mime_type = keys::kMimeTypePng;
135+
break;
136+
default:
137+
NOTREACHED() << "Invalid image format.";
138+
}
139+
140+
if (!encoded) {
141+
VLOG(1) << "Encoding failed.";
142+
return;
143+
}
144+
145+
std::string base64_result;
146+
base::StringPiece stream_as_string(
147+
reinterpret_cast<const char*>(vector_as_array(&data)), data.size());
148+
149+
base::Base64Encode(stream_as_string, &base64_result);
150+
base64_result.insert(0, base::StringPrintf("data:%s;base64,",
151+
mime_type.c_str()));
152+
153+
shell_->SendEvent("capturepagedone", base64_result);
154+
}
155+
156+
void CapturePageHelper::OnSnapshot(const SkBitmap& bitmap) {
157+
SendResultFromBitmap(bitmap);
158+
}
159+
160+
////////////////////////////////////////////////////////////////////////////////
161+
// WebContentsObserver overrides
162+
bool CapturePageHelper::OnMessageReceived(const IPC::Message& message) {
163+
bool handled = true;
164+
IPC_BEGIN_MESSAGE_MAP(CapturePageHelper, message)
165+
IPC_MESSAGE_HANDLER(NwViewHostMsg_Snapshot, OnSnapshot)
166+
IPC_MESSAGE_UNHANDLED(handled = false)
167+
IPC_END_MESSAGE_MAP()
168+
return handled;
169+
}
170+
171+
} // namespace nw

0 commit comments

Comments
 (0)