Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1109 OnPluginImeCompositionCompleted) | 1109 OnPluginImeCompositionCompleted) |
| 1110 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) | 1110 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 1111 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) | 1111 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize) |
| 1112 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) | 1112 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
| 1113 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) | 1113 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
| 1114 #endif | 1114 #endif |
| 1115 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, | 1115 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, |
| 1116 OnReleaseDisambiguationPopupDIB) | 1116 OnReleaseDisambiguationPopupDIB) |
| 1117 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, | 1117 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, |
| 1118 OnWindowSnapshotCompleted) | 1118 OnWindowSnapshotCompleted) |
| 1119 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot) | |
| 1119 | 1120 |
| 1120 // Have the super handle all other messages. | 1121 // Have the super handle all other messages. |
| 1121 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 1122 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
| 1122 IPC_END_MESSAGE_MAP() | 1123 IPC_END_MESSAGE_MAP() |
| 1123 | 1124 |
| 1124 if (!msg_is_ok) { | 1125 if (!msg_is_ok) { |
| 1125 // The message had a handler, but its deserialization failed. | 1126 // The message had a handler, but its deserialization failed. |
| 1126 // Kill the renderer to avoid potential spoofing attacks. | 1127 // Kill the renderer to avoid potential spoofing attacks. |
| 1127 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; | 1128 CHECK(false) << "Unable to deserialize message in RenderViewImpl."; |
| 1128 } | 1129 } |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1892 } | 1893 } |
| 1893 | 1894 |
| 1894 void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, | 1895 void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, |
| 1895 const gfx::Size& size, const std::vector<unsigned char>& png) { | 1896 const gfx::Size& size, const std::vector<unsigned char>& png) { |
| 1896 PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id); | 1897 PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id); |
| 1897 DCHECK(it != pending_snapshots_.end()); | 1898 DCHECK(it != pending_snapshots_.end()); |
| 1898 it->second.Run(size, png); | 1899 it->second.Run(size, png); |
| 1899 pending_snapshots_.erase(it); | 1900 pending_snapshots_.erase(it); |
| 1900 } | 1901 } |
| 1901 | 1902 |
| 1903 namespace { | |
| 1904 | |
| 1905 bool CaptureSnapshot(WebView* view, | |
| 1906 const gfx::Rect& src_subrect, | |
| 1907 SkBitmap* snapshot) { | |
| 1908 base::TimeTicks beginning_time = base::TimeTicks::Now(); | |
| 1909 | |
| 1910 view->layout(); | |
| 1911 const WebSize& size = view->size(); | |
|
jamesr
2013/03/18 22:41:18
I'm not sure about this - the size of a WebWidget
justinlin
2013/03/18 23:27:51
Done. Yea, this old stuff didn't really work with
| |
| 1912 gfx::Rect viewport_size = gfx::IntersectRects( | |
| 1913 src_subrect, gfx::Rect(size.width, size.height)); | |
| 1914 | |
| 1915 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( | |
| 1916 skia::CreatePlatformCanvas(viewport_size.width(), | |
| 1917 viewport_size.height(), | |
| 1918 true, | |
| 1919 NULL, | |
| 1920 skia::RETURN_NULL_ON_FAILURE)); | |
| 1921 if (!canvas) | |
| 1922 return false; | |
| 1923 | |
| 1924 view->paint(webkit_glue::ToWebCanvas(canvas.get()), viewport_size); | |
| 1925 | |
| 1926 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false); | |
| 1927 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) | |
| 1928 return false; | |
| 1929 | |
| 1930 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot", | |
| 1931 base::TimeTicks::Now() - beginning_time); | |
| 1932 return true; | |
| 1933 } | |
| 1934 | |
| 1935 } // namespace | |
| 1936 | |
| 1937 void RenderViewImpl::OnSnapshot(const gfx::Rect& src_subrect) { | |
| 1938 SkBitmap snapshot; | |
| 1939 bool error = false; | |
| 1940 | |
| 1941 if (!webview()->mainFrame() || !CaptureSnapshot(webview(), | |
| 1942 src_subrect, | |
| 1943 &snapshot)) | |
| 1944 error = true; | |
| 1945 | |
| 1946 DCHECK(error == snapshot.empty()) << | |
| 1947 "Snapshot should be empty on error, non-empty otherwise."; | |
| 1948 | |
| 1949 Send(new ViewHostMsg_Snapshot(routing_id_, !error, snapshot)); | |
| 1950 } | |
| 1951 | |
| 1902 // WebKit::WebViewClient ------------------------------------------------------ | 1952 // WebKit::WebViewClient ------------------------------------------------------ |
| 1903 | 1953 |
| 1904 WebView* RenderViewImpl::createView( | 1954 WebView* RenderViewImpl::createView( |
| 1905 WebFrame* creator, | 1955 WebFrame* creator, |
| 1906 const WebURLRequest& request, | 1956 const WebURLRequest& request, |
| 1907 const WebWindowFeatures& features, | 1957 const WebWindowFeatures& features, |
| 1908 const WebString& frame_name, | 1958 const WebString& frame_name, |
| 1909 WebNavigationPolicy policy) { | 1959 WebNavigationPolicy policy) { |
| 1910 // Check to make sure we aren't overloading on popups. | 1960 // Check to make sure we aren't overloading on popups. |
| 1911 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) | 1961 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| (...skipping 4680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6592 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); | 6642 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| 6593 RenderProcess::current()->ReleaseTransportDIB(dib); | 6643 RenderProcess::current()->ReleaseTransportDIB(dib); |
| 6594 } | 6644 } |
| 6595 | 6645 |
| 6596 void RenderViewImpl::DidCommitCompositorFrame() { | 6646 void RenderViewImpl::DidCommitCompositorFrame() { |
| 6597 RenderWidget::DidCommitCompositorFrame(); | 6647 RenderWidget::DidCommitCompositorFrame(); |
| 6598 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); | 6648 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame()); |
| 6599 } | 6649 } |
| 6600 | 6650 |
| 6601 } // namespace content | 6651 } // namespace content |
| OLD | NEW |