OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/renderer_host/chrome_render_view_host_observer.h" | 5 #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
6 | 6 |
7 #include "chrome/browser/dom_operation_notification_details.h" | 7 #include "chrome/browser/dom_operation_notification_details.h" |
| 8 #include "chrome/browser/net/predictor.h" |
8 #include "chrome/browser/net/predictor_api.h" | 9 #include "chrome/browser/net/predictor_api.h" |
9 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
10 #include "content/browser/renderer_host/render_view_host.h" | 11 #include "content/browser/renderer_host/render_view_host.h" |
11 #include "content/browser/renderer_host/render_view_host_delegate.h" | 12 #include "content/browser/renderer_host/render_view_host_delegate.h" |
12 #include "content/common/notification_service.h" | 13 #include "content/common/notification_service.h" |
13 #include "content/common/url_constants.h" | 14 #include "content/common/url_constants.h" |
14 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
15 | 16 |
16 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver( | 17 ChromeRenderViewHostObserver::ChromeRenderViewHostObserver( |
17 RenderViewHost* render_view_host) | 18 RenderViewHost* render_view_host, chrome_browser_net::Predictor* predictor) |
18 : RenderViewHostObserver(render_view_host) { | 19 : RenderViewHostObserver(render_view_host), |
| 20 predictor_(predictor) { |
19 } | 21 } |
20 | 22 |
21 ChromeRenderViewHostObserver::~ChromeRenderViewHostObserver() { | 23 ChromeRenderViewHostObserver::~ChromeRenderViewHostObserver() { |
22 } | 24 } |
23 | 25 |
24 void ChromeRenderViewHostObserver::Navigate( | 26 void ChromeRenderViewHostObserver::Navigate( |
25 const ViewMsg_Navigate_Params& params) { | 27 const ViewMsg_Navigate_Params& params) { |
26 const GURL& url = params.url; | 28 const GURL& url = params.url; |
| 29 if (!predictor_) |
| 30 return; |
27 if (!render_view_host()->delegate()->IsExternalTabContainer() && | 31 if (!render_view_host()->delegate()->IsExternalTabContainer() && |
28 (url.SchemeIs(chrome::kHttpScheme) || url.SchemeIs(chrome::kHttpsScheme))) | 32 (url.SchemeIs(chrome::kHttpScheme) || |
29 chrome_browser_net::PreconnectUrlAndSubresources(url); | 33 url.SchemeIs(chrome::kHttpsScheme))) { |
| 34 predictor_->PreconnectUrlAndSubresources(url); |
| 35 } |
30 } | 36 } |
31 | 37 |
32 bool ChromeRenderViewHostObserver::OnMessageReceived( | 38 bool ChromeRenderViewHostObserver::OnMessageReceived( |
33 const IPC::Message& message) { | 39 const IPC::Message& message) { |
34 bool handled = true; | 40 bool handled = true; |
35 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewHostObserver, message) | 41 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewHostObserver, message) |
36 IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse, | 42 IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse, |
37 OnDomOperationResponse) | 43 OnDomOperationResponse) |
38 IPC_MESSAGE_UNHANDLED(handled = false) | 44 IPC_MESSAGE_UNHANDLED(handled = false) |
39 IPC_END_MESSAGE_MAP() | 45 IPC_END_MESSAGE_MAP() |
40 return handled; | 46 return handled; |
41 } | 47 } |
42 | 48 |
43 void ChromeRenderViewHostObserver::OnDomOperationResponse( | 49 void ChromeRenderViewHostObserver::OnDomOperationResponse( |
44 const std::string& json_string, int automation_id) { | 50 const std::string& json_string, int automation_id) { |
45 DomOperationNotificationDetails details(json_string, automation_id); | 51 DomOperationNotificationDetails details(json_string, automation_id); |
46 NotificationService::current()->Notify( | 52 NotificationService::current()->Notify( |
47 NotificationType::DOM_OPERATION_RESPONSE, | 53 NotificationType::DOM_OPERATION_RESPONSE, |
48 Source<RenderViewHost>(render_view_host()), | 54 Source<RenderViewHost>(render_view_host()), |
49 Details<DomOperationNotificationDetails>(&details)); | 55 Details<DomOperationNotificationDetails>(&details)); |
50 } | 56 } |
OLD | NEW |