| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/extensions/app_bindings.h" | 5 #include "chrome/renderer/extensions/app_bindings.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (checkout_url_prefix.empty()) | 39 if (checkout_url_prefix.empty()) |
| 40 checkout_url_prefix = "https://checkout.google.com/"; | 40 checkout_url_prefix = "https://checkout.google.com/"; |
| 41 | 41 |
| 42 return StartsWithASCII(url_spec, checkout_url_prefix, false); | 42 return StartsWithASCII(url_spec, checkout_url_prefix, false); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool CheckAccessToAppDetails(WebFrame* frame, v8::Isolate* isolate) { | 45 bool CheckAccessToAppDetails(WebFrame* frame, v8::Isolate* isolate) { |
| 46 if (!IsCheckoutURL(frame->document().url().spec())) { | 46 if (!IsCheckoutURL(frame->document().url().spec())) { |
| 47 std::string error("Access denied for URL: "); | 47 std::string error("Access denied for URL: "); |
| 48 error += frame->document().url().spec(); | 48 error += frame->document().url().spec(); |
| 49 v8::ThrowException(v8::String::NewFromUtf8(isolate, error.c_str())); | 49 isolate->ThrowException(v8::String::NewFromUtf8(isolate, error.c_str())); |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 const char* kInvalidCallbackIdError = "Invalid callbackId"; | 56 const char* kInvalidCallbackIdError = "Invalid callbackId"; |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 88 args.GetReturnValue().Set(GetDetailsForFrameImpl(context()->web_frame())); | 88 args.GetReturnValue().Set(GetDetailsForFrameImpl(context()->web_frame())); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void AppBindings::GetDetailsForFrame( | 91 void AppBindings::GetDetailsForFrame( |
| 92 const v8::FunctionCallbackInfo<v8::Value>& args) { | 92 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 93 CHECK(context()->web_frame()); | 93 CHECK(context()->web_frame()); |
| 94 if (!CheckAccessToAppDetails(context()->web_frame(), context()->isolate())) | 94 if (!CheckAccessToAppDetails(context()->web_frame(), context()->isolate())) |
| 95 return; | 95 return; |
| 96 | 96 |
| 97 if (args.Length() < 0) { | 97 if (args.Length() < 0) { |
| 98 v8::ThrowException( | 98 context()->isolate()->ThrowException( |
| 99 v8::String::NewFromUtf8(context()->isolate(), "Not enough arguments.")); | 99 v8::String::NewFromUtf8(context()->isolate(), "Not enough arguments.")); |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 | 102 |
| 103 if (!args[0]->IsObject()) { | 103 if (!args[0]->IsObject()) { |
| 104 v8::ThrowException(v8::String::NewFromUtf8( | 104 context()->isolate()->ThrowException(v8::String::NewFromUtf8( |
| 105 context()->isolate(), "Argument 0 must be an object.")); | 105 context()->isolate(), "Argument 0 must be an object.")); |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 | 108 |
| 109 v8::Local<v8::Context> context = | 109 v8::Local<v8::Context> context = |
| 110 v8::Local<v8::Object>::Cast(args[0])->CreationContext(); | 110 v8::Local<v8::Object>::Cast(args[0])->CreationContext(); |
| 111 CHECK(!context.IsEmpty()); | 111 CHECK(!context.IsEmpty()); |
| 112 | 112 |
| 113 WebFrame* target_frame = WebFrame::frameForContext(context); | 113 WebFrame* target_frame = WebFrame::frameForContext(context); |
| 114 if (!target_frame) { | 114 if (!target_frame) { |
| 115 console::Error(v8::Context::GetCalling(), | 115 console::Error(args.GetIsolate()->GetCallingContext(), |
| 116 "Could not find frame for specified object."); | 116 "Could not find frame for specified object."); |
| 117 return; | 117 return; |
| 118 } | 118 } |
| 119 | 119 |
| 120 args.GetReturnValue().Set(GetDetailsForFrameImpl(target_frame)); | 120 args.GetReturnValue().Set(GetDetailsForFrameImpl(target_frame)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 v8::Handle<v8::Value> AppBindings::GetDetailsForFrameImpl( | 123 v8::Handle<v8::Value> AppBindings::GetDetailsForFrameImpl( |
| 124 WebFrame* frame) { | 124 WebFrame* frame) { |
| 125 v8::Isolate* isolate = frame->mainWorldScriptContext()->GetIsolate(); |
| 125 if (frame->document().securityOrigin().isUnique()) | 126 if (frame->document().securityOrigin().isUnique()) |
| 126 return v8::Null(); | 127 return v8::Null(isolate); |
| 127 | 128 |
| 128 const Extension* extension = | 129 const Extension* extension = |
| 129 dispatcher_->extensions()->GetExtensionOrAppByURL( | 130 dispatcher_->extensions()->GetExtensionOrAppByURL( |
| 130 frame->document().url()); | 131 frame->document().url()); |
| 131 | 132 |
| 132 if (!extension) | 133 if (!extension) |
| 133 return v8::Null(); | 134 return v8::Null(isolate); |
| 134 | 135 |
| 135 scoped_ptr<base::DictionaryValue> manifest_copy( | 136 scoped_ptr<base::DictionaryValue> manifest_copy( |
| 136 extension->manifest()->value()->DeepCopy()); | 137 extension->manifest()->value()->DeepCopy()); |
| 137 manifest_copy->SetString("id", extension->id()); | 138 manifest_copy->SetString("id", extension->id()); |
| 138 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 139 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 139 return converter->ToV8Value(manifest_copy.get(), | 140 return converter->ToV8Value(manifest_copy.get(), |
| 140 frame->mainWorldScriptContext()); | 141 frame->mainWorldScriptContext()); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void AppBindings::GetInstallState( | 144 void AppBindings::GetInstallState( |
| 144 const v8::FunctionCallbackInfo<v8::Value>& args) { | 145 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 145 // Get the callbackId. | 146 // Get the callbackId. |
| 146 int callback_id = 0; | 147 int callback_id = 0; |
| 147 if (args.Length() == 1) { | 148 if (args.Length() == 1) { |
| 148 if (!args[0]->IsInt32()) { | 149 if (!args[0]->IsInt32()) { |
| 149 v8::ThrowException(v8::String::NewFromUtf8(context()->isolate(), | 150 context()->isolate()->ThrowException(v8::String::NewFromUtf8( |
| 150 kInvalidCallbackIdError)); | 151 context()->isolate(), kInvalidCallbackIdError)); |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 callback_id = args[0]->Int32Value(); | 154 callback_id = args[0]->Int32Value(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 content::RenderView* render_view = context()->GetRenderView(); | 157 content::RenderView* render_view = context()->GetRenderView(); |
| 157 CHECK(render_view); | 158 CHECK(render_view); |
| 158 | 159 |
| 159 Send(new ExtensionHostMsg_GetAppInstallState( | 160 Send(new ExtensionHostMsg_GetAppInstallState( |
| 160 render_view->GetRoutingID(), context()->web_frame()->document().url(), | 161 render_view->GetRoutingID(), context()->web_frame()->document().url(), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 v8::Context::Scope context_scope(context()->v8_context()); | 217 v8::Context::Scope context_scope(context()->v8_context()); |
| 217 v8::Handle<v8::Value> argv[] = { | 218 v8::Handle<v8::Value> argv[] = { |
| 218 v8::String::NewFromUtf8(context()->isolate(), state.c_str()), | 219 v8::String::NewFromUtf8(context()->isolate(), state.c_str()), |
| 219 v8::Integer::New(callback_id) | 220 v8::Integer::New(callback_id) |
| 220 }; | 221 }; |
| 221 context()->module_system()->CallModuleMethod( | 222 context()->module_system()->CallModuleMethod( |
| 222 "app", "onInstallStateResponse", arraysize(argv), argv); | 223 "app", "onInstallStateResponse", arraysize(argv), argv); |
| 223 } | 224 } |
| 224 | 225 |
| 225 } // namespace extensions | 226 } // namespace extensions |
| OLD | NEW |