Replace image_messages.h with Mojo service
Implement ImageDownloader service and register it into RenderFrame
ServiceRegistry. This Mojo service will do the job did by
ImageLoadingHelper before.
Re-use mojom files:
third_party/mojo_services/src/geometry/public/interfaces/
geometry.mojom
skia/public/interfaces/bitmap.mojom
[email protected],[email protected],[email protected],[email protected]
BUG=
Review URL: https://codereview.chromium.org/1085783002
Cr-Commit-Position: refs/heads/master@{#337370}
diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
index 474f562..9211dc1 100644
--- a/content/browser/BUILD.gn
+++ b/content/browser/BUILD.gn
@@ -116,6 +116,9 @@
"//device/bluetooth",
"//gin",
"//mojo/application/public/interfaces",
+ "//mojo/common:url_type_converters",
+ "//mojo/converters/geometry",
+ "//skia/public",
"//storage/browser",
"//storage/common",
"//third_party/WebKit/public:image_resources",
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc
index e24f00c8..45b08917 100644
--- a/content/browser/frame_host/render_frame_host_impl.cc
+++ b/content/browser/frame_host/render_frame_host_impl.cc
@@ -1873,6 +1873,9 @@
#endif
service_registry_.reset();
+
+ // Disconnect with ImageDownloader Mojo service in RenderFrame.
+ mojo_image_downloader_.reset();
}
bool RenderFrameHostImpl::IsFocused() {
@@ -1885,6 +1888,15 @@
frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
}
+const image_downloader::ImageDownloaderPtr&
+RenderFrameHostImpl::GetMojoImageDownloader() {
+ if (!mojo_image_downloader_.get()) {
+ GetServiceRegistry()->ConnectToRemoteService(
+ mojo::GetProxy(&mojo_image_downloader_));
+ }
+ return mojo_image_downloader_;
+}
+
void RenderFrameHostImpl::UpdateCrossProcessIframeAccessibility(
const std::map<int32, int>& node_to_frame_routing_id_map) {
for (const auto& iter : node_to_frame_routing_id_map) {
diff --git a/content/browser/frame_host/render_frame_host_impl.h b/content/browser/frame_host/render_frame_host_impl.h
index d34b4ef3..72e39da 100644
--- a/content/browser/frame_host/render_frame_host_impl.h
+++ b/content/browser/frame_host/render_frame_host_impl.h
@@ -20,6 +20,7 @@
#include "content/common/content_export.h"
#include "content/common/frame_message_enums.h"
#include "content/common/frame_replication_state.h"
+#include "content/common/image_downloader/image_downloader.mojom.h"
#include "content/common/mojo/service_registry_impl.h"
#include "content/common/navigation_params.h"
#include "content/public/browser/render_frame_host.h"
@@ -445,6 +446,9 @@
// addition, its associated RenderWidgetHost has to be focused.
bool IsFocused();
+ // Returns the Mojo ImageDownloader service pointer.
+ const image_downloader::ImageDownloaderPtr& GetMojoImageDownloader();
+
protected:
friend class RenderFrameHostFactory;
@@ -735,6 +739,9 @@
// The frame's Mojo Shell service.
scoped_ptr<FrameMojoShell> frame_mojo_shell_;
+ // Holder of Mojo connection with ImageDownloader service in RenderFrame.
+ image_downloader::ImageDownloaderPtr mojo_image_downloader_;
+
// NOTE: This must be the last member.
base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_;
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 55d2e571..3df8edb 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -62,7 +62,6 @@
#include "content/common/browser_plugin/browser_plugin_constants.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/frame_messages.h"
-#include "content/common/image_messages.h"
#include "content/common/input_messages.h"
#include "content/common/ssl_status_serialization.h"
#include "content/common/view_messages.h"
@@ -97,11 +96,15 @@
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "content/public/common/web_preferences.h"
+#include "mojo/common/url_type_converters.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
#include "net/base/net_util.h"
#include "net/http/http_cache.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+#include "skia/public/type_converters.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/layout.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
@@ -135,19 +138,19 @@
base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
-static int StartDownload(RenderFrameHost* rfh,
- const GURL& url,
- bool is_favicon,
- uint32_t max_bitmap_size,
- bool bypass_cache) {
- static int g_next_image_download_id = 0;
- rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
- ++g_next_image_download_id,
- url,
- is_favicon,
- max_bitmap_size,
- bypass_cache));
- return g_next_image_download_id;
+static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
+ int id,
+ const GURL& image_url,
+ image_downloader::DownloadResultPtr result) {
+ DCHECK(result);
+
+ const std::vector<SkBitmap> images =
+ result->images.To<std::vector<SkBitmap>>();
+ const std::vector<gfx::Size> original_image_sizes =
+ result->original_image_sizes.To<std::vector<gfx::Size>>();
+
+ callback.Run(id, result->http_status_code, image_url, images,
+ original_image_sizes);
}
void NotifyCacheOnIO(
@@ -611,7 +614,6 @@
OnBrowserPluginMessage(render_frame_host,
message))
#endif
- IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
OnShowValidationMessage)
@@ -2593,15 +2595,27 @@
color_chooser_info_.reset();
}
-int WebContentsImpl::DownloadImage(const GURL& url,
- bool is_favicon,
- uint32_t max_bitmap_size,
- bool bypass_cache,
- const ImageDownloadCallback& callback) {
- int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size,
- bypass_cache);
- image_download_map_[id] = callback;
- return id;
+int WebContentsImpl::DownloadImage(
+ const GURL& url,
+ bool is_favicon,
+ uint32_t max_bitmap_size,
+ bool bypass_cache,
+ const WebContents::ImageDownloadCallback& callback) {
+ static int next_image_download_id = 0;
+ const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
+ GetMainFrame()->GetMojoImageDownloader();
+ image_downloader::DownloadRequestPtr req =
+ image_downloader::DownloadRequest::New();
+
+ req->url = mojo::String::From(url);
+ req->is_favicon = is_favicon;
+ req->max_bitmap_size = max_bitmap_size;
+ req->bypass_cache = bypass_cache;
+
+ mojo_image_downloader->DownloadImage(
+ req.Pass(),
+ base::Bind(&DidDownloadImage, callback, ++next_image_download_id, url));
+ return next_image_download_id;
}
bool WebContentsImpl::IsSubframe() const {
@@ -3176,28 +3190,6 @@
}
#endif // defined(ENABLE_PLUGINS)
-void WebContentsImpl::OnDidDownloadImage(
- int id,
- int http_status_code,
- const GURL& image_url,
- const std::vector<SkBitmap>& bitmaps,
- const std::vector<gfx::Size>& original_bitmap_sizes) {
- if (bitmaps.size() != original_bitmap_sizes.size())
- return;
-
- ImageDownloadMap::iterator iter = image_download_map_.find(id);
- if (iter == image_download_map_.end()) {
- // Currently WebContents notifies us of ANY downloads so that it is
- // possible to get here.
- return;
- }
- if (!iter->second.is_null()) {
- iter->second.Run(
- id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
- }
- image_download_map_.erase(id);
-}
-
void WebContentsImpl::OnUpdateFaviconURL(
const std::vector<FaviconURL>& candidates) {
// We get updated favicon URLs after the page stops loading. If a cross-site
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index b41a3507..8f3c90a7 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -856,11 +856,6 @@
void OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
const IPC::Message& message);
#endif // defined(ENABLE_PLUGINS)
- void OnDidDownloadImage(int id,
- int http_status_code,
- const GURL& image_url,
- const std::vector<SkBitmap>& bitmaps,
- const std::vector<gfx::Size>& original_bitmap_sizes);
void OnUpdateFaviconURL(const std::vector<FaviconURL>& candidates);
void OnFirstVisuallyNonEmptyPaint();
void OnMediaPlayingNotification(int64 player_cookie,
@@ -1242,10 +1237,6 @@
// completed making layout changes to effect an exit from fullscreen mode.
bool fullscreen_widget_had_focus_at_shutdown_;
- // Maps the ids of pending image downloads to their callbacks
- typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
- ImageDownloadMap image_download_map_;
-
// Whether this WebContents is responsible for displaying a subframe in a
// different process from its parent page.
bool is_subframe_;