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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
14 #include "content/public/child/v8_value_converter.h" | 14 #include "content/public/child/v8_value_converter.h" |
15 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
16 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
17 #include "extensions/common/extension_messages.h" | 17 #include "extensions/common/extension_messages.h" |
18 #include "extensions/common/extension_set.h" | 18 #include "extensions/common/extension_set.h" |
19 #include "extensions/common/manifest.h" | 19 #include "extensions/common/manifest.h" |
20 #include "extensions/renderer/console.h" | 20 #include "extensions/renderer/console.h" |
21 #include "extensions/renderer/dispatcher.h" | 21 #include "extensions/renderer/dispatcher.h" |
22 #include "extensions/renderer/extension_helper.h" | 22 #include "extensions/renderer/extension_helper.h" |
| 23 #include "extensions/renderer/renderer_extension_registry.h" |
23 #include "extensions/renderer/script_context.h" | 24 #include "extensions/renderer/script_context.h" |
24 #include "third_party/WebKit/public/web/WebDocument.h" | 25 #include "third_party/WebKit/public/web/WebDocument.h" |
25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
26 #include "v8/include/v8.h" | 27 #include "v8/include/v8.h" |
27 | 28 |
28 using blink::WebFrame; | 29 using blink::WebFrame; |
29 using content::V8ValueConverter; | 30 using content::V8ValueConverter; |
30 | 31 |
31 namespace extensions { | 32 namespace extensions { |
32 | 33 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 CHECK(web_frame); | 69 CHECK(web_frame); |
69 args.GetReturnValue().Set(GetDetailsImpl(web_frame)); | 70 args.GetReturnValue().Set(GetDetailsImpl(web_frame)); |
70 } | 71 } |
71 | 72 |
72 v8::Local<v8::Value> AppBindings::GetDetailsImpl(blink::WebLocalFrame* frame) { | 73 v8::Local<v8::Value> AppBindings::GetDetailsImpl(blink::WebLocalFrame* frame) { |
73 v8::Isolate* isolate = frame->mainWorldScriptContext()->GetIsolate(); | 74 v8::Isolate* isolate = frame->mainWorldScriptContext()->GetIsolate(); |
74 if (frame->document().securityOrigin().isUnique()) | 75 if (frame->document().securityOrigin().isUnique()) |
75 return v8::Null(isolate); | 76 return v8::Null(isolate); |
76 | 77 |
77 const Extension* extension = | 78 const Extension* extension = |
78 dispatcher_->extensions()->GetExtensionOrAppByURL( | 79 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL( |
79 frame->document().url()); | 80 frame->document().url()); |
80 | 81 |
81 if (!extension) | 82 if (!extension) |
82 return v8::Null(isolate); | 83 return v8::Null(isolate); |
83 | 84 |
84 scoped_ptr<base::DictionaryValue> manifest_copy( | 85 scoped_ptr<base::DictionaryValue> manifest_copy( |
85 extension->manifest()->value()->DeepCopy()); | 86 extension->manifest()->value()->DeepCopy()); |
86 manifest_copy->SetString("id", extension->id()); | 87 manifest_copy->SetString("id", extension->id()); |
87 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 88 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
88 return converter->ToV8Value(manifest_copy.get(), | 89 return converter->ToV8Value(manifest_copy.get(), |
(...skipping 20 matching lines...) Expand all Loading... |
109 render_frame->GetRoutingID(), context()->web_frame()->document().url(), | 110 render_frame->GetRoutingID(), context()->web_frame()->document().url(), |
110 GetRoutingID(), callback_id)); | 111 GetRoutingID(), callback_id)); |
111 } | 112 } |
112 | 113 |
113 void AppBindings::GetRunningState( | 114 void AppBindings::GetRunningState( |
114 const v8::FunctionCallbackInfo<v8::Value>& args) { | 115 const v8::FunctionCallbackInfo<v8::Value>& args) { |
115 // To distinguish between ready_to_run and cannot_run states, we need the app | 116 // To distinguish between ready_to_run and cannot_run states, we need the app |
116 // from the top frame. | 117 // from the top frame. |
117 blink::WebSecurityOrigin top_frame_security_origin = | 118 blink::WebSecurityOrigin top_frame_security_origin = |
118 context()->web_frame()->top()->securityOrigin(); | 119 context()->web_frame()->top()->securityOrigin(); |
119 const ExtensionSet* extensions = dispatcher_->extensions(); | 120 const RendererExtensionRegistry* extensions = |
| 121 RendererExtensionRegistry::Get(); |
120 | 122 |
121 // The app associated with the top level frame. | 123 // The app associated with the top level frame. |
122 const Extension* top_app = extensions->GetHostedAppByURL( | 124 const Extension* top_app = extensions->GetHostedAppByURL( |
123 GURL(top_frame_security_origin.toString().utf8())); | 125 GURL(top_frame_security_origin.toString().utf8())); |
124 | 126 |
125 // The app associated with this frame. | 127 // The app associated with this frame. |
126 const Extension* this_app = extensions->GetHostedAppByURL( | 128 const Extension* this_app = extensions->GetHostedAppByURL( |
127 context()->web_frame()->document().url()); | 129 context()->web_frame()->document().url()); |
128 | 130 |
129 if (!this_app || !top_app) { | 131 if (!this_app || !top_app) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 v8::Context::Scope context_scope(context()->v8_context()); | 166 v8::Context::Scope context_scope(context()->v8_context()); |
165 v8::Local<v8::Value> argv[] = { | 167 v8::Local<v8::Value> argv[] = { |
166 v8::String::NewFromUtf8(isolate, state.c_str()), | 168 v8::String::NewFromUtf8(isolate, state.c_str()), |
167 v8::Integer::New(isolate, callback_id) | 169 v8::Integer::New(isolate, callback_id) |
168 }; | 170 }; |
169 context()->module_system()->CallModuleMethod( | 171 context()->module_system()->CallModuleMethod( |
170 "app", "onInstallStateResponse", arraysize(argv), argv); | 172 "app", "onInstallStateResponse", arraysize(argv), argv); |
171 } | 173 } |
172 | 174 |
173 } // namespace extensions | 175 } // namespace extensions |
OLD | NEW |