Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Unified Diff: content/renderer/notification_icon_loader.cc

Issue 554213003: Request the icon of a Web Notification in the renderer process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include logging.h Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/notification_icon_loader.h ('k') | content/renderer/notification_provider.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/notification_icon_loader.cc
diff --git a/content/renderer/notification_icon_loader.cc b/content/renderer/notification_icon_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d535837dbf92642f2946207fe5cd04e6e507c6a8
--- /dev/null
+++ b/content/renderer/notification_icon_loader.cc
@@ -0,0 +1,83 @@
+// Copyright 2014 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 "content/renderer/notification_icon_loader.h"
+
+#include "base/logging.h"
+#include "content/child/image_decoder.h"
+#include "third_party/WebKit/public/platform/Platform.h"
+#include "third_party/WebKit/public/platform/WebURL.h"
+#include "third_party/WebKit/public/platform/WebURLLoader.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+using blink::WebURL;
+using blink::WebURLError;
+using blink::WebURLLoader;
+using blink::WebURLRequest;
+
+namespace content {
+
+NotificationIconLoader::NotificationIconLoader(
+ int notification_id,
+ const DownloadCompletedCallback& callback)
+ : notification_id_(notification_id),
+ callback_(callback),
+ completed_(false) {}
+
+NotificationIconLoader::~NotificationIconLoader() {}
+
+void NotificationIconLoader::Start(const WebURL& icon_url) {
+ DCHECK(!loader_);
+
+ WebURLRequest request(icon_url);
+ request.setRequestContext(WebURLRequest::RequestContextImage);
+
+ loader_.reset(blink::Platform::current()->createURLLoader());
+ loader_->loadAsynchronously(request, this);
+}
+
+void NotificationIconLoader::Cancel() {
+ DCHECK(loader_);
+
+ completed_ = true;
+ loader_->cancel();
+}
+
+void NotificationIconLoader::didReceiveData(
+ WebURLLoader* loader,
+ const char* data,
+ int data_length,
+ int encoded_data_length) {
+ DCHECK(!completed_);
+ DCHECK_GT(data_length, 0);
+
+ buffer_.insert(buffer_.end(), data, data + data_length);
+}
+
+void NotificationIconLoader::didFinishLoading(
+ WebURLLoader* loader,
+ double finish_time,
+ int64_t total_encoded_data_length) {
+ DCHECK(!completed_);
+
+ SkBitmap icon;
+ if (!buffer_.empty()) {
+ ImageDecoder decoder;
+ icon = decoder.Decode(&buffer_[0], buffer_.size());
+ }
+
+ completed_ = true;
+ callback_.Run(notification_id_, icon);
+}
+
+void NotificationIconLoader::didFail(
+ WebURLLoader* loader, const WebURLError& error) {
+ if (completed_)
+ return;
+
+ completed_ = true;
+ callback_.Run(notification_id_, SkBitmap());
+}
+
+} // namespace content
« no previous file with comments | « content/renderer/notification_icon_loader.h ('k') | content/renderer/notification_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698