Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: chrome/browser/ui/webui/html_dialog_ui.cc

Issue 9188056: Start splitting out WebUI into an implementation class and an interface that each page implements... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/html_dialog_ui.h ('k') | chrome/browser/ui/webui/keyboard_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/property_bag.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "content/browser/renderer_host/render_view_host.h" 13 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui_message_handler.h" 16 #include "content/public/browser/web_ui_message_handler.h"
17 #include "content/public/common/bindings_policy.h" 17 #include "content/public/common/bindings_policy.h"
18 18
19 using content::WebContents; 19 using content::WebContents;
20 using content::WebUIMessageHandler; 20 using content::WebUIMessageHandler;
21 21
22 static base::LazyInstance<base::PropertyAccessor<HtmlDialogUIDelegate*> > 22 static base::LazyInstance<base::PropertyAccessor<HtmlDialogUIDelegate*> >
23 g_html_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER; 23 g_html_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
24 24
25 HtmlDialogUI::HtmlDialogUI(WebContents* web_contents) 25 HtmlDialogUI::HtmlDialogUI(WebContents* web_contents)
26 : WebUI(web_contents) { 26 : WebUI(web_contents, this) {
27 } 27 }
28 28
29 HtmlDialogUI::~HtmlDialogUI() { 29 HtmlDialogUI::~HtmlDialogUI() {
30 // Don't unregister our property. During the teardown of the WebContents, 30 // Don't unregister our property. During the teardown of the WebContents,
31 // this will be deleted, but the WebContents will already be destroyed. 31 // this will be deleted, but the WebContents will already be destroyed.
32 // 32 //
33 // This object is owned indirectly by the WebContents. WebUIs can change, so 33 // This object is owned indirectly by the WebContents. WebUIs can change, so
34 // it's scary if this WebUI is changed out and replaced with something else, 34 // it's scary if this WebUI is changed out and replaced with something else,
35 // since the property will still point to the old delegate. But the delegate 35 // since the property will still point to the old delegate. But the delegate
36 // is itself the owner of the WebContents for a dialog so will be in scope, 36 // is itself the owner of the WebContents for a dialog so will be in scope,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 render_view_host->SetWebUIProperty("dialogArguments", dialog_args); 70 render_view_host->SetWebUIProperty("dialogArguments", dialog_args);
71 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); 71 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin();
72 it != handlers.end(); ++it) { 72 it != handlers.end(); ++it) {
73 AddMessageHandler(*it); 73 AddMessageHandler(*it);
74 } 74 }
75 75
76 content::NotificationService::current()->Notify( 76 content::NotificationService::current()->Notify(
77 chrome::NOTIFICATION_HTML_DIALOG_SHOWN, 77 chrome::NOTIFICATION_HTML_DIALOG_SHOWN,
78 content::Source<WebUI>(this), 78 content::Source<WebUI>(this),
79 content::Details<RenderViewHost>(render_view_host)); 79 content::Details<RenderViewHost>(render_view_host));
80
81 WebUI::RenderViewCreated(render_view_host);
82 } 80 }
83 81
84 void HtmlDialogUI::OnDialogClosed(const ListValue* args) { 82 void HtmlDialogUI::OnDialogClosed(const ListValue* args) {
85 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( 83 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty(
86 web_contents()->GetPropertyBag()); 84 web_contents()->GetPropertyBag());
87 if (delegate) { 85 if (delegate) {
88 std::string json_retval; 86 std::string json_retval;
89 if (args && !args->empty() && !args->GetString(0, &json_retval)) 87 if (args && !args->empty() && !args->GetString(0, &json_retval))
90 NOTREACHED() << "Could not read JSON argument"; 88 NOTREACHED() << "Could not read JSON argument";
91 89
92 (*delegate)->OnDialogClosed(json_retval); 90 (*delegate)->OnDialogClosed(json_retval);
93 } 91 }
94 } 92 }
95 93
96 ExternalHtmlDialogUI::ExternalHtmlDialogUI(WebContents* web_contents) 94 ExternalHtmlDialogUI::ExternalHtmlDialogUI(WebContents* web_contents)
97 : HtmlDialogUI(web_contents) { 95 : HtmlDialogUI(web_contents) {
98 // Non-file based UI needs to not have access to the Web UI bindings 96 // Non-file based UI needs to not have access to the Web UI bindings
99 // for security reasons. The code hosting the dialog should provide 97 // for security reasons. The code hosting the dialog should provide
100 // dialog specific functionality through other bindings and methods 98 // dialog specific functionality through other bindings and methods
101 // that are scoped in duration to the dialogs existence. 99 // that are scoped in duration to the dialogs existence.
102 bindings_ &= ~content::BINDINGS_POLICY_WEB_UI; 100 bindings_ &= ~content::BINDINGS_POLICY_WEB_UI;
103 } 101 }
104 102
105 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { 103 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() {
106 } 104 }
107 105
108 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { 106 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) {
109 return false; 107 return false;
110 } 108 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/html_dialog_ui.h ('k') | chrome/browser/ui/webui/keyboard_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698