OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/manifest/manifest_manager_host.h" |
| 6 |
| 7 #include "content/common/manifest_manager_messages.h" |
| 8 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/common/manifest.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 ManifestManagerHost::ManifestManagerHost(WebContents* web_contents) |
| 14 : WebContentsObserver(web_contents) { |
| 15 } |
| 16 |
| 17 ManifestManagerHost::~ManifestManagerHost() { |
| 18 } |
| 19 |
| 20 void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, |
| 21 const GetManifestCallback& callback) { |
| 22 int request_id = pending_callbacks_.Add(new GetManifestCallback(callback)); |
| 23 |
| 24 render_frame_host->Send(new ManifestManagerMsg_RequestManifest( |
| 25 render_frame_host->GetRoutingID(), request_id)); |
| 26 } |
| 27 |
| 28 bool ManifestManagerHost::OnMessageReceived( |
| 29 const IPC::Message& message, RenderFrameHost* render_frame_host) { |
| 30 bool handled = true; |
| 31 |
| 32 IPC_BEGIN_MESSAGE_MAP(ManifestManagerHost, message) |
| 33 IPC_MESSAGE_HANDLER(ManifestManagerHostMsg_RequestManifestResponse, |
| 34 OnRequestManifestResponse) |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() |
| 37 |
| 38 return handled; |
| 39 } |
| 40 |
| 41 void ManifestManagerHost::OnRequestManifestResponse(int request_id, |
| 42 const Manifest& manifest) { |
| 43 GetManifestCallback* callback = pending_callbacks_.Lookup(request_id); |
| 44 if (!callback) { |
| 45 LOG(ERROR) << "Received a request_id (" << request_id << ") from renderer " |
| 46 "with no associated callabck."; |
| 47 return; |
| 48 } |
| 49 |
| 50 callback->Run(manifest); |
| 51 pending_callbacks_.Remove(request_id); |
| 52 } |
| 53 |
| 54 } // namespace content |
OLD | NEW |