diff options
author | bajones@chromium.org <bajones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-15 22:20:09 +0000 |
---|---|---|
committer | bajones@chromium.org <bajones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-15 22:20:09 +0000 |
commit | c9bc8f1104914818e054b7f9f2b928ce78bc9dd8 (patch) | |
tree | 65db09fb71c6f73383285b406fe25aaf7d206dc9 /content | |
parent | d72acb0dd473cd8dd0d3d420e22a03c766d76623 (diff) | |
download | chromium_src-c9bc8f1104914818e054b7f9f2b928ce78bc9dd8.zip chromium_src-c9bc8f1104914818e054b7f9f2b928ce78bc9dd8.tar.gz chromium_src-c9bc8f1104914818e054b7f9f2b928ce78bc9dd8.tar.bz2 |
Implemented GetWindowSnapshot on RenderViewImpl
This necessitated the relocation of the previous chrome::GrabWindowSnapshot code
to ui/snapshot, which has been turned into it's own component to avoid circular dependencies with aura.
A new variant of GrabWindowSnapshot, GrabViewSnapshot, has been added as well to facilitate easier usage by views. chrome::GrabWindowSnapshotForUser was left in place to accomodate existing calls
to the API, but now calls up to the ui/snapshot code.
This is a subset of the prior CL 11362023, which has been broken apart to facilitate easier reviews
BUG=157479
Review URL: https://chromiumcodereview.appspot.com/11399002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/DEPS | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host_impl.cc | 25 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host_impl.h | 1 | ||||
-rw-r--r-- | content/common/view_messages.h | 10 | ||||
-rw-r--r-- | content/content_browser.gypi | 1 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 17 | ||||
-rw-r--r-- | content/renderer/render_view_impl.h | 16 |
7 files changed, 71 insertions, 0 deletions
diff --git a/content/DEPS b/content/DEPS index 09dd65b..0362df1 100644 --- a/content/DEPS +++ b/content/DEPS @@ -57,6 +57,7 @@ include_rules = [ "+ui/gfx", "+ui/gl", "+ui/native_theme", + "+ui/snapshot", "+ui/surface", # Content knows about grd files, but the specifics of how to get a resource # given its id is left to the embedder. diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index a578297..b49410c 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -65,6 +65,7 @@ #include "ui/base/dialogs/selected_file_info.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/native_widget_types.h" +#include "ui/snapshot/snapshot.h" #include "webkit/fileapi/isolated_context.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webkit_glue.h" @@ -1020,6 +1021,7 @@ bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse, OnScriptEvalResponse) IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL) IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification) + IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowSnapshot, OnGetWindowSnapshot) #if defined(OS_ANDROID) IPC_MESSAGE_HANDLER(ViewHostMsg_StartContentIntent, OnStartContentIntent) IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeBodyBackgroundColor, @@ -2058,4 +2060,27 @@ void RenderViewHostImpl::ClearPowerSaveBlockers() { STLDeleteValues(&power_save_blockers_); } +void RenderViewHostImpl::OnGetWindowSnapshot(const int snapshot_id) { + std::vector<unsigned char> png; + + // This feature is behind the kEnableGpuBenchmarking command line switch + // because it poses security concerns and should only be used for testing. + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kEnableGpuBenchmarking)) { + gfx::Rect view_bounds = GetView()->GetViewBounds(); + gfx::Rect snapshot_bounds(view_bounds.size()); + gfx::Size snapshot_size = snapshot_bounds.size(); + + if (ui::GrabViewSnapshot(GetView()->GetNativeView(), + &png, snapshot_bounds)) { + Send(new ViewMsg_WindowSnapshotCompleted( + GetRoutingID(), snapshot_id, snapshot_size, png)); + return; + } + } + + Send(new ViewMsg_WindowSnapshotCompleted( + GetRoutingID(), snapshot_id, gfx::Size(), png)); +} + } // namespace content diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index 76942f2..6aee5890 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -571,6 +571,7 @@ class CONTENT_EXPORT RenderViewHostImpl void OnDomOperationResponse(const std::string& json_string, int automation_id); void OnFrameTreeUpdated(const std::string& frame_tree); + void OnGetWindowSnapshot(const int snapshot_id); #if defined(OS_MACOSX) || defined(OS_ANDROID) void OnMsgShowPopup(const ViewHostMsg_ShowPopup_Params& params); diff --git a/content/common/view_messages.h b/content/common/view_messages.h index d1e322e..d2464e9 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1447,6 +1447,12 @@ IPC_MESSAGE_ROUTED1(ViewMsg_SelectPopupMenuItem, IPC_MESSAGE_ROUTED1(ViewMsg_ReleaseDisambiguationPopupDIB, TransportDIB::Handle /* DIB handle */) +// Notifies the renderer that a snapshot has been retrieved. +IPC_MESSAGE_ROUTED3(ViewMsg_WindowSnapshotCompleted, + int /* snapshot_id */, + gfx::Size /* size */, + std::vector<unsigned char> /* png */) + // ----------------------------------------------------------------------------- // Messages sent from the renderer to the browser. @@ -1946,6 +1952,10 @@ IPC_MESSAGE_ROUTED3(ViewHostMsg_WebUISend, std::string /* message */, base::ListValue /* args */) +// Requests a snapshot of the given window. +IPC_MESSAGE_ROUTED1(ViewHostMsg_GetWindowSnapshot, + int /* snapshot_id */) + // A renderer sends this to the browser process when it wants to create a ppapi // plugin. The browser will create the plugin process if necessary, and will // return a handle to the channel on success. diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 6817766..b2a7aa8 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -22,6 +22,7 @@ '../net/net.gyp:net', '../skia/skia.gyp:skia', '../third_party/zlib/zlib.gyp:zlib', + '../ui/snapshot/snapshot.gyp:snapshot', '../ui/ui.gyp:ui', '../ui/ui.gyp:ui_resources', ], diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index bb8bd79..fd18ad1 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -600,6 +600,7 @@ RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) #endif session_storage_namespace_id_(params->session_storage_namespace_id), handling_select_range_(false), + next_snapshot_id_(0), #if defined(OS_WIN) focused_plugin_id_(-1), #endif @@ -1043,6 +1044,8 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { #endif IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB, OnReleaseDisambiguationPopupDIB) + IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted, + OnWindowSnapshotCompleted) // Have the super handle all other messages. IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) @@ -1766,6 +1769,20 @@ bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { return Send(message); } +void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) { + int id = next_snapshot_id_++; + pending_snapshots_.insert(std::make_pair(id, callback)); + Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id)); +} + +void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id, + const gfx::Size& size, const std::vector<unsigned char>& png) { + PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id); + DCHECK(it != pending_snapshots_.end()); + it->second.Run(size, png); + pending_snapshots_.erase(it); +} + // WebKit::WebViewClient ------------------------------------------------------ WebView* RenderViewImpl::createView( diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 63be682..e0d13f1 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -379,6 +379,13 @@ class CONTENT_EXPORT RenderViewImpl // supported PPAPI plug-ins. bool HasIMETextFocus(); + // Callback for use with GetWindowSnapshot. + typedef base::Callback<void( + const gfx::Size&, const std::vector<unsigned char>&)> + WindowSnapshotCallback; + + void GetWindowSnapshot(const WindowSnapshotCallback& callback); + // IPC::Listener implementation ---------------------------------------------- virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; @@ -1032,6 +1039,9 @@ class CONTENT_EXPORT RenderViewImpl const gfx::Rect& view_frame); #endif + void OnWindowSnapshotCompleted(const int snapshot_id, + const gfx::Size& size, const std::vector<unsigned char>& png); + // Adding a new message handler? Please add it in alphabetical order above // and put it in the same position in the .cc file. @@ -1500,6 +1510,12 @@ class CONTENT_EXPORT RenderViewImpl // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface. scoped_ptr<MouseLockDispatcher::LockTarget> webwidget_mouse_lock_target_; + // State associated with the GetWindowSnapshot function. + int next_snapshot_id_; + typedef std::map<int, WindowSnapshotCallback> + PendingSnapshotMap; + PendingSnapshotMap pending_snapshots_; + // Plugins ------------------------------------------------------------------- // All the currently active plugin delegates for this RenderView; kept so |