Skip to content

Commit

Permalink
Merge pull request #1 from rogerwang/master
Browse files Browse the repository at this point in the history
Update from base
  • Loading branch information
trevorlinton committed Feb 11, 2013
2 parents ce7f335 + 549e3a8 commit c94237a
Show file tree
Hide file tree
Showing 46 changed files with 1,108 additions and 212 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Jeroen Ransijn <[email protected]>
Ivo Georgiev <[email protected]>
Krill Izotov <[email protected]>
Zhang Chaobin <[email protected]>
Michael Morrison <[email protected]>
William Towe <[email protected]>
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Introduction
## Introduction

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

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

# Features
## Features

* Apps written in modern HTML5, CSS3, JS and WebGL.
* Complete support for [Node.js APIs](http://nodejs.org/api/) and all its [third party modules](https://npmjs.org).
* 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;
* Easy to package and distribute apps.
* Available on Linux, Mac OSX and Windows

# Downloads
## Downloads

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

Prebuilt binaries (v0.4.0Jan 18, 2013):
Prebuilt binaries (v0.4.1Feb 1, 2013):

* 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)
* Windows: [win32](https://s3.amazonaws.com/node-webkit/v0.4.0/node-webkit-v0.4.0-win-ia32.zip)
* Mac: [32bit, 10.7+](https://s3.amazonaws.com/node-webkit/v0.4.0/node-webkit-v0.4.0-osx-ia32.zip)
* 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)
* Windows: [win32](https://s3.amazonaws.com/node-webkit/v0.4.1/node-webkit-v0.4.1-win-ia32.zip)
* Mac: [32bit, 10.7+](https://s3.amazonaws.com/node-webkit/v0.4.1/node-webkit-v0.4.1-osx-ia32.zip)

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

###Demos and real apps
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).

# Quick Start
## Quick Start

Create `index.html`:

Expand Down Expand Up @@ -72,7 +73,7 @@ $ ./nw app.nw

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

# Documents
## Documents

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

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

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

# Community
## Community

We use [node-webkit group](http://groups.google.com/group/node-webkit) as
our mailing list, subscribe via [[email protected]](mailto:[email protected]).

# License
## License

`node-webkit`'s code uses the MIT license, see our `LICENSE` file.
9 changes: 9 additions & 0 deletions nw.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
'src/api/window/window.h',
'src/browser/app_controller_mac.h',
'src/browser/app_controller_mac.mm',
'src/browser/capture_page_helper.h',
'src/browser/capture_page_helper.cc',
'src/browser/file_select_helper.cc',
'src/browser/file_select_helper.h',
'src/browser/native_window.cc',
Expand All @@ -148,6 +150,9 @@
'src/browser/shell_devtools_delegate.h',
'src/browser/shell_download_manager_delegate.cc',
'src/browser/shell_download_manager_delegate.h',
'src/browser/shell_download_manager_delegate_win.cc',
'src/browser/shell_download_manager_delegate_gtk.cc',
'src/browser/shell_download_manager_delegate_mac.mm',
'src/browser/shell_javascript_dialog_creator.cc',
'src/browser/shell_javascript_dialog_creator.h',
'src/browser/shell_javascript_dialog_gtk.cc',
Expand Down Expand Up @@ -198,8 +203,12 @@
'src/paths_mac.mm',
'src/renderer/autofill_agent.h',
'src/renderer/autofill_agent.cc',
'src/renderer/common/render_messages.cc',
'src/renderer/common/render_messages.h',
'src/renderer/prerenderer/prerenderer_client.cc',
'src/renderer/prerenderer/prerenderer_client.h',
'src/renderer/nw_render_view_observer.cc',
'src/renderer/nw_render_view_observer.h',
'src/renderer/shell_content_renderer_client.cc',
'src/renderer/shell_content_renderer_client.h',
'src/renderer/shell_render_process_observer.cc',
Expand Down
4 changes: 1 addition & 3 deletions src/api/dispatcher_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ void DispatcherHost::OnCreateShell(const std::string& url,
&new_renderer) && new_renderer)
browser_context->set_pinning_renderer(false);

WebContents::CreateParams create_params(
browser_context,
base_web_contents->GetSiteInstance());
WebContents::CreateParams create_params(browser_context, NULL);

WebContents* web_contents = content::WebContentsImpl::CreateWithOpener(
create_params,
Expand Down
1 change: 1 addition & 0 deletions src/api/menu/menu_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void Menu::Rebuild(const gfx::NativeMenu *parent_menu) {
if (is_menu_modified_) {
// Refresh menu before show.
menu_->Rebuild();
menu_->UpdateStates();
for (size_t index = 0; index < icon_bitmaps_.size(); ++index) {
::DeleteObject(icon_bitmaps_[index]);
}
Expand Down
4 changes: 4 additions & 0 deletions src/api/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ void Window::Call(const std::string& method,
int type;
if (arguments.GetInteger(0, &type))
shell_->Reload(static_cast<content::Shell::ReloadType>(type));
} else if (method == "CapturePage") {
std::string image_format_str;
if (arguments.GetString(0, &image_format_str))
shell_->window()->CapturePage(image_format_str);
} else {
NOTREACHED() << "Invalid call to Window method:" << method
<< " arguments:" << arguments;
Expand Down
14 changes: 14 additions & 0 deletions src/api/window_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,18 @@ Window.prototype.reloadDev = function() {
this.reload(3);
}

Window.prototype.capturePage = function(callback, image_format) {
if (image_format != 'jpeg' && image_format != 'png') {
image_format = 'jpeg';
}

if (typeof callback == 'function') {
this.once('capturepagedone', function(imgdata) {
callback(imgdata);
});
}

CallObjectMethod(this, 'CapturePage', [image_format]);
}

} // function Window.init
171 changes: 171 additions & 0 deletions src/browser/capture_page_helper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Copyright (c) 2012 Intel Corp
// Copyright (c) 2012 The Chromium Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
// pies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "content/nw/src/browser/capture_page_helper.h"

#include <vector>

#include "base/base64.h"
#include "base/bind.h"
#include "base/stl_util.h"
#include "base/stringprintf.h"
#include "content/nw/src/api/api_messages.h"
#include "content/nw/src/nw_shell.h"
#include "content/nw/src/renderer/common/render_messages.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "skia/ext/platform_canvas.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/rect.h"

namespace nw {

namespace capture_page_helper_constants {

const char kFormatValueJpeg[] = "jpeg";
const char kFormatValuePng[] = "png";
const char kMimeTypeJpeg[] = "image/jpeg";
const char kMimeTypePng[] = "image/png";

const int kDefaultQuality = 90;

}; // namespace capture_page_helper_constants

namespace keys = nw::capture_page_helper_constants;

// static
scoped_refptr<CapturePageHelper> CapturePageHelper::Create(
content::Shell* shell) {
return make_scoped_refptr(new CapturePageHelper(shell));
}

CapturePageHelper::CapturePageHelper(content::Shell *shell)
: content::WebContentsObserver(shell->web_contents()),
shell_(shell) {
}

CapturePageHelper::~CapturePageHelper() {
}

void CapturePageHelper::StartCapturePage(const std::string& image_format_str) {
image_format_ = FORMAT_JPEG; // default image format.
if (image_format_str == keys::kFormatValueJpeg) {
image_format_ = FORMAT_JPEG;
} else if (image_format_str == keys::kFormatValuePng) {
image_format_ = FORMAT_PNG;
} else {
NOTREACHED() << "Invalid image format";
}

content::WebContents* web_contents = shell_->web_contents();
content::RenderViewHost* render_view_host =
web_contents->GetRenderViewHost();
content::RenderWidgetHostView* view = render_view_host->GetView();

if (!view) {
VLOG(1) << "Get RenderViewWidgetHostView Failed.";
return;
}

skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap;
render_view_host->CopyFromBackingStore(
gfx::Rect(),
view->GetViewBounds().size(),
base::Bind(&CapturePageHelper::CopyFromBackingStoreComplete,
this,
base::Owned(temp_bitmap)),
temp_bitmap);
}

void CapturePageHelper::CopyFromBackingStoreComplete(
skia::PlatformBitmap* bitmap,
bool succeeded) {
if (succeeded) {
// Get image from backing store.
SendResultFromBitmap(bitmap->GetBitmap());
return;
}

// Ask the renderer for a snapshot.
Send(new NwViewMsg_CaptureSnapshot(routing_id()));
}

void CapturePageHelper::SendResultFromBitmap(const SkBitmap& screen_capture) {
std::vector<unsigned char> data;
SkAutoLockPixels screen_capture_lock(screen_capture);
bool encoded = false;
std::string mime_type;
switch (image_format_) {
case FORMAT_JPEG:
encoded = gfx::JPEGCodec::Encode(
reinterpret_cast<unsigned char*>(screen_capture.getAddr32(0, 0)),
gfx::JPEGCodec::FORMAT_SkBitmap,
screen_capture.width(),
screen_capture.height(),
static_cast<int>(screen_capture.rowBytes()),
keys::kDefaultQuality,
&data);
mime_type = keys::kMimeTypeJpeg;
break;
case FORMAT_PNG:
encoded = gfx::PNGCodec::EncodeBGRASkBitmap(
screen_capture,
true, // Discard transparency.
&data);
mime_type = keys::kMimeTypePng;
break;
default:
NOTREACHED() << "Invalid image format.";
}

if (!encoded) {
VLOG(1) << "Encoding failed.";
return;
}

std::string base64_result;
base::StringPiece stream_as_string(
reinterpret_cast<const char*>(vector_as_array(&data)), data.size());

base::Base64Encode(stream_as_string, &base64_result);
base64_result.insert(0, base::StringPrintf("data:%s;base64,",
mime_type.c_str()));

shell_->SendEvent("capturepagedone", base64_result);
}

void CapturePageHelper::OnSnapshot(const SkBitmap& bitmap) {
SendResultFromBitmap(bitmap);
}

////////////////////////////////////////////////////////////////////////////////
// WebContentsObserver overrides
bool CapturePageHelper::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(CapturePageHelper, message)
IPC_MESSAGE_HANDLER(NwViewHostMsg_Snapshot, OnSnapshot)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}

} // namespace nw
Loading

0 comments on commit c94237a

Please sign in to comment.