summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authornoelutz@google.com <noelutz@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 22:15:13 +0000
committernoelutz@google.com <noelutz@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 22:15:13 +0000
commit98e92fe2a09ad68c21e43dda8680db5263825db8 (patch)
tree676697b8ffcdc06385b4e3818e852ff51414afde /chrome
parentf3da4a2a4494f315000616cc756323b3af2e9f45 (diff)
downloadchromium_src-98e92fe2a09ad68c21e43dda8680db5263825db8.zip
chromium_src-98e92fe2a09ad68c21e43dda8680db5263825db8.tar.gz
chromium_src-98e92fe2a09ad68c21e43dda8680db5263825db8.tar.bz2
Revert 60368 - Client-side phishing detection: grab snapshot of custom sized view.
Client-side phishing detection needs to be able to take a snapshot of a particular page that has a constant size and aspect ratio (e.g., 1024x768). This CL adds a helper function (safe_browsing::GrabPhishingThumbnail) which re-sizes the view a given size, grabs the snapshot, and then re-sizes the view back to its previous size. Note: this function can be slow since it might re-layout the page twice. This function will only be called if we are very confident that the current page is a phishing site in which case we are OK with taking a slow snapshot. Also, this CL adds a test for the OnMsgPaintAtSize method in the RenderWidget since it does something very similar than the new Thumbnailer. BUG=None TEST=GrabPhishingThumbnail Review URL: http://codereview.chromium.org/3380001 TBR=noelutz@google.com Review URL: http://codereview.chromium.org/3439026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/chrome_renderer.gypi2
-rw-r--r--chrome/chrome_tests.gypi3
-rw-r--r--chrome/renderer/render_view.cc9
-rw-r--r--chrome/renderer/render_view.h8
-rw-r--r--chrome/renderer/render_widget.h2
-rw-r--r--chrome/renderer/render_widget_browsertest.h59
-rw-r--r--chrome/renderer/safe_browsing/phishing_thumbnailer.cc82
-rw-r--r--chrome/renderer/safe_browsing/phishing_thumbnailer.h40
-rw-r--r--chrome/renderer/safe_browsing/phishing_thumbnailer_browsertest.cc33
9 files changed, 7 insertions, 231 deletions
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index 9fe4e5b..3d072c0 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -205,8 +205,6 @@
'renderer/safe_browsing/phishing_dom_feature_extractor.h',
'renderer/safe_browsing/phishing_term_feature_extractor.cc',
'renderer/safe_browsing/phishing_term_feature_extractor.h',
- 'renderer/safe_browsing/phishing_thumbnailer.cc',
- 'renderer/safe_browsing/phishing_thumbnailer.h',
'renderer/safe_browsing/phishing_url_feature_extractor.cc',
'renderer/safe_browsing/phishing_url_feature_extractor.h',
'renderer/safe_browsing/scorer.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index e6d44a7..a9ae02e 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1809,12 +1809,9 @@
'renderer/pepper_devices_browsertest.cc',
'renderer/render_view_browsertest.cc',
'renderer/render_view_browsertest_mac.mm',
- 'renderer/render_widget_browsertest.cc',
- 'renderer/render_widget_browsertest.h',
'renderer/safe_browsing/mock_feature_extractor_clock.h',
'renderer/safe_browsing/phishing_classifier_browsertest.cc',
'renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc',
- 'renderer/safe_browsing/phishing_thumbnailer_browsertest.cc',
'renderer/safe_browsing/render_view_fake_resources_test.cc',
'renderer/safe_browsing/render_view_fake_resources_test.h',
'renderer/translate_helper_browsertest.cc',
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 98fa378..c3e2aa0 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -4660,9 +4660,14 @@ void RenderView::OnResize(const gfx::Size& new_size,
const gfx::Rect& resizer_rect) {
if (webview()) {
webview()->hidePopups();
+
if (send_preferred_size_changes_) {
- webview()->mainFrame()->setCanHaveScrollbars(
- should_display_scrollbars(new_size.width(), new_size.height()));
+ // If resizing to a size larger than |disable_scrollbars_size_limit_| in
+ // either width or height, allow scroll bars.
+ bool allow_scrollbars = (
+ disable_scrollbars_size_limit_.width() <= new_size.width() ||
+ disable_scrollbars_size_limit_.height() <= new_size.height());
+ webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
}
}
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index f267de6..1a8e0b5 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -220,14 +220,6 @@ class RenderView : public RenderWidget,
return page_click_tracker_.get();
}
- // Returns true if we should display scrollbars for the given view size and
- // false if the scrollbars should be hidden.
- bool should_display_scrollbars(int width, int height) const {
- return (!send_preferred_size_changes_ ||
- (disable_scrollbars_size_limit_.width() <= width ||
- disable_scrollbars_size_limit_.height() <= height));
- }
-
// Called from JavaScript window.external.AddSearchProvider() to add a
// keyword for a provider described in the given OpenSearch document.
void AddSearchProvider(const std::string& url);
diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h
index e1dacf3..47bdf38 100644
--- a/chrome/renderer/render_widget.h
+++ b/chrome/renderer/render_widget.h
@@ -128,8 +128,6 @@ class RenderWidget : public IPC::Channel::Listener,
// Friend RefCounted so that the dtor can be non-public. Using this class
// without ref-counting is an error.
friend class base::RefCounted<RenderWidget>;
- // For unit tests.
- friend class RenderWidgetTest;
RenderWidget(RenderThreadBase* render_thread,
WebKit::WebPopupType popup_type);
diff --git a/chrome/renderer/render_widget_browsertest.h b/chrome/renderer/render_widget_browsertest.h
deleted file mode 100644
index cf124dd..0000000
--- a/chrome/renderer/render_widget_browsertest.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef CHROME_RENDERER_RENDER_WIDGET_BROWSERTEST_H_
-#define CHROME_RENDERER_RENDER_WIDGET_BROWSERTEST_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "base/file_path.h"
-#include "chrome/test/render_view_test.h"
-
-namespace gfx {
-class Size;
-}
-
-class SkBitmap;
-class TransportDIB;
-
-class RenderWidgetTest : public RenderViewTest {
- public:
- RenderWidgetTest();
-
- protected:
- static const int kNumBytesPerPixel;
- static const int kLargeWidth;
- static const int kLargeHeight;
- static const int kSmallWidth;
- static const int kSmallHeight;
- static const int kTextPositionX;
- static const int kTextPositionY;
- static const int kSequenceNum;
- static const uint32 kRedARGB;
-
- // Helper function which calls OnMsgPaintAtSize and also paints the result
- // in the given bitmap. The widget is resized to |page_size| before we paint
- // and the final image is resized to |desired_size|. This method is virtual so
- // that TestResizeAndPaint() can be reused by subclasses of this test class.
- virtual void ResizeAndPaint(const gfx::Size& page_size,
- const gfx::Size& desired_size,
- SkBitmap* snapshot);
-
- // Test for ResizeAndPaint.
- void TestResizeAndPaint();
-
- // Helper function which returns true if the given bitmap contains the given
- // ARGB color and false otherwise.
- bool ImageContainsColor(const SkBitmap& bitmap, uint32 argb_color);
-
- // This can be used for debugging if you want to output a bitmap
- // image to a file.
- // FilePath tmp_path;
- // file_util::CreateTemporaryFile(&tmp_path);
- // OutputBitmapToFile(bitmap, tmp_path);
- // LOG(INFO) << "Bitmap image stored at: " << tmp_path.value();
- void OutputBitmapToFile(const SkBitmap& bitmap, const FilePath& file_path);
-};
-
-#endif // CHROME_RENDERER_RENDER_WIDGET_BROWSERTEST_H_
diff --git a/chrome/renderer/safe_browsing/phishing_thumbnailer.cc b/chrome/renderer/safe_browsing/phishing_thumbnailer.cc
deleted file mode 100644
index 439a40e..0000000
--- a/chrome/renderer/safe_browsing/phishing_thumbnailer.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (c) 2010 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.
-
-#include "chrome/renderer/safe_browsing/phishing_thumbnailer.h"
-
-#include "base/histogram.h"
-#include "base/logging.h"
-#include "base/time.h"
-#include "chrome/renderer/render_view.h"
-#include "gfx/size.h"
-#include "skia/ext/bitmap_platform_device.h"
-#include "skia/ext/image_operations.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
-#include "webkit/glue/webkit_glue.h"
-
-using WebKit::WebRect;
-using WebKit::WebSize;
-using WebKit::WebView;
-
-namespace safe_browsing {
-
-SkBitmap GrabPhishingThumbnail(RenderView* render_view,
- const gfx::Size& view_size,
- const gfx::Size& thumbnail_size) {
- if (!render_view || !render_view->webview()) {
- NOTREACHED();
- return SkBitmap();
- }
- WebView* view = render_view->webview();
- base::TimeTicks beginning_time = base::TimeTicks::Now();
- skia::PlatformCanvas canvas;
- if (!canvas.initialize(view_size.width(), view_size.height(), true)) {
- return SkBitmap();
- }
-
- // Make sure we are not using any zoom when we take the snapshot. We will
- // restore the previous zoom level after the snapshot is taken.
- int old_zoom_level = view->zoomLevel();
- if (view->zoomLevel() != 0) {
- view->setZoomLevel(false, 0);
- }
- WebSize old_size = view->size();
- // TODO(noelutz): not only should we hide all scroll bars but we should also
- // make sure that all scroll-bars are at the top.
- view->mainFrame()->setCanHaveScrollbars(false); // always hide scrollbars.
- view->resize(view_size);
- view->layout();
- view->paint(webkit_glue::ToWebCanvas(&canvas),
- WebRect(0, 0, view_size.width(), view_size.height()));
-
- skia::BitmapPlatformDevice& device =
- static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
-
- // Now resize the thumbnail to the right size. Note: it is important that we
- // use this resize algorithm here.
- const SkBitmap& bitmap = device.accessBitmap(false);
- SkBitmap thumbnail = skia::ImageOperations::Resize(
- bitmap,
- skia::ImageOperations::RESIZE_LANCZOS3,
- thumbnail_size.width(),
- thumbnail_size.height());
-
- // Put things back as they were before.
- if (view->zoomLevel() != old_zoom_level) {
- view->setZoomLevel(false, old_zoom_level);
- }
- // Maybe re-display the scrollbars and resize the view to its old size.
- view->mainFrame()->setCanHaveScrollbars(
- render_view->should_display_scrollbars(old_size.width, old_size.height));
- view->resize(old_size);
-
- HISTOGRAM_TIMES("SBClientPhishing.GrabPhishingThumbnail",
- base::TimeTicks::Now() - beginning_time);
- return thumbnail;
-}
-
-} // namespace safe_browsing
diff --git a/chrome/renderer/safe_browsing/phishing_thumbnailer.h b/chrome/renderer/safe_browsing/phishing_thumbnailer.h
deleted file mode 100644
index 99460c6..0000000
--- a/chrome/renderer/safe_browsing/phishing_thumbnailer.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2010 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.
-//
-// Helper function which takes a custom thumbnail for the client-side phishing
-// detector.
-//
-// Important note: in some circumstances grabbing a thumbnail using
-// this function can be very slow since it may need to re-layout the page
-// twice. Also, using this class may have some side effects (e.g.,
-// onScroll and onResize will be called, etc). Currently, this function
-// is only used if Chrome is almost certain that the current page is
-// phishing (according to the client-side phishing detector) in which
-// case we are not too worried about performance or possibly causing
-// some JavaScript weirdness on the page.
-
-#ifndef CHROME_RENDERER_SAFE_BROWSING_PHISHING_THUMBNAILER_H_
-#define CHROME_RENDERER_SAFE_BROWSING_PHISHING_THUMBNAILER_H_
-#pragma once
-
-namespace gfx {
-class Size;
-}
-class RenderView;
-class SkBitmap;
-
-namespace safe_browsing {
-
-// Grabs a thumbnail returns a bitmap that contains the result. Before grabbing
-// a snapshot the view will be re-sized to |view_size| and the resulting
-// snapshot will then be re-sized to the given |thumbnail_size|. If grabbing
-// the thumbnail fails this function returns SkBitmap() in which case calling
-// isNull() on the returned bitmap will return true.
-SkBitmap GrabPhishingThumbnail(RenderView* render_view,
- const gfx::Size& view_size,
- const gfx::Size& thumbnail_size);
-
-} // namespace safe_browsing
-
-#endif // CHROME_RENDERER_SAFE_BROWSING_PHISHING_THUMBNAILER_H_
diff --git a/chrome/renderer/safe_browsing/phishing_thumbnailer_browsertest.cc b/chrome/renderer/safe_browsing/phishing_thumbnailer_browsertest.cc
deleted file mode 100644
index a894b2d..0000000
--- a/chrome/renderer/safe_browsing/phishing_thumbnailer_browsertest.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2010 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.
-
-#include "base/basictypes.h"
-#include "chrome/renderer/render_widget_browsertest.h"
-#include "chrome/renderer/safe_browsing/phishing_thumbnailer.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
-
-namespace safe_browsing {
-
-class ThumbnailerTest : public RenderWidgetTest {
- public:
- ThumbnailerTest() {}
-
- protected:
- virtual void ResizeAndPaint(const gfx::Size& page_size,
- const gfx::Size& desired_size,
- SkBitmap* snapshot) {
- ASSERT_TRUE(snapshot);
- *snapshot = GrabPhishingThumbnail(view_.get(), page_size, desired_size);
- EXPECT_FALSE(snapshot->isNull());
- }
-};
-
-TEST_F(ThumbnailerTest, GrabPhishingThumbnail) {
- TestResizeAndPaint();
-}
-
-} // namespace safe_browsing