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

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

Issue 9003014: Replace WebUI::tab_contents() with web_contents() and switch all users to use web_contents.h inst... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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/bug_report_ui.h" 5 #include "chrome/browser/ui/webui/bug_report_ui.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/bug_report_data.h" 17 #include "chrome/browser/bug_report_data.h"
18 #include "chrome/browser/bug_report_util.h" 18 #include "chrome/browser/bug_report_util.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
24 #include "chrome/browser/ui/webui/screenshot_source.h" 25 #include "chrome/browser/ui/webui/screenshot_source.h"
25 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" 26 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
26 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
28 #include "content/browser/tab_contents/tab_contents.h" 29 #include "content/browser/tab_contents/navigation_controller.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/navigation_entry.h" 31 #include "content/public/browser/navigation_entry.h"
32 #include "content/public/browser/web_contents.h"
31 #include "grit/browser_resources.h" 33 #include "grit/browser_resources.h"
32 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
33 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
34 #include "grit/locale_settings.h" 36 #include "grit/locale_settings.h"
35 #include "net/base/escape.h" 37 #include "net/base/escape.h"
36 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
37 39
38 #if defined(OS_CHROMEOS) 40 #if defined(OS_CHROMEOS)
39 #include "base/file_util.h" 41 #include "base/file_util.h"
40 #include "base/path_service.h" 42 #include "base/path_service.h"
41 #include "base/synchronization/waitable_event.h" 43 #include "base/synchronization/waitable_event.h"
42 #include "chrome/browser/chromeos/cros/cros_library.h" 44 #include "chrome/browser/chromeos/cros/cros_library.h"
43 #include "chrome/browser/chromeos/login/user_manager.h" 45 #include "chrome/browser/chromeos/login/user_manager.h"
44 #include "chrome/browser/chromeos/system/syslogs_provider.h" 46 #include "chrome/browser/chromeos/system/syslogs_provider.h"
45 #endif 47 #endif
46 48
47 using content::BrowserThread; 49 using content::BrowserThread;
50 using content::WebContents;
48 51
49 namespace { 52 namespace {
50 53
51 const char kScreenshotBaseUrl[] = "chrome://screenshots/"; 54 const char kScreenshotBaseUrl[] = "chrome://screenshots/";
52 const char kCurrentScreenshotUrl[] = "chrome://screenshots/current"; 55 const char kCurrentScreenshotUrl[] = "chrome://screenshots/current";
53 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
54 const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/"; 57 const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/";
55 const char kScreenshotPattern[] = "screenshot-*.png"; 58 const char kScreenshotPattern[] = "screenshot-*.png";
56 59
57 const size_t kMaxSavedScreenshots = 2; 60 const size_t kMaxSavedScreenshots = 2;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return std::string(); 104 return std::string();
102 else 105 else
103 return manager->logged_in_user().display_email(); 106 return manager->logged_in_user().display_email();
104 } 107 }
105 #endif 108 #endif
106 109
107 // Returns the index of the feedback tab if already open, -1 otherwise 110 // Returns the index of the feedback tab if already open, -1 otherwise
108 int GetIndexOfFeedbackTab(Browser* browser) { 111 int GetIndexOfFeedbackTab(Browser* browser) {
109 GURL bug_report_url(chrome::kChromeUIBugReportURL); 112 GURL bug_report_url(chrome::kChromeUIBugReportURL);
110 for (int i = 0; i < browser->tab_count(); ++i) { 113 for (int i = 0; i < browser->tab_count(); ++i) {
111 TabContents* tab = browser->GetTabContentsAt(i); 114 WebContents* tab = browser->GetTabContentsWrapperAt(i)->web_contents();
112 if (tab && tab->GetURL().GetWithEmptyPath() == bug_report_url) 115 if (tab && tab->GetURL().GetWithEmptyPath() == bug_report_url)
113 return i; 116 return i;
114 } 117 }
115 118
116 return -1; 119 return -1;
117 } 120 }
118 121
119 } // namespace 122 } // namespace
120 123
121 124
(...skipping 30 matching lines...) Expand all
152 "&issueType=" + base::IntToString(issue_type); 155 "&issueType=" + base::IntToString(issue_type);
153 browser->ShowSingletonTab(GURL(bug_report_url)); 156 browser->ShowSingletonTab(GURL(bug_report_url));
154 } 157 }
155 158
156 } // namespace browser 159 } // namespace browser
157 160
158 // The handler for Javascript messages related to the "bug report" dialog 161 // The handler for Javascript messages related to the "bug report" dialog
159 class BugReportHandler : public WebUIMessageHandler, 162 class BugReportHandler : public WebUIMessageHandler,
160 public base::SupportsWeakPtr<BugReportHandler> { 163 public base::SupportsWeakPtr<BugReportHandler> {
161 public: 164 public:
162 explicit BugReportHandler(TabContents* tab); 165 explicit BugReportHandler(content::WebContents* tab);
163 virtual ~BugReportHandler(); 166 virtual ~BugReportHandler();
164 167
165 // Init work after Attach. Returns true on success. 168 // Init work after Attach. Returns true on success.
166 bool Init(); 169 bool Init();
167 170
168 // WebUIMessageHandler implementation. 171 // WebUIMessageHandler implementation.
169 virtual void RegisterMessages() OVERRIDE; 172 virtual void RegisterMessages() OVERRIDE;
170 173
171 private: 174 private:
172 void HandleGetDialogDefaults(const ListValue* args); 175 void HandleGetDialogDefaults(const ListValue* args);
173 void HandleRefreshCurrentScreenshot(const ListValue* args); 176 void HandleRefreshCurrentScreenshot(const ListValue* args);
174 #if defined(OS_CHROMEOS) 177 #if defined(OS_CHROMEOS)
175 void HandleRefreshSavedScreenshots(const ListValue* args); 178 void HandleRefreshSavedScreenshots(const ListValue* args);
176 #endif 179 #endif
177 void HandleSendReport(const ListValue* args); 180 void HandleSendReport(const ListValue* args);
178 void HandleCancel(const ListValue* args); 181 void HandleCancel(const ListValue* args);
179 void HandleOpenSystemTab(const ListValue* args); 182 void HandleOpenSystemTab(const ListValue* args);
180 183
181 void SetupScreenshotsSource(); 184 void SetupScreenshotsSource();
182 void ClobberScreenshotsSource(); 185 void ClobberScreenshotsSource();
183 186
184 void CancelFeedbackCollection(); 187 void CancelFeedbackCollection();
185 void CloseFeedbackTab(); 188 void CloseFeedbackTab();
186 189
187 TabContents* tab_; 190 WebContents* tab_;
188 ScreenshotSource* screenshot_source_; 191 ScreenshotSource* screenshot_source_;
189 192
190 BugReportData* bug_report_data_; 193 BugReportData* bug_report_data_;
191 std::string target_tab_url_; 194 std::string target_tab_url_;
192 #if defined(OS_CHROMEOS) 195 #if defined(OS_CHROMEOS)
193 // Variables to track SyslogsProvider::RequestSyslogs callback. 196 // Variables to track SyslogsProvider::RequestSyslogs callback.
194 chromeos::system::SyslogsProvider::Handle syslogs_handle_; 197 chromeos::system::SyslogsProvider::Handle syslogs_handle_;
195 CancelableRequestConsumer syslogs_consumer_; 198 CancelableRequestConsumer syslogs_consumer_;
196 #endif 199 #endif
197 200
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 successful_init ? IDR_BUGREPORT_HTML : IDR_BUGREPORT_HTML_INVALID); 303 successful_init ? IDR_BUGREPORT_HTML : IDR_BUGREPORT_HTML_INVALID);
301 304
302 return source; 305 return source;
303 } 306 }
304 307
305 //////////////////////////////////////////////////////////////////////////////// 308 ////////////////////////////////////////////////////////////////////////////////
306 // 309 //
307 // BugReportHandler 310 // BugReportHandler
308 // 311 //
309 //////////////////////////////////////////////////////////////////////////////// 312 ////////////////////////////////////////////////////////////////////////////////
310 BugReportHandler::BugReportHandler(TabContents* tab) 313 BugReportHandler::BugReportHandler(WebContents* tab)
311 : tab_(tab), 314 : tab_(tab),
312 screenshot_source_(NULL), 315 screenshot_source_(NULL),
313 bug_report_data_(NULL) 316 bug_report_data_(NULL)
314 #if defined(OS_CHROMEOS) 317 #if defined(OS_CHROMEOS)
315 , syslogs_handle_(0) 318 , syslogs_handle_(0)
316 #endif 319 #endif
317 { 320 {
318 } 321 }
319 322
320 BugReportHandler::~BugReportHandler() { 323 BugReportHandler::~BugReportHandler() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 if (!base::StringToInt(params, &index)) 371 if (!base::StringToInt(params, &index))
369 return false; 372 return false;
370 373
371 Browser* browser = BrowserList::GetLastActive(); 374 Browser* browser = BrowserList::GetLastActive();
372 // Sanity checks. 375 // Sanity checks.
373 if (((index == 0) && (params != "0")) || !browser || 376 if (((index == 0) && (params != "0")) || !browser ||
374 index >= browser->tab_count()) { 377 index >= browser->tab_count()) {
375 return false; 378 return false;
376 } 379 }
377 380
378 TabContents* target_tab = browser->GetTabContentsAt(index); 381 WebContents* target_tab =
382 browser->GetTabContentsWrapperAt(index)->web_contents();
379 if (target_tab) { 383 if (target_tab) {
380 target_tab_url_ = target_tab->GetURL().spec(); 384 target_tab_url_ = target_tab->GetURL().spec();
381 } 385 }
382 386
383 // Setup the screenshot source after we've verified input is legit. 387 // Setup the screenshot source after we've verified input is legit.
384 SetupScreenshotsSource(); 388 SetupScreenshotsSource();
385 389
386 return true; 390 return true;
387 } 391 }
388 392
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } else { 609 } else {
606 LOG(FATAL) << "Failed to get last active browser."; 610 LOG(FATAL) << "Failed to get last active browser.";
607 } 611 }
608 } 612 }
609 613
610 //////////////////////////////////////////////////////////////////////////////// 614 ////////////////////////////////////////////////////////////////////////////////
611 // 615 //
612 // BugReportUI 616 // BugReportUI
613 // 617 //
614 //////////////////////////////////////////////////////////////////////////////// 618 ////////////////////////////////////////////////////////////////////////////////
615 BugReportUI::BugReportUI(TabContents* tab) : HtmlDialogUI(tab) { 619 BugReportUI::BugReportUI(WebContents* tab) : HtmlDialogUI(tab) {
616 BugReportHandler* handler = new BugReportHandler(tab); 620 BugReportHandler* handler = new BugReportHandler(tab);
617 AddMessageHandler(handler); 621 AddMessageHandler(handler);
618 622
619 // The handler's init will determine whether we show the error html page. 623 // The handler's init will determine whether we show the error html page.
620 ChromeWebUIDataSource* html_source = 624 ChromeWebUIDataSource* html_source =
621 CreateBugReportUIHTMLSource(handler->Init()); 625 CreateBugReportUIHTMLSource(handler->Init());
622 626
623 // Set up the chrome://bugreport/ source. 627 // Set up the chrome://bugreport/ source.
624 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); 628 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
625 profile->GetChromeURLDataManager()->AddDataSource(html_source); 629 profile->GetChromeURLDataManager()->AddDataSource(html_source);
626 } 630 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/bug_report_ui.h ('k') | chrome/browser/ui/webui/certificate_viewer_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698