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/property_bag.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "content/browser/renderer_host/render_view_host.h" | 13 #include "content/browser/renderer_host/render_view_host.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
15 #include "content/public/common/bindings_policy.h" | 16 #include "content/public/common/bindings_policy.h" |
16 | 17 |
17 static base::LazyInstance<PropertyAccessor<HtmlDialogUIDelegate*> > | 18 static base::LazyInstance<base::PropertyAccessor<HtmlDialogUIDelegate*> > |
18 g_html_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; | 19 g_html_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; |
19 | 20 |
20 HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents) | 21 HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents) |
21 : ChromeWebUI(tab_contents) { | 22 : ChromeWebUI(tab_contents) { |
22 } | 23 } |
23 | 24 |
24 HtmlDialogUI::~HtmlDialogUI() { | 25 HtmlDialogUI::~HtmlDialogUI() { |
25 // Don't unregister our property. During the teardown of the TabContents, | 26 // Don't unregister our property. During the teardown of the TabContents, |
26 // this will be deleted, but the TabContents will already be destroyed. | 27 // this will be deleted, but the TabContents will already be destroyed. |
27 // | 28 // |
28 // This object is owned indirectly by the TabContents. WebUIs can change, so | 29 // This object is owned indirectly by the TabContents. WebUIs can change, so |
29 // it's scary if this WebUI is changed out and replaced with something else, | 30 // it's scary if this WebUI is changed out and replaced with something else, |
30 // since the property will still point to the old delegate. But the delegate | 31 // since the property will still point to the old delegate. But the delegate |
31 // is itself the owner of the TabContents for a dialog so will be in scope, | 32 // is itself the owner of the TabContents for a dialog so will be in scope, |
32 // and the HTML dialogs won't swap WebUIs anyway since they don't navigate. | 33 // and the HTML dialogs won't swap WebUIs anyway since they don't navigate. |
33 } | 34 } |
34 | 35 |
35 void HtmlDialogUI::CloseDialog(const base::ListValue* args) { | 36 void HtmlDialogUI::CloseDialog(const base::ListValue* args) { |
36 OnDialogClosed(args); | 37 OnDialogClosed(args); |
37 } | 38 } |
38 | 39 |
39 // static | 40 // static |
40 PropertyAccessor<HtmlDialogUIDelegate*>& HtmlDialogUI::GetPropertyAccessor() { | 41 base::PropertyAccessor<HtmlDialogUIDelegate*>& |
| 42 HtmlDialogUI::GetPropertyAccessor() { |
41 return g_html_dialog_ui_property_accessor.Get(); | 43 return g_html_dialog_ui_property_accessor.Get(); |
42 } | 44 } |
43 | 45 |
44 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
45 // Private: | 47 // Private: |
46 | 48 |
47 void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { | 49 void HtmlDialogUI::RenderViewCreated(RenderViewHost* render_view_host) { |
48 // Hook up the javascript function calls, also known as chrome.send("foo") | 50 // Hook up the javascript function calls, also known as chrome.send("foo") |
49 // calls in the HTML, to the actual C++ functions. | 51 // calls in the HTML, to the actual C++ functions. |
50 RegisterMessageCallback("DialogClose", | 52 RegisterMessageCallback("DialogClose", |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // that are scoped in duration to the dialogs existence. | 96 // that are scoped in duration to the dialogs existence. |
95 bindings_ &= ~content::BINDINGS_POLICY_WEB_UI; | 97 bindings_ &= ~content::BINDINGS_POLICY_WEB_UI; |
96 } | 98 } |
97 | 99 |
98 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { | 100 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { |
99 } | 101 } |
100 | 102 |
101 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { | 103 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { |
102 return false; | 104 return false; |
103 } | 105 } |
OLD | NEW |