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

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

Issue 10448066: Move the web dialogs code to src/ui/web_dialogs from src/chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/lazy_instance.h"
13 #include "base/property_bag.h"
14 #include "base/values.h"
15 #include "chrome/browser/ui/webui/web_dialog_delegate.h"
16 #include "chrome/browser/ui/webui/web_dialog_ui.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_ui.h"
21
22 using content::RenderViewHost;
23 using content::WebContents;
24 using content::WebUIMessageHandler;
25
26 static base::LazyInstance<base::PropertyAccessor<ConstrainedWebDialogDelegate*> >
27 g_constrained_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
28
29 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui)
30 : WebUIController(web_ui) {
31 }
32
33 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() {
34 }
35
36 void ConstrainedWebDialogUI::RenderViewCreated(
37 RenderViewHost* render_view_host) {
38 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate();
39 if (!delegate)
40 return;
41
42 WebDialogDelegate* dialog_delegate = delegate->GetWebDialogDelegate();
43 std::vector<WebUIMessageHandler*> handlers;
44 dialog_delegate->GetWebUIMessageHandlers(&handlers);
45 render_view_host->SetWebUIProperty("dialogArguments",
46 dialog_delegate->GetDialogArgs());
47 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin();
48 it != handlers.end(); ++it) {
49 web_ui()->AddMessageHandler(*it);
50 }
51
52 // Add a "DialogClose" callback which matches WebDialogUI behavior.
53 web_ui()->RegisterMessageCallback("DialogClose",
54 base::Bind(&ConstrainedWebDialogUI::OnDialogCloseMessage,
55 base::Unretained(this)));
56
57 dialog_delegate->OnDialogShown(web_ui(), render_view_host);
58 }
59
60 void ConstrainedWebDialogUI::OnDialogCloseMessage(const ListValue* args) {
61 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate();
62 if (!delegate)
63 return;
64
65 std::string json_retval;
66 if (!args->empty() && !args->GetString(0, &json_retval))
67 NOTREACHED() << "Could not read JSON argument";
68 delegate->GetWebDialogDelegate()->OnDialogClosed(json_retval);
69 delegate->OnDialogCloseFromWebUI();
70 }
71
72 ConstrainedWebDialogDelegate* ConstrainedWebDialogUI::GetConstrainedDelegate() {
73 ConstrainedWebDialogDelegate** property = GetPropertyAccessor().GetProperty(
74 web_ui()->GetWebContents()->GetPropertyBag());
75 return property ? *property : NULL;
76 }
77
78 // static
79 base::PropertyAccessor<ConstrainedWebDialogDelegate*>&
80 ConstrainedWebDialogUI::GetPropertyAccessor() {
81 return g_constrained_web_dialog_ui_property_accessor.Get();
82 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/constrained_web_dialog_ui.h ('k') | chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698