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

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

Issue 7861024: Adds testing infrastructure to web_ui_browsertest to support testing HtmlDialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add description of what triggers notifications and why it's not a race condition. Created 9 years, 3 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
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/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 "chrome/common/chrome_notification_types.h"
10 #include "content/browser/renderer_host/render_view_host.h" 11 #include "content/browser/renderer_host/render_view_host.h"
11 #include "content/browser/tab_contents/tab_contents.h" 12 #include "content/browser/tab_contents/tab_contents.h"
12 #include "content/common/bindings_policy.h" 13 #include "content/common/bindings_policy.h"
14 #include "content/common/notification_service.h"
13 15
14 static base::LazyInstance<PropertyAccessor<HtmlDialogUIDelegate*> > 16 static base::LazyInstance<PropertyAccessor<HtmlDialogUIDelegate*> >
15 g_html_dialog_ui_property_accessor(base::LINKER_INITIALIZED); 17 g_html_dialog_ui_property_accessor(base::LINKER_INITIALIZED);
16 18
17 HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents) 19 HtmlDialogUI::HtmlDialogUI(TabContents* tab_contents)
18 : ChromeWebUI(tab_contents) { 20 : ChromeWebUI(tab_contents) {
19 } 21 }
20 22
21 HtmlDialogUI::~HtmlDialogUI() { 23 HtmlDialogUI::~HtmlDialogUI() {
22 // Don't unregister our property. During the teardown of the TabContents, 24 // Don't unregister our property. During the teardown of the TabContents,
(...skipping 30 matching lines...) Expand all
53 (*delegate)->GetWebUIMessageHandlers(&handlers); 55 (*delegate)->GetWebUIMessageHandlers(&handlers);
54 } 56 }
55 57
56 if (0 != (bindings_ & BindingsPolicy::WEB_UI)) 58 if (0 != (bindings_ & BindingsPolicy::WEB_UI))
57 render_view_host->SetWebUIProperty("dialogArguments", dialog_args); 59 render_view_host->SetWebUIProperty("dialogArguments", dialog_args);
58 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin(); 60 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin();
59 it != handlers.end(); ++it) { 61 it != handlers.end(); ++it) {
60 (*it)->Attach(this); 62 (*it)->Attach(this);
61 AddMessageHandler(*it); 63 AddMessageHandler(*it);
62 } 64 }
65
66 NotificationService::current()->Notify(
67 chrome::NOTIFICATION_HTML_DIALOG_SHOWN,
68 Source<HtmlDialogUI>(this),
69 NotificationService::NoDetails());
63 } 70 }
64 71
65 void HtmlDialogUI::OnDialogClosed(const ListValue* args) { 72 void HtmlDialogUI::OnDialogClosed(const ListValue* args) {
66 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty( 73 HtmlDialogUIDelegate** delegate = GetPropertyAccessor().GetProperty(
67 tab_contents()->property_bag()); 74 tab_contents()->property_bag());
68 if (delegate) { 75 if (delegate) {
69 std::string json_retval; 76 std::string json_retval;
70 if (!args->GetString(0, &json_retval)) 77 if (!args->GetString(0, &json_retval))
71 NOTREACHED() << "Could not read JSON arguments"; 78 NOTREACHED() << "Could not read JSON arguments";
72 79
73 (*delegate)->OnDialogClosed(json_retval); 80 (*delegate)->OnDialogClosed(json_retval);
74 } 81 }
75 } 82 }
76 83
77 ExternalHtmlDialogUI::ExternalHtmlDialogUI(TabContents* tab_contents) 84 ExternalHtmlDialogUI::ExternalHtmlDialogUI(TabContents* tab_contents)
78 : HtmlDialogUI(tab_contents) { 85 : HtmlDialogUI(tab_contents) {
79 // Non-file based UI needs to not have access to the Web UI bindings 86 // Non-file based UI needs to not have access to the Web UI bindings
80 // for security reasons. The code hosting the dialog should provide 87 // for security reasons. The code hosting the dialog should provide
81 // dialog specific functionality through other bindings and methods 88 // dialog specific functionality through other bindings and methods
82 // that are scoped in duration to the dialogs existence. 89 // that are scoped in duration to the dialogs existence.
83 bindings_ &= ~BindingsPolicy::WEB_UI; 90 bindings_ &= ~BindingsPolicy::WEB_UI;
84 } 91 }
85 92
86 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() { 93 ExternalHtmlDialogUI::~ExternalHtmlDialogUI() {
87 } 94 }
88 95
89 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) { 96 bool HtmlDialogUIDelegate::HandleContextMenu(const ContextMenuParams& params) {
90 return false; 97 return false;
91 } 98 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/web_ui_browsertest.h » ('j') | chrome/browser/ui/webui/web_ui_browsertest.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698