| 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 "extensions/renderer/app_window_custom_bindings.h" | 5 #include "extensions/renderer/app_window_custom_bindings.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/public/child/v8_value_converter.h" | 8 #include "content/public/child/v8_value_converter.h" |
| 9 #include "content/public/renderer/render_frame.h" | 9 #include "content/public/renderer/render_frame.h" |
| 10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| 11 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 12 #include "extensions/common/extension_messages.h" | 12 #include "extensions/common/extension_messages.h" |
| 13 #include "extensions/common/switches.h" | 13 #include "extensions/common/switches.h" |
| 14 #include "extensions/renderer/script_context.h" | 14 #include "extensions/renderer/script_context.h" |
| 15 #include "grit/extensions_renderer_resources.h" | 15 #include "grit/extensions_renderer_resources.h" |
| 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 17 #include "third_party/WebKit/public/web/WebView.h" | 17 #include "third_party/WebKit/public/web/WebView.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "v8/include/v8.h" | 19 #include "v8/include/v8.h" |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 AppWindowCustomBindings::AppWindowCustomBindings(ScriptContext* context) | 23 AppWindowCustomBindings::AppWindowCustomBindings(ScriptContext* context) |
| 24 : ObjectBackedNativeHandler(context) { | 24 : ObjectBackedNativeHandler(context) { |
| 25 RouteFunction("GetFrame", base::Bind(&AppWindowCustomBindings::GetFrame, | 25 RouteFunction("GetFrame", base::Bind(&AppWindowCustomBindings::GetFrame, |
| 26 base::Unretained(this))); | 26 base::Unretained(this))); |
| 27 | |
| 28 RouteFunction("GetWindowControlsHtmlTemplate", | |
| 29 base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate, | |
| 30 base::Unretained(this))); | |
| 31 } | 27 } |
| 32 | 28 |
| 33 void AppWindowCustomBindings::GetFrame( | 29 void AppWindowCustomBindings::GetFrame( |
| 34 const v8::FunctionCallbackInfo<v8::Value>& args) { | 30 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 35 // TODO(jeremya): convert this to IDL nocompile to get validation, and turn | 31 // TODO(jeremya): convert this to IDL nocompile to get validation, and turn |
| 36 // these argument checks into CHECK(). | 32 // these argument checks into CHECK(). |
| 37 if (args.Length() != 2) | 33 if (args.Length() != 2) |
| 38 return; | 34 return; |
| 39 | 35 |
| 40 if (!args[0]->IsInt32() || !args[1]->IsBoolean()) | 36 if (!args[0]->IsInt32() || !args[1]->IsBoolean()) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 if (notify_browser) { | 50 if (notify_browser) { |
| 55 content::RenderThread::Get()->Send(new ExtensionHostMsg_AppWindowReady( | 51 content::RenderThread::Get()->Send(new ExtensionHostMsg_AppWindowReady( |
| 56 app_frame->GetRenderView()->GetRoutingID())); | 52 app_frame->GetRenderView()->GetRoutingID())); |
| 57 } | 53 } |
| 58 | 54 |
| 59 v8::Local<v8::Value> window = | 55 v8::Local<v8::Value> window = |
| 60 app_frame->GetWebFrame()->mainWorldScriptContext()->Global(); | 56 app_frame->GetWebFrame()->mainWorldScriptContext()->Global(); |
| 61 args.GetReturnValue().Set(window); | 57 args.GetReturnValue().Set(window); |
| 62 } | 58 } |
| 63 | 59 |
| 64 void AppWindowCustomBindings::GetWindowControlsHtmlTemplate( | |
| 65 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 66 CHECK_EQ(args.Length(), 0); | |
| 67 | |
| 68 v8::Local<v8::Value> result = v8::String::Empty(args.GetIsolate()); | |
| 69 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 70 switches::kEnableAppWindowControls)) { | |
| 71 base::StringValue value( | |
| 72 ResourceBundle::GetSharedInstance() | |
| 73 .GetRawDataResource(IDR_WINDOW_CONTROLS_TEMPLATE_HTML) | |
| 74 .as_string()); | |
| 75 std::unique_ptr<content::V8ValueConverter> converter( | |
| 76 content::V8ValueConverter::create()); | |
| 77 result = converter->ToV8Value(&value, context()->v8_context()); | |
| 78 } | |
| 79 args.GetReturnValue().Set(result); | |
| 80 } | |
| 81 | |
| 82 } // namespace extensions | 60 } // namespace extensions |
| OLD | NEW |