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

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, 6 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"
10 #include "content/public/renderer/render_frame.h" 9 #include "content/public/renderer/render_frame.h"
11 #include "content/renderer/fetchers/manifest_fetcher.h" 10 #include "content/renderer/fetchers/manifest_fetcher.h"
12 #include "content/renderer/manifest/manifest_parser.h" 11 #include "content/renderer/manifest/manifest_parser.h"
13 #include "content/renderer/manifest/manifest_uma_util.h" 12 #include "content/renderer/manifest/manifest_uma_util.h"
14 #include "third_party/WebKit/public/platform/WebURLResponse.h" 13 #include "third_party/WebKit/public/platform/WebURLResponse.h"
15 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 14 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 15 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 16 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 17
19 namespace content { 18 namespace content {
20 19
21 ManifestManager::ManifestManager(RenderFrame* render_frame) 20 ManifestManager::ManifestManager(RenderFrame* render_frame)
22 : RenderFrameObserver(render_frame), 21 : RenderFrameObserver(render_frame),
23 may_have_manifest_(false), 22 may_have_manifest_(false),
24 manifest_dirty_(true) { 23 manifest_dirty_(true) {
25 } 24 }
26 25
27 ManifestManager::~ManifestManager() { 26 ManifestManager::~ManifestManager() {
28 if (fetcher_) 27 if (fetcher_)
29 fetcher_->Cancel(); 28 fetcher_->Cancel();
30 29
31 // Consumers in the browser process will not receive this message but they 30 // 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 31 // will be aware of the RenderFrame dying and should act on that. Consumers
33 // in the renderer process should be correctly notified. 32 // in the renderer process should be correctly notified.
34 ResolveCallbacks(ResolveStateFailure); 33 ResolveCallbacks(ResolveStateFailure);
35 } 34 }
36 35
37 bool ManifestManager::OnMessageReceived(const IPC::Message& message) { 36 void ManifestManager::HasManifest(const HasManifestCallback& callback) {
38 bool handled = true; 37 GURL url(render_frame()->GetWebFrame()->document().manifestURL());
39 38
40 IPC_BEGIN_MESSAGE_MAP(ManifestManager, message) 39 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 } 40 }
48 41
49 void ManifestManager::OnHasManifest(int request_id) { 42 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, 43 GetManifest(base::Bind(&ManifestManager::OnRequestManifestComplete,
59 base::Unretained(this), request_id)); 44 base::Unretained(this), callback));
60 } 45 }
61 46
62 void ManifestManager::OnRequestManifestComplete( 47 void ManifestManager::OnRequestManifestComplete(
63 int request_id, const Manifest& manifest, 48 const RequestManifestCallback& callback,
49 const Manifest& manifest,
64 const ManifestDebugInfo&) { 50 const ManifestDebugInfo&) {
65 // When sent via IPC, the Manifest must follow certain security rules. 51 callback.Run(manifest);
66 Manifest ipc_manifest = manifest;
67 ipc_manifest.name = base::NullableString16(
68 ipc_manifest.name.string().substr(0, Manifest::kMaxIPCStringLength),
69 ipc_manifest.name.is_null());
70 ipc_manifest.short_name = base::NullableString16(
71 ipc_manifest.short_name.string().substr(0,
72 Manifest::kMaxIPCStringLength),
73 ipc_manifest.short_name.is_null());
74 for (auto& icon : ipc_manifest.icons) {
75 icon.type = base::NullableString16(
76 icon.type.string().substr(0, Manifest::kMaxIPCStringLength),
77 icon.type.is_null());
78 }
79 ipc_manifest.gcm_sender_id = base::NullableString16(
80 ipc_manifest.gcm_sender_id.string().substr(
81 0, Manifest::kMaxIPCStringLength),
82 ipc_manifest.gcm_sender_id.is_null());
83 for (auto& related_application : ipc_manifest.related_applications) {
84 related_application.id =
85 base::NullableString16(related_application.id.string().substr(
86 0, Manifest::kMaxIPCStringLength),
87 related_application.id.is_null());
88 }
89
90 Send(new ManifestManagerHostMsg_RequestManifestResponse(
91 routing_id(), request_id, ipc_manifest));
92 } 52 }
93 53
94 void ManifestManager::GetManifest(const GetManifestCallback& callback) { 54 void ManifestManager::GetManifest(const GetManifestCallback& callback) {
95 if (!may_have_manifest_) { 55 if (!may_have_manifest_) {
96 callback.Run(Manifest(), ManifestDebugInfo()); 56 callback.Run(Manifest(), ManifestDebugInfo());
97 return; 57 return;
98 } 58 }
99 59
100 if (!manifest_dirty_) { 60 if (!manifest_dirty_) {
101 callback.Run(manifest_, manifest_debug_info_); 61 callback.Run(manifest_, manifest_debug_info_);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 manifest_ = parser.manifest(); 150 manifest_ = parser.manifest();
191 ResolveCallbacks(ResolveStateSuccess); 151 ResolveCallbacks(ResolveStateSuccess);
192 } 152 }
193 153
194 void ManifestManager::ResolveCallbacks(ResolveState state) { 154 void ManifestManager::ResolveCallbacks(ResolveState state) {
195 if (state == ResolveStateFailure) 155 if (state == ResolveStateFailure)
196 manifest_ = Manifest(); 156 manifest_ = Manifest();
197 157
198 manifest_dirty_ = state != ResolveStateSuccess; 158 manifest_dirty_ = state != ResolveStateSuccess;
199 159
200 std::list<GetManifestCallback> callbacks; 160 Manifest manifest = manifest_;
201 callbacks.swap(pending_callbacks_); 161 std::vector<GetManifestCallback> callbacks = std::move(pending_callbacks_);
162 pending_callbacks_.clear();
202 163
203 for (std::list<GetManifestCallback>::const_iterator it = callbacks.begin(); 164 for (const auto& callback : callbacks)
204 it != callbacks.end(); ++it) { 165 callback.Run(manifest, manifest_debug_info_);
205 it->Run(manifest_, manifest_debug_info_); 166 }
206 } 167
168 void ManifestManager::BindToRequest(
169 blink::mojom::ManifestManagerRequest request) {
170 bindings_.AddBinding(this, std::move(request));
207 } 171 }
208 172
209 void ManifestManager::OnDestruct() { 173 void ManifestManager::OnDestruct() {
210 delete this; 174 delete this;
211 } 175 }
212 176
213 } // namespace content 177 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698