Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
| 13 #include "content/public/child/v8_value_converter.h" | 13 #include "content/public/child/v8_value_converter.h" |
| 14 #include "content/public/common/bindings_policy.h" | 14 #include "content/public/common/bindings_policy.h" |
| 15 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
| 16 #include "content/public/renderer/chrome_object_extensions_utils.h" | 16 #include "content/public/renderer/chrome_object_extensions_utils.h" |
| 17 #include "content/public/renderer/render_frame.h" | |
| 17 #include "content/public/renderer/render_thread.h" | 18 #include "content/public/renderer/render_thread.h" |
| 18 #include "content/public/renderer/render_view.h" | 19 #include "content/public/renderer/render_view.h" |
| 19 #include "content/renderer/web_ui_extension_data.h" | 20 #include "content/renderer/web_ui_extension_data.h" |
| 20 #include "gin/arguments.h" | 21 #include "gin/arguments.h" |
| 21 #include "gin/function_template.h" | 22 #include "gin/function_template.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebKit.h" | 24 #include "third_party/WebKit/public/web/WebKit.h" |
| 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 25 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 25 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 26 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 26 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 blink::WebFrame* frame = blink::WebLocalFrame::frameForCurrentContext(); | 38 blink::WebFrame* frame = blink::WebLocalFrame::frameForCurrentContext(); |
| 38 if (!frame || !frame->view()) | 39 if (!frame || !frame->view()) |
| 39 return false; | 40 return false; |
| 40 | 41 |
| 41 RenderView* render_view = RenderView::FromWebView(frame->view()); | 42 RenderView* render_view = RenderView::FromWebView(frame->view()); |
| 42 if (!render_view) | 43 if (!render_view) |
| 43 return false; | 44 return false; |
| 44 | 45 |
| 45 GURL frame_url = frame->document().url(); | 46 GURL frame_url = frame->document().url(); |
| 46 | 47 |
| 48 RenderFrame* render_frame = render_view->GetMainRenderFrame(); | |
|
Charlie Reis
2016/12/16 01:01:52
Is this wrong? The frame_ptr passed in might not
Sam McNally
2017/01/12 09:27:09
Done.
| |
| 49 if (!render_frame) | |
| 50 return false; | |
| 51 | |
| 47 bool webui_enabled = | 52 bool webui_enabled = |
| 48 (render_view->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI) && | 53 (render_frame->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI) && |
| 49 (frame_url.SchemeIs(kChromeUIScheme) || | 54 (frame_url.SchemeIs(kChromeUIScheme) || |
| 50 frame_url.SchemeIs(url::kDataScheme)); | 55 frame_url.SchemeIs(url::kDataScheme)); |
| 51 | 56 |
| 52 if (!webui_enabled) | 57 if (!webui_enabled) |
| 53 return false; | 58 return false; |
| 54 | 59 |
| 55 *frame_ptr = frame; | 60 *frame_ptr = frame; |
| 56 *render_view_ptr = render_view; | 61 *render_view_ptr = render_view; |
| 57 return true; | 62 return true; |
| 58 } | 63 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 return; | 122 return; |
| 118 } | 123 } |
| 119 | 124 |
| 120 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 125 std::unique_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 121 content = base::ListValue::From( | 126 content = base::ListValue::From( |
| 122 converter->FromV8Value(obj, frame->mainWorldScriptContext())); | 127 converter->FromV8Value(obj, frame->mainWorldScriptContext())); |
| 123 DCHECK(content); | 128 DCHECK(content); |
| 124 } | 129 } |
| 125 | 130 |
| 126 // Send the message up to the browser. | 131 // Send the message up to the browser. |
| 127 render_view->Send(new ViewHostMsg_WebUISend(render_view->GetRoutingID(), | 132 render_view->Send(new ViewHostMsg_WebUISend(render_view->GetRoutingID(), |
|
Charlie Reis
2016/12/16 01:01:52
I suppose this class will need conversion soon as
Sam McNally
2017/01/12 09:27:09
I think so.
| |
| 128 frame->document().url(), | 133 frame->document().url(), |
| 129 message, | 134 message, |
| 130 *content)); | 135 *content)); |
| 131 } | 136 } |
| 132 | 137 |
| 133 // static | 138 // static |
| 134 std::string WebUIExtension::GetVariableValue(const std::string& name) { | 139 std::string WebUIExtension::GetVariableValue(const std::string& name) { |
| 135 blink::WebFrame* frame; | 140 blink::WebFrame* frame; |
| 136 RenderView* render_view; | 141 RenderView* render_view; |
| 137 if (!ShouldRespondToRequest(&frame, &render_view)) | 142 if (!ShouldRespondToRequest(&frame, &render_view)) |
| 138 return std::string(); | 143 return std::string(); |
| 139 | 144 |
| 140 return WebUIExtensionData::Get(render_view)->GetValue(name); | 145 return WebUIExtensionData::Get(render_view)->GetValue(name); |
| 141 } | 146 } |
| 142 | 147 |
| 143 } // namespace content | 148 } // namespace content |
| OLD | NEW |