Chromium Code Reviews| 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 ManifestManagerHost::CallbackMap* ManifestManagerHost::GetCallbackMapForFrame( | |
| 21 RenderFrameHost* render_frame_host) { | |
| 22 FrameCallbackMap::iterator it = pending_callbacks_.find(render_frame_host); | |
| 23 return it != pending_callbacks_.end() ? it->second : 0; | |
| 24 } | |
| 25 | |
| 26 void ManifestManagerHost::RenderFrameDeleted( | |
| 27 RenderFrameHost* render_frame_host) { | |
| 28 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | |
| 29 if (!callbacks) | |
| 30 return; | |
| 31 | |
| 32 // Before deleting the callbacks, make sure they are called with a failure | |
| 33 // state. | |
| 34 CallbackMap::const_iterator it(callbacks); | |
| 35 for (; !it.IsAtEnd(); it.Advance()) | |
| 36 it.GetCurrentValue()->Run(Manifest()); | |
| 37 | |
| 38 pending_callbacks_.erase(render_frame_host); | |
| 39 } | |
| 40 | |
| 41 void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, | |
| 42 const GetManifestCallback& callback) { | |
| 43 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | |
| 44 if (!callbacks) { | |
| 45 callbacks = new CallbackMap(); | |
| 46 pending_callbacks_[render_frame_host] = callbacks; | |
| 47 } | |
| 48 | |
| 49 int request_id = callbacks->Add(new GetManifestCallback(callback)); | |
| 50 | |
| 51 render_frame_host->Send(new ManifestManagerMsg_RequestManifest( | |
| 52 render_frame_host->GetRoutingID(), request_id)); | |
| 53 } | |
| 54 | |
| 55 bool ManifestManagerHost::OnMessageReceived( | |
| 56 const IPC::Message& message, RenderFrameHost* render_frame_host) { | |
| 57 bool handled = true; | |
| 58 | |
| 59 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ManifestManagerHost, message, | |
| 60 render_frame_host) | |
| 61 IPC_MESSAGE_HANDLER(ManifestManagerHostMsg_RequestManifestResponse, | |
| 62 OnRequestManifestResponse) | |
| 63 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 64 IPC_END_MESSAGE_MAP() | |
| 65 | |
| 66 return handled; | |
| 67 } | |
| 68 | |
| 69 void ManifestManagerHost::OnRequestManifestResponse( | |
| 70 RenderFrameHost* render_frame_host, | |
| 71 int request_id, | |
| 72 const Manifest& insecure_manifest) { | |
| 73 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | |
| 74 if (!callbacks) { | |
| 75 LOG(ERROR) << "Unexpected ManifestResponse to RenderFrameHost."; | |
|
jochen (gone - plz use gerrit)
2014/09/16 14:41:39
DVLOG(1) should be enough
mlamouri (slow - plz ping)
2014/09/16 15:32:36
Done.
| |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 GetManifestCallback* callback = callbacks->Lookup(request_id); | |
| 80 if (!callback) { | |
| 81 LOG(ERROR) << "Received a request_id (" << request_id << ") from renderer " | |
|
jochen (gone - plz use gerrit)
2014/09/16 14:41:39
DVLOG(1). Also kill the renderer because an invali
mlamouri (slow - plz ping)
2014/09/16 15:32:36
Done. I've added some code to kill the renderer in
| |
| 82 "with no associated callback."; | |
| 83 return; | |
| 84 } | |
| 85 | |
| 86 // When receiving a Manifest, the browser process can't trust that it is | |
| 87 // coming from a known and secure source. It must be processed accordingly. | |
| 88 Manifest manifest = insecure_manifest; | |
| 89 manifest.name = base::NullableString16( | |
| 90 manifest.name.string().substr(0, Manifest::kMaxIPCStringLength), | |
| 91 manifest.name.is_null()); | |
| 92 manifest.short_name = base::NullableString16( | |
| 93 manifest.short_name.string().substr(0, Manifest::kMaxIPCStringLength), | |
| 94 manifest.short_name.is_null()); | |
| 95 | |
| 96 callback->Run(manifest); | |
| 97 callbacks->Remove(request_id); | |
| 98 if (callbacks->IsEmpty()) { | |
| 99 delete callbacks; | |
| 100 pending_callbacks_.erase(render_frame_host); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 } // namespace content | |
| OLD | NEW |