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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
12 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 13 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "content/common/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "content/public/common/bindings_policy.h" | 15 #include "content/public/common/bindings_policy.h" |
16 | 16 |
17 static base::LazyInstance<PropertyAccessor<HtmlDialogUIDelegate*> > | 17 static base::LazyInstance<PropertyAccessor<HtmlDialogUIDelegate*> > |
18 g_html_dialog_ui_property_accessor(base::LINKER_INITIALIZED); | 18 g_html_dialog_ui_property_accessor(base::LINKER_INITIALIZED); |
19 | 19 |
20 HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents) | 20 HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents) |
21 : ChromeWebUI(tab_contents) { | 21 : ChromeWebUI(tab_contents) { |
22 } | 22 } |
23 | 23 |
24 HtmlDialogUI::~HtmlDialogUI() { | 24 HtmlDialogUI::~HtmlDialogUI() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 if (0 != (bindings_ & content::BINDINGS_POLICY_WEB_UI)) | 63 if (0 != (bindings_ & content::BINDINGS_POLICY_WEB_UI)) |
64 render_view_host->SetWebUIProperty("dialogArguments", dialog_args); | 64 render_view_host->SetWebUIProperty("dialogArguments", dialog_args); |
65 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); | 65 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); |
66 it != handlers.end(); ++it) { | 66 it != handlers.end(); ++it) { |
67 (*it)->Attach(this); | 67 (*it)->Attach(this); |
68 AddMessageHandler(*it); | 68 AddMessageHandler(*it); |
69 } | 69 } |
70 | 70 |
71 NotificationService::current()->Notify( | 71 content::NotificationService::current()->Notify( |
72 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, | 72 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, |
73 content::Source<HtmlDialogUI>(this), | 73 content::Source<HtmlDialogUI>(this), |
74 NotificationService::NoDetails()); | 74 content::NotificationService::NoDetails()); |
75 } | 75 } |
76 | 76 |
77 void HtmlDialogUI::OnDialogClosed(const ListValue* args) { | 77 void HtmlDialogUI::OnDialogClosed(const ListValue* args) { |
78 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( | 78 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( |
79 tab_contents()->property_bag()); | 79 tab_contents()->property_bag()); |
80 if (delegate) { | 80 if (delegate) { |
81 std::string json_retval; | 81 std::string json_retval; |
82 if (args && !args->empty() && !args->GetString(0, &json_retval)) | 82 if (args && !args->empty() && !args->GetString(0, &json_retval)) |
83 NOTREACHED() << "Could not read JSON argument"; | 83 NOTREACHED() << "Could not read JSON argument"; |
84 | 84 |
85 (*delegate)->OnDialogClosed(json_retval); | 85 (*delegate)->OnDialogClosed(json_retval); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 ExternalHtmlDialogUI::ExternalHtmlDialogUI(TabContents* tab_contents) | 89 ExternalHtmlDialogUI::ExternalHtmlDialogUI(TabContents* tab_contents) |
90 : HtmlDialogUI(tab_contents) { | 90 : HtmlDialogUI(tab_contents) { |
91 // Non-file based UI needs to not have access to the Web UI bindings | 91 // Non-file based UI needs to not have access to the Web UI bindings |
92 // for security reasons. The code hosting the dialog should provide | 92 // for security reasons. The code hosting the dialog should provide |
93 // dialog specific functionality through other bindings and methods | 93 // dialog specific functionality through other bindings and methods |
94 // that are scoped in duration to the dialogs existence. | 94 // that are scoped in duration to the dialogs existence. |
95 bindings_ &= ~content::BINDINGS_POLICY_WEB_UI; | 95 bindings_ &= ~content::BINDINGS_POLICY_WEB_UI; |
96 } | 96 } |
97 | 97 |
98 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { | 98 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { |
99 } | 99 } |
100 | 100 |
101 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { | 101 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { |
102 return false; | 102 return false; |
103 } | 103 } |
OLD | NEW |