| 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/renderer/chrome_render_view_observer.h" | 5 #include "chrome/renderer/chrome_render_view_observer.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/icon_messages.h" |
| 11 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/common/thumbnail_score.h" | 13 #include "chrome/common/thumbnail_score.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/renderer/about_handler.h" | 15 #include "chrome/renderer/about_handler.h" |
| 15 #include "chrome/renderer/automation/dom_automation_controller.h" | 16 #include "chrome/renderer/automation/dom_automation_controller.h" |
| 16 #include "chrome/renderer/external_host_bindings.h" | 17 #include "chrome/renderer/external_host_bindings.h" |
| 17 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 18 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
| 18 #include "chrome/renderer/translate_helper.h" | 19 #include "chrome/renderer/translate_helper.h" |
| 19 #include "content/common/bindings_policy.h" | 20 #include "content/common/bindings_policy.h" |
| 20 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) | 135 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
| 135 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, | 136 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
| 136 OnHandleMessageFromExternalHost) | 137 OnHandleMessageFromExternalHost) |
| 137 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl, | 138 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl, |
| 138 OnJavaScriptStressTestControl) | 139 OnJavaScriptStressTestControl) |
| 139 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, | 140 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 140 OnGetAllSavableResourceLinksForCurrentPage) | 141 OnGetAllSavableResourceLinksForCurrentPage) |
| 141 IPC_MESSAGE_HANDLER( | 142 IPC_MESSAGE_HANDLER( |
| 142 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, | 143 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 143 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) | 144 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
| 144 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavicon, OnDownloadFavicon) | 145 IPC_MESSAGE_HANDLER(IconMsg_DownloadFavicon, OnDownloadFavicon) |
| 145 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 146 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| 146 IPC_MESSAGE_UNHANDLED(handled = false) | 147 IPC_MESSAGE_UNHANDLED(handled = false) |
| 147 IPC_END_MESSAGE_MAP() | 148 IPC_END_MESSAGE_MAP() |
| 148 | 149 |
| 149 // Filter only. | 150 // Filter only. |
| 150 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 151 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
| 151 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) | 152 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 152 IPC_END_MESSAGE_MAP() | 153 IPC_END_MESSAGE_MAP() |
| 153 | 154 |
| 154 return handled; | 155 return handled; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 242 } |
| 242 | 243 |
| 243 void ChromeRenderViewObserver::OnDownloadFavicon(int id, | 244 void ChromeRenderViewObserver::OnDownloadFavicon(int id, |
| 244 const GURL& image_url, | 245 const GURL& image_url, |
| 245 int image_size) { | 246 int image_size) { |
| 246 bool data_image_failed = false; | 247 bool data_image_failed = false; |
| 247 if (image_url.SchemeIs("data")) { | 248 if (image_url.SchemeIs("data")) { |
| 248 SkBitmap data_image = ImageFromDataUrl(image_url); | 249 SkBitmap data_image = ImageFromDataUrl(image_url); |
| 249 data_image_failed = data_image.empty(); | 250 data_image_failed = data_image.empty(); |
| 250 if (!data_image_failed) { | 251 if (!data_image_failed) { |
| 251 Send(new ViewHostMsg_DidDownloadFavicon( | 252 Send(new IconHostMsg_DidDownloadFavicon( |
| 252 routing_id(), id, image_url, false, data_image)); | 253 routing_id(), id, image_url, false, data_image)); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| 256 if (data_image_failed || | 257 if (data_image_failed || |
| 257 !DownloadFavicon(id, image_url, image_size)) { | 258 !DownloadFavicon(id, image_url, image_size)) { |
| 258 Send(new ViewHostMsg_DidDownloadFavicon( | 259 Send(new IconHostMsg_DidDownloadFavicon( |
| 259 routing_id(), id, image_url, true, SkBitmap())); | 260 routing_id(), id, image_url, true, SkBitmap())); |
| 260 } | 261 } |
| 261 } | 262 } |
| 262 | 263 |
| 263 void ChromeRenderViewObserver::OnEnableViewSourceMode() { | 264 void ChromeRenderViewObserver::OnEnableViewSourceMode() { |
| 264 if (!render_view()->webview()) | 265 if (!render_view()->webview()) |
| 265 return; | 266 return; |
| 266 WebFrame* main_frame = render_view()->webview()->mainFrame(); | 267 WebFrame* main_frame = render_view()->webview()->mainFrame(); |
| 267 if (!main_frame) | 268 if (!main_frame) |
| 268 return; | 269 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 299 if (!osd_url.is_empty()) { | 300 if (!osd_url.is_empty()) { |
| 300 Send(new ViewHostMsg_PageHasOSDD( | 301 Send(new ViewHostMsg_PageHasOSDD( |
| 301 routing_id(), render_view()->page_id(), osd_url, | 302 routing_id(), render_view()->page_id(), osd_url, |
| 302 search_provider::AUTODETECTED_PROVIDER)); | 303 search_provider::AUTODETECTED_PROVIDER)); |
| 303 } | 304 } |
| 304 | 305 |
| 305 // TODO : Get both favicon and touch icon url, and send them to the browser. | 306 // TODO : Get both favicon and touch icon url, and send them to the browser. |
| 306 GURL favicon_url(render_view()->webview()->mainFrame()->favIconURL()); | 307 GURL favicon_url(render_view()->webview()->mainFrame()->favIconURL()); |
| 307 if (!favicon_url.is_empty()) { | 308 if (!favicon_url.is_empty()) { |
| 308 std::vector<FaviconURL> urls; | 309 std::vector<FaviconURL> urls; |
| 309 urls.push_back(FaviconURL(favicon_url, FAVICON)); | 310 urls.push_back(FaviconURL(favicon_url, FaviconURL::FAVICON)); |
| 310 Send(new ViewHostMsg_UpdateFaviconURL( | 311 Send(new IconHostMsg_UpdateFaviconURL( |
| 311 routing_id(), render_view()->page_id(), urls)); | 312 routing_id(), render_view()->page_id(), urls)); |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 | 315 |
| 315 void ChromeRenderViewObserver::DidChangeIcons(WebFrame* frame) { | 316 void ChromeRenderViewObserver::DidChangeIcons(WebFrame* frame) { |
| 316 if (frame->parent()) | 317 if (frame->parent()) |
| 317 return; | 318 return; |
| 318 | 319 |
| 319 std::vector<FaviconURL> urls; | 320 std::vector<FaviconURL> urls; |
| 320 urls.push_back(FaviconURL(frame->favIconURL(), FAVICON)); | 321 urls.push_back(FaviconURL(frame->favIconURL(), FaviconURL::FAVICON)); |
| 321 Send(new ViewHostMsg_UpdateFaviconURL( | 322 Send(new IconHostMsg_UpdateFaviconURL( |
| 322 routing_id(), render_view()->page_id(), urls)); | 323 routing_id(), render_view()->page_id(), urls)); |
| 323 } | 324 } |
| 324 | 325 |
| 325 void ChromeRenderViewObserver::DidCommitProvisionalLoad( | 326 void ChromeRenderViewObserver::DidCommitProvisionalLoad( |
| 326 WebFrame* frame, bool is_new_navigation) { | 327 WebFrame* frame, bool is_new_navigation) { |
| 327 if (!is_new_navigation) | 328 if (!is_new_navigation) |
| 328 return; | 329 return; |
| 329 | 330 |
| 330 MessageLoop::current()->PostDelayedTask( | 331 MessageLoop::current()->PostDelayedTask( |
| 331 FROM_HERE, | 332 FROM_HERE, |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 new ImageResourceFetcher( | 578 new ImageResourceFetcher( |
| 578 image_url, render_view()->webview()->mainFrame(), id, image_size, | 579 image_url, render_view()->webview()->mainFrame(), id, image_size, |
| 579 WebURLRequest::TargetIsFavicon, | 580 WebURLRequest::TargetIsFavicon, |
| 580 NewCallback(this, &ChromeRenderViewObserver::DidDownloadFavicon)))); | 581 NewCallback(this, &ChromeRenderViewObserver::DidDownloadFavicon)))); |
| 581 return true; | 582 return true; |
| 582 } | 583 } |
| 583 | 584 |
| 584 void ChromeRenderViewObserver::DidDownloadFavicon( | 585 void ChromeRenderViewObserver::DidDownloadFavicon( |
| 585 ImageResourceFetcher* fetcher, const SkBitmap& image) { | 586 ImageResourceFetcher* fetcher, const SkBitmap& image) { |
| 586 // Notify requester of image download status. | 587 // Notify requester of image download status. |
| 587 Send(new ViewHostMsg_DidDownloadFavicon(routing_id(), | 588 Send(new IconHostMsg_DidDownloadFavicon(routing_id(), |
| 588 fetcher->id(), | 589 fetcher->id(), |
| 589 fetcher->image_url(), | 590 fetcher->image_url(), |
| 590 image.isNull(), | 591 image.isNull(), |
| 591 image)); | 592 image)); |
| 592 | 593 |
| 593 // Remove the image fetcher from our pending list. We're in the callback from | 594 // Remove the image fetcher from our pending list. We're in the callback from |
| 594 // ImageResourceFetcher, best to delay deletion. | 595 // ImageResourceFetcher, best to delay deletion. |
| 595 RenderView::ImageResourceFetcherList::iterator iter; | 596 RenderView::ImageResourceFetcherList::iterator iter; |
| 596 for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) { | 597 for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) { |
| 597 if (iter->get() == fetcher) { | 598 if (iter->get() == fetcher) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 608 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | 609 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 609 // Decode the favicon using WebKit's image decoder. | 610 // Decode the favicon using WebKit's image decoder. |
| 610 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); | 611 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); |
| 611 const unsigned char* src_data = | 612 const unsigned char* src_data = |
| 612 reinterpret_cast<const unsigned char*>(&data[0]); | 613 reinterpret_cast<const unsigned char*>(&data[0]); |
| 613 | 614 |
| 614 return decoder.Decode(src_data, data.size()); | 615 return decoder.Decode(src_data, data.size()); |
| 615 } | 616 } |
| 616 return SkBitmap(); | 617 return SkBitmap(); |
| 617 } | 618 } |
| OLD | NEW |