summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 22:19:42 +0000
committerrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 22:19:42 +0000
commit35d06150b498cd3f301ad26a3e979cdcbbd4c541 (patch)
tree62a32c216be4f2c943c1a329c0be44af8b122064 /chrome
parent4859b837fbb012c8f1976f98d29f2fdd15cd8c15 (diff)
downloadchromium_src-35d06150b498cd3f301ad26a3e979cdcbbd4c541.zip
chromium_src-35d06150b498cd3f301ad26a3e979cdcbbd4c541.tar.gz
chromium_src-35d06150b498cd3f301ad26a3e979cdcbbd4c541.tar.bz2
Refactored the screenshot mechanism.
Added a new method to browser window to get a screenshot in a platform independent way. Changed user feedback UI code to use the new method. BUG=65119 TEST=Tested with sending feedback with the new code. Screenshots are being taken and sent correctly. Review URL: http://codereview.chromium.org/6145001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70951 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/dom_ui/bug_report_ui.cc59
-rw-r--r--chrome/browser/dom_ui/bug_report_ui.h14
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc12
-rw-r--r--chrome/browser/gtk/browser_window_gtk.h6
-rw-r--r--chrome/browser/ui/browser.cc5
-rw-r--r--chrome/browser/ui/browser_window.h11
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.h6
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.mm17
-rw-r--r--chrome/browser/ui/toolbar/wrench_menu_model.cc6
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc20
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h6
-rw-r--r--chrome/test/test_browser_window.h8
12 files changed, 72 insertions, 98 deletions
diff --git a/chrome/browser/dom_ui/bug_report_ui.cc b/chrome/browser/dom_ui/bug_report_ui.cc
index dc75bad..a780c50 100644
--- a/chrome/browser/dom_ui/bug_report_ui.cc
+++ b/chrome/browser/dom_ui/bug_report_ui.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -26,6 +26,7 @@
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/url_constants.h"
@@ -142,55 +143,16 @@ namespace browser {
std::vector<unsigned char>* last_screenshot_png = 0;
gfx::Rect screen_size;
-// Get bounds in different ways for different OS's;
-#if defined(TOOLKIT_VIEWS)
-// Windows/ChromeOS support Views - so we get dimensions from the
-// views::Window object
-void RefreshLastScreenshot(views::Window* parent) {
- gfx::NativeWindow window = parent->GetNativeWindow();
- int width = parent->GetBounds().width();
- int height = parent->GetBounds().height();
-#elif defined(OS_LINUX)
-// Linux provides its bounds and a native window handle to the screen
-void RefreshLastScreenshot(gfx::NativeWindow window,
- const gfx::Rect& bounds) {
- int width = bounds.width();
- int height = bounds.height();
-#elif defined(OS_MACOSX)
-// Mac gets its bounds from the GrabWindowSnapshot function
-void RefreshLastScreenshot(NSWindow* window) {
- int width = 0;
- int height = 0;
-#endif
-
- // Grab an exact snapshot of the window that the user is seeing (i.e. as
- // rendered--do not re-render, and include windowed plugins).
+void RefreshLastScreenshot(Browser* browser) {
if (last_screenshot_png)
last_screenshot_png->clear();
else
last_screenshot_png = new std::vector<unsigned char>;
-#if defined(USE_X11)
- x11_util::GrabWindowSnapshot(window, last_screenshot_png);
-#elif defined(OS_MACOSX)
- base::mac::GrabWindowSnapshot(window, last_screenshot_png, &width, &height);
-#elif defined(OS_WIN)
- app::win::GrabWindowSnapshot(window, last_screenshot_png);
-#endif
-
- screen_size.set_width(width);
- screen_size.set_height(height);
+ screen_size = browser->window()->GrabWindowSnapshot(last_screenshot_png);
}
-#if defined(TOOLKIT_VIEWS)
-void ShowHtmlBugReportView(views::Window* parent, Browser* browser) {
-#elif defined(OS_LINUX)
-void ShowHtmlBugReportView(gfx::NativeWindow window, const gfx::Rect& bounds,
- Browser* browser) {
-#elif defined(OS_MACOSX)
-void ShowHtmlBugReportView(NSWindow* window, Browser* browser) {
-#endif
-
+void ShowHtmlBugReportView(Browser* browser) {
// First check if we're already open (we cannot depend on ShowSingletonTab
// for this functionality since we need to make *sure* we never get
// instantiated again while we are open - with singleton tabs, that can
@@ -199,17 +161,10 @@ void ShowHtmlBugReportView(NSWindow* window, Browser* browser) {
if (feedback_tab_index >=0) {
// Do not refresh screenshot, do not create a new tab
browser->SelectTabContentsAt(feedback_tab_index, true);
+ return;
}
- // now for refreshing the last screenshot
-#if defined(TOOLKIT_VIEWS)
- RefreshLastScreenshot(parent);
-#elif defined(OS_LINUX)
- RefreshLastScreenshot(window, bounds);
-#elif defined(OS_MACOSX)
- RefreshLastScreenshot(window);
-#endif
-
+ RefreshLastScreenshot(browser);
std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) +
"#" + base::IntToString(browser->selected_index());
browser->ShowSingletonTab(GURL(bug_report_url), false);
diff --git a/chrome/browser/dom_ui/bug_report_ui.h b/chrome/browser/dom_ui/bug_report_ui.h
index 31d9eae..72240eb 100644
--- a/chrome/browser/dom_ui/bug_report_ui.h
+++ b/chrome/browser/dom_ui/bug_report_ui.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,18 +16,8 @@ class Rect;
class TabContents;
class NSWindow;
-
-// TODO(rkc): The following code is very ugly and needs to be refactored.
-// http://code.google.com/p/chromium/issues/detail?id=65119
namespace browser {
-#if defined(TOOLKIT_VIEWS)
-void ShowHtmlBugReportView(views::Window* parent, Browser* browser);
-#elif defined(OS_LINUX)
-void ShowHtmlBugReportView(gfx::NativeWindow window, const gfx::Rect& bounds,
- Browser* browser);
-#elif defined(OS_MACOSX)
-void ShowHtmlBugReportView(NSWindow* window, Browser* browser);
-#endif
+void ShowHtmlBugReportView(Browser* browser);
} // namespace browser
class BugReportUI : public HtmlDialogUI {
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index ec300a1..cf6cb70 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -901,10 +901,6 @@ DownloadShelf* BrowserWindowGtk::GetDownloadShelf() {
return download_shelf_.get();
}
-void BrowserWindowGtk::ShowReportBugDialog() {
- browser::ShowHtmlBugReportView(window_, bounds_, browser_.get());
-}
-
void BrowserWindowGtk::ShowClearBrowsingDataDialog() {
ClearBrowsingDataDialogGtk::Show(window_, browser_->profile());
}
@@ -1123,6 +1119,12 @@ gfx::Rect BrowserWindowGtk::GetInstantBounds() {
return gtk_util::GetWidgetScreenBounds(contents_container_->widget());
}
+gfx::Rect BrowserWindowGtk::GrabWindowSnapshot(std::vector<unsigned char>*
+ png_representation) {
+ x11_util::GrabWindowSnapshot(window_, png_representation);
+ return bounds_;
+}
+
void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() {
new DownloadInProgressDialogGtk(browser());
}
diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h
index ad2fa40..e851c15 100644
--- a/chrome/browser/gtk/browser_window_gtk.h
+++ b/chrome/browser/gtk/browser_window_gtk.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -95,7 +95,6 @@ class BrowserWindowGtk : public BrowserWindow,
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
virtual bool IsDownloadShelfVisible() const;
virtual DownloadShelf* GetDownloadShelf();
- virtual void ShowReportBugDialog();
virtual void ShowClearBrowsingDataDialog();
virtual void ShowImportDialog();
virtual void ShowSearchEnginesDialog();
@@ -132,6 +131,9 @@ class BrowserWindowGtk : public BrowserWindow,
virtual void HideInstant(bool instant_is_active);
virtual gfx::Rect GetInstantBounds();
+ virtual gfx::Rect GrabWindowSnapshot(
+ std::vector<unsigned char>* png_representation);
+
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index cdaf933..92fca10 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,6 +36,7 @@
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/debugger/devtools_toggle_action.h"
#include "chrome/browser/debugger/devtools_window.h"
+#include "chrome/browser/dom_ui/bug_report_ui.h"
#include "chrome/browser/dom_ui/filebrowse_ui.h"
#include "chrome/browser/dom_ui/options/content_settings_handler.h"
#include "chrome/browser/download/download_item.h"
@@ -1724,7 +1725,7 @@ void Browser::OpenTaskManager() {
void Browser::OpenBugReportDialog() {
UserMetrics::RecordAction(UserMetricsAction("ReportBug"), profile_);
- window_->ShowReportBugDialog();
+ browser::ShowHtmlBugReportView(this);
}
void Browser::ToggleBookmarkBar() {
diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h
index 154431e..5251502 100644
--- a/chrome/browser/ui/browser_window.h
+++ b/chrome/browser/ui/browser_window.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_UI_BROWSER_WINDOW_H_
#pragma once
+#include <vector>
+
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/content_settings_types.h"
#include "gfx/native_widget_types.h"
@@ -216,9 +218,6 @@ class BrowserWindow {
// Returns the DownloadShelf.
virtual DownloadShelf* GetDownloadShelf() = 0;
- // Shows the Report a Bug dialog box.
- virtual void ShowReportBugDialog() = 0;
-
// Shows the Clear Browsing Data dialog box.
virtual void ShowClearBrowsingDataDialog() = 0;
@@ -345,6 +344,10 @@ class BrowserWindow {
// Construct a FindBar implementation for the specified |browser|.
static FindBar* CreateFindBar(Browser* browser_window);
+ // Grabs a snapshot of the current browser window and returns the bounds.
+ virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>*
+ png_representation) = 0;
+
protected:
friend class BrowserList;
friend class BrowserView;
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h
index d41afc1..398ba0e 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.h
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -76,7 +76,6 @@ class BrowserWindowCocoa : public BrowserWindow,
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
virtual bool IsDownloadShelfVisible() const;
virtual DownloadShelf* GetDownloadShelf();
- virtual void ShowReportBugDialog();
virtual void ShowClearBrowsingDataDialog();
virtual void ShowImportDialog();
virtual void ShowSearchEnginesDialog();
@@ -114,6 +113,9 @@ class BrowserWindowCocoa : public BrowserWindow,
virtual void HideInstant(bool instant_is_active);
virtual gfx::Rect GetInstantBounds();
+ virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>*
+ png_representation);
+
// Overridden from NotificationObserver
virtual void Observe(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
index 1d3f512..12bccc3 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/mac/mac_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
@@ -328,13 +329,6 @@ DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
return [shelfController bridge];
}
-void BrowserWindowCocoa::ShowReportBugDialog() {
- TabContents* current_tab = browser_->GetSelectedTabContents();
- if (current_tab && current_tab->controller().GetActiveEntry()) {
- browser_->ShowBrokenPageTab(current_tab);
- }
-}
-
void BrowserWindowCocoa::ShowClearBrowsingDataDialog() {
[ClearBrowsingDataController
showClearBrowsingDialogForProfile:browser_->profile()];
@@ -607,6 +601,13 @@ gfx::Rect BrowserWindowCocoa::GetInstantBounds() {
return bounds;
}
+gfx::Rect BrowserWindowCocoa::GrabWindowSnapshot(std::vector<unsigned char>*
+ png_representation) {
+ int width = 0, height = 0;
+ base::mac::GrabWindowSnapshot(window(), png_representation, &width, &height);
+ return gfx::Rect(width, height);
+}
+
void BrowserWindowCocoa::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc
index a68922f..e45db37 100644
--- a/chrome/browser/ui/toolbar/wrench_menu_model.cc
+++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -171,10 +171,10 @@ void ToolsMenuModel::Build(Browser* browser) {
AddItemWithStringId(IDC_CLEAR_BROWSING_DATA, IDS_CLEAR_BROWSING_DATA);
AddSeparator();
-#if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_LINUX)
+
AddItemWithStringId(IDC_FEEDBACK, IDS_FEEDBACK);
+
AddSeparator();
-#endif
encoding_menu_model_.reset(new EncodingMenuModel(browser));
AddSubMenuWithStringId(IDC_ENCODING_MENU, IDS_ENCODING_MENU,
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 1559980..1bb37a5 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "app/win/win_util.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "base/string_number_conversions.h"
@@ -1094,10 +1095,6 @@ DownloadShelf* BrowserView::GetDownloadShelf() {
return download_shelf_.get();
}
-void BrowserView::ShowReportBugDialog() {
- browser::ShowHtmlBugReportView(GetWindow(), browser_.get());
-}
-
void BrowserView::ShowClearBrowsingDataDialog() {
browser::ShowClearBrowsingDataView(GetWindow()->GetNativeWindow(),
browser_->profile());
@@ -1393,6 +1390,19 @@ gfx::Rect BrowserView::GetInstantBounds() {
return contents_->GetPreviewBounds();
}
+gfx::Rect BrowserView::GrabWindowSnapshot(std::vector<unsigned char>*
+ png_representation) {
+ views::Window* window = GetWindow();
+
+#if defined(USE_X11)
+ x11_util::GrabWindowSnapshot(window->GetNativeWindow(), png_representation);
+#elif defined(OS_WIN)
+ app::win::GrabWindowSnapshot(window->GetNativeWindow(), png_representation);
+#endif
+
+ return window->GetBounds();
+}
+
#if defined(OS_CHROMEOS)
void BrowserView::ShowKeyboardOverlay(gfx::NativeWindow owning_window) {
KeyboardOverlayDelegate::ShowDialog(owning_window);
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index 645b425..3a570ee 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -292,7 +292,6 @@ class BrowserView : public BrowserBubbleHost,
virtual void SetDownloadShelfVisible(bool visible);
virtual bool IsDownloadShelfVisible() const;
virtual DownloadShelf* GetDownloadShelf();
- virtual void ShowReportBugDialog();
virtual void ShowClearBrowsingDataDialog();
virtual void ShowImportDialog();
virtual void ShowSearchEnginesDialog();
@@ -328,6 +327,9 @@ class BrowserView : public BrowserBubbleHost,
virtual void ShowInstant(TabContents* preview_contents);
virtual void HideInstant(bool instant_is_active);
virtual gfx::Rect GetInstantBounds();
+ virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>*
+ png_representation);
+
#if defined(OS_CHROMEOS)
virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window);
#endif
diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h
index cb22ab1..9e33f75 100644
--- a/chrome/test/test_browser_window.h
+++ b/chrome/test/test_browser_window.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -109,6 +109,12 @@ class TestBrowserWindow : public BrowserWindow {
virtual void ShowInstant(TabContents* preview_contents) {}
virtual void HideInstant(bool instant_is_active) {}
virtual gfx::Rect GetInstantBounds() { return gfx::Rect(); }
+
+ virtual gfx::Rect GrabWindowSnapshot(std::vector<unsigned char>*
+ png_representation) {
+ return gfx::Rect();
+ }
+
#if defined(OS_CHROMEOS)
virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) {}
#endif