summaryrefslogtreecommitdiffstats
path: root/chrome
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
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')
-rw-r--r--chrome/browser/ui/constrained_window_tab_helper.cc14
-rw-r--r--chrome/chrome_renderer.gypi2
-rw-r--r--chrome/common/render_messages.h5
-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
7 files changed, 123 insertions, 7 deletions
diff --git a/chrome/browser/ui/constrained_window_tab_helper.cc b/chrome/browser/ui/constrained_window_tab_helper.cc
index 92acd63..16912a5 100644
--- a/chrome/browser/ui/constrained_window_tab_helper.cc
+++ b/chrome/browser/ui/constrained_window_tab_helper.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/ui/constrained_window_tab_helper_delegate.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
+#include "chrome/common/render_messages.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "content/browser/tab_contents/navigation_details.h"
@@ -73,14 +74,13 @@ void ConstrainedWindowTabHelper::BlockTabContent(bool blocked) {
return;
}
- RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView();
- // 70% opaque grey.
- SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
- if (rwhv)
- rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
// RenderViewHost may be NULL during shutdown.
- if (contents->render_view_host())
- contents->render_view_host()->set_ignore_input_events(blocked);
+ RenderViewHost* host = contents->render_view_host();
+ if (host) {
+ host->set_ignore_input_events(blocked);
+ host->Send(
+ new ChromeViewMsg_SetVisuallyDeemphasized(host->routing_id(), blocked));
+ }
if (delegate_)
delegate_->SetTabContentBlocked(wrapper_, blocked);
}
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index 7a00b52..5fc04aa 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -194,6 +194,8 @@
'renderer/visitedlink_slave.h',
'renderer/weak_v8_function_map.cc',
'renderer/weak_v8_function_map.h',
+ 'renderer/webview_color_overlay.cc',
+ 'renderer/webview_color_overlay.h',
],
'conditions': [
['disable_nacl!=1', {
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 459f13d..deb84a2 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -285,6 +285,11 @@ IPC_MESSAGE_ROUTED4(ChromeViewMsg_DetermineIfPageSupportsInstant,
int /* selection_start */,
int /* selection_end */)
+// Toggles visual muting of the render view area. This is on when a constrained
+// window is showing.
+IPC_MESSAGE_ROUTED1(ChromeViewMsg_SetVisuallyDeemphasized,
+ bool /* deemphazied */)
+
// Tells the renderer to translate the page contents from one language to
// another.
IPC_MESSAGE_ROUTED4(ChromeViewMsg_TranslatePage,
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_