| 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/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
| 9 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
| 10 #include "content/public/browser/browser_context.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 #include "content/public/browser/web_ui_data_source.h" | 10 #include "content/public/browser/web_ui_data_source.h" |
| 13 #include "grit/browser_resources.h" | 11 #include "grit/browser_resources.h" |
| 14 #include "ui/web_dialogs/web_dialog_delegate.h" | |
| 15 #include "url/gurl.h" | |
| 16 | 12 |
| 17 #if !defined(OS_MACOSX) | 13 #if !defined(OS_MACOSX) |
| 18 #include "chrome/browser/ui/browser_dialogs.h" | 14 #include "chrome/browser/ui/browser_dialogs.h" |
| 19 #endif | 15 #endif |
| 20 | 16 |
| 21 namespace { | 17 namespace { |
| 22 | 18 |
| 23 // The WebDialogDelegate that specifies what the MD Feedback dialog will look | |
| 24 // like. | |
| 25 class MdFeedbackDialogDelegate : public ui::WebDialogDelegate { | |
| 26 public: | |
| 27 MdFeedbackDialogDelegate() {} | |
| 28 ~MdFeedbackDialogDelegate() override {} | |
| 29 | |
| 30 ui::ModalType GetDialogModalType() const override { | |
| 31 return ui::MODAL_TYPE_SYSTEM; | |
| 32 } | |
| 33 | |
| 34 base::string16 GetDialogTitle() const override { | |
| 35 return base::string16(); | |
| 36 } | |
| 37 | |
| 38 GURL GetDialogContentURL() const override { | |
| 39 return GURL(chrome::kChromeUIFeedbackURL); | |
| 40 } | |
| 41 | |
| 42 void GetWebUIMessageHandlers( | |
| 43 std::vector<content::WebUIMessageHandler*>* handlers) const override {} | |
| 44 | |
| 45 void GetDialogSize(gfx::Size* size) const override { | |
| 46 // TODO(apacible): Update when WebUI sizing behavior is finalized. | |
| 47 size->SetSize(400, 600); | |
| 48 } | |
| 49 | |
| 50 std::string GetDialogArgs() const override { | |
| 51 return std::string(); | |
| 52 } | |
| 53 | |
| 54 void OnDialogClosed(const std::string& json_retval) override { | |
| 55 delete this; | |
| 56 } | |
| 57 | |
| 58 void OnCloseContents( | |
| 59 content::WebContents* source, bool* out_close_dialog) override {} | |
| 60 | |
| 61 bool ShouldShowDialogTitle() const override { | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 bool HandleContextMenu(const content::ContextMenuParams& params) override { | |
| 66 // Do not show the contextual menu. | |
| 67 return true; | |
| 68 } | |
| 69 }; | |
| 70 | |
| 71 } // namespace | |
| 72 | |
| 73 namespace { | |
| 74 | |
| 75 content::WebUIDataSource* CreateMdFeedbackUIHTMLSource(Profile* profile) { | 19 content::WebUIDataSource* CreateMdFeedbackUIHTMLSource(Profile* profile) { |
| 76 content::WebUIDataSource* html_source = | 20 content::WebUIDataSource* html_source = |
| 77 content::WebUIDataSource::Create(chrome::kChromeUIFeedbackHost); | 21 content::WebUIDataSource::Create(chrome::kChromeUIFeedbackHost); |
| 78 | 22 |
| 79 // General strings. | 23 // General strings. |
| 80 html_source->AddLocalizedString("headingText", | 24 html_source->AddLocalizedString("headingText", |
| 81 IDS_MD_FEEDBACK_HEADING); | 25 IDS_MD_FEEDBACK_HEADING); |
| 82 | 26 |
| 83 // Input labels. | 27 // Input labels. |
| 84 html_source->AddLocalizedString("emailLabel", | 28 html_source->AddLocalizedString("emailLabel", |
| (...skipping 25 matching lines...) Expand all Loading... |
| 110 MdFeedbackUI::MdFeedbackUI(content::WebUI* web_ui) | 54 MdFeedbackUI::MdFeedbackUI(content::WebUI* web_ui) |
| 111 : content::WebUIController(web_ui) { | 55 : content::WebUIController(web_ui) { |
| 112 // Set up the chrome://feedback data html_source. | 56 // Set up the chrome://feedback data html_source. |
| 113 Profile* profile = Profile::FromWebUI(web_ui); | 57 Profile* profile = Profile::FromWebUI(web_ui); |
| 114 content::WebUIDataSource* html_source = | 58 content::WebUIDataSource* html_source = |
| 115 CreateMdFeedbackUIHTMLSource(profile); | 59 CreateMdFeedbackUIHTMLSource(profile); |
| 116 content::WebUIDataSource::Add(profile, html_source); | 60 content::WebUIDataSource::Add(profile, html_source); |
| 117 } | 61 } |
| 118 | 62 |
| 119 MdFeedbackUI::~MdFeedbackUI() {} | 63 MdFeedbackUI::~MdFeedbackUI() {} |
| 120 | |
| 121 void ShowFeedbackWebDialog( | |
| 122 content::BrowserContext* browser_context) { | |
| 123 // TODO(apacible): Platform dependent implementations. | |
| 124 #if !defined(OS_MACOSX) | |
| 125 // TODO(apacible): If a feedback dialog is already open, bring that dialog | |
| 126 // to the front rather than creating a new dialog. | |
| 127 chrome::ShowWebDialog(NULL, browser_context, new MdFeedbackDialogDelegate()); | |
| 128 #endif // !OS_MACOSX | |
| 129 } | |
| OLD | NEW |