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