OLD | NEW |
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/browser/manifest/manifest_manager_host.h" | 5 #include "content/browser/manifest/manifest_manager_host.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "content/common/manifest_manager_messages.h" | 10 #include "content/common/manifest_manager_messages.h" |
11 #include "content/public/browser/render_frame_host.h" | 11 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/common/manifest.h" | 13 #include "content/public/common/manifest.h" |
14 #include "content/public/common/result_codes.h" | 14 #include "content/public/common/result_codes.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 void KillRenderer(RenderFrameHost* render_frame_host) { | 20 void KillRenderer(RenderFrameHost* render_frame_host) { |
21 base::ProcessHandle process_handle = | 21 base::ProcessHandle process_handle = |
22 render_frame_host->GetProcess()->GetHandle(); | 22 render_frame_host->GetProcess()->GetHandle(); |
23 if (process_handle == base::kNullProcessHandle) | 23 if (process_handle == base::kNullProcessHandle) |
24 return; | 24 return; |
25 render_frame_host->GetProcess()->Shutdown(RESULT_CODE_KILLED_BAD_MESSAGE, | 25 render_frame_host->GetProcess()->Shutdown(RESULT_CODE_KILLED_BAD_MESSAGE, |
26 false); | 26 false); |
27 } | 27 } |
28 | 28 |
29 } // anonymous namespace | 29 } // anonymous namespace |
30 | 30 |
31 ManifestManagerHost::ManifestManagerHost(WebContents* web_contents) | 31 ManifestManagerHost::ManifestManagerHost(WebContents* web_contents) |
32 : WebContentsObserver(web_contents) { | 32 : WebContentsObserver(web_contents) { |
33 } | 33 } |
34 | 34 |
35 ManifestManagerHost::~ManifestManagerHost() { | 35 ManifestManagerHost::~ManifestManagerHost() {} |
36 base::STLDeleteValues(&pending_get_callbacks_); | |
37 } | |
38 | 36 |
39 ManifestManagerHost::GetCallbackMap* | 37 ManifestManagerHost::GetCallbackMap* |
40 ManifestManagerHost::GetCallbackMapForFrame( | 38 ManifestManagerHost::GetCallbackMapForFrame( |
41 RenderFrameHost* render_frame_host) { | 39 RenderFrameHost* render_frame_host) { |
42 FrameGetCallbackMap::iterator it = | 40 auto it = pending_get_callbacks_.find(render_frame_host); |
43 pending_get_callbacks_.find(render_frame_host); | 41 return it != pending_get_callbacks_.end() ? it->second.get() : nullptr; |
44 return it != pending_get_callbacks_.end() ? it->second : nullptr; | |
45 } | 42 } |
46 | 43 |
47 void ManifestManagerHost::RenderFrameDeleted( | 44 void ManifestManagerHost::RenderFrameDeleted( |
48 RenderFrameHost* render_frame_host) { | 45 RenderFrameHost* render_frame_host) { |
49 GetCallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | 46 GetCallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); |
50 if (!callbacks) | 47 if (!callbacks) |
51 return; | 48 return; |
52 | 49 |
53 // Call the callbacks with a failure state before deleting them. Do this in | 50 // Call the callbacks with a failure state before deleting them. Do this in |
54 // a block so the iterator is destroyed before |callbacks|. | 51 // a block so the iterator is destroyed before |callbacks|. |
55 { | 52 { |
56 GetCallbackMap::const_iterator it(callbacks); | 53 GetCallbackMap::const_iterator it(callbacks); |
57 for (; !it.IsAtEnd(); it.Advance()) | 54 for (; !it.IsAtEnd(); it.Advance()) |
58 it.GetCurrentValue()->Run(GURL(), Manifest()); | 55 it.GetCurrentValue()->Run(GURL(), Manifest()); |
59 } | 56 } |
60 | 57 |
61 delete callbacks; | |
62 pending_get_callbacks_.erase(render_frame_host); | 58 pending_get_callbacks_.erase(render_frame_host); |
63 } | 59 } |
64 | 60 |
65 void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, | 61 void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, |
66 const GetManifestCallback& callback) { | 62 const GetManifestCallback& callback) { |
67 GetCallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | 63 GetCallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); |
68 if (!callbacks) { | 64 if (!callbacks) { |
69 callbacks = new GetCallbackMap(); | 65 callbacks = new GetCallbackMap(); |
70 pending_get_callbacks_[render_frame_host] = callbacks; | 66 pending_get_callbacks_[render_frame_host] = base::WrapUnique(callbacks); |
71 } | 67 } |
72 | 68 |
73 int request_id = callbacks->Add(new GetManifestCallback(callback)); | 69 int request_id = callbacks->Add(new GetManifestCallback(callback)); |
74 | 70 |
75 render_frame_host->Send(new ManifestManagerMsg_RequestManifest( | 71 render_frame_host->Send(new ManifestManagerMsg_RequestManifest( |
76 render_frame_host->GetRoutingID(), request_id)); | 72 render_frame_host->GetRoutingID(), request_id)); |
77 } | 73 } |
78 | 74 |
79 bool ManifestManagerHost::OnMessageReceived( | 75 bool ManifestManagerHost::OnMessageReceived( |
80 const IPC::Message& message, RenderFrameHost* render_frame_host) { | 76 const IPC::Message& message, RenderFrameHost* render_frame_host) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // any value outside the range of a 32 bit integer is invalid. | 140 // any value outside the range of a 32 bit integer is invalid. |
145 if (manifest.theme_color < std::numeric_limits<int32_t>::min() || | 141 if (manifest.theme_color < std::numeric_limits<int32_t>::min() || |
146 manifest.theme_color > std::numeric_limits<int32_t>::max()) | 142 manifest.theme_color > std::numeric_limits<int32_t>::max()) |
147 manifest.theme_color = Manifest::kInvalidOrMissingColor; | 143 manifest.theme_color = Manifest::kInvalidOrMissingColor; |
148 if (manifest.background_color < std::numeric_limits<int32_t>::min() || | 144 if (manifest.background_color < std::numeric_limits<int32_t>::min() || |
149 manifest.background_color > std::numeric_limits<int32_t>::max()) | 145 manifest.background_color > std::numeric_limits<int32_t>::max()) |
150 manifest.background_color = Manifest::kInvalidOrMissingColor; | 146 manifest.background_color = Manifest::kInvalidOrMissingColor; |
151 | 147 |
152 callback->Run(manifest_url, manifest); | 148 callback->Run(manifest_url, manifest); |
153 callbacks->Remove(request_id); | 149 callbacks->Remove(request_id); |
154 if (callbacks->IsEmpty()) { | 150 if (callbacks->IsEmpty()) |
155 delete callbacks; | |
156 pending_get_callbacks_.erase(render_frame_host); | 151 pending_get_callbacks_.erase(render_frame_host); |
157 } | |
158 } | 152 } |
159 | 153 |
160 } // namespace content | 154 } // namespace content |
OLD | NEW |