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

Side by Side Diff: content/renderer/manifest/manifest_manager.cc

Issue 1913043002: Convert ManifestManager IPCs to Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/manifest/manifest_manager.h" 5 #include "content/renderer/manifest/manifest_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/nullable_string16.h" 8 #include "base/strings/nullable_string16.h"
9 #include "content/common/manifest_manager_messages.h" 9 #include "content/common/manifest_type_converters.h"
10 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
11 #include "content/renderer/fetchers/manifest_fetcher.h" 11 #include "content/renderer/fetchers/manifest_fetcher.h"
12 #include "content/renderer/manifest/manifest_parser.h" 12 #include "content/renderer/manifest/manifest_parser.h"
13 #include "content/renderer/manifest/manifest_uma_util.h" 13 #include "content/renderer/manifest/manifest_uma_util.h"
14 #include "third_party/WebKit/public/platform/WebURLResponse.h" 14 #include "third_party/WebKit/public/platform/WebURLResponse.h"
15 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 15 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 ManifestManager::ManifestManager(RenderFrame* render_frame) 21 ManifestManager::ManifestManager(RenderFrame* render_frame)
22 : RenderFrameObserver(render_frame), 22 : RenderFrameObserver(render_frame),
23 may_have_manifest_(false), 23 may_have_manifest_(false),
24 manifest_dirty_(true) { 24 manifest_dirty_(true) {
25 } 25 }
26 26
27 ManifestManager::~ManifestManager() { 27 ManifestManager::~ManifestManager() {
28 if (fetcher_) 28 if (fetcher_)
29 fetcher_->Cancel(); 29 fetcher_->Cancel();
30 30
31 // Consumers in the browser process will not receive this message but they 31 // Consumers in the browser process will not receive this message but they
32 // will be aware of the RenderFrame dying and should act on that. Consumers 32 // will be aware of the RenderFrame dying and should act on that. Consumers
33 // in the renderer process should be correctly notified. 33 // in the renderer process should be correctly notified.
34 ResolveCallbacks(ResolveStateFailure); 34 ResolveCallbacks(ResolveStateFailure);
35 } 35 }
36 36
37 bool ManifestManager::OnMessageReceived(const IPC::Message& message) { 37 void ManifestManager::HasManifest(const HasManifestCallback& callback) {
38 bool handled = true; 38 GURL url(render_frame()->GetWebFrame()->document().manifestURL());
39 39
40 IPC_BEGIN_MESSAGE_MAP(ManifestManager, message) 40 callback.Run(may_have_manifest_ && !url.is_empty());
41 IPC_MESSAGE_HANDLER(ManifestManagerMsg_HasManifest, OnHasManifest)
42 IPC_MESSAGE_HANDLER(ManifestManagerMsg_RequestManifest, OnRequestManifest)
43 IPC_MESSAGE_UNHANDLED(handled = false)
44 IPC_END_MESSAGE_MAP()
45
46 return handled;
47 } 41 }
48 42
49 void ManifestManager::OnHasManifest(int request_id) { 43 void ManifestManager::RequestManifest(const RequestManifestCallback& callback) {
50 GURL url(render_frame()->GetWebFrame()->document().manifestURL());
51
52 bool has_manifest = may_have_manifest_ && !url.is_empty();
53 Send(new ManifestManagerHostMsg_HasManifestResponse(
54 routing_id(), request_id, has_manifest));
55 }
56
57 void ManifestManager::OnRequestManifest(int request_id) {
58 GetManifest(base::Bind(&ManifestManager::OnRequestManifestComplete, 44 GetManifest(base::Bind(&ManifestManager::OnRequestManifestComplete,
59 base::Unretained(this), request_id)); 45 base::Unretained(this), callback));
60 } 46 }
61 47
62 void ManifestManager::OnRequestManifestComplete( 48 void ManifestManager::OnRequestManifestComplete(
63 int request_id, const Manifest& manifest) { 49 const RequestManifestCallback& callback,
64 // When sent via IPC, the Manifest must follow certain security rules. 50 const Manifest& manifest) {
65 Manifest ipc_manifest = manifest; 51 callback.Run(blink::mojom::Manifest::From(manifest));
66 ipc_manifest.name = base::NullableString16(
67 ipc_manifest.name.string().substr(0, Manifest::kMaxIPCStringLength),
68 ipc_manifest.name.is_null());
69 ipc_manifest.short_name = base::NullableString16(
70 ipc_manifest.short_name.string().substr(0,
71 Manifest::kMaxIPCStringLength),
72 ipc_manifest.short_name.is_null());
73 for (auto& icon : ipc_manifest.icons) {
74 icon.type = base::NullableString16(
75 icon.type.string().substr(0, Manifest::kMaxIPCStringLength),
76 icon.type.is_null());
77 }
78 ipc_manifest.gcm_sender_id = base::NullableString16(
79 ipc_manifest.gcm_sender_id.string().substr(
80 0, Manifest::kMaxIPCStringLength),
81 ipc_manifest.gcm_sender_id.is_null());
82 for (auto& related_application : ipc_manifest.related_applications) {
83 related_application.id =
84 base::NullableString16(related_application.id.string().substr(
85 0, Manifest::kMaxIPCStringLength),
86 related_application.id.is_null());
87 }
88
89 Send(new ManifestManagerHostMsg_RequestManifestResponse(
90 routing_id(), request_id, ipc_manifest));
91 } 52 }
92 53
93 void ManifestManager::GetManifest(const GetManifestCallback& callback) { 54 void ManifestManager::GetManifest(const GetManifestCallback& callback) {
94 if (!may_have_manifest_) { 55 if (!may_have_manifest_) {
95 callback.Run(Manifest()); 56 callback.Run(Manifest());
96 return; 57 return;
97 } 58 }
98 59
99 if (!manifest_dirty_) { 60 if (!manifest_dirty_) {
100 callback.Run(manifest_); 61 callback.Run(manifest_);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 ResolveCallbacks(ResolveStateSuccess); 144 ResolveCallbacks(ResolveStateSuccess);
184 } 145 }
185 146
186 void ManifestManager::ResolveCallbacks(ResolveState state) { 147 void ManifestManager::ResolveCallbacks(ResolveState state) {
187 if (state == ResolveStateFailure) 148 if (state == ResolveStateFailure)
188 manifest_ = Manifest(); 149 manifest_ = Manifest();
189 150
190 manifest_dirty_ = state != ResolveStateSuccess; 151 manifest_dirty_ = state != ResolveStateSuccess;
191 152
192 Manifest manifest = manifest_; 153 Manifest manifest = manifest_;
193 std::list<GetManifestCallback> callbacks = pending_callbacks_; 154 std::vector<GetManifestCallback> callbacks = std::move(pending_callbacks_);
194
195 pending_callbacks_.clear(); 155 pending_callbacks_.clear();
196 156
197 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); 157 for (const auto& callback : callbacks) {
198 it != callbacks.end(); ++it) { 158 callback.Run(manifest);
199 it->Run(manifest);
200 } 159 }
mlamouri (slow - plz ping) 2016/04/27 13:38:08 style: remove { }
Sam McNally 2016/04/28 08:25:28 Done.
201 } 160 }
202 161
203 } // namespace content 162 void ManifestManager::BindToRequest(
163 blink::mojom::ManifestManagerRequest request) {
164 bindings_.AddBinding(this, std::move(request));
165 }
166
167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698