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/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) | 1031 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
1032 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, | 1032 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
1033 OnSetContentSettingsForLoadingURL) | 1033 OnSetContentSettingsForLoadingURL) |
1034 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) | 1034 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
1035 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, | 1035 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
1036 OnSetZoomLevelForLoadingURL) | 1036 OnSetZoomLevelForLoadingURL) |
1037 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) | 1037 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
1038 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, | 1038 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
1039 OnResetPageEncodingToDefault) | 1039 OnResetPageEncodingToDefault) |
1040 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) | 1040 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
1041 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) | 1041 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavicon, OnDownloadFavicon) |
1042 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) | 1042 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
1043 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) | 1043 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
1044 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) | 1044 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
1045 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) | 1045 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
1046 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) | 1046 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
1047 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) | 1047 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
1048 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) | 1048 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
1049 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) | 1049 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
1050 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) | 1050 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
1051 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty) | 1051 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty) |
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2178 | 2178 |
2179 is_loading_ = false; | 2179 is_loading_ = false; |
2180 | 2180 |
2181 // NOTE: For now we're doing the safest thing, and sending out notification | 2181 // NOTE: For now we're doing the safest thing, and sending out notification |
2182 // when done loading. This currently isn't an issue as the favicon is only | 2182 // when done loading. This currently isn't an issue as the favicon is only |
2183 // displayed when done loading. Ideally we would send notification when | 2183 // displayed when done loading. Ideally we would send notification when |
2184 // finished parsing the head, but webkit doesn't support that yet. | 2184 // finished parsing the head, but webkit doesn't support that yet. |
2185 // The feed discovery code would also benefit from access to the head. | 2185 // The feed discovery code would also benefit from access to the head. |
2186 GURL favicon_url(webview()->mainFrame()->favIconURL()); | 2186 GURL favicon_url(webview()->mainFrame()->favIconURL()); |
2187 if (!favicon_url.is_empty()) | 2187 if (!favicon_url.is_empty()) |
2188 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); | 2188 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, favicon_url)); |
2189 | 2189 |
2190 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), | 2190 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), |
2191 ViewHostMsg_PageHasOSDD_Type::Autodetected()); | 2191 ViewHostMsg_PageHasOSDD_Type::Autodetected()); |
2192 | 2192 |
2193 Send(new ViewHostMsg_DidStopLoading(routing_id_)); | 2193 Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
2194 | 2194 |
2195 if (load_progress_tracker_ != NULL) | 2195 if (load_progress_tracker_ != NULL) |
2196 load_progress_tracker_->DidStopLoading(); | 2196 load_progress_tracker_->DidStopLoading(); |
2197 | 2197 |
2198 MessageLoop::current()->PostDelayedTask( | 2198 MessageLoop::current()->PostDelayedTask( |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3487 | 3487 |
3488 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { | 3488 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
3489 UpdateTitle(frame, title); | 3489 UpdateTitle(frame, title); |
3490 | 3490 |
3491 // Also check whether we have new encoding name. | 3491 // Also check whether we have new encoding name. |
3492 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); | 3492 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
3493 } | 3493 } |
3494 | 3494 |
3495 void RenderView::didChangeIcons(WebFrame* frame) { | 3495 void RenderView::didChangeIcons(WebFrame* frame) { |
3496 if (!frame->parent()) { | 3496 if (!frame->parent()) { |
3497 Send(new ViewHostMsg_UpdateFavIconURL( | 3497 Send(new ViewHostMsg_UpdateFaviconURL( |
3498 routing_id_, | 3498 routing_id_, |
3499 page_id_, | 3499 page_id_, |
3500 frame->favIconURL())); | 3500 frame->favIconURL())); |
3501 } | 3501 } |
3502 } | 3502 } |
3503 | 3503 |
3504 void RenderView::didFinishDocumentLoad(WebFrame* frame) { | 3504 void RenderView::didFinishDocumentLoad(WebFrame* frame) { |
3505 WebDataSource* ds = frame->dataSource(); | 3505 WebDataSource* ds = frame->dataSource(); |
3506 NavigationState* navigation_state = NavigationState::FromDataSource(ds); | 3506 NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
3507 DCHECK(navigation_state); | 3507 DCHECK(navigation_state); |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3992 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>( | 3992 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>( |
3993 new ImageResourceFetcher( | 3993 new ImageResourceFetcher( |
3994 image_url, webview()->mainFrame(), id, image_size, | 3994 image_url, webview()->mainFrame(), id, image_size, |
3995 NewCallback(this, &RenderView::DidDownloadImage)))); | 3995 NewCallback(this, &RenderView::DidDownloadImage)))); |
3996 return true; | 3996 return true; |
3997 } | 3997 } |
3998 | 3998 |
3999 void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, | 3999 void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, |
4000 const SkBitmap& image) { | 4000 const SkBitmap& image) { |
4001 // Notify requester of image download status. | 4001 // Notify requester of image download status. |
4002 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, | 4002 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_, |
4003 fetcher->id(), | 4003 fetcher->id(), |
4004 fetcher->image_url(), | 4004 fetcher->image_url(), |
4005 image.isNull(), | 4005 image.isNull(), |
4006 image)); | 4006 image)); |
4007 | 4007 |
4008 // Remove the image fetcher from our pending list. We're in the callback from | 4008 // Remove the image fetcher from our pending list. We're in the callback from |
4009 // ImageResourceFetcher, best to delay deletion. | 4009 // ImageResourceFetcher, best to delay deletion. |
4010 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin(); | 4010 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin(); |
4011 iter != image_fetchers_.end(); ++iter) { | 4011 iter != image_fetchers_.end(); ++iter) { |
4012 if (iter->get() == fetcher) { | 4012 if (iter->get() == fetcher) { |
4013 iter->release(); | 4013 iter->release(); |
4014 image_fetchers_.erase(iter); | 4014 image_fetchers_.erase(iter); |
4015 break; | 4015 break; |
4016 } | 4016 } |
4017 } | 4017 } |
4018 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); | 4018 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
4019 } | 4019 } |
4020 | 4020 |
4021 void RenderView::OnDownloadFavIcon(int id, | 4021 void RenderView::OnDownloadFavicon(int id, |
4022 const GURL& image_url, | 4022 const GURL& image_url, |
4023 int image_size) { | 4023 int image_size) { |
4024 bool data_image_failed = false; | 4024 bool data_image_failed = false; |
4025 if (image_url.SchemeIs("data")) { | 4025 if (image_url.SchemeIs("data")) { |
4026 SkBitmap data_image = ImageFromDataUrl(image_url); | 4026 SkBitmap data_image = ImageFromDataUrl(image_url); |
4027 data_image_failed = data_image.empty(); | 4027 data_image_failed = data_image.empty(); |
4028 if (!data_image_failed) { | 4028 if (!data_image_failed) { |
4029 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false, | 4029 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_, id, image_url, false, |
4030 data_image)); | 4030 data_image)); |
4031 } | 4031 } |
4032 } | 4032 } |
4033 | 4033 |
4034 if (data_image_failed || | 4034 if (data_image_failed || |
4035 !DownloadImage(id, image_url, image_size)) { | 4035 !DownloadImage(id, image_url, image_size)) { |
4036 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true, | 4036 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_, id, image_url, true, |
4037 SkBitmap())); | 4037 SkBitmap())); |
4038 } | 4038 } |
4039 } | 4039 } |
4040 | 4040 |
4041 SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { | 4041 SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
4042 std::string mime_type, char_set, data; | 4042 std::string mime_type, char_set, data; |
4043 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { | 4043 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
4044 // Decode the favicon using WebKit's image decoder. | 4044 // Decode the favicon using WebKit's image decoder. |
4045 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); | 4045 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); |
4046 const unsigned char* src_data = | 4046 const unsigned char* src_data = |
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5605 const webkit_glue::CustomContextMenuContext& custom_context) { | 5605 const webkit_glue::CustomContextMenuContext& custom_context) { |
5606 if (custom_context.is_pepper_menu) | 5606 if (custom_context.is_pepper_menu) |
5607 pepper_delegate_.OnContextMenuClosed(custom_context); | 5607 pepper_delegate_.OnContextMenuClosed(custom_context); |
5608 else | 5608 else |
5609 context_menu_node_.reset(); | 5609 context_menu_node_.reset(); |
5610 } | 5610 } |
5611 | 5611 |
5612 void RenderView::OnNetworkStateChanged(bool online) { | 5612 void RenderView::OnNetworkStateChanged(bool online) { |
5613 WebNetworkStateNotifier::setOnLine(online); | 5613 WebNetworkStateNotifier::setOnLine(online); |
5614 } | 5614 } |
OLD | NEW |