-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rogerwang/master
Update from base
- Loading branch information
Showing
46 changed files
with
1,108 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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.0 — Jan 18, 2013): | ||
Prebuilt binaries (v0.4.1 — Feb 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`: | ||
|
||
|
@@ -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: | ||
|
||
|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.