Commit 4084ef9c authored by tommycli@chromium.org's avatar tommycli@chromium.org

Media Galleries API Metadata: Make Blob native extension bindings available to multiple extensions.

Feedback_private currently has a extension native handler for getting a Blob's UUID. Media Galleries API Metadata and other extensions that take a Blob will also want this.

This simply moves the function from a Feedback_private specific custom binding to a general ObjectBackedNativeHandler called BlobNativeHandler. This follows the CssNativeHandler example.

The parent class changed from ChromeV8Extension to ObjectBackedNativeHandler because ChromeV8Extension class has been deprecated.

R=thestig@chromium.org

BUG=318450

Review URL: https://codereview.chromium.org/76703002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236847 0039d316-1c4b-4281-b951-d872f2087c98
parent 48d13b23
......@@ -68,6 +68,8 @@
'renderer/extensions/app_window_custom_bindings.h',
'renderer/extensions/binding_generating_native_handler.cc',
'renderer/extensions/binding_generating_native_handler.h',
'renderer/extensions/blob_native_handler.cc',
'renderer/extensions/blob_native_handler.h',
'renderer/extensions/chrome_v8_context.cc',
'renderer/extensions/chrome_v8_context.h',
'renderer/extensions/chrome_v8_context_set.cc',
......@@ -97,8 +99,6 @@
'renderer/extensions/extension_helper.h',
'renderer/extensions/extension_localization_peer.cc',
'renderer/extensions/extension_localization_peer.h',
'renderer/extensions/feedback_private_custom_bindings.cc',
'renderer/extensions/feedback_private_custom_bindings.h',
'renderer/extensions/file_browser_handler_custom_bindings.cc',
'renderer/extensions/file_browser_handler_custom_bindings.h',
'renderer/extensions/file_browser_private_custom_bindings.cc',
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/extensions/feedback_private_custom_bindings.h"
#include "chrome/renderer/extensions/blob_native_handler.h"
#include "base/bind.h"
#include "third_party/WebKit/public/platform/WebCString.h"
......@@ -11,8 +11,9 @@
namespace {
void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value> &args) {
DCHECK(args.Length() == 1);
// Expects a single Blob argument. Returns the Blob's UUID.
void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) {
DCHECK_EQ(1, args.Length());
blink::WebBlob blob = blink::WebBlob::fromV8Value(args[0]);
args.GetReturnValue().Set(v8::String::New(blob.uuid().utf8().data()));
}
......@@ -21,9 +22,8 @@ void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value> &args) {
namespace extensions {
FeedbackPrivateCustomBindings::FeedbackPrivateCustomBindings(
Dispatcher* dispatcher,
ChromeV8Context* context) : ChromeV8Extension(dispatcher, context) {
BlobNativeHandler::BlobNativeHandler(ChromeV8Context* context)
: ObjectBackedNativeHandler(context) {
RouteFunction("GetBlobUuid", base::Bind(&GetBlobUuid));
}
......
// Copyright 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 CHROME_RENDERER_EXTENSIONS_BLOB_NATIVE_HANDLER_H_
#define CHROME_RENDERER_EXTENSIONS_BLOB_NATIVE_HANDLER_H_
#include "chrome/renderer/extensions/chrome_v8_extension.h"
namespace extensions {
// This native handler is used to extract Blobs' UUIDs and pass them over to the
// browser process extension implementation via argument modification. This is
// necessary to support extension functions that take Blob parameters, as Blobs
// are not serialized and sent over to the browser process in the normal way.
//
// Blobs sent via this method don't have their ref-counts incremented, so the
// app using this technique must be sure to keep a reference.
class BlobNativeHandler : public ObjectBackedNativeHandler {
public:
explicit BlobNativeHandler(ChromeV8Context* context);
};
} // namespace extensions
#endif // CHROME_RENDERER_EXTENSIONS_BLOB_NATIVE_HANDLER_H_
......@@ -31,6 +31,7 @@
#include "chrome/renderer/extensions/app_runtime_custom_bindings.h"
#include "chrome/renderer/extensions/app_window_custom_bindings.h"
#include "chrome/renderer/extensions/binding_generating_native_handler.h"
#include "chrome/renderer/extensions/blob_native_handler.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
#include "chrome/renderer/extensions/chrome_v8_extension.h"
#include "chrome/renderer/extensions/content_watcher.h"
......@@ -41,7 +42,6 @@
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/extension_groups.h"
#include "chrome/renderer/extensions/extension_helper.h"
#include "chrome/renderer/extensions/feedback_private_custom_bindings.h"
#include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h"
#include "chrome/renderer/extensions/file_browser_private_custom_bindings.h"
#include "chrome/renderer/extensions/file_system_natives.h"
......@@ -896,6 +896,8 @@ void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
module_system->RegisterNativeHandler("app_window_natives",
scoped_ptr<NativeHandler>(
new AppWindowCustomBindings(this, context)));
module_system->RegisterNativeHandler("blob_natives",
scoped_ptr<NativeHandler>(new BlobNativeHandler(context)));
module_system->RegisterNativeHandler("context_menus",
scoped_ptr<NativeHandler>(
new ContextMenusCustomBindings(this, context)));
......@@ -907,9 +909,6 @@ void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
module_system->RegisterNativeHandler("sync_file_system",
scoped_ptr<NativeHandler>(
new SyncFileSystemCustomBindings(this, context)));
module_system->RegisterNativeHandler("feedback_private",
scoped_ptr<NativeHandler>(new FeedbackPrivateCustomBindings(
this, context)));
module_system->RegisterNativeHandler("file_browser_handler",
scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings(
this, context)));
......
// Copyright 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 CHROME_RENDERER_EXTENSIONS_FEEDBACK_PRIVATE_CUSTOM_BINDINGS_H_
#define CHROME_RENDERER_EXTENSIONS_FEEDBACK_PRIVATE_CUSTOM_BINDINGS_H_
#include "chrome/renderer/extensions/chrome_v8_extension.h"
namespace extensions {
// The native component of custom bindings for the chrome.app.runtime API.
class FeedbackPrivateCustomBindings : public ChromeV8Extension {
public:
FeedbackPrivateCustomBindings(Dispatcher* dispatcher,
ChromeV8Context* context);
private:
DISALLOW_COPY_AND_ASSIGN(FeedbackPrivateCustomBindings);
};
} // namespace extensions
#endif // CHROME_RENDERER_EXTENSIONS_FEEDBACK_PRIVATE_CUSTOM_BINDINGS_H_
......@@ -6,7 +6,7 @@
var binding = require('binding').Binding.create('feedbackPrivate');
var feedbackPrivateNatives = requireNative('feedback_private');
var blobNatives = requireNative('blob_natives');
binding.registerCustomHook(function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions;
......@@ -17,10 +17,10 @@ binding.registerCustomHook(function(bindingsAPI) {
if (feedbackInfo.attachedFile)
attachedFileBlobUuid =
feedbackPrivateNatives.GetBlobUuid(feedbackInfo.attachedFile.data);
blobNatives.GetBlobUuid(feedbackInfo.attachedFile.data);
if (feedbackInfo.screenshot)
screenshotBlobUuid =
feedbackPrivateNatives.GetBlobUuid(feedbackInfo.screenshot);
blobNatives.GetBlobUuid(feedbackInfo.screenshot);
feedbackInfo.attachedFileBlobUuid = attachedFileBlobUuid;
feedbackInfo.screenshotBlobUuid = screenshotBlobUuid;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment