summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authorbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-07 23:51:10 +0000
committerbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-07 23:51:10 +0000
commit038687dc0399a3228985fc168e12015aaba25798 (patch)
tree856182760b08d3a8c517096771f733bb8e335d1c /native_client_sdk
parentbb3ce678a5f19ef41a98e0979b850c4ab799d944 (diff)
downloadchromium_src-038687dc0399a3228985fc168e12015aaba25798.zip
chromium_src-038687dc0399a3228985fc168e12015aaba25798.tar.gz
chromium_src-038687dc0399a3228985fc168e12015aaba25798.tar.bz2
[NaCl SDK] Cleanup examples.
* Remove duplicated comments. * Rename main .cc/.c file to the name of the example. * Remove _module.cc files BUG=none R=noelallen@chromium.org Review URL: https://codereview.chromium.org/14607005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198828 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/examples/api/audio/audio.cc (renamed from native_client_sdk/src/examples/api/audio/sine_synth.cc)68
-rw-r--r--native_client_sdk/src/examples/api/audio/example.dsc4
-rw-r--r--native_client_sdk/src/examples/api/gamepad/example.dsc2
-rw-r--r--native_client_sdk/src/examples/api/gamepad/gamepad.cc105
-rw-r--r--native_client_sdk/src/examples/api/gamepad/gamepad.h72
-rw-r--r--native_client_sdk/src/examples/api/gamepad/gamepad_module.cc32
-rw-r--r--native_client_sdk/src/examples/api/graphics_3d/example.dsc4
-rw-r--r--native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc (renamed from native_client_sdk/src/examples/api/graphics_3d/hello_world.cc)11
-rw-r--r--native_client_sdk/src/examples/api/input_event/custom_events.cc4
-rw-r--r--native_client_sdk/src/examples/api/input_event/custom_events.h4
-rw-r--r--native_client_sdk/src/examples/api/input_event/example.dsc4
-rw-r--r--native_client_sdk/src/examples/api/input_event/input_event.cc (renamed from native_client_sdk/src/examples/api/input_event/input_events.cc)43
-rw-r--r--native_client_sdk/src/examples/api/input_event/shared_queue.h4
-rw-r--r--native_client_sdk/src/examples/api/mouse_lock/check_browser.js178
-rw-r--r--native_client_sdk/src/examples/api/mouse_lock/example.dsc4
-rw-r--r--native_client_sdk/src/examples/api/mouse_lock/mouse_lock.cc (renamed from native_client_sdk/src/examples/api/mouse_lock/mouselock.cc)12
-rw-r--r--native_client_sdk/src/examples/api/mouse_lock/mouse_lock.h (renamed from native_client_sdk/src/examples/api/mouse_lock/mouselock.h)6
-rw-r--r--native_client_sdk/src/examples/api/url_loader/example.dsc10
-rw-r--r--native_client_sdk/src/examples/api/url_loader/geturl_success.html20
-rw-r--r--native_client_sdk/src/examples/api/url_loader/index.html4
-rw-r--r--native_client_sdk/src/examples/api/url_loader/url_loader.cc (renamed from native_client_sdk/src/examples/api/url_loader/geturl.cc)44
-rw-r--r--native_client_sdk/src/examples/api/url_loader/url_loader_handler.cc (renamed from native_client_sdk/src/examples/api/url_loader/geturl_handler.cc)46
-rw-r--r--native_client_sdk/src/examples/api/url_loader/url_loader_handler.h (renamed from native_client_sdk/src/examples/api/url_loader/geturl_handler.h)31
-rw-r--r--native_client_sdk/src/examples/api/url_loader/url_loader_success.html17
-rw-r--r--native_client_sdk/src/examples/api/var_array_buffer/example.dsc4
-rw-r--r--native_client_sdk/src/examples/api/var_array_buffer/index.html2
-rw-r--r--native_client_sdk/src/examples/api/var_array_buffer/var_array_buffer.cc (renamed from native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc)61
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/example.dsc6
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/handlers.c2
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c (renamed from native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.c)2
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h (renamed from native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h)6
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/example.dsc6
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc166
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/pi_generator.h108
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc32
-rw-r--r--native_client_sdk/src/examples/tutorial/debugging/debugging.c (renamed from native_client_sdk/src/examples/tutorial/debugging/hello_world.c)2
-rw-r--r--native_client_sdk/src/examples/tutorial/debugging/example.dsc2
-rw-r--r--native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc44
-rw-r--r--native_client_sdk/src/examples/tutorial/load_progress/check_browser.js178
-rw-r--r--native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc40
40 files changed, 381 insertions, 1009 deletions
diff --git a/native_client_sdk/src/examples/api/audio/sine_synth.cc b/native_client_sdk/src/examples/api/audio/audio.cc
index 3e31930..27daf57 100644
--- a/native_client_sdk/src/examples/api/audio/sine_synth.cc
+++ b/native_client_sdk/src/examples/api/audio/audio.cc
@@ -26,26 +26,15 @@ const uint32_t kSampleFrameCount = 4096u;
const uint32_t kChannels = 2u;
} // namespace
-namespace sine_synth {
-// The Instance class. One of these exists for each instance of your NaCl
-// module on the web page. The browser will ask the Module object to create
-// a new Instance for each occurrence of the <embed> tag that has these
-// attributes:
-// type="application/x-nacl"
-// src="sine_synth.nmf"
-class SineSynthInstance : public pp::Instance {
+class AudioInstance : public pp::Instance {
public:
- explicit SineSynthInstance(PP_Instance instance)
+ explicit AudioInstance(PP_Instance instance)
: pp::Instance(instance),
frequency_(kDefaultFrequency),
theta_(0),
sample_frame_count_(kSampleFrameCount) {}
- virtual ~SineSynthInstance() {}
+ virtual ~AudioInstance() {}
- // Called by the browser once the NaCl module is loaded and ready to
- // initialize. Creates a Pepper audio context and initializes it. Returns
- // true on success. Returning false causes the NaCl module to be deleted and
- // no other functions to be called.
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
// Called by the browser to handle the postMessage() call in Javascript.
@@ -71,26 +60,24 @@ class SineSynthInstance : public pp::Instance {
static void SineWaveCallback(void* samples,
uint32_t buffer_size,
void* data) {
- SineSynthInstance* sine_synth_instance =
- reinterpret_cast<SineSynthInstance*>(data);
- const double frequency = sine_synth_instance->frequency();
+ AudioInstance* instance = reinterpret_cast<AudioInstance*>(data);
+ const double frequency = instance->frequency();
const double delta = kTwoPi * frequency / PP_AUDIOSAMPLERATE_44100;
const int16_t max_int16 = std::numeric_limits<int16_t>::max();
int16_t* buff = reinterpret_cast<int16_t*>(samples);
// Make sure we can't write outside the buffer.
- assert(buffer_size >= (sizeof(*buff) * kChannels *
- sine_synth_instance->sample_frame_count_));
+ assert(buffer_size >=
+ (sizeof(*buff) * kChannels * instance->sample_frame_count_));
- for (size_t sample_i = 0;
- sample_i < sine_synth_instance->sample_frame_count_;
- ++sample_i, sine_synth_instance->theta_ += delta) {
+ for (size_t sample_i = 0; sample_i < instance->sample_frame_count_;
+ ++sample_i, instance->theta_ += delta) {
// Keep theta_ from going beyond 2*Pi.
- if (sine_synth_instance->theta_ > kTwoPi) {
- sine_synth_instance->theta_ -= kTwoPi;
+ if (instance->theta_ > kTwoPi) {
+ instance->theta_ -= kTwoPi;
}
- double sin_value(std::sin(sine_synth_instance->theta_));
+ double sin_value(std::sin(instance->theta_));
int16_t scaled_value = static_cast<int16_t>(sin_value * max_int16);
for (size_t channel = 0; channel < kChannels; ++channel) {
*buff++ = scaled_value;
@@ -109,9 +96,9 @@ class SineSynthInstance : public pp::Instance {
uint32_t sample_frame_count_;
};
-bool SineSynthInstance::Init(uint32_t argc,
- const char* argn[],
- const char* argv[]) {
+bool AudioInstance::Init(uint32_t argc,
+ const char* argn[],
+ const char* argv[]) {
// Ask the device for an appropriate sample count size.
sample_frame_count_ = pp::AudioConfig::RecommendSampleFrameCount(
this, PP_AUDIOSAMPLERATE_44100, kSampleFrameCount);
@@ -123,7 +110,7 @@ bool SineSynthInstance::Init(uint32_t argc,
return true;
}
-void SineSynthInstance::HandleMessage(const pp::Var& var_message) {
+void AudioInstance::HandleMessage(const pp::Var& var_message) {
if (!var_message.is_string()) {
return;
}
@@ -148,32 +135,21 @@ void SineSynthInstance::HandleMessage(const pp::Var& var_message) {
}
}
-void SineSynthInstance::SetFrequency(double frequency) {
+void AudioInstance::SetFrequency(double frequency) {
frequency_ = frequency;
PostMessage(pp::Var(frequency_));
}
-// The Module class. The browser calls the CreateInstance() method to create
-// an instance of your NaCl module on the web page. The browser creates a new
-// instance for each <embed> tag with type="application/x-nacl".
-class SineSynthModule : public pp::Module {
+class AudioModule : public pp::Module {
public:
- SineSynthModule() : pp::Module() {}
- ~SineSynthModule() {}
+ AudioModule() : pp::Module() {}
+ ~AudioModule() {}
- // Create and return a HelloWorldInstance object.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new SineSynthInstance(instance);
+ return new AudioInstance(instance);
}
};
-} // namespace sine_synth
-
-// Factory function called by the browser when the module is first loaded.
-// The browser keeps a singleton of this module. It calls the
-// CreateInstance() method on the object you return to make instances. There
-// is one instance per <embed> tag on the page. This is the main binding
-// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() { return new sine_synth::SineSynthModule(); }
+Module* CreateModule() { return new AudioModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/api/audio/example.dsc b/native_client_sdk/src/examples/api/audio/example.dsc
index e401dc7..4d4e307 100644
--- a/native_client_sdk/src/examples/api/audio/example.dsc
+++ b/native_client_sdk/src/examples/api/audio/example.dsc
@@ -2,9 +2,9 @@
'TOOLS': ['newlib', 'glibc', 'pnacl', 'win', 'linux'],
'TARGETS': [
{
- 'NAME' : 'sine_synth',
+ 'NAME' : 'audio',
'TYPE' : 'main',
- 'SOURCES' : ['sine_synth.cc'],
+ 'SOURCES' : ['audio.cc'],
'LIBS': ['ppapi_cpp', 'ppapi', 'pthread']
}
],
diff --git a/native_client_sdk/src/examples/api/gamepad/example.dsc b/native_client_sdk/src/examples/api/gamepad/example.dsc
index 65a61bc..2087860 100644
--- a/native_client_sdk/src/examples/api/gamepad/example.dsc
+++ b/native_client_sdk/src/examples/api/gamepad/example.dsc
@@ -4,7 +4,7 @@
{
'NAME' : 'gamepad',
'TYPE' : 'main',
- 'SOURCES' : ['gamepad.cc', 'gamepad_module.cc', 'gamepad.h'],
+ 'SOURCES' : ['gamepad.cc'],
'LIBS': ['ppapi_cpp', 'ppapi', 'pthread']
}
],
diff --git a/native_client_sdk/src/examples/api/gamepad/gamepad.cc b/native_client_sdk/src/examples/api/gamepad/gamepad.cc
index 8e8b588..5b275ec 100644
--- a/native_client_sdk/src/examples/api/gamepad/gamepad.cc
+++ b/native_client_sdk/src/examples/api/gamepad/gamepad.cc
@@ -2,37 +2,71 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "gamepad.h"
-
#include <stdio.h>
#include <stdlib.h>
+
#include <cassert>
-#include <cmath>
-#include <cstring>
-#include <string>
+
#include "ppapi/c/ppb_gamepad.h"
-#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/cpp/graphics_2d.h"
+#include "ppapi/cpp/image_data.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/rect.h"
+#include "ppapi/cpp/size.h"
#include "ppapi/cpp/var.h"
+#include "ppapi/utility/completion_callback_factory.h"
-namespace {
+class GamepadInstance : public pp::Instance {
+ public:
+ explicit GamepadInstance(PP_Instance instance);
+ virtual ~GamepadInstance();
-// This is called by the browser when the 2D context has been flushed to the
-// browser window.
-void FlushCallback(void* data, int32_t result) {
- static_cast<gamepad::Gamepad*>(data)->set_flush_pending(false);
- static_cast<gamepad::Gamepad*>(data)->Paint();
-}
+ // Update the graphics context to the new size, and regenerate |pixel_buffer_|
+ // to fit the new size as well.
+ virtual void DidChangeView(const pp::View& view);
-} // namespace
+ // Flushes its contents of |pixel_buffer_| to the 2D graphics context.
+ void Paint();
-namespace gamepad {
+ int width() const {
+ return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
+ }
+ int height() const {
+ return pixel_buffer_ ? pixel_buffer_->size().height() : 0;
+ }
-Gamepad::Gamepad(PP_Instance instance)
+ // Indicate whether a flush is pending. This can only be called from the
+ // main thread; it is not thread safe.
+ bool flush_pending() const { return flush_pending_; }
+ void set_flush_pending(bool flag) { flush_pending_ = flag; }
+
+ private:
+ // Create and initialize the 2D context used for drawing.
+ void CreateContext(const pp::Size& size);
+ // Destroy the 2D drawing context.
+ void DestroyContext();
+ // Push the pixels to the browser, then attempt to flush the 2D context. If
+ // there is a pending flush on the 2D context, then update the pixels only
+ // and do not flush.
+ void FlushPixelBuffer();
+
+ void FlushCallback(int32_t result);
+
+ bool IsContextValid() const { return graphics_2d_context_ != NULL; }
+
+ pp::CompletionCallbackFactory<GamepadInstance> callback_factory_;
+ pp::Graphics2D* graphics_2d_context_;
+ pp::ImageData* pixel_buffer_;
+ const PPB_Gamepad* gamepad_;
+ bool flush_pending_;
+};
+
+GamepadInstance::GamepadInstance(PP_Instance instance)
: pp::Instance(instance),
+ callback_factory_(this),
graphics_2d_context_(NULL),
pixel_buffer_(NULL),
- flush_pending_(false),
- quit_(false) {
+ flush_pending_(false) {
pp::Module* module = pp::Module::Get();
assert(module);
gamepad_ = static_cast<const PPB_Gamepad*>(
@@ -40,13 +74,12 @@ Gamepad::Gamepad(PP_Instance instance)
assert(gamepad_);
}
-Gamepad::~Gamepad() {
- quit_ = true;
+GamepadInstance::~GamepadInstance() {
DestroyContext();
delete pixel_buffer_;
}
-void Gamepad::DidChangeView(const pp::View& view) {
+void GamepadInstance::DidChangeView(const pp::View& view) {
pp::Rect position = view.GetRect();
if (position.size().width() == width() &&
position.size().height() == height())
@@ -83,7 +116,7 @@ void FillRect(pp::ImageData* image,
}
}
-void Gamepad::Paint() {
+void GamepadInstance::Paint() {
// Clear the background.
FillRect(pixel_buffer_, 0, 0, width(), height(), 0xfff0f0f0);
@@ -123,7 +156,7 @@ void Gamepad::Paint() {
FlushPixelBuffer();
}
-void Gamepad::CreateContext(const pp::Size& size) {
+void GamepadInstance::CreateContext(const pp::Size& size) {
if (IsContextValid())
return;
graphics_2d_context_ = new pp::Graphics2D(this, size, false);
@@ -132,14 +165,14 @@ void Gamepad::CreateContext(const pp::Size& size) {
}
}
-void Gamepad::DestroyContext() {
+void GamepadInstance::DestroyContext() {
if (!IsContextValid())
return;
delete graphics_2d_context_;
graphics_2d_context_ = NULL;
}
-void Gamepad::FlushPixelBuffer() {
+void GamepadInstance::FlushPixelBuffer() {
if (!IsContextValid())
return;
// Note that the pixel lock is held while the buffer is copied into the
@@ -148,7 +181,25 @@ void Gamepad::FlushPixelBuffer() {
if (flush_pending())
return;
set_flush_pending(true);
- graphics_2d_context_->Flush(pp::CompletionCallback(&FlushCallback, this));
+ graphics_2d_context_->Flush(
+ callback_factory_.NewCallback(&GamepadInstance::FlushCallback));
}
-} // namespace gamepad
+void GamepadInstance::FlushCallback(int32_t result) {
+ set_flush_pending(false);
+ Paint();
+}
+
+class GamepadModule : public pp::Module {
+ public:
+ GamepadModule() : pp::Module() {}
+ virtual ~GamepadModule() {}
+
+ virtual pp::Instance* CreateInstance(PP_Instance instance) {
+ return new GamepadInstance(instance);
+ }
+};
+
+namespace pp {
+Module* CreateModule() { return new GamepadModule(); }
+} // namespace pp
diff --git a/native_client_sdk/src/examples/api/gamepad/gamepad.h b/native_client_sdk/src/examples/api/gamepad/gamepad.h
deleted file mode 100644
index 67649e0..0000000
--- a/native_client_sdk/src/examples/api/gamepad/gamepad.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef EXAMPLES_GAMEPAD_GAMEPAD_H_
-#define EXAMPLES_GAMEPAD_GAMEPAD_H_
-
-#include <map>
-#include <vector>
-#include "ppapi/c/ppb_gamepad.h"
-#include "ppapi/cpp/graphics_2d.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/rect.h"
-#include "ppapi/cpp/size.h"
-
-namespace gamepad {
-
-// The Instance class. One of these exists for each instance of your NaCl
-// module on the web page. The browser will ask the Module object to create
-// a new Instance for each occurrence of the <embed> tag that has these
-// attributes:
-// type="application/x-nacl"
-// nacl="pi_generator.nmf"
-class Gamepad : public pp::Instance {
- public:
- explicit Gamepad(PP_Instance instance);
- virtual ~Gamepad();
-
- // Update the graphics context to the new size, and regenerate |pixel_buffer_|
- // to fit the new size as well.
- virtual void DidChangeView(const pp::View& view);
-
- // Flushes its contents of |pixel_buffer_| to the 2D graphics context.
- void Paint();
-
- bool quit() const { return quit_; }
-
- int width() const {
- return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
- }
- int height() const {
- return pixel_buffer_ ? pixel_buffer_->size().height() : 0;
- }
-
- // Indicate whether a flush is pending. This can only be called from the
- // main thread; it is not thread safe.
- bool flush_pending() const { return flush_pending_; }
- void set_flush_pending(bool flag) { flush_pending_ = flag; }
-
- private:
- // Create and initialize the 2D context used for drawing.
- void CreateContext(const pp::Size& size);
- // Destroy the 2D drawing context.
- void DestroyContext();
- // Push the pixels to the browser, then attempt to flush the 2D context. If
- // there is a pending flush on the 2D context, then update the pixels only
- // and do not flush.
- void FlushPixelBuffer();
-
- bool IsContextValid() const { return graphics_2d_context_ != NULL; }
-
- pp::Graphics2D* graphics_2d_context_;
- pp::ImageData* pixel_buffer_;
- const PPB_Gamepad* gamepad_;
- bool flush_pending_;
- bool quit_;
-};
-
-} // namespace gamepad
-
-#endif // EXAMPLES_GAMEPAD_GAMEPAD_H_
diff --git a/native_client_sdk/src/examples/api/gamepad/gamepad_module.cc b/native_client_sdk/src/examples/api/gamepad/gamepad_module.cc
deleted file mode 100644
index f24968c..0000000
--- a/native_client_sdk/src/examples/api/gamepad/gamepad_module.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <ppapi/cpp/module.h>
-
-#include "gamepad.h"
-
-namespace gamepad {
-// The Module class. The browser calls the CreateInstance() method to create
-// an instance of your NaCl module on the web page. The browser creates a new
-// instance for each <embed> tag with type="application/x-nacl".
-class GamepadModule : public pp::Module {
- public:
- GamepadModule() : pp::Module() {}
- virtual ~GamepadModule() {}
-
- // Create and return a GamepadInstance object.
- virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new Gamepad(instance);
- }
-};
-} // namespace gamepad
-
-// Factory function called by the browser when the module is first loaded.
-// The browser keeps a singleton of this module. It calls the
-// CreateInstance() method on the object you return to make instances. There
-// is one instance per <embed> tag on the page. This is the main binding
-// point for your NaCl module with the browser.
-namespace pp {
-Module* CreateModule() { return new gamepad::GamepadModule(); }
-} // namespace pp
diff --git a/native_client_sdk/src/examples/api/graphics_3d/example.dsc b/native_client_sdk/src/examples/api/graphics_3d/example.dsc
index ea8377f..c7535b4 100644
--- a/native_client_sdk/src/examples/api/graphics_3d/example.dsc
+++ b/native_client_sdk/src/examples/api/graphics_3d/example.dsc
@@ -2,9 +2,9 @@
'TOOLS': ['newlib', 'glibc', 'pnacl', 'win', 'linux'],
'TARGETS': [
{
- 'NAME' : 'hello_world_gles',
+ 'NAME' : 'graphics_3d',
'TYPE' : 'main',
- 'SOURCES' : ['hello_world.cc', 'matrix.cc', 'matrix.h'],
+ 'SOURCES' : ['graphics_3d.cc', 'matrix.cc', 'matrix.h'],
'CXXFLAGS': [
'-I../../src',
'-I../../src/ppapi/lib/gl'
diff --git a/native_client_sdk/src/examples/api/graphics_3d/hello_world.cc b/native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc
index 9ba1941..b976c43 100644
--- a/native_client_sdk/src/examples/api/graphics_3d/hello_world.cc
+++ b/native_client_sdk/src/examples/api/graphics_3d/graphics_3d.cc
@@ -3,11 +3,6 @@
* found in the LICENSE file.
*/
-/** @file hello_world_gles.cc
- * This example demonstrates loading and running a simple 3D openGL ES 2.0
- * application.
- */
-
//-----------------------------------------------------------------------------
// The spinning Cube
//-----------------------------------------------------------------------------
@@ -21,11 +16,11 @@
#include <stdlib.h>
#include <string.h>
-#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_graphics_3d.h"
#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb.h"
#include "ppapi/c/ppb_core.h"
@@ -33,12 +28,12 @@
#include "ppapi/c/ppb_instance.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/c/ppb_opengles2.h"
+#include "ppapi/c/ppb_url_loader.h"
+#include "ppapi/c/ppb_url_request_info.h"
#include "ppapi/c/ppb_var.h"
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppp_messaging.h"
-#include "ppapi/c/ppb_url_loader.h"
-#include "ppapi/c/ppb_url_request_info.h"
#include "ppapi/c/ppp_graphics_3d.h"
#include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"
diff --git a/native_client_sdk/src/examples/api/input_event/custom_events.cc b/native_client_sdk/src/examples/api/input_event/custom_events.cc
index 9f2e6f4..4d92853 100644
--- a/native_client_sdk/src/examples/api/input_event/custom_events.cc
+++ b/native_client_sdk/src/examples/api/input_event/custom_events.cc
@@ -6,8 +6,6 @@
#include "custom_events.h"
-namespace event_queue {
-
// Convert a given modifier to a descriptive string. Note that the actual
// declared type of modifier in each of the event classes is uint32_t, but it is
// expected to be interpreted as a bitfield of 'or'ed PP_InputEvent_Modifier
@@ -150,5 +148,3 @@ std::string TouchEvent::ToString() const {
stream << " time:" << timestamp_ << "\n";
return stream.str();
}
-
-} // end namespace
diff --git a/native_client_sdk/src/examples/api/input_event/custom_events.h b/native_client_sdk/src/examples/api/input_event/custom_events.h
index fec2561..ca9b2b3 100644
--- a/native_client_sdk/src/examples/api/input_event/custom_events.h
+++ b/native_client_sdk/src/examples/api/input_event/custom_events.h
@@ -9,8 +9,6 @@
#include <string>
#include <vector>
-namespace event_queue {
-
// These functions and classes are used to define a non-Pepper set of
// events. This is typical of what many developers might do, since it
// would be common to convert a Pepper event into some other more
@@ -187,6 +185,4 @@ class TouchEvent : public Event {
double timestamp_;
};
-} // end namespace
-
#endif // CUSTOM_EVENTS_H
diff --git a/native_client_sdk/src/examples/api/input_event/example.dsc b/native_client_sdk/src/examples/api/input_event/example.dsc
index 4c88c56..5744367 100644
--- a/native_client_sdk/src/examples/api/input_event/example.dsc
+++ b/native_client_sdk/src/examples/api/input_event/example.dsc
@@ -7,7 +7,7 @@
'SOURCES' : [
'custom_events.cc',
'custom_events.h',
- 'input_events.cc',
+ 'input_event.cc',
'shared_queue.h',
],
'LIBS': ['ppapi_cpp', 'ppapi', 'pthread']
@@ -18,7 +18,7 @@
],
'DEST': 'examples/api',
'NAME': 'input_event',
- 'TITLE': 'Input Events',
+ 'TITLE': 'Input Event',
'GROUP': 'API',
}
diff --git a/native_client_sdk/src/examples/api/input_event/input_events.cc b/native_client_sdk/src/examples/api/input_event/input_event.cc
index 1a6b19085..f97b94e 100644
--- a/native_client_sdk/src/examples/api/input_event/input_events.cc
+++ b/native_client_sdk/src/examples/api/input_event/input_event.cc
@@ -26,7 +26,6 @@
#undef PostMessage
#endif
-namespace event_queue {
const char* const kDidChangeView = "DidChangeView\n";
const char* const kHandleInputEvent = "DidHandleInputEvent\n";
const char* const kDidChangeFocus = "DidChangeFocus\n";
@@ -74,9 +73,9 @@ unsigned int ConvertEventModifier(uint32_t pp_modifier) {
return custom_modifier;
}
-class EventInstance : public pp::Instance {
+class InputEventInstance : public pp::Instance {
public:
- explicit EventInstance(PP_Instance instance)
+ explicit InputEventInstance(PP_Instance instance)
: pp::Instance(instance), event_thread_(NULL), callback_factory_(this) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL |
PP_INPUTEVENT_CLASS_TOUCH);
@@ -85,7 +84,7 @@ class EventInstance : public pp::Instance {
// Not guaranteed to be called in Pepper, but a good idea to cancel the
// queue and signal to workers to die if it is called.
- virtual ~EventInstance() { CancelQueueAndWaitForWorker(); }
+ virtual ~InputEventInstance() { CancelQueueAndWaitForWorker(); }
// Create the 'worker thread'.
bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
@@ -114,13 +113,6 @@ class EventInstance : public pp::Instance {
PostMessage(pp::Var(kDidChangeView));
}
- /// Called by the browser to handle the postMessage() call in Javascript.
- /// Detects which method is being called from the message contents, and
- /// calls the appropriate function. Posts the result back to the browser
- /// asynchronously.
- /// @param[in] var_message The message posted by the browser. The only
- /// supported message is |kCancelMessage|. If we receive this, we
- /// cancel the shared queue.
virtual void HandleMessage(const pp::Var& var_message) {
std::string message = var_message.AsString();
if (kCancelMessage == message) {
@@ -281,7 +273,8 @@ class EventInstance : public pp::Instance {
// PostStringToBrowser will be called, which will call PostMessage
// to send the converted event back to the browser.
static void* ProcessEventOnWorkerThread(void* param) {
- EventInstance* event_instance = static_cast<EventInstance*>(param);
+ InputEventInstance* event_instance =
+ static_cast<InputEventInstance*>(param);
while (1) {
// Grab a generic Event* so that down below we can call
// event->ToString(), which will use the correct virtual method
@@ -300,8 +293,8 @@ class EventInstance : public pp::Instance {
// Need to invoke callback on main thread.
pp::Module::Get()->core()->CallOnMainThread(
0,
- event_instance->callback_factory()
- .NewCallback(&EventInstance::PostStringToBrowser, event_string));
+ event_instance->callback_factory().NewCallback(
+ &InputEventInstance::PostStringToBrowser, event_string));
} // end of while loop.
return 0;
}
@@ -309,7 +302,7 @@ class EventInstance : public pp::Instance {
// Return the callback factory.
// Allows the static method (ProcessEventOnWorkerThread) to use
// the |event_instance| pointer to get the factory.
- pp::CompletionCallbackFactory<EventInstance>& callback_factory() {
+ pp::CompletionCallbackFactory<InputEventInstance>& callback_factory() {
return callback_factory_;
}
@@ -327,27 +320,19 @@ class EventInstance : public pp::Instance {
}
pthread_t* event_thread_;
LockingQueue<Event*> event_queue_;
- pp::CompletionCallbackFactory<EventInstance> callback_factory_;
+ pp::CompletionCallbackFactory<InputEventInstance> callback_factory_;
};
-// The EventModule provides an implementation of pp::Module that creates
-// EventInstance objects when invoked. This is part of the glue code that makes
-// our example accessible to ppapi.
-class EventModule : public pp::Module {
+class InputEventModule : public pp::Module {
public:
- EventModule() : pp::Module() {}
- virtual ~EventModule() {}
+ InputEventModule() : pp::Module() {}
+ virtual ~InputEventModule() {}
virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new EventInstance(instance);
+ return new InputEventInstance(instance);
}
};
-} // namespace
-
-// Implement the required pp::CreateModule function that creates our specific
-// kind of Module (in this case, EventModule). This is part of the glue code
-// that makes our example accessible to ppapi.
namespace pp {
-Module* CreateModule() { return new event_queue::EventModule(); }
+Module* CreateModule() { return new InputEventModule(); }
}
diff --git a/native_client_sdk/src/examples/api/input_event/shared_queue.h b/native_client_sdk/src/examples/api/input_event/shared_queue.h
index ff13996..b3c1784 100644
--- a/native_client_sdk/src/examples/api/input_event/shared_queue.h
+++ b/native_client_sdk/src/examples/api/input_event/shared_queue.h
@@ -9,8 +9,6 @@
#include <cassert>
#include <deque>
-namespace event_queue {
-
// This file provides a queue that uses a mutex and condition variable so that
// one thread can put pointers into the queue and another thread can pull items
// out of the queue.
@@ -146,6 +144,4 @@ template <class T> class LockingQueue {
bool is_empty_no_locking() const { return the_queue_.empty(); }
};
-} // end of unnamed namespace
-
#endif // SHARED_QUEUE_H
diff --git a/native_client_sdk/src/examples/api/mouse_lock/check_browser.js b/native_client_sdk/src/examples/api/mouse_lock/check_browser.js
deleted file mode 100644
index 0c54ba4..0000000
--- a/native_client_sdk/src/examples/api/mouse_lock/check_browser.js
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/**
- * @fileoverview This file provides a BrowserChecker Javascript class.
- * Users can create a BrowserChecker object, invoke checkBrowser(|version|),
- * and then use getIsValidBrowser() and getBrowserSupportStatus()
- * to determine if the browser version is greater than |version|
- * and if the Native Client plugin is found.
- */
-
-// Create a namespace object
-var browser_version = browser_version || {};
-
-/**
- * Class to provide checking for version and NativeClient.
- * @param {integer} arg1 An argument that indicates major version of Chrome we
- * require, such as 14.
- */
-
-/**
- * Constructor for the BrowserChecker. Sets the major version of
- * Chrome that is required to |minChromeVersion|.
- * @param minChromeVersion The earliest major version of chrome that
- * is supported. If the Chrome browser version is less than
- * |minChromeVersion| then |isValidBrowswer| will be set to false.
- * @param opt_maxChromeVersion Ignored. Retained for backwards compatibility.
- * @param appVersion The application version string.
- * @param plugins The plugins that exist in the browser.
- * @constructor
- */
-browser_version.BrowserChecker = function(minChromeVersion,
- appVersion, plugins,
- opt_maxChromeVersion) {
- /**
- * Version specified by the user. This class looks to see if the browser
- * version is >= |minChromeVersion_|.
- * @type {integer}
- * @private
- */
- this.minChromeVersion_ = minChromeVersion;
-
- /**
- * List of Browser plugin objects.
- * @type {Ojbect array}
- * @private
- */
- this.plugins_ = plugins;
-
- /**
- * Application version string from the Browser.
- * @type {integer}
- * @private
- */
- this.appVersion_ = appVersion;
-
- /**
- * Flag used to indicate if the browser has Native Client and is if the
- * browser version is recent enough.
- * @type {boolean}
- * @private
- */
- this.isValidBrowser_ = false;
-
- /**
- * Actual major version of Chrome -- found by querying the browser.
- * @type {integer}
- * @private
- */
- this.chromeVersion_ = null;
-
- /**
- * Browser support status. This allows the user to get a detailed status
- * rather than using this.browserSupportMessage.
- */
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.UNKNOWN;
-}
-
-/**
- * The values used for BrowserChecker status to indicate success or
- * a specific error.
- * @enum {id}
- */
-browser_version.BrowserChecker.StatusValues = {
- UNKNOWN: 0,
- NACL_ENABLED: 1,
- UNKNOWN_BROWSER: 2,
- CHROME_VERSION_TOO_OLD: 3,
- NACL_NOT_ENABLED: 4,
- NOT_USING_SERVER: 5
-};
-
-/**
- * Determines if the plugin with name |name| exists in the browser.
- * @param {string} name The name of the plugin.
- * @param {Object array} plugins The plugins in this browser.
- * @return {bool} |true| if the plugin is found.
- */
-browser_version.BrowserChecker.prototype.pluginExists = function(name,
- plugins) {
- for (var index=0; index < plugins.length; index++) {
- var plugin = this.plugins_[index];
- var plugin_name = plugin['name'];
- // If the plugin is not found, you can use the Javascript console
- // to see the names of the plugins that were found when debugging.
- if (plugin_name.indexOf(name) != -1) {
- return true;
- }
- }
- return false;
-}
-
-/**
- * Returns browserSupportStatus_ which indicates if the browser supports
- * Native Client. Values are defined as literals in
- * browser_version.BrowserChecker.StatusValues.
- * @ return {int} Level of NaCl support.
- */
-browser_version.BrowserChecker.prototype.getBrowserSupportStatus = function() {
- return this.browserSupportStatus_;
-}
-
-/**
- * Returns isValidBrowser (true/false) to indicate if the browser supports
- * Native Client.
- * @ return {bool} If this browser has NativeClient and correct version.
- */
-browser_version.BrowserChecker.prototype.getIsValidBrowser = function() {
- return this.isValidBrowser_;
-}
-
-/**
- * Checks to see if this browser can support Native Client applications.
- * For Chrome browsers, checks to see if the "Native Client" plugin is
- * enabled.
- */
-browser_version.BrowserChecker.prototype.checkBrowser = function() {
- var versionPatt = /Chrome\/(\d+)\.(\d+)\.(\d+)\.(\d+)/;
- var result = this.appVersion_.match(versionPatt);
-
- // |result| stores the Chrome version number.
- if (!result) {
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.UNKNOWN_BROWSER;
- } else {
- this.chromeVersion_ = result[1];
- // We know we have Chrome, check version and/or plugin named Native Client
- if (this.chromeVersion_ >= this.minChromeVersion_) {
- var found_nacl = this.pluginExists('Native Client', this.plugins_);
- if (found_nacl) {
- this.isValidBrowser_ = true;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.NACL_ENABLED;
- } else {
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.NACL_NOT_ENABLED;
- }
- } else {
- // We are in a version that is less than |minChromeVersion_|
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.CHROME_VERSION_TOO_OLD;
- }
- }
- var my_protocol = window.location.protocol;
- if (my_protocol.indexOf('file') == 0) {
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.NOT_USING_SERVER;
- }
-}
-
diff --git a/native_client_sdk/src/examples/api/mouse_lock/example.dsc b/native_client_sdk/src/examples/api/mouse_lock/example.dsc
index 566c2c5..63b7fdf 100644
--- a/native_client_sdk/src/examples/api/mouse_lock/example.dsc
+++ b/native_client_sdk/src/examples/api/mouse_lock/example.dsc
@@ -3,9 +3,9 @@
'TOOLS': ['newlib', 'glibc', 'pnacl', 'win', 'linux'],
'TARGETS': [
{
- 'NAME' : 'mouselock',
+ 'NAME' : 'mouse_lock',
'TYPE' : 'main',
- 'SOURCES' : ['mouselock.cc', 'mouselock.h'],
+ 'SOURCES' : ['mouse_lock.cc', 'mouse_lock.h'],
'LIBS': ['ppapi_cpp', 'ppapi', 'pthread']
}
],
diff --git a/native_client_sdk/src/examples/api/mouse_lock/mouselock.cc b/native_client_sdk/src/examples/api/mouse_lock/mouse_lock.cc
index 4305b18..6c02b8f 100644
--- a/native_client_sdk/src/examples/api/mouse_lock/mouselock.cc
+++ b/native_client_sdk/src/examples/api/mouse_lock/mouse_lock.cc
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <cmath>
-#include <cstdlib>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <cmath>
+#include <cstdlib>
#include <algorithm>
-#include "mouselock.h"
+#include "mouse_lock.h"
#ifdef WIN32
#undef min
@@ -35,8 +35,6 @@ const uint32_t kBackgroundColor = 0xff606060;
const uint32_t kForegroundColor = 0xfff08080;
} // namespace
-namespace mouselock {
-
MouseLockInstance::~MouseLockInstance() {
free(background_scanline_);
background_scanline_ = NULL;
@@ -345,8 +343,6 @@ void MouseLockInstance::Log(const char* format, ...) {
console->Log(pp_instance(), PP_LOGLEVEL_ERROR, value.pp_var());
}
-} // namespace mouselock
-
// This object is the global object representing this plugin library as long
// as it is loaded.
class MouseLockModule : public pp::Module {
@@ -356,7 +352,7 @@ class MouseLockModule : public pp::Module {
// Override CreateInstance to create your customized Instance object.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new mouselock::MouseLockInstance(instance);
+ return new MouseLockInstance(instance);
}
};
diff --git a/native_client_sdk/src/examples/api/mouse_lock/mouselock.h b/native_client_sdk/src/examples/api/mouse_lock/mouse_lock.h
index 2e1d190..88fcc5f 100644
--- a/native_client_sdk/src/examples/api/mouse_lock/mouselock.h
+++ b/native_client_sdk/src/examples/api/mouse_lock/mouse_lock.h
@@ -8,12 +8,12 @@
#include "ppapi/c/ppb_input_event.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/fullscreen.h"
-#include "ppapi/cpp/mouse_lock.h"
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/mouse_lock.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/size.h"
#include "ppapi/cpp/var.h"
@@ -24,8 +24,6 @@
#pragma warning(disable : 4355)
#endif
-namespace mouselock {
-
class MouseLockInstance : public pp::Instance, public pp::MouseLock {
public:
explicit MouseLockInstance(PP_Instance instance)
@@ -102,5 +100,3 @@ class MouseLockInstance : public pp::Instance, public pp::MouseLock {
bool was_fullscreen_;
uint32_t* background_scanline_;
};
-
-} // namespace mouselock
diff --git a/native_client_sdk/src/examples/api/url_loader/example.dsc b/native_client_sdk/src/examples/api/url_loader/example.dsc
index a5c4503da..baafd66 100644
--- a/native_client_sdk/src/examples/api/url_loader/example.dsc
+++ b/native_client_sdk/src/examples/api/url_loader/example.dsc
@@ -2,15 +2,19 @@
'TOOLS': ['newlib', 'glibc', 'pnacl', 'win', 'linux'],
'TARGETS': [
{
- 'NAME' : 'geturl',
+ 'NAME' : 'url_loader',
'TYPE' : 'main',
- 'SOURCES' : ['geturl.cc', 'geturl_handler.cc', 'geturl_handler.h'],
+ 'SOURCES' : [
+ 'url_loader.cc',
+ 'url_loader_handler.cc',
+ 'url_loader_handler.h'
+ ],
'LIBS': ['ppapi_cpp', 'ppapi', 'pthread']
}
],
'DATA': [
'example.js',
- 'geturl_success.html',
+ 'url_loader_success.html',
],
'DEST': 'examples/api',
'NAME': 'url_loader',
diff --git a/native_client_sdk/src/examples/api/url_loader/geturl_success.html b/native_client_sdk/src/examples/api/url_loader/geturl_success.html
deleted file mode 100644
index f5a3b8b..0000000
--- a/native_client_sdk/src/examples/api/url_loader/geturl_success.html
+++ /dev/null
@@ -1,20 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
- <!--
- Copyright (c) 2010 The Chromium Authors. All rights reserved.
- Use of this source code is governed by a BSD-style license that can be
- found in the LICENSE file.
- -->
- <head>
- <title>PPAPI geturl example</title>
- <META HTTP-EQUIV="Pragma" CONTENT="no-cache" />
- <META HTTP-EQUIV="Expires" CONTENT="-1" />
- </head>
- <body>
- <h1>PPAPI geturl example</h1>
- The PPAPI geturl example fetches the contents of this page.
- If you are seeing the contents of this page as part of the test output,
- then the test passed.
- </body>
-</html>
diff --git a/native_client_sdk/src/examples/api/url_loader/index.html b/native_client_sdk/src/examples/api/url_loader/index.html
index cdaa241..828ff1f 100644
--- a/native_client_sdk/src/examples/api/url_loader/index.html
+++ b/native_client_sdk/src/examples/api/url_loader/index.html
@@ -15,8 +15,8 @@ found in the LICENSE file.
<body {{attrs}}>
<h1>{{title}}</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
- <p>The Get URL example demonstrates fetching an URL and then displaying its
- contents. Clicking the GetURL button will cause a geturl_success.html
+ <p>The URL Loader example demonstrates fetching an URL and then displaying its
+ contents. Clicking the Get URL button will cause a url_loader_success.html
file to get loaded asynchronously, then displayed in a text box when the
load completes.</p>
<table border=5 cellpadding=5% summary="A title and a result log">
diff --git a/native_client_sdk/src/examples/api/url_loader/geturl.cc b/native_client_sdk/src/examples/api/url_loader/url_loader.cc
index db7abe2..d000a93 100644
--- a/native_client_sdk/src/examples/api/url_loader/geturl.cc
+++ b/native_client_sdk/src/examples/api/url_loader/url_loader.cc
@@ -7,11 +7,11 @@
#include <cstdio>
#include <string>
#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/var.h"
-#include "geturl_handler.h"
+#include "url_loader_handler.h"
// These are the method names as JavaScript sees them.
namespace {
@@ -20,20 +20,14 @@ static const char kMessageArgumentSeparator = ':';
// Exception strings. These are passed back to the browser when errors
// happen during property accesses or method calls.
-const char* const kExceptionStartFailed = "GetURLHandler::Start() failed";
+const char* const kExceptionStartFailed = "URLLoaderHandler::Start() failed";
const char* const kExceptionURLNotAString = "URL is not a string";
} // namespace
-// The Instance class. One of these exists for each instance of your NaCl
-// module on the web page. The browser will ask the Module object to create
-// a new Instance for each occurrence of the <embed> tag that has these
-// attributes:
-// type="application/x-nacl"
-// src="geturl.nmf"
-class GetURLInstance : public pp::Instance {
+class URLLoaderInstance : public pp::Instance {
public:
- explicit GetURLInstance(PP_Instance instance) : pp::Instance(instance) {}
- virtual ~GetURLInstance() {}
+ explicit URLLoaderInstance(PP_Instance instance) : pp::Instance(instance) {}
+ virtual ~URLLoaderInstance() {}
// Called by the browser to handle the postMessage() call in Javascript.
// The message in this case is expected to contain the string 'getUrl'
@@ -44,7 +38,7 @@ class GetURLInstance : public pp::Instance {
virtual void HandleMessage(const pp::Var& var_message);
};
-void GetURLInstance::HandleMessage(const pp::Var& var_message) {
+void URLLoaderInstance::HandleMessage(const pp::Var& var_message) {
if (!var_message.is_string()) {
return;
}
@@ -54,11 +48,11 @@ void GetURLInstance::HandleMessage(const pp::Var& var_message) {
size_t sep_pos = message.find_first_of(kMessageArgumentSeparator);
if (sep_pos != std::string::npos) {
std::string url = message.substr(sep_pos + 1);
- printf("GetURLInstance::HandleMessage('%s', '%s')\n",
+ printf("URLLoaderInstance::HandleMessage('%s', '%s')\n",
message.c_str(),
url.c_str());
fflush(stdout);
- GetURLHandler* handler = GetURLHandler::Create(this, url);
+ URLLoaderHandler* handler = URLLoaderHandler::Create(this, url);
if (handler != NULL) {
// Starts asynchronous download. When download is finished or when an
// error occurs, |handler| posts the results back to the browser
@@ -69,25 +63,17 @@ void GetURLInstance::HandleMessage(const pp::Var& var_message) {
}
}
-// The Module class. The browser calls the CreateInstance() method to create
-// an instance of you NaCl module on the web page. The browser creates a new
-// instance for each <embed> tag with type="application/x-nacl".
-class GetURLModule : public pp::Module {
+class URLLoaderModule : public pp::Module {
public:
- GetURLModule() : pp::Module() {}
- virtual ~GetURLModule() {}
+ URLLoaderModule() : pp::Module() {}
+ virtual ~URLLoaderModule() {}
- // Create and return a GetURLInstance object.
+ // Create and return a URLLoaderInstance object.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new GetURLInstance(instance);
+ return new URLLoaderInstance(instance);
}
};
-// Factory function called by the browser when the module is first loaded.
-// The browser keeps a singleton of this module. It calls the
-// CreateInstance() method on the object you return to make instances. There
-// is one instance per <embed> tag on the page. This is the main binding
-// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() { return new GetURLModule(); }
+Module* CreateModule() { return new URLLoaderModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/api/url_loader/geturl_handler.cc b/native_client_sdk/src/examples/api/url_loader/url_loader_handler.cc
index e13ca1f..6948257 100644
--- a/native_client_sdk/src/examples/api/url_loader/geturl_handler.cc
+++ b/native_client_sdk/src/examples/api/url_loader/url_loader_handler.cc
@@ -9,7 +9,7 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
-#include "geturl_handler.h"
+#include "url_loader_handler.h"
#ifdef WIN32
#undef min
@@ -20,12 +20,13 @@
#pragma warning(disable : 4355)
#endif
-GetURLHandler* GetURLHandler::Create(pp::Instance* instance,
- const std::string& url) {
- return new GetURLHandler(instance, url);
+URLLoaderHandler* URLLoaderHandler::Create(pp::Instance* instance,
+ const std::string& url) {
+ return new URLLoaderHandler(instance, url);
}
-GetURLHandler::GetURLHandler(pp::Instance* instance, const std::string& url)
+URLLoaderHandler::URLLoaderHandler(pp::Instance* instance,
+ const std::string& url)
: instance_(instance),
url_(url),
url_request_(instance),
@@ -37,17 +38,18 @@ GetURLHandler::GetURLHandler(pp::Instance* instance, const std::string& url)
url_request_.SetRecordDownloadProgress(true);
}
-GetURLHandler::~GetURLHandler() {
+URLLoaderHandler::~URLLoaderHandler() {
delete[] buffer_;
buffer_ = NULL;
}
-void GetURLHandler::Start() {
- pp::CompletionCallback cc = cc_factory_.NewCallback(&GetURLHandler::OnOpen);
+void URLLoaderHandler::Start() {
+ pp::CompletionCallback cc =
+ cc_factory_.NewCallback(&URLLoaderHandler::OnOpen);
url_loader_.Open(url_request_, cc);
}
-void GetURLHandler::OnOpen(int32_t result) {
+void URLLoaderHandler::OnOpen(int32_t result) {
if (result != PP_OK) {
ReportResultAndDie(url_, "pp::URLLoader::Open() failed", false);
return;
@@ -60,7 +62,7 @@ void GetURLHandler::OnOpen(int32_t result) {
// order to allocate memory for the response body in advance (this will
// reduce heap traffic and also the amount of memory allocated).
// It is not a problem if this fails, it just means that the
- // url_response_body_.insert() call in GetURLHandler::AppendDataBytes()
+ // url_response_body_.insert() call in URLLoaderHandler::AppendDataBytes()
// will allocate the memory later on.
int64_t bytes_received = 0;
int64_t total_bytes_to_be_received = 0;
@@ -77,7 +79,7 @@ void GetURLHandler::OnOpen(int32_t result) {
ReadBody();
}
-void GetURLHandler::AppendDataBytes(const char* buffer, int32_t num_bytes) {
+void URLLoaderHandler::AppendDataBytes(const char* buffer, int32_t num_bytes) {
if (num_bytes <= 0)
return;
// Make sure we don't get a buffer overrun.
@@ -89,7 +91,7 @@ void GetURLHandler::AppendDataBytes(const char* buffer, int32_t num_bytes) {
url_response_body_.end(), buffer, buffer + num_bytes);
}
-void GetURLHandler::OnRead(int32_t result) {
+void URLLoaderHandler::OnRead(int32_t result) {
if (result == PP_OK) {
// Streaming the file is complete, delete the read buffer since it is
// no longer needed.
@@ -108,7 +110,7 @@ void GetURLHandler::OnRead(int32_t result) {
}
}
-void GetURLHandler::ReadBody() {
+void URLLoaderHandler::ReadBody() {
// Note that you specifically want an "optional" callback here. This will
// allow ReadBody() to return synchronously, ignoring your completion
// callback, if data is available. For fast connections and large files,
@@ -116,7 +118,7 @@ void GetURLHandler::ReadBody() {
// However, in the case of a synchronous return, we need to be sure to run
// the callback we created since the loader won't do anything with it.
pp::CompletionCallback cc =
- cc_factory_.NewOptionalCallback(&GetURLHandler::OnRead);
+ cc_factory_.NewOptionalCallback(&URLLoaderHandler::OnRead);
int32_t result = PP_OK;
do {
result = url_loader_.ReadResponseBody(buffer_, READ_BUFFER_SIZE, cc);
@@ -139,20 +141,20 @@ void GetURLHandler::ReadBody() {
}
}
-void GetURLHandler::ReportResultAndDie(const std::string& fname,
- const std::string& text,
- bool success) {
+void URLLoaderHandler::ReportResultAndDie(const std::string& fname,
+ const std::string& text,
+ bool success) {
ReportResult(fname, text, success);
delete this;
}
-void GetURLHandler::ReportResult(const std::string& fname,
- const std::string& text,
- bool success) {
+void URLLoaderHandler::ReportResult(const std::string& fname,
+ const std::string& text,
+ bool success) {
if (success)
- printf("GetURLHandler::ReportResult(Ok).\n");
+ printf("URLLoaderHandler::ReportResult(Ok).\n");
else
- printf("GetURLHandler::ReportResult(Err). %s\n", text.c_str());
+ printf("URLLoaderHandler::ReportResult(Err). %s\n", text.c_str());
fflush(stdout);
if (instance_) {
pp::Var var_result(fname + "\n" + text);
diff --git a/native_client_sdk/src/examples/api/url_loader/geturl_handler.h b/native_client_sdk/src/examples/api/url_loader/url_loader_handler.h
index cad71b0..b54e7a4 100644
--- a/native_client_sdk/src/examples/api/url_loader/geturl_handler.h
+++ b/native_client_sdk/src/examples/api/url_loader/url_loader_handler.h
@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef EXAMPLES_GETURL_GETURL_HANDLER_H_
-#define EXAMPLES_GETURL_GETURL_HANDLER_H_
+#ifndef URL_LOADER_HANDLER_H_
+#define URL_LOADER_HANDLER_H_
#include <string>
#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/url_request_info.h"
-#include "ppapi/cpp/instance.h"
#include "ppapi/utility/completion_callback_factory.h"
#define READ_BUFFER_SIZE 32768
-// GetURLHandler is used to download data from |url|. When download is
+// URLLoaderHandler is used to download data from |url|. When download is
// finished or when an error occurs, it posts a message back to the browser
// with the results encoded in the message as a string and self-destroys.
//
@@ -26,21 +26,22 @@
// bug: http://code.google.com/p/chromium/issues/detail?id=103947
//
// EXAMPLE USAGE:
-// GetURLHandler* handler* = GetURLHandler::Create(instance,url);
+// URLLoaderHandler* handler* = URLLoaderHandler::Create(instance,url);
// handler->Start();
//
-class GetURLHandler {
+class URLLoaderHandler {
public:
- // Creates instance of GetURLHandler on the heap.
- // GetURLHandler objects shall be created only on the heap (they
+ // Creates instance of URLLoaderHandler on the heap.
+ // URLLoaderHandler objects shall be created only on the heap (they
// self-destroy when all data is in).
- static GetURLHandler* Create(pp::Instance* instance_, const std::string& url);
+ static URLLoaderHandler* Create(pp::Instance* instance_,
+ const std::string& url);
// Initiates page (URL) download.
void Start();
private:
- GetURLHandler(pp::Instance* instance_, const std::string& url);
- ~GetURLHandler();
+ URLLoaderHandler(pp::Instance* instance_, const std::string& url);
+ ~URLLoaderHandler();
// Callback for the pp::URLLoader::Open().
// Called by pp::URLLoader when response headers are received or when an
@@ -78,10 +79,10 @@ class GetURLHandler {
pp::URLLoader url_loader_; // URLLoader provides an API to download URLs.
char* buffer_; // Temporary buffer for reads.
std::string url_response_body_; // Contains accumulated downloaded data.
- pp::CompletionCallbackFactory<GetURLHandler> cc_factory_;
+ pp::CompletionCallbackFactory<URLLoaderHandler> cc_factory_;
- GetURLHandler(const GetURLHandler&);
- void operator=(const GetURLHandler&);
+ URLLoaderHandler(const URLLoaderHandler&);
+ void operator=(const URLLoaderHandler&);
};
-#endif // EXAMPLES_GETURL_GETURL_HANDLER_H_
+#endif // URL_LOADER_HANDLER_H_
diff --git a/native_client_sdk/src/examples/api/url_loader/url_loader_success.html b/native_client_sdk/src/examples/api/url_loader/url_loader_success.html
new file mode 100644
index 0000000..340d538
--- /dev/null
+++ b/native_client_sdk/src/examples/api/url_loader/url_loader_success.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <!--
+ Copyright (c) 2010 The Chromium Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style license that can be
+ found in the LICENSE file.
+ -->
+ <head>
+ <title>PPAPI UrlLoader example</title>
+ </head>
+ <body>
+ <h1>PPAPI UrlLoader example</h1>
+ The PPAPI UrlLoader example fetches the contents of this page. If you are
+ seeing the contents of this page as part of the test output, then the test
+ passed.
+ </body>
+</html>
diff --git a/native_client_sdk/src/examples/api/var_array_buffer/example.dsc b/native_client_sdk/src/examples/api/var_array_buffer/example.dsc
index 43da815..4b1f296 100644
--- a/native_client_sdk/src/examples/api/var_array_buffer/example.dsc
+++ b/native_client_sdk/src/examples/api/var_array_buffer/example.dsc
@@ -2,9 +2,9 @@
'TOOLS': ['newlib', 'glibc', 'pnacl', 'win', 'linux'],
'TARGETS': [
{
- 'NAME' : 'file_histogram',
+ 'NAME' : 'var_array_buffer',
'TYPE' : 'main',
- 'SOURCES' : ['file_histogram.cc'],
+ 'SOURCES' : ['var_array_buffer.cc'],
'LIBS' : ['ppapi_cpp', 'ppapi', 'pthread']
}
],
diff --git a/native_client_sdk/src/examples/api/var_array_buffer/index.html b/native_client_sdk/src/examples/api/var_array_buffer/index.html
index 53858d9..10f4069 100644
--- a/native_client_sdk/src/examples/api/var_array_buffer/index.html
+++ b/native_client_sdk/src/examples/api/var_array_buffer/index.html
@@ -15,7 +15,7 @@
<body data-width="256" data-height="256" {{attrs}}>
<h1>{{title}}</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
- <p>The File Histogram example demonstrates prompting the user for a file,
+ <p>The VarArrayBuffer example demonstrates prompting the user for a file,
passing the file contents to NativeClient as a VarArrayBuffer, then
drawing a histogram representing the contents of the file to a 2D
square.</p>
diff --git a/native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc b/native_client_sdk/src/examples/api/var_array_buffer/var_array_buffer.cc
index ce293e9..9f42ee6 100644
--- a/native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc
+++ b/native_client_sdk/src/examples/api/var_array_buffer/var_array_buffer.cc
@@ -2,28 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-/// @file file_histogram.cc
-/// This example demonstrates loading, running and scripting a very simple NaCl
-/// module. To load the NaCl module, the browser first looks for the
-/// CreateModule() factory method (at the end of this file). It calls
-/// CreateModule() once to load the module code from your .nexe. After the
-/// .nexe code is loaded, CreateModule() is not called again.
-///
-/// Once the .nexe code is loaded, the browser than calls the CreateInstance()
-/// method on the object returned by CreateModule(). It calls CreateInstance()
-/// each time it encounters an <embed> tag that references your NaCl module.
-///
-/// The browser can talk to your NaCl module via the postMessage() Javascript
-/// function. When you call postMessage() on your NaCl module from the browser,
-/// this becomes a call to the HandleMessage() method of your pp::Instance
-/// subclass. You can send messages back to the browser by calling the
-/// PostMessage() method on your pp::Instance. Note that these two methods
-/// (postMessage() in Javascript and PostMessage() in C++) are asynchronous.
-/// This means they return immediately - there is no waiting for the message
-/// to be handled. This has implications in your program design, particularly
-/// when mutating property values that are exposed to both the browser and the
-/// NaCl module.
-
#include <algorithm>
#include <deque>
#include <string>
@@ -55,22 +33,14 @@ const size_t kHistogramSize = 256u;
} // namespace
-/// The Instance class. One of these exists for each instance of your NaCl
-/// module on the web page. The browser will ask the Module object to create
-/// a new Instance for each occurrence of the <embed> tag that has these
-/// attributes:
-/// type="application/x-nacl"
-/// src="file_histogram.nmf"
-class FileHistogramInstance : public pp::Instance {
+class VarArrayBufferInstance : public pp::Instance {
public:
- /// The constructor creates the plugin-side instance.
- /// @param[in] instance the handle to the browser-side plugin instance.
- explicit FileHistogramInstance(PP_Instance instance)
+ explicit VarArrayBufferInstance(PP_Instance instance)
: pp::Instance(instance),
callback_factory_(this),
flushing_(false),
histogram_() {}
- virtual ~FileHistogramInstance() {}
+ virtual ~VarArrayBufferInstance() {}
private:
/// Handler for messages coming in from the browser via postMessage(). The
@@ -121,7 +91,7 @@ class FileHistogramInstance : public pp::Instance {
assert(!flushing_);
graphics_2d_context_.ReplaceContents(image_data);
graphics_2d_context_.Flush(
- callback_factory_.NewCallback(&FileHistogramInstance::DidFlush));
+ callback_factory_.NewCallback(&VarArrayBufferInstance::DidFlush));
flushing_ = true;
}
@@ -186,7 +156,7 @@ class FileHistogramInstance : public pp::Instance {
}
pp::Graphics2D graphics_2d_context_;
- pp::CompletionCallbackFactory<FileHistogramInstance> callback_factory_;
+ pp::CompletionCallbackFactory<VarArrayBufferInstance> callback_factory_;
/// A queue of images to paint. We must maintain a queue because we can not
/// call pp::Graphics2D::Flush while a Flush is already pending.
@@ -204,27 +174,16 @@ class FileHistogramInstance : public pp::Instance {
double histogram_[kHistogramSize];
};
-/// The Module class. The browser calls the CreateInstance() method to create
-/// an instance of your NaCl module on the web page. The browser creates a new
-/// instance for each <embed> tag with type="application/x-nacl".
-class FileHistogramModule : public pp::Module {
+class VarArrayBufferModule : public pp::Module {
public:
- FileHistogramModule() : pp::Module() {}
- virtual ~FileHistogramModule() {}
+ VarArrayBufferModule() : pp::Module() {}
+ virtual ~VarArrayBufferModule() {}
- /// Create and return a FileHistogramInstance object.
- /// @param[in] instance The browser-side instance.
- /// @return the plugin-side instance.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new FileHistogramInstance(instance);
+ return new VarArrayBufferInstance(instance);
}
};
namespace pp {
-/// Factory function called by the browser when the module is first loaded.
-/// The browser keeps a singleton of this module. It calls the
-/// CreateInstance() method on the object you return to make instances. There
-/// is one instance per <embed> tag on the page. This is the main binding
-/// point for your NaCl module with the browser.
-Module* CreateModule() { return new FileHistogramModule(); }
+Module* CreateModule() { return new VarArrayBufferModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/demo/nacl_io/example.dsc b/native_client_sdk/src/examples/demo/nacl_io/example.dsc
index f390187..fda8dc6 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/example.dsc
+++ b/native_client_sdk/src/examples/demo/nacl_io/example.dsc
@@ -7,12 +7,12 @@
'SOURCES' : [
'handlers.c',
'handlers.h',
- 'hello_nacl_io.c',
- 'hello_nacl_io.h',
+ 'nacl_io_demo.c',
+ 'nacl_io_demo.h',
'queue.c',
'queue.h',
],
- 'LIBS': ['ppapi', 'pthread', 'nacl_io']
+ 'LIBS': ['nacl_io', 'ppapi', 'pthread']
}
],
'DATA': [
diff --git a/native_client_sdk/src/examples/demo/nacl_io/handlers.c b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
index 46d8594..c223d1a 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/handlers.c
+++ b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
@@ -12,7 +12,7 @@
#include <string.h>
#include <sys/stat.h>
-#include "hello_nacl_io.h"
+#include "nacl_io.h"
#define MAX_OPEN_FILES 10
diff --git a/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.c b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c
index b56e1c6..43e4847 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.c
+++ b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "hello_nacl_io.h"
+#include "nacl_io_demo.h"
#include <assert.h>
#include <stdio.h>
diff --git a/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h
index f3bcd10..25de395 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h
+++ b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h
@@ -3,8 +3,8 @@
* found in the LICENSE file.
*/
-#ifndef HELLO_NACL_IO_H_
-#define HELLO_NACL_IO_H_
+#ifndef NACL_IO_DEMO_H_
+#define NACL_IO_DEMO_H_
#include <stdarg.h>
#include "ppapi/c/pp_var.h"
@@ -15,4 +15,4 @@ char* PrintfToNewString(const char* format, ...);
struct PP_Var PrintfToVar(const char* format, ...);
uint32_t VarToCStr(struct PP_Var var, char* buffer, uint32_t length);
-#endif /* HELLO_NACL_IO_H_ */
+#endif /* NACL_IO_DEMO_H_ */
diff --git a/native_client_sdk/src/examples/demo/pi_generator/example.dsc b/native_client_sdk/src/examples/demo/pi_generator/example.dsc
index 6a4b9a1..99aefd0 100644
--- a/native_client_sdk/src/examples/demo/pi_generator/example.dsc
+++ b/native_client_sdk/src/examples/demo/pi_generator/example.dsc
@@ -4,11 +4,7 @@
{
'NAME' : 'pi_generator',
'TYPE' : 'main',
- 'SOURCES' : [
- 'pi_generator.cc',
- 'pi_generator.h',
- 'pi_generator_module.cc'
- ],
+ 'SOURCES' : ['pi_generator.cc'],
'LIBS': ['ppapi_cpp', 'ppapi', 'pthread']
}
],
diff --git a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
index bada610..6080b03 100644
--- a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
+++ b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
@@ -2,16 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <math.h>
+#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
-#include <cassert>
-#include <cmath>
-#include <cstring>
+
#include <string>
-#include "ppapi/cpp/completion_callback.h"
-#include "ppapi/cpp/var.h"
-#include "pi_generator.h"
+#include "ppapi/cpp/graphics_2d.h"
+#include "ppapi/cpp/image_data.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/rect.h"
+#include "ppapi/cpp/size.h"
+#include "ppapi/cpp/var.h"
+#include "ppapi/utility/completion_callback_factory.h"
namespace {
const int kPthreadMutexSuccess = 0;
@@ -23,16 +27,91 @@ const uint32_t kRedMask = 0xff0000;
const uint32_t kBlueMask = 0xff;
const uint32_t kRedShift = 16;
const uint32_t kBlueShift = 0;
+} // namespace
-// This is called by the browser when the 2D context has been flushed to the
-// browser window.
-void FlushCallback(void* data, int32_t result) {
- static_cast<pi_generator::PiGenerator*>(data)->set_flush_pending(false);
-}
+class PiGeneratorInstance : public pp::Instance {
+ public:
+ explicit PiGeneratorInstance(PP_Instance instance);
+ virtual ~PiGeneratorInstance();
-} // namespace
+ // Start up the ComputePi() thread.
+ virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
+
+ // Update the graphics context to the new size, and regenerate |pixel_buffer_|
+ // to fit the new size as well.
+ virtual void DidChangeView(const pp::View& view);
+
+ // Called by the browser to handle the postMessage() call in Javascript.
+ // The message in this case is expected to contain the string 'paint', and
+ // if so this invokes the Paint() function. If |var_message| is not a string
+ // type, or contains something other than 'paint', this method posts an
+ // invalid value for Pi (-1.0) back to the browser.
+ virtual void HandleMessage(const pp::Var& var_message);
+
+ // Return a pointer to the pixels represented by |pixel_buffer_|. When this
+ // method returns, the underlying |pixel_buffer_| object is locked. This
+ // call must have a matching UnlockPixels() or various threading errors
+ // (e.g. deadlock) will occur.
+ uint32_t* LockPixels();
+ // Release the image lock acquired by LockPixels().
+ void UnlockPixels() const;
+
+ // Flushes its contents of |pixel_buffer_| to the 2D graphics context. The
+ // ComputePi() thread fills in |pixel_buffer_| pixels as it computes Pi.
+ // This method is called by HandleMessage when a message containing 'paint'
+ // is received. Echos the current value of pi as computed by the Monte Carlo
+ // method by posting the value back to the browser.
+ void Paint();
+
+ bool quit() const { return quit_; }
+
+ // |pi_| is computed in the ComputePi() thread.
+ double pi() const { return pi_; }
+
+ int width() const {
+ return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
+ }
+ int height() const {
+ return pixel_buffer_ ? pixel_buffer_->size().height() : 0;
+ }
-namespace pi_generator {
+ // Indicate whether a flush is pending. This can only be called from the
+ // main thread; it is not thread safe.
+ bool flush_pending() const { return flush_pending_; }
+ void set_flush_pending(bool flag) { flush_pending_ = flag; }
+
+ private:
+ // Create and initialize the 2D context used for drawing.
+ void CreateContext(const pp::Size& size, float device_scale);
+ // Destroy the 2D drawing context.
+ void DestroyContext();
+ // Push the pixels to the browser, then attempt to flush the 2D context. If
+ // there is a pending flush on the 2D context, then update the pixels only
+ // and do not flush.
+ void FlushPixelBuffer();
+
+ void FlushCallback(int32_t result);
+
+ bool IsContextValid() const { return graphics_2d_context_ != NULL; }
+
+ pp::CompletionCallbackFactory<PiGeneratorInstance> callback_factory_;
+ mutable pthread_mutex_t pixel_buffer_mutex_;
+ pp::Graphics2D* graphics_2d_context_;
+ pp::ImageData* pixel_buffer_;
+ bool flush_pending_;
+ bool quit_;
+ pthread_t compute_pi_thread_;
+ int thread_create_result_;
+ double pi_;
+ float device_scale_;
+
+ // ComputePi() estimates Pi using Monte Carlo method and it is executed by a
+ // separate thread created in SetWindow(). ComputePi() puts kMaxPointCount
+ // points inside the square whose length of each side is 1.0, and calculates
+ // the ratio of the number of points put inside the inscribed quadrant divided
+ // by the total number of random points to get Pi/4.
+ static void* ComputePi(void* param);
+};
// A small helper RAII class that implements a scoped pthread_mutex lock.
class ScopedMutexLock {
@@ -55,7 +134,7 @@ class ScopedMutexLock {
// A small helper RAII class used to acquire and release the pixel lock.
class ScopedPixelLock {
public:
- explicit ScopedPixelLock(PiGenerator* image_owner)
+ explicit ScopedPixelLock(PiGeneratorInstance* image_owner)
: image_owner_(image_owner), pixels_(image_owner->LockPixels()) {}
~ScopedPixelLock() {
@@ -66,14 +145,13 @@ class ScopedPixelLock {
uint32_t* pixels() const { return pixels_; }
private:
- PiGenerator* image_owner_; // Weak reference.
- uint32_t* pixels_; // Weak reference.
-
- ScopedPixelLock(); // Not implemented, do not use.
+ PiGeneratorInstance* image_owner_; // Weak reference.
+ uint32_t* pixels_; // Weak reference.
};
-PiGenerator::PiGenerator(PP_Instance instance)
+PiGeneratorInstance::PiGeneratorInstance(PP_Instance instance)
: pp::Instance(instance),
+ callback_factory_(this),
graphics_2d_context_(NULL),
pixel_buffer_(NULL),
flush_pending_(false),
@@ -84,7 +162,7 @@ PiGenerator::PiGenerator(PP_Instance instance)
pthread_mutex_init(&pixel_buffer_mutex_, NULL);
}
-PiGenerator::~PiGenerator() {
+PiGeneratorInstance::~PiGeneratorInstance() {
quit_ = true;
if (thread_create_result_ == 0) {
pthread_join(compute_pi_thread_, NULL);
@@ -96,7 +174,7 @@ PiGenerator::~PiGenerator() {
pthread_mutex_destroy(&pixel_buffer_mutex_);
}
-void PiGenerator::DidChangeView(const pp::View& view) {
+void PiGeneratorInstance::DidChangeView(const pp::View& view) {
pp::Size size = view.GetRect().size();
float device_scale = view.GetDeviceScale();
size.set_width(static_cast<int>(size.width() * device_scale));
@@ -121,13 +199,15 @@ void PiGenerator::DidChangeView(const pp::View& view) {
}
}
-bool PiGenerator::Init(uint32_t argc, const char* argn[], const char* argv[]) {
+bool PiGeneratorInstance::Init(uint32_t argc,
+ const char* argn[],
+ const char* argv[]) {
thread_create_result_ =
pthread_create(&compute_pi_thread_, NULL, ComputePi, this);
return thread_create_result_ == 0;
}
-uint32_t* PiGenerator::LockPixels() {
+uint32_t* PiGeneratorInstance::LockPixels() {
void* pixels = NULL;
// Do not use a ScopedMutexLock here, since the lock needs to be held until
// the matching UnlockPixels() call.
@@ -139,7 +219,7 @@ uint32_t* PiGenerator::LockPixels() {
return reinterpret_cast<uint32_t*>(pixels);
}
-void PiGenerator::HandleMessage(const pp::Var& var_message) {
+void PiGeneratorInstance::HandleMessage(const pp::Var& var_message) {
if (!var_message.is_string()) {
PostMessage(pp::Var(kInvalidPiValue));
}
@@ -151,11 +231,11 @@ void PiGenerator::HandleMessage(const pp::Var& var_message) {
}
}
-void PiGenerator::UnlockPixels() const {
+void PiGeneratorInstance::UnlockPixels() const {
pthread_mutex_unlock(&pixel_buffer_mutex_);
}
-void PiGenerator::Paint() {
+void PiGeneratorInstance::Paint() {
ScopedMutexLock scoped_mutex(&pixel_buffer_mutex_);
if (!scoped_mutex.is_valid()) {
return;
@@ -168,7 +248,8 @@ void PiGenerator::Paint() {
PostMessage(pi_estimate);
}
-void PiGenerator::CreateContext(const pp::Size& size, float device_scale) {
+void PiGeneratorInstance::CreateContext(const pp::Size& size,
+ float device_scale) {
ScopedMutexLock scoped_mutex(&pixel_buffer_mutex_);
if (!scoped_mutex.is_valid()) {
return;
@@ -186,7 +267,7 @@ void PiGenerator::CreateContext(const pp::Size& size, float device_scale) {
}
}
-void PiGenerator::DestroyContext() {
+void PiGeneratorInstance::DestroyContext() {
ScopedMutexLock scoped_mutex(&pixel_buffer_mutex_);
if (!scoped_mutex.is_valid()) {
return;
@@ -197,7 +278,7 @@ void PiGenerator::DestroyContext() {
graphics_2d_context_ = NULL;
}
-void PiGenerator::FlushPixelBuffer() {
+void PiGeneratorInstance::FlushPixelBuffer() {
if (!IsContextValid())
return;
// Note that the pixel lock is held while the buffer is copied into the
@@ -206,15 +287,22 @@ void PiGenerator::FlushPixelBuffer() {
if (flush_pending())
return;
set_flush_pending(true);
- graphics_2d_context_->Flush(pp::CompletionCallback(&FlushCallback, this));
+ graphics_2d_context_->Flush(
+ callback_factory_.NewCallback(&PiGeneratorInstance::FlushCallback));
}
-void* PiGenerator::ComputePi(void* param) {
+// This is called by the browser when the 2D context has been flushed to the
+// browser window.
+void PiGeneratorInstance::FlushCallback(int32_t result) {
+ set_flush_pending(false);
+}
+
+void* PiGeneratorInstance::ComputePi(void* param) {
int count = 0; // The number of points put inside the inscribed quadrant.
unsigned int seed = 1;
srand(seed);
- PiGenerator* pi_generator = static_cast<PiGenerator*>(param);
+ PiGeneratorInstance* pi_generator = static_cast<PiGeneratorInstance*>(param);
for (int i = 1; i <= kMaxPointCount && !pi_generator->quit(); ++i) {
ScopedPixelLock scoped_pixel_lock(pi_generator);
uint32_t* pixel_bits = scoped_pixel_lock.pixels();
@@ -248,4 +336,16 @@ void* PiGenerator::ComputePi(void* param) {
return 0;
}
-} // namespace pi_generator
+class PiGeneratorModule : public pp::Module {
+ public:
+ PiGeneratorModule() : pp::Module() {}
+ virtual ~PiGeneratorModule() {}
+
+ virtual pp::Instance* CreateInstance(PP_Instance instance) {
+ return new PiGeneratorInstance(instance);
+ }
+};
+
+namespace pp {
+Module* CreateModule() { return new PiGeneratorModule(); }
+} // namespace pp
diff --git a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.h b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.h
deleted file mode 100644
index 67b4781..0000000
--- a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.h
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef EXAMPLES_PI_GENERATOR_PI_GENERATOR_H_
-#define EXAMPLES_PI_GENERATOR_PI_GENERATOR_H_
-
-#include <pthread.h>
-#include <map>
-#include <vector>
-#include "ppapi/cpp/graphics_2d.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/rect.h"
-#include "ppapi/cpp/size.h"
-
-namespace pi_generator {
-
-// The Instance class. One of these exists for each instance of your NaCl
-// module on the web page. The browser will ask the Module object to create
-// a new Instance for each occurrence of the <embed> tag that has these
-// attributes:
-// type="application/x-nacl"
-// nacl="pi_generator.nmf"
-class PiGenerator : public pp::Instance {
- public:
- explicit PiGenerator(PP_Instance instance);
- virtual ~PiGenerator();
-
- // Start up the ComputePi() thread.
- virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
-
- // Update the graphics context to the new size, and regenerate |pixel_buffer_|
- // to fit the new size as well.
- virtual void DidChangeView(const pp::View& view);
-
- // Called by the browser to handle the postMessage() call in Javascript.
- // The message in this case is expected to contain the string 'paint', and
- // if so this invokes the Paint() function. If |var_message| is not a string
- // type, or contains something other than 'paint', this method posts an
- // invalid value for Pi (-1.0) back to the browser.
- virtual void HandleMessage(const pp::Var& var_message);
-
- // Return a pointer to the pixels represented by |pixel_buffer_|. When this
- // method returns, the underlying |pixel_buffer_| object is locked. This
- // call must have a matching UnlockPixels() or various threading errors
- // (e.g. deadlock) will occur.
- uint32_t* LockPixels();
- // Release the image lock acquired by LockPixels().
- void UnlockPixels() const;
-
- // Flushes its contents of |pixel_buffer_| to the 2D graphics context. The
- // ComputePi() thread fills in |pixel_buffer_| pixels as it computes Pi.
- // This method is called by HandleMessage when a message containing 'paint'
- // is received. Echos the current value of pi as computed by the Monte Carlo
- // method by posting the value back to the browser.
- void Paint();
-
- bool quit() const { return quit_; }
-
- // |pi_| is computed in the ComputePi() thread.
- double pi() const { return pi_; }
-
- int width() const {
- return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
- }
- int height() const {
- return pixel_buffer_ ? pixel_buffer_->size().height() : 0;
- }
-
- // Indicate whether a flush is pending. This can only be called from the
- // main thread; it is not thread safe.
- bool flush_pending() const { return flush_pending_; }
- void set_flush_pending(bool flag) { flush_pending_ = flag; }
-
- private:
- // Create and initialize the 2D context used for drawing.
- void CreateContext(const pp::Size& size, float device_scale);
- // Destroy the 2D drawing context.
- void DestroyContext();
- // Push the pixels to the browser, then attempt to flush the 2D context. If
- // there is a pending flush on the 2D context, then update the pixels only
- // and do not flush.
- void FlushPixelBuffer();
-
- bool IsContextValid() const { return graphics_2d_context_ != NULL; }
-
- mutable pthread_mutex_t pixel_buffer_mutex_;
- pp::Graphics2D* graphics_2d_context_;
- pp::ImageData* pixel_buffer_;
- bool flush_pending_;
- bool quit_;
- pthread_t compute_pi_thread_;
- int thread_create_result_;
- double pi_;
- float device_scale_;
-
- // ComputePi() estimates Pi using Monte Carlo method and it is executed by a
- // separate thread created in SetWindow(). ComputePi() puts kMaxPointCount
- // points inside the square whose length of each side is 1.0, and calculates
- // the ratio of the number of points put inside the inscribed quadrant divided
- // by the total number of random points to get Pi/4.
- static void* ComputePi(void* param);
-};
-
-} // namespace pi_generator
-
-#endif // EXAMPLES_PI_GENERATOR_PI_GENERATOR_H_
diff --git a/native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc b/native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc
deleted file mode 100644
index e5edebb..0000000
--- a/native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <ppapi/cpp/module.h>
-
-#include "pi_generator.h"
-
-namespace pi_generator {
-// The Module class. The browser calls the CreateInstance() method to create
-// an instance of your NaCl module on the web page. The browser creates a new
-// instance for each <embed> tag with type="application/x-nacl".
-class PiGeneratorModule : public pp::Module {
- public:
- PiGeneratorModule() : pp::Module() {}
- virtual ~PiGeneratorModule() {}
-
- // Create and return a PiGeneratorInstance object.
- virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new PiGenerator(instance);
- }
-};
-} // namespace pi_generator
-
-// Factory function called by the browser when the module is first loaded.
-// The browser keeps a singleton of this module. It calls the
-// CreateInstance() method on the object you return to make instances. There
-// is one instance per <embed> tag on the page. This is the main binding
-// point for your NaCl module with the browser.
-namespace pp {
-Module* CreateModule() { return new pi_generator::PiGeneratorModule(); }
-} // namespace pp
diff --git a/native_client_sdk/src/examples/tutorial/debugging/hello_world.c b/native_client_sdk/src/examples/tutorial/debugging/debugging.c
index 2001651..99b56a2 100644
--- a/native_client_sdk/src/examples/tutorial/debugging/hello_world.c
+++ b/native_client_sdk/src/examples/tutorial/debugging/debugging.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/** @file hello_world.c
+/** @file debugging.c
* This example, is a modified version of hello world. It will start a second
* thread and cause that thread to crash via a NULL dereference.
*/
diff --git a/native_client_sdk/src/examples/tutorial/debugging/example.dsc b/native_client_sdk/src/examples/tutorial/debugging/example.dsc
index 72cd94b..49e31ba 100644
--- a/native_client_sdk/src/examples/tutorial/debugging/example.dsc
+++ b/native_client_sdk/src/examples/tutorial/debugging/example.dsc
@@ -10,7 +10,7 @@
'NAME' : 'debugging',
'TYPE' : 'main',
'SOURCES' : [
- 'hello_world.c',
+ 'debugging.c',
],
'CCFLAGS': ['-fno-omit-frame-pointer'],
'DEPS' : ['error_handling'],
diff --git a/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc b/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc
index 90a59fd..7d13a10 100644
--- a/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc
+++ b/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc
@@ -2,19 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-/// @file
-/// This example demonstrates building a dynamic library which is loaded by the
-/// NaCl module. To load the NaCl module, the browser first looks for the
-/// CreateModule() factory method (at the end of this file). It calls
-/// CreateModule() once to load the module code from your .nexe. After the
-/// .nexe code is loaded, CreateModule() is not called again.
-///
-/// Once the .nexe code is loaded, the browser then calls the CreateInstance()
-/// method on the object returned by CreateModule(). If the CreateInstance
-/// returns successfully, then Init function is called, which will load the
-/// shared object on a worker thread. We use a worker because dlopen is
-/// a blocking call, which is not allowed on the main thread.
-
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
@@ -40,9 +27,9 @@
#define STRINGIFY(x) #x
#define NACL_ARCH_STRING XSTRINGIFY(NACL_ARCH)
-class DlopenInstance : public pp::Instance {
+class DlOpenInstance : public pp::Instance {
public:
- explicit DlopenInstance(PP_Instance instance)
+ explicit DlOpenInstance(PP_Instance instance)
: pp::Instance(instance),
eightball_so_(NULL),
reverse_so_(NULL),
@@ -50,8 +37,7 @@ class DlopenInstance : public pp::Instance {
reverse_(NULL),
tid_(NULL) {}
- virtual ~DlopenInstance() {}
- ;
+ virtual ~DlOpenInstance() {}
// Helper function to post a message back to the JS and stdout functions.
void logmsg(const char* pStr) {
@@ -167,13 +153,13 @@ class DlopenInstance : public pp::Instance {
}
static void* LoadLibrariesOnWorker(void* pInst) {
- DlopenInstance* inst = static_cast<DlopenInstance*>(pInst);
+ DlOpenInstance* inst = static_cast<DlOpenInstance*>(pInst);
inst->LoadLibrary();
return NULL;
}
static void LoadDoneCB(void* pInst, int32_t result) {
- DlopenInstance* inst = static_cast<DlopenInstance*>(pInst);
+ DlOpenInstance* inst = static_cast<DlOpenInstance*>(pInst);
inst->UseLibrary();
}
@@ -185,25 +171,17 @@ class DlopenInstance : public pp::Instance {
pthread_t tid_;
};
-// The Module class. The browser calls the CreateInstance() method to create
-// an instance of your NaCl module on the web page. The browser creates a new
-// instance for each <embed> tag with type="application/x-nacl".
-class dlOpenModule : public pp::Module {
+class DlOpenModule : public pp::Module {
public:
- dlOpenModule() : pp::Module() {}
- virtual ~dlOpenModule() {}
+ DlOpenModule() : pp::Module() {}
+ virtual ~DlOpenModule() {}
- // Create and return a DlopenInstance object.
+ // Create and return a DlOpenInstance object.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
- return new DlopenInstance(instance);
+ return new DlOpenInstance(instance);
}
};
-// Factory function called by the browser when the module is first loaded.
-// The browser keeps a singleton of this module. It calls the
-// CreateInstance() method on the object you return to make instances. There
-// is one instance per <embed> tag on the page. This is the main binding
-// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() { return new dlOpenModule(); }
+Module* CreateModule() { return new DlOpenModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/tutorial/load_progress/check_browser.js b/native_client_sdk/src/examples/tutorial/load_progress/check_browser.js
deleted file mode 100644
index 0c54ba4..0000000
--- a/native_client_sdk/src/examples/tutorial/load_progress/check_browser.js
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/**
- * @fileoverview This file provides a BrowserChecker Javascript class.
- * Users can create a BrowserChecker object, invoke checkBrowser(|version|),
- * and then use getIsValidBrowser() and getBrowserSupportStatus()
- * to determine if the browser version is greater than |version|
- * and if the Native Client plugin is found.
- */
-
-// Create a namespace object
-var browser_version = browser_version || {};
-
-/**
- * Class to provide checking for version and NativeClient.
- * @param {integer} arg1 An argument that indicates major version of Chrome we
- * require, such as 14.
- */
-
-/**
- * Constructor for the BrowserChecker. Sets the major version of
- * Chrome that is required to |minChromeVersion|.
- * @param minChromeVersion The earliest major version of chrome that
- * is supported. If the Chrome browser version is less than
- * |minChromeVersion| then |isValidBrowswer| will be set to false.
- * @param opt_maxChromeVersion Ignored. Retained for backwards compatibility.
- * @param appVersion The application version string.
- * @param plugins The plugins that exist in the browser.
- * @constructor
- */
-browser_version.BrowserChecker = function(minChromeVersion,
- appVersion, plugins,
- opt_maxChromeVersion) {
- /**
- * Version specified by the user. This class looks to see if the browser
- * version is >= |minChromeVersion_|.
- * @type {integer}
- * @private
- */
- this.minChromeVersion_ = minChromeVersion;
-
- /**
- * List of Browser plugin objects.
- * @type {Ojbect array}
- * @private
- */
- this.plugins_ = plugins;
-
- /**
- * Application version string from the Browser.
- * @type {integer}
- * @private
- */
- this.appVersion_ = appVersion;
-
- /**
- * Flag used to indicate if the browser has Native Client and is if the
- * browser version is recent enough.
- * @type {boolean}
- * @private
- */
- this.isValidBrowser_ = false;
-
- /**
- * Actual major version of Chrome -- found by querying the browser.
- * @type {integer}
- * @private
- */
- this.chromeVersion_ = null;
-
- /**
- * Browser support status. This allows the user to get a detailed status
- * rather than using this.browserSupportMessage.
- */
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.UNKNOWN;
-}
-
-/**
- * The values used for BrowserChecker status to indicate success or
- * a specific error.
- * @enum {id}
- */
-browser_version.BrowserChecker.StatusValues = {
- UNKNOWN: 0,
- NACL_ENABLED: 1,
- UNKNOWN_BROWSER: 2,
- CHROME_VERSION_TOO_OLD: 3,
- NACL_NOT_ENABLED: 4,
- NOT_USING_SERVER: 5
-};
-
-/**
- * Determines if the plugin with name |name| exists in the browser.
- * @param {string} name The name of the plugin.
- * @param {Object array} plugins The plugins in this browser.
- * @return {bool} |true| if the plugin is found.
- */
-browser_version.BrowserChecker.prototype.pluginExists = function(name,
- plugins) {
- for (var index=0; index < plugins.length; index++) {
- var plugin = this.plugins_[index];
- var plugin_name = plugin['name'];
- // If the plugin is not found, you can use the Javascript console
- // to see the names of the plugins that were found when debugging.
- if (plugin_name.indexOf(name) != -1) {
- return true;
- }
- }
- return false;
-}
-
-/**
- * Returns browserSupportStatus_ which indicates if the browser supports
- * Native Client. Values are defined as literals in
- * browser_version.BrowserChecker.StatusValues.
- * @ return {int} Level of NaCl support.
- */
-browser_version.BrowserChecker.prototype.getBrowserSupportStatus = function() {
- return this.browserSupportStatus_;
-}
-
-/**
- * Returns isValidBrowser (true/false) to indicate if the browser supports
- * Native Client.
- * @ return {bool} If this browser has NativeClient and correct version.
- */
-browser_version.BrowserChecker.prototype.getIsValidBrowser = function() {
- return this.isValidBrowser_;
-}
-
-/**
- * Checks to see if this browser can support Native Client applications.
- * For Chrome browsers, checks to see if the "Native Client" plugin is
- * enabled.
- */
-browser_version.BrowserChecker.prototype.checkBrowser = function() {
- var versionPatt = /Chrome\/(\d+)\.(\d+)\.(\d+)\.(\d+)/;
- var result = this.appVersion_.match(versionPatt);
-
- // |result| stores the Chrome version number.
- if (!result) {
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.UNKNOWN_BROWSER;
- } else {
- this.chromeVersion_ = result[1];
- // We know we have Chrome, check version and/or plugin named Native Client
- if (this.chromeVersion_ >= this.minChromeVersion_) {
- var found_nacl = this.pluginExists('Native Client', this.plugins_);
- if (found_nacl) {
- this.isValidBrowser_ = true;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.NACL_ENABLED;
- } else {
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.NACL_NOT_ENABLED;
- }
- } else {
- // We are in a version that is less than |minChromeVersion_|
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.CHROME_VERSION_TOO_OLD;
- }
- }
- var my_protocol = window.location.protocol;
- if (my_protocol.indexOf('file') == 0) {
- this.isValidBrowser_ = false;
- this.browserSupportStatus_ =
- browser_version.BrowserChecker.StatusValues.NOT_USING_SERVER;
- }
-}
-
diff --git a/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc b/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc
index 3ed7583..d1005c3 100644
--- a/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc
+++ b/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc
@@ -2,31 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-/// @file
-/// This example demonstrates loading and running a very simple NaCl
-/// module. To load the NaCl module, the browser first looks for the
-/// CreateModule() factory method (at the end of this file). It calls
-/// CreateModule() once to load the module code from your .nexe. After the
-/// .nexe code is loaded, CreateModule() is not called again.
-///
-/// Once the .nexe code is loaded, the browser then calls the
-/// LoadProgressModule::CreateInstance()
-/// method on the object returned by CreateModule(). It calls CreateInstance()
-/// each time it encounters an <embed> tag that references your NaCl module.
-
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
-#include "ppapi/cpp/var.h"
-namespace load_progress {
-/// The Instance class. One of these exists for each instance of your NaCl
-/// module on the web page. The browser will ask the Module object to create
-/// a new Instance for each occurrence of the <embed> tag that has these
-/// attributes:
-/// <pre>
-/// type="application/x-nacl"
-/// nacl="hello_world.nmf"
-/// </pre>
class LoadProgressInstance : public pp::Instance {
public:
explicit LoadProgressInstance(PP_Instance instance)
@@ -34,32 +12,16 @@ class LoadProgressInstance : public pp::Instance {
virtual ~LoadProgressInstance() {}
};
-/// The Module class. The browser calls the CreateInstance() method to create
-/// an instance of your NaCl module on the web page. The browser creates a new
-/// instance for each <embed> tag with
-/// <code>type="application/x-nacl"</code>.
class LoadProgressModule : public pp::Module {
public:
LoadProgressModule() : pp::Module() {}
virtual ~LoadProgressModule() {}
- /// Create and return a HelloWorldInstance object.
- /// @param[in] instance a handle to a plug-in instance.
- /// @return a newly created HelloWorldInstance.
- /// @note The browser is responsible for calling @a delete when done.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new LoadProgressInstance(instance);
}
};
-} // namespace load_progress
namespace pp {
-/// Factory function called by the browser when the module is first loaded.
-/// The browser keeps a singleton of this module. It calls the
-/// CreateInstance() method on the object you return to make instances. There
-/// is one instance per <embed> tag on the page. This is the main binding
-/// point for your NaCl module with the browser.
-/// @return new LoadProgressModule.
-/// @note The browser is responsible for deleting returned @a Module.
-Module* CreateModule() { return new load_progress::LoadProgressModule(); }
+Module* CreateModule() { return new LoadProgressModule(); }
} // namespace pp