summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 21:52:51 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-14 21:52:51 +0000
commita964e11511d9d88667b1bdca3a71d676dd5f8954 (patch)
treeec789e280930e8ed8f50f35180bc07f2f7d143f6 /chrome/renderer/extensions
parent982414001c0484b9f9959a3a66708ef7f304776c (diff)
downloadchromium_src-a964e11511d9d88667b1bdca3a71d676dd5f8954.zip
chromium_src-a964e11511d9d88667b1bdca3a71d676dd5f8954.tar.gz
chromium_src-a964e11511d9d88667b1bdca3a71d676dd5f8954.tar.bz2
Implement private API for web store to determine app ID of
a given frame. BUG=73225 TEST= Review URL: http://codereview.chromium.org/6823068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81652 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r--chrome/renderer/extensions/chrome_app_bindings.cc122
1 files changed, 109 insertions, 13 deletions
diff --git a/chrome/renderer/extensions/chrome_app_bindings.cc b/chrome/renderer/extensions/chrome_app_bindings.cc
index ef072346..e71209d 100644
--- a/chrome/renderer/extensions/chrome_app_bindings.cc
+++ b/chrome/renderer/extensions/chrome_app_bindings.cc
@@ -4,8 +4,13 @@
#include "chrome/renderer/extensions/chrome_app_bindings.h"
+#include "base/command_line.h"
+#include "base/json/json_writer.h"
#include "base/string16.h"
+#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_set.h"
#include "chrome/renderer/extensions/bindings_utils.h"
#include "chrome/renderer/extensions/extension_dispatcher.h"
@@ -15,25 +20,66 @@
using WebKit::WebFrame;
+namespace {
+
+bool IsCheckoutURL(const std::string& url_spec) {
+ std::string checkout_url_prefix =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kAppsCheckoutURL);
+ if (checkout_url_prefix.empty())
+ checkout_url_prefix = "https://checkout.google.com/";
+
+ return StartsWithASCII(url_spec, checkout_url_prefix, false);
+}
+
+bool CheckAccessToAppDetails() {
+ WebFrame* frame = WebFrame::frameForCurrentContext();
+ if (!frame) {
+ LOG(ERROR) << "Could not get frame for current context.";
+ return false;
+ }
+
+ if (!IsCheckoutURL(frame->url().spec())) {
+ std::string error("Access denied for URL: ");
+ error += frame->url().spec();
+ v8::ThrowException(v8::String::New(error.c_str()));
+ return false;
+ }
+
+ return true;
+}
+
+}
+
namespace extensions_v8 {
static const char* const kAppExtensionName = "v8/ChromeApp";
class ChromeAppExtensionWrapper : public v8::Extension {
public:
- explicit ChromeAppExtensionWrapper(ExtensionDispatcher* extension_dispatcher)
- : v8::Extension(kAppExtensionName,
- "var chrome;"
- "if (!chrome)"
- " chrome = {};"
- "if (!chrome.app) {"
- " chrome.app = new function() {"
- " native function GetIsInstalled();"
- " native function Install();"
- " this.__defineGetter__('isInstalled', GetIsInstalled);"
- " this.install = Install;"
- " };"
- "}") {
+ explicit ChromeAppExtensionWrapper(ExtensionDispatcher* extension_dispatcher) :
+ v8::Extension(kAppExtensionName,
+ "var chrome;"
+ "if (!chrome)"
+ " chrome = {};"
+ "if (!chrome.app) {"
+ " chrome.app = new function() {"
+ " native function GetIsInstalled();"
+ " native function Install();"
+ " native function GetDetails();"
+ " native function GetDetailsForFrame();"
+ " this.__defineGetter__('isInstalled', GetIsInstalled);"
+ " this.install = Install;"
+ " this.getDetails = function() {"
+ " var json = GetDetails();"
+ " return json == null ? null : JSON.parse(json);"
+ " };"
+ " this.getDetailsForFrame = function(frame) {"
+ " var json = GetDetailsForFrame(frame);"
+ " return json == null ? null : JSON.parse(json);"
+ " };"
+ " };"
+ "}") {
extension_dispatcher_ = extension_dispatcher;
}
@@ -47,6 +93,10 @@ class ChromeAppExtensionWrapper : public v8::Extension {
return v8::FunctionTemplate::New(GetIsInstalled);
} else if (name->Equals(v8::String::New("Install"))) {
return v8::FunctionTemplate::New(Install);
+ } else if (name->Equals(v8::String::New("GetDetails"))) {
+ return v8::FunctionTemplate::New(GetDetails);
+ } else if (name->Equals(v8::String::New("GetDetailsForFrame"))) {
+ return v8::FunctionTemplate::New(GetDetailsForFrame);
} else {
return v8::Handle<v8::FunctionTemplate>();
}
@@ -80,6 +130,52 @@ class ChromeAppExtensionWrapper : public v8::Extension {
return v8::Undefined();
}
+ static v8::Handle<v8::Value> GetDetails(const v8::Arguments& args) {
+ return GetDetailsForFrameImpl(WebFrame::frameForCurrentContext());
+ }
+
+ static v8::Handle<v8::Value> GetDetailsForFrame(
+ const v8::Arguments& args) {
+ if (!CheckAccessToAppDetails())
+ return v8::Undefined();
+
+ if (args.Length() < 0)
+ return v8::ThrowException(v8::String::New("Not enough arguments."));
+
+ if (!args[0]->IsObject()) {
+ return v8::ThrowException(
+ v8::String::New("Argument 0 must be an object."));
+ }
+
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Object>::Cast(args[0])->CreationContext();
+ CHECK(!context.IsEmpty());
+
+ WebFrame* target_frame = WebFrame::frameForContext(context);
+ if (!target_frame) {
+ return v8::ThrowException(
+ v8::String::New("Could not find frame for specified object."));
+ }
+
+ return GetDetailsForFrameImpl(target_frame);
+ }
+
+ static v8::Handle<v8::Value> GetDetailsForFrameImpl(const WebFrame* frame) {
+ const ::Extension* extension =
+ extension_dispatcher_->extensions()->GetByURL(frame->url());
+ if (!extension)
+ return v8::Null();
+
+ std::string manifest_json;
+ const bool kPrettyPrint = false;
+ scoped_ptr<DictionaryValue> manifest_copy(
+ extension->manifest_value()->DeepCopy());
+ manifest_copy->SetString("id", extension->id());
+ base::JSONWriter::Write(manifest_copy.get(), kPrettyPrint, &manifest_json);
+
+ return v8::String::New(manifest_json.c_str(), manifest_json.size());
+ }
+
static ExtensionDispatcher* extension_dispatcher_;
};