OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" | 7 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" |
8 | 8 |
| 9 #include "base/message_loop.h" |
9 #include "chrome/browser/renderer_host/render_view_host.h" | 10 #include "chrome/browser/renderer_host/render_view_host.h" |
10 #include "chrome/browser/tab_contents/tab_util.h" | |
11 #include "chrome/browser/tab_contents/tab_contents.h" | |
12 | 11 |
13 namespace { | 12 namespace { |
| 13 |
14 // Task to notify the TabContents that a cross-site response has begun, so that | 14 // Task to notify the TabContents that a cross-site response has begun, so that |
15 // TabContents can tell the old page to run its onunload handler. | 15 // TabContents can tell the old page to run its onunload handler. |
16 class CrossSiteNotifyTabTask : public Task { | 16 class CrossSiteNotifyTask : public Task { |
17 public: | 17 public: |
18 CrossSiteNotifyTabTask(int render_process_host_id, | 18 CrossSiteNotifyTask(int render_process_host_id, |
19 int render_view_id, | 19 int render_view_id, |
20 int request_id) | 20 int request_id) |
21 : render_process_host_id_(render_process_host_id), | 21 : render_process_host_id_(render_process_host_id), |
22 render_view_id_(render_view_id), | 22 render_view_id_(render_view_id), |
23 request_id_(request_id) {} | 23 request_id_(request_id) {} |
24 | 24 |
25 void Run() { | 25 void Run() { |
26 RenderViewHost* view = | 26 RenderViewHost* view = |
27 RenderViewHost::FromID(render_process_host_id_, render_view_id_); | 27 RenderViewHost::FromID(render_process_host_id_, render_view_id_); |
28 if (view) { | 28 if (view) { |
29 view->OnCrossSiteResponse(render_process_host_id_, request_id_); | 29 view->OnCrossSiteResponse(render_process_host_id_, request_id_); |
30 } else { | 30 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
41 }; | 41 }; |
42 | 42 |
43 class CancelPendingRenderViewTask : public Task { | 43 class CancelPendingRenderViewTask : public Task { |
44 public: | 44 public: |
45 CancelPendingRenderViewTask(int render_process_host_id, | 45 CancelPendingRenderViewTask(int render_process_host_id, |
46 int render_view_id) | 46 int render_view_id) |
47 : render_process_host_id_(render_process_host_id), | 47 : render_process_host_id_(render_process_host_id), |
48 render_view_id_(render_view_id) {} | 48 render_view_id_(render_view_id) {} |
49 | 49 |
50 void Run() { | 50 void Run() { |
51 TabContents* tab_contents = | 51 RenderViewHost* view = |
52 tab_util::GetTabContentsByID(render_process_host_id_, render_view_id_); | 52 RenderViewHost::FromID(render_process_host_id_, render_view_id_); |
53 if (tab_contents) | 53 if (view) |
54 tab_contents->CrossSiteNavigationCanceled(); | 54 view->delegate()->OnCrossSiteNavigationCanceled(); |
55 } | 55 } |
56 | 56 |
57 private: | 57 private: |
58 int render_process_host_id_; | 58 int render_process_host_id_; |
59 int render_view_id_; | 59 int render_view_id_; |
60 }; | 60 }; |
61 } | 61 |
| 62 } // namespace |
62 | 63 |
63 CrossSiteResourceHandler::CrossSiteResourceHandler( | 64 CrossSiteResourceHandler::CrossSiteResourceHandler( |
64 ResourceHandler* handler, | 65 ResourceHandler* handler, |
65 int render_process_host_id, | 66 int render_process_host_id, |
66 int render_view_id, | 67 int render_view_id, |
67 ResourceDispatcherHost* resource_dispatcher_host) | 68 ResourceDispatcherHost* resource_dispatcher_host) |
68 : next_handler_(handler), | 69 : next_handler_(handler), |
69 render_process_host_id_(render_process_host_id), | 70 render_process_host_id_(render_process_host_id), |
70 render_view_id_(render_view_id), | 71 render_view_id_(render_view_id), |
71 has_started_response_(false), | 72 has_started_response_(false), |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // renderer is ready. | 244 // renderer is ready. |
244 rdh_->PauseRequest(render_process_host_id_, request_id, true); | 245 rdh_->PauseRequest(render_process_host_id_, request_id, true); |
245 } | 246 } |
246 // If our OnResponseStarted wasn't called, then we're being called by | 247 // If our OnResponseStarted wasn't called, then we're being called by |
247 // OnResponseCompleted after a failure. We don't need to pause, because | 248 // OnResponseCompleted after a failure. We don't need to pause, because |
248 // there will be no reads. | 249 // there will be no reads. |
249 | 250 |
250 // Tell the tab responsible for this request that a cross-site response is | 251 // Tell the tab responsible for this request that a cross-site response is |
251 // starting, so that it can tell its old renderer to run its onunload | 252 // starting, so that it can tell its old renderer to run its onunload |
252 // handler now. We will wait to hear the corresponding ClosePage_ACK. | 253 // handler now. We will wait to hear the corresponding ClosePage_ACK. |
253 CrossSiteNotifyTabTask* task = | 254 CrossSiteNotifyTask* task = |
254 new CrossSiteNotifyTabTask(render_process_host_id_, | 255 new CrossSiteNotifyTask(render_process_host_id_, |
255 render_view_id_, | 256 render_view_id_, |
256 request_id); | 257 request_id); |
257 rdh_->ui_loop()->PostTask(FROM_HERE, task); | 258 rdh_->ui_loop()->PostTask(FROM_HERE, task); |
258 } | 259 } |
OLD | NEW |