summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 21:29:36 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 21:29:36 +0000
commit1138ccee095823e0c05ec084f19fbabe96b8f0a3 (patch)
tree3e456a5aa0a97f5bf0a430e2dacb24eea59101db /chrome/renderer
parent70f48c0a4cfc3675313ad7e8262a6e6b72583690 (diff)
downloadchromium_src-1138ccee095823e0c05ec084f19fbabe96b8f0a3.zip
chromium_src-1138ccee095823e0c05ec084f19fbabe96b8f0a3.tar.gz
chromium_src-1138ccee095823e0c05ec084f19fbabe96b8f0a3.tar.bz2
Implement SetVisuallyDeemphasized in ChromeRenderViewObserver.
Implement SetVisuallyDeemphasized in ChromeRenderViewObserver - Add a ChromeViewMsg_SetVisuallyDeemphasized and use it to toggle background dimming on web contents via ChromeRenderViewObserver; - Derive WebViewColorOverlay from WebKit::WebPageOverlay and add to web view when need to dimming the background; - Remove RWHV SetVisuallyDeemphasized since it's no longer used; BUG=103386 TEST=Verify fix for 103386, dimming should show up even when accelerated compositing is on. Review URL: http://codereview.chromium.org/8730001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112787 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/chrome_render_view_observer.cc19
-rw-r--r--chrome/renderer/chrome_render_view_observer.h6
-rw-r--r--chrome/renderer/webview_color_overlay.cc49
-rw-r--r--chrome/renderer/webview_color_overlay.h35
4 files changed, 109 insertions, 0 deletions
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc
index d4451c5..d352fe5 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -27,6 +27,7 @@
#include "chrome/renderer/prerender/prerender_helper.h"
#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
#include "chrome/renderer/translate_helper.h"
+#include "chrome/renderer/webview_color_overlay.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/content_renderer_client.h"
@@ -47,6 +48,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/favicon_size.h"
+#include "ui/gfx/size.h"
#include "ui/gfx/skbitmap_operations.h"
#include "webkit/glue/image_decoder.h"
#include "webkit/glue/image_resource_fetcher.h"
@@ -259,6 +261,8 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
OnSetAllowRunningInsecureContent)
IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection,
OnSetClientSidePhishingDetection)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SetVisuallyDeemphasized,
+ OnSetVisuallyDeemphasized)
#if defined(OS_CHROMEOS)
IPC_MESSAGE_HANDLER(ChromeViewMsg_StartFrameSniffer, OnStartFrameSniffer)
#endif
@@ -380,6 +384,21 @@ void ChromeRenderViewObserver::OnSetClientSidePhishingDetection(
#endif
}
+void ChromeRenderViewObserver::OnSetVisuallyDeemphasized(bool deemphasized) {
+ bool already_deemphasized = !!dimmed_color_overlay_.get();
+ if (already_deemphasized == deemphasized)
+ return;
+
+ if (deemphasized) {
+ // 70% opaque grey.
+ SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
+ dimmed_color_overlay_.reset(
+ new WebViewColorOverlay(render_view(), greyish));
+ } else {
+ dimmed_color_overlay_.reset();
+ }
+}
+
void ChromeRenderViewObserver::OnStartFrameSniffer(const string16& frame_name) {
new FrameSniffer(render_view(), frame_name);
}
diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h
index 4f995b1..bbaa13e 100644
--- a/chrome/renderer/chrome_render_view_observer.h
+++ b/chrome/renderer/chrome_render_view_observer.h
@@ -25,10 +25,12 @@ class ExternalHostBindings;
class SkBitmap;
class TranslateHelper;
struct ThumbnailScore;
+class WebViewColorOverlay;
namespace WebKit {
class WebView;
}
+
namespace safe_browsing {
class PhishingClassifierDelegate;
}
@@ -127,6 +129,7 @@ class ChromeRenderViewObserver : public content::RenderViewObserver,
void OnSetAllowDisplayingInsecureContent(bool allow);
void OnSetAllowRunningInsecureContent(bool allow);
void OnSetClientSidePhishingDetection(bool enable_phishing_detection);
+ void OnSetVisuallyDeemphasized(bool deemphasized);
void OnStartFrameSniffer(const string16& frame_name);
void OnGetFPS();
void OnAddStrictSecurityHost(const std::string& host);
@@ -220,6 +223,9 @@ class ChromeRenderViewObserver : public content::RenderViewObserver,
// ImageResourceFetchers schedule via DownloadImage.
ImageResourceFetcherList image_fetchers_;
+ // A color page overlay when visually de-emaphasized.
+ scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_;
+
DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver);
};
diff --git a/chrome/renderer/webview_color_overlay.cc b/chrome/renderer/webview_color_overlay.cc
new file mode 100644
index 0000000..c300dfd
--- /dev/null
+++ b/chrome/renderer/webview_color_overlay.cc
@@ -0,0 +1,49 @@
+// 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.
+
+#include "chrome/renderer/webview_color_overlay.h"
+
+#include "base/logging.h"
+#include "content/public/renderer/render_view.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkRect.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+#include "ui/gfx/size.h"
+#include "ui/gfx/skia_util.h"
+
+#if WEBKIT_USING_CG
+#include "skia/ext/skia_utils_mac.h"
+#endif
+
+WebViewColorOverlay::WebViewColorOverlay(content::RenderView* render_view,
+ SkColor color)
+ : render_view_(render_view),
+ color_(color) {
+ render_view_->GetWebView()->addPageOverlay(this, 0);
+}
+
+WebViewColorOverlay::~WebViewColorOverlay() {
+ render_view_->GetWebView()->removePageOverlay(this);
+}
+
+void WebViewColorOverlay::paintPageOverlay(WebKit::WebCanvas* canvas) {
+ SkRect rect = gfx::RectToSkRect(gfx::Rect(render_view_->GetSize()));
+
+#if WEBKIT_USING_SKIA
+ SkPaint paint;
+ paint.setColor(color_);
+ paint.setStyle(SkPaint::kFill_Style);
+ canvas->drawRect(rect, paint);
+#elif WEBKIT_USING_CG
+ CGContextSaveGState(canvas);
+ CGColorRef color = gfx::SkColorToCGColorRef(color_);
+ CGContextSetFillColorWithColor(canvas, color);
+ CGColorRelease(color);
+ CGContextFillRect(canvas, gfx::SkRectToCGRect(rect));
+ CGContextRestoreGState(canvas);
+#else
+ NOTIMPLEMENTED();
+#endif
+}
diff --git a/chrome/renderer/webview_color_overlay.h b/chrome/renderer/webview_color_overlay.h
new file mode 100644
index 0000000..3592637
--- /dev/null
+++ b/chrome/renderer/webview_color_overlay.h
@@ -0,0 +1,35 @@
+// 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.
+
+#ifndef CHROME_RENDERER_WEBVIEW_COLOR_OVERLAY_H_
+#define CHROME_RENDERER_WEBVIEW_COLOR_OVERLAY_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageOverlay.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
+
+namespace content {
+class RenderView;
+}
+
+// This class draws the given color on a PageOverlay of a WebView.
+class WebViewColorOverlay : public WebKit::WebPageOverlay {
+ public:
+ WebViewColorOverlay(content::RenderView* render_view, SkColor color);
+ virtual ~WebViewColorOverlay();
+
+ private:
+ // WebKit::WebPageOverlay implementation:
+ virtual void paintPageOverlay(WebKit::WebCanvas* canvas);
+
+ content::RenderView* render_view_;
+ SkColor color_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebViewColorOverlay);
+};
+
+#endif // CHROME_RENDERER_WEBVIEW_COLOR_OVERLAY_H_