OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/md_feedback/md_feedback_ui.h" | 5 #include "chrome/browser/ui/webui/md_feedback/md_feedback_ui.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/webui/md_feedback/md_feedback_webui_message_handler. h" | |
8 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
9 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
10 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
12 #include "content/public/browser/web_ui_data_source.h" | 13 #include "content/public/browser/web_ui_data_source.h" |
13 #include "grit/browser_resources.h" | 14 #include "grit/browser_resources.h" |
14 #include "ui/web_dialogs/web_dialog_delegate.h" | 15 #include "ui/web_dialogs/web_dialog_delegate.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 #if !defined(OS_MACOSX) | 18 #if !defined(OS_MACOSX) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 IDS_MD_FEEDBACK_CANCEL_BUTTON); | 98 IDS_MD_FEEDBACK_CANCEL_BUTTON); |
98 html_source->AddLocalizedString("sendReportButton", | 99 html_source->AddLocalizedString("sendReportButton", |
99 IDS_MD_FEEDBACK_SEND_REPORT_BUTTON); | 100 IDS_MD_FEEDBACK_SEND_REPORT_BUTTON); |
100 | 101 |
101 // Checkbox labels. | 102 // Checkbox labels. |
102 html_source->AddLocalizedString("includeScreenshotLabel", | 103 html_source->AddLocalizedString("includeScreenshotLabel", |
103 IDS_MD_FEEDBACK_SCREENSHOT_LABEL); | 104 IDS_MD_FEEDBACK_SCREENSHOT_LABEL); |
104 html_source->AddLocalizedString("sendSystemInfoLabel", | 105 html_source->AddLocalizedString("sendSystemInfoLabel", |
105 IDS_MD_FEEDBACK_SEND_SYSTEM_INFO_LABEL); | 106 IDS_MD_FEEDBACK_SEND_SYSTEM_INFO_LABEL); |
106 | 107 |
108 // File resources. | |
109 html_source->AddResourcePath("feedback.js", | |
110 IDR_MD_FEEDBACK_FEEDBACK_JS); | |
111 | |
107 // Polymer resources. | 112 // Polymer resources. |
108 html_source->AddResourcePath("feedback_container.html", | 113 html_source->AddResourcePath("feedback_container.html", |
109 IDR_MD_FEEDBACK_FEEDBACK_CONTAINER_HTML); | 114 IDR_MD_FEEDBACK_FEEDBACK_CONTAINER_HTML); |
110 html_source->AddResourcePath("feedback_container.js", | 115 html_source->AddResourcePath("feedback_container.js", |
111 IDR_MD_FEEDBACK_FEEDBACK_CONTAINER_JS); | 116 IDR_MD_FEEDBACK_FEEDBACK_CONTAINER_JS); |
112 | 117 |
113 html_source->SetJsonPath("strings.js"); | 118 html_source->SetJsonPath("strings.js"); |
114 html_source->SetDefaultResource(IDR_MD_FEEDBACK_FEEDBACK_HTML); | 119 html_source->SetDefaultResource(IDR_MD_FEEDBACK_FEEDBACK_HTML); |
115 return html_source; | 120 return html_source; |
116 } | 121 } |
117 | 122 |
118 } // namespace | 123 } // namespace |
119 | 124 |
120 MdFeedbackUI::MdFeedbackUI(content::WebUI* web_ui) | 125 MdFeedbackUI::MdFeedbackUI(content::WebUI* web_ui) |
121 : content::WebUIController(web_ui) { | 126 : content::WebUIController(web_ui), |
127 handler_(new MdFeedbackWebUIMessageHandler(this)) { | |
afakhry
2016/08/03 23:56:01
You don't need that internal reference |handler_|
apacible
2016/08/11 18:50:33
Done.
| |
122 // Set up the chrome://feedback data html_source. | 128 // Set up the chrome://feedback data html_source. |
123 Profile* profile = Profile::FromWebUI(web_ui); | 129 Profile* profile = Profile::FromWebUI(web_ui); |
124 content::WebUIDataSource* html_source = | 130 content::WebUIDataSource* html_source = |
125 CreateMdFeedbackUIHTMLSource(profile); | 131 CreateMdFeedbackUIHTMLSource(profile); |
126 content::WebUIDataSource::Add(profile, html_source); | 132 content::WebUIDataSource::Add(profile, html_source); |
133 | |
134 // Ownership of |handler_| is transferred to |web_ui|. | |
135 web_ui->AddMessageHandler(handler_); | |
127 } | 136 } |
128 | 137 |
129 MdFeedbackUI::~MdFeedbackUI() {} | 138 MdFeedbackUI::~MdFeedbackUI() {} |
130 | 139 |
131 void ShowFeedbackWebDialog( | 140 void ShowFeedbackWebDialog( |
132 content::BrowserContext* browser_context) { | 141 content::BrowserContext* browser_context) { |
133 // TODO(apacible): Platform dependent implementations. | 142 // TODO(apacible): Platform dependent implementations. |
134 #if !defined(OS_MACOSX) | 143 #if !defined(OS_MACOSX) |
135 // TODO(apacible): If a feedback dialog is already open, bring that dialog | 144 // TODO(apacible): If a feedback dialog is already open, bring that dialog |
136 // to the front rather than creating a new dialog. | 145 // to the front rather than creating a new dialog. |
137 chrome::ShowWebDialog(NULL, browser_context, new MdFeedbackDialogDelegate()); | 146 chrome::ShowWebDialog(NULL, browser_context, new MdFeedbackDialogDelegate()); |
138 #endif // !OS_MACOSX | 147 #endif // !OS_MACOSX |
139 } | 148 } |
OLD | NEW |