summaryrefslogtreecommitdiffstats
path: root/o3d/plugin/cross
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-17 22:25:08 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-17 22:25:08 +0000
commit523b2523c1f2cb22f56be9cc52fb734370992387 (patch)
treeede3f93c4e118e840778e39b5633d6bfc7058ab3 /o3d/plugin/cross
parent9521c61f5588480d8cd6134144db7137630f2529 (diff)
downloadchromium_src-523b2523c1f2cb22f56be9cc52fb734370992387.zip
chromium_src-523b2523c1f2cb22f56be9cc52fb734370992387.tar.gz
chromium_src-523b2523c1f2cb22f56be9cc52fb734370992387.tar.bz2
Add RawData request in preparation for manual loading of
Bitmaps and being able to flip them, scale them, etc... Basically this just makes it possible to download a RawData directly which you can then pass you'll be able to pass to pack->CreateBitmapFromRawData. Some design comments: I used SetFromFile instead of making a different constructor since it seemed wrong to do file IO in a constructor. Given that SetFromFile is private I don't think this is a problem since you can't call it directly. Also, I thought about loading the file first and then calling the original constructor but it seemed like a waste to load the file into memory, then copy it to a new buffer when I could just load it directly. Finally I made it take a String instead of a FilePath because it meant other places had to do less work. Review URL: http://codereview.chromium.org/149784 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/plugin/cross')
-rw-r--r--o3d/plugin/cross/async_loading.cc68
-rw-r--r--o3d/plugin/cross/async_loading.h6
2 files changed, 71 insertions, 3 deletions
diff --git a/o3d/plugin/cross/async_loading.cc b/o3d/plugin/cross/async_loading.cc
index bcd8333..f38ef5d 100644
--- a/o3d/plugin/cross/async_loading.cc
+++ b/o3d/plugin/cross/async_loading.cc
@@ -41,6 +41,7 @@
#include "core/cross/file_request.h"
#include "core/cross/pack.h"
#include "core/cross/texture.h"
+#include "import/cross/raw_data.h"
namespace glue {
namespace namespace_o3d {
@@ -49,6 +50,7 @@ namespace class_FileRequest {
using _o3d::PluginObject;
using o3d::Bitmap;
using o3d::Pack;
+using o3d::RawData;
using o3d::Texture;
// StreamManager::FinishedCallback
@@ -124,6 +126,69 @@ class LoadTextureURLCallback : public StreamManager::FinishedCallback {
}
};
+// StreamManager::FinishedCallback
+// implementation that imports the file as a RawData once downloaded. When the
+// download completes, LoadRawDataURLCallback::Run() will be called, which will
+// parse and load the downloaded file. After that load is complete,
+// onreadystatechange will be run to notify the user.
+class LoadRawDataURLCallback : public StreamManager::FinishedCallback {
+ public:
+ // Creates a new LoadRawDataURLCallback.
+ static LoadRawDataURLCallback *Create(FileRequest *request) {
+ return new LoadRawDataURLCallback(request);
+ }
+
+ virtual ~LoadRawDataURLCallback() {
+ // If the file request was interrupted (for example we moved to a new page
+ // before the file transfer was completed) then we tell the FileRequest
+ // object that the request failed. It's important to call this here since
+ // set_success() will release the pack reference that the FileRequest holds
+ // which will allow the pack to be garbage collected.
+ if (!request_->done()) {
+ request_->set_success(false);
+ }
+ }
+
+ // Loads the RawData file, calls the JS callback to pass back the RawData
+ // object.
+ virtual void Run(DownloadStream*,
+ bool success,
+ const std::string &filename,
+ const std::string &mime_type) {
+ RawData::Ref data;
+ if (success) {
+ o3d::ErrorCollector error_collector(request_->service_locator());
+ request_->set_ready_state(FileRequest::STATE_LOADED);
+ data = RawData::Ref(RawData::CreateFromFile(request_->service_locator(),
+ request_->uri(),
+ filename));
+ if (data) {
+ request_->set_data(data);
+ } else {
+ success = false;
+ }
+ request_->set_error(error_collector.errors());
+ } else {
+ // No error is passed in from the stream but we MUST have an error
+ // for the request to work on the javascript side.
+ request_->set_error("Could not download: " + request_->uri());
+ }
+ request_->set_success(success);
+ // Since the standard codes only go far enough to tell us that the download
+ // succeeded, we set the success [and implicitly the done] flags to give the
+ // rest of the story.
+ if (request_->onreadystatechange())
+ request_->onreadystatechange()->Run();
+ }
+
+ private:
+ FileRequest::Ref request_;
+
+ explicit LoadRawDataURLCallback(FileRequest *request)
+ : request_(request) {
+ }
+};
+
// Sets up the parameters required for all FileRequests.
void userglue_method_open(void *plugin_data,
FileRequest *request,
@@ -183,6 +248,9 @@ void userglue_method_send(void *plugin_data,
case FileRequest::TYPE_TEXTURE:
callback = LoadTextureURLCallback::Create(request);
break;
+ case FileRequest::TYPE_RAWDATA:
+ callback = LoadRawDataURLCallback::Create(request);
+ break;
default:
CHECK(false);
}
diff --git a/o3d/plugin/cross/async_loading.h b/o3d/plugin/cross/async_loading.h
index d0df9df..b64175e 100644
--- a/o3d/plugin/cross/async_loading.h
+++ b/o3d/plugin/cross/async_loading.h
@@ -32,8 +32,8 @@
// This file declares the glue for FileRequest actions.
-#ifndef EXPERIMENTAL_O3D_O3DPLUGIN_AUTOGEN_O3D_GLUE_ASYNC_LOADING_H_
-#define EXPERIMENTAL_O3D_O3DPLUGIN_AUTOGEN_O3D_GLUE_ASYNC_LOADING_H_
+#ifndef O3D_PLUGIN_CROSS_ASYNC_LOADING_H_
+#define O3D_PLUGIN_CROSS_ASYNC_LOADING_H_
#include "core/cross/callback.h"
#include "core/cross/types.h"
@@ -64,4 +64,4 @@ void userglue_method_send(void *plugin_data,
} // namespace namespace_o3d
} // namespace glue
-#endif // EXPERIMENTAL_O3D_O3DPLUGIN_AUTOGEN_O3D_GLUE_ASYNC_LOADING_H_
+#endif // O3D_PLUGIN_CROSS_ASYNC_LOADING_H_