summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 01:19:56 +0000
committerrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 01:19:56 +0000
commit9fbfb8c857ffdad94b4438bc20f8e349fa06b6ec (patch)
tree22a3792903afc467e9337ec7ff23086002aa2a22 /chrome/renderer
parent8d990d54368990f0cc12ffabde1fc19fccb2c4c4 (diff)
downloadchromium_src-9fbfb8c857ffdad94b4438bc20f8e349fa06b6ec.zip
chromium_src-9fbfb8c857ffdad94b4438bc20f8e349fa06b6ec.tar.gz
chromium_src-9fbfb8c857ffdad94b4438bc20f8e349fa06b6ec.tar.bz2
Revert 104410 - Add js api for hosted/packaged apps to request notification authorization
BUG=98145 TEST=None (more pieces will be landing that will make it testable) Review URL: http://codereview.chromium.org/8113006 TBR=asargent@chromium.org Review URL: http://codereview.chromium.org/8188004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/extensions/chrome_app_bindings.cc75
-rw-r--r--chrome/renderer/extensions/chrome_app_bindings.h6
-rw-r--r--chrome/renderer/extensions/chrome_webstore_bindings.cc63
-rw-r--r--chrome/renderer/extensions/extension_helper.cc23
-rw-r--r--chrome/renderer/extensions/extension_helper.h8
-rw-r--r--chrome/renderer/weak_v8_function_map.cc51
-rw-r--r--chrome/renderer/weak_v8_function_map.h39
7 files changed, 55 insertions, 210 deletions
diff --git a/chrome/renderer/extensions/chrome_app_bindings.cc b/chrome/renderer/extensions/chrome_app_bindings.cc
index db0fb36..c13e497 100644
--- a/chrome/renderer/extensions/chrome_app_bindings.cc
+++ b/chrome/renderer/extensions/chrome_app_bindings.cc
@@ -14,7 +14,6 @@
#include "chrome/common/extensions/extension_set.h"
#include "chrome/renderer/extensions/extension_dispatcher.h"
#include "chrome/renderer/extensions/extension_helper.h"
-#include "chrome/renderer/weak_v8_function_map.h"
#include "content/public/renderer/v8_value_converter.h"
#include "content/renderer/render_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
@@ -53,14 +52,6 @@ bool CheckAccessToAppDetails() {
return true;
}
-int g_next_request_id = 0;
-base::LazyInstance<WeakV8FunctionMap> g_callbacks(base::LINKER_INITIALIZED);
-
-const char* kMissingClientIdError = "Missing clientId parameter";
-const char* kInvalidClientIdError = "Invalid clientId";
-const char* kCallbackNotAFunctionError =
- "The callback that was passed is not a function";
-
} // namespace
const char kAppExtensionName[] = "v8/ChromeApp";
@@ -81,14 +72,10 @@ class ChromeAppExtensionWrapper : public v8::Extension {
" native function Install();"
" native function GetDetails();"
" native function GetDetailsForFrame();"
- " native function GetAppNotifyChannel();"
" this.__defineGetter__('isInstalled', GetIsInstalled);"
" this.install = Install;"
" this.getDetails = GetDetails;"
" this.getDetailsForFrame = GetDetailsForFrame;"
- " this.experimental = {};"
- " this.experimental.getNotificationChannel ="
- " GetAppNotifyChannel;"
" };"
"}") {
extension_dispatcher_ = extension_dispatcher;
@@ -108,8 +95,6 @@ class ChromeAppExtensionWrapper : public v8::Extension {
return v8::FunctionTemplate::New(GetDetails);
} else if (name->Equals(v8::String::New("GetDetailsForFrame"))) {
return v8::FunctionTemplate::New(GetDetailsForFrame);
- } else if (name->Equals(v8::String::New("GetAppNotifyChannel"))) {
- return v8::FunctionTemplate::New(GetAppNotifyChannel);
} else {
return v8::Handle<v8::FunctionTemplate>();
}
@@ -195,53 +180,6 @@ class ChromeAppExtensionWrapper : public v8::Extension {
frame->mainWorldScriptContext());
}
- static v8::Handle<v8::Value> GetAppNotifyChannel(const v8::Arguments& args) {
- WebFrame* frame = WebFrame::frameForCurrentContext();
- if (!frame || !frame->view())
- return v8::Undefined();
-
- RenderView* render_view = RenderView::FromWebView(frame->view());
- if (!render_view)
- return v8::Undefined();
-
- if (g_next_request_id < 0)
- return v8::Undefined();
- int request_id = g_next_request_id++;
-
- // Read the required 'clientId' value out of the object at args[0].
- std::string client_id;
- if (args.Length() < 1 || !args[0]->IsObject()) {
- v8::ThrowException(v8::String::New(kMissingClientIdError));
- return v8::Undefined();
- }
- v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(args[0]);
- v8::Local<v8::String> client_id_key = v8::String::New("clientId");
- if (obj->Has(client_id_key)) {
- v8::String::Utf8Value id_value(obj->Get(client_id_key));
- if (id_value.length() > 0)
- client_id = std::string(*id_value);
- }
- if (client_id.empty()) {
- v8::ThrowException(v8::String::New(kInvalidClientIdError));
- return v8::Undefined();
- }
-
- // Hang on to the callback if there was one.
- if (args.Length() >= 2) {
- if (args[1]->IsFunction()) {
- g_callbacks.Get().Add(request_id, v8::Function::Cast(*args[1]));
- } else {
- v8::ThrowException(v8::String::New(kCallbackNotAFunctionError));
- return v8::Undefined();
- }
- }
-
- ExtensionHelper* helper = ExtensionHelper::Get(render_view);
- helper->GetAppNotifyChannel(
- request_id, frame->document().url(), client_id);
- return v8::Undefined();
- }
-
static ExtensionDispatcher* extension_dispatcher_;
};
@@ -252,17 +190,4 @@ v8::Extension* ChromeAppExtension::Get(
return new ChromeAppExtensionWrapper(extension_dispatcher);
}
-void ChromeAppExtension::HandleGetAppNotifyChannelResponse(
- int request_id, const std::string& channel_id, const std::string& error) {
- v8::Persistent<v8::Function> function = g_callbacks.Get().Remove(request_id);
- if (function.IsEmpty())
- return;
- v8::HandleScope handle_scope;
- v8::Context::Scope context_scope(function->CreationContext());
- v8::Handle<v8::Value> argv[2];
- argv[0] = v8::String::New(channel_id.c_str());
- argv[1] = v8::String::New(error.c_str());
- function->Call(v8::Object::New(), arraysize(argv), argv);
-}
-
} // namespace extensions_v8
diff --git a/chrome/renderer/extensions/chrome_app_bindings.h b/chrome/renderer/extensions/chrome_app_bindings.h
index c02366f3..8e7da1b 100644
--- a/chrome/renderer/extensions/chrome_app_bindings.h
+++ b/chrome/renderer/extensions/chrome_app_bindings.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -12,8 +12,6 @@
#define CHROME_RENDERER_EXTENSIONS_CHROME_APP_BINDINGS_H_
#pragma once
-#include <string>
-
class ExtensionDispatcher;
namespace v8 {
@@ -25,8 +23,6 @@ namespace extensions_v8 {
class ChromeAppExtension {
public:
static v8::Extension* Get(ExtensionDispatcher* extension_dispatcher);
- static void HandleGetAppNotifyChannelResponse(
- int request_id, const std::string& channel_id, const std::string& error);
};
} // namespace extensions_v8
diff --git a/chrome/renderer/extensions/chrome_webstore_bindings.cc b/chrome/renderer/extensions/chrome_webstore_bindings.cc
index 56bb4b9..74e3f95 100644
--- a/chrome/renderer/extensions/chrome_webstore_bindings.cc
+++ b/chrome/renderer/extensions/chrome_webstore_bindings.cc
@@ -8,7 +8,6 @@
#include "base/string_util.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/renderer/extensions/extension_helper.h"
-#include "chrome/renderer/weak_v8_function_map.h"
#include "content/renderer/render_view.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
@@ -50,10 +49,48 @@ const char kInvalidWebstoreItemUrlError[] =
// (successful or not) via HandleInstallResponse.
int g_next_install_id = 0;
-base::LazyInstance<WeakV8FunctionMap> g_success_callbacks(
- base::LINKER_INITIALIZED);
-base::LazyInstance<WeakV8FunctionMap> g_failure_callbacks(
- base::LINKER_INITIALIZED);
+// Callbacks are kept track of in maps keyed by install ID. Values are weak
+// references to functions. Entries are automatically removed when functions
+// get garbage collected.
+typedef std::map<int, v8::Persistent<v8::Function> > CallbackMap;
+
+base::LazyInstance<CallbackMap> g_success_callbacks(base::LINKER_INITIALIZED);
+base::LazyInstance<CallbackMap> g_failure_callbacks(base::LINKER_INITIALIZED);
+
+// Extra data to be passed to MakeWeak/RemoveFromCallbackMap to know which entry
+// to remove from which map.
+struct CallbackMapData {
+ CallbackMap* callback_map;
+ int install_id;
+};
+
+// Disposes of a callback function and its corresponding entry in the callback
+// map.
+static void RemoveFromCallbackMap(v8::Persistent<v8::Value> context,
+ void* data) {
+ CallbackMapData* callback_map_data = static_cast<CallbackMapData*>(data);
+ callback_map_data->callback_map->erase(callback_map_data->install_id);
+ delete callback_map_data;
+ context.Dispose();
+}
+
+// Adds |callback_param| (assumed to be a function) to |callback_map| under the
+// |install_id| key. Will be removed from the map when the value is about to be
+// GCed.
+static void AddToCallbackMap(int install_id,
+ v8::Local<v8::Value> callback_param,
+ CallbackMap* callback_map) {
+ CHECK(callback_param->IsFunction());
+ CallbackMapData* callback_map_data = new CallbackMapData();
+ callback_map_data->install_id = install_id;
+ callback_map_data->callback_map = callback_map;
+
+ v8::Local<v8::Function> function = v8::Function::Cast(*callback_param);
+ v8::Persistent<v8::Function> wrapper =
+ v8::Persistent<v8::Function>::New(function);
+ (*callback_map)[install_id] = wrapper;
+ wrapper.MakeWeak(callback_map_data, RemoveFromCallbackMap);
+}
} // anonymous namespace
@@ -110,7 +147,7 @@ class ExtensionImpl : public v8::Extension {
int install_id = g_next_install_id++;
if (args.Length() >= 2 && !args[1]->IsUndefined()) {
if (args[1]->IsFunction()) {
- g_success_callbacks.Get().Add(install_id, v8::Function::Cast(*args[1]));
+ AddToCallbackMap(install_id, args[1], g_success_callbacks.Pointer());
} else {
v8::ThrowException(v8::String::New(kSuccessCallbackNotAFunctionError));
return v8::Undefined();
@@ -118,7 +155,7 @@ class ExtensionImpl : public v8::Extension {
}
if (args.Length() >= 3 && !args[2]->IsUndefined()) {
if (args[2]->IsFunction()) {
- g_failure_callbacks.Get().Add(install_id, v8::Function::Cast(*args[2]));
+ AddToCallbackMap(install_id, args[2], g_failure_callbacks.Pointer());
} else {
v8::ThrowException(v8::String::New(kFailureCallbackNotAFunctionError));
return v8::Undefined();
@@ -233,16 +270,18 @@ v8::Extension* ChromeWebstoreExtension::Get() {
void ChromeWebstoreExtension::HandleInstallResponse(int install_id,
bool success,
const std::string& error) {
- WeakV8FunctionMap& callback_map =
- success ? g_success_callbacks.Get() : g_failure_callbacks.Get();
+ CallbackMap* callback_map =
+ success ? g_success_callbacks.Pointer() : g_failure_callbacks.Pointer();
+ CallbackMap::iterator iter = callback_map->find(install_id);
- v8::Persistent<v8::Function> function = callback_map.Remove(install_id);
- if (function.IsEmpty())
- return;
+ if (iter == callback_map->end() || iter->second.IsEmpty()) return;
+ const v8::Persistent<v8::Function>& function = (*iter).second;
v8::HandleScope handle_scope;
v8::Context::Scope context_scope(function->CreationContext());
v8::Handle<v8::Value> argv[1];
argv[0] = v8::String::New(error.c_str());
function->Call(v8::Object::New(), arraysize(argv), argv);
+
+ callback_map->erase(iter);
}
diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc
index c2c880c..85f610b 100644
--- a/chrome/renderer/extensions/extension_helper.cc
+++ b/chrome/renderer/extensions/extension_helper.cc
@@ -9,11 +9,10 @@
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/chrome_view_types.h"
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
-#include "chrome/renderer/extensions/chrome_app_bindings.h"
+#include "chrome/common/chrome_view_types.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
#include "chrome/renderer/extensions/chrome_webstore_bindings.h"
#include "chrome/renderer/extensions/event_bindings.h"
@@ -24,14 +23,13 @@
#include "chrome/renderer/extensions/user_script_slave.h"
#include "content/common/json_value_serializer.h"
#include "content/renderer/render_view.h"
+#include "webkit/glue/image_resource_fetcher.h"
+#include "webkit/glue/resource_fetcher.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
-#include "webkit/glue/image_resource_fetcher.h"
-#include "webkit/glue/resource_fetcher.h"
-using extensions_v8::ChromeAppExtension;
using WebKit::WebConsoleMessage;
using WebKit::WebDataSource;
using WebKit::WebFrame;
@@ -121,19 +119,6 @@ void ExtensionHelper::OnInlineWebstoreInstallResponse(
ChromeWebstoreExtension::HandleInstallResponse(install_id, success, error);
}
-void ExtensionHelper::GetAppNotifyChannel(int request_id,
- const GURL& requestor_url,
- const std::string& client_id) {
- Send(new ExtensionHostMsg_GetAppNotifyChannel(
- routing_id(), request_id, requestor_url, client_id));
-}
-
-void ExtensionHelper::OnGetAppNotifyChannelResponse(
- int request_id, const std::string& channel_id, const std::string& error) {
- ChromeAppExtension::HandleGetAppNotifyChannelResponse(
- request_id, channel_id, error);
-}
-
bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ExtensionHelper, message)
@@ -148,8 +133,6 @@ bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) {
OnNotifyRendererViewType)
IPC_MESSAGE_HANDLER(ExtensionMsg_InlineWebstoreInstallResponse,
OnInlineWebstoreInstallResponse)
- IPC_MESSAGE_HANDLER(ExtensionMsg_GetAppNotifyChannelResponse,
- OnGetAppNotifyChannelResponse)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
diff --git a/chrome/renderer/extensions/extension_helper.h b/chrome/renderer/extensions/extension_helper.h
index 1086a31..ef7f4ae 100644
--- a/chrome/renderer/extensions/extension_helper.h
+++ b/chrome/renderer/extensions/extension_helper.h
@@ -46,12 +46,6 @@ class ExtensionHelper
std::string webstore_item_id,
GURL requestor_url);
- // Starts fetching a channel id for server pushed notifications. The result
- // comes back via OnGetAppNotifyChannelResponse.
- void GetAppNotifyChannel(int request_id,
- const GURL& requestor_url,
- const std::string& client_id);
-
int browser_window_id() const { return browser_window_id_; }
content::ViewType::Type view_type() const { return view_type_; }
@@ -81,8 +75,6 @@ class ExtensionHelper
void OnUpdateBrowserWindowId(int window_id);
void OnInlineWebstoreInstallResponse(
int install_id, bool success, const std::string& error);
- void OnGetAppNotifyChannelResponse(
- int request_id, const std::string& channel_id, const std::string& error);
// Callback triggered when we finish downloading the application definition
// file.
diff --git a/chrome/renderer/weak_v8_function_map.cc b/chrome/renderer/weak_v8_function_map.cc
deleted file mode 100644
index 0d70523..0000000
--- a/chrome/renderer/weak_v8_function_map.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2011 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 "base/logging.h"
-#include "chrome/renderer/weak_v8_function_map.h"
-
-// Extra data to be passed to MakeWeak/RemoveFromMap to know which entry
-// to remove from which map.
-struct WeakV8FunctionMapData {
- base::WeakPtr<WeakV8FunctionMap> map;
- int key;
-};
-
-// Disposes of a callback function and its corresponding entry in the callback
-// map, if that callback map is still alive.
-static void RemoveFromMap(v8::Persistent<v8::Value> context,
- void* data) {
- WeakV8FunctionMapData* map_data =
- static_cast<WeakV8FunctionMapData*>(data);
- if (map_data->map)
- map_data->map->Remove(map_data->key);
- delete map_data;
- context.Dispose();
-}
-
-WeakV8FunctionMap::WeakV8FunctionMap()
- : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
-
-WeakV8FunctionMap::~WeakV8FunctionMap() {}
-
-
-void WeakV8FunctionMap::Add(int key,
- v8::Local<v8::Function> callback_function) {
- WeakV8FunctionMapData* map_data = new WeakV8FunctionMapData();
- map_data->key = key;
- map_data->map = weak_ptr_factory_.GetWeakPtr();
- v8::Persistent<v8::Function> wrapper =
- v8::Persistent<v8::Function>::New(callback_function);
- map_[key] = wrapper;
- wrapper.MakeWeak(map_data, RemoveFromMap);
-}
-
-v8::Persistent<v8::Function> WeakV8FunctionMap::Remove(int key) {
- WeakV8FunctionMap::Map::iterator i = map_.find(key);
- if (i == map_.end())
- return v8::Persistent<v8::Function>();
- v8::Persistent<v8::Function> callback = i->second;
- map_.erase(i);
- return callback;
-}
diff --git a/chrome/renderer/weak_v8_function_map.h b/chrome/renderer/weak_v8_function_map.h
deleted file mode 100644
index a51dc9d..0000000
--- a/chrome/renderer/weak_v8_function_map.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 2011 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_WEAK_V8_FUNCTION_MAP_H_
-#define CHROME_RENDERER_WEAK_V8_FUNCTION_MAP_H_
-#pragma once
-
-#include <map>
-
-#include "base/compiler_specific.h"
-#include "base/memory/weak_ptr.h"
-#include "v8/include/v8.h"
-
-// This class lets you keep a mapping of integer to weak reference to a v8
-// function. The entry will automatically get removed from the map if the
-// function gets garbage collected.
-class WeakV8FunctionMap {
- public:
- WeakV8FunctionMap();
- ~WeakV8FunctionMap();
-
- // Adds |callback_function| to the map under |key|. The entry will be removed
- // from the map when the function is about to be GCed.
- void Add(int key, v8::Local<v8::Function> callback_function);
-
- // Removes and returns a entry from the map for |key|. If there was no entry
- // for |key|, the return value will return true for IsEmpty().
- v8::Persistent<v8::Function> Remove(int key);
-
- private:
- typedef std::map<int, v8::Persistent<v8::Function> > Map;
- Map map_;
- base::WeakPtrFactory<WeakV8FunctionMap> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(WeakV8FunctionMap);
-};
-
-#endif // CHROME_RENDERER_WEAK_V8_FUNCTION_MAP_H_