| 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/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 console::Error(v8::Context::GetCalling(), | 110 console::Error(v8::Context::GetCalling(), |
| 111 "Could not find frame for specified object."); | 111 "Could not find frame for specified object."); |
| 112 return v8::Undefined(); | 112 return v8::Undefined(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 return GetDetailsForFrameImpl(target_frame); | 115 return GetDetailsForFrameImpl(target_frame); |
| 116 } | 116 } |
| 117 | 117 |
| 118 v8::Handle<v8::Value> AppBindings::GetDetailsForFrameImpl( | 118 v8::Handle<v8::Value> AppBindings::GetDetailsForFrameImpl( |
| 119 WebFrame* frame) { | 119 WebFrame* frame) { |
| 120 if (frame->document().securityOrigin().isUnique()) |
| 121 return v8::Null(); |
| 122 |
| 120 const Extension* extension = | 123 const Extension* extension = |
| 121 dispatcher_->extensions()->GetExtensionOrAppByURL( | 124 dispatcher_->extensions()->GetExtensionOrAppByURL( |
| 122 ExtensionURLInfo(frame->document().securityOrigin(), | 125 frame->document().url()); |
| 123 frame->document().url())); | 126 |
| 124 if (!extension) | 127 if (!extension) |
| 125 return v8::Null(); | 128 return v8::Null(); |
| 126 | 129 |
| 127 scoped_ptr<DictionaryValue> manifest_copy( | 130 scoped_ptr<DictionaryValue> manifest_copy( |
| 128 extension->manifest()->value()->DeepCopy()); | 131 extension->manifest()->value()->DeepCopy()); |
| 129 manifest_copy->SetString("id", extension->id()); | 132 manifest_copy->SetString("id", extension->id()); |
| 130 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 133 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 131 return converter->ToV8Value(manifest_copy.get(), | 134 return converter->ToV8Value(manifest_copy.get(), |
| 132 frame->mainWorldScriptContext()); | 135 frame->mainWorldScriptContext()); |
| 133 } | 136 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 156 // To distinguish between ready_to_run and cannot_run states, we need the top | 159 // To distinguish between ready_to_run and cannot_run states, we need the top |
| 157 // level frame. | 160 // level frame. |
| 158 const WebFrame* parent_frame = context()->web_frame(); | 161 const WebFrame* parent_frame = context()->web_frame(); |
| 159 while (parent_frame->parent()) | 162 while (parent_frame->parent()) |
| 160 parent_frame = parent_frame->parent(); | 163 parent_frame = parent_frame->parent(); |
| 161 | 164 |
| 162 const ExtensionSet* extensions = dispatcher_->extensions(); | 165 const ExtensionSet* extensions = dispatcher_->extensions(); |
| 163 | 166 |
| 164 // The app associated with the top level frame. | 167 // The app associated with the top level frame. |
| 165 const Extension* parent_app = extensions->GetHostedAppByURL( | 168 const Extension* parent_app = extensions->GetHostedAppByURL( |
| 166 ExtensionURLInfo(parent_frame->document().url())); | 169 parent_frame->document().url()); |
| 167 | 170 |
| 168 // The app associated with this frame. | 171 // The app associated with this frame. |
| 169 const Extension* this_app = extensions->GetHostedAppByURL(ExtensionURLInfo( | 172 const Extension* this_app = extensions->GetHostedAppByURL( |
| 170 context()->web_frame()->document().url())); | 173 context()->web_frame()->document().url()); |
| 171 | 174 |
| 172 if (!this_app || !parent_app) | 175 if (!this_app || !parent_app) |
| 173 return v8::String::New(extension_misc::kAppStateCannotRun); | 176 return v8::String::New(extension_misc::kAppStateCannotRun); |
| 174 | 177 |
| 175 const char* state = NULL; | 178 const char* state = NULL; |
| 176 if (dispatcher_->IsExtensionActive(parent_app->id())) { | 179 if (dispatcher_->IsExtensionActive(parent_app->id())) { |
| 177 if (parent_app == this_app) | 180 if (parent_app == this_app) |
| 178 state = extension_misc::kAppStateRunning; | 181 state = extension_misc::kAppStateRunning; |
| 179 else | 182 else |
| 180 state = extension_misc::kAppStateCannotRun; | 183 state = extension_misc::kAppStateCannotRun; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 202 v8::Context::Scope context_scope(context()->v8_context()); | 205 v8::Context::Scope context_scope(context()->v8_context()); |
| 203 v8::Handle<v8::Value> argv[] = { | 206 v8::Handle<v8::Value> argv[] = { |
| 204 v8::String::New(state.c_str()), | 207 v8::String::New(state.c_str()), |
| 205 v8::Integer::New(callback_id) | 208 v8::Integer::New(callback_id) |
| 206 }; | 209 }; |
| 207 context()->module_system()->CallModuleMethod( | 210 context()->module_system()->CallModuleMethod( |
| 208 "app", "onInstallStateResponse", arraysize(argv), argv); | 211 "app", "onInstallStateResponse", arraysize(argv), argv); |
| 209 } | 212 } |
| 210 | 213 |
| 211 } // namespace extensions | 214 } // namespace extensions |
| OLD | NEW |