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

Side by Side Diff: chrome/browser/ui/webui/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
« no previous file with comments | « chrome/browser/ui/webui/web_dialog_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/web_dialog_ui.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h"
10 #include "base/property_bag.h"
11 #include "base/values.h"
12 #include "chrome/browser/ui/webui/web_dialog_delegate.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_message_handler.h"
18 #include "content/public/common/bindings_policy.h"
19
20 using content::RenderViewHost;
21 using content::WebUIMessageHandler;
22
23 static base::LazyInstance<base::PropertyAccessor<WebDialogDelegate*> >
24 g_web_dialog_ui_property_accessor = LAZY_INSTANCE_INITIALIZER;
25
26 WebDialogUI::WebDialogUI(content::WebUI* web_ui)
27 : WebUIController(web_ui) {
28 }
29
30 WebDialogUI::~WebDialogUI() {
31 // Don't unregister our property. During the teardown of the WebContents,
32 // this will be deleted, but the WebContents will already be destroyed.
33 //
34 // This object is owned indirectly by the WebContents. WebUIs can change, so
35 // it's scary if this WebUI is changed out and replaced with something else,
36 // since the property will still point to the old delegate. But the delegate
37 // is itself the owner of the WebContents for a dialog so will be in scope,
38 // and the HTML dialogs won't swap WebUIs anyway since they don't navigate.
39 }
40
41 void WebDialogUI::CloseDialog(const base::ListValue* args) {
42 OnDialogClosed(args);
43 }
44
45 // static
46 base::PropertyAccessor<WebDialogDelegate*>& WebDialogUI::GetPropertyAccessor() {
47 return g_web_dialog_ui_property_accessor.Get();
48 }
49
50 ////////////////////////////////////////////////////////////////////////////////
51 // Private:
52
53 void WebDialogUI::RenderViewCreated(RenderViewHost* render_view_host) {
54 // Hook up the javascript function calls, also known as chrome.send("foo")
55 // calls in the HTML, to the actual C++ functions.
56 web_ui()->RegisterMessageCallback("DialogClose",
57 base::Bind(&WebDialogUI::OnDialogClosed, base::Unretained(this)));
58
59 // Pass the arguments to the renderer supplied by the delegate.
60 std::string dialog_args;
61 std::vector<WebUIMessageHandler*> handlers;
62 WebDialogDelegate** delegate = GetPropertyAccessor().GetProperty(
63 web_ui()->GetWebContents()->GetPropertyBag());
64 if (delegate) {
65 dialog_args = (*delegate)->GetDialogArgs();
66 (*delegate)->GetWebUIMessageHandlers(&handlers);
67 }
68
69 if (0 != (web_ui()->GetBindings() & content::BINDINGS_POLICY_WEB_UI))
70 render_view_host->SetWebUIProperty("dialogArguments", dialog_args);
71 for (std::vector<WebUIMessageHandler*>::iterator it = handlers.begin();
72 it != handlers.end(); ++it) {
73 web_ui()->AddMessageHandler(*it);
74 }
75
76 if (delegate)
77 (*delegate)->OnDialogShown(web_ui(), render_view_host);
78 }
79
80 void WebDialogUI::OnDialogClosed(const ListValue* args) {
81 WebDialogDelegate** delegate = GetPropertyAccessor().GetProperty(
82 web_ui()->GetWebContents()->GetPropertyBag());
83 if (delegate) {
84 std::string json_retval;
85 if (args && !args->empty() && !args->GetString(0, &json_retval))
86 NOTREACHED() << "Could not read JSON argument";
87
88 (*delegate)->OnDialogClosed(json_retval);
89 }
90 }
91
92 ExternalWebDialogUI::ExternalWebDialogUI(content::WebUI* web_ui)
93 : WebDialogUI(web_ui) {
94 // Non-file based UI needs to not have access to the Web UI bindings
95 // for security reasons. The code hosting the dialog should provide
96 // dialog specific functionality through other bindings and methods
97 // that are scoped in duration to the dialogs existence.
98 web_ui->SetBindings(web_ui->GetBindings() & ~content::BINDINGS_POLICY_WEB_UI);
99 }
100
101 ExternalWebDialogUI::~ExternalWebDialogUI() {
102 }
103
104 std::string WebDialogDelegate::GetDialogName() const {
105 return std::string();
106 }
107
108 void WebDialogDelegate::GetMinimumDialogSize(gfx::Size* size) const {
109 GetDialogSize(size);
110 }
111
112 bool WebDialogDelegate::HandleContextMenu(
113 const content::ContextMenuParams& params) {
114 return false;
115 }
116
117 bool WebDialogDelegate::HandleOpenURLFromTab(
118 content::WebContents* source,
119 const content::OpenURLParams& params,
120 content::WebContents** out_new_contents) {
121 return false;
122 }
123
124 bool WebDialogDelegate::HandleAddNewContents(
125 content::WebContents* source,
126 content::WebContents* new_contents,
127 WindowOpenDisposition disposition,
128 const gfx::Rect& initial_pos,
129 bool user_gesture) {
130 return false;
131 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/web_dialog_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698