| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/ui/webui/html_dialog_ui.h" | 5 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Don't unregister our property. During the teardown of the TabContents, | 22 // Don't unregister our property. During the teardown of the TabContents, |
| 23 // this will be deleted, but the TabContents will already be destroyed. | 23 // this will be deleted, but the TabContents will already be destroyed. |
| 24 // | 24 // |
| 25 // This object is owned indirectly by the TabContents. WebUIs can change, so | 25 // This object is owned indirectly by the TabContents. WebUIs can change, so |
| 26 // it's scary if this WebUI is changed out and replaced with something else, | 26 // it's scary if this WebUI is changed out and replaced with something else, |
| 27 // since the property will still point to the old delegate. But the delegate | 27 // since the property will still point to the old delegate. But the delegate |
| 28 // is itself the owner of the TabContents for a dialog so will be in scope, | 28 // is itself the owner of the TabContents for a dialog so will be in scope, |
| 29 // and the HTML dialogs won't swap WebUIs anyway since they don't navigate. | 29 // and the HTML dialogs won't swap WebUIs anyway since they don't navigate. |
| 30 } | 30 } |
| 31 | 31 |
| 32 void HtmlDialogUI::CloseDialog(const base::ListValue* args) { | |
| 33 OnDialogClosed(args); | |
| 34 } | |
| 35 | |
| 36 // static | 32 // static |
| 37 PropertyAccessor<HtmlDialogUIDelegate*>& HtmlDialogUI::GetPropertyAccessor() { | 33 PropertyAccessor<HtmlDialogUIDelegate*>& HtmlDialogUI::GetPropertyAccessor() { |
| 38 return g_html_dialog_ui_property_accessor.Get(); | 34 return g_html_dialog_ui_property_accessor.Get(); |
| 39 } | 35 } |
| 40 | 36 |
| 41 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
| 42 // Private: | 38 // Private: |
| 43 | 39 |
| 44 void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { | 40 void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { |
| 45 // Hook up the javascript function calls, also known as chrome.send("foo") | 41 // Hook up the javascript function calls, also known as chrome.send("foo") |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 (*it)->Attach(this); | 60 (*it)->Attach(this); |
| 65 AddMessageHandler(*it); | 61 AddMessageHandler(*it); |
| 66 } | 62 } |
| 67 } | 63 } |
| 68 | 64 |
| 69 void HtmlDialogUI::OnDialogClosed(const ListValue* args) { | 65 void HtmlDialogUI::OnDialogClosed(const ListValue* args) { |
| 70 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( | 66 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( |
| 71 tab_contents()->property_bag()); | 67 tab_contents()->property_bag()); |
| 72 if (delegate) { | 68 if (delegate) { |
| 73 std::string json_retval; | 69 std::string json_retval; |
| 74 if (args && !args->empty() && !args->GetString(0, &json_retval)) | 70 if (!args->GetString(0, &json_retval)) |
| 75 NOTREACHED() << "Could not read JSON argument"; | 71 NOTREACHED() << "Could not read JSON arguments"; |
| 76 | 72 |
| 77 (*delegate)->OnDialogClosed(json_retval); | 73 (*delegate)->OnDialogClosed(json_retval); |
| 78 } | 74 } |
| 79 } | 75 } |
| 80 | 76 |
| 81 ExternalHtmlDialogUI::ExternalHtmlDialogUI(TabContents* tab_contents) | 77 ExternalHtmlDialogUI::ExternalHtmlDialogUI(TabContents* tab_contents) |
| 82 : HtmlDialogUI(tab_contents) { | 78 : HtmlDialogUI(tab_contents) { |
| 83 // Non-file based UI needs to not have access to the Web UI bindings | 79 // Non-file based UI needs to not have access to the Web UI bindings |
| 84 // for security reasons. The code hosting the dialog should provide | 80 // for security reasons. The code hosting the dialog should provide |
| 85 // dialog specific functionality through other bindings and methods | 81 // dialog specific functionality through other bindings and methods |
| 86 // that are scoped in duration to the dialogs existence. | 82 // that are scoped in duration to the dialogs existence. |
| 87 bindings_ &= ~BindingsPolicy::WEB_UI; | 83 bindings_ &= ~BindingsPolicy::WEB_UI; |
| 88 } | 84 } |
| 89 | 85 |
| 90 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { | 86 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { |
| 91 } | 87 } |
| 92 | 88 |
| 93 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { | 89 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { |
| 94 return false; | 90 return false; |
| 95 } | 91 } |
| OLD | NEW |