OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "content/renderer/web_ui_extension.h" | 5 #include "content/renderer/web_ui_extension.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
8 #include "base/values.h" | 9 #include "base/values.h" |
9 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
10 #include "content/public/child/v8_value_converter.h" | 11 #include "content/public/child/v8_value_converter.h" |
11 #include "content/public/common/bindings_policy.h" | 12 #include "content/public/common/bindings_policy.h" |
12 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
13 #include "content/public/renderer/chrome_object_extensions_utils.h" | 14 #include "content/public/renderer/chrome_object_extensions_utils.h" |
14 #include "content/public/renderer/render_thread.h" | 15 #include "content/public/renderer/render_thread.h" |
15 #include "content/public/renderer/render_view.h" | 16 #include "content/public/renderer/render_view.h" |
16 #include "content/renderer/web_ui_extension_data.h" | 17 #include "content/renderer/web_ui_extension_data.h" |
17 #include "gin/arguments.h" | 18 #include "gin/arguments.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return; | 90 return; |
90 | 91 |
91 std::string message; | 92 std::string message; |
92 if (!args->GetNext(&message)) { | 93 if (!args->GetNext(&message)) { |
93 args->ThrowError(); | 94 args->ThrowError(); |
94 return; | 95 return; |
95 } | 96 } |
96 | 97 |
97 // If they've provided an optional message parameter, convert that into a | 98 // If they've provided an optional message parameter, convert that into a |
98 // Value to send to the browser process. | 99 // Value to send to the browser process. |
99 scoped_ptr<base::ListValue> content; | 100 std::unique_ptr<base::ListValue> content; |
100 if (args->PeekNext().IsEmpty() || args->PeekNext()->IsUndefined()) { | 101 if (args->PeekNext().IsEmpty() || args->PeekNext()->IsUndefined()) { |
101 content.reset(new base::ListValue()); | 102 content.reset(new base::ListValue()); |
102 } else { | 103 } else { |
103 v8::Local<v8::Object> obj; | 104 v8::Local<v8::Object> obj; |
104 if (!args->GetNext(&obj)) { | 105 if (!args->GetNext(&obj)) { |
105 args->ThrowError(); | 106 args->ThrowError(); |
106 return; | 107 return; |
107 } | 108 } |
108 | 109 |
109 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 110 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
110 | 111 |
111 base::Value* value = | 112 base::Value* value = |
112 converter->FromV8Value(obj, frame->mainWorldScriptContext()); | 113 converter->FromV8Value(obj, frame->mainWorldScriptContext()); |
113 base::ListValue* list = NULL; | 114 base::ListValue* list = NULL; |
114 value->GetAsList(&list); | 115 value->GetAsList(&list); |
115 DCHECK(list); | 116 DCHECK(list); |
116 content.reset(list); | 117 content.reset(list); |
117 } | 118 } |
118 | 119 |
119 // Send the message up to the browser. | 120 // Send the message up to the browser. |
120 render_view->Send(new ViewHostMsg_WebUISend(render_view->GetRoutingID(), | 121 render_view->Send(new ViewHostMsg_WebUISend(render_view->GetRoutingID(), |
121 frame->document().url(), | 122 frame->document().url(), |
122 message, | 123 message, |
123 *content)); | 124 *content)); |
124 } | 125 } |
125 | 126 |
126 // static | 127 // static |
127 std::string WebUIExtension::GetVariableValue(const std::string& name) { | 128 std::string WebUIExtension::GetVariableValue(const std::string& name) { |
128 blink::WebFrame* frame; | 129 blink::WebFrame* frame; |
129 RenderView* render_view; | 130 RenderView* render_view; |
130 if (!ShouldRespondToRequest(&frame, &render_view)) | 131 if (!ShouldRespondToRequest(&frame, &render_view)) |
131 return std::string(); | 132 return std::string(); |
132 | 133 |
133 return WebUIExtensionData::Get(render_view)->GetValue(name); | 134 return WebUIExtensionData::Get(render_view)->GetValue(name); |
134 } | 135 } |
135 | 136 |
136 } // namespace content | 137 } // namespace content |
OLD | NEW |